[gnome-maps/wip/mlundblad/reduce-dup-place-init: 5/7] place: Add method to update place from tags




commit ec2dd132fb947078b4fbb259e7d0f2d147518ab6
Author: Marcus Lundblad <ml update uu se>
Date:   Wed Sep 22 22:35:05 2021 +0200

    place: Add method to update place from tags
    
    Add a method to update a place from OSM tags.

 src/place.js | 78 +++++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 53 insertions(+), 25 deletions(-)
---
diff --git a/src/place.js b/src/place.js
index 87948a74..2c2a1a12 100644
--- a/src/place.js
+++ b/src/place.js
@@ -48,42 +48,22 @@ var Place = GObject.registerClass(
 class Place extends Geocode.Place {
 
     _init(params) {
-        this._isCurrentLocation = params.isCurrentLocation;
-        delete params.isCurrentLocation;
+        this.updateFromTags(params);
 
-        this._population = params.population;
         delete params.population;
-
-        this._website = params.website;
         delete params.website;
-
-        this._email = params.email;
         delete params.email;
-
-        this._phone = params.phone;
         delete params.phone;
-
-        this._wiki = params.wiki;
         delete params.wiki;
-
-        this._openingHours = params.openingHours;
         delete params.openingHours;
-
-        this._internetAccess = params.internetAccess;
         delete params.internetAccess;
-
-        this._religion = params.religion;
         delete params.religion;
-
-        this._toilets = params.toilets;
-        delete params.toilets;
-
-        this._takeaway = params.takeaway;
         delete params.takeaway;
-
-        this._note = params.note;
         delete params.note;
 
+        this._isCurrentLocation = params.isCurrentLocation;
+        delete params.isCurrentLocation;
+
         this._initialZoom = params.initialZoom;
         delete params.initialZoom;
 
@@ -102,7 +82,6 @@ class Place extends Geocode.Place {
             delete params.store;
         }
 
-        this._wheelchair = params.wheelchair;
         delete params.wheelchair;
 
         this._nativeName = params.nativeName;
@@ -141,6 +120,55 @@ class Place extends Geocode.Place {
         super._init(params);
     }
 
+    /**
+     * Update place with values from OSM tags.
+     */
+    updateFromTags(tags) {
+        /* special handle tags where we use a different name compared to
+         * OSM, to remain backwards-compatible with the place store
+         */
+        let wiki = tags.wiki ?? tags.wikipedia;
+        let openingHours = tags.openingHours ?? tags.opening_hours;
+        let internetAccess = tags.internetAccess ?? tags.internet_access;
+
+        if (tags.name)
+            this.nativeName = tags.name;
+        if (tags.population)
+            this.population = tags.population;
+        if (tags['contact:website'])
+            this.website = tags['contact:website'];
+        if (tags.website)
+            this.website = tags.website;
+        if (tags['contact:email'])
+            this.email = tags['contact:email'];
+        if (tags.email)
+            this.email = tags.email;
+        if (tags['contact:phone'])
+            this.phone = tags['contact:phone'];
+        if (tags.phone)
+            this.phone = tags.phone;
+        if (wiki)
+            this.wiki = wiki;
+        if (tags.wheelchair)
+            this.wheelchair = tags.wheelchair;
+        if (openingHours)
+            this.openingHours = openingHours;
+        if (internetAccess)
+            this.internetAccess = internetAccess;
+        if (tags.ele && this.location)
+            this.location.altitude = parseFloat(tags.ele);
+        else if (tags.ele && tags.location)
+            tags.location.altitude = tags.ele;
+        if (tags.religion)
+            this.religion = tags.religion
+        if (tags.toilets)
+            this.toilets = tags.toilets;
+        if (tags.takeaway)
+            this.takeaway = tags.takeaway;
+        if (tags.note)
+            this.note = tags.note;
+    }
+
     set store(v) {
         this._store = v;
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]