-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMapPage.tsx
More file actions
43 lines (38 loc) · 1.52 KB
/
MapPage.tsx
File metadata and controls
43 lines (38 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { useEffect, useState } from 'react';
import { MapContainer } from '@/components/Map/MapContainer';
import { LayerControls } from '@/components/Map/LayerControls';
import { FixtureReader } from '@/data/fixture-reader';
import type { LayerVisibilityMap } from '@/types/map';
import type { FeatureCollection } from '@/types/geometry';
/**
* Map Page - renders the interactive map with layer controls
* This is the primary view of the application, displaying
* geospatial data via Leaflet and allowing users to toggle layers.
* @component
* @returns {JSX.Element} The map view with layer controls
*/
export const MapPage = () => {
const [layers, setLayers] = useState<FeatureCollection[]>([]);
const [layerVisibility, setLayerVisibility] = useState<LayerVisibilityMap>({});
useEffect(() => {
FixtureReader.collections()
.then(collections => {
setLayers([...collections]);
// Take the name property of each collection and set it's initial visibility to true
const layerNames = collections.map((fc) => fc.name);
const visibilityMap = layerNames.reduce((map, name) => { map[name] = true; return map; }, {} as LayerVisibilityMap);
setLayerVisibility({ ...visibilityMap });
});
}, []);
const layersToRender = layers.filter((fc) => layerVisibility[fc.name]);
return (
<>
<MapContainer layers={layersToRender} />
{/*<MapLegend />*/}
<LayerControls
visibilityMap={layerVisibility}
onLayerChange={setLayerVisibility}
/>
</>
);
};