Refactoring
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import L from "leaflet";
|
||||
import { createAndSetDevices } from "../../utils/createAndSetDevices";
|
||||
import { addContextMenuToMarker } from "../../utils/contextMenuUtils";
|
||||
import { checkOverlappingMarkers } from "../../utils/mapUtils";
|
||||
|
||||
const useTalasMarkersLayer = (map, oms, GisSystemStatic, priorityConfig) => {
|
||||
const [talasMarkers, setTalasMarkers] = useState([]);
|
||||
@@ -14,12 +12,11 @@ const useTalasMarkersLayer = (map, oms, GisSystemStatic, priorityConfig) => {
|
||||
}, [GisSystemStatic, map, priorityConfig]);
|
||||
|
||||
useEffect(() => {
|
||||
if (map && talasMarkers.length) {
|
||||
if (map && talasMarkers.length && oms) {
|
||||
talasMarkers.forEach((marker) => {
|
||||
marker.addTo(map);
|
||||
oms.addMarker(marker);
|
||||
oms.addMarker(marker); // Erst zu OMS hinzufügen
|
||||
marker.addTo(map); // Dann zum Map hinzufügen
|
||||
|
||||
// Popup beim Überfahren mit der Maus öffnen und schließen
|
||||
marker.on("mouseover", function () {
|
||||
this.openPopup();
|
||||
});
|
||||
@@ -27,19 +24,10 @@ const useTalasMarkersLayer = (map, oms, GisSystemStatic, priorityConfig) => {
|
||||
this.closePopup();
|
||||
});
|
||||
|
||||
addContextMenuToMarker(marker);
|
||||
addContextMenuToMarker(marker); // Kontextmenü-Event hinzufügen
|
||||
});
|
||||
// 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, talasMarkers]);
|
||||
}, [map, talasMarkers, oms]);
|
||||
|
||||
return talasMarkers;
|
||||
};
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
// hooks/useLayerVisibility.js
|
||||
import { useEffect } from "react";
|
||||
import { useRecoilValue } from "recoil";
|
||||
import { mapLayersState } from "../store/atoms/mapLayersState";
|
||||
import { addContextMenuToMarker } from "../utils/contextMenuUtils";
|
||||
|
||||
const useLayerVisibility = (map, markers, mapLayersVisibility, layerKey) => {
|
||||
const useLayerVisibility = (map, markers, mapLayersVisibility, layerKey, oms) => {
|
||||
useEffect(() => {
|
||||
if (!map || !markers) return;
|
||||
if (!map || !markers || !oms) return;
|
||||
|
||||
const toggleLayer = (isVisible) => {
|
||||
markers.forEach((marker) => {
|
||||
if (isVisible) {
|
||||
marker.addTo(map);
|
||||
oms.addMarker(marker);
|
||||
addContextMenuToMarker(marker); // Kontextmenü hinzufügen
|
||||
} else {
|
||||
map.removeLayer(marker);
|
||||
oms.removeMarker(marker);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
toggleLayer(mapLayersVisibility[layerKey]);
|
||||
}, [map, markers, mapLayersVisibility, layerKey]);
|
||||
}, [map, markers, mapLayersVisibility, layerKey, oms]);
|
||||
};
|
||||
|
||||
export default useLayerVisibility;
|
||||
|
||||
Reference in New Issue
Block a user