Changeset 16157 in osm for applications/editors/josm


Ignore:
Timestamp:
2009-06-26T21:00:40+02:00 (15 years ago)
Author:
lvarga
Message:

Another 3 patches from Dave Hansen <dave@…>. For more info look at previouse log.

This is helpful for debugging or if you just want to
reload all the tiles

I got into a few loops where zooms were in strange states
and got stuck. This keeps us from retrying things that
are futile, like zooming out continuously.

The reason for this will become apparent in a moment, but
I want to be able to do these calculations for zooms other
than the current one.

6 of 14 patches added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/slippymap/src/org/openstreetmap/josm/plugins/slippymap/SlippyMapLayer.java

    r16153 r16157  
    127127                    }
    128128                }));
     129       
     130        tileOptionMenu.add(new JMenuItem(
     131                        new AbstractAction(tr("Flush Tile Cache")) {
     132                                public void actionPerformed(ActionEvent ae) {
     133                                        System.out.print("flushing all tiles...");
     134                                        for (SlippyMapTile t : tileStorage.values()) {
     135                                                t.dropImage();
     136                                                }
     137                                        System.out.println("done");
     138                                        }
     139                                }));
    129140        // end of adding menu commands
    130141
     
    161172    /**
    162173     * Zoom in, go closer to map.
     174     *
     175     * @return  true, if zoom increasing was successfull, false othervise
    163176     */
    164     public void increaseZoomLevel() {
     177    public boolean increaseZoomLevel() {
    165178        if (currentZoomLevel < SlippyMapPreferences.getMaxZoomLvl()) {
    166179            currentZoomLevel++;
     
    170183            System.err.println("current zoom lvl ("+currentZoomLevel+") couldnt be increased. "+
    171184                             "MaxZoomLvl ("+SlippyMapPreferences.getMaxZoomLvl()+") reached.");
    172         }
     185            return false;
     186            }
     187        return true;
    173188    }
    174189
    175190    /**
    176191     * Zoom out from map.
     192     *
     193     * @return  true, if zoom increasing was successfull, false othervise
    177194     */
    178     public void decreaseZoomLevel() {
     195    public boolean decreaseZoomLevel() {
    179196        if (currentZoomLevel > SlippyMapPreferences.getMinZoomLvl()) {
    180197            Main.debug("decreasing zoom level to: " + currentZoomLevel);
     
    183200        } else {
    184201            System.err.println("current zoom lvl couldnt be decreased. MinZoomLvl reached.");
    185         }
     202            return false;
     203        }
     204        return true;
    186205    }
    187206
     
    249268    void loadAllTiles() {
    250269        MapView mv = Main.map.mapView;
     270        int zoom = currentZoomLevel;
    251271        LatLon topLeft = mv.getLatLon(0, 0);
    252272        LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight());
    253         z12x0 = lonToTileX(topLeft.lon());
    254         z12x1 = lonToTileX(botRight.lon());
    255         z12y0 = latToTileY(topLeft.lat());
    256         z12y1 = latToTileY(botRight.lat());
     273        z12x0 = lonToTileX(topLeft.lon(), zoom);
     274        z12x1 = lonToTileX(botRight.lon(), zoom);
     275        z12y0 = latToTileY(topLeft.lat(), zoom);
     276        z12y1 = latToTileY(botRight.lat(), zoom);
    257277        if (z12x0 > z12x1) {
    258278            int tmp = z12x0;
     
    365385        g = bufferImage.getGraphics();
    366386
    367         z12x0 = lonToTileX(topLeft.lon());
    368         z12x1 = lonToTileX(botRight.lon());
    369         z12y0 = latToTileY(topLeft.lat());
    370         z12y1 = latToTileY(botRight.lat());
     387        int zoom = currentZoomLevel;
     388        z12x0 = lonToTileX(topLeft.lon(), zoom);
     389        z12x1 = lonToTileX(botRight.lon(), zoom);
     390        z12y0 = latToTileY(topLeft.lat(), zoom);
     391        z12y1 = latToTileY(botRight.lat(), zoom);
    371392
    372393        if (z12x0 > z12x1) {
     
    387408
    388409        for (int x = z12x0 - 1; x <= z12x1 + 1; x++) {
    389             double lon = tileXToLon(x);
     410            double lon = tileXToLon(x, zoom);
    390411            for (int y = z12y0 - 1; y <= z12y1 + 1; y++) {
    391                 LatLon tmpLL = new LatLon(tileYToLat(y), lon);
     412                LatLon tmpLL = new LatLon(tileYToLat(y, zoom), lon);
    392413                pixelpos[x - z12x0 + 1][y - z12y0 + 1] = mv.getPoint(Main.proj
    393414                        .latlon2eastNorth(tmpLL));
     
    605626    }
    606627
    607     private int latToTileY(double lat) {
     628    private int latToTileY(double lat, int zoom) {
    608629        double l = lat / 180 * Math.PI;
    609630        double pf = Math.log(Math.tan(l) + (1 / Math.cos(l)));
    610         return (int) (Math.pow(2.0, currentZoomLevel - 1) * (Math.PI - pf) / Math.PI);
    611     }
    612 
    613     private int lonToTileX(double lon) {
    614         return (int) (Math.pow(2.0, currentZoomLevel - 3) * (lon + 180.0) / 45.0);
    615     }
    616 
    617     private double tileYToLat(int y) {
     631        return (int) (Math.pow(2.0, zoom - 1) * (Math.PI - pf) / Math.PI);
     632    }
     633
     634    private int lonToTileX(double lon, int zoom) {
     635        return (int) (Math.pow(2.0, zoom - 3) * (lon + 180.0) / 45.0);
     636    }
     637
     638    private double tileYToLat(int y, int zoom) {
    618639        return Math.atan(Math.sinh(Math.PI
    619                 - (Math.PI * y / Math.pow(2.0, currentZoomLevel - 1))))
     640                        - (Math.PI * y / Math.pow(2.0, zoom - 1))))
    620641                * 180 / Math.PI;
    621642    }
    622643
    623     private double tileXToLon(int x) {
    624         return x * 45.0 / Math.pow(2.0, currentZoomLevel - 3) - 180.0;
     644    private double tileXToLon(int x, int zoom) {
     645        return x * 45.0 / Math.pow(2.0, zoom - 3) - 180.0;
    625646    }
    626647
Note: See TracChangeset for help on using the changeset viewer.