MarkerUpdates.from constructor
根据之前的marker列表previous
和当前的marker列表current
创建MakerUpdates
.
Implementation
MarkerUpdates.from(Set<Marker> previous, Set<Marker> current) {
final Map<String, Marker> previousMarkers = keyByMarkerId(previous);
final Map<String, Marker> currentMarkers = keyByMarkerId(current);
final Set<String> prevMarkerIds = previousMarkers.keys.toSet();
final Set<String> currentMarkerIds = currentMarkers.keys.toSet();
Marker idToCurrentMarker(String id) {
return currentMarkers[id]!;
}
final Set<String> tempMarkerIdsToRemove =
prevMarkerIds.difference(currentMarkerIds);
final Set<Marker> tempMarkersToAdd = currentMarkerIds
.difference(prevMarkerIds)
.map(idToCurrentMarker)
.toSet();
bool hasChanged(Marker current) {
final Marker? previous = previousMarkers[current.id];
return current != previous;
}
final Set<Marker> tempMarkersToChange = currentMarkerIds
.intersection(prevMarkerIds)
.map(idToCurrentMarker)
.where(hasChanged)
.toSet();
markersToAdd = tempMarkersToAdd;
markerIdsToRemove = tempMarkerIdsToRemove;
markersToChange = tempMarkersToChange;
}