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.
This commit is contained in:
@@ -57,6 +57,7 @@ import {
|
|||||||
saveLineData,
|
saveLineData,
|
||||||
redrawPolyline,
|
redrawPolyline,
|
||||||
restoreMapSettings,
|
restoreMapSettings,
|
||||||
|
checkOverlappingMarkers,
|
||||||
} from "../utils/mapUtils.js";
|
} from "../utils/mapUtils.js";
|
||||||
import circleIcon from "./CircleIcon";
|
import circleIcon from "./CircleIcon";
|
||||||
import startIcon from "./StartIcon";
|
import startIcon from "./StartIcon";
|
||||||
@@ -499,43 +500,11 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
};
|
};
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
//---------------------------------------------------------
|
//---------------------------------------------------------
|
||||||
// Now update checkOverlappingMarkers to check if oms is initialized
|
/* const handleMarkerClick = (markerData) => {
|
||||||
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) => {
|
|
||||||
// Setze die aktuellen Daten im State, um sie im Formular vorzubelegen
|
// Setze die aktuellen Daten im State, um sie im Formular vorzubelegen
|
||||||
setCurrentMarkerData(markerData);
|
setCurrentMarkerData(markerData);
|
||||||
setShowEditModal(true);
|
setShowEditModal(true);
|
||||||
};
|
}; */
|
||||||
// In der Marker-Erstellungsfunktion
|
// In der Marker-Erstellungsfunktion
|
||||||
//---------------------------------------------------------
|
//---------------------------------------------------------
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
@@ -543,9 +512,9 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
// serverIP 10.10.0.13 idMap=10 idUser=485
|
// serverIP 10.10.0.13 idMap=10 idUser=485
|
||||||
|
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
const hostname = url.hostname; // Gibt den Hostnamen (IP oder Domain) zurück
|
//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 port = url.port; // Gibt den Port zurück, leer wenn Standardport verwendet wird
|
||||||
const protocol = url.protocol; // "http:" oder "https:"
|
//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
|
const serverURL = urls.SERVER_URL; // weil ich keine API habe, ansonsten serverURL ist localhost(IP-Adresse) für GisSystemStatic für die Benutzerrechte
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user