From c9962ab13957000df9c547227fd400b376142010 Mon Sep 17 00:00:00 2001
From: danesfeder
+ * This plugin also offers the ability to set a map camera behavior for tracking the user
+ * location. These different {@link CameraMode}s will track, stop tracking the location based on the
+ * mode set with {@link LocationLayerPlugin#setCameraMode(int)}.
*
* Lastly, {@link LocationLayerPlugin#setLocationLayerEnabled(boolean)} can be used
* to disable the Location Layer but keep the instance around till the activity is destroyed.
@@ -50,9 +52,7 @@
*
* @since 0.1.0
*/
-public final class LocationLayerPlugin implements LocationEngineListener, CompassListener,
- OnMapChangedListener, LifecycleObserver, OnCameraMoveListener, OnMapClickListener,
- OnLocationStaleListener {
+public final class LocationLayerPlugin implements LifecycleObserver {
private final MapboxMap mapboxMap;
private final MapView mapView;
@@ -74,10 +74,10 @@ public final class LocationLayerPlugin implements LocationEngineListener, Compas
= new CopyOnWriteArrayList<>();
/**
- * Construct a {@code LocationLayerPlugin}
+ * Construct a LocationLayerPlugin
*
- * @param mapView the MapView to apply the My Location layer plugin to
- * @param mapboxMap the MapboxMap to apply the My Location layer plugin with
+ * @param mapView the MapView to apply the LocationLayerPlugin to
+ * @param mapboxMap the MapboxMap to apply the LocationLayerPlugin with
* @param locationEngine the {@link LocationEngine} this plugin should use to update
* @since 0.1.0
*/
@@ -88,10 +88,10 @@ public LocationLayerPlugin(@NonNull MapView mapView, @NonNull MapboxMap mapboxMa
}
/**
- * Construct a {@code LocationLayerPlugin}
+ * Construct a LocationLayerPlugin
*
- * @param mapView the MapView to apply the My Location layer plugin to
- * @param mapboxMap the MapboxMap to apply the My Location layer plugin with
+ * @param mapView the MapView to apply the LocationLayerPlugin to
+ * @param mapboxMap the MapboxMap to apply the LocationLayerPlugin with
* @param locationEngine the {@link LocationEngine} this plugin should use to update
* @param styleRes customize the user location icons inside your apps {@code style.xml}
* @since 0.1.0
@@ -102,6 +102,15 @@ public LocationLayerPlugin(@NonNull MapView mapView, @NonNull MapboxMap mapboxMa
LocationLayerOptions.createFromAttributes(mapView.getContext(), styleRes));
}
+ /**
+ * Construct a LocationLayerPlugin
+ *
+ * @param mapView the MapView to apply the LocationLayerPlugin to
+ * @param mapboxMap the MapboxMap to apply the LocationLayerPlugin with
+ * @param locationEngine the {@link LocationEngine} this plugin should use to update
+ * @param options to customize the user location icons inside your apps
+ * @since 0.3.0
+ */
public LocationLayerPlugin(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap,
@Nullable LocationEngine locationEngine,
LocationLayerOptions options) {
@@ -112,25 +121,13 @@ public LocationLayerPlugin(@NonNull MapView mapView, @NonNull MapboxMap mapboxMa
initialize();
}
- private void initialize() {
- AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
-
- mapView.addOnMapChangedListener(this);
- mapboxMap.addOnMapClickListener(this);
-
- compassManager = new CompassManager(mapView.getContext());
- compassManager.addCompassListener(this);
- staleStateRunnable = new StaleStateRunnable(this, options.staleStateDelay());
-
- locationLayer = new LocationLayer(mapView, mapboxMap, options);
- locationLayerCamera = new LocationLayerCamera(mapboxMap);
- locationLayerAnimator = new LocationLayerAnimator();
- locationLayerAnimator.addListener(locationLayer);
- locationLayerAnimator.addListener(locationLayerCamera);
-
- enableLocationLayerPlugin();
- }
-
+ /**
+ * This method will show or hide the location icon and enable or disable the camera
+ * tracking the location.
+ *
+ * @param isEnabled true to show layers and enable camera, false otherwise
+ * @since 0.5.0
+ */
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
public void setLocationLayerEnabled(boolean isEnabled) {
if (isEnabled) {
@@ -140,110 +137,128 @@ public void setLocationLayerEnabled(boolean isEnabled) {
}
}
- private void enableLocationLayerPlugin() {
- isEnabled = true;
-
- if (locationEngine != null) {
- locationEngine.addLocationEngineListener(this);
- }
- setLastLocation();
- setLastCompassHeading();
- locationLayer.show();
- }
-
- private void disableLocationLayerPlugin() {
- isEnabled = false;
-
- if (locationEngine != null) {
- locationEngine.removeLocationEngineListener(this);
- }
- locationLayer.hide();
- }
-
/**
- * After creating an instance of this plugin, you can use this API to enable the location mode of
- * your choice. These modes can be found in the {@link LocationLayerMode} class and the parameter
- * only accepts one of those modes. Note that before enabling the My Location layer, you will need
- * to ensure that you have the requested the required user location permissions.
+ * Sets the camera mode, which determines how the map camera will track the rendered location.
*
*
+ *
- *
*
- * @param locationLayerMode one of the modes found in {@link LocationLayerMode}
- * @since 0.1.0
+ * @param cameraMode one of the modes found in {@link CameraMode}
+ * @since 0.5.0
*/
public void setCameraMode(@CameraMode.Mode int cameraMode) {
locationLayerCamera.setCameraMode(cameraMode);
}
+ /**
+ * Provides the current camera mode being used to track
+ * the location or compass updates.
+ *
+ * @return the current camera mode
+ * @since 0.5.0
+ */
@CameraMode.Mode
public int getCameraMode() {
return locationLayerCamera.getCameraMode();
}
+ /**
+ * Sets the render mode, which determines how the location updates will be rendered on the map.
+ *
+ *
+ *
+ * @param renderMode one of the modes found in {@link RenderMode}
+ * @since 0.5.0
+ */
public void setRenderMode(@RenderMode.Mode int renderMode) {
locationLayer.setRenderMode(renderMode);
}
+
+ /**
+ * Provides the current render mode being used to show
+ * the location and/or compass updates on the map.
+ *
+ * @return the current render mode
+ * @since 0.5.0
+ */
@RenderMode.Mode
public int getRenderMode() {
return locationLayer.getRenderMode();
}
/**
- * Returns the current location mode being used with this plugin.
+ * Returns the current location options being used.
*
- * @return on of the {@link LocationLayerMode} values
- * @since 0.1.0
+ * @return the current {@link LocationLayerOptions}
+ * @since 0.4.0
*/
public LocationLayerOptions getLocationLayerOptions() {
return options;
}
- @Override
- public void onMapChanged(int change) {
- if (change == MapView.WILL_START_LOADING_MAP) {
- locationLayerAnimator.cancelAllAnimations();
- } else if (change == MapView.DID_FINISH_LOADING_STYLE) {
- mapStyleFinishedLoading();
- }
- }
-
- @Override
- public void onStaleStateChange(boolean isStale) {
- locationLayer.setLocationsStale(isStale);
-
- for (OnLocationStaleListener listener : onLocationStaleListeners) {
- listener.onStaleStateChange(isStale);
- }
- }
-
/**
- * Apply a new Location Layer style after the {@link LocationLayerPlugin} has been constructed.
+ * Apply a new LocationLayer style with a style resource.
*
* @param styleRes a XML style overriding some or all the options
- * @since 0.1.0
+ * @since 0.4.0
*/
public void applyStyle(@StyleRes int styleRes) {
applyStyle(LocationLayerOptions.createFromAttributes(mapView.getContext(), styleRes));
}
+ /**
+ * Apply a new LocationLayer style with location layer options.
+ *
+ * @param options to update the current style
+ * @since 0.4.0
+ */
public void applyStyle(LocationLayerOptions options) {
locationLayer.applyStyle(options);
if (!options.enableStaleState()) {
staleStateRunnable.onStop();
}
- staleStateRunnable.setDelayTime(options.staleStateDelay());
+ staleStateRunnable.setDelayTime(options.staleStateTimeout());
+ }
+
+ /**
+ * Sets the distance from the edges of the map view’s frame to the edges of the map
+ * view’s logical viewport.
+ *
+ * When the value of this property is equal to {0,0,0,0}, viewport + * properties such as `centerCoordinate` assume a viewport that matches the map + * view’s frame. Otherwise, those properties are inset, excluding part of the + * frame from the viewport. For instance, if the only the top edge is inset, the + * map center is effectively shifted downward. + *
+ * + * @param left The left margin in pixels. + * @param top The top margin in pixels. + * @param right The right margin in pixels. + * @param bottom The bottom margin in pixels. + * @since 0.5.0 + */ + public void setPadding(int left, int top, int right, int bottom) { + mapboxMap.setPadding(left, top, right, bottom); } /** * Use to either force a location update or to manually control when the user location gets * updated. * - * @param location where you'd like the location icon to be placed on the map + * @param location where the location icon is placed on the map * @since 0.1.0 */ public void forceLocationUpdate(@Nullable Location location) { @@ -251,8 +266,9 @@ public void forceLocationUpdate(@Nullable Location location) { } /** - * The {@link LocationEngine} the plugin will use to update it's position. If {@code null} is - * passed in, all updates will occur through the + * Set the location engine to update the current user location. + *+ * If {@code null} is passed in, all updates will occur through the * {@link LocationLayerPlugin#forceLocationUpdate(Location)} method. * * @param locationEngine a {@link LocationEngine} this plugin should use to handle updates @@ -263,7 +279,7 @@ public void setLocationEngine(@Nullable LocationEngine locationEngine) { if (locationEngine != null) { this.locationEngine = locationEngine; } else if (this.locationEngine != null) { - this.locationEngine.removeLocationEngineListener(this); + this.locationEngine.removeLocationEngineListener(locationEngineListener); this.locationEngine = null; } } @@ -280,46 +296,15 @@ public LocationEngine getLocationEngine() { } /** - * Required to place inside your activities {@code onStart} method. You'll also most likely want - * to check that this Location Layer plugin instance inside your activity is null or not. - * - * @since 0.1.0 - */ - @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) - @OnLifecycleEvent(Lifecycle.Event.ON_START) - public void onStart() { - if (isEnabled) { - if (locationEngine != null) { - locationEngine.addLocationEngineListener(this); - } - setLastLocation(); - setLastCompassHeading(); - } - if (mapboxMap != null) { - mapboxMap.addOnCameraMoveListener(this); - } - if (options.enableStaleState()) { - staleStateRunnable.onStart(); - } - compassManager.onStart(); - } - - /** - * Required to place inside your activities {@code onStop} method. + * Get the last know location of the location layer plugin. * - * @since 0.1.0 + * @return the last known location + * @since 0.4.0 */ - @OnLifecycleEvent(Lifecycle.Event.ON_STOP) - public void onStop() { - staleStateRunnable.onStop(); - compassManager.onStop(); - locationLayerAnimator.cancelAllAnimations(); - if (locationEngine != null) { - locationEngine.removeLocationEngineListener(this); - } - if (mapboxMap != null) { - mapboxMap.removeOnCameraMoveListener(this); - } + @SuppressLint("MissingPermission") + @Nullable + public Location getLastKnownLocation() { + return locationEngine != null ? locationEngine.getLastLocation() : null; } /** @@ -355,93 +340,117 @@ public void addOnLocationClickListener(@NonNull OnLocationLayerClickListener loc onLocationLayerClickListeners.add(locationClickListener); } + /** + * Removes the passed listener from the current list of location click listeners. + * + * @param locationClickListener to be removed + * @since 0.3.0 + */ public void removeOnLocationClickListener(@NonNull OnLocationLayerClickListener locationClickListener) { onLocationLayerClickListeners.remove(locationClickListener); } + /** + * Adds the passed listener that gets invoked when user updates have stopped long enough for the last update + * to be considered stale. + * + * @param listener invoked when last update is considered stale + * @since 0.5.0 + */ public void addOnLocationStaleListener(@NonNull OnLocationStaleListener listener) { onLocationStaleListeners.add(listener); } + /** + * Removes the passed listener from the current list of stale listeners. + * + * @param listener to be removed from the list + * @since 0.5.0 + */ public void removeOnLocationStaleListener(@NonNull OnLocationStaleListener listener) { onLocationStaleListeners.remove(listener); } - @Override - public void onMapClick(@NonNull LatLng point) { - if (!onLocationLayerClickListeners.isEmpty() && locationLayer.onMapClick(point)) { - for (OnLocationLayerClickListener listener : onLocationLayerClickListeners) { - listener.onLocationLayerClick(); + /** + * Required to place inside your activities {@code onStart} method. You'll also most likely want + * to check that this Location Layer plugin instance inside your activity is null or not. + * + * @since 0.1.0 + */ + @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + @OnLifecycleEvent(Lifecycle.Event.ON_START) + public void onStart() { + if (isEnabled) { + if (locationEngine != null) { + locationEngine.addLocationEngineListener(locationEngineListener); } + setLastLocation(); + setLastCompassHeading(); } + if (mapboxMap != null) { + mapboxMap.addOnCameraMoveListener(onCameraMoveListener); + } + if (options.enableStaleState()) { + staleStateRunnable.onStart(); + } + compassManager.onStart(); } - @Override - @SuppressWarnings( {"MissingPermission"}) - public void onConnected() { + /** + * Required to place inside your activities {@code onStop} method. + * + * @since 0.1.0 + */ + @OnLifecycleEvent(Lifecycle.Event.ON_STOP) + public void onStop() { + staleStateRunnable.onStop(); + compassManager.onStop(); + locationLayerAnimator.cancelAllAnimations(); if (locationEngine != null) { - locationEngine.requestLocationUpdates(); + locationEngine.removeLocationEngineListener(locationEngineListener); + } + if (mapboxMap != null) { + mapboxMap.removeOnCameraMoveListener(onCameraMoveListener); } } - @Override - public void onLocationChanged(Location location) { - updateLocation(location); - } + private void initialize() { + AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); - @Override - public void onCompassChanged(float userHeading) { - updateCompassHeading(userHeading); - } + mapView.addOnMapChangedListener(onMapChangedListener); + mapboxMap.addOnMapClickListener(onMapClickListener); - @Override - public void onCompassAccuracyChange(int compassStatus) { - // Currently don't handle this inside SDK - } + compassManager = new CompassManager(mapView.getContext()); + compassManager.addCompassListener(compassListener); + staleStateRunnable = new StaleStateRunnable(onLocationStaleListener, options.staleStateTimeout()); - /** - * If the locationEngine contains a last location value, we use it for the initial location layer - * position. - */ - @SuppressWarnings( {"MissingPermission"}) - private void setLastLocation() { - if (locationEngine != null) { - updateLocation(locationEngine.getLastLocation()); - } - } + locationLayer = new LocationLayer(mapView, mapboxMap, options); + locationLayerCamera = new LocationLayerCamera(mapboxMap); + locationLayerAnimator = new LocationLayerAnimator(); + locationLayerAnimator.addListener(locationLayer); + locationLayerAnimator.addListener(locationLayerCamera); - private void setLastCompassHeading() { - updateCompassHeading(compassManager.getLastHeading()); + enableLocationLayerPlugin(); } - /** - * Get the last know location of the location layer plugin. - * - * @return the last known location - */ - @SuppressLint("MissingPermission") - @Nullable - public Location getLastKnownLocation() { - return locationEngine != null ? locationEngine.getLastLocation() : null; - } + private void enableLocationLayerPlugin() { + isEnabled = true; - /** - * If the location layer was being displayed before the style change, it will need to be displayed - * in the new style. - */ - @SuppressWarnings( {"MissingPermission"}) - private void mapStyleFinishedLoading() { - // recreate runtime style components - locationLayer = new LocationLayer(mapView, mapboxMap, options); + if (locationEngine != null) { + locationEngine.addLocationEngineListener(locationEngineListener); + } setLastLocation(); setLastCompassHeading(); + locationLayer.show(); } - @Override - public void onCameraMove() { - CameraPosition position = mapboxMap.getCameraPosition(); - locationLayer.updateAccuracyRadius(getLastKnownLocation()); - locationLayer.updateForegroundOffset(position.tilt); + private void disableLocationLayerPlugin() { + isEnabled = false; + + if (locationEngine != null) { + locationEngine.removeLocationEngineListener(locationEngineListener); + } + locationLayer.hide(); } /** @@ -466,4 +475,100 @@ private void updateLocation(final Location location) { private void updateCompassHeading(float heading) { locationLayerAnimator.feedNewCompassBearing(compassManager.getLastHeading(), heading); } + + /** + * If the location layer was being displayed before the style change, it will need to be displayed + * in the new style. + */ + @SuppressWarnings( {"MissingPermission"}) + private void mapStyleFinishedLoading() { + // recreate runtime style components + locationLayer = new LocationLayer(mapView, mapboxMap, options); + setLastLocation(); + setLastCompassHeading(); + } + + /** + * If the locationEngine contains a last location value, we use it for the initial location layer + * position. + */ + @SuppressWarnings( {"MissingPermission"}) + private void setLastLocation() { + if (locationEngine != null) { + updateLocation(locationEngine.getLastLocation()); + } + } + + private void setLastCompassHeading() { + updateCompassHeading(compassManager.getLastHeading()); + } + + private OnCameraMoveListener onCameraMoveListener = new OnCameraMoveListener() { + @Override + public void onCameraMove() { + CameraPosition position = mapboxMap.getCameraPosition(); + locationLayer.updateAccuracyRadius(getLastKnownLocation()); + locationLayer.updateForegroundOffset(position.tilt); + } + }; + + private OnMapClickListener onMapClickListener = new OnMapClickListener() { + @Override + public void onMapClick(@NonNull LatLng point) { + if (!onLocationLayerClickListeners.isEmpty() && locationLayer.onMapClick(point)) { + for (OnLocationLayerClickListener listener : onLocationLayerClickListeners) { + listener.onLocationLayerClick(); + } + } + } + }; + + private OnLocationStaleListener onLocationStaleListener = new OnLocationStaleListener() { + @Override + public void onStaleStateChange(boolean isStale) { + locationLayer.setLocationsStale(isStale); + + for (OnLocationStaleListener listener : onLocationStaleListeners) { + listener.onStaleStateChange(isStale); + } + } + }; + + private OnMapChangedListener onMapChangedListener = new OnMapChangedListener() { + @Override + public void onMapChanged(int change) { + if (change == MapView.WILL_START_LOADING_MAP) { + locationLayerAnimator.cancelAllAnimations(); + } else if (change == MapView.DID_FINISH_LOADING_STYLE) { + mapStyleFinishedLoading(); + } + } + }; + + private CompassListener compassListener = new CompassListener() { + @Override + public void onCompassChanged(float userHeading) { + updateCompassHeading(userHeading); + } + + @Override + public void onCompassAccuracyChange(int compassStatus) { + // Currently don't handle this inside SDK + } + }; + + private LocationEngineListener locationEngineListener = new LocationEngineListener() { + @Override + @SuppressWarnings( {"MissingPermission"}) + public void onConnected() { + if (locationEngine != null) { + locationEngine.requestLocationUpdates(); + } + } + + @Override + public void onLocationChanged(Location location) { + updateLocation(location); + } + }; } diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationStaleListener.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationStaleListener.java index 99a1a6d2e..7389dd945 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationStaleListener.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/OnLocationStaleListener.java @@ -1,5 +1,15 @@ package com.mapbox.mapboxsdk.plugins.locationlayer; +/** + * Listener that can be added as a callback when the last location update + * is considered stale. + *
+ * The time from the last location update that determines if a location update
+ * is stale or not is provided by {@link LocationLayerOptions#staleStateTimeout()}.
+ *
+ * @since 0.5.0
+ */
public interface OnLocationStaleListener {
+
void onStaleStateChange(boolean isStale);
}
diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/StaleStateRunnable.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/StaleStateRunnable.java
index 0f288a36d..3b91d11f4 100644
--- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/StaleStateRunnable.java
+++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/StaleStateRunnable.java
@@ -1,14 +1,10 @@
package com.mapbox.mapboxsdk.plugins.locationlayer;
import android.os.Handler;
-import android.support.annotation.NonNull;
-
-import java.util.ArrayList;
-import java.util.List;
/**
* Class controls the location layer stale state when the {@link android.location.Location} hasn't
- * been updated in 'x' amount of time. {@link LocationLayerOptions#staleStateDelay()} can be used to
+ * been updated in 'x' amount of time. {@link LocationLayerOptions#staleStateTimeout()} can be used to
* control the amount of time before the locations considered stale.
* {@link LocationLayerOptions#enableStaleState()} is available for disabling this behaviour.
*
diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/CameraMode.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/CameraMode.java
index 6672ea2e8..68692a429 100644
--- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/CameraMode.java
+++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/CameraMode.java
@@ -9,9 +9,10 @@
import java.lang.annotation.RetentionPolicy;
/**
- * Contains the variety of Location Layer modes which shape the behavior of the plugin.
+ * Contains the variety of camera modes which determine how the camera will track
+ * the user location.
*
- * @since 0.1.0
+ * @since 0.5.0
*/
public final class CameraMode {
@@ -22,7 +23,7 @@ private CameraMode() {
/**
* Determine the camera tracking behavior in the {@link LocationLayerPlugin}.
*
- * @since 0.4.0
+ * @since 0.5.0
*/
@IntDef( {NONE, NONE_COMPASS, NONE_GPS, TRACKING, TRACKING_COMPASS, TRACKING_GPS, TRACKING_GPS_NORTH})
@Retention(RetentionPolicy.SOURCE)
@@ -32,28 +33,28 @@ private CameraMode() {
/**
* No camera tracking.
*
- * @since 0.4.0
+ * @since 0.5.0
*/
public static final int NONE = 0x00000000;
/**
* Camera does not track location, but does track compass bearing.
*
- * @since 0.4.0
+ * @since 0.5.0
*/
public static final int NONE_COMPASS = 0x00000010;
/**
* Camera does not track location, but does track GPS {@link Location} bearing.
*
- * @since 0.4.0
+ * @since 0.5.0
*/
public static final int NONE_GPS = 0x00000016;
/**
* Camera tracks the user location.
*
- * @since 0.4.0
+ * @since 0.5.0
*/
public static final int TRACKING = 0x00000018;
@@ -61,7 +62,7 @@ private CameraMode() {
* Camera tracks the user location, with bearing
* provided by a compass.
*
- * @since 0.4.0
+ * @since 0.5.0
*/
public static final int TRACKING_COMPASS = 0x00000020;
@@ -69,7 +70,7 @@ private CameraMode() {
* Camera tracks the user location, with bearing
* provided by a normalized {@link Location#getBearing()}.
*
- * @since 0.4.0
+ * @since 0.5.0
*/
public static final int TRACKING_GPS = 0x00000022;
@@ -78,7 +79,7 @@ private CameraMode() {
* Camera tracks the user location, with bearing
* always set to north (0).
*
- * @since 0.4.0
+ * @since 0.5.0
*/
public static final int TRACKING_GPS_NORTH = 0x00000024;
}
diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/RenderMode.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/RenderMode.java
index a7326410f..3928689b6 100644
--- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/RenderMode.java
+++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/modes/RenderMode.java
@@ -8,9 +8,9 @@
import java.lang.annotation.RetentionPolicy;
/**
- * Contains the variety of Location Layer modes which shape the behavior of the plugin.
+ * Contains the variety of ways the user location can be rendered on the map.
*
- * @since 0.1.0
+ * @since 0.5.0
*/
public final class RenderMode {
@@ -19,9 +19,8 @@ private RenderMode() {
}
/**
- * One of these constants should be used when
- * {@link LocationLayerPlugin#setLocationLayerMode(int)}'s called. The
- * mode can be switched at anytime by calling the {@code setLocationLayerMode} method passing
+ * One of these constants should be used with {@link LocationLayerPlugin#setRenderMode(int)}.
+ *mode can be switched at anytime by calling the {@code setLocationLayerMode} method passing
* in the new mode you'd like the location layer to be in.
*
* @since 0.1.0
diff --git a/plugin-locationlayer/src/main/res/values/attrs.xml b/plugin-locationlayer/src/main/res/values/attrs.xml
index 475feeb4e..5623ba972 100644
--- a/plugin-locationlayer/src/main/res/values/attrs.xml
+++ b/plugin-locationlayer/src/main/res/values/attrs.xml
@@ -20,7 +20,7 @@
+ * When the value of this property is equal to {0,0,0,0}, viewport + * properties such as `centerCoordinate` assume a viewport that matches the map + * view’s frame. Otherwise, those properties are inset, excluding part of the + * frame from the viewport. For instance, if the only the top edge is inset, the + * map center is effectively shifted downward. + *
+ * + * @return integer array of padding values + * @since 0.5.0 + */ + public abstract int[] padding(); + + /** + * The maximum zoom level the map can be displayed at. + * + * @return the maximum zoom level + * @since 0.5.0 + */ + public abstract double maxZoom(); + + /** + * The minimum zoom level the map can be displayed at. + * + * @return the minimum zoom level + * @since 0.5.0 + */ + public abstract double minZoom(); + /** * Builder class for constructing a new instance of {@link LocationLayerOptions}. * @@ -493,6 +526,39 @@ public abstract static class Builder { */ public abstract Builder staleStateTimeout(long timeout); + /** + * Sets the distance from the edges of the map view’s frame to the edges of the map + * view’s logical viewport. + * + *+ * When the value of this property is equal to {0,0,0,0}, viewport + * properties such as `centerCoordinate` assume a viewport that matches the map + * view’s frame. Otherwise, those properties are inset, excluding part of the + * frame from the viewport. For instance, if the only the top edge is inset, the + * map center is effectively shifted downward. + *
+ * + * @param padding The margins for the map in pixels (left, top, right, bottom). + * @since 0.5.0 + */ + public abstract Builder setPadding(int[] padding); + + /** + * Sets the maximum zoom level the map can be displayed at. + *+ * The default maximum zoomn level is 22. The upper bound for this value is 25.5. + * + * @param maxZoom The new maximum zoom level. + * @since 0.5.0 + */ + public abstract Builder setMaxZoom(double maxZoom); + + /** + * Sets the minimum zoom level the map can be displayed at. + * + * @param minZoom The new minimum zoom level. + */ + public abstract Builder setMinZoom(double minZoom); abstract LocationLayerOptions autoBuild(); diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java index 1f626b7b1..c4ca3f750 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java @@ -256,6 +256,27 @@ public void setPadding(int left, int top, int right, int bottom) { mapboxMap.setPadding(left, top, right, bottom); } + /** + * Sets the maximum zoom level the map can be displayed at. + *
+ * The default maximum zoom level is 22. The upper bound for this value is 25.5.
+ *
+ * @param maxZoom The new maximum zoom level.
+ * @since 0.5.0
+ */
+ public void setMaxZoom(double maxZoom) {
+ mapboxMap.setMaxZoomPreference(maxZoom);
+ }
+
+ /**
+ * Sets the minimum zoom level the map can be displayed at.
+ *
+ * @param minZoom The new minimum zoom level.
+ */
+ public void setMinZoom(double minZoom) {
+ mapboxMap.setMinZoomPreference(minZoom);
+ }
+
/**
* Use to either force a location update or to manually control when the user location gets
* updated.
@@ -443,6 +464,7 @@ private void initialize() {
mapView.addOnMapChangedListener(onMapChangedListener);
mapboxMap.addOnMapClickListener(onMapClickListener);
mapboxMap.addOnMapLongClickListener(onMapLongClickListener);
+ updateMapWithOptions(options);
compassManager = new CompassManager(mapView.getContext());
compassManager.addCompassListener(compassListener);
@@ -477,6 +499,19 @@ private void disableLocationLayerPlugin() {
locationLayer.hide();
}
+ private void updateMapWithOptions(LocationLayerOptions options) {
+ int[] padding = options.padding();
+ if (options.padding() != null && options.padding().length == 4) {
+ setPadding(options.padding()[0], padding[1], padding[2], padding[3]);
+ }
+ if (options.maxZoom() > 0) {
+ setMaxZoom(options.maxZoom());
+ }
+ if (options.minZoom() > 0) {
+ setMinZoom(options.minZoom());
+ }
+ }
+
/**
* Updates the user location icon.
*
From 2d2952475b1259356ccaa986bdaa0d094b11c979 Mon Sep 17 00:00:00 2001
From: danesfeder
*
- * <<<<<<< HEAD
- *
*
* @param renderMode one of the modes found in {@link RenderMode}
@@ -326,12 +320,10 @@ public LocationEngine getLocationEngine() {
}
/**
- * <<<<<<< HEAD
* Get the last know location of the location layer plugin.
*
* @return the last known location
* @since 0.1.0
- * >>>>>>> map-location-animators
*/
@SuppressLint("MissingPermission")
@Nullable
From 31a5b699a109d2f31d5ed56d1518774572e8563d Mon Sep 17 00:00:00 2001
From: danesfeder