我需要为扩展 JXMapKit 的类中的关闭按钮添加功能(例如保存位置和 *EXIT_ON_CLOSE* )。main() 方法只是 JXMapKit 的原始 main 方法的复制粘贴。
我有以下简单的代码来使用 JXMapKit:
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import org.jdesktop.swingx.mapviewer.DefaultTileFactory;
import org.jdesktop.swingx.mapviewer.GeoPosition;
import org.jdesktop.swingx.mapviewer.TileFactory;
import org.jdesktop.swingx.mapviewer.TileFactoryInfo;
@SuppressWarnings("serial")
public class MyMap extends JXMapKit{
public static void main(String ... args){
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JXMapKit kit = new JXMapKit();
kit.setDefaultProvider(DefaultProviders.OpenStreetMaps);
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
"http://tile.openstreetmap.org",//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";
return url;
}
};
TileFactory tf = new DefaultTileFactory(info);
kit.setTileFactory(tf);
kit.setZoom(14);
kit.setAddressLocation(new GeoPosition(22.5697, 88.3697));//coordinates of Kolkata
kit.getMainMap().setDrawTileBorders(true);
kit.getMainMap().setRestrictOutsidePanning(true);
kit.getMainMap().setHorizontalWrapped(false);
((DefaultTileFactory)kit.getMainMap().getTileFactory()).setThreadPoolSize(8);
JFrame frame = new JFrame("JXMapKit test");
frame.add(kit);
frame.pack();
frame.setSize(500,300);
frame.setVisible(true);
}
});
}
}