diff --git a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/LocationLayerMapChangeActivity.java b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/LocationLayerMapChangeActivity.java index 8439cae5b..3857ae3fb 100644 --- a/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/LocationLayerMapChangeActivity.java +++ b/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/location/LocationLayerMapChangeActivity.java @@ -4,9 +4,6 @@ import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AppCompatActivity; -import com.mapbox.android.core.location.LocationEngine; -import com.mapbox.android.core.location.LocationEnginePriority; -import com.mapbox.android.core.location.LocationEngineProvider; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; @@ -27,11 +24,8 @@ public class LocationLayerMapChangeActivity extends AppCompatActivity implements FloatingActionButton stylesFab; private LocationLayerPlugin locationPlugin; - private LocationEngine locationEngine; private MapboxMap mapboxMap; - private boolean customStyle; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -46,11 +40,7 @@ protected void onCreate(Bundle savedInstanceState) { @Override public void onMapReady(MapboxMap mapboxMap) { this.mapboxMap = mapboxMap; - locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable(); - locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY); - locationEngine.setFastestInterval(1000); - locationEngine.activate(); - locationPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine); + locationPlugin = new LocationLayerPlugin(mapView, mapboxMap); locationPlugin.setRenderMode(RenderMode.COMPASS); getLifecycle().addObserver(locationPlugin); } @@ -67,9 +57,6 @@ public void onStyleFabClick() { protected void onStart() { super.onStart(); mapView.onStart(); - if (locationEngine != null) { - locationEngine.requestLocationUpdates(); - } } @Override @@ -87,9 +74,6 @@ protected void onPause() { @Override protected void onStop() { super.onStop(); - if (locationEngine != null) { - locationEngine.removeLocationUpdates(); - } mapView.onStop(); } @@ -103,9 +87,6 @@ protected void onSaveInstanceState(Bundle outState) { protected void onDestroy() { super.onDestroy(); mapView.onDestroy(); - if (locationEngine != null) { - locationEngine.deactivate(); - } } @Override diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java index 6649b8dc9..118b31a59 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java @@ -52,9 +52,9 @@ import static com.mapbox.mapboxsdk.plugins.locationlayer.Utils.generateShadow; import static com.mapbox.mapboxsdk.plugins.locationlayer.Utils.getBitmapFromDrawable; import static com.mapbox.mapboxsdk.plugins.locationlayer.Utils.getDrawable; -import static com.mapbox.mapboxsdk.style.expressions.Expression.exponential; import static com.mapbox.mapboxsdk.style.expressions.Expression.get; import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate; +import static com.mapbox.mapboxsdk.style.expressions.Expression.linear; import static com.mapbox.mapboxsdk.style.expressions.Expression.literal; import static com.mapbox.mapboxsdk.style.expressions.Expression.match; import static com.mapbox.mapboxsdk.style.expressions.Expression.stop; @@ -121,6 +121,7 @@ void applyStyle(@NonNull LocationLayerOptions options) { styleBackground(options); styleBearing(options); styleAccuracy(options.accuracyAlpha(), options.accuracyColor()); + styleScaling(options); } void setRenderMode(@RenderMode.Mode int renderMode) { @@ -196,12 +197,6 @@ private void addSymbolLayer(String layerId, String beforeLayerId) { layer.setProperties( iconAllowOverlap(true), iconIgnorePlacement(true), - iconSize( - interpolate(exponential(1f), zoom(), - stop(0f, 0.6f), - stop(18f, 1.2f) - ) - ), iconRotationAlignment(ICON_ROTATION_ALIGNMENT_MAP), iconRotate( match(literal(layerId), literal(0f), @@ -383,6 +378,21 @@ private void styleForegroundGPS(LocationLayerOptions options) { getDrawable(context, options.gpsDrawable(), options.foregroundStaleTintColor())); } + private void styleScaling(LocationLayerOptions options) { + for (Layer layer : layerMap.values()) { + if (layer instanceof SymbolLayer) { + layer.setProperties( + iconSize( + interpolate(linear(), zoom(), + stop(options.minZoom(), options.minZoomIconScale()), + stop(options.maxZoom(), options.maxZoomIconScale()) + ) + ) + ); + } + } + } + void setLocationsStale(boolean isStale) { // If options has stale state disabled, just return here. if (!options.enableStaleState()) { diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java index 8302dcac3..c203de754 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptions.java @@ -53,6 +53,16 @@ public abstract class LocationLayerOptions implements Parcelable { */ private static final float MIN_ZOOM_DEFAULT = 2; + /** + * Default icon scale factor when the map is zoomed out + */ + private static final float MIN_ZOOM_ICON_SCALE_DEFAULT = 0.6f; + + /** + * Default icon scale factor when the map is zoomed in + */ + private static final float MAX_ZOOM_ICON_SCALE_DEFAULT = 1f; + /** * Default map padding */ @@ -162,6 +172,13 @@ public static LocationLayerOptions createFromAttributes(@NonNull Context context builder.maxZoom(maxZoom); builder.minZoom(minZoom); + float minScale = typedArray.getFloat( + R.styleable.mapbox_LocationLayer_mapbox_minZoomIconScale, MIN_ZOOM_ICON_SCALE_DEFAULT); + float maxScale = typedArray.getFloat( + R.styleable.mapbox_LocationLayer_mapbox_maxZoomIconScale, MAX_ZOOM_ICON_SCALE_DEFAULT); + builder.minZoomIconScale(minScale); + builder.maxZoomIconScale(maxScale); + typedArray.recycle(); return builder.build(); @@ -200,6 +217,8 @@ private static Builder builder() { .staleStateTimeout(STALE_STATE_DELAY_MS) .maxZoom(MAX_ZOOM_DEFAULT) .minZoom(MIN_ZOOM_DEFAULT) + .maxZoomIconScale(MAX_ZOOM_ICON_SCALE_DEFAULT) + .minZoomIconScale(MIN_ZOOM_ICON_SCALE_DEFAULT) .padding(PADDING_DEFAULT); } @@ -405,6 +424,24 @@ private static Builder builder() { */ public abstract double minZoom(); + /** + * The scale factor of the location icon when the map is zoomed in. Based on {@link #maxZoom()}. + * Scaling is linear. + * + * @return icon scale factor + * @since 0.6.0 + */ + public abstract float maxZoomIconScale(); + + /** + * The scale factor of the location icon when the map is zoomed out. Based on {@link #minZoom()}. + * Scaling is linear. + * + * @return icon scale factor + * @since 0.6.0 + */ + public abstract float minZoomIconScale(); + /** * Minimum single pointer movement in pixels required to break camera tracking. * @@ -627,10 +664,35 @@ public abstract Builder maxZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, * Sets the minimum zoom level the map can be displayed at. * * @param minZoom The new minimum zoom level. + * @since 0.5.0 */ public abstract Builder minZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double minZoom); + /** + * Sets the scale factor of the location icon when the map is zoomed in. Based on {@link #maxZoom()}. + * Scaling is linear and the new pixel size of the image will be the original pixel size multiplied by the argument. + *
+ * Set both this and {@link #minZoomIconScale(float)} to 1f to disable location icon scaling. + *
+ * + * @param maxZoomIconScale icon scale factor + * @since 0.6.0 + */ + public abstract Builder maxZoomIconScale(float maxZoomIconScale); + + /** + * Sets the scale factor of the location icon when the map is zoomed out. Based on {@link #maxZoom()}. + * Scaling is linear and the new pixel size of the image will be the original pixel size multiplied by the argument. + *+ * Set both this and {@link #maxZoomIconScale(float)} to 1f to disable location icon scaling. + *
+ * + * @param minZoomIconScale icon scale factor + * @since 0.6.0 + */ + public abstract Builder minZoomIconScale(float minZoomIconScale); + /** * Sets minimum single pointer movement (map pan) in pixels required to break camera tracking. * diff --git a/plugin-locationlayer/src/main/res-public/values/public_attrs.xml b/plugin-locationlayer/src/main/res-public/values/public_attrs.xml index 73e897ab0..27469068f 100644 --- a/plugin-locationlayer/src/main/res-public/values/public_attrs.xml +++ b/plugin-locationlayer/src/main/res-public/values/public_attrs.xml @@ -35,6 +35,10 @@