addMarker method

Future addMarker(
  1. LatLng position, {
  2. String? color,
  3. String? iconImage,
  4. double size = 1.0,
  5. Map<String, dynamic>? data,
  6. double opacity = 1.0,
  7. double? iconRotate,
  8. String? iconAnchor,
})

Adds a customizable marker symbol to the MapLibre controller.

Returns the created Symbol or Circle object.

The optional opacity parameter (0.0 = transparent, 1.0 = fully visible) allows markers to be added in an invisible state and faded in later via setMarkersOpacity.

Implementation

Future<dynamic> addMarker(
  LatLng position, {
  String? color,
  String? iconImage,
  double size = 1.0,
  Map<String, dynamic>? data,
  double opacity = 1.0,
  double? iconRotate,
  String? iconAnchor,
}) async {
  // If a custom icon is NOT provided, we draw a high-accuracy GL Circle
  if (iconImage == null && color != null) {
    return await _controller.addCircle(
      CircleOptions(
        geometry: position,
        circleRadius: 8.0 * size,
        circleColor: color,
        circleOpacity: opacity,
        circleStrokeWidth: 2.0,
        circleStrokeColor: '#FFFFFF',
        circleStrokeOpacity: opacity,
      ),
      data,
    );
  }

  // Draw standard symbol (default or custom image)
  return await _controller.addSymbol(
    SymbolOptions(
      geometry: position,
      iconImage:
          iconImage ??
          'packages/powermap_sdk/assets/markers/marker-o.png', // fallback to web sdk default
      iconSize: size,
      iconColor: color, // Valid for SDF icons
      iconOpacity: opacity,
      iconRotate: iconRotate,
      iconAnchor: iconAnchor,
    ),
    data,
  );
}