MarkerUpdates.update constructor

MarkerUpdates.update(
  1. Set<Marker> previous,
  2. Set<Marker> current
)

Implementation

MarkerUpdates.update(Set<Marker> previous, Set<Marker> current) {
  final Map<MarkerId, Marker> oldMarkers = markerToMap(previous);
  final Map<MarkerId, Marker> currMarkers = markerToMap(current);

  final Set<MarkerId> oldIds = oldMarkers.keys.toSet();
  final Set<MarkerId> currIds = currMarkers.keys.toSet();

  final Set<MarkerId> _toDelete = oldIds.difference(currIds);

  final Set<Marker> _toInsert = Set<Marker>.from(
      currIds.difference(oldIds).map((id) => currMarkers[id]).toSet());

  final Set<Marker> _toUpdate = Set<Marker>.from(currIds
      .intersection(oldIds)
      .map((id) => currMarkers[id])
      .where((x) => isChanged(x!, oldMarkers))
      .toSet());

  insertSet = _toInsert;
  deleteSet = _toDelete;
  updateSet = _toUpdate;
}