Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix location puck getting hidden #956

Merged
merged 1 commit into from
Mar 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ public boolean onTouch(View v, MotionEvent event) {

@Override
public void setStyleString(String styleString) {
// clear old layer id from the location Component
clearLocationComponentLayer();

// Check if json, url, absolute path or asset path:
if (styleString == null || styleString.isEmpty()) {
Log.e(TAG, "setStyleString - string empty or null");
Expand All @@ -246,9 +249,7 @@ public void setStyleString(String styleString) {
public void onStyleLoaded(@NonNull Style style) {
MapboxMapController.this.style = style;

if (myLocationEnabled) {
enableLocationComponent(style);
}
updateMyLocationEnabled();

if (null != bounds) {
mapboxMap.setLatLngBoundsForCameraTarget(bounds);
Expand All @@ -266,24 +267,48 @@ public void onStyleLoaded(@NonNull Style style) {
private void enableLocationComponent(@NonNull Style style) {
if (hasLocationPermission()) {
locationEngine = LocationEngineProvider.getBestLocationEngine(context);
LocationComponentOptions locationComponentOptions =
LocationComponentOptions.builder(context).trackingGesturesManagement(true).build();
locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(context, style, locationComponentOptions);
locationComponent.activateLocationComponent(
context, style, buildLocationComponentOptions(style));
locationComponent.setLocationComponentEnabled(true);
// locationComponent.setRenderMode(RenderMode.COMPASS); // remove or keep default?
locationComponent.setLocationEngine(locationEngine);
locationComponent.setMaxAnimationFps(30);
updateMyLocationTrackingMode();
setMyLocationTrackingMode(this.myLocationTrackingMode);
updateMyLocationRenderMode();
setMyLocationRenderMode(this.myLocationRenderMode);
locationComponent.addOnCameraTrackingChangedListener(this);
} else {
Log.e(TAG, "missing location permissions");
}
}

private void updateLocationLocationComponentLayer() {
if (locationComponent != null && style != null) {
locationComponent.applyStyle(buildLocationComponentOptions(style));
}
}

private void clearLocationComponentLayer() {
if (locationComponent != null) {
locationComponent.applyStyle(buildLocationComponentOptions(null));
}
}

private LocationComponentOptions buildLocationComponentOptions(Style style) {
final LocationComponentOptions.Builder optionsBuilder =
LocationComponentOptions.builder(context);
optionsBuilder.trackingGesturesManagement(true);

if (style != null) {
final List<Layer> layers = style.getLayers();
if (layers.size() > 0) {
optionsBuilder.layerAbove(layers.get(layers.size() - 1).getId());
Log.i(TAG, layers.get(layers.size() - 1).getId());
}
}
return optionsBuilder.build();
}

private void onUserLocationUpdate(Location location) {
if (location == null) {
return;
Expand Down Expand Up @@ -798,6 +823,8 @@ public void onError(@NonNull String message) {
properties,
enableInteraction,
null);
updateLocationLocationComponentLayer();

result.success(null);
break;
}
Expand All @@ -822,6 +849,8 @@ public void onError(@NonNull String message) {
properties,
enableInteraction,
null);
updateLocationLocationComponentLayer();

result.success(null);
break;
}
Expand All @@ -846,6 +875,8 @@ public void onError(@NonNull String message) {
properties,
enableInteraction,
null);
updateLocationLocationComponentLayer();

result.success(null);
break;
}
Expand All @@ -870,6 +901,8 @@ public void onError(@NonNull String message) {
properties,
enableInteraction,
null);
updateLocationLocationComponentLayer();

result.success(null);
break;
}
Expand All @@ -890,6 +923,8 @@ public void onError(@NonNull String message) {
belowLayerId,
properties,
null);
updateLocationLocationComponentLayer();

result.success(null);
break;
}
Expand All @@ -910,6 +945,8 @@ public void onError(@NonNull String message) {
belowLayerId,
properties,
null);
updateLocationLocationComponentLayer();

result.success(null);
break;
}
Expand Down