Bug fix to support more overlay definitions

This commit is contained in:
Eric van der Vlist 2023-05-16 19:29:00 +02:00
parent c8367450d6
commit 2295991f23
2 changed files with 23 additions and 9 deletions

View File

@ -28,6 +28,7 @@ import {
overlayCategories, overlayCategories,
overlayDefinitions, overlayDefinitions,
} from '../overlays/overlay-definitions'; } from '../overlays/overlay-definitions';
import { cloneDeep } from 'lodash';
const id = getUri('overlays', undefined); const id = getUri('overlays', undefined);
@ -113,15 +114,16 @@ type Overlay = {
}; };
type Overlays = Record<string, Overlay>; type Overlays = Record<string, Overlay>;
const defaultOverlayContent = {
selected: false,
highlighted: {
none: [],
},
hidden: { none: [] },
};
const defaultOverlays: Overlays = { const defaultOverlays: Overlays = {
none: { selected: true, highlighted: { none: [] }, hidden: {} }, none: { selected: true, highlighted: { none: [] }, hidden: {} },
hiking: {
selected: false,
highlighted: {
none: [],
},
hidden: { none: [] },
},
}; };
// type OverlayDefinition = Record<string, FeatureTypes>; // type OverlayDefinition = Record<string, FeatureTypes>;
@ -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 handleOverlayChange = (ev: any) => {
const value = ev.target.value; const value = ev.target.value;
console.log({ console.log({
@ -387,7 +397,7 @@ const MapTilesProvider: Component<{}> = (props) => {
ev, ev,
value, value,
}); });
const newOverlays = getOverlays(); const newOverlays = getOverlaysAddingSelectedIfMissing(value);
Object.keys(newOverlays).forEach((key) => { Object.keys(newOverlays).forEach((key) => {
newOverlays[key].selected = key === value; newOverlays[key].selected = key === value;
}); });

View File

@ -3,7 +3,11 @@ import { Feature } from 'ol';
export const overlayDefinitions = { export const overlayDefinitions = {
amenity: { amenity: {
bar: { hiking: { drinking: true } }, bar: {
hiking: { drinking: true },
cycling: { drinking: true },
vanlife: { drinking: true },
},
fast_food: { hiking: { eating: true } }, fast_food: { hiking: { eating: true } },
food_court: { hiking: { eating: true } }, food_court: { hiking: { eating: true } },
pub: { hiking: { eating: true } }, pub: { hiking: { eating: true } },