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



commit 774abd9db8a620f3b7915cead6ea3bd351616b7b
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 | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
---
diff --git a/src/place.js b/src/place.js
index 7d72af2..e7b1016 100644
--- a/src/place.js
+++ b/src/place.js
@@ -22,7 +22,9 @@
 const Geocode = imports.gi.GeocodeGlib;
 const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
+
 const Location = imports.location;
+const Overpass = imports.overpass;
 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 {
 
@@ -434,3 +439,19 @@ Place.parseCoordinates = function(text) {
         return null;
     }
 };
+
+function matchOSMURL(text) {
+    return text.match(OSM_OBJECT_URL_REGEX);
+}
+
+let overpass = null;
+
+function parseOSMURL(text, callback) {
+    let [,, type, id] = text.match(OSM_OBJECT_URL_REGEX);
+
+    if (overpass === null)
+        overpass = new Overpass.Overpass();
+
+    overpass.fetchPlace(type, id, (place) => callback(place));
+}
+


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