[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: Mon, 1 Jul 2019 10:39:05 +0000 (UTC)
commit 07046c4c7ae1b9ec690a181560758a8ee945dd06
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 | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
---
diff --git a/src/place.js b/src/place.js
index 7d72af2..dbc85cc 100644
--- a/src/place.js
+++ b/src/place.js
@@ -19,10 +19,14 @@
* Author: Jonas Danielsson <jonas threetimestwo org>
*/
+const _ = imports.gettext.gettext;
+
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 +42,12 @@ const DMS_COORDINATES_REGEX = new RegExp(
"i"
);
+const OSM_OBJECT_URL_REGEX =
+ new RegExp(/https?:\/\/(www\.)?openstreetmap\.org\/(node|way|relation)\/(\d+)\/?$/);
+
+const OSM_COORD_URL_REGEX =
+ new
RegExp(/https?:\/\/(www.)?openstreetmap\.org\/\?m?lat=^\s*(\-?\d+(?:\.\d+)?)\s*\&m?lon=^\s*(\-?\d+(?:\.\d+)?)\s/);
+
var Place = GObject.registerClass(
class Place extends Geocode.Place {
@@ -434,3 +444,30 @@ Place.parseCoordinates = function(text) {
return null;
}
};
+
+function matchOSMURL(text) {
+ return text.match(OSM_OBJECT_URL_REGEX);
+}
+
+let overpass = null;
+
+function parseHttpURL(text, callback) {
+ let [,, type, id] = text.match(OSM_OBJECT_URL_REGEX);
+ let storedPlace = imports.placeStore.existsWithOsmTypeAndId(type, id);
+
+ if (storedPlace) {
+ callback(storedPlace, null);
+ return;
+ }
+
+ if (overpass === null)
+ overpass = new Overpass.Overpass();
+
+ overpass.fetchPlace(type, id, (place) => {
+ if (place)
+ callback(place, null);
+ else
+ callback(null, _("Place not found in OpenStreetMap"));
+ });
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]