Codebase list gnome-maps / 2d9988e
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 Marcus Lundblad 8 years ago
5 changed file(s) with 160 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
00 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
11
2 SUBDIRS = lib src data po
2 SUBDIRS = lib src data po scripts
7474 data/Makefile
7575 data/icons/Makefile
7676 po/Makefile.in
77 scripts/Makefile
7778 ])
7879 AC_OUTPUT
0 noinst_DATA = \
1 extractPoiTypesFromID.js \
2 README
3
4 EXTRA_DIST = $(noinst_DATA)
5
6 -include $(top_srcdir)/git.mk
7
8
0 SCRIPTS
1 =======
2
3 extractPoiTypesFromID.js
4 ------------------------
5
6 Extracts the POI types (presets) that the iD editor uses to JSON for us to consume.
7
8 Run the extractPoiTypesFromID.js script against a checkout of iD (https://github.com/openstreetmap/iD)
9
10 $ ./extractPoiTypesFromID.js <path to iD checkout> > osm-types.json
11
12 This script would be run by upstream before making a release of gnome-maps if an updated version
13 of the iD editor is available with updated OSM types preset and/or new or updated translations
14 of those.
15 Check the resulting .json file (i.e. check size and possibly diff against the current version).
16 Copy the result to data/osm-types.json
17
0 #!/usr/bin/env gjs
1
2 /* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
3 /* vim: set et ts=4 sw=4: */
4 /*
5 * Copyright (c) 2016 Marcus Lundblad.
6 *
7 * GNOME Maps is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 * GNOME Maps is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>.
19 *
20 * Author: Marcus Lundblad <ml@update.uu.se>
21 */
22
23 /*
24 * Script to generate a simplified JSON mapping file for POI types from the
25 * presets definitions from the iD Web-based OpenStreetMap editor
26 *
27 * Usage: ./extractPoiTypesFromID.js <path to iD checkout> > osm-types.json
28 *
29 */
30
31 const Gio = imports.gi.Gio;
32
33 const PRESETS_PATH = 'data/presets/presets';
34 const LOCALES_PATH = 'dist/locales';
35 const PRESET_TYPES = [ 'amenity',
36 'leisure',
37 'office',
38 'place',
39 'shop',
40 'tourism' ];
41
42 const OUTPUT = {};
43
44 function parseJson(dirPath, fileName) {
45 let file = Gio.File.new_for_path(dirPath + '/' + fileName);
46 let [status, buffer] = file.load_contents(null);
47 let {tags, name} = JSON.parse(buffer);
48
49 for (let key in tags) {
50 let value = tags[key];
51
52 OUTPUT[key + '/' + value] = {'title': {'C': name}};
53 }
54 }
55
56 function processType(type, basePath) {
57 let dirPath = [basePath, PRESETS_PATH, type].join('/');
58 let dir = Gio.File.new_for_path(dirPath);
59 let enumerator =
60 dir.enumerate_children('*',
61 Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
62
63 while (true) {
64 let file = enumerator.next_file(null);
65
66 if (file === null)
67 break;
68
69 if (file.get_name().endsWith('.json'))
70 parseJson(dirPath, file.get_name());
71 }
72 }
73
74 function processTypes(basePath) {
75 PRESET_TYPES.forEach(function(type) {
76 processType(type, basePath);
77 });
78 }
79
80 function processLocale(dirPath, fileName) {
81 let file = Gio.File.new_for_path(dirPath + '/' + fileName);
82 let [status, buffer] = file.load_contents(null);
83 let object = JSON.parse(buffer);
84 let lang = fileName.substring(0, fileName.indexOf('.json'));
85
86 for (let type in OUTPUT) {
87 let name;
88
89 try {
90 name = object.presets.presets[type].name;
91 } catch (ex) {
92 continue;
93 }
94
95 OUTPUT[type].title[lang] = name;
96 }
97 }
98
99 function processLocales(basePath) {
100 let dirPath = basePath + '/' + LOCALES_PATH;
101 let dir = Gio.File.new_for_path(dirPath);
102 let enumerator =
103 dir.enumerate_children('*.json',
104 Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
105
106 while (true) {
107 let file = enumerator.next_file(null);
108
109 if (file === null)
110 break;
111
112 if (file.get_name().endsWith('.json'))
113 processLocale(dirPath, file.get_name());
114 }
115 }
116
117 function outputJson() {
118 print(JSON.stringify(OUTPUT));
119 }
120
121 function main(args) {
122 let path = args[0];
123
124 processTypes(path);
125 processLocales(path);
126
127 outputJson();
128 }
129
130 main(ARGV);