polylines tooltip content
This commit is contained in:
19
utils/geometryUtils.js
Normal file
19
utils/geometryUtils.js
Normal file
@@ -0,0 +1,19 @@
|
||||
// utils/geometryUtils.js
|
||||
|
||||
export const findClosestPoints = (coordinates, newPoint, map) => {
|
||||
if (!map) {
|
||||
console.error("Map is not defined. Cannot find closest points.");
|
||||
return [];
|
||||
}
|
||||
|
||||
let minDist = Infinity;
|
||||
let closestPair = [];
|
||||
for (let i = 1; i < coordinates.length; i++) {
|
||||
const dist = L.LineUtil.pointToSegmentDistance(map.latLngToLayerPoint(newPoint), map.latLngToLayerPoint(coordinates[i - 1]), map.latLngToLayerPoint(coordinates[i]));
|
||||
if (dist < minDist) {
|
||||
minDist = dist;
|
||||
closestPair = [coordinates[i - 1], coordinates[i], i];
|
||||
}
|
||||
}
|
||||
return closestPair;
|
||||
};
|
||||
Reference in New Issue
Block a user