PolygonUpdates.from constructor
通过Polygon的前后更新集合构造一个PolygonUpdates
Implementation
PolygonUpdates.from(Set<Polygon> previous, Set<Polygon> current) {
final Map<String, Polygon> previousPolygons = keyByPolygonId(previous);
final Map<String, Polygon> currentPolygons = keyByPolygonId(current);
final Set<String> prevPolygonIds = previousPolygons.keys.toSet();
final Set<String> currentPolygonIds = currentPolygons.keys.toSet();
Polygon idToCurrentPolygon(String id) {
return currentPolygons[id]!;
}
final Set<String> tempPolygonIdsToRemove =
prevPolygonIds.difference(currentPolygonIds);
final Set<Polygon> tempPolygonsToAdd = currentPolygonIds
.difference(prevPolygonIds)
.map(idToCurrentPolygon)
.toSet();
bool hasChanged(Polygon current) {
final Polygon previous = previousPolygons[current.id]!;
return current != previous;
}
final Set<Polygon> tempPolygonsToChange = currentPolygonIds
.intersection(prevPolygonIds)
.map(idToCurrentPolygon)
.where(hasChanged)
.toSet();
polygonsToAdd = tempPolygonsToAdd;
polygonIdsToRemove = tempPolygonIdsToRemove;
polygonsToChange = tempPolygonsToChange;
}