diff --git a/src/js/components/leftPanel/layersPanel/LayerToggleSwitch.tsx b/src/js/components/leftPanel/layersPanel/LayerToggleSwitch.tsx index 8c2956618..d8821b69c 100644 --- a/src/js/components/leftPanel/layersPanel/LayerToggleSwitch.tsx +++ b/src/js/components/leftPanel/layersPanel/LayerToggleSwitch.tsx @@ -7,7 +7,6 @@ import '../../../../css/layer-toggle-checkbox.scss'; import { handleCustomColorTheme } from '../../../../utils'; import { LAYER_IDS } from '../../../../../configs/layer-config'; import { setProdesLayer } from '../../../store/appState/actions'; -import Switch from 'react-switch'; import ToggleComponent from '../../ui/ToggleComponent'; //Dynamic custom theme override using styled-components lib interface CheckBoxWrapperProps { @@ -62,7 +61,13 @@ const LayerToggleSwitch = (props: LayerToggleProps): React.ReactElement => { return (
- + diff --git a/src/js/components/ui/ToggleComponent.tsx b/src/js/components/ui/ToggleComponent.tsx index c41eba355..8212e0994 100644 --- a/src/js/components/ui/ToggleComponent.tsx +++ b/src/js/components/ui/ToggleComponent.tsx @@ -1,4 +1,5 @@ -import React from 'react'; +import { layer } from 'esri/views/3d/support/LayerPerformanceInfo'; +import React, { useEffect } from 'react'; import Switch from 'react-switch'; interface IToggleComponent { @@ -6,14 +7,28 @@ interface IToggleComponent { checked: boolean; themeColor: string; disabled: boolean; + layerName?: string; } const ToggleComponent = (props: IToggleComponent) => { - const { onChange, checked, themeColor, disabled } = props; + const { onChange, checked, themeColor, disabled, layerName } = props; + + useEffect(() => { + // The class, id, and data-layer-name are tied to Google Analytics. Allows WRI to track clicks on the layer checkboxes and the layer name. + if (!layerName) return; + + const layerElement = document.querySelector(`[data-layer-name="${layerName}"]`); + if (checked) { + layerElement?.setAttribute('class', `layer-checkbox-on`); + } else { + layerElement?.removeAttribute('class'); + } + }, [checked, layerName]); + return (
{ onChange={onChange} checked={checked} disabled={disabled} + id={`layer-checkbox-${layerName}`} + data-layer-name={layerName} />
);