Changeset 8751 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2015-09-12T01:06:10+02:00 (9 years ago)
Author:
wiktorn
Message:

Introduce zoom offseting. See: #11856

  • MemoryTileCache size based on ZOOM_OFFSET
  • getBestZoom called on every paint, as cost of callign getBestZoom is neglible and clarifies the code
  • use ZOOM_OFFSET to choose higher or lower zoom levels
  • provide settings panel for ZOOM_OFFSET control
Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

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

    r8729 r8751  
    135135
    136136    /**
     137     * Offset between calculated zoom level and zoom level used to download and show tiles. Negative values will result in
     138     * lower resolution of imagery useful in "retina" displays, positive values will result in higher resolution
     139     */
     140    public static final IntegerProperty ZOOM_OFFSET = new IntegerProperty(PREFERENCE_PREFIX + ".zoom_offset", 0);
     141
     142    /**
    137143     * use fairly small memory cache, as cached objects are quite big, as they contain BufferedImages
    138144     */
    139     public static final IntegerProperty MEMORY_CACHE_SIZE = new IntegerProperty(PREFERENCE_PREFIX + "cache.max_objects_ram", 200);
     145    public static final IntegerProperty MEMORY_CACHE_SIZE = new IntegerProperty(PREFERENCE_PREFIX + ".cache.max_objects_ram", (int)Math.max(200,  200 * Math.pow(4, ZOOM_OFFSET.get())));
    140146
    141147    /*
     
    280286    protected int getBestZoom() {
    281287        double factor = getScaleFactor(1); // check the ratio between area of tilesize at zoom 1 to current view
    282         double result = Math.log(factor)/Math.log(2)/2+1;
     288        double result = Math.log(factor)/Math.log(2)/2;
    283289        /*
    284290         * Math.log(factor)/Math.log(2) - gives log base 2 of factor
    285291         * We divide result by 2, as factor contains ratio between areas. We could do Math.sqrt before log, or just divide log by 2
    286          * In general, smaller zoom levels are more readable.  We prefer big,
    287          * block, pixelated (but readable) map text to small, smeared,
    288          * unreadable underzoomed text.  So, use .floor() instead of rounding
    289          * to skew things a bit toward the lower zooms.
    290          * Remember, that result here, should correspond to TMSLayer.paint(...)
    291          * getScaleFactor(...) is supposed to be between 0.75 and 3
     292         *
     293         * ZOOM_OFFSET controls, whether we work with overzoomed or underzoomed tiles. Positive ZOOM_OFFSET
     294         * is for working with underzoomed tiles (higher quality when working with aerial imagery), negative ZOOM_OFFSET
     295         * is for working with overzoomed tiles (big, pixelated), which is good when working with high-dpi screens and/or
     296         * maps as a imagery layer
    292297         */
    293         int intResult = (int) Math.floor(result);
    294         if (intResult > getMaxZoomLvl())
    295             return getMaxZoomLvl();
    296         if (intResult < getMinZoomLvl())
    297             return getMinZoomLvl();
     298
     299        int intResult = (int) Math.round(result + 1 + ZOOM_OFFSET.get() / 1.9);
     300
     301        intResult = Math.min(intResult, getMaxZoomLvl());
     302        intResult = Math.max(intResult, getMinZoomLvl());
    298303        return intResult;
    299304    }
     
    11921197
    11931198        private boolean tooLarge() {
    1194             return this.tilesSpanned() > 10;
     1199            return this.tilesSpanned() > 20;
    11951200        }
    11961201
     
    13741379        int zoom = currentZoomLevel;
    13751380        if (autoZoom) {
    1376             double pixelScaling = getScaleFactor(zoom);
    1377             if (pixelScaling > 3 || pixelScaling < 0.7) {
    1378                 zoom = getBestZoom();
    1379             }
     1381            zoom = getBestZoom();
    13801382        }
    13811383
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/CommonSettingsPanel.java

    r8598 r8751  
    2020import org.openstreetmap.josm.data.imagery.CachedTileLoaderFactory;
    2121import org.openstreetmap.josm.gui.layer.AbstractCachedTileSourceLayer;
     22import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer;
    2223import org.openstreetmap.josm.gui.layer.ImageryLayer;
    2324import org.openstreetmap.josm.gui.widgets.JosmComboBox;
     
    3940    private final JSpinner maxElementsOnDisk;
    4041    private final JSpinner maxElementsInRam;
     42    private final JSlider tilesZoom = new JSlider(-2, 2, 0);
    4143
    4244
     
    99101        add(GBC.glue(5, 0), GBC.std());
    100102        add(this.maxElementsInRam, GBC.eol());
     103
     104        this.tilesZoom.setPaintLabels(true);
     105        this.tilesZoom.setMajorTickSpacing(2);
     106        this.tilesZoom.setMinorTickSpacing(1);
     107        this.tilesZoom.setPaintTicks(true);
     108        add(new JLabel(tr("Tiles zoom offset:")));
     109        add(GBC.glue(5, 0), GBC.std());
     110        add(this.tilesZoom, GBC.eol());
    101111    }
    102112
     
    113123        this.maxElementsOnDisk.setValue(AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.get());
    114124        this.maxElementsInRam.setValue(AbstractCachedTileSourceLayer.MEMORY_CACHE_SIZE.get());
    115 
     125        this.tilesZoom.setValue(AbstractTileSourceLayer.ZOOM_OFFSET.get());
    116126    }
    117127
     
    124134        ImageryLayer.PROP_FADE_COLOR.put(this.btnFadeColor.getBackground());
    125135        ImageryLayer.PROP_SHARPEN_LEVEL.put(sharpen.getSelectedIndex());
     136
    126137        boolean restartRequired = false;
    127138        if (!AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.get().equals(this.maxElementsOnDisk.getValue())) {
     
    138149        if (!AbstractCachedTileSourceLayer.MEMORY_CACHE_SIZE.get().equals(this.maxElementsInRam.getValue())) {
    139150            AbstractCachedTileSourceLayer.MEMORY_CACHE_SIZE.put((Integer) this.maxElementsInRam.getValue());
     151            restartRequired = true;
    140152        }
    141153
    142 
     154        if (!AbstractTileSourceLayer.ZOOM_OFFSET.get().equals(this.tilesZoom.getValue())) {
     155            // TODO: make warning about too small MEMORY_CACHE_SIZE?
     156            AbstractTileSourceLayer.ZOOM_OFFSET.put(this.tilesZoom.getValue());
     157            restartRequired = true;
     158        }
    143159        return restartRequired;
    144160    }
Note: See TracChangeset for help on using the changeset viewer.