Changeset 3787 in josm


Ignore:
Timestamp:
2011-01-13T18:00:36+01:00 (14 years ago)
Author:
Upliner
Message:

Another rework of autozoom algorithm, fixes flicker when zooming in.

Also uses binary search of neccecary zoomlevel when downloading instead of linear one.
Has less code, more comments and more comprehensible at all.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r3785 r3787  
    10211021    private class DeepTileSet {
    10221022        final EastNorth topLeft, botRight;
    1023         final int minZoom;
     1023        final int minZoom, maxZoom;
    10241024        private final TileSet[] tileSets;
    10251025        private final TileSetInfo[] tileSetInfos;
     
    10281028            this.botRight = botRight;
    10291029            this.minZoom = minZoom;
     1030            this.maxZoom = maxZoom;
    10301031            this.tileSets = new TileSet[maxZoom - minZoom + 1];
    10311032            this.tileSetInfos = new TileSetInfo[maxZoom - minZoom + 1];
     
    10771078        }
    10781079
    1079         DeepTileSet dts = new DeepTileSet(topLeft, botRight, getMinZoomLvl(), getMaxZoomLvl());
     1080        DeepTileSet dts = new DeepTileSet(topLeft, botRight, getMinZoomLvl(), zoom);
    10801081        TileSet ts = dts.getTileSet(zoom);
    10811082
     
    10891090                noTilesAtZoom = true;
    10901091            }
    1091             if (!tsi.hasVisibleTiles && tsi.hasOverzoomedTiles) {
    1092                 while (displayZoomLevel > dts.minZoom && !tsi.hasVisibleTiles && tsi.hasOverzoomedTiles){
    1093                     displayZoomLevel--;
    1094                     tsi = dts.getTileSetInfo(displayZoomLevel);
    1095                 }
    1096                 if (zoom > displayZoomLevel && !dts.getTileSetInfo(displayZoomLevel+1).hasLoadingTiles) {
    1097                     zoom = displayZoomLevel+1;
    1098                 } else {
    1099                     zoom = displayZoomLevel;
    1100                 }
    1101                 while (displayZoomLevel >= dts.minZoom && !tsi.hasVisibleTiles){
    1102                     displayZoomLevel--;
    1103                     tsi = dts.getTileSetInfo(displayZoomLevel);
    1104                 }
    1105                 if (displayZoomLevel < dts.minZoom) {
    1106                     displayZoomLevel = 0;
    1107                 }
     1092            // Find highest zoom level with at least one visible tile
     1093            while (displayZoomLevel > dts.minZoom &&
     1094                    !dts.getTileSetInfo(displayZoomLevel).hasVisibleTiles) {
     1095                displayZoomLevel--;
     1096            }
     1097            // Do binary search between currentZoomLevel and displayZoomLevel
     1098            while (zoom > displayZoomLevel && !tsi.hasVisibleTiles && tsi.hasOverzoomedTiles){
     1099                zoom = (zoom + displayZoomLevel)/2;
    11081100                tsi = dts.getTileSetInfo(zoom);
    11091101            }
     1102
    11101103            setZoomLevel(zoom);
     1104
     1105            // If all tiles at displayZoomLevel is loaded, load all tiles at next zoom level
     1106            // to make sure there're really no more zoom levels
     1107            if (zoom == displayZoomLevel && !tsi.hasLoadingTiles && zoom < dts.maxZoom) {
     1108                zoom++;
     1109                tsi = dts.getTileSetInfo(zoom);
     1110            }
    11111111            // When we have overzoomed tiles and all tiles at current zoomlevel is loaded,
    11121112            // load tiles at previovus zoomlevels until we have all tiles on screen is loaded.
Note: See TracChangeset for help on using the changeset viewer.