From 5ecfb67a942e7ffd35d9f1b432ffe2184a137a00 Mon Sep 17 00:00:00 2001 From: Lisa Stillwell Date: Tue, 10 Sep 2024 13:58:54 -0400 Subject: [PATCH] #212 updated logic to work as requested --- src/components/control-panel/control-panel.js | 7 +++++-- src/components/map/storm-layers.js | 16 ++++++++++++++++ src/components/trays/layers/list.js | 14 +++++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/components/control-panel/control-panel.js b/src/components/control-panel/control-panel.js index e28a89d1..06e8bd52 100644 --- a/src/components/control-panel/control-panel.js +++ b/src/components/control-panel/control-panel.js @@ -239,8 +239,11 @@ export const ControlPanel = () => { // switch on/off the hurricane track layer, if it exists const toggleHurricaneLayer = () => { - const layerID = obs_layer.id.substr(0, obs_layer.id.lastIndexOf("-")) + '-hurr'; - toggleHurricaneLayerVisibility(layerID); + // if there is a hurricane layer + if (hurrLayers) { + // toggle the view of it + toggleHurricaneLayerVisibility(hurrLayers[0].id); + } }; const changeSynopticCycle = (direction) => { diff --git a/src/components/map/storm-layers.js b/src/components/map/storm-layers.js index 3c76e5e3..9c27d263 100644 --- a/src/components/map/storm-layers.js +++ b/src/components/map/storm-layers.js @@ -40,6 +40,17 @@ export const StormLayers = () => { } }; + // set visibily to false for all hurricane layers + const setHurricaneLayersVisiblityOff = () => { + const allHurrLayers = hurrLayers.map((x) => x); + if (allHurrLayers && allHurrLayers.length > 0) { + allHurrLayers.forEach(layer => { + layer.state = { visible: false, opacity: 1, }; + }); + setHurricaneTrackLayers([...allHurrLayers]); + } + }; + useEffect(() => { @@ -95,6 +106,11 @@ export const StormLayers = () => { setHurricaneTrackLayers([...trackLayer, ...currentLayers]); } } + else { + // this is not a hurricane layer - turn off all hurricane layers, if any + setHurricaneLayersVisiblityOff(); + } + // remove any hurricane layers that do not have an assocatiated model run removeAnyOrphanHurricaneLayers(); } diff --git a/src/components/trays/layers/list.js b/src/components/trays/layers/list.js index 38c060f1..9c5cf47b 100644 --- a/src/components/trays/layers/list.js +++ b/src/components/trays/layers/list.js @@ -172,11 +172,14 @@ const newLayerDefaultState = (layer, group) => { */ export const LayersList = () => { // get a handle to the layer state - const { removeObservations, defaultModelLayers, setDefaultModelLayers } = useLayers(); + const { removeObservations, defaultModelLayers, setDefaultModelLayers, hurricaneTrackLayers, setHurricaneTrackLayers } = useLayers(); // get the default layers const layers = [...defaultModelLayers]; + // get hurricane layers + const hurrLayers = [...hurricaneTrackLayers]; + // get the unique groups in the selected model runs const groupList = getGroupList(layers); @@ -245,6 +248,15 @@ export const LayersList = () => { layer.state = newLayerDefaultState(layer, newLayerList[0].group); }); + // turn on/off any hurricane layers + if (hurrLayers) { + newLayerList[0].properties.met_class === "tropical" ? + hurrLayers[0].state.visible = true + : + hurrLayers[0].state.visible = false; + setHurricaneTrackLayers([...hurrLayers]); + } + // update the layer list in state setDefaultModelLayers(newLayerList); };