[gnome-maps/wip/mlundblad/handle-osm-urls] WIP: place: Add parsing of OSM URLs



commit a6496242eecbc327bdb6853067fe75a9c43a00be
Author: Marcus Lundblad <ml update uu se>
Date:   Thu Jun 13 21:54:54 2019 +0200

    WIP: place: Add parsing of OSM URLs

 src/place.js | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
---
diff --git a/src/place.js b/src/place.js
index babb8b6..a6d489e 100644
--- a/src/place.js
+++ b/src/place.js
@@ -22,6 +22,8 @@
 const Geocode = imports.gi.GeocodeGlib;
 const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
+
+const Application = imports.application;
 const Location = imports.location;
 const Translations = imports.translations;
 const Utils = imports.utils;
@@ -38,6 +40,9 @@ const DMS_COORDINATES_REGEX = new RegExp(
     "i"
 );
 
+const OSM_OBJECT_URL_REGEX =
+    new RegExp(/https?:\/\/(www\.)?openstreetmap\.org\/(node|way|relation)\/(\d+)\/?$/);
+
 var Place = GObject.registerClass(
 class Place extends Geocode.Place {
 
@@ -419,3 +424,28 @@ Place.parseCoordinates = function(text) {
         return null;
     }
 };
+
+function matchOSMURL(text) {
+    reurn text.match(OSM_OBJECT_URL_REGEX);
+}
+
+function parseOSMURL(text, callback, cancellable) {
+    let [,, type, id] = text.match(OSM);
+    let location = new Location.Location();
+    let place = new Place( { location: location,
+                             osm_type: type,
+                             osm_id:   id });
+
+    Application.osmEdit.fetchObject(place,
+                                    (sucess, status, osmObject, osmType) => {
+        if (sucess) {
+            location.latitude = osmObject.get_tag('lat');
+            location.longitude = osmObject.get_tag('lon');
+
+            callback(place);
+        } else {
+            callback(null);
+        }
+    }, cancellable);
+}
+


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