move method
void
move(
- Key key,
- LatLng to, {
- bool merge = false,
})
Implementation
void move(Key key, LatLng to, {bool merge = false}) {
final before = findByKey(key);
if (before == null) {
debugPrint(
'Warning: Attempted to move non-existent polyline with key: $key');
return;
}
if (before.points.isEmpty) return;
final bounds = LatLngBounds.fromPoints(before.points);
final centerBefore = bounds.center;
perform(
MovePolylineOp(key: key, from: centerBefore, to: to),
merge: merge,
);
// Calculate new points for callback
final deltaLat = to.latitude - centerBefore.latitude;
final deltaLng = to.longitude - centerBefore.longitude;
final newPoints = before.points.map((p) {
return LatLng(p.latitude + deltaLat, p.longitude + deltaLng);
}).toList();
final moved = before.copyWith(points: newPoints);
_options.onSpatialUpdate?.call(moved, before);
scheduleAutoSave();
}