diff options
author | Tobrun <tobrun@mapbox.com> | 2016-01-12 10:48:39 +0100 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2016-01-12 12:34:45 +0100 |
commit | 71edb38cf10bde4180e5e4c65ea229c80ee680eb (patch) | |
tree | f158588084facf8e0c1716406d5a945f20037402 | |
parent | 2b5d7bfb8e9acac242e25df437b536ebf1fa59c5 (diff) | |
download | qtlocation-mapboxgl-71edb38cf10bde4180e5e4c65ea229c80ee680eb.tar.gz |
[android] #3327 - replaced ZoomLevel with Zoom, introduced new methods, deprecated old ones
12 files changed, 98 insertions, 25 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java index 65128c31d6..0f7f014d54 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java @@ -125,7 +125,7 @@ public final class MapView extends FrameLayout { // Used for saving instance state private static final String STATE_CENTER_COORDINATE = "centerCoordinate"; private static final String STATE_CENTER_DIRECTION = "centerDirection"; - private static final String STATE_ZOOM_LEVEL = "zoomLevel"; + private static final String STATE_ZOOM = "zoomLevel"; private static final String STATE_TILT = "tilt"; private static final String STATE_ZOOM_ENABLED = "zoomEnabled"; private static final String STATE_SCROLL_ENABLED = "scrollEnabled"; @@ -172,10 +172,18 @@ public final class MapView extends FrameLayout { * The currently supported maximum zoom level. * * @see MapView#setZoomLevel(double) + * @deprecated use #MAXIMUM_ZOOM instead. */ public static final double MAXIMUM_ZOOM_LEVEL = 18.0; /** + * The currently supported maximum zoom level. + * + * @see MapView#setZoom(double) + */ + public static final double MAXIMUM_ZOOM = 18.0; + + /** * The currently supported maximum and minimum tilt values. * * @see MapView#setTilt(Double, Long) @@ -825,6 +833,7 @@ public final class MapView extends FrameLayout { LatLng centerCoordinate = new LatLng(centerLatitude, centerLongitude); setCenterCoordinate(centerCoordinate); // need to set zoom level first because of limitation on rotating when zoomed out + setZoom(typedArray.getFloat(R.styleable.MapView_zoom, 0.0f)); setZoomLevel(typedArray.getFloat(R.styleable.MapView_zoom_level, 0.0f)); setDirection(typedArray.getFloat(R.styleable.MapView_direction, 0.0f)); setZoomEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_enabled, true)); @@ -907,7 +916,7 @@ public final class MapView extends FrameLayout { if (savedInstanceState != null) { setCenterCoordinate((LatLng) savedInstanceState.getParcelable(STATE_CENTER_COORDINATE)); // need to set zoom level first because of limitation on rotating when zoomed out - setZoomLevel(savedInstanceState.getDouble(STATE_ZOOM_LEVEL)); + setZoom(savedInstanceState.getDouble(STATE_ZOOM)); setDirection(savedInstanceState.getDouble(STATE_CENTER_DIRECTION)); setTilt(savedInstanceState.getDouble(STATE_TILT), null); setZoomEnabled(savedInstanceState.getBoolean(STATE_ZOOM_ENABLED)); @@ -996,7 +1005,7 @@ public final class MapView extends FrameLayout { outState.putParcelable(STATE_CENTER_COORDINATE, getCenterCoordinate()); // need to set zoom level first because of limitation on rotating when zoomed out - outState.putDouble(STATE_ZOOM_LEVEL, getZoomLevel()); + outState.putDouble(STATE_ZOOM, getZoom()); outState.putDouble(STATE_CENTER_DIRECTION, getDirection()); outState.putDouble(STATE_TILT, getTilt()); outState.putBoolean(STATE_ZOOM_ENABLED, isZoomEnabled()); @@ -1379,10 +1388,72 @@ public final class MapView extends FrameLayout { /** * Returns the current zoom level of the map view. * + * @return The current zoom. + */ + @UiThread + @FloatRange(from = 0.0, to = MAXIMUM_ZOOM) + public double getZoom() { + return mNativeMapView.getZoom(); + } + + /** + * <p> + * Zooms the map to a new zoom level immediately without changing the center coordinate. + * </p> + * <p> + * At zoom level 0, tiles cover the entire world map; + * at zoom level 1, tiles cover 1/14 of the world; + * at zoom level 2, tiles cover 1/16 of the world, and so on. + * </p> + * <p> + * The initial zoom level is 0. The maximum zoom level is {@link MapView#MAXIMUM_ZOOM}. + * </p> + * If you want to animate the change, use {@link MapView#setZoom(double, boolean)}. + * + * @param zoomLevel The new zoom. + * @see MapView#setZoom(double, boolean) + * @see MapView#MAXIMUM_ZOOM + */ + @UiThread + public void setZoom(@FloatRange(from = 0.0, to = MAXIMUM_ZOOM) double zoomLevel) { + setZoom(zoomLevel, false); + setZoom(zoomLevel, false); + } + + /** + * <p> + * Zooms the map to a new zoom level and optionally animates the change without changing the center coordinate. + * </p> + * <p> + * At zoom level 0, tiles cover the entire world map; + * at zoom level 1, tiles cover 1/14 of the world; + * at zoom level 2, tiles cover 1/16 of the world, and so on. + * </p> + * The initial zoom level is 0. The maximum zoom level is {@link MapView#MAXIMUM_ZOOM}. + * + * @param zoomLevel The new zoom level. + * @param animated If true, animates the change. If false, immediately changes the map. + * @see MapView#MAXIMUM_ZOOM + */ + @UiThread + public void setZoom(@FloatRange(from = 0.0, to = MAXIMUM_ZOOM_LEVEL) double zoomLevel, boolean animated) { + if ((zoomLevel < 0.0) || (zoomLevel > MAXIMUM_ZOOM_LEVEL)) { + throw new IllegalArgumentException("zoomLevel is < 0 or > MapView.MAXIMUM_ZOOM_LEVEL"); + } + long duration = animated ? ANIMATION_DURATION : 0; + mNativeMapView.cancelTransitions(); + mNativeMapView.setZoom(zoomLevel, duration); + } + + /** + * Returns the current zoom level of the map view. + * * @return The current zoom level. + * @deprecated use {@link #getZoom()} instead. */ @UiThread @FloatRange(from = 0.0, to = MAXIMUM_ZOOM_LEVEL) + @Deprecated public double getZoomLevel() { return mNativeMapView.getZoom(); } @@ -1404,8 +1475,10 @@ public final class MapView extends FrameLayout { * @param zoomLevel The new coordinate. * @see MapView#setZoomLevel(double, boolean) * @see MapView#MAXIMUM_ZOOM_LEVEL + * @deprecated use {@link #setZoom(double)} instead. */ @UiThread + @Deprecated public void setZoomLevel(@FloatRange(from = 0.0, to = MAXIMUM_ZOOM_LEVEL) double zoomLevel) { setZoomLevel(zoomLevel, false); } @@ -1424,8 +1497,10 @@ public final class MapView extends FrameLayout { * @param zoomLevel The new coordinate. * @param animated If true, animates the change. If false, immediately changes the map. * @see MapView#MAXIMUM_ZOOM_LEVEL + * @deprecated use {@link #setZoom(double, boolean)} instead. */ @UiThread + @Deprecated public void setZoomLevel(@FloatRange(from = 0.0, to = MAXIMUM_ZOOM_LEVEL) double zoomLevel, boolean animated) { if ((zoomLevel < 0.0) || (zoomLevel > MAXIMUM_ZOOM_LEVEL)) { throw new IllegalArgumentException("zoomLevel is < 0 or > MapView.MAXIMUM_ZOOM_LEVEL"); @@ -1558,7 +1633,7 @@ public final class MapView extends FrameLayout { * @return The current position of the Camera. */ public final CameraPosition getCameraPosition() { - return new CameraPosition(getCenterCoordinate(), (float) getZoomLevel(), (float) getTilt(), (float) getBearing()); + return new CameraPosition(getCenterCoordinate(), (float) getZoom(), (float) getTilt(), (float) getBearing()); } /** @@ -2480,7 +2555,7 @@ public final class MapView extends FrameLayout { */ @UiThread public double getMetersPerPixelAtLatitude(@FloatRange(from = -180, to = 180) double latitude) { - return mNativeMapView.getMetersPerPixelAtLatitude(latitude, getZoomLevel()) / mScreenDensity; + return mNativeMapView.getMetersPerPixelAtLatitude(latitude, getZoom()) / mScreenDensity; } /** @@ -2954,7 +3029,7 @@ public final class MapView extends FrameLayout { setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE); //noinspection ResourceType setMyBearingTrackingMode(MyBearingTracking.NONE); - }catch(SecurityException ignore){ + } catch (SecurityException ignore) { // User did not accept location permissions } @@ -3884,7 +3959,6 @@ public final class MapView extends FrameLayout { * or @link android.Manifest.permission#ACCESS_FINE_LOCATION. * * @param enabled True to enable; false to disable. - * * @throws SecurityException if no suitable permission is present */ @UiThread @@ -3928,16 +4002,15 @@ public final class MapView extends FrameLayout { * See {@link MyLocationTracking} for different values. * * @param myLocationTrackingMode The location tracking mode to be used. - * @see MyLocationTracking - * * @throws SecurityException if no suitable permission is present + * @see MyLocationTracking */ @UiThread @RequiresPermission(anyOf = { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}) public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) { - if(myLocationTrackingMode!=MyLocationTracking.TRACKING_NONE && !isMyLocationEnabled()){ + if (myLocationTrackingMode != MyLocationTracking.TRACKING_NONE && !isMyLocationEnabled()) { //noinspection ResourceType setMyLocationEnabled(true); } @@ -3985,16 +4058,15 @@ public final class MapView extends FrameLayout { * See {@link MyBearingTracking} for different values. * * @param myBearingTrackingMode The bearing tracking mode to be used. - * @see MyBearingTracking - * * @throws SecurityException if no suitable permission is present + * @see MyBearingTracking */ @UiThread @RequiresPermission(anyOf = { Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}) public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) { - if(myBearingTrackingMode!=MyBearingTracking.NONE && !isMyLocationEnabled()){ + if (myBearingTrackingMode != MyBearingTracking.NONE && !isMyLocationEnabled()) { //noinspection ResourceType setMyLocationEnabled(true); } @@ -4243,7 +4315,7 @@ public final class MapView extends FrameLayout { String url = context.getResources().getStringArray(R.array.attribution_links)[which]; if (which == ATTRIBUTION_INDEX_IMPROVE_THIS_MAP) { LatLng latLng = mMapView.getCenterCoordinate(); - url = String.format(url, latLng.getLongitude(), latLng.getLatitude(), (int) mMapView.getZoomLevel()); + url = String.format(url, latLng.getLongitude(), latLng.getLatitude(), (int) mMapView.getZoom()); } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml index 35696850b7..538e0afbf0 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml @@ -3,6 +3,7 @@ <declare-styleable name="MapView"> <attr name="center_longitude" format="float" /> <attr name="center_latitude" format="float" /> + <attr name="zoom" format="float" /> <attr name="zoom_level" format="float" /> <attr name="direction" format="float" /> <attr name="zoom_enabled" format="boolean" /> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java index ca2fa389b5..2c4e84302e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MainActivity.java @@ -478,7 +478,7 @@ public class MainActivity extends AppCompatActivity { @Override public void onMyLocationChange(@Nullable Location location) { if (location != null) { - mMapView.setZoomLevel(16); + mMapView.setZoom(16); mMapView.setCenterCoordinate(new LatLng(location)); mMapView.setOnMyLocationChangeListener(null); } @@ -507,7 +507,7 @@ public class MainActivity extends AppCompatActivity { addMarkers(); addPolyline(); addPolygon(); - mMapView.setZoomLevel(7); + mMapView.setZoom(7); mMapView.setCenterCoordinate(new LatLng(38.11727, -122.22839)); } } else { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java index 2eadedca2a..f3f61275e0 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/MapFragmentActivity.java @@ -50,7 +50,7 @@ public class MapFragmentActivity extends AppCompatActivity { MapView mapView = getMap(); mapView.setStyleUrl(Style.EMERALD); - mapView.setZoomLevel(12); + mapView.setZoom(12); mapView.setCenterCoordinate(new LatLng(50.853658, 4.352419)); // move attribution control to right of screen diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java index 1a4257c517..9e216d40f6 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/PressForMarkerActivity.java @@ -45,7 +45,7 @@ public class PressForMarkerActivity extends AppCompatActivity implements MapView mMapView.setStyleUrl(Style.EMERALD); mMapView.onCreate(savedInstanceState); mMapView.setCenterCoordinate(new LatLng(45.1855569, 5.7215506)); - mMapView.setZoomLevel(11); + mMapView.setZoom(11); mMapView.setOnMapLongClickListener(this); ((ViewGroup) findViewById(R.id.activity_container)).addView(mMapView); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java index ff0ad223f4..b7e1e2c548 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/TiltActivity.java @@ -35,7 +35,7 @@ public class TiltActivity extends AppCompatActivity { mMapView.setAccessToken(ApiAccess.getToken(this)); mMapView.setStyleUrl(Style.MAPBOX_STREETS); mMapView.setCenterCoordinate(dc); - mMapView.setZoomLevel(11); + mMapView.setZoom(11); mMapView.onCreate(savedInstanceState); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow.xml index c2c3210589..ac79fdfcb0 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow.xml @@ -19,6 +19,6 @@ app:style_url="@string/style_mapbox_streets" app:center_latitude="38.897705003219784" app:center_longitude="-77.03655168667463" - app:zoom_level="15" /> + app:zoom="15" /> </LinearLayout> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_adapter.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_adapter.xml index aee7834aaa..306225cff1 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_adapter.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_adapter.xml @@ -19,6 +19,6 @@ app:style_url="@string/style_mapbox_streets" app:center_latitude="47.798202" app:center_longitude="7.573781" - app:zoom_level="4" /> + app:zoom="4" /> </LinearLayout> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_concurrent.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_concurrent.xml index a1d36ac397..80fe54fe89 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_concurrent.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_infowindow_concurrent.xml @@ -19,6 +19,6 @@ app:style_url="@string/style_mapbox_streets" app:center_latitude="38.897705003219784" app:center_longitude="-77.03655168667463" - app:zoom_level="15" /> + app:zoom="15" /> </LinearLayout> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml index efca94e8a2..e48e5cfc1b 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_marker_bulk.xml @@ -26,6 +26,6 @@ app:center_latitude="38.897705003219784" app:center_longitude="-77.03655168667463" app:style_url="@string/style_mapbox_streets" - app:zoom_level="15" /> + app:zoom="15" /> </LinearLayout> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_my_location_tracking.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_my_location_tracking.xml index e526faeaa6..96d623481b 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_my_location_tracking.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_my_location_tracking.xml @@ -43,6 +43,6 @@ android:layout_width="match_parent" android:layout_height="match_parent" app:style_url="@string/style_mapbox_streets" - app:zoom_level="15" /> + app:zoom="15" /> </LinearLayout>
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_polyline.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_polyline.xml index 649190a132..48d0461e1e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_polyline.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_polyline.xml @@ -20,7 +20,7 @@ app:center_latitude="47.798202" app:center_longitude="7.573781" app:style_url="@string/style_mapbox_streets" - app:zoom_level="4" /> + app:zoom="4" /> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" |