Пример #1
0
 /** Sets the displayed map pane and zoom level so that all map markers are visible. */
 public void setDisplayToFitMapRectangle() {
   if (mapRectangleList == null || mapRectangleList.size() == 0) {
     return;
   }
   int x_min = Integer.MAX_VALUE;
   int y_min = Integer.MAX_VALUE;
   int x_max = Integer.MIN_VALUE;
   int y_max = Integer.MIN_VALUE;
   int mapZoomMax = tileController.getTileSource().getMaxZoom();
   for (MapRectangle rectangle : mapRectangleList) {
     x_max = Math.max(x_max, OsmMercator.LonToX(rectangle.getBottomRight().getLon(), mapZoomMax));
     y_max = Math.max(y_max, OsmMercator.LatToY(rectangle.getTopLeft().getLat(), mapZoomMax));
     x_min = Math.min(x_min, OsmMercator.LonToX(rectangle.getTopLeft().getLon(), mapZoomMax));
     y_min = Math.min(y_min, OsmMercator.LatToY(rectangle.getBottomRight().getLat(), mapZoomMax));
   }
   int height = Math.max(0, getHeight());
   int width = Math.max(0, getWidth());
   // System.out.println(x_min + " < x < " + x_max);
   // System.out.println(y_min + " < y < " + y_max);
   // System.out.println("tiles: " + width + " " + height);
   int newZoom = mapZoomMax;
   int x = x_max - x_min;
   int y = y_max - y_min;
   while (x > width || y > height) {
     // System.out.println("zoom: " + zoom + " -> " + x + " " + y);
     newZoom--;
     x >>= 1;
     y >>= 1;
   }
   x = x_min + (x_max - x_min) / 2;
   y = y_min + (y_max - y_min) / 2;
   int z = 1 << (mapZoomMax - newZoom);
   x /= z;
   y /= z;
   setDisplayPosition(x, y, newZoom);
 }
Пример #2
0
 public void setDisplayPosition(int x, int y, int zoom) {
   setDisplayPosition(new Point(getWidth() / 2, getHeight() / 2), x, y, zoom);
 }
Пример #3
0
 /**
  * Changes the map pane so that the specified coordinate at the given zoom level is displayed on
  * the map at the screen coordinate <code>mapPoint</code>.
  *
  * @param mapPoint point on the map denoted in pixels where the coordinate should be set
  * @param lat latitude of the specified coordinate
  * @param lon longitude of the specified coordinate
  * @param zoom {@link #MIN_ZOOM} <= zoom level <= {@link TileSource#getMaxZoom()}
  */
 public void setDisplayPositionByLatLon(Point mapPoint, double lat, double lon, int zoom) {
   int x = OsmMercator.LonToX(lon, zoom);
   int y = OsmMercator.LatToY(lat, zoom);
   setDisplayPosition(mapPoint, x, y, zoom);
 }