apply method

  1. @override
PolylineOp apply(
  1. List<InteractivePolyline<Object>> list
)
override

Applies this operation to the current list.

Modifies current in place and returns the effective operation (e.g. populated with captured state like removed index).

Implementation

@override
PolylineOp apply(List<InteractivePolyline> list) {
  final idx = list.indexWhere((p) => p.key == key);
  if (idx >= 0) {
    final target = list[idx];
    final deltaLat = to.latitude - from.latitude;
    final deltaLng = to.longitude - from.longitude;
    final newPoints = target.points.map((p) {
      return LatLng(p.latitude + deltaLat, p.longitude + deltaLng);
    }).toList();
    list[idx] = target.copyWith(points: newPoints);
  }
  return this;
}