Skip to content

Commit

Permalink
Add support for layer zoom limits (#934)
Browse files Browse the repository at this point in the history
  • Loading branch information
morvagergely authored Mar 8, 2022
1 parent feb2770 commit 4867ed7
Show file tree
Hide file tree
Showing 7 changed files with 408 additions and 52 deletions.
153 changes: 136 additions & 17 deletions android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ private void addSymbolLayer(
String sourceName,
String belowLayerId,
String sourceLayer,
Float minZoom,
Float maxZoom,
PropertyValue[] properties,
boolean enableInteraction,
Expression filter) {
Expand All @@ -356,7 +358,12 @@ private void addSymbolLayer(
if (sourceLayer != null) {
symbolLayer.setSourceLayer(sourceLayer);
}

if (minZoom != null) {
symbolLayer.setMinZoom(minZoom);
}
if (maxZoom != null) {
symbolLayer.setMaxZoom(maxZoom);
}
if (belowLayerId != null) {
style.addLayerBelow(symbolLayer, belowLayerId);
} else {
Expand All @@ -372,6 +379,8 @@ private void addLineLayer(
String sourceName,
String belowLayerId,
String sourceLayer,
Float minZoom,
Float maxZoom,
PropertyValue[] properties,
boolean enableInteraction,
Expression filter) {
Expand All @@ -380,7 +389,12 @@ private void addLineLayer(
if (sourceLayer != null) {
lineLayer.setSourceLayer(sourceLayer);
}

if (minZoom != null) {
lineLayer.setMinZoom(minZoom);
}
if (maxZoom != null) {
lineLayer.setMaxZoom(maxZoom);
}
if (belowLayerId != null) {
style.addLayerBelow(lineLayer, belowLayerId);
} else {
Expand All @@ -396,6 +410,8 @@ private void addFillLayer(
String sourceName,
String belowLayerId,
String sourceLayer,
Float minZoom,
Float maxZoom,
PropertyValue[] properties,
boolean enableInteraction,
Expression filter) {
Expand All @@ -404,7 +420,12 @@ private void addFillLayer(
if (sourceLayer != null) {
fillLayer.setSourceLayer(sourceLayer);
}

if (minZoom != null) {
fillLayer.setMinZoom(minZoom);
}
if (maxZoom != null) {
fillLayer.setMaxZoom(maxZoom);
}
if (belowLayerId != null) {
style.addLayerBelow(fillLayer, belowLayerId);
} else {
Expand All @@ -420,6 +441,8 @@ private void addCircleLayer(
String sourceName,
String belowLayerId,
String sourceLayer,
Float minZoom,
Float maxZoom,
PropertyValue[] properties,
boolean enableInteraction,
Expression filter) {
Expand All @@ -428,7 +451,12 @@ private void addCircleLayer(
if (sourceLayer != null) {
circleLayer.setSourceLayer(sourceLayer);
}

if (minZoom != null) {
circleLayer.setMinZoom(minZoom);
}
if (maxZoom != null) {
circleLayer.setMaxZoom(maxZoom);
}
if (belowLayerId != null) {
style.addLayerBelow(circleLayer, belowLayerId);
} else {
Expand All @@ -443,12 +471,19 @@ private void addCircleLayer(
private void addRasterLayer(
String layerName,
String sourceName,
Float minZoom,
Float maxZoom,
String belowLayerId,
PropertyValue[] properties,
Expression filter) {
RasterLayer layer = new RasterLayer(layerName, sourceName);
layer.setProperties(properties);

if (minZoom != null) {
layer.setMinZoom(minZoom);
}
if (maxZoom != null) {
layer.setMaxZoom(maxZoom);
}
if (belowLayerId != null) {
style.addLayerBelow(layer, belowLayerId);
} else {
Expand All @@ -459,12 +494,19 @@ private void addRasterLayer(
private void addHillshadeLayer(
String layerName,
String sourceName,
Float minZoom,
Float maxZoom,
String belowLayerId,
PropertyValue[] properties,
Expression filter) {
HillshadeLayer layer = new HillshadeLayer(layerName, sourceName);
layer.setProperties(properties);

if (minZoom != null) {
layer.setMinZoom(minZoom);
}
if (maxZoom != null) {
layer.setMaxZoom(maxZoom);
}
if (belowLayerId != null) {
style.addLayerBelow(layer, belowLayerId);
} else {
Expand Down Expand Up @@ -741,11 +783,21 @@ public void onError(@NonNull String message) {
final String layerId = call.argument("layerId");
final String belowLayerId = call.argument("belowLayerId");
final String sourceLayer = call.argument("sourceLayer");
final Double minzoom = call.argument("minzoom");
final Double maxzoom = call.argument("maxzoom");
final boolean enableInteraction = call.argument("enableInteraction");
final PropertyValue[] properties =
LayerPropertyConverter.interpretSymbolLayerProperties(call.argument("properties"));
addSymbolLayer(
layerId, sourceId, belowLayerId, sourceLayer, properties, enableInteraction, null);
layerId,
sourceId,
belowLayerId,
sourceLayer,
minzoom != null ? minzoom.floatValue() : null,
maxzoom != null ? maxzoom.floatValue() : null,
properties,
enableInteraction,
null);
result.success(null);
break;
}
Expand All @@ -755,11 +807,21 @@ public void onError(@NonNull String message) {
final String layerId = call.argument("layerId");
final String belowLayerId = call.argument("belowLayerId");
final String sourceLayer = call.argument("sourceLayer");
final Double minzoom = call.argument("minzoom");
final Double maxzoom = call.argument("maxzoom");
final boolean enableInteraction = call.argument("enableInteraction");
final PropertyValue[] properties =
LayerPropertyConverter.interpretLineLayerProperties(call.argument("properties"));
addLineLayer(
layerId, sourceId, belowLayerId, sourceLayer, properties, enableInteraction, null);
layerId,
sourceId,
belowLayerId,
sourceLayer,
minzoom != null ? minzoom.floatValue() : null,
maxzoom != null ? maxzoom.floatValue() : null,
properties,
enableInteraction,
null);
result.success(null);
break;
}
Expand All @@ -769,11 +831,21 @@ public void onError(@NonNull String message) {
final String layerId = call.argument("layerId");
final String belowLayerId = call.argument("belowLayerId");
final String sourceLayer = call.argument("sourceLayer");
final Double minzoom = call.argument("minzoom");
final Double maxzoom = call.argument("maxzoom");
final boolean enableInteraction = call.argument("enableInteraction");
final PropertyValue[] properties =
LayerPropertyConverter.interpretFillLayerProperties(call.argument("properties"));
addFillLayer(
layerId, sourceId, belowLayerId, sourceLayer, properties, enableInteraction, null);
layerId,
sourceId,
belowLayerId,
sourceLayer,
minzoom != null ? minzoom.floatValue() : null,
maxzoom != null ? maxzoom.floatValue() : null,
properties,
enableInteraction,
null);
result.success(null);
break;
}
Expand All @@ -783,11 +855,21 @@ public void onError(@NonNull String message) {
final String layerId = call.argument("layerId");
final String belowLayerId = call.argument("belowLayerId");
final String sourceLayer = call.argument("sourceLayer");
final Double minzoom = call.argument("minzoom");
final Double maxzoom = call.argument("maxzoom");
final boolean enableInteraction = call.argument("enableInteraction");
final PropertyValue[] properties =
LayerPropertyConverter.interpretCircleLayerProperties(call.argument("properties"));
addCircleLayer(
layerId, sourceId, belowLayerId, sourceLayer, properties, enableInteraction, null);
layerId,
sourceId,
belowLayerId,
sourceLayer,
minzoom != null ? minzoom.floatValue() : null,
maxzoom != null ? maxzoom.floatValue() : null,
properties,
enableInteraction,
null);
result.success(null);
break;
}
Expand All @@ -796,9 +878,18 @@ public void onError(@NonNull String message) {
final String sourceId = call.argument("sourceId");
final String layerId = call.argument("layerId");
final String belowLayerId = call.argument("belowLayerId");
final Double minzoom = call.argument("minzoom");
final Double maxzoom = call.argument("maxzoom");
final PropertyValue[] properties =
LayerPropertyConverter.interpretRasterLayerProperties(call.argument("properties"));
addRasterLayer(layerId, sourceId, belowLayerId, properties, null);
addRasterLayer(
layerId,
sourceId,
minzoom != null ? minzoom.floatValue() : null,
maxzoom != null ? maxzoom.floatValue() : null,
belowLayerId,
properties,
null);
result.success(null);
break;
}
Expand All @@ -807,9 +898,18 @@ public void onError(@NonNull String message) {
final String sourceId = call.argument("sourceId");
final String layerId = call.argument("layerId");
final String belowLayerId = call.argument("belowLayerId");
final Double minzoom = call.argument("minzoom");
final Double maxzoom = call.argument("maxzoom");
final PropertyValue[] properties =
LayerPropertyConverter.interpretHillshadeLayerProperties(call.argument("properties"));
addHillshadeLayer(layerId, sourceId, belowLayerId, properties, null);
addHillshadeLayer(
layerId,
sourceId,
minzoom != null ? minzoom.floatValue() : null,
maxzoom != null ? maxzoom.floatValue() : null,
belowLayerId,
properties,
null);
result.success(null);
break;
}
Expand Down Expand Up @@ -907,8 +1007,18 @@ public void onFailure(@NonNull Exception exception) {
"The style is null. Has onStyleLoaded() already been invoked?",
null);
}
style.addLayer(
new RasterLayer(call.argument("imageLayerId"), call.argument("imageSourceId")));
addRasterLayer(
call.argument("imageLayerId"),
call.argument("imageSourceId"),
call.argument("minzoom") != null
? ((Double) call.argument("minzoom")).floatValue()
: null,
call.argument("maxzoom") != null
? ((Double) call.argument("maxzoom")).floatValue()
: null,
null,
new PropertyValue[] {},
null);
result.success(null);
break;
}
Expand All @@ -920,9 +1030,18 @@ public void onFailure(@NonNull Exception exception) {
"The style is null. Has onStyleLoaded() already been invoked?",
null);
}
style.addLayerBelow(
new RasterLayer(call.argument("imageLayerId"), call.argument("imageSourceId")),
call.argument("belowLayerId"));
addRasterLayer(
call.argument("imageLayerId"),
call.argument("imageSourceId"),
call.argument("minzoom") != null
? ((Double) call.argument("minzoom")).floatValue()
: null,
call.argument("maxzoom") != null
? ((Double) call.argument("maxzoom")).floatValue()
: null,
call.argument("belowLayerId"),
new PropertyValue[] {},
null);
result.success(null);
break;
}
Expand Down
1 change: 1 addition & 0 deletions example/lib/layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class LayerState extends State {
iconAllowOverlap: true,
textAllowOverlap: true,
),
minzoom: 11,
);
timer = Timer.periodic(
Duration(milliseconds: 10),
Expand Down
Loading

0 comments on commit 4867ed7

Please sign in to comment.