[英]Scrolling JMapViewer map programmatically
我有一個JMapViewer
作為JFrame
和Button上的面板。 如果按下按鈕,則希望JMapViewer
顯示滾動的地圖摘錄。
我試圖通過緯度/經度設置另一個顯示位置,但是我不知道如何獲取舊的以地圖為中心的緯度/經度值。
我的按鈕動作偵聽器,應顯示略微向上移動的地圖摘錄:
btn_PanUp.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
jmv.setDisplayPositionByLatLon(lat+0.01, lon, zoom)
jmv.invalidate();
}
});
但是我不知道如何獲取地圖中心的當前緯度/經度值。 我如何獲得它們?
查看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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.