indexOfTappedPath method
Implementation
int indexOfTappedPath(TapEvent tapEvent) {
Mappoint tapped = tapEvent.mappoint;
for (int idx = 0; idx < _path.length - 1; ++idx) {
Mappoint point0 = tapEvent.projection.latLonToPixel(_path.path[idx]);
Mappoint point1 = tapEvent.projection.latLonToPixel(_path.path[idx + 1]);
double distance = LatLongUtils.distanceSegmentPoint(point0.x, point0.y, point1.x, point1.y, tapped.x, tapped.y);
// correct would be half of strokeWidth but it is hard to tap exactly so be graceful here
if (distance <= (renderInfo?.renderInstruction.strokeWidth ?? 0)) return idx;
}
return -1;
}