Skip to content

Commit

Permalink
Revert "fix for LocationComponent update issue (flutter-mapbox-gl#969)"
Browse files Browse the repository at this point in the history
This reverts commit 256b5aa.
  • Loading branch information
FreeGrow committed Sep 21, 2023
1 parent 457860c commit 8e8bda7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
42 changes: 14 additions & 28 deletions android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ private void enableLocationComponent(@NonNull Style style) {
}
}

private void updateLocationComponentLayer() {
if (locationComponent != null && locationComponentRequiresUpdate()) {
private void updateLocationLocationComponentLayer() {
if (locationComponent != null && style != null) {
locationComponent.applyStyle(buildLocationComponentOptions(style));
}
}
Expand All @@ -293,31 +293,17 @@ private void clearLocationComponentLayer() {
}
}

String getLastLayerOnStyle(Style style) {
if (style != null) {
final List<Layer> layers = style.getLayers();

if (layers.size() > 0) {
return layers.get(layers.size() - 1).getId();
}
}
return null;
}

/// only update if the last layer is not the mapbox-location-bearing-layer
boolean locationComponentRequiresUpdate() {
final String lastLayerId = getLastLayerOnStyle(style);
return lastLayerId != null && !lastLayerId.equals("mapbox-location-bearing-layer");
}

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

final String lastLayerId = getLastLayerOnStyle(style);
if (lastLayerId != null) {
optionsBuilder.layerAbove(lastLayerId);
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();
}
Expand Down Expand Up @@ -836,7 +822,7 @@ public void onError(@NonNull String message) {
properties,
enableInteraction,
null);
updateLocationComponentLayer();
updateLocationLocationComponentLayer();

result.success(null);
break;
Expand All @@ -862,7 +848,7 @@ public void onError(@NonNull String message) {
properties,
enableInteraction,
null);
updateLocationComponentLayer();
updateLocationLocationComponentLayer();

result.success(null);
break;
Expand All @@ -888,7 +874,7 @@ public void onError(@NonNull String message) {
properties,
enableInteraction,
null);
updateLocationComponentLayer();
updateLocationLocationComponentLayer();

result.success(null);
break;
Expand All @@ -914,7 +900,7 @@ public void onError(@NonNull String message) {
properties,
enableInteraction,
null);
updateLocationComponentLayer();
updateLocationLocationComponentLayer();

result.success(null);
break;
Expand All @@ -936,7 +922,7 @@ public void onError(@NonNull String message) {
belowLayerId,
properties,
null);
updateLocationComponentLayer();
updateLocationLocationComponentLayer();

result.success(null);
break;
Expand All @@ -958,7 +944,7 @@ public void onError(@NonNull String message) {
belowLayerId,
properties,
null);
updateLocationComponentLayer();
updateLocationLocationComponentLayer();

result.success(null);
break;
Expand Down
1 change: 0 additions & 1 deletion example/lib/layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class LayerState extends State {
return MapboxMap(
accessToken: MapsDemo.ACCESS_TOKEN,
dragEnabled: false,
myLocationEnabled: true,
onMapCreated: _onMapCreated,
onMapClick: (point, latLong) =>
print(point.toString() + latLong.toString()),
Expand Down

0 comments on commit 8e8bda7

Please sign in to comment.