[gnome-maps/wip/mlundblad/handle-osm-urls: 2/3] WIP: place: Add parsing of OSM URLs
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/handle-osm-urls: 2/3] WIP: place: Add parsing of OSM URLs
- Date: Wed, 26 Jun 2019 20:52:22 +0000 (UTC)
commit 8788a98e1f51e256cfd66ac368ea419f3eb104ff
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]