summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Lundblad <ml@update.uu.se>2016-01-31 11:48:46 +0100
committerMarcus Lundblad <ml@update.uu.se>2016-02-12 07:55:19 +0100
commit2d9988ee5dda6f9bdf2ff0bba6394d4ef82647d2 (patch)
tree2c60faf87df951b06106c6c975164fa9460bba15
parent3930b1782a71ee999260dc8f842a24105f4c4de6 (diff)
downloadgnome-maps-2d9988ee5dda6f9bdf2ff0bba6394d4ef82647d2.tar.gz
osmEdit: Add GJS script to extract POI definitions from the iD OSM editor
This creates an updated definition of POI types (with translations) from a checkout of the iD editor's code. This script could be run (and the output copied to data/osm-types.json) if POI presets have been added and/or updated or if new or updated translations are available in a new version of iD. https://bugzilla.gnome.org/show_bug.cgi?id=761327
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac1
-rw-r--r--scripts/Makefile.am9
-rw-r--r--scripts/README18
-rwxr-xr-xscripts/extractPoiTypesFromID.js131
5 files changed, 160 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 8f53c8fa..c5dd3b6a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,3 +1,3 @@
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
-SUBDIRS = lib src data po
+SUBDIRS = lib src data po scripts
diff --git a/configure.ac b/configure.ac
index b8cab4d8..f0ca3cc1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,5 +75,6 @@ AC_CONFIG_FILES([
data/Makefile
data/icons/Makefile
po/Makefile.in
+ scripts/Makefile
])
AC_OUTPUT
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
new file mode 100644
index 00000000..ae31c48a
--- /dev/null
+++ b/scripts/Makefile.am
@@ -0,0 +1,9 @@
+noinst_DATA = \
+ extractPoiTypesFromID.js \
+ README
+
+EXTRA_DIST = $(noinst_DATA)
+
+-include $(top_srcdir)/git.mk
+
+
diff --git a/scripts/README b/scripts/README
new file mode 100644
index 00000000..2be7d78f
--- /dev/null
+++ b/scripts/README
@@ -0,0 +1,18 @@
+SCRIPTS
+=======
+
+extractPoiTypesFromID.js
+------------------------
+
+Extracts the POI types (presets) that the iD editor uses to JSON for us to consume.
+
+Run the extractPoiTypesFromID.js script against a checkout of iD (https://github.com/openstreetmap/iD)
+
+$ ./extractPoiTypesFromID.js <path to iD checkout> > osm-types.json
+
+This script would be run by upstream before making a release of gnome-maps if an updated version
+of the iD editor is available with updated OSM types preset and/or new or updated translations
+of those.
+Check the resulting .json file (i.e. check size and possibly diff against the current version).
+Copy the result to data/osm-types.json
+
diff --git a/scripts/extractPoiTypesFromID.js b/scripts/extractPoiTypesFromID.js
new file mode 100755
index 00000000..30d5279b
--- /dev/null
+++ b/scripts/extractPoiTypesFromID.js
@@ -0,0 +1,131 @@
+#!/usr/bin/env gjs
+
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2016 Marcus Lundblad.
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Marcus Lundblad <ml@update.uu.se>
+ */
+
+/*
+ * Script to generate a simplified JSON mapping file for POI types from the
+ * presets definitions from the iD Web-based OpenStreetMap editor
+ *
+ * Usage: ./extractPoiTypesFromID.js <path to iD checkout> > osm-types.json
+ *
+ */
+
+const Gio = imports.gi.Gio;
+
+const PRESETS_PATH = 'data/presets/presets';
+const LOCALES_PATH = 'dist/locales';
+const PRESET_TYPES = [ 'amenity',
+ 'leisure',
+ 'office',
+ 'place',
+ 'shop',
+ 'tourism' ];
+
+const OUTPUT = {};
+
+function parseJson(dirPath, fileName) {
+ let file = Gio.File.new_for_path(dirPath + '/' + fileName);
+ let [status, buffer] = file.load_contents(null);
+ let {tags, name} = JSON.parse(buffer);
+
+ for (let key in tags) {
+ let value = tags[key];
+
+ OUTPUT[key + '/' + value] = {'title': {'C': name}};
+ }
+}
+
+function processType(type, basePath) {
+ let dirPath = [basePath, PRESETS_PATH, type].join('/');
+ let dir = Gio.File.new_for_path(dirPath);
+ let enumerator =
+ dir.enumerate_children('*',
+ Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
+
+ while (true) {
+ let file = enumerator.next_file(null);
+
+ if (file === null)
+ break;
+
+ if (file.get_name().endsWith('.json'))
+ parseJson(dirPath, file.get_name());
+ }
+}
+
+function processTypes(basePath) {
+ PRESET_TYPES.forEach(function(type) {
+ processType(type, basePath);
+ });
+}
+
+function processLocale(dirPath, fileName) {
+ let file = Gio.File.new_for_path(dirPath + '/' + fileName);
+ let [status, buffer] = file.load_contents(null);
+ let object = JSON.parse(buffer);
+ let lang = fileName.substring(0, fileName.indexOf('.json'));
+
+ for (let type in OUTPUT) {
+ let name;
+
+ try {
+ name = object.presets.presets[type].name;
+ } catch (ex) {
+ continue;
+ }
+
+ OUTPUT[type].title[lang] = name;
+ }
+}
+
+function processLocales(basePath) {
+ let dirPath = basePath + '/' + LOCALES_PATH;
+ let dir = Gio.File.new_for_path(dirPath);
+ let enumerator =
+ dir.enumerate_children('*.json',
+ Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
+
+ while (true) {
+ let file = enumerator.next_file(null);
+
+ if (file === null)
+ break;
+
+ if (file.get_name().endsWith('.json'))
+ processLocale(dirPath, file.get_name());
+ }
+}
+
+function outputJson() {
+ print(JSON.stringify(OUTPUT));
+}
+
+function main(args) {
+ let path = args[0];
+
+ processTypes(path);
+ processLocales(path);
+
+ outputJson();
+}
+
+main(ARGV);