diff --git a/composables/useGeometry.ts b/composables/useGeometry.ts new file mode 100644 index 000000000..0466529c2 --- /dev/null +++ b/composables/useGeometry.ts @@ -0,0 +1,33 @@ +import type { MultiPoint } from 'geojson' +import type { MapPoi } from '~/lib/mapPois' + +export default function () { + const flattenMultipoint = (features: MapPoi[]): MapPoi[] => { + const explodedPointFeatures: MapPoi[] = [] + features.forEach((f: MapPoi) => { + if (f.geometry.type === 'MultiPoint') { + const { coordinates } = f.geometry as MultiPoint + + coordinates.forEach((coords: number[]) => { + explodedPointFeatures.push({ + ...f, + geometry: { + type: 'Point', + coordinates: coords, + }, + }) + }) + } + + return f + }) + + features = features.filter(f => f.geometry.type !== 'MultiPoint') + + return [...features, ...explodedPointFeatures] + } + + return { + flattenMultipoint, + } +} diff --git a/stores/menu.ts b/stores/menu.ts index 343865f13..af4cd2af4 100644 --- a/stores/menu.ts +++ b/stores/menu.ts @@ -171,7 +171,7 @@ export const menuStore = defineStore('menu', { Boolean(previousFeatures[categoryId]), ) - const posts: ApiPois[] = ( + let posts: ApiPois[] = ( await Promise.all( categoryIds .filter(categoryId => !previousFeatures[categoryId]) @@ -191,6 +191,9 @@ export const menuStore = defineStore('menu', { ) ).filter(e => e) as ApiPois[] + const { flattenMultipoint } = useGeometry() + posts = posts.map(p => ({ ...p, features: flattenMultipoint(p.features) as ApiPoi[] })) + const features: State['features'] = {} let i = 0