Min zoom and max zoom are now dynamically updated. #2648

This commit is contained in:
GaidamakUA 2016-06-10 14:27:41 +03:00
parent 6a44ef06ae
commit f9e1748deb
3 changed files with 31 additions and 22 deletions

View file

@ -119,7 +119,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private static final int LONG_KEYPRESS_DELAY = 500; private static final int LONG_KEYPRESS_DELAY = 500;
private static final Log LOG = PlatformUtil.getLog(MapActivity.class); private static final Log LOG = PlatformUtil.getLog(MapActivity.class);
public static final int MAX_ZOOM = 22;
private static MapViewTrackingUtilities mapViewTrackingUtilities; private static MapViewTrackingUtilities mapViewTrackingUtilities;
private static MapContextMenu mapContextMenu = new MapContextMenu(); private static MapContextMenu mapContextMenu = new MapContextMenu();
@ -796,11 +795,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
final int newZoom = mapView.getZoom() + stp; final int newZoom = mapView.getZoom() + stp;
final double zoomFrac = mapView.getZoomFractionalPart(); 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$ Toast.makeText(this, R.string.edit_tilesource_maxzoom, Toast.LENGTH_SHORT).show(); //$NON-NLS-1$
return; 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$ Toast.makeText(this, R.string.edit_tilesource_minzoom, Toast.LENGTH_SHORT).show(); //$NON-NLS-1$
return; return;
} }

View file

@ -3,6 +3,7 @@ package net.osmand.plus.views;
public abstract class BaseMapLayer extends OsmandMapLayer { public abstract class BaseMapLayer extends OsmandMapLayer {
public static final int DEFAULT_MAX_ZOOM = 21; public static final int DEFAULT_MAX_ZOOM = 21;
public static final int DEFAULT_MIN_ZOOM = 1;
private int alpha = 255; private int alpha = 255;
protected int warningToSwitchMapShown = 0; protected int warningToSwitchMapShown = 0;
@ -11,7 +12,7 @@ public abstract class BaseMapLayer extends OsmandMapLayer {
} }
public int getMinimumShownMapZoom(){ public int getMinimumShownMapZoom(){
return 1; return DEFAULT_MIN_ZOOM;
} }
public void setAlpha(int alpha) { public void setAlpha(int alpha) {

View file

@ -60,7 +60,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class OsmandMapTileView implements IMapDownloaderCallback { public class OsmandMapTileView implements IMapDownloaderCallback {
private static final int MAP_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 4; 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 MAP_FORCE_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 5;
private static final int BASE_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 3; 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; private OsmandApplication application;
protected OsmandSettings settings = null; protected OsmandSettings settings = null;
private int maxZoom;
private int minZoom;
private class FPSMeasurement { private class FPSMeasurement {
int fpsMeasureCount = 0; int fpsMeasureCount = 0;
int fpsMeasureMs = 0; int fpsMeasureMs = 0;
@ -311,8 +307,8 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
// ///////////////////////// NON UI PART (could be extracted in common) ///////////////////////////// // ///////////////////////// NON UI PART (could be extracted in common) /////////////////////////////
public void setIntZoom(int zoom) { public void setIntZoom(int zoom) {
zoom = zoom > maxZoom ? maxZoom : zoom; zoom = zoom > getMaxZoom() ? getMaxZoom() : zoom;
zoom = zoom < minZoom ? minZoom : zoom; zoom = zoom < getMinZoom() ? getMinZoom() : zoom;
if (mainLayer != null) { if (mainLayer != null) {
animatedDraggingThread.stopAnimating(); animatedDraggingThread.stopAnimating();
currentViewport.setZoomAndAnimation(zoom, 0, 0); currentViewport.setZoomAndAnimation(zoom, 0, 0);
@ -322,7 +318,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
} }
public void setComplexZoom(int zoom, double mapDensity) { public void setComplexZoom(int zoom, double mapDensity) {
if (mainLayer != null && zoom <= maxZoom && zoom >= minZoom) { if (mainLayer != null && zoom <= getMaxZoom() && zoom >= getMinZoom()) {
animatedDraggingThread.stopAnimating(); animatedDraggingThread.stopAnimating();
currentViewport.setZoomAndAnimation(zoom, 0); currentViewport.setZoomAndAnimation(zoom, 0);
currentViewport.setMapDensity(mapDensity); currentViewport.setMapDensity(mapDensity);
@ -408,13 +404,12 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
public void setMainLayer(BaseMapLayer mainLayer) { public void setMainLayer(BaseMapLayer mainLayer) {
this.mainLayer = mainLayer; this.mainLayer = mainLayer;
int zoom = currentViewport.getZoom(); int zoom = currentViewport.getZoom();
maxZoom = mainLayer.getMaximumShownMapZoom();
minZoom = mainLayer.getMinimumShownMapZoom() + 1; if (getMaxZoom() < zoom) {
if (maxZoom < zoom) { zoom = getMaxZoom();
zoom = maxZoom;
} }
if (minZoom > zoom) { if (getMinZoom() > zoom) {
zoom = minZoom; zoom = getMinZoom();
} }
currentViewport.setZoomAndAnimation(zoom, 0, 0); currentViewport.setZoomAndAnimation(zoom, 0, 0);
refreshMap(); refreshMap();
@ -436,6 +431,20 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
return settings; 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) { private void drawBasemap(Canvas canvas) {
if (bufferImgLoc != null) { if (bufferImgLoc != null) {
float rot = -bufferImgLoc.getRotate(); float rot = -bufferImgLoc.getRotate();
@ -740,7 +749,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
// for internal usage // for internal usage
protected void zoomToAnimate(int zoom, double zoomToAnimate, boolean notify) { 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.setZoomAndAnimation(zoom, zoomToAnimate);
currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0); currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0);
refreshMap(); refreshMap();
@ -1026,16 +1035,16 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
} }
private boolean isZoomingAllowed(int baseZoom, float dz) { private boolean isZoomingAllowed(int baseZoom, float dz) {
if (baseZoom > maxZoom) { if (baseZoom > getMaxZoom()) {
return false; return false;
} }
if (baseZoom > maxZoom - 1 && dz > 1) { if (baseZoom > getMaxZoom() - 1 && dz > 1) {
return false; return false;
} }
if (baseZoom < minZoom) { if (baseZoom < getMinZoom()) {
return false; return false;
} }
if (baseZoom < minZoom + 1 && dz < -1) { if (baseZoom < getMinZoom() + 1 && dz < -1) {
return false; return false;
} }
return true; return true;