Skip to content

Commit

Permalink
feat: add Multipoint support with useGeometry composable #189
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Mar 8, 2024
1 parent e1b1ca3 commit 0af8505
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
33 changes: 33 additions & 0 deletions composables/useGeometry.ts
Original file line number Diff line number Diff line change
@@ -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,
}
}
5 changes: 4 additions & 1 deletion stores/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
Expand Down

0 comments on commit 0af8505

Please sign in to comment.