From a046bc1f596a1238d8378d09c3ec13261e4857f4 Mon Sep 17 00:00:00 2001 From: Ismail Ali Date: Sun, 21 Apr 2024 19:16:30 +0200 Subject: [PATCH] Use Recoil State Management --- components/MapComponent.js | 39 +++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/components/MapComponent.js b/components/MapComponent.js index 9106327bd..8d92a88d5 100644 --- a/components/MapComponent.js +++ b/components/MapComponent.js @@ -7,18 +7,16 @@ import "leaflet-contextmenu"; import * as config from "../config/config.js"; import dynamic from "next/dynamic"; import "leaflet.smooth_marker_bouncing"; -//import { OverlappingMarkerSpiderfier } from "../lib/OverlappingMarkerSpiderfier.js"; -//import { OverlappingMarkerSpiderfier } from "../public/js/OverlappingMarkerSpiderfier.js"; import OverlappingMarkerSpiderfier from "overlapping-marker-spiderfier-leaflet"; import DataSheet from "../components/DataSheet"; +import { useRecoilState } from 'recoil'; +import { gisStationsStaticDistrictState } from '../features/gisStationState'; const MapComponent = ({ locations, onLocationUpdate }) => { const mapRef = useRef(null); // Referenz auf das DIV-Element der Karte const [map, setMap] = useState(null); // Zustand der Karteninstanz const [online, setOnline] = useState(navigator.onLine); // Zustand der Internetverbindung - const [GisStationsStaticDistrict, setGisStationsStaticDistrict] = useState( - [] - ); // Zustand für statische Daten + const [GisStationsStaticDistrict, setGisStationsStaticDistrict] = useRecoilState(gisStationsStaticDistrictState); const [GisStationsStatusDistrict, setGisStationsStatusDistrict] = useState( [] ); // Zustand für Statusdaten @@ -560,11 +558,11 @@ const MapComponent = ({ locations, onLocationUpdate }) => { // Alte Marker entfernen, indem alle Marker, die durch OMS verwaltet werden, gelöscht werden oms.clearMarkers(); - /* map.eachLayer((layer) => { + map.eachLayer((layer) => { if (layer instanceof L.Marker) { map.removeLayer(layer); } - }); */ + }); // Neue Marker für jede Station hinzufügen GisStationsStaticDistrict.forEach((station) => { @@ -638,6 +636,28 @@ const MapComponent = ({ locations, onLocationUpdate }) => { }); marker.bounce(3); } + // Prüfen, ob der Name der Station "GMA Littwin (TEST)" entspricht + if (station.LD_Name === "GMA Littwin (TEST)") { + marker.bindTooltip( + `
${station.Area_Name}
`, + { + permanent: true, + direction: "right", + opacity: 1, // Tooltip immer sichtbar + offset: L.point({ x: 10, y: 0 }), + } + ).addTo(GMA); + } else { + marker.bindTooltip( + `
${station.LD_Name}
`, + { + permanent: false, + direction: "right", + opacity: 0, + offset: L.point({ x: 10, y: 0 }), + } + ).addTo(GMA); + } // Marker zu OMS und der Karte hinzufügen oms.addMarker(marker); marker.addTo(map).bindPopup(` @@ -648,7 +668,7 @@ const MapComponent = ({ locations, onLocationUpdate }) => { ${statusInfo}
`); let LocID = station.IdLocation; - marker + /* marker .bindTooltip( `
${LocID}
`, { @@ -658,8 +678,9 @@ const MapComponent = ({ locations, onLocationUpdate }) => { offset: L.point({ x: 10, y: 0 }), } ) - .addTo(GMA); + .addTo(GMA); */ }); + }, [map, oms, GisStationsStaticDistrict, GisStationsStatusDistrict]); //------------------------------------------