2013-10-21 78 views
1

我有一个JMapViewer作为面板上的JFrame和一个按钮。如果我按下按钮,我想让JMapViewer显示滚动的地图摘录。以编程方式滚动JMapViewer地图

我试图设置另一个显示位置的纬度/经度,但我不知道如何获得旧的mapcentered纬度/经度值..?

我的按钮的ActionListener,它应该表现出小幅上扬移动地图摘录:

btn_PanUp.addActionListener(new ActionListener(){ 

    @Override 
    public void actionPerformed(ActionEvent arg0) { 
     jmv.setDisplayPositionByLatLon(lat+0.01, lon, zoom) 
     jmv.invalidate(); 
    } 
}); 

但我不知道如何获取地图中心的当前纬度/经度值。我如何获得它们?

回答

2

看看JMapViewer有一个名为getPosition()的方法,可以给你当前的地图中心。

来源:https://github.com/balloob/JMapViewer/blob/master/org/openstreetmap/gui/jmapviewer/JMapViewer.java

/** 
    * Calculates the latitude/longitude coordinate of the center of the 
    * currently displayed map area. 
    * 
    * @return latitude/longitude 
    */ 
    public Coordinate getPosition() { 
     double lon = OsmMercator.XToLon(center.x, zoom); 
     double lat = OsmMercator.YToLat(center.y, zoom); 
     return new Coordinate(lat, lon); 
    }