Skip to content

Commit

Permalink
Revert "Support filtering on addLayer (flutter-mapbox-gl#1024)"
Browse files Browse the repository at this point in the history
This reverts commit 71c4de4.
  • Loading branch information
FreeGrow committed Sep 21, 2023
1 parent 43391dc commit a9bf86f
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 241 deletions.
43 changes: 5 additions & 38 deletions android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,6 @@ private void addSymbolLayer(
if (maxZoom != null) {
symbolLayer.setMaxZoom(maxZoom);
}
if (filter != null) {
symbolLayer.setFilter(filter);
}
if (belowLayerId != null) {
style.addLayerBelow(symbolLayer, belowLayerId);
} else {
Expand Down Expand Up @@ -438,9 +435,6 @@ private void addLineLayer(
if (maxZoom != null) {
lineLayer.setMaxZoom(maxZoom);
}
if (filter != null) {
lineLayer.setFilter(filter);
}
if (belowLayerId != null) {
style.addLayerBelow(lineLayer, belowLayerId);
} else {
Expand Down Expand Up @@ -472,9 +466,6 @@ private void addFillLayer(
if (maxZoom != null) {
fillLayer.setMaxZoom(maxZoom);
}
if (filter != null) {
fillLayer.setFilter(filter);
}
if (belowLayerId != null) {
style.addLayerBelow(fillLayer, belowLayerId);
} else {
Expand Down Expand Up @@ -506,9 +497,6 @@ private void addCircleLayer(
if (maxZoom != null) {
circleLayer.setMaxZoom(maxZoom);
}
if (filter != null) {
circleLayer.setFilter(filter);
}
if (belowLayerId != null) {
style.addLayerBelow(circleLayer, belowLayerId);
} else {
Expand All @@ -517,12 +505,7 @@ private void addCircleLayer(
if (enableInteraction) {
interactiveFeatureLayerIds.add(layerName);
}
}

private Expression parseFilter(String filter) {
JsonParser parser = new JsonParser();
JsonElement filterJsonElement = parser.parse(filter);
return filterJsonElement.isJsonNull() ? null : Expression.Converter.convert(filterJsonElement);
;
}

private void addRasterLayer(
Expand Down Expand Up @@ -842,13 +825,9 @@ public void onError(@NonNull String message) {
final String sourceLayer = call.argument("sourceLayer");
final Double minzoom = call.argument("minzoom");
final Double maxzoom = call.argument("maxzoom");
final String filter = call.argument("filter");
final boolean enableInteraction = call.argument("enableInteraction");
final PropertyValue[] properties =
LayerPropertyConverter.interpretSymbolLayerProperties(call.argument("properties"));

Expression filterExpression = parseFilter(filter);

addSymbolLayer(
layerId,
sourceId,
Expand All @@ -858,7 +837,7 @@ public void onError(@NonNull String message) {
maxzoom != null ? maxzoom.floatValue() : null,
properties,
enableInteraction,
filterExpression);
null);
updateLocationComponentLayer();

result.success(null);
Expand All @@ -872,13 +851,9 @@ public void onError(@NonNull String message) {
final String sourceLayer = call.argument("sourceLayer");
final Double minzoom = call.argument("minzoom");
final Double maxzoom = call.argument("maxzoom");
final String filter = call.argument("filter");
final boolean enableInteraction = call.argument("enableInteraction");
final PropertyValue[] properties =
LayerPropertyConverter.interpretLineLayerProperties(call.argument("properties"));

Expression filterExpression = parseFilter(filter);

addLineLayer(
layerId,
sourceId,
Expand All @@ -888,7 +863,7 @@ public void onError(@NonNull String message) {
maxzoom != null ? maxzoom.floatValue() : null,
properties,
enableInteraction,
filterExpression);
null);
updateLocationComponentLayer();

result.success(null);
Expand All @@ -902,13 +877,9 @@ public void onError(@NonNull String message) {
final String sourceLayer = call.argument("sourceLayer");
final Double minzoom = call.argument("minzoom");
final Double maxzoom = call.argument("maxzoom");
final String filter = call.argument("filter");
final boolean enableInteraction = call.argument("enableInteraction");
final PropertyValue[] properties =
LayerPropertyConverter.interpretFillLayerProperties(call.argument("properties"));

Expression filterExpression = parseFilter(filter);

addFillLayer(
layerId,
sourceId,
Expand All @@ -918,7 +889,7 @@ public void onError(@NonNull String message) {
maxzoom != null ? maxzoom.floatValue() : null,
properties,
enableInteraction,
filterExpression);
null);
updateLocationComponentLayer();

result.success(null);
Expand All @@ -932,13 +903,9 @@ public void onError(@NonNull String message) {
final String sourceLayer = call.argument("sourceLayer");
final Double minzoom = call.argument("minzoom");
final Double maxzoom = call.argument("maxzoom");
final String filter = call.argument("filter");
final boolean enableInteraction = call.argument("enableInteraction");
final PropertyValue[] properties =
LayerPropertyConverter.interpretCircleLayerProperties(call.argument("properties"));

Expression filterExpression = parseFilter(filter);

addCircleLayer(
layerId,
sourceId,
Expand All @@ -948,7 +915,7 @@ public void onError(@NonNull String message) {
maxzoom != null ? maxzoom.floatValue() : null,
properties,
enableInteraction,
filterExpression);
null);
updateLocationComponentLayer();

result.success(null);
Expand Down
2 changes: 1 addition & 1 deletion example/lib/layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class LayerState extends State {
'green'
], fillOpacity: 0.4),
belowLayerId: "water",
filter: ['==', 'id', filteredId],
);

await controller.addLineLayer(
Expand Down Expand Up @@ -144,6 +143,7 @@ class LayerState extends State {
controller.setGeoJsonSource("moving", _movingFeature(t.tick / 2000));
});

controller.setFilter('fills', ['==', 'id', filteredId]);
filterTimer = Timer.periodic(Duration(seconds: 3), (t) {
filteredId = filteredId == 0 ? 1 : 0;
controller.setFilter('fills', ['==', 'id', filteredId]);
Expand Down
Loading

0 comments on commit a9bf86f

Please sign in to comment.