die hooks Layer in den Verzeichnis /hooks/layers verschoben
This commit is contained in:
49
hooks/layers/useCiscoRouterMarkersLayer.js
Normal file
49
hooks/layers/useCiscoRouterMarkersLayer.js
Normal file
@@ -0,0 +1,49 @@
|
||||
// hooks/useCiscoRouterMarkersLayer.js
|
||||
import { useEffect, useState } from "react";
|
||||
import L from "leaflet";
|
||||
import { createAndSetMarkers } from "../../utils/markerUtils";
|
||||
import { addContextMenuToMarker } from "../../utils/contextMenuUtils";
|
||||
import { checkOverlappingMarkers } from "../../utils/mapUtils";
|
||||
|
||||
const useCiscoRouterMarkersLayer = (map, oms, GisSystemStatic, priorityConfig) => {
|
||||
const [ciscoRouterMarkers, setCiscoRouterMarkers] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (GisSystemStatic && GisSystemStatic.length && map) {
|
||||
createAndSetMarkers(6, setCiscoRouterMarkers, GisSystemStatic, priorityConfig); // Cisco Router
|
||||
}
|
||||
}, [GisSystemStatic, map, priorityConfig]);
|
||||
|
||||
useEffect(() => {
|
||||
if (map && ciscoRouterMarkers.length) {
|
||||
ciscoRouterMarkers.forEach((marker) => {
|
||||
marker.addTo(map);
|
||||
oms.addMarker(marker);
|
||||
|
||||
// Popup on mouseover and mouseout
|
||||
marker.on("mouseover", function () {
|
||||
this.openPopup();
|
||||
});
|
||||
marker.on("mouseout", function () {
|
||||
this.closePopup();
|
||||
});
|
||||
|
||||
addContextMenuToMarker(marker);
|
||||
});
|
||||
|
||||
// Disable map context menu
|
||||
map.options.contextmenu = false;
|
||||
map.options.contextmenuItems = [];
|
||||
|
||||
oms.map.options.contextmenu = false;
|
||||
oms.map.options.contextmenuItems = [];
|
||||
|
||||
// Call the function to check for overlapping markers
|
||||
checkOverlappingMarkers(oms, map);
|
||||
}
|
||||
}, [map, ciscoRouterMarkers]);
|
||||
|
||||
return ciscoRouterMarkers;
|
||||
};
|
||||
|
||||
export default useCiscoRouterMarkersLayer;
|
||||
Reference in New Issue
Block a user