1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| package modif.posit;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import org.jdesktop.swingx.JXMapKit;
import org.jdesktop.swingx.JXMapViewer;
import org.jdesktop.swingx.mapviewer.DefaultTileFactory;
import org.jdesktop.swingx.mapviewer.DefaultWaypoint;
import org.jdesktop.swingx.mapviewer.GeoPosition;
import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
import org.jdesktop.swingx.mapviewer.Waypoint;
import org.jdesktop.swingx.mapviewer.WaypointPainter;
public class WSDemo {
double lat,longi;
String[] args;
class CustomPainter extends WaypointPainter<JXMapViewer> {
public void setWaypoints(List<? extends Waypoint> waypoints) {
super.setWaypoints(new HashSet<Waypoint>(waypoints));
}
}
private JComponent createContent() {
JComponent content = new JPanel();
content.setLayout(new BorderLayout());
content.add(createMapKit());
return content;
}
protected JComponent createMapKit() {
final int max = 17;
TileFactoryInfo info = new TileFactoryInfo(1, max - 2, max, 256, true,
true, // tile size is 256 and x/y orientation is normal
"file:/D:/Tiles",// 5/15/10.png",
"x", "y", "z") {
public String getTileUrl(int x, int y, int zoom) {
zoom = max - zoom;
String url = this.baseURL + "/" + zoom + "/" + x + "/" + y
+ ".png";
System.out.print(url + "\n");
return url;
}
};
DefaultTileFactory tf = new DefaultTileFactory(info);
tf.setThreadPoolSize(1);
final JXMapKit kit = new JXMapKit();
kit.setTileFactory(tf);
kit.setZoom(12);
kit.setAddressLocation(new GeoPosition(48, -3));
kit.getMainMap().setDrawTileBorders(true);
List<DefaultWaypoint> waypoints = new ArrayList<DefaultWaypoint>();
waypoints.add(new DefaultWaypoint(51.5, -3));
waypoints.add(new DefaultWaypoint(48, -5));
CustomPainter painter = new CustomPainter();
painter.setWaypoints(waypoints);
kit.getMainMap().setOverlayPainter(painter);
return kit;
}
public WSDemo(String[] args) {
this.args = args;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.add(new WSDemo().createContent());
frame.setLocationByPlatform(true);
frame.setSize(900, 900);
frame.setVisible(true);
}
});
}
} |
Partager