mapTapToEditPolygon method

Future<void> mapTapToEditPolygon(
  1. LatLng tapLoc
)

cases being handled using mapTapToEditPolygon,

  1. if _editPolyline is not null then either a point will be inserted or added depending on tap location tapLoc
  2. if _editPolyline is null then if the user taps on any of the polygon it will be made editable

Implementation

Future<void> mapTapToEditPolygon(LatLng tapLoc) async {
  if (_editPolygon == null) return;
  LatLngBounds bounds = await mapController.getVisibleRegion();
  List<LatLng> _editPolygonPoints = _editPolygon!.points;
  int idx = PointAlgo.locationIndexOnEdgeOrPath(tapLoc, _editPolygonPoints,bounds);
  if (idx >= 0) {
    _editPolygonPoints.insert(idx + 1, tapLoc);
  } else {
    if (_editPolygonPoints.length > 2  && _editPolygonPoints.first == _editPolygonPoints.last) {
      _editPolygonPoints.removeLast();
    }
    _editPolygonPoints.add(tapLoc);
  }
  _editPolygon = _editPolygon!.copyWith(pointsParam: ensureLinearRing(_editPolygonPoints),);
  if (_editPolygonPoints.isNotEmpty) {
    await generateEditPolyline();
  }
}