diff options
author | Tobrun <tobrun@mapbox.com> | 2016-02-18 16:25:19 +0100 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2016-02-19 15:24:16 +0100 |
commit | 9ec01034316cd3f2184ca11fc4c4de5db93a031d (patch) | |
tree | 12d2cd9f1b313da13e3cc310ac204305757fe8be /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java | |
parent | 27ed15c18c43617f64edc469c1dbbcf9cdf98511 (diff) | |
download | qtlocation-mapboxgl-9ec01034316cd3f2184ca11fc4c4de5db93a031d.tar.gz |
[android] #4018 - migrated max/min zoom to UiSettings + added tests + update sample app
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java | 99 |
1 files changed, 85 insertions, 14 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java index ede6217a47..aac31cd0f0 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java @@ -1,11 +1,15 @@ package com.mapbox.mapboxsdk.maps; +import android.support.annotation.FloatRange; import android.support.annotation.NonNull; import android.support.annotation.UiThread; +import android.util.Log; import android.view.Gravity; import android.view.View; import android.widget.VideoView; +import com.mapbox.mapboxsdk.constants.MapboxConstants; + /** * Settings for the user interface of a MapboxMap. To obtain this interface, call getUiSettings(). */ @@ -23,6 +27,9 @@ public class UiSettings { private boolean zoomControlsEnabled; private boolean scrollGesturesEnabled; + private double maxZoomLevel = -1; + private double minZoomLevel = -1; + UiSettings(@NonNull MapView mapView) { this.mapView = mapView; this.compassSettings = new ViewSettings(); @@ -32,6 +39,70 @@ public class UiSettings { /** * <p> + * Sets the minimum zoom level the map can be displayed at. + * </p> + * + * @param minZoom The new minimum zoom level. + */ + @UiThread + public void setMinZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double minZoom) { + if ((minZoom < MapboxConstants.MINIMUM_ZOOM) || (minZoom > MapboxConstants.MAXIMUM_ZOOM)) { + Log.e(MapboxConstants.TAG, "Not setting minZoom, value is in unsupported range: " + minZoom); + return; + } + minZoomLevel = minZoom; + mapView.setMinZoom(minZoom); + } + + /** + * <p> + * Gets the maximum zoom level the map can be displayed at. + * </p> + * + * @return The minimum zoom level. + */ + @UiThread + public double getMinZoom() { + if (minZoomLevel == -1) { + return minZoomLevel = mapView.getMinZoom(); + } + return minZoomLevel; + } + + /** + * <p> + * Sets the maximum zoom level the map can be displayed at. + * </p> + * + * @param maxZoom The new maximum zoom level. + */ + @UiThread + public void setMaxZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) { + if ((maxZoom < MapboxConstants.MINIMUM_ZOOM) || (maxZoom > MapboxConstants.MAXIMUM_ZOOM)) { + Log.e(MapboxConstants.TAG, "Not setting maxZoom, value is in unsupported range: " + maxZoom); + return; + } + maxZoomLevel = maxZoom; + mapView.setMaxZoom(maxZoom); + } + + /** + * <p> + * Gets the maximum zoom level the map can be displayed at. + * </p> + * + * @return The maximum zoom level. + */ + @UiThread + public double getMaxZoom() { + if (maxZoomLevel == -1) { + return maxZoomLevel = mapView.getMaxZoom(); + } + return maxZoomLevel; + } + + /** + * <p> * Enables or disables the compass. The compass is an icon on the map that indicates the * direction of north on the map. When a user clicks * the compass, the camera orients itself to its default orientation and fades away shortly @@ -110,7 +181,7 @@ public class UiSettings { * @return The top margin in pixels */ public int getCompassMarginTop() { - return compassSettings.getMargins()[1]; + return compassSettings.getMargins()[1]; } /** @@ -119,7 +190,7 @@ public class UiSettings { * @return The right margin in pixels */ public int getCompassMarginRight() { - return compassSettings.getMargins()[2]; + return compassSettings.getMargins()[2]; } /** @@ -128,7 +199,7 @@ public class UiSettings { * @return The bottom margin in pixels */ public int getCompassMarginBottom() { - return compassSettings.getMargins()[3]; + return compassSettings.getMargins()[3]; } /** @@ -141,7 +212,7 @@ public class UiSettings { */ public void setLogoEnabled(boolean enabled) { logoSettings.setEnabled(enabled); - mapView.setLogoVisibility(enabled ); + mapView.setLogoVisibility(enabled); } /** @@ -196,7 +267,7 @@ public class UiSettings { * * @return The left margin in pixels */ - public int getLogoMarginLeft(){ + public int getLogoMarginLeft() { return logoSettings.getMargins()[0]; } @@ -205,7 +276,7 @@ public class UiSettings { * * @return The top margin in pixels */ - public int getLogoMarginTop(){ + public int getLogoMarginTop() { return logoSettings.getMargins()[1]; } @@ -214,7 +285,7 @@ public class UiSettings { * * @return The right margin in pixels */ - public int getLogoMarginRight(){ + public int getLogoMarginRight() { return logoSettings.getMargins()[2]; } @@ -223,7 +294,7 @@ public class UiSettings { * * @return The bottom margin in pixels */ - public int getLogoMarginBottom(){ + public int getLogoMarginBottom() { return logoSettings.getMargins()[3]; } @@ -292,7 +363,7 @@ public class UiSettings { * * @return The left margin in pixels */ - public int getAttributionMarginLeft(){ + public int getAttributionMarginLeft() { return attributionSettings.getMargins()[0]; } @@ -301,7 +372,7 @@ public class UiSettings { * * @return The top margin in pixels */ - public int getAttributionMarginTop(){ + public int getAttributionMarginTop() { return attributionSettings.getMargins()[1]; } @@ -310,7 +381,7 @@ public class UiSettings { * * @return The right margin in pixels */ - public int getAttributionMarginRight(){ + public int getAttributionMarginRight() { return attributionSettings.getMargins()[2]; } @@ -319,7 +390,7 @@ public class UiSettings { * * @return The bottom margin in pixels */ - public int getAttributionMarginBottom(){ + public int getAttributionMarginBottom() { return attributionSettings.getMargins()[3]; } @@ -471,9 +542,9 @@ public class UiSettings { setZoomGesturesEnabled(enabled); } - public void invalidate(){ + public void invalidate() { mapView.setLogoMargins(getLogoMarginLeft(), getLogoMarginTop(), getLogoMarginRight(), getLogoMarginBottom()); - mapView.setCompassMargins(getCompassMarginLeft(),getCompassMarginTop(),getCompassMarginRight(),getCompassMarginBottom()); + mapView.setCompassMargins(getCompassMarginLeft(), getCompassMarginTop(), getCompassMarginRight(), getCompassMarginBottom()); mapView.setAttributionMargins(getAttributionMarginLeft(), getAttributionMarginTop(), getAttributionMarginRight(), getAttributionMarginBottom()); } } |