diff --git a/src/components/control-panel/control-panel.js b/src/components/control-panel/control-panel.js index 64f31dd8..0f20ea84 100644 --- a/src/components/control-panel/control-panel.js +++ b/src/components/control-panel/control-panel.js @@ -1,16 +1,43 @@ import React from 'react'; import { useLayers } from '@context/map-context'; -import { Sheet, ButtonGroup, Button, Typography, IconButton, Box, Switch } from '@mui/joy'; -import { ArrowUpward, ArrowDownward } from '@mui/icons-material'; +import { Sheet, ButtonGroup, Typography, IconButton, Box, Switch, ToggleButtonGroup } from '@mui/joy'; +import { ArrowUpward, ArrowDownward, Tsunami, Water, Air } from '@mui/icons-material'; import apsLogo from '@images/aps-trans-logo.png'; -//import { useLayers } from '@context'; - export const ControlPanel = () => { //const { defaultModelLayers, toggleLayerVisibility } = useLayers(); - const { defaultModelLayers } = useLayers(); + const { defaultModelLayers, toggleLayerVisibility } = useLayers(); + const layers = [...defaultModelLayers]; + const maxele_layer = layers.find((layer) => layer.properties.product_type === "maxele63"); + const obs_layer = layers.find((layer) => layer.properties.product_type === "obs"); + + const [value, setValue] = React.useState('maxele63'); + const [checked, setChecked] = React.useState(true); + + const layerChange = (event, newValue) => { + + setValue(newValue); + // turn off the old + layers.map(layer => { + if (layer.layers.includes(value)) { + toggleLayerVisibility(layer.id); + } + }); + // turn on the new + layers.map(layer => { + if (layer.layers.includes(newValue)) { + console.log(newValue); + toggleLayerVisibility(layer.id); + } + }); + }; + + const toggleObsLayer = (event) => { + setChecked(event.target.checked); + toggleLayerVisibility(obs_layer.id); + }; return ( <> @@ -21,58 +48,76 @@ export const ControlPanel = () => { bottom: 0, right: 0, overflow: 'hidden', p: 0, - backgroundColor: '#f0f4f820', - height: '40vh', + backgroundColor: '#f0f4f800', + height: '30vh', width: '300px', zIndex: 999, filter: 'drop-shadow(0 0 8px rgba(0, 0, 0, 0.2))', borderRadius: 10, - + display: 'flex', + flexDirection: 'column', }} > { (layers.length) && -

model run date: {layers[0].properties.run_date}

+ model run date: {layers[0].properties.run_date} } - - + + - + - }> - {/* NOTE: If this is a tropical storm run, we need to change cycle to advisoy + }> + {/* TODO: NOTE: If this is a tropical storm run, we need to change cycle to advisoy Also probabaly want to add a switch for hurricane layers - which - involves making a request to the MetGet API */} - cycle {layers.length && layers[0].properties.cycle} + involves making a request to the MetGet API + Third need to implement actual code to load different model runs each time + up/down arrows are clicked. This has to time managed in some way so that + Geoserver is not inundated with requests */} + cycle {layers.length && layers[0].properties.cycle} { (layers.length) && -

{layers[0].properties.grid_type} grid

+ {layers[0].properties.grid_type} grid } - }> + + }> observations - - { layers.map(layer => { - if (layer.properties.product_type != "obs") - return ( - - ); - })}; - + { { (maxele_layer) && + + + + } + { layers.map(layer => { + if (layer.properties.product_type != "obs" && layer.properties.product_type != "maxele63") + + return ( + + { (layer.properties.product_type === "maxwvel63") && + } + {(layer.properties.product_type === "swan_HS_max63") && + } + + ); + })} + }> + } ); diff --git a/src/components/map/default-layers.js b/src/components/map/default-layers.js index 689f089d..c9859af1 100644 --- a/src/components/map/default-layers.js +++ b/src/components/map/default-layers.js @@ -4,6 +4,21 @@ import { CircleMarker } from 'leaflet'; import { useLayers } from '@context'; import { markClicked } from '@utils/map-utils'; +const newLayerDefaultState = (layer) => { + const { product_type } = layer.properties; + + if (['obs', 'maxele63'].includes(product_type)) { + return ({ + visible: true, + }); + } + + return ({ + visible: false, + }); + }; + + export const DefaultLayers = () => { const [obsData, setObsData] = useState(""); @@ -92,9 +107,7 @@ export const DefaultLayers = () => { if (layer) layer_list.push({ ...layer, - state: { - visible: true, - } + state: newLayerDefaultState(layer, layer_list.length) }); // TODO: do we really need to do this here??! diff --git a/src/components/map/map.js b/src/components/map/map.js index d54bf614..7fb63715 100644 --- a/src/components/map/map.js +++ b/src/components/map/map.js @@ -17,7 +17,7 @@ export const Map = () => { zoom={5} zoomControl={false} scrollWheelZoom={true} - whenCreated={setMap} + ref={setMap} style={{ height: '100vh', width:'100wh' }}>