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



commit 6f84f3079ff3b517294d97b89f18bd08e528cc0c
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 babb8b6..5f4d3a8 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 {
 
@@ -419,3 +424,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]