1

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
MojioMS
  • 1,583
  • 4
  • 17
  • 42

1 Answers1

2

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);
    }
jzd
  • 23,473
  • 9
  • 54
  • 76