From f9e1748deb2519c8adc67807585dc6add1b3230f Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Fri, 10 Jun 2016 14:27:41 +0300 Subject: [PATCH] Min zoom and max zoom are now dynamically updated. #2648 --- .../osmand/plus/activities/MapActivity.java | 5 +-- .../net/osmand/plus/views/BaseMapLayer.java | 3 +- .../osmand/plus/views/OsmandMapTileView.java | 45 +++++++++++-------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 979f7a903c..a1eda21f8c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -119,7 +119,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven private static final int LONG_KEYPRESS_DELAY = 500; private static final Log LOG = PlatformUtil.getLog(MapActivity.class); - public static final int MAX_ZOOM = 22; private static MapViewTrackingUtilities mapViewTrackingUtilities; private static MapContextMenu mapContextMenu = new MapContextMenu(); @@ -796,11 +795,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven final int newZoom = mapView.getZoom() + stp; final double zoomFrac = mapView.getZoomFractionalPart(); - if (newZoom > mapView.getMainLayer().getMaximumShownMapZoom()) { + if (newZoom > mapView.getMaxZoom()) { Toast.makeText(this, R.string.edit_tilesource_maxzoom, Toast.LENGTH_SHORT).show(); //$NON-NLS-1$ return; } - if (newZoom < mapView.getMainLayer().getMinimumShownMapZoom()) { + if (newZoom < mapView.getMinZoom()) { Toast.makeText(this, R.string.edit_tilesource_minzoom, Toast.LENGTH_SHORT).show(); //$NON-NLS-1$ return; } diff --git a/OsmAnd/src/net/osmand/plus/views/BaseMapLayer.java b/OsmAnd/src/net/osmand/plus/views/BaseMapLayer.java index d23af4351e..2c8651928c 100644 --- a/OsmAnd/src/net/osmand/plus/views/BaseMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/BaseMapLayer.java @@ -3,6 +3,7 @@ package net.osmand.plus.views; public abstract class BaseMapLayer extends OsmandMapLayer { public static final int DEFAULT_MAX_ZOOM = 21; + public static final int DEFAULT_MIN_ZOOM = 1; private int alpha = 255; protected int warningToSwitchMapShown = 0; @@ -11,7 +12,7 @@ public abstract class BaseMapLayer extends OsmandMapLayer { } public int getMinimumShownMapZoom(){ - return 1; + return DEFAULT_MIN_ZOOM; } public void setAlpha(int alpha) { diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 505f407a65..a173b14ac4 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -60,7 +60,6 @@ import java.util.List; import java.util.Map; public class OsmandMapTileView implements IMapDownloaderCallback { - private static final int MAP_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 4; private static final int MAP_FORCE_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 5; private static final int BASE_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 3; @@ -73,9 +72,6 @@ public class OsmandMapTileView implements IMapDownloaderCallback { private OsmandApplication application; protected OsmandSettings settings = null; - private int maxZoom; - private int minZoom; - private class FPSMeasurement { int fpsMeasureCount = 0; int fpsMeasureMs = 0; @@ -311,8 +307,8 @@ public class OsmandMapTileView implements IMapDownloaderCallback { // ///////////////////////// NON UI PART (could be extracted in common) ///////////////////////////// public void setIntZoom(int zoom) { - zoom = zoom > maxZoom ? maxZoom : zoom; - zoom = zoom < minZoom ? minZoom : zoom; + zoom = zoom > getMaxZoom() ? getMaxZoom() : zoom; + zoom = zoom < getMinZoom() ? getMinZoom() : zoom; if (mainLayer != null) { animatedDraggingThread.stopAnimating(); currentViewport.setZoomAndAnimation(zoom, 0, 0); @@ -322,7 +318,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { } public void setComplexZoom(int zoom, double mapDensity) { - if (mainLayer != null && zoom <= maxZoom && zoom >= minZoom) { + if (mainLayer != null && zoom <= getMaxZoom() && zoom >= getMinZoom()) { animatedDraggingThread.stopAnimating(); currentViewport.setZoomAndAnimation(zoom, 0); currentViewport.setMapDensity(mapDensity); @@ -408,13 +404,12 @@ public class OsmandMapTileView implements IMapDownloaderCallback { public void setMainLayer(BaseMapLayer mainLayer) { this.mainLayer = mainLayer; int zoom = currentViewport.getZoom(); - maxZoom = mainLayer.getMaximumShownMapZoom(); - minZoom = mainLayer.getMinimumShownMapZoom() + 1; - if (maxZoom < zoom) { - zoom = maxZoom; + + if (getMaxZoom() < zoom) { + zoom = getMaxZoom(); } - if (minZoom > zoom) { - zoom = minZoom; + if (getMinZoom() > zoom) { + zoom = getMinZoom(); } currentViewport.setZoomAndAnimation(zoom, 0, 0); refreshMap(); @@ -436,6 +431,20 @@ public class OsmandMapTileView implements IMapDownloaderCallback { return settings; } + public int getMaxZoom() { + if (mainLayer != null) { + return mainLayer.getMaximumShownMapZoom(); + } + return BaseMapLayer.DEFAULT_MAX_ZOOM; + } + + public int getMinZoom() { + if (mainLayer != null) { + return mainLayer.getMinimumShownMapZoom() + 1; + } + return BaseMapLayer.DEFAULT_MIN_ZOOM; + } + private void drawBasemap(Canvas canvas) { if (bufferImgLoc != null) { float rot = -bufferImgLoc.getRotate(); @@ -740,7 +749,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { // for internal usage protected void zoomToAnimate(int zoom, double zoomToAnimate, boolean notify) { - if (mainLayer != null && maxZoom >= zoom && minZoom <= zoom) { + if (mainLayer != null && getMaxZoom() >= zoom && getMinZoom() <= zoom) { currentViewport.setZoomAndAnimation(zoom, zoomToAnimate); currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0); refreshMap(); @@ -1026,16 +1035,16 @@ public class OsmandMapTileView implements IMapDownloaderCallback { } private boolean isZoomingAllowed(int baseZoom, float dz) { - if (baseZoom > maxZoom) { + if (baseZoom > getMaxZoom()) { return false; } - if (baseZoom > maxZoom - 1 && dz > 1) { + if (baseZoom > getMaxZoom() - 1 && dz > 1) { return false; } - if (baseZoom < minZoom) { + if (baseZoom < getMinZoom()) { return false; } - if (baseZoom < minZoom + 1 && dz < -1) { + if (baseZoom < getMinZoom() + 1 && dz < -1) { return false; } return true;