expose LocationIndicatorLayer and an alternative rendering mode based on it
This commit is contained in:
@@ -140,6 +140,12 @@ public final class LocationComponent {
|
||||
*/
|
||||
private boolean isComponentInitialized;
|
||||
|
||||
/**
|
||||
* Indicates whether we're using the {@link com.mapbox.mapboxsdk.style.layers.LocationIndicatorLayer}
|
||||
* or the stack of {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer}s.
|
||||
*/
|
||||
private boolean useSpecializedLocationLayer;
|
||||
|
||||
/**
|
||||
* Indicates that the component is enabled and should be displaying location if Mapbox components are available and
|
||||
* the lifecycle is in a started state.
|
||||
@@ -341,7 +347,7 @@ public final class LocationComponent {
|
||||
@Deprecated
|
||||
public void activateLocationComponent(@NonNull Context context, @NonNull Style style,
|
||||
@NonNull LocationComponentOptions options) {
|
||||
initialize(context, style, options);
|
||||
initialize(context, style, false, options);
|
||||
initializeLocationEngine(context);
|
||||
applyStyle(options);
|
||||
}
|
||||
@@ -425,7 +431,7 @@ public final class LocationComponent {
|
||||
public void activateLocationComponent(@NonNull Context context, @NonNull Style style,
|
||||
@Nullable LocationEngine locationEngine,
|
||||
@NonNull LocationComponentOptions options) {
|
||||
initialize(context, style, options);
|
||||
initialize(context, style, false, options);
|
||||
setLocationEngine(locationEngine);
|
||||
applyStyle(options);
|
||||
}
|
||||
@@ -446,7 +452,7 @@ public final class LocationComponent {
|
||||
@Nullable LocationEngine locationEngine,
|
||||
@NonNull LocationEngineRequest locationEngineRequest,
|
||||
@NonNull LocationComponentOptions options) {
|
||||
initialize(context, style, options);
|
||||
initialize(context, style, false, options);
|
||||
setLocationEngineRequest(locationEngineRequest);
|
||||
setLocationEngine(locationEngine);
|
||||
applyStyle(options);
|
||||
@@ -470,7 +476,8 @@ public final class LocationComponent {
|
||||
|
||||
// Initialize the LocationComponent with Context, the map's `Style`, and either custom LocationComponentOptions
|
||||
// or backup options created from default/custom attributes
|
||||
initialize(activationOptions.context(), activationOptions.style(), options);
|
||||
initialize(activationOptions.context(), activationOptions.style(),
|
||||
activationOptions.useSpecializedLocationLayer(), options);
|
||||
|
||||
// Apply the LocationComponent styling
|
||||
// TODO avoid doubling style initialization
|
||||
@@ -1255,7 +1262,7 @@ public final class LocationComponent {
|
||||
mapboxMap.removeOnCameraIdleListener(onCameraIdleListener);
|
||||
}
|
||||
|
||||
private void initialize(@NonNull final Context context, @NonNull Style style,
|
||||
private void initialize(@NonNull final Context context, @NonNull Style style, boolean useSpecializedLocationLayer,
|
||||
@NonNull final LocationComponentOptions options) {
|
||||
if (isComponentInitialized) {
|
||||
return;
|
||||
@@ -1268,6 +1275,7 @@ public final class LocationComponent {
|
||||
|
||||
this.style = style;
|
||||
this.options = options;
|
||||
this.useSpecializedLocationLayer = useSpecializedLocationLayer;
|
||||
|
||||
mapboxMap.addOnMapClickListener(onMapClickListener);
|
||||
mapboxMap.addOnMapLongClickListener(onMapLongClickListener);
|
||||
@@ -1276,7 +1284,7 @@ public final class LocationComponent {
|
||||
LayerFeatureProvider featureProvider = new LayerFeatureProvider();
|
||||
LayerBitmapProvider bitmapProvider = new LayerBitmapProvider(context);
|
||||
locationLayerController = new LocationLayerController(mapboxMap, style, sourceProvider, featureProvider,
|
||||
bitmapProvider, options, renderModeChangedListener);
|
||||
bitmapProvider, options, renderModeChangedListener, useSpecializedLocationLayer);
|
||||
locationCameraController = new LocationCameraController(
|
||||
context, mapboxMap, transform, cameraTrackingChangedListener, options, onCameraMoveInvalidateListener);
|
||||
|
||||
@@ -1446,20 +1454,24 @@ public final class LocationComponent {
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private void updateLayerOffsets(boolean forceUpdate) {
|
||||
if (useSpecializedLocationLayer) {
|
||||
return;
|
||||
}
|
||||
|
||||
CameraPosition position = mapboxMap.getCameraPosition();
|
||||
if (lastCameraPosition == null || forceUpdate) {
|
||||
lastCameraPosition = position;
|
||||
locationLayerController.updateForegroundBearing((float) position.bearing);
|
||||
locationLayerController.updateForegroundOffset(position.tilt);
|
||||
locationLayerController.cameraBearingUpdated(position.bearing);
|
||||
locationLayerController.cameraTiltUpdated(position.tilt);
|
||||
updateAccuracyRadius(getLastKnownLocation(), true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (position.bearing != lastCameraPosition.bearing) {
|
||||
locationLayerController.updateForegroundBearing((float) position.bearing);
|
||||
locationLayerController.cameraBearingUpdated(position.bearing);
|
||||
}
|
||||
if (position.tilt != lastCameraPosition.tilt) {
|
||||
locationLayerController.updateForegroundOffset(position.tilt);
|
||||
locationLayerController.cameraTiltUpdated(position.tilt);
|
||||
}
|
||||
if (position.zoom != lastCameraPosition.zoom) {
|
||||
updateAccuracyRadius(getLastKnownLocation(), true);
|
||||
@@ -1468,7 +1480,15 @@ public final class LocationComponent {
|
||||
}
|
||||
|
||||
private void updateAccuracyRadius(Location location, boolean noAnimation) {
|
||||
locationAnimatorCoordinator.feedNewAccuracyRadius(Utils.calculateZoomLevelRadius(mapboxMap, location), noAnimation);
|
||||
float radius;
|
||||
if (location == null) {
|
||||
radius = 0;
|
||||
} else if (useSpecializedLocationLayer) {
|
||||
radius = location.getAccuracy();
|
||||
} else {
|
||||
radius = Utils.calculateZoomLevelRadius(mapboxMap, location);
|
||||
}
|
||||
locationAnimatorCoordinator.feedNewAccuracyRadius(radius, noAnimation);
|
||||
}
|
||||
|
||||
private void updateAnimatorListenerHolders() {
|
||||
|
||||
Reference in New Issue
Block a user