Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

UI update: Reverse Geocoding functionality for MaplibreGeocoder using nominatim.org (#1149)

Panos Kalogeropoulosd742fefaa8fb
diff --git a/ui/component/or-map/src/mapwidget.ts b/ui/component/or-map/src/mapwidget.ts
index a7d2de8c4..496eb774f 100644
--- a/ui/component/or-map/src/mapwidget.ts
+++ b/ui/component/or-map/src/mapwidget.ts
@@ -904,9 +904,36 @@ export class MapWidget {
};
}
- protected async _reverseGeocode(config: any) {
+ public async _reverseGeocode(config: {lat: number, lon:number}) {
+ const features = [];
+ try {
+ let request = this._viewSettings!.geocodeUrl + '/reverse?lat=' + config.lat + '&lon='+config.lon+'&format=geojson&polygon_geojson=1&addressdetails=1';
+ const response = await fetch(request);
+ const geojson = await response.json();
+ for (let feature of geojson.features) {
+ let center = [feature.bbox[0] + (feature.bbox[2] - feature.bbox[0]) / 2, feature.bbox[1] + (feature.bbox[3] - feature.bbox[1]) / 2 ];
+ let point = {
+ type: 'Feature',
+ geometry: {
+ type: 'Point',
+ coordinates: center
+ },
+ place_name: feature.properties.display_name,
+ properties: feature.properties,
+ text: feature.properties.display_name,
+ place_type: ['place'],
+ center: center
+ };
+ features.push(point);
+ }
+ } catch (e) {
+ console.error(`Failed to reverseGeocode with error: ${e}`);
+ }
- }
+ return {
+ features: features
+ };
+ }
protected _initLongPressEvent() {
if (this._mapGl) {