osm2geojson-lite 0.8.13 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Makefile +1 -1
- package/index.html +7 -3
- package/lib/index.d.ts +21 -0
- package/lib/index.js +51 -59
- package/lib/osmobjs.js +1 -1
- package/lib/xmlparser.js +1 -1
- package/osm2geojson-lite +10 -0
- package/package.json +12 -2
- package/ts/release/index.js +195 -0
- package/ts/release/osmobjs.js +348 -0
- package/ts/release/utils.js +213 -0
- package/ts/release/xmlparser.js +157 -0
- package/ts/src/index.d.ts +17 -0
- package/ts/src/index.ts +217 -169
- package/ts/src/osmobjs.ts +400 -365
- package/ts/src/typings.d.ts +1 -1
- package/ts/src/utils.ts +207 -170
- package/ts/src/xmlparser.ts +173 -132
- package/ts/tsconfig.json +4 -0
- package/ts/tslint.json +24 -0
- package/ts/types/imports.d.ts +1 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function conditioned(evt) {
|
|
4
|
+
return evt.match(/^(.+?)\[(.+?)\]>$/g) !== null;
|
|
5
|
+
}
|
|
6
|
+
function parseEvent(evt) {
|
|
7
|
+
const match = /^(.+?)\[(.+?)\]>$/g.exec(evt);
|
|
8
|
+
if (match) {
|
|
9
|
+
return { evt: match[1] + '>', exp: match[2] };
|
|
10
|
+
}
|
|
11
|
+
return { evt };
|
|
12
|
+
}
|
|
13
|
+
function genConditionFunc(cond) {
|
|
14
|
+
const body = 'return ' + cond.replace(/(\$.+?)(?=[=!.])/g, 'node.$&') + ';';
|
|
15
|
+
return new Function('node', body);
|
|
16
|
+
}
|
|
17
|
+
class default_1 {
|
|
18
|
+
constructor(opts) {
|
|
19
|
+
if (opts) {
|
|
20
|
+
this.queryParent = opts.queryParent ? true : false;
|
|
21
|
+
this.progressive = opts.progressive;
|
|
22
|
+
if (this.queryParent) {
|
|
23
|
+
this.parentMap = new WeakMap();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
this.evtListeners = {};
|
|
27
|
+
}
|
|
28
|
+
parse(xml, parent, dir) {
|
|
29
|
+
dir = dir ? dir + '.' : '';
|
|
30
|
+
const nodeRegEx = /<([^ >\/]+)(.*?)>/mg;
|
|
31
|
+
const nodes = [];
|
|
32
|
+
let nodeMatch = nodeRegEx.exec(xml);
|
|
33
|
+
while (nodeMatch) {
|
|
34
|
+
const tag = nodeMatch[1];
|
|
35
|
+
const node = { $tag: tag };
|
|
36
|
+
const fullTag = dir + tag;
|
|
37
|
+
const attrText = nodeMatch[2].trim();
|
|
38
|
+
let closed = false;
|
|
39
|
+
if (attrText.endsWith('/') || tag.startsWith('?') || tag.startsWith('!')) {
|
|
40
|
+
closed = true;
|
|
41
|
+
}
|
|
42
|
+
const attRegEx1 = /([^ ]+?)="(.+?)"/g;
|
|
43
|
+
const attRegEx2 = /([^ ]+?)='(.+?)'/g;
|
|
44
|
+
let attMatch = attRegEx1.exec(attrText);
|
|
45
|
+
let hasAttrs = false;
|
|
46
|
+
while (attMatch) {
|
|
47
|
+
hasAttrs = true;
|
|
48
|
+
node[attMatch[1]] = attMatch[2];
|
|
49
|
+
attMatch = attRegEx1.exec(attrText);
|
|
50
|
+
}
|
|
51
|
+
if (!hasAttrs) {
|
|
52
|
+
attMatch = attRegEx2.exec(attrText);
|
|
53
|
+
while (attMatch) {
|
|
54
|
+
hasAttrs = true;
|
|
55
|
+
node[attMatch[1]] = attMatch[2];
|
|
56
|
+
attMatch = attRegEx2.exec(attrText);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!hasAttrs && attrText !== '') {
|
|
60
|
+
node.text = attrText;
|
|
61
|
+
}
|
|
62
|
+
if (this.progressive) {
|
|
63
|
+
this.emit(`<${fullTag}>`, node, parent);
|
|
64
|
+
}
|
|
65
|
+
if (!closed) {
|
|
66
|
+
const innerRegEx = new RegExp(`([^]+?)<\/${tag}>`, 'g');
|
|
67
|
+
innerRegEx.lastIndex = nodeRegEx.lastIndex;
|
|
68
|
+
const innerMatch = innerRegEx.exec(xml);
|
|
69
|
+
if (innerMatch && innerMatch[1]) {
|
|
70
|
+
nodeRegEx.lastIndex = innerRegEx.lastIndex;
|
|
71
|
+
const innerNodes = this.parse(innerMatch[1], node, fullTag);
|
|
72
|
+
if (innerNodes.length > 0) {
|
|
73
|
+
node.$innerNodes = innerNodes;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
node.$innerText = innerMatch[1];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (this.queryParent && parent) {
|
|
81
|
+
this.parentMap.set(node, parent);
|
|
82
|
+
}
|
|
83
|
+
if (this.progressive) {
|
|
84
|
+
this.emit(`</${fullTag}>`, node, parent);
|
|
85
|
+
}
|
|
86
|
+
nodes.push(node);
|
|
87
|
+
nodeMatch = nodeRegEx.exec(xml);
|
|
88
|
+
}
|
|
89
|
+
return nodes;
|
|
90
|
+
}
|
|
91
|
+
getParent(node) {
|
|
92
|
+
if (this.queryParent) {
|
|
93
|
+
return this.parentMap.get(node);
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
// support javascript condition for the last tag
|
|
98
|
+
addListener(evt, func) {
|
|
99
|
+
if (conditioned(evt)) {
|
|
100
|
+
// func.prototype = evt;
|
|
101
|
+
const ev = parseEvent(evt);
|
|
102
|
+
if (ev.exp) {
|
|
103
|
+
func.condition = genConditionFunc(ev.exp);
|
|
104
|
+
}
|
|
105
|
+
evt = ev.evt;
|
|
106
|
+
}
|
|
107
|
+
this.$addListener(evt, func);
|
|
108
|
+
}
|
|
109
|
+
removeListener(evt, func) {
|
|
110
|
+
if (conditioned(evt)) {
|
|
111
|
+
const ev = parseEvent(evt);
|
|
112
|
+
evt = ev.evt;
|
|
113
|
+
}
|
|
114
|
+
this.$removeListener(evt, func);
|
|
115
|
+
}
|
|
116
|
+
on(evt, func) {
|
|
117
|
+
this.addListener(evt, func);
|
|
118
|
+
}
|
|
119
|
+
off(evt, func) {
|
|
120
|
+
this.removeListener(evt, func);
|
|
121
|
+
}
|
|
122
|
+
$addListener(evt, func) {
|
|
123
|
+
const funcs = this.evtListeners[evt];
|
|
124
|
+
if (funcs) {
|
|
125
|
+
funcs.push(func);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
this.evtListeners[evt] = [func];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
$removeListener(evt, func) {
|
|
132
|
+
const funcs = this.evtListeners[evt];
|
|
133
|
+
let idx = -1;
|
|
134
|
+
if (funcs) {
|
|
135
|
+
idx = funcs.indexOf(func);
|
|
136
|
+
}
|
|
137
|
+
if (idx >= 0) {
|
|
138
|
+
funcs.splice(idx, 1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
emit(evt, ...args) {
|
|
142
|
+
const funcs = this.evtListeners[evt];
|
|
143
|
+
if (funcs) {
|
|
144
|
+
for (const func of funcs) {
|
|
145
|
+
if (func.condition) {
|
|
146
|
+
if (func.condition.apply(null, args) === true) {
|
|
147
|
+
func.apply(null, args);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
func.apply(null, args);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {FeatureCollection, GeometryObject} from 'geojson';
|
|
2
|
+
|
|
3
|
+
export = osm2geojson;
|
|
4
|
+
|
|
5
|
+
declare let osm2geojson: osm2geojson.IDefault;
|
|
6
|
+
|
|
7
|
+
declare namespace osm2geojson {
|
|
8
|
+
interface IOptions {
|
|
9
|
+
completeFeature?: boolean;
|
|
10
|
+
allFeatures?: boolean;
|
|
11
|
+
renderTagged?: boolean;
|
|
12
|
+
excludeWay?: boolean;
|
|
13
|
+
suppressWay?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type IDefault = (osm: string | {[k: string]: any}, opts?: IOptions) => FeatureCollection<GeometryObject>;
|
|
17
|
+
}
|
package/ts/src/index.ts
CHANGED
|
@@ -1,172 +1,220 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {FeatureCollection, GeometryObject} from 'geojson';
|
|
2
|
+
import {Node, Relation, Way} from './osmobjs';
|
|
2
3
|
import {purgeProps, RefElements} from './utils';
|
|
3
4
|
import XmlParser from './xmlparser';
|
|
4
5
|
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
6
|
+
interface IOptions {
|
|
7
|
+
completeFeature?: boolean;
|
|
8
|
+
allFeatures?: boolean;
|
|
9
|
+
renderTagged?: boolean;
|
|
10
|
+
excludeWay?: boolean;
|
|
11
|
+
suppressWay?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default (osm: string | {[k: string]: any}, opts?: IOptions): FeatureCollection<GeometryObject> => {
|
|
15
|
+
let completeFeature = false;
|
|
16
|
+
let renderTagged = false;
|
|
17
|
+
let excludeWay = true;
|
|
18
|
+
|
|
19
|
+
const parseOpts = (os: IOptions) => {
|
|
20
|
+
if (os) {
|
|
21
|
+
completeFeature = os.completeFeature || os.allFeatures ? true : false;
|
|
22
|
+
renderTagged = os.renderTagged ? true : false;
|
|
23
|
+
const wayOpt = os.suppressWay || os.excludeWay;
|
|
24
|
+
if (wayOpt !== undefined && !wayOpt) {
|
|
25
|
+
excludeWay = false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
if (opts) {
|
|
31
|
+
parseOpts(opts);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const detectFormat = (o: string | {[k: string]: any}): string => {
|
|
35
|
+
if ((o as {[k: string]: any}).elements) {
|
|
36
|
+
return 'json';
|
|
37
|
+
}
|
|
38
|
+
if (o.indexOf('<osm') >= 0) {
|
|
39
|
+
return 'xml';
|
|
40
|
+
}
|
|
41
|
+
if (o.trim().startsWith('{')) {
|
|
42
|
+
return 'json-raw';
|
|
43
|
+
}
|
|
44
|
+
return 'invalid';
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
let format = detectFormat(osm);
|
|
48
|
+
|
|
49
|
+
const refElements = new RefElements();
|
|
50
|
+
let featureArray: any[] = [];
|
|
51
|
+
|
|
52
|
+
const analyzeFeaturesFromJson = (o: string | {[k: string]: any}) => {
|
|
53
|
+
for (const elem of (osm as {[k: string]: any}).elements) {
|
|
54
|
+
switch (elem.type) {
|
|
55
|
+
case 'node':
|
|
56
|
+
const node = new Node(elem.id, refElements);
|
|
57
|
+
if (elem.tags) {
|
|
58
|
+
node.addTags(elem.tags);
|
|
59
|
+
}
|
|
60
|
+
node.addProps(purgeProps(elem as {[k: string]: string}, ['id', 'type', 'tags', 'lat', 'lon']));
|
|
61
|
+
node.setLatLng(elem);
|
|
62
|
+
break;
|
|
63
|
+
|
|
64
|
+
case 'way':
|
|
65
|
+
const way = new Way(elem.id, refElements);
|
|
66
|
+
if (elem.tags) {
|
|
67
|
+
way.addTags(elem.tags);
|
|
68
|
+
}
|
|
69
|
+
way.addProps(purgeProps(elem as {[k: string]: string}, ['id', 'type', 'tags', 'nodes', 'geometry']));
|
|
70
|
+
if (elem.nodes) {
|
|
71
|
+
for (const n of elem.nodes) {
|
|
72
|
+
way.addNodeRef(n);
|
|
73
|
+
}
|
|
74
|
+
} else if (elem.geometry) {
|
|
75
|
+
way.setLatLngArray(elem.geometry);
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
|
|
79
|
+
case 'relation':
|
|
80
|
+
const relation = new Relation(elem.id, refElements);
|
|
81
|
+
if (elem.bounds) {
|
|
82
|
+
relation.setBounds([parseFloat(elem.bounds.minlon), parseFloat(elem.bounds.minlat), parseFloat(elem.bounds.maxlon), parseFloat(elem.bounds.maxlat)]);
|
|
83
|
+
}
|
|
84
|
+
if (elem.tags) {
|
|
85
|
+
relation.addTags(elem.tags);
|
|
86
|
+
}
|
|
87
|
+
relation.addProps(purgeProps(elem as {[k: string]: string}, ['id', 'type', 'tags', 'bounds', 'members']));
|
|
88
|
+
if (elem.members) {
|
|
89
|
+
for (const member of elem.members) {
|
|
90
|
+
relation.addMember(member);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
default:
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const analyzeFeaturesFromXml = (o: string | {[k: string]: any}) => {
|
|
100
|
+
const xmlParser = new XmlParser({progressive: true});
|
|
101
|
+
|
|
102
|
+
xmlParser.on('</osm.node>', (node: {[k: string]: any}) => {
|
|
103
|
+
const nd = new Node(node.id, refElements);
|
|
104
|
+
for (const [k, v] of Object.entries(node)) {
|
|
105
|
+
if (!k.startsWith('$') && ['id', 'lon', 'lat'].indexOf(k) < 0) {
|
|
106
|
+
nd.addProp(k, v);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
nd.setLatLng(node as {lat: string, lon: string});
|
|
110
|
+
if (node.$innerNodes) {
|
|
111
|
+
for (const ind of node.$innerNodes) {
|
|
112
|
+
if (ind.$tag === 'tag') {
|
|
113
|
+
nd.addTag(ind.k, ind.v);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
xmlParser.on('</osm.way>', (node: {[k: string]: any}) => {
|
|
120
|
+
const way = new Way(node.id, refElements);
|
|
121
|
+
for (const [k, v] of Object.entries(node)) {
|
|
122
|
+
if (!k.startsWith('$') && ['id'].indexOf(k) < 0) {
|
|
123
|
+
way.addProp(k, v);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (node.$innerNodes) {
|
|
127
|
+
for (const ind of node.$innerNodes) {
|
|
128
|
+
if (ind.$tag === 'nd') {
|
|
129
|
+
if (ind.lon && ind.lat) {
|
|
130
|
+
way.addLatLng(ind);
|
|
131
|
+
} else if (ind.ref) {
|
|
132
|
+
way.addNodeRef(ind.ref);
|
|
133
|
+
}
|
|
134
|
+
} else if (ind.$tag === 'tag') {
|
|
135
|
+
way.addTag(ind.k, ind.v);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
xmlParser.on('<osm.relation>', (node: {[k: string]: any}) => new Relation(node.id, refElements));
|
|
142
|
+
|
|
143
|
+
xmlParser.on('</osm.relation.member>', (node: {[k: string]: any}, parent: {[k: string]: any}) => {
|
|
144
|
+
const relation = refElements.get(`relation/${parent.id}`);
|
|
145
|
+
const member: {[k: string]: any} = {
|
|
146
|
+
type: node.type,
|
|
147
|
+
role: node.role ? node.role : '',
|
|
148
|
+
ref: node.ref,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
if (node.lat && node.lon) {
|
|
152
|
+
member.lat = node.lat, member.lon = node.lon, member.tags = {};
|
|
153
|
+
for (const [k, v] of Object.entries(node)) {
|
|
154
|
+
if (!k.startsWith('$') && ['type', 'lat', 'lon'].indexOf(k) < 0) {
|
|
155
|
+
member[k] = v;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (node.$innerNodes) {
|
|
161
|
+
const geometry: any[] = [];
|
|
162
|
+
const nodes: any[] = [];
|
|
163
|
+
for (const ind of node.$innerNodes) {
|
|
164
|
+
if (ind.lat && ind.lon) {
|
|
165
|
+
geometry.push(ind);
|
|
166
|
+
} else if (ind.ref) {
|
|
167
|
+
nodes.push(ind.ref);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (geometry.length > 0) {
|
|
171
|
+
member.geometry = geometry;
|
|
172
|
+
} else if (nodes.length > 0) {
|
|
173
|
+
member.nodes = nodes;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
relation.addMember(member);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
xmlParser.on('</osm.relation.bounds>', (node: {[k: string]: any}, parent: {[k: string]: any}) => {
|
|
180
|
+
refElements.get(`relation/${parent.id}`).setBounds([parseFloat(node.minlon), parseFloat(node.minlat), parseFloat(node.maxlon), parseFloat(node.maxlat)]);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
xmlParser.on('</osm.relation.tag>', (node: {[k: string]: any}, parent: {[k: string]: any}) => {
|
|
184
|
+
refElements.get(`relation/${parent.id}`).addTag(node.k, node.v);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
xmlParser.parse(o as string);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
if (format === 'json-raw') {
|
|
191
|
+
osm = JSON.parse(osm as string) as {[k: string]: any};
|
|
192
|
+
if ((osm as {[k: string]: any}).elements) {
|
|
193
|
+
format = 'json';
|
|
194
|
+
} else {
|
|
195
|
+
format = 'invalid';
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (format === 'json') {
|
|
200
|
+
analyzeFeaturesFromJson(osm);
|
|
201
|
+
} else if (format === 'xml') {
|
|
202
|
+
analyzeFeaturesFromXml(osm);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
refElements.bindAll();
|
|
206
|
+
|
|
207
|
+
for (const v of refElements.values()) {
|
|
208
|
+
if (v.refCount <= 0 || (v.hasTag && renderTagged && !(v instanceof Way && excludeWay))) {
|
|
209
|
+
const features = v.toFeatureArray();
|
|
210
|
+
// return the first geometry of the first relation element
|
|
211
|
+
if (v instanceof Relation && !completeFeature && features.length > 0) {
|
|
212
|
+
return features[0].geometry;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
featureArray = featureArray.concat(features);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return {type: 'FeatureCollection', features: featureArray};
|
|
220
|
+
};
|