]> gitweb.fperrin.net Git - GpsPrune.git/commitdiff
Never overzoom when initially opening a track
authorFrédéric Perrin <fred@fperrin.net>
Sun, 30 Dec 2018 13:56:13 +0000 (13:56 +0000)
committerFrédéric Perrin <fred@fperrin.net>
Fri, 6 Nov 2020 19:31:39 +0000 (19:31 +0000)
src/tim/prune/gui/map/MapCanvas.java
src/tim/prune/gui/map/MapPosition.java
src/tim/prune/gui/map/MapTileManager.java

index fb2b589fc744f9c8be0303b29e16ec3d7daa30a2..4b9609f5037b9817eb78e48f22e5edfe69d54166 100644 (file)
@@ -353,8 +353,11 @@ public class MapCanvas extends JPanel implements MouseListener, MouseMotionListe
                        MapUtils.getXFromLongitude(_lonRange.getMaximum()));
                _yRange = new DoubleRange(MapUtils.getYFromLatitude(_latRange.getMinimum()),
                        MapUtils.getYFromLatitude(_latRange.getMaximum()));
-               _mapPosition.zoomToXY(_xRange.getMinimum(), _xRange.getMaximum(), _yRange.getMinimum(), _yRange.getMaximum(),
-                       getWidth(), getHeight());
+               _mapPosition.zoomToXY(
+                       _xRange.getMinimum(), _xRange.getMaximum(),
+                       _yRange.getMinimum(), _yRange.getMaximum(),
+                       getWidth(), getHeight(),
+                       _tileManager.getMaxZoomLevel());
        }
 
        /**
index a70bbf63ba79b86c02114d785c3737d96b6625c5..3d9e05f300520cd5b2b4664cae8d2aa2f3d2ab20 100644 (file)
@@ -32,14 +32,14 @@ public class MapPosition
         * @param inWidth width of display
         * @param inHeight height of display
         */
-       public void zoomToXY(double inMinX, double inMaxX, double inMinY, double inMaxY, int inWidth, int inHeight)
+       public void zoomToXY(double inMinX, double inMaxX, double inMinY, double inMaxY, int inWidth, int inHeight, int maxZoom)
        {
                // System.out.println("Zooming to " + inMinX + ", " + inMaxX + ", " + inMinY + ", " + inMaxY + "; width=" + inWidth + ", height=" + inHeight);
                double diffX = Math.abs(inMaxX - inMinX);
                double diffY = Math.abs(inMaxY - inMinY);
                // Find out what zoom level to go to
                int requiredZoom = -1;
-               for (int currZoom = MAX_ZOOM; currZoom >= 2; currZoom--)
+               for (int currZoom = maxZoom; currZoom >= 2; currZoom--)
                {
                        if (transformToPixels(diffX, currZoom) < inWidth
                                && transformToPixels(diffY, currZoom) < inHeight)
index 8c2c6eed9e3f7e70ccf251ba91e01ebe4f550be9..b4a60c88b607a10cee8737f7ce80bd4c3b701e89 100644 (file)
@@ -70,10 +70,19 @@ public class MapTileManager implements ImageObserver
         * @return true if zoom is too high for tiles
         */
        public boolean isOverzoomed()
+       {
+               return _zoom > getMaxZoomLevel();
+       }
+
+       /**
+        * @return the maximum useable zoom level for tiles
+        */
+       public int getMaxZoomLevel()
        {
                // Ask current map source what maximum zoom is
                int maxZoom = (_mapSource == null?0:_mapSource.getMaxZoomLevel());
-               return (_zoom > maxZoom);
+               return maxZoom;
+
        }
 
        /**