set method

Future<void> set(
  1. T annotation
)

Updates (re-sets) an existing annotation quickly by only replacing its underlying GeoJSON feature if it remains on the same logical layer.

Implementation

Future<void> set(T annotation) async {
  assert(
    _idToAnnotation.containsKey(annotation.id),
    "you can only set existing annotations",
  );
  _idToAnnotation[annotation.id] = annotation;
  final oldLayerIndex = _idToLayerIndex[annotation.id];
  final layerIndex = selectLayer != null ? selectLayer!(annotation) : 0;
  if (oldLayerIndex != layerIndex) {
    // Layer changed; must rewrite all sources.
    await _setAll();
  } else {
    await controller.setGeoJsonFeature(
      _makeLayerId(layerIndex),
      annotation.toGeoJson(),
    );
  }
}