Skip to content

Commit

Permalink
Update show/hide icon
Browse files Browse the repository at this point in the history
Based on action eye closed or eye icon will be displayed.

Signed-off-by: Vijayan Balasubramanian <[email protected]>
  • Loading branch information
VijayanB committed Dec 8, 2022
1 parent 5523e00 commit 6a4f23d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions maps_dashboards/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const MAP_LAYER_DEFAULT_OPACITY_STEP = 1;
export const MAP_LAYER_DEFAULT_BORDER_THICKNESS = 1;
export const DOCUMENTS_DEFAULT_REQUEST_NUMBER = 20;
export const DOCUMENTS_DEFAULT_MARKER_SIZE = 5;
export const LAYER_PANEL_SHOW_LAYER_ICON = 'eye'
export const LAYER_PANEL_HIDE_LAYER_ICON = 'eyeClosed'

// Starting position [lng, lat] and zoom
export const MAP_INITIAL_STATE = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import './layer_control_panel.scss';
import { AddLayerPanel } from '../add_layer_panel';
import { LayerConfigPanel } from '../layer_config';
import { MapLayerSpecification } from '../../model/mapLayerType';
import { LAYER_VISIBILITY, DASHBOARDS_MAPS_LAYER_TYPE, LAYER_ICON_TYPE_MAP } from '../../../common';
import {
LAYER_VISIBILITY, DASHBOARDS_MAPS_LAYER_TYPE, LAYER_ICON_TYPE_MAP,
LAYER_PANEL_SHOW_LAYER_ICON, LAYER_PANEL_HIDE_LAYER_ICON
} from '../../../common';
import { layersFunctionMap } from '../../model/layersFunctions';
import { useOpenSearchDashboards } from '../../../../../src/plugins/opensearch_dashboards_react/public';
import { MapServices } from '../../types';
Expand Down Expand Up @@ -140,6 +143,12 @@ const LayerControlPanel = memo(({ maplibreRef, setLayers, layers }: Props) => {
setIsLayerConfigVisible(true);
};

const [layerVisibility, setLayerVisibility] = useState(new Map<string, boolean>([]));
layers.forEach((layer) => {
layerVisibility.set(layer.id, layer.visibility === LAYER_VISIBILITY.VISIBLE);
}
);

if (isLayerControlVisible) {
return (
<I18nProvider>
Expand Down Expand Up @@ -192,13 +201,15 @@ const LayerControlPanel = memo(({ maplibreRef, setLayers, layers }: Props) => {
<EuiFlexGroup justifyContent="flexEnd" gutterSize="none">
<EuiFlexItem grow={false} className="layerControlPanel__layerFunctionButton">
<EuiButtonEmpty
iconType="eyeClosed"
iconType={layerVisibility.get(layer.id) ? LAYER_PANEL_HIDE_LAYER_ICON : LAYER_PANEL_SHOW_LAYER_ICON}
size="s"
onClick={() => {
if (layer.visibility === LAYER_VISIBILITY.VISIBLE) {
layer.visibility = LAYER_VISIBILITY.NONE;
setLayerVisibility(new Map(layerVisibility.set(layer.id, false)));
} else {
layer.visibility = LAYER_VISIBILITY.VISIBLE;
setLayerVisibility(new Map(layerVisibility.set(layer.id, true)));
}
layersFunctionMap[layer.type]?.hide(maplibreRef, layer);
}}
Expand Down

0 comments on commit 6a4f23d

Please sign in to comment.