setOpacity method

Future<bool> setOpacity(
  1. String layerId,
  2. double opacity
)

Changes a layer's opacity.

Implementation

Future<bool> setOpacity(String layerId, double opacity) async {
  final properties = await _properties(layerId);
  final type = StyleLayerType.fromWireName(properties?['type'] as String?);
  if (type == null) return false;
  final property = switch (type) {
    StyleLayerType.fill => 'fill-opacity',
    StyleLayerType.line => 'line-opacity',
    StyleLayerType.symbol => 'text-opacity',
    StyleLayerType.circle => 'circle-opacity',
    StyleLayerType.background => 'background-opacity',
    StyleLayerType.raster => 'raster-opacity',
    StyleLayerType.hillshade => null,
    StyleLayerType.heatmap => 'heatmap-opacity',
    StyleLayerType.fillExtrusion => 'fill-extrusion-opacity',
  };
  if (property == null) return false;
  return _applyPaint(layerId, <String, Object?>{property: opacity});
}