From 18f0f8266b4e9442f526eaa0410f9a33d9d02e7f Mon Sep 17 00:00:00 2001 From: ISA Date: Thu, 11 Jul 2024 10:44:40 +0200 Subject: [PATCH] refactor: Move checkOverlappingMarkers to utils and update import in MapComponent - Moved checkOverlappingMarkers function from MapComponent.js to a new file in /utils/mapUtils.js for better separation of concerns. - Updated the import statement in MapComponent.js to reflect the new location of checkOverlappingMarkers. --- components/MapComponent.js | 43 ++++++-------------------------------- utils/mapUtils.js | 32 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/components/MapComponent.js b/components/MapComponent.js index a214771b0..99a1017f0 100644 --- a/components/MapComponent.js +++ b/components/MapComponent.js @@ -57,6 +57,7 @@ import { saveLineData, redrawPolyline, restoreMapSettings, + checkOverlappingMarkers, } from "../utils/mapUtils.js"; import circleIcon from "./CircleIcon"; import startIcon from "./StartIcon"; @@ -499,43 +500,11 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { }; //-------------------------------------------------------------- //--------------------------------------------------------- - // Now update checkOverlappingMarkers to check if oms is initialized - function checkOverlappingMarkers(map, markers, plusIcon) { - // Ensure markers is always an array - if (!Array.isArray(markers)) { - //console.error("The `markers` argument is not an array:", markers); - return; - } - - const overlappingGroups = {}; - - // Group markers by coordinates as strings - markers.forEach((marker) => { - const latlngStr = marker.getLatLng().toString(); - if (overlappingGroups[latlngStr]) { - overlappingGroups[latlngStr].push(marker); - } else { - overlappingGroups[latlngStr] = [marker]; - } - }); - - // Add plus markers at coordinates where overlaps occur - for (const coords in overlappingGroups) { - if (overlappingGroups[coords].length > 1) { - const latLng = L.latLng(coords.match(/[-.\d]+/g).map(Number)); - const plusMarker = L.marker(latLng, { icon: plusIcon }); - plusMarker.addTo(map); - - //console.log("Adding plus icon marker at", latLng); - } - } - } - //--------------------------------------------------------- - const handleMarkerClick = (markerData) => { + /* const handleMarkerClick = (markerData) => { // Setze die aktuellen Daten im State, um sie im Formular vorzubelegen setCurrentMarkerData(markerData); setShowEditModal(true); - }; + }; */ // In der Marker-Erstellungsfunktion //--------------------------------------------------------- //----------------------------------------------------------- @@ -543,9 +512,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { // serverIP 10.10.0.13 idMap=10 idUser=485 const url = new URL(window.location.href); - const hostname = url.hostname; // Gibt den Hostnamen (IP oder Domain) zurück - const port = url.port; // Gibt den Port zurück, leer wenn Standardport verwendet wird - const protocol = url.protocol; // "http:" oder "https:" + //const hostname = url.hostname; // Gibt den Hostnamen (IP oder Domain) zurück + //const port = url.port; // Gibt den Port zurück, leer wenn Standardport verwendet wird + //const protocol = url.protocol; // "http:" oder "https:" const serverURL = urls.SERVER_URL; // weil ich keine API habe, ansonsten serverURL ist localhost(IP-Adresse) für GisSystemStatic für die Benutzerrechte diff --git a/utils/mapUtils.js b/utils/mapUtils.js index 05a31d723..b9d7d85f7 100644 --- a/utils/mapUtils.js +++ b/utils/mapUtils.js @@ -77,3 +77,35 @@ export const restoreMapSettings = (map) => { } } }; + +// Now update checkOverlappingMarkers to check if oms is initialized +export const checkOverlappingMarkers = (map, markers, plusIcon) => { + // Ensure markers is always an array + if (!Array.isArray(markers)) { + //console.error("The `markers` argument is not an array:", markers); + return; + } + + const overlappingGroups = {}; + + // Group markers by coordinates as strings + markers.forEach((marker) => { + const latlngStr = marker.getLatLng().toString(); + if (overlappingGroups[latlngStr]) { + overlappingGroups[latlngStr].push(marker); + } else { + overlappingGroups[latlngStr] = [marker]; + } + }); + + // Add plus markers at coordinates where overlaps occur + for (const coords in overlappingGroups) { + if (overlappingGroups[coords].length > 1) { + const latLng = L.latLng(coords.match(/[-.\d]+/g).map(Number)); + const plusMarker = L.marker(latLng, { icon: plusIcon }); + plusMarker.addTo(map); + + //console.log("Adding plus icon marker at", latLng); + } + } +};