Beispiel #1
0
 /**
  * Every time the zoom level changes this method is called. Override it in derived implementations
  * for adapting zoom dependent values. The new zoom level can be obtained via {@link #getZoom()}.
  *
  * @param oldZoom the previous zoom level
  */
 protected void zoomChanged(int oldZoom) {
   zoomSlider.setToolTipText("Zoom level " + zoom);
   zoomInButton.setToolTipText("Zoom to level " + (zoom + 1));
   zoomOutButton.setToolTipText("Zoom to level " + (zoom - 1));
   zoomOutButton.setEnabled(zoom > tileController.getTileSource().getMinZoom());
   zoomInButton.setEnabled(zoom < tileController.getTileSource().getMaxZoom());
   fireMapViewChanged();
 }
Beispiel #2
0
 public void setZoom(int zoom, Point mapPoint) {
   if (zoom > tileController.getTileSource().getMaxZoom()
       || zoom < tileController.getTileSource().getMinZoom()
       || zoom == this.zoom) return;
   Coordinate zoomPos = getPosition(mapPoint);
   tileController.cancelOutstandingJobs(); // Clearing outstanding load
   // requests
   setDisplayPositionByLatLon(mapPoint, zoomPos.getLat(), zoomPos.getLon(), zoom);
 }
Beispiel #3
0
  protected void initializeZoomSlider() {
    zoomSlider = new JSlider(MIN_ZOOM, tileController.getTileSource().getMaxZoom());
    zoomSlider.setOrientation(JSlider.VERTICAL);
    zoomSlider.setBounds(10, 10, 30, 150);
    zoomSlider.setOpaque(false);
    zoomSlider.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            setZoom(zoomSlider.getValue());
          }
        });
    add(zoomSlider);
    int size = 18;
    try {
      ImageIcon icon = new ImageIcon(getClass().getResource("images/plus.png"));
      zoomInButton = new JButton(icon);
    } catch (Exception e) {
      zoomInButton = new JButton("+");
      zoomInButton.setFont(new Font("sansserif", Font.BOLD, 9));
      zoomInButton.setMargin(new Insets(0, 0, 0, 0));
    }
    zoomInButton.setBounds(4, 155, size, size);
    zoomInButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            zoomIn();
          }
        });
    add(zoomInButton);
    try {
      ImageIcon icon = new ImageIcon(getClass().getResource("images/minus.png"));
      zoomOutButton = new JButton(icon);
    } catch (Exception e) {
      zoomOutButton = new JButton("-");
      zoomOutButton.setFont(new Font("sansserif", Font.BOLD, 9));
      zoomOutButton.setMargin(new Insets(0, 0, 0, 0));
    }
    zoomOutButton.setBounds(8 + size, 155, size, size);
    zoomOutButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            zoomOut();
          }
        });
    add(zoomOutButton);
  }
Beispiel #4
0
  public void setDisplayPosition(Point mapPoint, int x, int y, int zoom) {
    if (zoom > tileController.getTileSource().getMaxZoom() || zoom < MIN_ZOOM) return;

    // Get the plain tile number
    Point p = new Point();
    p.x = x - mapPoint.x + getWidth() / 2;
    p.y = y - mapPoint.y + getHeight() / 2;
    center = p;
    setIgnoreRepaint(true);
    try {
      int oldZoom = this.zoom;
      this.zoom = zoom;
      if (oldZoom != zoom) zoomChanged(oldZoom);
      if (zoomSlider.getValue() != zoom) zoomSlider.setValue(zoom);
    } finally {
      setIgnoreRepaint(false);
      repaint();
    }
  }
Beispiel #5
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);
 }