diff --git a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java b/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java index d5fa47a8d..519462570 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java +++ b/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java @@ -348,6 +348,8 @@ private void addSymbolLayer( String sourceName, String belowLayerId, String sourceLayer, + Float minZoom, + Float maxZoom, PropertyValue[] properties, boolean enableInteraction, Expression filter) { @@ -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 { @@ -372,6 +379,8 @@ private void addLineLayer( String sourceName, String belowLayerId, String sourceLayer, + Float minZoom, + Float maxZoom, PropertyValue[] properties, boolean enableInteraction, Expression filter) { @@ -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 { @@ -396,6 +410,8 @@ private void addFillLayer( String sourceName, String belowLayerId, String sourceLayer, + Float minZoom, + Float maxZoom, PropertyValue[] properties, boolean enableInteraction, Expression filter) { @@ -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 { @@ -420,6 +441,8 @@ private void addCircleLayer( String sourceName, String belowLayerId, String sourceLayer, + Float minZoom, + Float maxZoom, PropertyValue[] properties, boolean enableInteraction, Expression filter) { @@ -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 { @@ -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 { @@ -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 { @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } diff --git a/example/lib/layer.dart b/example/lib/layer.dart index 80b4e7c2b..682a013de 100644 --- a/example/lib/layer.dart +++ b/example/lib/layer.dart @@ -133,6 +133,7 @@ class LayerState extends State { iconAllowOverlap: true, textAllowOverlap: true, ), + minzoom: 11, ); timer = Timer.periodic( Duration(milliseconds: 10), diff --git a/ios/Classes/MapboxMapController.swift b/ios/Classes/MapboxMapController.swift index f9b5978e0..f14c31863 100644 --- a/ios/Classes/MapboxMapController.swift +++ b/ios/Classes/MapboxMapController.swift @@ -340,11 +340,15 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma guard let enableInteraction = arguments["enableInteraction"] as? Bool else { return } let belowLayerId = arguments["belowLayerId"] as? String let sourceLayer = arguments["sourceLayer"] as? String + let minzoom = arguments["minzoom"] as? Double + let maxzoom = arguments["maxzoom"] as? Double addSymbolLayer( sourceId: sourceId, layerId: layerId, belowLayerId: belowLayerId, sourceLayerIdentifier: sourceLayer, + minimumZoomLevel: minzoom, + maximumZoomLevel: maxzoom, enableInteraction: enableInteraction, properties: properties ) @@ -358,11 +362,15 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma guard let enableInteraction = arguments["enableInteraction"] as? Bool else { return } let belowLayerId = arguments["belowLayerId"] as? String let sourceLayer = arguments["sourceLayer"] as? String + let minzoom = arguments["minzoom"] as? Double + let maxzoom = arguments["maxzoom"] as? Double addLineLayer( sourceId: sourceId, layerId: layerId, belowLayerId: belowLayerId, sourceLayerIdentifier: sourceLayer, + minimumZoomLevel: minzoom, + maximumZoomLevel: maxzoom, enableInteraction: enableInteraction, properties: properties ) @@ -376,11 +384,15 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma guard let enableInteraction = arguments["enableInteraction"] as? Bool else { return } let belowLayerId = arguments["belowLayerId"] as? String let sourceLayer = arguments["sourceLayer"] as? String + let minzoom = arguments["minzoom"] as? Double + let maxzoom = arguments["maxzoom"] as? Double addFillLayer( sourceId: sourceId, layerId: layerId, belowLayerId: belowLayerId, sourceLayerIdentifier: sourceLayer, + minimumZoomLevel: minzoom, + maximumZoomLevel: maxzoom, enableInteraction: enableInteraction, properties: properties ) @@ -394,11 +406,15 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma guard let enableInteraction = arguments["enableInteraction"] as? Bool else { return } let belowLayerId = arguments["belowLayerId"] as? String let sourceLayer = arguments["sourceLayer"] as? String + let minzoom = arguments["minzoom"] as? Double + let maxzoom = arguments["maxzoom"] as? Double addCircleLayer( sourceId: sourceId, layerId: layerId, belowLayerId: belowLayerId, sourceLayerIdentifier: sourceLayer, + minimumZoomLevel: minzoom, + maximumZoomLevel: maxzoom, enableInteraction: enableInteraction, properties: properties ) @@ -410,10 +426,14 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma guard let layerId = arguments["layerId"] as? String else { return } guard let properties = arguments["properties"] as? [String: String] else { return } let belowLayerId = arguments["belowLayerId"] as? String + let minzoom = arguments["minzoom"] as? Double + let maxzoom = arguments["maxzoom"] as? Double addHillshadeLayer( sourceId: sourceId, layerId: layerId, belowLayerId: belowLayerId, + minimumZoomLevel: minzoom, + maximumZoomLevel: maxzoom, properties: properties ) result(nil) @@ -424,10 +444,14 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma guard let layerId = arguments["layerId"] as? String else { return } guard let properties = arguments["properties"] as? [String: String] else { return } let belowLayerId = arguments["belowLayerId"] as? String + let minzoom = arguments["minzoom"] as? Double + let maxzoom = arguments["maxzoom"] as? Double addRasterLayer( sourceId: sourceId, layerId: layerId, belowLayerId: belowLayerId, + minimumZoomLevel: minzoom, + maximumZoomLevel: maxzoom, properties: properties ) result(nil) @@ -502,6 +526,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma guard let arguments = methodCall.arguments as? [String: Any] else { return } guard let imageLayerId = arguments["imageLayerId"] as? String else { return } guard let imageSourceId = arguments["imageSourceId"] as? String else { return } + let minzoom = arguments["minzoom"] as? Double + let maxzoom = arguments["maxzoom"] as? Double // Check for duplicateLayer error if (mapView.style?.layer(withIdentifier: imageLayerId)) != nil { @@ -523,6 +549,15 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma } let layer = MGLRasterStyleLayer(identifier: imageLayerId, source: source) + + if let minzoom = minzoom { + layer.minimumZoomLevel = Float(minzoom) + } + + if let maxzoom = maxzoom { + layer.maximumZoomLevel = Float(maxzoom) + } + mapView.style?.addLayer(layer) result(nil) case "style#addLayerBelow": @@ -530,6 +565,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma guard let imageLayerId = arguments["imageLayerId"] as? String else { return } guard let imageSourceId = arguments["imageSourceId"] as? String else { return } guard let belowLayerId = arguments["belowLayerId"] as? String else { return } + let minzoom = arguments["minzoom"] as? Double + let maxzoom = arguments["maxzoom"] as? Double // Check for duplicateLayer error if (mapView.style?.layer(withIdentifier: imageLayerId)) != nil { @@ -558,7 +595,17 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma )) return } + let layer = MGLRasterStyleLayer(identifier: imageLayerId, source: source) + + if let minzoom = minzoom { + layer.minimumZoomLevel = Float(minzoom) + } + + if let maxzoom = maxzoom { + layer.maximumZoomLevel = Float(maxzoom) + } + mapView.style?.insertLayer(layer, below: belowLayer) result(nil) @@ -570,11 +617,15 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma guard let properties = arguments["properties"] as? [String: String] else { return } let belowLayerId = arguments["belowLayerId"] as? String let sourceLayer = arguments["sourceLayer"] as? String + let minzoom = arguments["minzoom"] as? Double + let maxzoom = arguments["maxzoom"] as? Double addSymbolLayer( sourceId: sourceId, layerId: layerId, belowLayerId: belowLayerId, sourceLayerIdentifier: sourceLayer, + minimumZoomLevel: minzoom, + maximumZoomLevel: maxzoom, enableInteraction: enableInteraction, properties: properties ) @@ -588,11 +639,15 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma guard let properties = arguments["properties"] as? [String: String] else { return } let belowLayerId = arguments["belowLayerId"] as? String let sourceLayer = arguments["sourceLayer"] as? String + let minzoom = arguments["minzoom"] as? Double + let maxzoom = arguments["maxzoom"] as? Double addLineLayer( sourceId: sourceId, layerId: layerId, belowLayerId: belowLayerId, sourceLayerIdentifier: sourceLayer, + minimumZoomLevel: minzoom, + maximumZoomLevel: maxzoom, enableInteraction: enableInteraction, properties: properties ) @@ -606,11 +661,15 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma guard let properties = arguments["properties"] as? [String: String] else { return } let belowLayerId = arguments["belowLayerId"] as? String let sourceLayer = arguments["sourceLayer"] as? String + let minzoom = arguments["minzoom"] as? Double + let maxzoom = arguments["maxzoom"] as? Double addFillLayer( sourceId: sourceId, layerId: layerId, belowLayerId: belowLayerId, sourceLayerIdentifier: sourceLayer, + minimumZoomLevel: minzoom, + maximumZoomLevel: maxzoom, enableInteraction: enableInteraction, properties: properties ) @@ -624,11 +683,15 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma guard let properties = arguments["properties"] as? [String: String] else { return } let belowLayerId = arguments["belowLayerId"] as? String let sourceLayer = arguments["sourceLayer"] as? String + let minzoom = arguments["minzoom"] as? Double + let maxzoom = arguments["maxzoom"] as? Double addCircleLayer( sourceId: sourceId, layerId: layerId, belowLayerId: belowLayerId, sourceLayerIdentifier: sourceLayer, + minimumZoomLevel: minzoom, + maximumZoomLevel: maxzoom, enableInteraction: enableInteraction, properties: properties ) @@ -936,6 +999,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma layerId: String, belowLayerId: String?, sourceLayerIdentifier: String?, + minimumZoomLevel: Double?, + maximumZoomLevel: Double?, enableInteraction: Bool, properties: [String: String] ) { @@ -949,6 +1014,12 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma if let sourceLayerIdentifier = sourceLayerIdentifier { layer.sourceLayerIdentifier = sourceLayerIdentifier } + if let minimumZoomLevel = minimumZoomLevel { + layer.minimumZoomLevel = Float(minimumZoomLevel) + } + if let maximumZoomLevel = maximumZoomLevel { + layer.maximumZoomLevel = Float(maximumZoomLevel) + } if let id = belowLayerId, let belowLayer = style.layer(withIdentifier: id) { style.insertLayer(layer, below: belowLayer) } else { @@ -966,6 +1037,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma layerId: String, belowLayerId: String?, sourceLayerIdentifier: String?, + minimumZoomLevel: Double?, + maximumZoomLevel: Double?, enableInteraction: Bool, properties: [String: String] ) { @@ -976,6 +1049,12 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma if let sourceLayerIdentifier = sourceLayerIdentifier { layer.sourceLayerIdentifier = sourceLayerIdentifier } + if let minimumZoomLevel = minimumZoomLevel { + layer.minimumZoomLevel = Float(minimumZoomLevel) + } + if let maximumZoomLevel = maximumZoomLevel { + layer.maximumZoomLevel = Float(maximumZoomLevel) + } if let id = belowLayerId, let belowLayer = style.layer(withIdentifier: id) { style.insertLayer(layer, below: belowLayer) } else { @@ -993,6 +1072,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma layerId: String, belowLayerId: String?, sourceLayerIdentifier: String?, + minimumZoomLevel: Double?, + maximumZoomLevel: Double?, enableInteraction: Bool, properties: [String: String] ) { @@ -1003,6 +1084,12 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma if let sourceLayerIdentifier = sourceLayerIdentifier { layer.sourceLayerIdentifier = sourceLayerIdentifier } + if let minimumZoomLevel = minimumZoomLevel { + layer.minimumZoomLevel = Float(minimumZoomLevel) + } + if let maximumZoomLevel = maximumZoomLevel { + layer.maximumZoomLevel = Float(maximumZoomLevel) + } if let id = belowLayerId, let belowLayer = style.layer(withIdentifier: id) { style.insertLayer(layer, below: belowLayer) } else { @@ -1020,6 +1107,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma layerId: String, belowLayerId: String?, sourceLayerIdentifier: String?, + minimumZoomLevel: Double?, + maximumZoomLevel: Double?, enableInteraction: Bool, properties: [String: String] ) { @@ -1033,6 +1122,12 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma if let sourceLayerIdentifier = sourceLayerIdentifier { layer.sourceLayerIdentifier = sourceLayerIdentifier } + if let minimumZoomLevel = minimumZoomLevel { + layer.minimumZoomLevel = Float(minimumZoomLevel) + } + if let maximumZoomLevel = maximumZoomLevel { + layer.maximumZoomLevel = Float(maximumZoomLevel) + } if let id = belowLayerId, let belowLayer = style.layer(withIdentifier: id) { style.insertLayer(layer, below: belowLayer) } else { @@ -1049,6 +1144,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma sourceId: String, layerId: String, belowLayerId: String?, + minimumZoomLevel: Double?, + maximumZoomLevel: Double?, properties: [String: String] ) { if let style = mapView.style { @@ -1058,6 +1155,12 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma hillshadeLayer: layer, properties: properties ) + if let minimumZoomLevel = minimumZoomLevel { + layer.minimumZoomLevel = Float(minimumZoomLevel) + } + if let maximumZoomLevel = maximumZoomLevel { + layer.maximumZoomLevel = Float(maximumZoomLevel) + } if let id = belowLayerId, let belowLayer = style.layer(withIdentifier: id) { style.insertLayer(layer, below: belowLayer) } else { @@ -1071,6 +1174,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma sourceId: String, layerId: String, belowLayerId: String?, + minimumZoomLevel: Double?, + maximumZoomLevel: Double?, properties: [String: String] ) { if let style = mapView.style { @@ -1080,6 +1185,12 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma rasterLayer: layer, properties: properties ) + if let minimumZoomLevel = minimumZoomLevel { + layer.minimumZoomLevel = Float(minimumZoomLevel) + } + if let maximumZoomLevel = maximumZoomLevel { + layer.maximumZoomLevel = Float(maximumZoomLevel) + } if let id = belowLayerId, let belowLayer = style.layer(withIdentifier: id) { style.insertLayer(layer, below: belowLayer) } else { diff --git a/lib/src/controller.dart b/lib/src/controller.dart index 378a49d52..b11505ddc 100644 --- a/lib/src/controller.dart +++ b/lib/src/controller.dart @@ -340,6 +340,8 @@ class MapboxMapController extends ChangeNotifier { String sourceId, String layerId, SymbolLayerProperties properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, bool enableInteraction = true}) async { await _mapboxGlPlatform.addSymbolLayer( sourceId, @@ -347,6 +349,8 @@ class MapboxMapController extends ChangeNotifier { properties.toJson(), belowLayerId: belowLayerId, sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom, enableInteraction: enableInteraction, ); } @@ -366,6 +370,8 @@ class MapboxMapController extends ChangeNotifier { String sourceId, String layerId, LineLayerProperties properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, bool enableInteraction = true}) async { await _mapboxGlPlatform.addLineLayer( sourceId, @@ -373,6 +379,8 @@ class MapboxMapController extends ChangeNotifier { properties.toJson(), belowLayerId: belowLayerId, sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom, enableInteraction: enableInteraction, ); } @@ -392,6 +400,8 @@ class MapboxMapController extends ChangeNotifier { String sourceId, String layerId, FillLayerProperties properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, bool enableInteraction = true}) async { await _mapboxGlPlatform.addFillLayer( sourceId, @@ -399,6 +409,8 @@ class MapboxMapController extends ChangeNotifier { properties.toJson(), belowLayerId: belowLayerId, sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom, enableInteraction: enableInteraction, ); } @@ -418,6 +430,8 @@ class MapboxMapController extends ChangeNotifier { String sourceId, String layerId, CircleLayerProperties properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, bool enableInteraction = true}) async { await _mapboxGlPlatform.addCircleLayer( sourceId, @@ -425,6 +439,8 @@ class MapboxMapController extends ChangeNotifier { properties.toJson(), belowLayerId: belowLayerId, sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom, enableInteraction: enableInteraction, ); } @@ -441,13 +457,18 @@ class MapboxMapController extends ChangeNotifier { /// Raster source Future addRasterLayer( String sourceId, String layerId, RasterLayerProperties properties, - {String? belowLayerId, String? sourceLayer}) async { + {String? belowLayerId, + String? sourceLayer, + double? minzoom, + double? maxzoom}) async { await _mapboxGlPlatform.addRasterLayer( sourceId, layerId, properties.toJson(), belowLayerId: belowLayerId, sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom, ); } @@ -463,13 +484,18 @@ class MapboxMapController extends ChangeNotifier { /// Raster source Future addHillshadeLayer( String sourceId, String layerId, HillshadeLayerProperties properties, - {String? belowLayerId, String? sourceLayer}) async { + {String? belowLayerId, + String? sourceLayer, + double? minzoom, + double? maxzoom}) async { await _mapboxGlPlatform.addHillshadeLayer( sourceId, layerId, properties.toJson(), belowLayerId: belowLayerId, sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom, ); } @@ -1003,21 +1029,26 @@ class MapboxMapController extends ChangeNotifier { } /// Adds a Mapbox image layer to the map's style at render time. - Future addImageLayer(String layerId, String imageSourceId) { - return _mapboxGlPlatform.addLayer(layerId, imageSourceId); + Future addImageLayer(String layerId, String imageSourceId, + {double? minzoom, double? maxzoom}) { + return _mapboxGlPlatform.addLayer(layerId, imageSourceId, minzoom, maxzoom); } /// Adds a Mapbox image layer below the layer provided with belowLayerId to the map's style at render time. Future addImageLayerBelow( - String layerId, String sourceId, String imageSourceId) { - return _mapboxGlPlatform.addLayerBelow(layerId, sourceId, imageSourceId); + String layerId, String sourceId, String imageSourceId, + {double? minzoom, double? maxzoom}) { + return _mapboxGlPlatform.addLayerBelow( + layerId, sourceId, imageSourceId, minzoom, maxzoom); } /// Adds a Mapbox image layer below the layer provided with belowLayerId to the map's style at render time. Only works for image sources! @Deprecated("This method was renamed to addImageLayerBelow for clarity.") Future addLayerBelow( - String layerId, String sourceId, String imageSourceId) { - return _mapboxGlPlatform.addLayerBelow(layerId, sourceId, imageSourceId); + String layerId, String sourceId, String imageSourceId, + {double? minzoom, double? maxzoom}) { + return _mapboxGlPlatform.addLayerBelow( + layerId, sourceId, imageSourceId, minzoom, maxzoom); } /// Removes a Mapbox style layer @@ -1070,33 +1101,49 @@ class MapboxMapController extends ChangeNotifier { String sourceId, String layerId, LayerProperties properties, {String? belowLayerId, bool enableInteraction = true, - String? sourceLayer}) async { + String? sourceLayer, + double? minzoom, + double? maxzoom}) async { if (properties is FillLayerProperties) { addFillLayer(sourceId, layerId, properties, belowLayerId: belowLayerId, enableInteraction: enableInteraction, - sourceLayer: sourceLayer); + sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom); } else if (properties is LineLayerProperties) { addLineLayer(sourceId, layerId, properties, belowLayerId: belowLayerId, enableInteraction: enableInteraction, - sourceLayer: sourceLayer); + sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom); } else if (properties is SymbolLayerProperties) { addSymbolLayer(sourceId, layerId, properties, belowLayerId: belowLayerId, enableInteraction: enableInteraction, - sourceLayer: sourceLayer); + sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom); } else if (properties is CircleLayerProperties) { addCircleLayer(sourceId, layerId, properties, belowLayerId: belowLayerId, enableInteraction: enableInteraction, - sourceLayer: sourceLayer); + sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom); } else if (properties is RasterLayerProperties) { addRasterLayer(sourceId, layerId, properties, - belowLayerId: belowLayerId, sourceLayer: sourceLayer); + belowLayerId: belowLayerId, + sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom); } else if (properties is HillshadeLayerProperties) { addHillshadeLayer(sourceId, layerId, properties, - belowLayerId: belowLayerId, sourceLayer: sourceLayer); + belowLayerId: belowLayerId, + sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom); } else { throw UnimplementedError("Unknown layer type $properties"); } diff --git a/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart b/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart index 540e138de..48b319af4 100644 --- a/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart +++ b/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart @@ -78,9 +78,11 @@ abstract class MapboxGlPlatform { Future addImageSource( String imageSourceId, Uint8List bytes, LatLngQuad coordinates); - Future addLayer(String imageLayerId, String imageSourceId); - Future addLayerBelow( - String imageLayerId, String imageSourceId, String belowLayerId); + Future addLayer(String imageLayerId, String imageSourceId, + double? minzoom, double? maxzoom); + + Future addLayerBelow(String imageLayerId, String imageSourceId, + String belowLayerId, double? minzoom, double? maxzoom); Future removeLayer(String imageLayerId); @@ -106,33 +108,47 @@ abstract class MapboxGlPlatform { String sourceId, String layerId, Map properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, required bool enableInteraction}); Future addLineLayer( String sourceId, String layerId, Map properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, required bool enableInteraction}); Future addCircleLayer( String sourceId, String layerId, Map properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, required bool enableInteraction}); Future addFillLayer( String sourceId, String layerId, Map properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, required bool enableInteraction}); Future addRasterLayer( String sourceId, String layerId, Map properties, - {String? belowLayerId, String? sourceLayer}); + {String? belowLayerId, + String? sourceLayer, + double? minzoom, + double? maxzoom}); Future addHillshadeLayer( String sourceId, String layerId, Map properties, - {String? belowLayerId, String? sourceLayer}); + {String? belowLayerId, + String? sourceLayer, + double? minzoom, + double? maxzoom}); Future addSource(String sourceId, SourceProperties properties); diff --git a/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart b/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart index b53ef9100..0ef0ff788 100644 --- a/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart +++ b/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart @@ -393,11 +393,14 @@ class MethodChannelMapboxGl extends MapboxGlPlatform { } @override - Future addLayer(String imageLayerId, String imageSourceId) async { + Future addLayer(String imageLayerId, String imageSourceId, + double? minzoom, double? maxzoom) async { try { - return await _channel.invokeMethod('style#addLayer', { + return await _channel.invokeMethod('style#addLayer', { 'imageLayerId': imageLayerId, - 'imageSourceId': imageSourceId + 'imageSourceId': imageSourceId, + 'minzoom': minzoom, + 'maxzoom': maxzoom }); } on PlatformException catch (e) { return new Future.error(e); @@ -405,14 +408,16 @@ class MethodChannelMapboxGl extends MapboxGlPlatform { } @override - Future addLayerBelow( - String imageLayerId, String imageSourceId, String belowLayerId) async { + Future addLayerBelow(String imageLayerId, String imageSourceId, + String belowLayerId, double? minzoom, double? maxzoom) async { try { return await _channel - .invokeMethod('style#addLayerBelow', { + .invokeMethod('style#addLayerBelow', { 'imageLayerId': imageLayerId, 'imageSourceId': imageSourceId, - 'belowLayerId': belowLayerId + 'belowLayerId': belowLayerId, + 'minzoom': minzoom, + 'maxzoom': maxzoom }); } on PlatformException catch (e) { return new Future.error(e); @@ -479,12 +484,16 @@ class MethodChannelMapboxGl extends MapboxGlPlatform { String sourceId, String layerId, Map properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, required bool enableInteraction}) async { await _channel.invokeMethod('symbolLayer#add', { 'sourceId': sourceId, 'layerId': layerId, 'belowLayerId': belowLayerId, 'sourceLayer': sourceLayer, + 'minzoom': minzoom, + 'maxzoom': maxzoom, 'enableInteraction': enableInteraction, 'properties': properties .map((key, value) => MapEntry(key, jsonEncode(value))) @@ -496,12 +505,16 @@ class MethodChannelMapboxGl extends MapboxGlPlatform { String sourceId, String layerId, Map properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, required bool enableInteraction}) async { await _channel.invokeMethod('lineLayer#add', { 'sourceId': sourceId, 'layerId': layerId, 'belowLayerId': belowLayerId, 'sourceLayer': sourceLayer, + 'minzoom': minzoom, + 'maxzoom': maxzoom, 'enableInteraction': enableInteraction, 'properties': properties .map((key, value) => MapEntry(key, jsonEncode(value))) @@ -513,12 +526,16 @@ class MethodChannelMapboxGl extends MapboxGlPlatform { String sourceId, String layerId, Map properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, required bool enableInteraction}) async { await _channel.invokeMethod('circleLayer#add', { 'sourceId': sourceId, 'layerId': layerId, 'belowLayerId': belowLayerId, 'sourceLayer': sourceLayer, + 'minzoom': minzoom, + 'maxzoom': maxzoom, 'enableInteraction': enableInteraction, 'properties': properties .map((key, value) => MapEntry(key, jsonEncode(value))) @@ -530,12 +547,16 @@ class MethodChannelMapboxGl extends MapboxGlPlatform { String sourceId, String layerId, Map properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, required bool enableInteraction}) async { await _channel.invokeMethod('fillLayer#add', { 'sourceId': sourceId, 'layerId': layerId, 'belowLayerId': belowLayerId, 'sourceLayer': sourceLayer, + 'minzoom': minzoom, + 'maxzoom': maxzoom, 'enableInteraction': enableInteraction, 'properties': properties .map((key, value) => MapEntry(key, jsonEncode(value))) @@ -559,11 +580,16 @@ class MethodChannelMapboxGl extends MapboxGlPlatform { @override Future addRasterLayer( String sourceId, String layerId, Map properties, - {String? belowLayerId, String? sourceLayer}) async { + {String? belowLayerId, + String? sourceLayer, + double? minzoom, + double? maxzoom}) async { await _channel.invokeMethod('rasterLayer#add', { 'sourceId': sourceId, 'layerId': layerId, 'belowLayerId': belowLayerId, + 'minzoom': minzoom, + 'maxzoom': maxzoom, 'properties': properties .map((key, value) => MapEntry(key, jsonEncode(value))) }); @@ -572,11 +598,16 @@ class MethodChannelMapboxGl extends MapboxGlPlatform { @override Future addHillshadeLayer( String sourceId, String layerId, Map properties, - {String? belowLayerId, String? sourceLayer}) async { + {String? belowLayerId, + String? sourceLayer, + double? minzoom, + double? maxzoom}) async { await _channel.invokeMethod('hillshadeLayer#add', { 'sourceId': sourceId, 'layerId': layerId, 'belowLayerId': belowLayerId, + 'minzoom': minzoom, + 'maxzoom': maxzoom, 'properties': properties .map((key, value) => MapEntry(key, jsonEncode(value))) }); diff --git a/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart b/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart index d5ed42bd8..c08136cba 100644 --- a/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart +++ b/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart @@ -669,10 +669,14 @@ class MapboxWebGlPlatform extends MapboxGlPlatform String sourceId, String layerId, Map properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, required bool enableInteraction}) async { return _addLayer(sourceId, layerId, properties, "circle", belowLayerId: belowLayerId, sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom, enableInteraction: enableInteraction); } @@ -681,10 +685,14 @@ class MapboxWebGlPlatform extends MapboxGlPlatform String sourceId, String layerId, Map properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, required bool enableInteraction}) async { return _addLayer(sourceId, layerId, properties, "fill", belowLayerId: belowLayerId, sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom, enableInteraction: enableInteraction); } @@ -693,10 +701,14 @@ class MapboxWebGlPlatform extends MapboxGlPlatform String sourceId, String layerId, Map properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, required bool enableInteraction}) async { return _addLayer(sourceId, layerId, properties, "line", belowLayerId: belowLayerId, sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom, enableInteraction: enableInteraction); } @@ -705,30 +717,44 @@ class MapboxWebGlPlatform extends MapboxGlPlatform String sourceId, String layerId, Map properties, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, required bool enableInteraction}) async { return _addLayer(sourceId, layerId, properties, "symbol", belowLayerId: belowLayerId, sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom, enableInteraction: enableInteraction); } @override Future addHillshadeLayer( String sourceId, String layerId, Map properties, - {String? belowLayerId, String? sourceLayer}) async { + {String? belowLayerId, + String? sourceLayer, + double? minzoom, + double? maxzoom}) async { return _addLayer(sourceId, layerId, properties, "hillshade", belowLayerId: belowLayerId, sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom, enableInteraction: false); } @override Future addRasterLayer( String sourceId, String layerId, Map properties, - {String? belowLayerId, String? sourceLayer}) async { + {String? belowLayerId, + String? sourceLayer, + double? minzoom, + double? maxzoom}) async { await _addLayer(sourceId, layerId, properties, "raster", belowLayerId: belowLayerId, sourceLayer: sourceLayer, + minzoom: minzoom, + maxzoom: maxzoom, enableInteraction: false); } @@ -736,6 +762,8 @@ class MapboxWebGlPlatform extends MapboxGlPlatform Map properties, String layerType, {String? belowLayerId, String? sourceLayer, + double? minzoom, + double? maxzoom, required bool enableInteraction}) async { final layout = Map.fromEntries( properties.entries.where((entry) => isLayoutProperty(entry.key))); @@ -748,7 +776,9 @@ class MapboxWebGlPlatform extends MapboxGlPlatform 'source': sourceId, 'layout': layout, 'paint': paint, - if (sourceLayer != null) 'source-layer': sourceLayer + if (sourceLayer != null) 'source-layer': sourceLayer, + if (minzoom != null) 'minzoom': minzoom, + if (maxzoom != null) 'maxzoom': maxzoom, }, belowLayerId); if (enableInteraction) { @@ -839,14 +869,15 @@ class MapboxWebGlPlatform extends MapboxGlPlatform } @override - Future addLayer(String imageLayerId, String imageSourceId) { + Future addLayer(String imageLayerId, String imageSourceId, + double? minzoom, double? maxzoom) { // TODO: implement addLayer throw UnimplementedError(); } @override - Future addLayerBelow( - String imageLayerId, String imageSourceId, String belowLayerId) { + Future addLayerBelow(String imageLayerId, String imageSourceId, + String belowLayerId, double? minzoom, double? maxzoom) { // TODO: implement addLayerBelow throw UnimplementedError(); }