// components/DataSheet.js import React, { useEffect, useState } from "react"; import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil"; import { gisStationsStaticDistrictState } from "../store/atoms/gisStationState"; import { gisSystemStaticState } from "../store/atoms/gisSystemState"; import { mapLayersState } from "../store/atoms/mapLayersState"; import { selectedAreaState } from "../store/atoms/selectedAreaState"; import { zoomTriggerState } from "../store/atoms/zoomTriggerState"; import { poiLayerVisibleState } from "../store/atoms/poiLayerVisibleState"; function DataSheet() { const [poiVisible, setPoiVisible] = useRecoilState(poiLayerVisibleState); const setSelectedArea = useSetRecoilState(selectedAreaState); const [mapLayersVisibility, setMapLayersVisibility] = useRecoilState(mapLayersState); const [stationListing, setStationListing] = useState([]); const [systemListing, setSystemListing] = useState([]); const GisStationsStaticDistrict = useRecoilValue(gisStationsStaticDistrictState); const GisSystemStatic = useRecoilValue(gisSystemStaticState); const setZoomTrigger = useSetRecoilState(zoomTriggerState); const handleAreaChange = (event) => { const selectedIndex = event.target.options.selectedIndex; const areaName = event.target.options[selectedIndex].text; setSelectedArea(areaName); }; useEffect(() => { console.log("GisStationsStaticDistrict:", GisStationsStaticDistrict); console.log("GisSystemStatic:", GisSystemStatic); const allowedSystems = new Set(GisSystemStatic.filter((system) => system.Allow === 1).map((system) => system.IdSystem)); console.log("allowedSystems:", allowedSystems); const seenNames = new Set(); const filteredAreas = GisStationsStaticDistrict.filter((item) => { const isUnique = !seenNames.has(item.Area_Name) && allowedSystems.has(item.System); if (isUnique) { seenNames.add(item.Area_Name); } return isUnique; }); setStationListing( filteredAreas.map((area, index) => ({ id: index + 1, name: area.Area_Name, })) ); //console.log("filteredAreas:", filteredAreas); const seenSystemNames = new Set(); const filteredSystems = GisSystemStatic.filter((item) => { const formattedName = item.Name.replace(/[\s\-]+/g, ""); const isUnique = !seenSystemNames.has(formattedName) && item.Allow === 1; if (isUnique) { seenSystemNames.add(formattedName); } return isUnique; }); setSystemListing( filteredSystems.map((system, index) => ({ id: index + 1, name: system.Name.replace(/[\s\-]+/g, ""), })) ); }, [GisStationsStaticDistrict, GisSystemStatic]); //}, []); //----------------------------------------- //----------------------------------------- const handleCheckboxChange = (name, event) => { const { checked } = event.target; setMapLayersVisibility((prev) => { const newState = { ...prev, [name]: checked, }; return newState; }); console.log("mapLayersVisibility:", mapLayersVisibility); }; const handleIconClick = () => { setSelectedArea("Station wählen"); setZoomTrigger((current) => current + 1); }; return (