Skip to content

Commit

Permalink
MapPanel code - fix
Browse files Browse the repository at this point in the history
  • Loading branch information
makaw committed Dec 31, 2019
1 parent 9396645 commit 087a5fd
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/main/java/gui/mapview/MapPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
@SuppressWarnings("serial")
public class MapPanel extends JXMapKit {

private final JXMapViewer map = getMainMap();

/**
* Konstruktor
Expand Down Expand Up @@ -71,7 +72,7 @@ public String getTileUrl(int x, int y, int zoom) {
gbc.gridheight = 1;
gbc.anchor = GridBagConstraints.NORTHEAST;

getMainMap().add(new OSMCreditPanel(), gbc);
map.add(new OSMCreditPanel(), gbc);

}

Expand All @@ -85,7 +86,7 @@ public String getTileUrl(int x, int y, int zoom) {
public void setAddressPoint(GeoPosition point) {

setAddressLocation(point);
getMainMap().setZoom(5);
map.setZoom(5);

}

Expand Down Expand Up @@ -122,29 +123,27 @@ public <T extends IAddressPoint> void setRoute(List<T> routePoints) {

}

pos.add(new GeoPosition(routePoints.get(0).getCustomerLatitude(), routePoints.get(0).getCustomerLongitude()));

finishRoute(painters, pos);
CompoundPainter<JXMapViewer> painter = new CompoundPainter<>(painters);
map.setOverlayPainter(painter);

zoomToBestFitOnLoad(pos, 0.7);

}




private void finishRoute(List<Painter<JXMapViewer>> painters, Set<GeoPosition> pos) {

CompoundPainter<JXMapViewer> painter = new CompoundPainter<>(painters);
getMainMap().setOverlayPainter(painter);

private void zoomToBestFitOnLoad(Set<GeoPosition> pos, double maxFraction) {

ComponentListener listener = new ComponentListener() {

@Override
public void componentShown(ComponentEvent arg0) {}

@Override
public void componentResized(ComponentEvent arg0) {
getMainMap().zoomToBestFit(pos, 0.7);
getMainMap().removeComponentListener(this);
map.zoomToBestFit(pos, maxFraction);
map.removeComponentListener(this);
}

@Override
Expand All @@ -154,7 +153,7 @@ public void componentHidden(ComponentEvent e) {}
public void componentMoved(ComponentEvent e) {}
};

getMainMap().addComponentListener(listener);
map.addComponentListener(listener);

}

Expand Down

0 comments on commit 087a5fd

Please sign in to comment.