From de2e8e77f325c183dec8bbeb252bbb967537fd79 Mon Sep 17 00:00:00 2001 From: Phil Owen <19691521+PhillipsOwen@users.noreply.github.com> Date: Tue, 13 Aug 2024 16:38:50 -0400 Subject: [PATCH 1/8] when the observations are toggled, all open obs dialogs and "target" overlays are removed. --- src/components/control-panel/control-panel.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/components/control-panel/control-panel.js b/src/components/control-panel/control-panel.js index d70e6e23..f50c0949 100644 --- a/src/components/control-panel/control-panel.js +++ b/src/components/control-panel/control-panel.js @@ -35,7 +35,10 @@ const layerIcons = { export const ControlPanel = () => { - const { defaultModelLayers, + const { map, + selectedObservations, + setSelectedObservations, + defaultModelLayers, hurricaneTrackLayers, setDefaultModelLayers, getAllLayersInvisible, @@ -230,6 +233,18 @@ export const ControlPanel = () => { // switch on/off the observation layer if it exists const toggleObsLayer = () => { toggleLayerVisibility(obs_layer.id); + + // remove all the "target" overlays from state + map.eachLayer((layer) => { + // if this is an observation selection marker + if (layer.options && layer.options.pane === "markerPane") { + // remove the layer + map.removeLayer(layer); + } + }); + + // remove all the observation dialogs from state + setSelectedObservations(selectedObservations.filter(item => item === undefined)); }; // switch on/off the hurricane track layer, if it exists From fbe96d06eaa71f8d2bfe50ea780db56b1679a4c0 Mon Sep 17 00:00:00 2001 From: Phil Owen <19691521+PhillipsOwen@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:26:40 -0400 Subject: [PATCH 2/8] adding method to remove observation layers and selected observations. --- src/context/map-context.js | 54 +++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/context/map-context.js b/src/context/map-context.js index 10b38adb..20e6d3b6 100644 --- a/src/context/map-context.js +++ b/src/context/map-context.js @@ -39,7 +39,6 @@ const layerTypes = { }, }; - export const LayersProvider = ({ children }) => { const [defaultModelLayers, setDefaultModelLayers] = useState([]); const [hurricaneTrackLayers, setHurricaneTrackLayers] = useState([]); @@ -49,6 +48,48 @@ export const LayersProvider = ({ children }) => { const [map, setMap] = useState(null); + /** + * removes the observation "target" icons and dialogs from the map + */ + const removeObservations = ( id ) => { + // init the product name + let product_name = ''; + + // did we get a layer id + if (id !== undefined) { + const index = defaultModelLayers.findIndex(l => l.id === id); + + // find this item in the layer list + if (index === -1) { + console.error('Could not locate layer', id); + + // no need to continue + return; + } + else + // get the layers' product name + product_name = defaultModelLayers[index]['properties']['product_name']; + } + else + // no incoming id defaults to removing all selected observations + product_name = 'Observations'; + + // clear all observations if this is an observation layer + if (product_name === 'Observations') { + // remove all the targets on the map + map.eachLayer((layer) => { + // if this is an observation selection marker + if (layer.options && layer.options.pane === "markerPane") { + // remove the layer + map.removeLayer(layer); + } + }); + + // remove all the dialogs from the data list + setSelectedObservations(selectedObservations.filter(item => item === undefined)); + } + }; + const toggleHurricaneLayerVisibility = id => { const newLayers = [...hurricaneTrackLayers]; const index = newLayers.findIndex(l => l.id === id); @@ -72,6 +113,10 @@ export const LayersProvider = ({ children }) => { console.error('Could not locate layer', id); return; } + + // if this is a observation layer remove all observation layers/dialogs from the map + removeObservations(id); + const alteredLayer = newLayers[index]; alteredLayer.state.visible = !alteredLayer.state.visible; setDefaultModelLayers([ @@ -132,6 +177,9 @@ export const LayersProvider = ({ children }) => { } const newLayers = defaultModelLayers.filter(l => l.id !== id); setDefaultModelLayers(newLayers); + + // if this is a observation layer remove all observation layers/dialogs from the map + removeObservations(id); }; const removeModelRun = groupId => { @@ -147,6 +195,9 @@ export const LayersProvider = ({ children }) => { layer.state = newLayerDefaultState(layer, newLayers[0].group); }); + // remove all observations when there is a model run removal + removeObservations(); + setDefaultModelLayers(newLayers); }; @@ -195,6 +246,7 @@ export const LayersProvider = ({ children }) => { swapLayers, removeLayer, removeModelRun, + removeObservations, layerTypes, baseMap, setBaseMap, From 4d2fc1c7f2ce4b2dab0baf9eb689d4f3e95fe5b9 Mon Sep 17 00:00:00 2001 From: Phil Owen <19691521+PhillipsOwen@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:27:24 -0400 Subject: [PATCH 3/8] changing control name to something more appropriate --- src/components/trays/remove/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/trays/remove/index.js b/src/components/trays/remove/index.js index 009b8565..588d5f17 100644 --- a/src/components/trays/remove/index.js +++ b/src/components/trays/remove/index.js @@ -3,7 +3,7 @@ import { Stack } from '@mui/joy'; import { Delete as RemoveIcon} from '@mui/icons-material'; // import the components that will remove selected items from state -import { RemoveObservations } from "./remove-observations"; +import { RemoveAllObservations } from "./remove-observations"; import { RemoveModels } from "./remove-models"; // get an icon for the tray @@ -19,7 +19,7 @@ export const title = 'Remove items'; */ export const trayContents = () => ( - + ); From d64552dc874e185e01f6959291f406d3491197c4 Mon Sep 17 00:00:00 2001 From: Phil Owen <19691521+PhillipsOwen@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:28:04 -0400 Subject: [PATCH 4/8] changing control name to something more appropriate, moving remove observation operations to a common place. --- .../trays/remove/remove-observations.js | 33 ++++--------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/src/components/trays/remove/remove-observations.js b/src/components/trays/remove/remove-observations.js index fca4b740..d278ab82 100644 --- a/src/components/trays/remove/remove-observations.js +++ b/src/components/trays/remove/remove-observations.js @@ -1,6 +1,6 @@ import React, { Fragment } from 'react'; import { Button } from '@mui/joy'; -import {useLayers} from "@context"; +import { useLayers } from "@context"; /** * component that handles the removal of observations. @@ -8,35 +8,14 @@ import {useLayers} from "@context"; * @returns {JSX.Element} * @constructor */ -export const RemoveObservations = () => { - // get references to the observation data/list - const { - map, - selectedObservations, - setSelectedObservations - } = useLayers(); - - /** - * remove the observation selections from state and map - */ - function removeObservations() { - // remove all the targets on the map - map.eachLayer((layer) => { - // if this is an observation selection marker - if (layer.options && layer.options.pane === "markerPane") { - // remove the layer - map.removeLayer(layer); - } - }); - - // remove all the dialog items from the data list - setSelectedObservations(selectedObservations.filter(item => item === undefined)); - } +export const RemoveAllObservations = () => { + // get the method to remove the observation items in state + const { removeObservations } = useLayers(); // render the button return ( - + - ); + ); }; From caa6d951aa9734b8caf4dcc5b2f6654d25d39fdb Mon Sep 17 00:00:00 2001 From: Phil Owen <19691521+PhillipsOwen@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:28:55 -0400 Subject: [PATCH 5/8] removing selected observations when a new model run is added. --- src/components/trays/model-selection/catalogItems.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/trays/model-selection/catalogItems.js b/src/components/trays/model-selection/catalogItems.js index 1f281a5f..5d9b8a19 100644 --- a/src/components/trays/model-selection/catalogItems.js +++ b/src/components/trays/model-selection/catalogItems.js @@ -15,7 +15,7 @@ CatalogItems.propTypes = { data: PropTypes.any }; */ export default function CatalogItems(data) { // get the layers in state - const { defaultModelLayers, setDefaultModelLayers } = useLayers(); + const { removeObservations, defaultModelLayers, setDefaultModelLayers } = useLayers(); // create some state for what catalog accordian is expanded/not expanded const [accordianDateIndex, setAccordianDateIndex] = useState(-1); @@ -38,6 +38,9 @@ export default function CatalogItems(data) { // add or remove the layer group handleSelectedLayers(layerGroup, layers, checked); + + // remove all selected observations + removeObservations(); }; /** From 19b04fcc186e4f9b704b1a5e46fd16d19ddb166f Mon Sep 17 00:00:00 2001 From: Phil Owen <19691521+PhillipsOwen@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:29:43 -0400 Subject: [PATCH 6/8] removing code that removed selected observations --- src/components/control-panel/control-panel.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/components/control-panel/control-panel.js b/src/components/control-panel/control-panel.js index f50c0949..d70e6e23 100644 --- a/src/components/control-panel/control-panel.js +++ b/src/components/control-panel/control-panel.js @@ -35,10 +35,7 @@ const layerIcons = { export const ControlPanel = () => { - const { map, - selectedObservations, - setSelectedObservations, - defaultModelLayers, + const { defaultModelLayers, hurricaneTrackLayers, setDefaultModelLayers, getAllLayersInvisible, @@ -233,18 +230,6 @@ export const ControlPanel = () => { // switch on/off the observation layer if it exists const toggleObsLayer = () => { toggleLayerVisibility(obs_layer.id); - - // remove all the "target" overlays from state - map.eachLayer((layer) => { - // if this is an observation selection marker - if (layer.options && layer.options.pane === "markerPane") { - // remove the layer - map.removeLayer(layer); - } - }); - - // remove all the observation dialogs from state - setSelectedObservations(selectedObservations.filter(item => item === undefined)); }; // switch on/off the hurricane track layer, if it exists From 73c2bb31709dce2a1e701cef4957c5891a090326 Mon Sep 17 00:00:00 2001 From: Phil Owen <19691521+PhillipsOwen@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:38:25 -0400 Subject: [PATCH 7/8] making sure that selected observations are cleared on a model run drag event --- src/components/trays/layers/list.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/trays/layers/list.js b/src/components/trays/layers/list.js index 3058aeb9..92e4965b 100644 --- a/src/components/trays/layers/list.js +++ b/src/components/trays/layers/list.js @@ -172,7 +172,7 @@ const newLayerDefaultState = (layer, group) => { */ export const LayersList = () => { // get a handle to the layer state - const {defaultModelLayers, setDefaultModelLayers} = useLayers(); + const { removeObservations, defaultModelLayers, setDefaultModelLayers } = useLayers(); // get the default layers const layers = [...defaultModelLayers]; @@ -205,6 +205,9 @@ export const LayersList = () => { // reorder the layers and put them back in state reOrderLayers(grpList); + + // clear out all the selected observations + removeObservations(); }; /** From 900e8ee6c0a5e631e4638a650f5dd64c90969ec1 Mon Sep 17 00:00:00 2001 From: Phil Owen <19691521+PhillipsOwen@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:57:01 -0400 Subject: [PATCH 8/8] making sure that selected observations are cleared on a cycle increment --- src/components/control-panel/control-panel.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/control-panel/control-panel.js b/src/components/control-panel/control-panel.js index d70e6e23..bf8c1e78 100644 --- a/src/components/control-panel/control-panel.js +++ b/src/components/control-panel/control-panel.js @@ -35,7 +35,8 @@ const layerIcons = { export const ControlPanel = () => { - const { defaultModelLayers, + const { removeObservations, + defaultModelLayers, hurricaneTrackLayers, setDefaultModelLayers, getAllLayersInvisible, @@ -305,6 +306,9 @@ export const ControlPanel = () => { const changeModelRunCycle = (e) => { const direction = e.currentTarget.getAttribute("button-key"); metClass === "synoptic" ? changeSynopticCycle(direction) : changeTropicalAdvisory(direction); + + // remove all selected observations + removeObservations(); }; return (