[英]Scrolling JMapViewer map programmatically
I have a JMapViewer
as a panel on a JFrame
and a Button. 我有一个JMapViewer
作为JFrame
和Button上的面板。 If i press the Button, I want the JMapViewer
to show a scrolled map excerpt. 如果按下按钮,则希望JMapViewer
显示滚动的地图摘录。
I've trying to set another display position by lat/lon but I dont know how to obtain the old mapcentered lat/lon values..? 我试图通过纬度/经度设置另一个显示位置,但是我不知道如何获取旧的以地图为中心的纬度/经度值。
My Button Actionlistener, which should show a slightly up moved map excerpt: 我的按钮动作侦听器,应显示略微向上移动的地图摘录:
btn_PanUp.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
jmv.setDisplayPositionByLatLon(lat+0.01, lon, zoom)
jmv.invalidate();
}
});
But I don't know how to obtain the current lat/lon values of the map center. 但是我不知道如何获取地图中心的当前纬度/经度值。 How do I obtain them? 我如何获得它们?
Looking at JMapViewer there is method named getPosition()
which gives you the current map center. 查看JMapViewer,有一个名为getPosition()
方法可为您提供当前地图中心。
Source: https://github.com/balloob/JMapViewer/blob/master/org/openstreetmap/gui/jmapviewer/JMapViewer.java 来源: 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.