POIs hinzufügen, löschen und bearbeiten funktioniert! in mapFeatures.js als marker, irgendwann in poi umbenennen

This commit is contained in:
ISA
2024-08-15 15:53:27 +02:00
parent 18ad7cad7e
commit 8699c1c4a0
10 changed files with 121 additions and 103 deletions

View File

@@ -17,3 +17,37 @@ export const findClosestPoints = (coordinates, newPoint, map) => {
}
return closestPair;
};
// Hilfsfunktion zur Berechnung der Entfernung zwischen zwei Punkten (LatLng)
export function getDistance(latlng1, latlng2) {
const R = 6371e3; // Erdradius in Metern
const lat1 = latlng1.lat * (Math.PI / 180);
const lat2 = latlng2.lat * (Math.PI / 180);
const deltaLat = (latlng2.lat - latlng1.lat) * (Math.PI / 180);
const deltaLng = (latlng2.lng - latlng1.lng) * (Math.PI / 180);
const a = Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) + Math.cos(lat1) * Math.cos(lat2) * Math.sin(deltaLng / 2) * Math.sin(deltaLng / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return R * c; // Entfernung in Metern
}
// Funktion zum Finden der nächsten Linie basierend auf der Mausposition
export function findNearestPolyline(map, mouseLatLng) {
let nearestPolyline = null;
let minDistance = Infinity;
map.eachLayer(function (layer) {
if (layer instanceof L.Polyline) {
const latlngs = layer.getLatLngs();
latlngs.forEach((latlng) => {
const distance = getDistance(mouseLatLng, latlng);
if (distance < minDistance) {
minDistance = distance;
nearestPolyline = layer;
}
});
}
});
return nearestPolyline;
}