PolygonUpdates.update constructor

PolygonUpdates.update(
  1. Set<Polygon> previous,
  2. Set<Polygon> current
)

Implementation

PolygonUpdates.update(Set<Polygon> previous, Set<Polygon> current) {
  final Map<PolygonId, Polygon> oldPolygons = polygonToMap(previous);
  final Map<PolygonId, Polygon> currPolygons = polygonToMap(current);

  final Set<PolygonId> oldIds = oldPolygons.keys.toSet();
  final Set<PolygonId> currIds = currPolygons.keys.toSet();

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

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

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

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