Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update show/hide icon #114

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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