-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
67 lines (54 loc) · 2.19 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import fs from 'node:fs';
import localeCompare from 'locale-compare';
import stringify from '@aitodotai/json-stringify-pretty-compact';
const withLocale = localeCompare('en-US');
import presetsJSON from '@openstreetmap/id-tagging-schema/dist/presets.json' with {type: 'json'};
// Because of the open nature of tagging, there will never be a complete
// list of tags used in OSM, so we want it to have logic like "assume
// that a closed way with an amenity tag is an area, unless the amenity
// is one of these specific types". This function computes a structure
// that allows testing of such conditions, based on the presets designated
// as as supporting (or not supporting) the area geometry.
//
// The returned object L is a keeplist/discardlist of tags. A closed way
// with a tag (k, v) is considered to be an area if `k in L && !(v in L[k])`
// (see `iD.osmWay#isArea()`). In other words, the keys of L form the keeplist,
// and the subkeys form the discardlist.
const ignore = ['area', 'barrier', 'highway', 'footway', 'railway', 'type'];
const presets = Object.values(presetsJSON).filter(p => !p.suggestion);
let areaKeys = {};
// keeplist
presets.forEach(d => {
for (var key in d.tags) break;
if (!key) return;
if (ignore.indexOf(key) !== -1) return;
if (d.geometry.indexOf('area') !== -1) { // probably an area..
areaKeys[key] = areaKeys[key] || {};
}
});
// discardlist
presets.forEach(d => {
for (var key in d.tags) break;
if (!key) return;
if (ignore.indexOf(key) !== -1) return;
var value = d.tags[key];
if (key in areaKeys && // probably an area...
d.geometry.indexOf('line') !== -1 && // but sometimes a line
value !== '*') {
areaKeys[key][value] = true;
}
});
if (!fs.existsSync('./dist')) {
fs.mkdirSync('./dist');
}
fs.writeFileSync('./dist/areaKeys.json', stringify({ areaKeys: sortObject(areaKeys) }, { maxLength: 1 }));
// Returns an object with sorted keys and sorted values.
// (This is useful for file diffing)
function sortObject(obj) {
if (!obj) return null;
let sorted = {};
Object.keys(obj).sort(withLocale).forEach(k => {
sorted[k] = Array.isArray(obj[k]) ? obj[k].sort(withLocale) : obj[k];
});
return sorted;
}