Changeset 16459 in osm


Ignore:
Timestamp:
2009-07-12T20:27:28+02:00 (15 years ago)
Author:
dhansen
Message:

Centralize the checking of the zoom level preferences. This
also gives a convenient helper for when it is OK to zoom
or not.

File:
1 edited

Legend:

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

    r16458 r16459  
    180180     * @return  true, if zoom increasing was successfull, false othervise
    181181     */
    182     public boolean increaseZoomLevel() {
    183         if (currentZoomLevel < SlippyMapPreferences.getMaxZoomLvl()) {
     182    public boolean zoomIncreaseAllowed()
     183        {
     184        return currentZoomLevel < SlippyMapPreferences.getMaxZoomLvl();
     185        }
     186        public boolean increaseZoomLevel() {
     187                if (zoomIncreaseAllowed()) {
    184188            currentZoomLevel++;
    185189            Main.debug("increasing zoom level to: " + currentZoomLevel);
     
    198202     * @return  true, if zoom increasing was successfull, false othervise
    199203     */
    200     public boolean decreaseZoomLevel() {
    201         if (currentZoomLevel > SlippyMapPreferences.getMinZoomLvl()) {
     204    public boolean zoomDecreaseAllowed()
     205        {
     206        return currentZoomLevel > SlippyMapPreferences.getMinZoomLvl();
     207        }
     208        public boolean decreaseZoomLevel() {
     209                int minZoom = SlippyMapPreferences.getMinZoomLvl();
     210                if (zoomDecreaseAllowed()) {
    202211            Main.debug("decreasing zoom level to: " + currentZoomLevel);
    203212            currentZoomLevel--;
    204213            needRedraw = true;
    205214        } else {
    206             System.err.println("current zoom lvl couldnt be decreased. MinZoomLvl reached.");
     215            System.err.println("current zoom lvl couldnt be decreased. MinZoomLvl("+minZoom+") reached.");
    207216            return false;
    208217        }
     
    213222        // when max zoom lvl is begin saved, this method is called and probably
    214223        // the setting isnt saved yet.
    215         int maxZoom = 30; // SlippyMapPreferences.getMaxZoomLvl();
     224        int maxZoom = SlippyMapPreferences.getMaxZoomLvl();
    216225        tileStorage = new Hashtable<SlippyMapKey, SlippyMapTile>();
    217 
    218226        checkTileStorage();
    219227    }
     
    518526        {
    519527            List<Tile> ret = new ArrayList<Tile>();
     528                        int tileMax = (int)Math.pow(2.0, zoom);
    520529            for (int x = z12x0 - 1; x <= z12x1 + 1; x++) {
    521530                if (x < 0)
     
    524533                    if (y < 0)
    525534                        continue;
    526                     Tile t = new Tile(x, y);
     535                    Tile t = new Tile(x % tileMax, y % tileMax);
    527536                    ret.add(t);
    528537                }
     
    575584                int zoom = currentZoomLevel;
    576585
    577                 if (ts.tilesSpanned() > (18*18)) {
    578                         System.out.println("too many tiles, decreasing zoom from " + currentZoomLevel);
     586                if (zoomDecreaseAllowed() && (ts.tilesSpanned() > (18*18))) {
     587                        this.debug("too many tiles, decreasing zoom from " + currentZoomLevel);
    579588            if (decreaseZoomLevel())
    580589                                this.paint(oldg, mv);
    581             return;
    582             }
    583                
    584                 if (ts.tilesSpanned() <= 0) {
    585                         System.out.println("doesn't even cover one tile, increasing zoom from " + currentZoomLevel);
     590                        return;
     591                }
     592                if (zoomIncreaseAllowed() && (ts.tilesSpanned() <= 0)) {
     593                        this.debug("doesn't even cover one tile (" + ts.tilesSpanned()
     594                                           + "), increasing zoom from " + currentZoomLevel);
    586595            if (increaseZoomLevel())
    587596                 this.paint(oldg, mv);
     
    638647                        // If each source image pixel is being stretched into > 3
    639648                        // drawn pixels, zoom in... getting too pixelated
    640                         if (imageScale > 3) {
     649                        if (imageScale > 3 && zoomIncreaseAllowed()) {
    641650                                if (SlippyMapPreferences.getAutozoom()) {
    642651                                        Main.debug("autozoom increase: scale: " + imageScale);
     
    648657                        // If each source image pixel is being squished into > 0.32
    649658                        // of a drawn pixels, zoom out.
    650                         if (imageScale < 0.32) {
     659                        if ((imageScale < 0.32) && (imageScale > 0) && zoomDecreaseAllowed()) {
    651660                                if (SlippyMapPreferences.getAutozoom()) {
    652661                                        Main.debug("autozoom decrease: scale: " + imageScale);
Note: See TracChangeset for help on using the changeset viewer.