mapTapToEditPolygon method
cases being handled using mapTapToEditPolygon,
- if
_editPolylineis not null then either a point will be inserted or added depending on tap locationtapLoc - if
_editPolylineis 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();
}
}