I have a JMapViewer
as a panel on a JFrame
and a Button. If i press the Button, I want the JMapViewer
to show a scrolled map excerpt.
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.
Source: 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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.