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


Ignore:
Timestamp:
2016-02-17T23:27:47+01:00 (8 years ago)
Author:
wiktorn
Message:

Snap scale to mercator zoom levels.

See #12350

Patch submitted by: kolesar

Location:
trunk/src/org/openstreetmap/josm
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/ZoomInAction.java

    r8510 r9818  
    4747    public void actionPerformed(ActionEvent e) {
    4848        if (!Main.isDisplayingMapView()) return;
    49         Main.map.mapView.zoomToFactor(1/Math.sqrt(2));
     49        Main.map.mapView.zoomIn();
    5050    }
    5151
  • trunk/src/org/openstreetmap/josm/actions/ZoomOutAction.java

    r6380 r9818  
    3333    public void actionPerformed(ActionEvent e) {
    3434        if (!Main.isDisplayingMapView()) return;
    35         Main.map.mapView.zoomToFactor(Math.sqrt(2));
     35        Main.map.mapView.zoomOut();
    3636    }
    3737
  • trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java

    r9799 r9818  
    4747import org.openstreetmap.josm.data.projection.Projections;
    4848import org.openstreetmap.josm.gui.ExtendedDialog;
     49import org.openstreetmap.josm.gui.layer.NativeScaleLayer.Scale;
     50import org.openstreetmap.josm.gui.layer.NativeScaleLayer.ScaleList;
    4951import org.openstreetmap.josm.io.CachedFile;
    5052import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    286288    }
    287289
    288     private Collection<Layer> getCapabilities() throws IOException {
     290    private Collection<Layer> getCapabilities() {
    289291        XMLInputFactory factory = XMLInputFactory.newFactory();
    290292        // do not try to load external entities, nor validate the XML
     
    709711            return null;
    710712        }
    711         if (zoom < 1) {
     713        if (zoom < 0) {
    712714            return null;
    713715        }
    714         return this.currentTileMatrixSet.tileMatrix.get(zoom - 1);
     716        return this.currentTileMatrixSet.tileMatrix.get(zoom);
    715717    }
    716718
     
    830832    public int getMaxZoom() {
    831833        if (this.currentTileMatrixSet != null) {
    832             return this.currentTileMatrixSet.tileMatrix.size();
     834            return this.currentTileMatrixSet.tileMatrix.size()-1;
    833835        }
    834836        return 0;
     
    911913        return (int) Math.ceil(Math.abs(max.east() - min.east()) / scale);
    912914    }
     915
     916    /**
     917     * Get native scales of tile source.
     918     * @return {@link ScaleList} of native scales
     919     */
     920    public ScaleList getNativeScales() {
     921        ScaleList scales = new ScaleList();
     922        if (currentTileMatrixSet != null) {
     923            for (TileMatrix tileMatrix : currentTileMatrixSet.tileMatrix) {
     924                scales.add(new Scale(tileMatrix.scaleDenominator * 0.28e-03));
     925            }
     926        }
     927        return scales;
     928    }
     929
    913930}
  • trunk/src/org/openstreetmap/josm/gui/MapMover.java

    r8840 r9818  
    214214    @Override
    215215    public void mouseWheelMoved(MouseWheelEvent e) {
    216         nc.zoomToFactor(e.getX(), e.getY(), Math.pow(Math.sqrt(2), e.getWheelRotation()));
     216        nc.zoomManyTimes(e.getX(), e.getY(), e.getWheelRotation());
    217217    }
    218218
  • trunk/src/org/openstreetmap/josm/gui/MapSlider.java

    r8840 r9818  
    1111import javax.swing.event.ChangeListener;
    1212
    13 import org.openstreetmap.josm.data.ProjectionBounds;
    1413import org.openstreetmap.josm.gui.help.Helpful;
    1514
    1615class MapSlider extends JSlider implements PropertyChangeListener, ChangeListener, Helpful {
    1716
     17    private static final double zoomStep = 1.1;
    1818    private final MapView mv;
    1919    private boolean preventChange;
     20    private int lastValue;
    2021
    2122    MapSlider(MapView mv) {
    22         super(35, 150);
     23        super(0, 150);
    2324        setOpaque(false);
    2425        this.mv = mv;
     
    3132    @Override
    3233    public void propertyChange(PropertyChangeEvent evt) {
    33         if (getModel().getValueIsAdjusting()) return;
    34 
    35         ProjectionBounds world = this.mv.getMaxProjectionBounds();
    36         ProjectionBounds current = this.mv.getProjectionBounds();
    37 
    38         double cur_e = current.maxEast-current.minEast;
    39         double cur_n = current.maxNorth-current.minNorth;
    40         double e = world.maxEast-world.minEast;
    41         double n = world.maxNorth-world.minNorth;
    42         int zoom = 0;
    43 
    44         while (zoom <= 150) {
    45             e /= 1.1;
    46             n /= 1.1;
    47             if (e < cur_e && n < cur_n) {
    48                 break;
    49             }
    50             ++zoom;
    51         }
     34        double maxScale = this.mv.getMaxScale();
     35        int zoom = (int) Math.round(Math.log(maxScale/mv.getScale())/Math.log(zoomStep));
    5236        preventChange = true;
    5337        setValue(zoom);
     38        lastValue = zoom;
    5439        preventChange = false;
    5540    }
     
    5944        if (preventChange) return;
    6045
    61         ProjectionBounds world = this.mv.getMaxProjectionBounds();
    62         double fact = Math.pow(1.1, getValue());
    63         double es = world.maxEast-world.minEast;
    64         double n = world.maxNorth-world.minNorth;
    65 
    66         this.mv.zoomTo(new ProjectionBounds(this.mv.getCenter(), es/fact, n/fact));
     46        if (!getModel().getValueIsAdjusting() && mv.getNativeScaleLayer() != null) {
     47            if (getValue() < lastValue) {
     48                mv.zoomOut();
     49            } else if (getValue() > lastValue) {
     50                mv.zoomIn();
     51            }
     52        } else {
     53            double maxScale = this.mv.getMaxScale();
     54            double scale = maxScale/Math.pow(zoomStep, getValue());
     55            double snapped = mv.scaleFloor(scale);
     56            mv.zoomTo(this.mv.getCenter(), snapped);
     57        }
     58        propertyChange(null);
    6759    }
    6860
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r9623 r9818  
    6060import org.openstreetmap.josm.gui.layer.MapViewPaintable;
    6161import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     62import org.openstreetmap.josm.gui.layer.NativeScaleLayer;
    6263import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer;
    6364import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
     
    411412            if (isOsmDataLayer) {
    412413                ((OsmDataLayer) layer).addLayerStateChangeListener(this);
     414            }
     415
     416            if (layer instanceof NativeScaleLayer) {
     417                Main.map.mapView.setNativeScaleLayer((NativeScaleLayer) layer);
    413418            }
    414419
     
    915920     *
    916921     * @param layer the layer to be activate; must be one of the layers in the list of layers
    917      * @throws IllegalArgumentException if layer is not in the lis of layers
     922     * @throws IllegalArgumentException if layer is not in the list of layers
    918923     */
    919924    public void setActiveLayer(Layer layer) {
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r9634 r9818  
    4545import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    4646import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
     47import org.openstreetmap.josm.data.preferences.BooleanProperty;
     48import org.openstreetmap.josm.data.preferences.DoubleProperty;
    4749import org.openstreetmap.josm.data.preferences.IntegerProperty;
    4850import org.openstreetmap.josm.data.projection.Projection;
     
    5052import org.openstreetmap.josm.gui.download.DownloadDialog;
    5153import org.openstreetmap.josm.gui.help.Helpful;
     54import org.openstreetmap.josm.gui.layer.NativeScaleLayer;
     55import org.openstreetmap.josm.gui.layer.NativeScaleLayer.Scale;
     56import org.openstreetmap.josm.gui.layer.NativeScaleLayer.ScaleList;
    5257import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    5358import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
     
    9095
    9196    public static final IntegerProperty PROP_SNAP_DISTANCE = new IntegerProperty("mappaint.node.snap-distance", 10);
     97    public static final DoubleProperty PROP_ZOOM_RATIO = new DoubleProperty("zoom.ratio", 2.0);
     98    public static final BooleanProperty PROP_ZOOM_INTERMEDIATE_STEPS = new BooleanProperty("zoom.intermediate-steps", true);
    9299
    93100    public static final String PROPNAME_CENTER = "center";
    94101    public static final String PROPNAME_SCALE  = "scale";
     102
     103    /**
     104     * The layer which scale is set to.
     105     */
     106    private transient NativeScaleLayer nativeScaleLayer;
    95107
    96108    /**
     
    144156    public NavigatableComponent() {
    145157        setLayout(null);
     158        PROP_ZOOM_RATIO.get(); // make sure it is available in preferences
     159    }
     160
     161    /**
     162     * Choose a layer that scale will be snap to its native scales.
     163     * @param nativeScaleLayer layer to which scale will be snapped
     164     */
     165    public void setNativeScaleLayer(NativeScaleLayer nativeScaleLayer) {
     166        this.nativeScaleLayer = nativeScaleLayer;
     167        zoomTo(center, scaleRound(scale));
     168        repaint();
     169    }
     170
     171    /**
     172     * Replies the layer which scale is set to.
     173     * @return the current scale layer (may be null)
     174     */
     175    public NativeScaleLayer getNativeScaleLayer() {
     176        return nativeScaleLayer;
     177    }
     178
     179    /**
     180     * Get a new scale that is zoomed in from previous scale
     181     * and snapped to selected native scale layer.
     182     * @return new scale
     183     */
     184    public double scaleZoomIn() {
     185        return scaleZoomManyTimes(-1);
     186    }
     187
     188    /**
     189     * Get a new scale that is zoomed out from previous scale
     190     * and snapped to selected native scale layer.
     191     * @return new scale
     192     */
     193    public double scaleZoomOut() {
     194        return scaleZoomManyTimes(1);
     195    }
     196
     197    /**
     198     * Get a new scale that is zoomed in/out a number of times
     199     * from previous scale and snapped to selected native scale layer.
     200     * @param times count of zoom operations, negative means zoom in
     201     * @return new scale
     202     */
     203    public double scaleZoomManyTimes(int times) {
     204        if (nativeScaleLayer != null) {
     205            ScaleList scaleList = nativeScaleLayer.getNativeScales();
     206            if (PROP_ZOOM_INTERMEDIATE_STEPS.get()) {
     207                scaleList = scaleList.withIntermediateSteps(PROP_ZOOM_RATIO.get());
     208            }
     209            Scale scale = scaleList.scaleZoomTimes(getScale(), PROP_ZOOM_RATIO.get(), times);
     210            return scale.scale;
     211        } else {
     212            return getScale() * Math.pow(PROP_ZOOM_RATIO.get(), times);
     213        }
     214    }
     215
     216    /**
     217     * Get a scale snapped to native resolutions, use round method.
     218     * It gives nearest step from scale list.
     219     * Use round method.
     220     * @param scale to snap
     221     * @return snapped scale
     222     */
     223    public double scaleRound(double scale) {
     224        return scaleSnap(scale, false);
     225    }
     226
     227    /**
     228     * Get a scale snapped to native resolutions.
     229     * It gives nearest lower step from scale list, usable to fit objects.
     230     * @param scale to snap
     231     * @return snapped scale
     232     */
     233    public double scaleFloor(double scale) {
     234        return scaleSnap(scale, true);
     235    }
     236
     237    /**
     238     * Get a scale snapped to native resolutions.
     239     * It gives nearest lower step from scale list, usable to fit objects.
     240     * @param scale to snap
     241     * @param floor use floor instead of round, set true when fitting view to objects
     242     * @return new scale
     243     */
     244    public double scaleSnap(double scale, boolean floor) {
     245        if (nativeScaleLayer != null) {
     246            ScaleList scaleList = nativeScaleLayer.getNativeScales();
     247            return scaleList.getSnapScale(scale, PROP_ZOOM_RATIO.get(), floor).scale;
     248        } else {
     249            return scale;
     250        }
     251    }
     252
     253    /**
     254     * Zoom in current view. Use configured zoom step and scaling settings.
     255     */
     256    public void zoomIn() {
     257        zoomTo(center, scaleZoomIn());
     258    }
     259
     260    /**
     261     * Zoom out current view. Use configured zoom step and scaling settings.
     262     */
     263    public void zoomOut() {
     264        zoomTo(center, scaleZoomOut());
    146265    }
    147266
     
    435554            }
    436555        }
     556
     557        // snap scale to imagery if needed
     558        scale = scaleRound(scale);
    437559
    438560        if (!newCenter.equals(center) || !Utils.equalsEpsilon(scale, newScale)) {
     
    517639    }
    518640
     641    public void zoomManyTimes(double x, double y, int times) {
     642        double oldScale = scale;
     643        double newScale = scaleZoomManyTimes(times);
     644        zoomToFactor(x, y, newScale / oldScale);
     645    }
     646
    519647    public void zoomToFactor(double x, double y, double factor) {
    520648        double newScale = scale*factor;
     
    550678        double newScale = Math.max(scaleX, scaleY);
    551679
     680        newScale = scaleFloor(newScale);
    552681        zoomTo(box.getCenter(), newScale);
    553682    }
     
    15051634        repaint();
    15061635    }
     1636
     1637    /**
     1638     * Get a max scale for projection that describes world in 256 pixels
     1639     * @return max scale
     1640     */
     1641    public double getMaxScale() {
     1642        ProjectionBounds world = getMaxProjectionBounds();
     1643        return Math.max(
     1644            world.maxNorth-world.minNorth,
     1645            world.maxEast-world.minEast
     1646        )/256;
     1647    }
    15071648}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r9510 r9818  
    6060import org.openstreetmap.josm.gui.layer.Layer;
    6161import org.openstreetmap.josm.gui.layer.Layer.LayerAction;
     62import org.openstreetmap.josm.gui.layer.NativeScaleLayer;
    6263import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    6364import org.openstreetmap.josm.gui.util.GuiHelper;
     
    188189        layerList.getColumnModel().getColumn(0).setPreferredWidth(12);
    189190        layerList.getColumnModel().getColumn(0).setResizable(false);
    190         layerList.getColumnModel().getColumn(1).setCellRenderer(new LayerVisibleCellRenderer());
    191         layerList.getColumnModel().getColumn(1).setCellEditor(new LayerVisibleCellEditor(new LayerVisibleCheckBox()));
    192         layerList.getColumnModel().getColumn(1).setMaxWidth(16);
    193         layerList.getColumnModel().getColumn(1).setPreferredWidth(16);
     191
     192        layerList.getColumnModel().getColumn(1).setCellRenderer(new NativeScaleLayerCellRenderer());
     193        layerList.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(new NativeScaleLayerCheckBox()));
     194        layerList.getColumnModel().getColumn(1).setMaxWidth(12);
     195        layerList.getColumnModel().getColumn(1).setPreferredWidth(12);
    194196        layerList.getColumnModel().getColumn(1).setResizable(false);
    195         layerList.getColumnModel().getColumn(2).setCellRenderer(new LayerNameCellRenderer());
    196         layerList.getColumnModel().getColumn(2).setCellEditor(new LayerNameCellEditor(new DisableShortcutsOnFocusGainedTextField()));
     197
     198        layerList.getColumnModel().getColumn(2).setCellRenderer(new LayerVisibleCellRenderer());
     199        layerList.getColumnModel().getColumn(2).setCellEditor(new LayerVisibleCellEditor(new LayerVisibleCheckBox()));
     200        layerList.getColumnModel().getColumn(2).setMaxWidth(16);
     201        layerList.getColumnModel().getColumn(2).setPreferredWidth(16);
     202        layerList.getColumnModel().getColumn(2).setResizable(false);
     203
     204        layerList.getColumnModel().getColumn(3).setCellRenderer(new LayerNameCellRenderer());
     205        layerList.getColumnModel().getColumn(3).setCellEditor(new LayerNameCellEditor(new DisableShortcutsOnFocusGainedTextField()));
    197206        // Disable some default JTable shortcuts to use JOSM ones (see #5678, #10458)
    198207        for (KeyStroke ks : new KeyStroke[] {
     
    10261035    }
    10271036
     1037    private static class NativeScaleLayerCheckBox extends JCheckBox {
     1038        NativeScaleLayerCheckBox() {
     1039            setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
     1040            ImageIcon blank = ImageProvider.get("dialogs/layerlist", "blank");
     1041            ImageIcon active = ImageProvider.get("dialogs/layerlist", "scale");
     1042            setIcon(blank);
     1043            setSelectedIcon(active);
     1044        }
     1045    }
     1046
    10281047    private static class ActiveLayerCellRenderer implements TableCellRenderer {
    10291048        private final JCheckBox cb;
     
    10381057        @Override
    10391058        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    1040             boolean active =  value != null && (Boolean) value;
     1059            boolean active = value != null && (Boolean) value;
    10411060            cb.setSelected(active);
    10421061            cb.setToolTipText(active ? tr("this layer is the active layer") : tr("this layer is not currently active (click to activate)"));
     
    10751094        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    10761095            cb.updateStatus((Layer) value);
     1096            return cb;
     1097        }
     1098    }
     1099
     1100    private static class NativeScaleLayerCellRenderer implements TableCellRenderer {
     1101        private final JCheckBox cb;
     1102
     1103        /**
     1104         * Constructs a new {@code ActiveLayerCellRenderer}.
     1105         */
     1106        NativeScaleLayerCellRenderer() {
     1107            cb = new NativeScaleLayerCheckBox();
     1108        }
     1109
     1110        @Override
     1111        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
     1112            Layer layer = (Layer) value;
     1113            if (layer instanceof NativeScaleLayer) {
     1114                boolean active = layer != null && layer == Main.map.mapView.getNativeScaleLayer();
     1115                cb.setSelected(active);
     1116                cb.setToolTipText(active
     1117                    ? tr("scale follows native resolution of this layer")
     1118                    : tr("scale follows native resolution of another layer (click to set this layer)")
     1119                );
     1120            } else {
     1121                cb.setSelected(false);
     1122                cb.setToolTipText(tr("this layer has no native resolution"));
     1123            }
    10771124            return cb;
    10781125        }
     
    15501597        }
    15511598
     1599        /**
     1600         * Replies the scale layer. null, if no active layer is available
     1601         *
     1602         * @return the scale layer. null, if no active layer is available
     1603         */
     1604        protected NativeScaleLayer getNativeScaleLayer() {
     1605            if (!Main.isDisplayingMapView()) return null;
     1606            return Main.map.mapView.getNativeScaleLayer();
     1607        }
     1608
    15521609        /* ------------------------------------------------------------------------------ */
    15531610        /* Interface TableModel                                                           */
     
    15631620        @Override
    15641621        public int getColumnCount() {
    1565             return 3;
     1622            return 4;
    15661623        }
    15671624
     
    15741631                case 1: return layers.get(row);
    15751632                case 2: return layers.get(row);
     1633                case 3: return layers.get(row);
    15761634                default: throw new RuntimeException();
    15771635                }
     
    15981656                    break;
    15991657                case 1:
     1658                    if (Main.map.mapView.getNativeScaleLayer() == l) {
     1659                        Main.map.mapView.setNativeScaleLayer(null);
     1660                    } else if (l instanceof NativeScaleLayer) {
     1661                        Main.map.mapView.setNativeScaleLayer((NativeScaleLayer) l);
     1662                    }
     1663                    break;
     1664                case 2:
    16001665                    l.setVisible((Boolean) value);
    16011666                    break;
    1602                 case 2:
     1667                case 3:
    16031668                    l.rename((String) value);
    16041669                    break;
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r9731 r9818  
    55
    66import org.apache.commons.jcs.access.CacheAccess;
     7import org.openstreetmap.gui.jmapviewer.OsmMercator;
    78import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
    89import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTMSTileSource;
     
    2930 *
    3031 */
    31 public class TMSLayer extends AbstractCachedTileSourceLayer {
     32public class TMSLayer extends AbstractCachedTileSourceLayer implements NativeScaleLayer {
    3233    private static final String CACHE_REGION_NAME = "TMS";
    3334
     
    145146        return AbstractCachedTileSourceLayer.getCache(CACHE_REGION_NAME);
    146147    }
     148
     149    @Override
     150    public ScaleList getNativeScales() {
     151        ScaleList scales = new ScaleList();
     152        for (int zoom = info.getMinZoom(); zoom <= info.getMaxZoom(); zoom++) {
     153            double scale = OsmMercator.EARTH_RADIUS * Math.PI * 2 / Math.pow(2, zoom) / OsmMercator.DEFAUL_TILE_SIZE;
     154            scales.add(new Scale(scale));
     155        }
     156        return scales;
     157    }
    147158}
  • trunk/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java

    r9430 r9818  
    66
    77import org.apache.commons.jcs.access.CacheAccess;
    8 import org.openstreetmap.gui.jmapviewer.TileXY;
    9 import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
    108import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
    119import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTMSTileSource;
    1210import org.openstreetmap.josm.Main;
    1311import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
    14 import org.openstreetmap.josm.data.coor.LatLon;
    1512import org.openstreetmap.josm.data.imagery.ImageryInfo;
    1613import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
     
    1916import org.openstreetmap.josm.data.preferences.BooleanProperty;
    2017import org.openstreetmap.josm.data.projection.Projection;
    21 import org.openstreetmap.josm.gui.MapView;
    2218
    2319/**
     
    2824 * http://www.opengeospatial.org/standards/wmts
    2925 *
    30  * @author Wiktor Niesiobędzki
     26 * @author Wiktor NiesiobÄ™dzki
    3127 *
    3228 */
    33 public class WMTSLayer extends AbstractCachedTileSourceLayer {
     29public class WMTSLayer extends AbstractCachedTileSourceLayer implements NativeScaleLayer {
    3430    /**
    3531     * default setting of autozoom per layer
     
    6359    }
    6460
    65     /**
    66      * @param zoom level of the tile
    67      * @return how many pixels of the screen occupies one pixel of the tile
    68      */
    69     private double getTileToScreenRatio(int zoom) {
    70          MapView mv = Main.map.mapView;
    71          LatLon topLeft = mv.getLatLon(0, 0);
    72          LatLon botLeft = mv.getLatLon(0, tileSource.getTileSize());
    73 
    74          TileXY topLeftTile = tileSource.latLonToTileXY(topLeft.toCoordinate(), zoom);
    75 
    76          ICoordinate north = tileSource.tileXYToLatLon(topLeftTile.getXIndex(), topLeftTile.getYIndex(), zoom);
    77          ICoordinate south = tileSource.tileXYToLatLon(topLeftTile.getXIndex(), topLeftTile.getYIndex() + 1, zoom);
    78 
    79          return Math.abs((north.getLat() - south.getLat()) / (topLeft.lat() - botLeft.lat()));
     61    @Override
     62    protected int getBestZoom() {
     63        if (!Main.isDisplayingMapView()) return 0;
     64        ScaleList scaleList = getNativeScales();
     65        for (int i = scaleList.size()-1; i >= 0; i--) {
     66            Scale scale = scaleList.get(i);
     67            if (scale.scale >= Main.map.mapView.getScale()) {
     68                return i;
     69            }
     70        }
     71        return 0;
    8072    }
    8173
    8274    @Override
    83     protected int getBestZoom() {
    84         if (!Main.isDisplayingMapView()) return 1;
     75    protected int getMaxZoomLvl() {
     76        return getNativeScales().size()-1;
     77    }
    8578
    86         for (int i = getMinZoomLvl() + 1; i <= getMaxZoomLvl(); i++) {
    87             double ret = getTileToScreenRatio(i);
    88             if (ret < 1) {
    89                 return i - 1;
    90             }
    91         }
    92         return getMaxZoomLvl();
     79    @Override
     80    protected int getMinZoomLvl() {
     81        return 0;
    9382    }
    9483
     
    130119        return AbstractCachedTileSourceLayer.getCache(CACHE_REGION_NAME);
    131120    }
     121
     122    @Override
     123    public ScaleList getNativeScales() {
     124        return ((WMTSTileSource) tileSource).getNativeScales();
     125    }
    132126}
Note: See TracChangeset for help on using the changeset viewer.