publish method

void publish(
  1. MapLayerHost host,
  2. List<MarkerSpec> specs, {
  3. MarkerTapHandler? onTap,
  4. MarkerTransition? transition,
  5. List<Polyline<Object>>? polylines,
})

Publishes specs as the layer's new generation. onTap receives the object id of a tapped marker of this generation; it replaces the previous handler when the generation reaches the map. polylines, when given, replace the layer's polylines (as MapLayerState.setPolylines) at the same time as the markers; when null the layer's polylines are left as they are.

Implementation

void publish(
  MapLayerHost host,
  List<MarkerSpec> specs, {
  MarkerTapHandler? onTap,
  MarkerTransition? transition,
  List<Polyline>? polylines,
}) {
  if (_disposed) return;
  final generation = ++_generation;
  final pixelRatio = host.pixelRatio;
  _followIcons(host, pixelRatio);
  assert(() {
    (_widgetKeyCheck ??= _WidgetKeyCheck(layerId)).check(specs);
    return true;
  }());
  final icons = <_IconKey, PlatformIcon>{};
  final requested = <_IconKey>{};
  final pending = <Future<void>>[];
  for (final spec in specs) {
    final key = (spec.iconKey, spec.size);
    if (!requested.add(key) || _failed.contains(key)) continue;
    final icon = _held[key] ?? host.icons.lookup(spec.iconKey, spec.size, pixelRatio);
    if (icon != null) {
      icons[key] = icon;
    } else {
      pending.add(
        _resolve(host, spec, pixelRatio).then((icon) {
          if (icon != null) icons[key] = icon;
        }),
      );
    }
  }
  void apply() => _apply(host, generation, specs, requested, icons, onTap, transition, polylines);
  if (pending.isEmpty) {
    apply();
    return;
  }
  unawaited(
    Future.wait(pending).then((_) {
      if (_disposed || generation != _generation) return;
      apply();
    }),
  );
}