setOpacity method

Future<void> setOpacity(
  1. String sourceId,
  2. double opacity
)

Real-time opacity adjustment for a geometry source using Expressions.

Implementation

Future<void> setOpacity(String sourceId, double opacity) async {
  final geoJson = _geoJsonCache[sourceId];
  if (geoJson != null && geoJson['features'] != null) {
    final features = geoJson['features'] as List<dynamic>;
    for (var f in features) {
      final props = f['properties'] as Map<String, dynamic>? ?? {};
      props['user_fillOpacity'] = opacity;
      props['user_lineOpacity'] = opacity;
      f['properties'] = props;
    }
    await updateGeoJson(sourceId, geoJson);
  }
}