addLayer method
Add a layer to the map with the given properties
The returned Future completes after the change has been made on the platform side.
Setting belowLayerId
adds the new layer below the given id.
If enableInteraction
is set the layer is considered for touch or drag
events this has no effect for RasterLayerProperties and
HillshadeLayerProperties.
sourceLayer
is used to selected a specific source layer from Vector
source.
minzoom
is the minimum (inclusive) zoom level at which the layer is
visible.
maxzoom
is the maximum (exclusive) zoom level at which the layer is
visible.
filter
determines which features should be rendered in the layer.
Filters are written as expressions
.
filter
is not supported by RasterLayer and HillshadeLayer.
Implementation
Future<void> addLayer(
String sourceId, String layerId, LayerProperties properties,
{String? belowLayerId,
bool enableInteraction = true,
String? sourceLayer,
double? minzoom,
double? maxzoom,
dynamic filter}) async {
if (properties is FillLayerProperties) {
addFillLayer(sourceId, layerId, properties,
belowLayerId: belowLayerId,
enableInteraction: enableInteraction,
sourceLayer: sourceLayer,
minzoom: minzoom,
maxzoom: maxzoom,
filter: filter);
} else if (properties is FillExtrusionLayerProperties) {
addFillExtrusionLayer(sourceId, layerId, properties,
belowLayerId: belowLayerId,
sourceLayer: sourceLayer,
minzoom: minzoom,
maxzoom: maxzoom);
} else if (properties is LineLayerProperties) {
addLineLayer(sourceId, layerId, properties,
belowLayerId: belowLayerId,
enableInteraction: enableInteraction,
sourceLayer: sourceLayer,
minzoom: minzoom,
maxzoom: maxzoom,
filter: filter);
} else if (properties is SymbolLayerProperties) {
addSymbolLayer(sourceId, layerId, properties,
belowLayerId: belowLayerId,
enableInteraction: enableInteraction,
sourceLayer: sourceLayer,
minzoom: minzoom,
maxzoom: maxzoom,
filter: filter);
} else if (properties is CircleLayerProperties) {
addCircleLayer(sourceId, layerId, properties,
belowLayerId: belowLayerId,
enableInteraction: enableInteraction,
sourceLayer: sourceLayer,
minzoom: minzoom,
maxzoom: maxzoom,
filter: filter);
} else if (properties is RasterLayerProperties) {
if (filter != null) {
throw UnimplementedError("RasterLayer does not support filter");
}
addRasterLayer(sourceId, layerId, properties,
belowLayerId: belowLayerId,
sourceLayer: sourceLayer,
minzoom: minzoom,
maxzoom: maxzoom);
} else if (properties is HillshadeLayerProperties) {
if (filter != null) {
throw UnimplementedError("HillShadeLayer does not support filter");
}
addHillshadeLayer(sourceId, layerId, properties,
belowLayerId: belowLayerId,
sourceLayer: sourceLayer,
minzoom: minzoom,
maxzoom: maxzoom);
} else if (properties is HeatmapLayerProperties) {
addHeatmapLayer(sourceId, layerId, properties,
belowLayerId: belowLayerId,
sourceLayer: sourceLayer,
minzoom: minzoom,
maxzoom: maxzoom);
} else {
throw UnimplementedError("Unknown layer type $properties");
}
}