From 2295991f23f48bef1edab0cae322fa185040c2e9 Mon Sep 17 00:00:00 2001 From: evlist Date: Tue, 16 May 2023 19:29:00 +0200 Subject: [PATCH] Bug fix to support more overlay definitions --- .../map-tile-provider/MapTileProvider.tsx | 26 +++++++++++++------ .../overlays/overlay-definitions.ts | 6 ++++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/components/map-tile-provider/MapTileProvider.tsx b/src/components/map-tile-provider/MapTileProvider.tsx index e4eac60..d0fcdb8 100644 --- a/src/components/map-tile-provider/MapTileProvider.tsx +++ b/src/components/map-tile-provider/MapTileProvider.tsx @@ -28,6 +28,7 @@ import { overlayCategories, overlayDefinitions, } from '../overlays/overlay-definitions'; +import { cloneDeep } from 'lodash'; const id = getUri('overlays', undefined); @@ -113,15 +114,16 @@ type Overlay = { }; type Overlays = Record; +const defaultOverlayContent = { + selected: false, + highlighted: { + none: [], + }, + hidden: { none: [] }, +}; + const defaultOverlays: Overlays = { none: { selected: true, highlighted: { none: [] }, hidden: {} }, - hiking: { - selected: false, - highlighted: { - none: [], - }, - hidden: { none: [] }, - }, }; // type OverlayDefinition = Record; @@ -380,6 +382,14 @@ const MapTilesProvider: Component<{}> = (props) => { }); }); + const getOverlaysAddingSelectedIfMissing = (key: string) => { + const overlays = getOverlays(); + if (!Object.keys(overlays).includes(key)) { + overlays[key] = cloneDeep(defaultOverlayContent); + } + return overlays; + }; + const handleOverlayChange = (ev: any) => { const value = ev.target.value; console.log({ @@ -387,7 +397,7 @@ const MapTilesProvider: Component<{}> = (props) => { ev, value, }); - const newOverlays = getOverlays(); + const newOverlays = getOverlaysAddingSelectedIfMissing(value); Object.keys(newOverlays).forEach((key) => { newOverlays[key].selected = key === value; }); diff --git a/src/components/overlays/overlay-definitions.ts b/src/components/overlays/overlay-definitions.ts index b0d18cb..f229cd4 100644 --- a/src/components/overlays/overlay-definitions.ts +++ b/src/components/overlays/overlay-definitions.ts @@ -3,7 +3,11 @@ import { Feature } from 'ol'; export const overlayDefinitions = { amenity: { - bar: { hiking: { drinking: true } }, + bar: { + hiking: { drinking: true }, + cycling: { drinking: true }, + vanlife: { drinking: true }, + }, fast_food: { hiking: { eating: true } }, food_court: { hiking: { eating: true } }, pub: { hiking: { eating: true } },