Checkboxen switch
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
//components/DataSheet.js
|
// components/DataSheet.js
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { useRecoilValue, useRecoilState } from "recoil";
|
import { useRecoilValue, useRecoilState } from "recoil";
|
||||||
import { gisStationsStaticDistrictState } from "../states/gisStationState";
|
import { gisStationsStaticDistrictState } from "../states/gisStationState";
|
||||||
import { gisSystemStaticState } from "../states/gisSystemState";
|
import { gisSystemStaticState } from "../states/gisSystemState";
|
||||||
import { mapLayersState } from "../states/mapLayersState";
|
import { mapLayersState } from "../states/mapLayersState";
|
||||||
|
|
||||||
function DataSheet() {
|
function DataSheet() {
|
||||||
const [layers, setLayers] = useRecoilState(mapLayersState);
|
const [layers, setLayers] = useRecoilState(mapLayersState);
|
||||||
// useState für uniqueAreas und stationListing
|
|
||||||
const [uniqueAreas, setUniqueAreas] = useState([]);
|
const [uniqueAreas, setUniqueAreas] = useState([]);
|
||||||
const [uniqueSystems, setUniqueSystems] = useState([]);
|
const [uniqueSystems, setUniqueSystems] = useState([]);
|
||||||
const [stationListing, setStationListing] = useState([]);
|
const [stationListing, setStationListing] = useState([]);
|
||||||
@@ -17,13 +17,6 @@ function DataSheet() {
|
|||||||
const GisSystemStatic = useRecoilValue(gisSystemStaticState);
|
const GisSystemStatic = useRecoilValue(gisSystemStaticState);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
/* console.log(
|
|
||||||
"GisStationsStaticDistrict in DataSheet:",
|
|
||||||
GisStationsStaticDistrict
|
|
||||||
); */
|
|
||||||
//console.log("GisSystemStatic in DataSheet:", GisSystemStatic);
|
|
||||||
|
|
||||||
// Filtern der eindeutigen Gebiete (Areas) und alphabetisches Sortieren
|
|
||||||
const seenNames = new Set();
|
const seenNames = new Set();
|
||||||
const filteredAreas = GisStationsStaticDistrict.filter((item) => {
|
const filteredAreas = GisStationsStaticDistrict.filter((item) => {
|
||||||
const isUnique = !seenNames.has(item.Area_Name);
|
const isUnique = !seenNames.has(item.Area_Name);
|
||||||
@@ -32,7 +25,6 @@ function DataSheet() {
|
|||||||
}
|
}
|
||||||
return isUnique;
|
return isUnique;
|
||||||
});
|
});
|
||||||
|
|
||||||
setUniqueAreas(filteredAreas);
|
setUniqueAreas(filteredAreas);
|
||||||
|
|
||||||
const seenSystemNames = new Set();
|
const seenSystemNames = new Set();
|
||||||
@@ -43,44 +35,44 @@ function DataSheet() {
|
|||||||
}
|
}
|
||||||
return isUnique;
|
return isUnique;
|
||||||
});
|
});
|
||||||
|
|
||||||
setUniqueSystems(filteredSystems);
|
setUniqueSystems(filteredSystems);
|
||||||
|
|
||||||
// Erzeugen von stationListing aus uniqueAreas und alphabetisches Sortieren
|
|
||||||
const newStationListing = filteredAreas
|
const newStationListing = filteredAreas
|
||||||
.map((area, index) => ({
|
.map((area, index) => ({ id: index + 1, name: area.Area_Name }))
|
||||||
id: index + 1, // Zuweisung einer eindeutigen ID
|
.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
name: area.Area_Name,
|
|
||||||
}))
|
|
||||||
.sort((a, b) => a.name.localeCompare(b.name)); // Alphabetisches Sortieren der Namen
|
|
||||||
|
|
||||||
setStationListing(newStationListing);
|
setStationListing(newStationListing);
|
||||||
|
|
||||||
//----------
|
const newSystemListing = filteredSystems.map((system, index) => ({
|
||||||
const newSystemListing = filteredSystems.map((area, index) => ({
|
id: index + 1,
|
||||||
id: index + 1, // Zuweisung einer eindeutigen ID
|
name: system.Name.replace(/[^a-zA-Z0-9]/g, ""), // Ersetzen von Sonderzeichen
|
||||||
name: area.Name,
|
displayName: system.Name, // Beibehalten des originalen Namens für die Anzeige
|
||||||
}));
|
}));
|
||||||
setSystemListing(newSystemListing);
|
setSystemListing(newSystemListing);
|
||||||
// console.log("System Listing:", systemListing);
|
|
||||||
}, [GisStationsStaticDistrict]);
|
|
||||||
|
|
||||||
const [checkedStations, setCheckedStations] = useState({});
|
console.log("Station Listing:", newStationListing);
|
||||||
|
console.log("System Listing:", newSystemListing);
|
||||||
|
}, [GisStationsStaticDistrict, GisSystemStatic]);
|
||||||
|
|
||||||
const handleCheckboxChange = (layerName) => {
|
const handleCheckboxChange = (layerKey) => {
|
||||||
// Umschalten der Sichtbarkeit im Zustand
|
console.log(
|
||||||
setLayers((prevLayers) => ({
|
`Ändern der Sichtbarkeit für: ${layerKey}, aktueller Wert: ${layers[layerKey]}`
|
||||||
...prevLayers,
|
);
|
||||||
[layerName]: !prevLayers[layerName], // Umschalten des Booleschen Werts
|
setLayers((prevLayers) => {
|
||||||
}));
|
const newLayers = {
|
||||||
|
...prevLayers,
|
||||||
|
[layerKey]: !prevLayers[layerKey],
|
||||||
|
};
|
||||||
|
console.log(`Neuer Wert für ${layerKey}: ${newLayers[layerKey]}`);
|
||||||
|
return newLayers;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleStationChange = (event) => {
|
const handleStationChange = (event) => {
|
||||||
// console.log("Station selected:", event.target.value);
|
console.log("Ausgewählte Station:", event.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const resetView = () => {
|
const resetView = () => {
|
||||||
// console.log("View has been reset");
|
console.log("Ansicht wird zurückgesetzt.");
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -90,7 +82,6 @@ function DataSheet() {
|
|||||||
>
|
>
|
||||||
<div className="flex flex-col gap-4 p-4">
|
<div className="flex flex-col gap-4 p-4">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
{/* Dropdown */}
|
|
||||||
<select
|
<select
|
||||||
onChange={handleStationChange}
|
onChange={handleStationChange}
|
||||||
id="stationListing"
|
id="stationListing"
|
||||||
@@ -103,23 +94,20 @@ function DataSheet() {
|
|||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
{/* Icon */}
|
|
||||||
<img
|
<img
|
||||||
src="/img/expand-icon.svg"
|
src="/img/expand-icon.svg"
|
||||||
alt="Expand"
|
alt="Expand"
|
||||||
className="h-6 w-6 ml-2"
|
className="h-6 w-6 ml-2"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Liste der Stationen mit Checkboxen */}
|
|
||||||
{systemListing.map((station) => (
|
{systemListing.map((station) => (
|
||||||
<div key={station.id} className="flex items-center">
|
<div key={station.id} className="flex items-center">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id={`box-${station.id}`}
|
id={`box-${station.id}`}
|
||||||
className="accent-blue-500 checked:bg-blue-500"
|
className="accent-blue-500 checked:bg-blue-500"
|
||||||
checked={layers[station.name] || false} // Zustand von Recoil verwenden
|
checked={layers[`show_${station.name}`] || false}
|
||||||
onChange={() => handleCheckboxChange(station.name)}
|
onChange={() => handleCheckboxChange(`show_${station.name}`)}
|
||||||
/>
|
/>
|
||||||
<label
|
<label
|
||||||
htmlFor={`box-${station.id}`}
|
htmlFor={`box-${station.id}`}
|
||||||
|
|||||||
@@ -910,7 +910,7 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
|
|||||||
//-------------------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------------------
|
||||||
//GMA Layer
|
//GMA Layer
|
||||||
const [layerGMA, setLayerGMA] = useState([]);
|
const [layerGMA, setLayerGMA] = useState([]);
|
||||||
const [showGMA, setShowGMA] = useState(false);
|
const [showGMA, setShowGMA] = useState(true);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!map || !GisStationsStaticDistrict) return;
|
if (!map || !GisStationsStaticDistrict) return;
|
||||||
|
|
||||||
@@ -977,7 +977,7 @@ const MapComponent = ({ locations, onLocationUpdate }) => {
|
|||||||
//-------------------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------------------
|
||||||
//TALAS Layer
|
//TALAS Layer
|
||||||
const [layerTALAS, setLayerTALAS] = useState([]);
|
const [layerTALAS, setLayerTALAS] = useState([]);
|
||||||
const [showTALAS, setShowTALAS] = useState(false);
|
const [showTALAS, setShowTALAS] = useState(true);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!map || !GisStationsStaticDistrict) return;
|
if (!map || !GisStationsStaticDistrict) return;
|
||||||
|
|
||||||
|
|||||||
@@ -5,20 +5,20 @@ export const mapLayersState = atom({
|
|||||||
key: "mapLayersState", // Eindeutiger Schlüssel für das Atom
|
key: "mapLayersState", // Eindeutiger Schlüssel für das Atom
|
||||||
default: {
|
default: {
|
||||||
// Standardwerte für jeden Layer
|
// Standardwerte für jeden Layer
|
||||||
show_TALAS: false,
|
show_TALAS: true,
|
||||||
show_ECI: false,
|
show_ECI: true,
|
||||||
show_ULAF: false,
|
// show_ULAF: false,
|
||||||
show_GSMModem: false,
|
show_GSMModem: true,
|
||||||
show_CiscoRouter: false,
|
show_CiscoRouter: true,
|
||||||
show_WAGO: false,
|
show_WAGO: true,
|
||||||
show_Siemens: false,
|
show_Siemens: true,
|
||||||
show_OTDR: false,
|
show_OTDR: true,
|
||||||
show_WDM: false,
|
show_WDM: true,
|
||||||
show_GMA: false,
|
show_GMA: true,
|
||||||
show_Messstellen: false,
|
show_Messstellen: true,
|
||||||
show_TALASICL: false,
|
show_TALASICL: true,
|
||||||
show_DAUZ: false,
|
show_DAUZ: true,
|
||||||
show_SMSFunkmodem: false,
|
show_SMSFunkmodem: true,
|
||||||
show_Sonstige: false,
|
show_Sonstige: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user