forked from MapComplete/MapComplete
Add search previews on the map
This commit is contained in:
parent
1c46a65c84
commit
4f52483a98
19 changed files with 315 additions and 87 deletions
41
src/Logic/Geocoding/GeocodingFeatureSource.ts
Normal file
41
src/Logic/Geocoding/GeocodingFeatureSource.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { GeoCodeResult } from "./GeocodingProvider"
|
||||
import { Store } from "../UIEventSource"
|
||||
import { FeatureSource } from "../FeatureSource/FeatureSource"
|
||||
import { Feature, Geometry } from "geojson"
|
||||
|
||||
export default class GeocodingFeatureSource implements FeatureSource {
|
||||
public features: Store<Feature<Geometry, Record<string, string>>[]>
|
||||
|
||||
constructor(provider: Store<GeoCodeResult[]>) {
|
||||
this.features = provider.mapD(geocoded => {
|
||||
const features: Feature[] = []
|
||||
|
||||
for (const gc of geocoded) {
|
||||
if (gc.lat === undefined || gc.lon === undefined) {
|
||||
continue
|
||||
}
|
||||
|
||||
features.push({
|
||||
type: "Feature",
|
||||
properties: {
|
||||
id: "search_result_" + gc.osm_type + "/" + gc.osm_id,
|
||||
category: gc.category,
|
||||
description: gc.description,
|
||||
display_name: gc.display_name,
|
||||
osm_id: gc.osm_type + "/" + gc.osm_id,
|
||||
osm_key: gc.feature?.properties?.osm_key,
|
||||
osm_value: gc.feature?.properties?.osm_value
|
||||
},
|
||||
geometry: {
|
||||
type: "Point",
|
||||
coordinates: [gc.lon, gc.lat]
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
return features
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue