Ignore:
Timestamp:
2008-08-12T14:16:26+02:00 (17 years ago)
Author:
stotz
Message:

new method: zoomChanged()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/JMapViewer.java

    r9619 r9713  
    4343         * Vectors for clock-wise tile painting
    4444         */
    45         protected static final Point[] move = { new Point(1, 0), new Point(0, 1),
    46                         new Point(-1, 0), new Point(0, -1) };
     45        protected static final Point[] move =
     46                        { new Point(1, 0), new Point(0, 1), new Point(-1, 0), new Point(0, -1) };
    4747
    4848        public static final int MAX_ZOOM = 18;
     
    102102                setPreferredSize(new Dimension(400, 400));
    103103                try {
    104                         loadingImage = ImageIO.read(JMapViewer.class
    105                                         .getResourceAsStream("images/hourglass.png"));
     104                        loadingImage =
     105                                        ImageIO.read(JMapViewer.class.getResourceAsStream("images/hourglass.png"));
    106106                } catch (Exception e1) {
    107107                        loadingImage = null;
     
    123123                int size = 18;
    124124                try {
    125                         ImageIcon icon = new ImageIcon(getClass().getResource(
    126                                         "images/plus.png"));
     125                        ImageIcon icon = new ImageIcon(getClass().getResource("images/plus.png"));
    127126                        zoomInButton = new JButton(icon);
    128127                } catch (Exception e) {
     
    140139                add(zoomInButton);
    141140                try {
    142                         ImageIcon icon = new ImageIcon(getClass().getResource(
    143                                         "images/minus.png"));
     141                        ImageIcon icon = new ImageIcon(getClass().getResource("images/minus.png"));
    144142                        zoomOutButton = new JButton(icon);
    145143                } catch (Exception e) {
     
    170168         */
    171169        public void setDisplayPositionByLatLon(double lat, double lon, int zoom) {
    172                 setDisplayPositionByLatLon(new Point(getWidth() / 2, getHeight() / 2),
    173                                 lat, lon, zoom);
     170                setDisplayPositionByLatLon(new Point(getWidth() / 2, getHeight() / 2), lat, lon, zoom);
    174171        }
    175172
     
    189186         *            {@link #MIN_ZOOM} <= zoom level <= {@link #MAX_ZOOM}
    190187         */
    191         public void setDisplayPositionByLatLon(Point mapPoint, double lat,
    192                         double lon, int zoom) {
     188        public void setDisplayPositionByLatLon(Point mapPoint, double lat, double lon, int zoom) {
    193189                int x = OsmMercator.LonToX(lon, zoom);
    194190                int y = OsmMercator.LatToY(lat, zoom);
     
    197193
    198194        public void setDisplayPosition(int x, int y, int zoom) {
    199                 setDisplayPosition(new Point(getWidth() / 2, getHeight() / 2), x, y,
    200                                 zoom);
     195                setDisplayPosition(new Point(getWidth() / 2, getHeight() / 2), x, y, zoom);
    201196        }
    202197
     
    210205                p.y = y - mapPoint.y + getHeight() / 2;
    211206                center = p;
    212                 this.zoom = zoom;
    213                 if (zoomSlider.getValue() != zoom)
    214                         zoomSlider.setValue(zoom);
    215                 repaint();
     207                setIgnoreRepaint(true);
     208                try {
     209                        int oldZoom = this.zoom;
     210                        this.zoom = zoom;
     211                        if (oldZoom != zoom)
     212                                zoomChanged(oldZoom);
     213                        if (zoomSlider.getValue() != zoom)
     214                                zoomSlider.setValue(zoom);
     215                } finally {
     216                        setIgnoreRepaint(false);
     217                        repaint();
     218                }
    216219        }
    217220
     
    240243                // System.out.println(y_min + " < y < " + y_max);
    241244                // System.out.println("tiles: " + width + " " + height);
    242                 int zoom = MAX_ZOOM;
     245                int newZoom = MAX_ZOOM;
    243246                int x = x_max - x_min;
    244247                int y = y_max - y_min;
    245248                while (x > width || y > height) {
    246249                        // System.out.println("zoom: " + zoom + " -> " + x + " " + y);
    247                         zoom--;
     250                        newZoom--;
    248251                        x >>= 1;
    249252                        y >>= 1;
     
    251254                x = x_min + (x_max - x_min) / 2;
    252255                y = y_min + (y_max - y_min) / 2;
    253                 int z = 1 << (MAX_ZOOM - zoom);
     256                int z = 1 << (MAX_ZOOM - newZoom);
    254257                x /= z;
    255258                y /= z;
    256                 setDisplayPosition(x, y, zoom);
     259                setDisplayPosition(x, y, newZoom);
    257260        }
    258261
     
    334337                                        x++;
    335338                                for (int z = 0; z < x; z++) {
    336                                         if (x_min <= posx && posx <= x_max && y_min <= posy
    337                                                         && posy <= y_max) { // tile
     339                                        if (x_min <= posx && posx <= x_max && y_min <= posy && posy <= y_max) { // tile
    338340                                                // is
    339341                                                // visible
     
    419421                        return;
    420422                Point2D.Double zoomPos = getPosition(mapPoint);
    421                 // addMapMarker(new MapMarkerDot(Color.RED, zoomPos.x, zoomPos.y));
    422423                jobDispatcher.cancelOutstandingJobs(); // Clearing outstanding load
    423424                // requests
     
    450451                }
    451452                if (!tile.isLoaded()) {
    452                         jobDispatcher.addJob(tileLoader.createTileLoaderJob(tilex, tiley,
    453                                         zoom));
     453                        jobDispatcher.addJob(tileLoader.createTileLoaderJob(tilex, tiley, zoom));
    454454                }
    455455                return tile;
     456        }
     457
     458        /**
     459         * Every time the zoom level changes this method is called. Override it in
     460         * derived implementations for adapting zoom dependent values. The new zoom
     461         * level can be obtained via {@link #getZoom()}.
     462         *
     463         * @param oldZoom
     464         *            the previous zoom level
     465         */
     466        protected void zoomChanged(int oldZoom) {
    456467        }
    457468
Note: See TracChangeset for help on using the changeset viewer.