osm2geojson-lite 1.2.0 → 2.1.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/README.md +37 -15
- package/dist/cli.mjs +1504 -0
- package/dist/index.cjs +1469 -0
- package/dist/index.d.ts +226 -0
- package/dist/index.mjs +1469 -0
- package/dist/polytags.json +63 -0
- package/package.json +53 -56
- package/dist/node/index.d.ts +0 -25
- package/dist/node/index.js +0 -196
- package/dist/node/late-binder.d.ts +0 -8
- package/dist/node/late-binder.js +0 -24
- package/dist/node/node.d.ts +0 -14
- package/dist/node/node.js +0 -31
- package/dist/node/osm-object.d.ts +0 -25
- package/dist/node/osm-object.js +0 -38
- package/dist/node/polytags.json +0 -84
- package/dist/node/ref-elements.d.ts +0 -9
- package/dist/node/ref-elements.js +0 -19
- package/dist/node/relation.d.ts +0 -21
- package/dist/node/relation.js +0 -220
- package/dist/node/utils.d.ts +0 -22
- package/dist/node/utils.js +0 -97
- package/dist/node/way-collection.d.ts +0 -14
- package/dist/node/way-collection.js +0 -109
- package/dist/node/way.d.ts +0 -21
- package/dist/node/way.js +0 -87
- package/dist/node/xmlparser.d.ts +0 -32
- package/dist/node/xmlparser.js +0 -161
- package/dist/web/osm2geojson-lite.js +0 -1
package/dist/node/relation.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { OsmObject } from "./osm-object";
|
|
2
|
-
import { Way } from "./way";
|
|
3
|
-
import { LateBinder } from "./late-binder";
|
|
4
|
-
import type { RefElements } from "./ref-elements";
|
|
5
|
-
import type { Feature } from "geojson";
|
|
6
|
-
export declare class Relation extends OsmObject {
|
|
7
|
-
private relations;
|
|
8
|
-
private nodes;
|
|
9
|
-
private bounds;
|
|
10
|
-
ways: (LateBinder<Way> | Way)[];
|
|
11
|
-
roles: string[];
|
|
12
|
-
constructor(id: string, refElems: RefElements);
|
|
13
|
-
setBounds(bounds: any[]): void;
|
|
14
|
-
addMember(member: {
|
|
15
|
-
[k: string]: any;
|
|
16
|
-
}): void;
|
|
17
|
-
private constructStringGeometry;
|
|
18
|
-
private constructPolygonGeometry;
|
|
19
|
-
private collectAllWaysForRelation;
|
|
20
|
-
toFeatureArray(): Array<Feature<any, any>>;
|
|
21
|
-
}
|
package/dist/node/relation.js
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Relation = void 0;
|
|
4
|
-
const osm_object_1 = require("./osm-object");
|
|
5
|
-
const way_1 = require("./way");
|
|
6
|
-
const node_1 = require("./node");
|
|
7
|
-
const way_collection_1 = require("./way-collection");
|
|
8
|
-
const late_binder_1 = require("./late-binder");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
class Relation extends osm_object_1.OsmObject {
|
|
11
|
-
constructor(id, refElems) {
|
|
12
|
-
super('relation', id, refElems);
|
|
13
|
-
this.relations = [];
|
|
14
|
-
this.nodes = [];
|
|
15
|
-
this.bounds = undefined;
|
|
16
|
-
this.ways = [];
|
|
17
|
-
this.roles = [];
|
|
18
|
-
}
|
|
19
|
-
setBounds(bounds) {
|
|
20
|
-
this.bounds = bounds;
|
|
21
|
-
}
|
|
22
|
-
addMember(member) {
|
|
23
|
-
switch (member.type) {
|
|
24
|
-
// super relation, need to do combination
|
|
25
|
-
case 'relation':
|
|
26
|
-
let binder = new late_binder_1.LateBinder(this.relations, (id) => {
|
|
27
|
-
const relation = this.refElems.get(`relation/${id}`);
|
|
28
|
-
if (relation) {
|
|
29
|
-
relation.refCount++;
|
|
30
|
-
return relation;
|
|
31
|
-
}
|
|
32
|
-
}, this, [member.ref]);
|
|
33
|
-
this.relations.push(binder);
|
|
34
|
-
this.refElems.addBinder(binder);
|
|
35
|
-
break;
|
|
36
|
-
case 'way':
|
|
37
|
-
if (!member.role) {
|
|
38
|
-
member.role = '';
|
|
39
|
-
}
|
|
40
|
-
if (member.geometry) {
|
|
41
|
-
const way = new way_1.Way(member.ref, this.refElems);
|
|
42
|
-
way.setLatLngArray(member.geometry);
|
|
43
|
-
way.refCount++;
|
|
44
|
-
this.ways.push(way);
|
|
45
|
-
this.roles.push(member.role);
|
|
46
|
-
}
|
|
47
|
-
else if (member.nodes) {
|
|
48
|
-
const way = new way_1.Way(member.ref, this.refElems);
|
|
49
|
-
for (const nid of member.nodes) {
|
|
50
|
-
way.addNodeRef(nid);
|
|
51
|
-
}
|
|
52
|
-
way.refCount++;
|
|
53
|
-
this.ways.push(way);
|
|
54
|
-
this.roles.push(member.role);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
let binder = new late_binder_1.LateBinder(this.ways, (nid) => {
|
|
58
|
-
const way = this.refElems.get(`way/${nid}`);
|
|
59
|
-
if (way) {
|
|
60
|
-
way.refCount++;
|
|
61
|
-
return way;
|
|
62
|
-
}
|
|
63
|
-
}, this, [member.ref]);
|
|
64
|
-
this.ways.push(binder);
|
|
65
|
-
this.roles.push(member.role);
|
|
66
|
-
this.refElems.addBinder(binder);
|
|
67
|
-
}
|
|
68
|
-
break;
|
|
69
|
-
case 'node':
|
|
70
|
-
let node = null;
|
|
71
|
-
if (member.lat && member.lon) {
|
|
72
|
-
node = new node_1.Node(member.ref, this.refElems);
|
|
73
|
-
node.setLatLng({ lon: member.lon, lat: member.lat });
|
|
74
|
-
if (member.tags) {
|
|
75
|
-
node.addTags(member.tags);
|
|
76
|
-
}
|
|
77
|
-
for (const [k, v] of Object.entries(member)) {
|
|
78
|
-
if (['id', 'type', 'lat', 'lon'].indexOf(k) < 0) {
|
|
79
|
-
node.addProp(k, v);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
node.refCount++;
|
|
83
|
-
this.nodes.push(node);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
let binder = new late_binder_1.LateBinder(this.nodes, (id) => {
|
|
87
|
-
const nn = this.refElems.get(`node/${id}`);
|
|
88
|
-
if (nn) {
|
|
89
|
-
nn.refCount++;
|
|
90
|
-
return nn;
|
|
91
|
-
}
|
|
92
|
-
}, this, [member.ref]);
|
|
93
|
-
this.nodes.push(binder);
|
|
94
|
-
this.refElems.addBinder(binder);
|
|
95
|
-
}
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
constructStringGeometry(ws) {
|
|
100
|
-
const strings = ws ? ws.mergeWays() : [];
|
|
101
|
-
if (strings.length === 0) {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
type: 'MultiLineString',
|
|
106
|
-
coordinates: strings,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
constructPolygonGeometry(ows, iws) {
|
|
110
|
-
const outerRings = ows ? ows.toRings('counterclockwise') : [];
|
|
111
|
-
const innerRings = iws ? iws.toRings('clockwise') : [];
|
|
112
|
-
if (outerRings.length > 0) {
|
|
113
|
-
const compositPolyons = [];
|
|
114
|
-
let ring;
|
|
115
|
-
for (ring of outerRings) {
|
|
116
|
-
compositPolyons.push([ring]);
|
|
117
|
-
}
|
|
118
|
-
// link inner polygons to outer containers
|
|
119
|
-
ring = innerRings.shift();
|
|
120
|
-
while (ring) {
|
|
121
|
-
for (const idx in outerRings) {
|
|
122
|
-
if ((0, utils_1.pointInsidePolygon)((0, utils_1.first)(ring), outerRings[idx])) {
|
|
123
|
-
compositPolyons[idx].push(ring);
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
ring = innerRings.shift();
|
|
128
|
-
}
|
|
129
|
-
// construct the Polygon/MultiPolygon geometry
|
|
130
|
-
if (compositPolyons.length === 1) {
|
|
131
|
-
return {
|
|
132
|
-
type: 'Polygon',
|
|
133
|
-
coordinates: compositPolyons[0],
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
return {
|
|
137
|
-
type: 'MultiPolygon',
|
|
138
|
-
coordinates: compositPolyons,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
collectAllWaysForRelation(relation, relationToWaysMap) {
|
|
144
|
-
const ways = [...relation.ways];
|
|
145
|
-
const roles = [...relation.roles];
|
|
146
|
-
if (relation.relations.length === 0) {
|
|
147
|
-
relationToWaysMap.set(relation.id, { ways, roles });
|
|
148
|
-
return { ways, roles };
|
|
149
|
-
}
|
|
150
|
-
for (const subRelation of relation.relations) {
|
|
151
|
-
if (!subRelation) {
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
if (!relationToWaysMap.has(subRelation.id)) {
|
|
155
|
-
this.collectAllWaysForRelation(subRelation, relationToWaysMap);
|
|
156
|
-
}
|
|
157
|
-
const entry = relationToWaysMap.get(subRelation.id);
|
|
158
|
-
for (let i = 0; i < entry.ways.length; i++) {
|
|
159
|
-
ways.push(entry.ways[i]);
|
|
160
|
-
roles.push(entry.roles[i]);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
relationToWaysMap.set(relation.id, { ways, roles });
|
|
164
|
-
return { ways, roles };
|
|
165
|
-
}
|
|
166
|
-
toFeatureArray() {
|
|
167
|
-
const polygonFeatures = [];
|
|
168
|
-
const stringFeatures = [];
|
|
169
|
-
let pointFeatures = [];
|
|
170
|
-
const relationToWaysMap = new Map();
|
|
171
|
-
const waysAndRoles = this.collectAllWaysForRelation(this, relationToWaysMap);
|
|
172
|
-
let templateFeature = {
|
|
173
|
-
type: 'Feature',
|
|
174
|
-
id: this.getCompositeId(),
|
|
175
|
-
bbox: this.bounds,
|
|
176
|
-
properties: this.getProps(),
|
|
177
|
-
geometry: null
|
|
178
|
-
};
|
|
179
|
-
if (!this.bounds) {
|
|
180
|
-
delete templateFeature.bbox;
|
|
181
|
-
}
|
|
182
|
-
if (this.roles.some((r) => r === 'outer')) {
|
|
183
|
-
const outerWayCollection = new way_collection_1.WayCollection();
|
|
184
|
-
const innerWayCollection = new way_collection_1.WayCollection();
|
|
185
|
-
for (let i = 0; i < waysAndRoles.ways.length; i++) {
|
|
186
|
-
const way = waysAndRoles.ways[i];
|
|
187
|
-
const role = waysAndRoles.roles[i];
|
|
188
|
-
if (role === 'outer') {
|
|
189
|
-
outerWayCollection.addWay(way);
|
|
190
|
-
}
|
|
191
|
-
else if (role === 'inner') {
|
|
192
|
-
innerWayCollection.addWay(way);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
let feature = Object.assign({}, templateFeature);
|
|
196
|
-
let geometry = this.constructPolygonGeometry(outerWayCollection, innerWayCollection);
|
|
197
|
-
if (geometry) {
|
|
198
|
-
feature.geometry = geometry;
|
|
199
|
-
polygonFeatures.push(feature);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
const wayCollection = new way_collection_1.WayCollection();
|
|
204
|
-
for (let way of waysAndRoles.ways) {
|
|
205
|
-
wayCollection.addWay(way);
|
|
206
|
-
}
|
|
207
|
-
let geometry = this.constructStringGeometry(wayCollection);
|
|
208
|
-
if (geometry) {
|
|
209
|
-
let feature = Object.assign({}, templateFeature);
|
|
210
|
-
feature.geometry = geometry;
|
|
211
|
-
stringFeatures.push(feature);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
for (let node of this.nodes) {
|
|
215
|
-
pointFeatures = pointFeatures.concat(node.toFeatureArray());
|
|
216
|
-
}
|
|
217
|
-
return [...polygonFeatures, ...stringFeatures, ...pointFeatures];
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
exports.Relation = Relation;
|
package/dist/node/utils.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export declare function purgeProps(obj: {
|
|
2
|
-
[k: string]: any;
|
|
3
|
-
}, blacklist: string[]): {
|
|
4
|
-
[k: string]: any;
|
|
5
|
-
};
|
|
6
|
-
export declare function first<T>(a: T[]): T;
|
|
7
|
-
export declare function last<T>(a: T[]): T;
|
|
8
|
-
export declare function coordsToKey<T>(a: T[]): string;
|
|
9
|
-
export declare function addToMap<T>(m: {
|
|
10
|
-
[k: string]: T[];
|
|
11
|
-
}, k: string, v: T): void;
|
|
12
|
-
export declare function removeFromMap<T>(m: {
|
|
13
|
-
[k: string]: T[];
|
|
14
|
-
}, k: string, v: T): void;
|
|
15
|
-
export declare function getFirstFromMap<T>(m: {
|
|
16
|
-
[k: string]: T[];
|
|
17
|
-
}, k: string): T | null;
|
|
18
|
-
export declare function isRing(a: number[][]): boolean;
|
|
19
|
-
export declare function ringDirection(a: number[][], xIdx?: number, yIdx?: number): string;
|
|
20
|
-
export declare function pointInsidePolygon(pt: number[], polygon: number[][], xIdx?: number, yIdx?: number): boolean;
|
|
21
|
-
export declare function strArrayArrayToFloat(el: string[][]): number[][];
|
|
22
|
-
export declare function strArrayToFloat(el: string[]): number[];
|
package/dist/node/utils.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.purgeProps = purgeProps;
|
|
4
|
-
exports.first = first;
|
|
5
|
-
exports.last = last;
|
|
6
|
-
exports.coordsToKey = coordsToKey;
|
|
7
|
-
exports.addToMap = addToMap;
|
|
8
|
-
exports.removeFromMap = removeFromMap;
|
|
9
|
-
exports.getFirstFromMap = getFirstFromMap;
|
|
10
|
-
exports.isRing = isRing;
|
|
11
|
-
exports.ringDirection = ringDirection;
|
|
12
|
-
exports.pointInsidePolygon = pointInsidePolygon;
|
|
13
|
-
exports.strArrayArrayToFloat = strArrayArrayToFloat;
|
|
14
|
-
exports.strArrayToFloat = strArrayToFloat;
|
|
15
|
-
function purgeProps(obj, blacklist) {
|
|
16
|
-
if (obj) {
|
|
17
|
-
const rs = Object.assign({}, obj);
|
|
18
|
-
if (blacklist) {
|
|
19
|
-
for (const prop of blacklist) {
|
|
20
|
-
delete rs[prop];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return rs;
|
|
24
|
-
}
|
|
25
|
-
return {};
|
|
26
|
-
}
|
|
27
|
-
function first(a) { return a[0]; }
|
|
28
|
-
function last(a) { return a[a.length - 1]; }
|
|
29
|
-
function coordsToKey(a) { return a.join(','); }
|
|
30
|
-
function addToMap(m, k, v) {
|
|
31
|
-
const a = m[k];
|
|
32
|
-
if (a) {
|
|
33
|
-
a.push(v);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
m[k] = [v];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function removeFromMap(m, k, v) {
|
|
40
|
-
const a = m[k];
|
|
41
|
-
let idx = -1;
|
|
42
|
-
if (a) {
|
|
43
|
-
idx = a.indexOf(v);
|
|
44
|
-
}
|
|
45
|
-
if (idx >= 0) {
|
|
46
|
-
a.splice(idx, 1);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function getFirstFromMap(m, k) {
|
|
50
|
-
const a = m[k];
|
|
51
|
-
if (a && a.length > 0) {
|
|
52
|
-
return a[0];
|
|
53
|
-
}
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
// need 3+ different points to form a ring, here using > 3 is 'coz a the first and the last points are actually the same
|
|
57
|
-
function isRing(a) {
|
|
58
|
-
return a.length > 3 && coordsToKey(first(a)) === coordsToKey(last(a));
|
|
59
|
-
}
|
|
60
|
-
function ringDirection(a, xIdx, yIdx) {
|
|
61
|
-
xIdx = xIdx || 0, yIdx = yIdx || 1;
|
|
62
|
-
// get the index of the point which has the maximum x value
|
|
63
|
-
const m = a.reduce((maxxIdx, v, idx) => a[maxxIdx][xIdx || 0] > v[xIdx || 0] ? maxxIdx : idx, 0);
|
|
64
|
-
// 'coz the first point is virtually the same one as the last point,
|
|
65
|
-
// we need to skip a.length - 1 for left when m = 0,
|
|
66
|
-
// and skip 0 for right when m = a.length - 1;
|
|
67
|
-
const l = m <= 0 ? a.length - 2 : m - 1;
|
|
68
|
-
const r = m >= a.length - 1 ? 1 : m + 1;
|
|
69
|
-
const xa = a[l][xIdx];
|
|
70
|
-
const xb = a[m][xIdx];
|
|
71
|
-
const xc = a[r][xIdx];
|
|
72
|
-
const ya = a[l][yIdx];
|
|
73
|
-
const yb = a[m][yIdx];
|
|
74
|
-
const yc = a[r][yIdx];
|
|
75
|
-
const det = (xb - xa) * (yc - ya) - (xc - xa) * (yb - ya);
|
|
76
|
-
return det < 0 ? 'clockwise' : 'counterclockwise';
|
|
77
|
-
}
|
|
78
|
-
;
|
|
79
|
-
function pointInsidePolygon(pt, polygon, xIdx, yIdx) {
|
|
80
|
-
xIdx = xIdx || 0, yIdx = yIdx || 1;
|
|
81
|
-
let result = false;
|
|
82
|
-
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
83
|
-
if ((polygon[i][xIdx] <= pt[xIdx] && pt[xIdx] < polygon[j][xIdx] ||
|
|
84
|
-
polygon[j][xIdx] <= pt[xIdx] && pt[xIdx] < polygon[i][xIdx]) &&
|
|
85
|
-
pt[yIdx] < (polygon[j][yIdx] - polygon[i][yIdx]) * (pt[xIdx] - polygon[i][xIdx]) / (polygon[j][xIdx] - polygon[i][xIdx]) + polygon[i][yIdx]) {
|
|
86
|
-
result = !result;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
;
|
|
92
|
-
function strArrayArrayToFloat(el) {
|
|
93
|
-
return el.map(strArrayToFloat);
|
|
94
|
-
}
|
|
95
|
-
function strArrayToFloat(el) {
|
|
96
|
-
return el.map(parseFloat);
|
|
97
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Way } from "./way";
|
|
2
|
-
export declare class WayCollection extends Array {
|
|
3
|
-
private firstMap;
|
|
4
|
-
private lastMap;
|
|
5
|
-
constructor();
|
|
6
|
-
addWay(way: Way): void;
|
|
7
|
-
mergeWays(): number[][][];
|
|
8
|
-
/**
|
|
9
|
-
* Try to find the next way to add to the current way.
|
|
10
|
-
* It first tries the next way in the array, and if this doesn't work, try any other way.
|
|
11
|
-
*/
|
|
12
|
-
private getNextWay;
|
|
13
|
-
toRings(direction: string): number[][][];
|
|
14
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WayCollection = void 0;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
|
-
class WayCollection extends Array {
|
|
6
|
-
constructor() {
|
|
7
|
-
super();
|
|
8
|
-
this.firstMap = {};
|
|
9
|
-
this.lastMap = {};
|
|
10
|
-
}
|
|
11
|
-
addWay(way) {
|
|
12
|
-
const w = way.toCoordsArray();
|
|
13
|
-
if (w.length > 0) {
|
|
14
|
-
this.push(w);
|
|
15
|
-
(0, utils_1.addToMap)(this.firstMap, (0, utils_1.coordsToKey)((0, utils_1.first)(w)), w);
|
|
16
|
-
(0, utils_1.addToMap)(this.lastMap, (0, utils_1.coordsToKey)((0, utils_1.last)(w)), w);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
mergeWays() {
|
|
20
|
-
const strings = [];
|
|
21
|
-
let way = this.shift();
|
|
22
|
-
while (way) {
|
|
23
|
-
(0, utils_1.removeFromMap)(this.firstMap, (0, utils_1.coordsToKey)((0, utils_1.first)(way)), way);
|
|
24
|
-
(0, utils_1.removeFromMap)(this.lastMap, (0, utils_1.coordsToKey)((0, utils_1.last)(way)), way);
|
|
25
|
-
let current = way;
|
|
26
|
-
let next;
|
|
27
|
-
do {
|
|
28
|
-
let nextWay = this.getNextWay(current);
|
|
29
|
-
next = nextWay.next;
|
|
30
|
-
let mergeType = nextWay.mergeType;
|
|
31
|
-
if (!next) {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
this.splice(this.indexOf(next), 1);
|
|
35
|
-
(0, utils_1.removeFromMap)(this.firstMap, (0, utils_1.coordsToKey)((0, utils_1.first)(next)), next);
|
|
36
|
-
(0, utils_1.removeFromMap)(this.lastMap, (0, utils_1.coordsToKey)((0, utils_1.last)(next)), next);
|
|
37
|
-
switch (mergeType) {
|
|
38
|
-
case 0 /* MergeType.EndStart */:
|
|
39
|
-
current = current.concat(next.slice(1));
|
|
40
|
-
break;
|
|
41
|
-
case 1 /* MergeType.EndEnd */:
|
|
42
|
-
next.reverse();
|
|
43
|
-
current = current.concat(next.slice(1));
|
|
44
|
-
break;
|
|
45
|
-
case 2 /* MergeType.StartStart */:
|
|
46
|
-
current.reverse();
|
|
47
|
-
current = current.concat(next.slice(1));
|
|
48
|
-
break;
|
|
49
|
-
case 3 /* MergeType.StartEnd */:
|
|
50
|
-
current = next.concat(current.slice(1));
|
|
51
|
-
current.reverse();
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
} while (next);
|
|
55
|
-
strings.push((0, utils_1.strArrayArrayToFloat)(current));
|
|
56
|
-
way = this.shift();
|
|
57
|
-
}
|
|
58
|
-
return strings;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Try to find the next way to add to the current way.
|
|
62
|
-
* It first tries the next way in the array, and if this doesn't work, try any other way.
|
|
63
|
-
*/
|
|
64
|
-
getNextWay(current) {
|
|
65
|
-
const lastKey = (0, utils_1.coordsToKey)((0, utils_1.last)(current));
|
|
66
|
-
const firstKey = (0, utils_1.coordsToKey)((0, utils_1.first)(current));
|
|
67
|
-
// Step 1: Prefer the next way in the array if it connects
|
|
68
|
-
let next = this.length > 0 ? this[0] : null;
|
|
69
|
-
if (next) {
|
|
70
|
-
const nextFirstKey = (0, utils_1.coordsToKey)((0, utils_1.first)(next));
|
|
71
|
-
const nextLastKey = (0, utils_1.coordsToKey)((0, utils_1.last)(next));
|
|
72
|
-
if (lastKey === nextFirstKey) {
|
|
73
|
-
return { next, mergeType: 0 /* MergeType.EndStart */ };
|
|
74
|
-
}
|
|
75
|
-
if (lastKey === nextLastKey) {
|
|
76
|
-
return { next, mergeType: 1 /* MergeType.EndEnd */ };
|
|
77
|
-
}
|
|
78
|
-
if (firstKey === nextFirstKey) {
|
|
79
|
-
return { next, mergeType: 2 /* MergeType.StartStart */ };
|
|
80
|
-
}
|
|
81
|
-
if (firstKey === nextLastKey) {
|
|
82
|
-
return { next, mergeType: 3 /* MergeType.StartEnd */ };
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Step 2: Fallback to map-based lookup if no sequential match
|
|
86
|
-
next = (0, utils_1.getFirstFromMap)(this.firstMap, lastKey);
|
|
87
|
-
if (next) {
|
|
88
|
-
return { next, mergeType: 0 /* MergeType.EndStart */ };
|
|
89
|
-
}
|
|
90
|
-
next = (0, utils_1.getFirstFromMap)(this.lastMap, lastKey);
|
|
91
|
-
return { next, mergeType: 1 /* MergeType.EndEnd */ };
|
|
92
|
-
}
|
|
93
|
-
toRings(direction) {
|
|
94
|
-
const strings = this.mergeWays();
|
|
95
|
-
const rings = [];
|
|
96
|
-
let str = strings.shift();
|
|
97
|
-
while (str) {
|
|
98
|
-
if ((0, utils_1.isRing)(str)) {
|
|
99
|
-
if ((0, utils_1.ringDirection)(str) !== direction) {
|
|
100
|
-
str.reverse();
|
|
101
|
-
}
|
|
102
|
-
rings.push(str);
|
|
103
|
-
}
|
|
104
|
-
str = strings.shift();
|
|
105
|
-
}
|
|
106
|
-
return rings;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
exports.WayCollection = WayCollection;
|
package/dist/node/way.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Feature } from "geojson";
|
|
2
|
-
import { OsmObject } from "./osm-object";
|
|
3
|
-
import { LatLon } from "./node";
|
|
4
|
-
import type { RefElements } from "./ref-elements";
|
|
5
|
-
export declare class Way extends OsmObject {
|
|
6
|
-
private latLngArray;
|
|
7
|
-
private isPolygon;
|
|
8
|
-
constructor(id: string, refElems: RefElements);
|
|
9
|
-
addLatLng(latLng: LatLon): void;
|
|
10
|
-
setLatLngArray(latLngArray: Array<LatLon & {
|
|
11
|
-
[k: string]: any;
|
|
12
|
-
}>): void;
|
|
13
|
-
addNodeRef(ref: string): void;
|
|
14
|
-
addTags(tags: {
|
|
15
|
-
[k: string]: string;
|
|
16
|
-
}): void;
|
|
17
|
-
addTag(k: string, v: string): void;
|
|
18
|
-
toCoordsArray(): string[][];
|
|
19
|
-
toFeatureArray(): Array<Feature<any, any>>;
|
|
20
|
-
private analyzeTag;
|
|
21
|
-
}
|
package/dist/node/way.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Way = void 0;
|
|
7
|
-
const osm_object_1 = require("./osm-object");
|
|
8
|
-
const late_binder_1 = require("./late-binder");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
const polytags_json_1 = __importDefault(require("./polytags.json"));
|
|
11
|
-
class Way extends osm_object_1.OsmObject {
|
|
12
|
-
constructor(id, refElems) {
|
|
13
|
-
super('way', id, refElems);
|
|
14
|
-
this.latLngArray = [];
|
|
15
|
-
this.isPolygon = false;
|
|
16
|
-
}
|
|
17
|
-
addLatLng(latLng) {
|
|
18
|
-
this.latLngArray.push(latLng);
|
|
19
|
-
}
|
|
20
|
-
setLatLngArray(latLngArray) {
|
|
21
|
-
this.latLngArray = latLngArray;
|
|
22
|
-
}
|
|
23
|
-
addNodeRef(ref) {
|
|
24
|
-
const binder = new late_binder_1.LateBinder(this.latLngArray, (id) => {
|
|
25
|
-
const node = this.refElems.get(`node/${id}`);
|
|
26
|
-
if (node) {
|
|
27
|
-
node.refCount++;
|
|
28
|
-
return node.getLatLng();
|
|
29
|
-
}
|
|
30
|
-
}, this, [ref]);
|
|
31
|
-
this.latLngArray.push(binder);
|
|
32
|
-
this.refElems.addBinder(binder);
|
|
33
|
-
}
|
|
34
|
-
addTags(tags) {
|
|
35
|
-
super.addTags(tags);
|
|
36
|
-
for (const [k, v] of Object.entries(tags)) {
|
|
37
|
-
this.analyzeTag(k, v);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
addTag(k, v) {
|
|
41
|
-
super.addTag(k, v);
|
|
42
|
-
this.analyzeTag(k, v);
|
|
43
|
-
}
|
|
44
|
-
toCoordsArray() {
|
|
45
|
-
return this.latLngArray.map((latLng) => [latLng.lon, latLng.lat]);
|
|
46
|
-
}
|
|
47
|
-
toFeatureArray() {
|
|
48
|
-
let coordsArrayString = this.toCoordsArray();
|
|
49
|
-
if (coordsArrayString.length > 1) {
|
|
50
|
-
const coordsArray = (0, utils_1.strArrayArrayToFloat)(coordsArrayString);
|
|
51
|
-
const feature = {
|
|
52
|
-
type: 'Feature',
|
|
53
|
-
id: this.getCompositeId(),
|
|
54
|
-
properties: this.getProps(),
|
|
55
|
-
geometry: {
|
|
56
|
-
type: 'LineString',
|
|
57
|
-
coordinates: coordsArray,
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
if (this.isPolygon && (0, utils_1.isRing)(coordsArray)) {
|
|
61
|
-
if ((0, utils_1.ringDirection)(coordsArray) !== 'counterclockwise') {
|
|
62
|
-
coordsArray.reverse();
|
|
63
|
-
}
|
|
64
|
-
feature.geometry = {
|
|
65
|
-
type: 'Polygon',
|
|
66
|
-
coordinates: [coordsArray],
|
|
67
|
-
};
|
|
68
|
-
return [feature];
|
|
69
|
-
}
|
|
70
|
-
return [feature];
|
|
71
|
-
}
|
|
72
|
-
return [];
|
|
73
|
-
}
|
|
74
|
-
analyzeTag(k, v) {
|
|
75
|
-
const o = polytags_json_1.default[k];
|
|
76
|
-
if (o) {
|
|
77
|
-
this.isPolygon = true;
|
|
78
|
-
if (o.whitelist) {
|
|
79
|
-
this.isPolygon = o.whitelist.indexOf(v) >= 0 ? true : false;
|
|
80
|
-
}
|
|
81
|
-
else if (o.blacklist) {
|
|
82
|
-
this.isPolygon = o.blacklist.indexOf(v) >= 0 ? false : true;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.Way = Way;
|
package/dist/node/xmlparser.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export declare class XmlParser {
|
|
2
|
-
private queryParent;
|
|
3
|
-
private progressive;
|
|
4
|
-
private parentMap;
|
|
5
|
-
private evtListeners;
|
|
6
|
-
constructor(opts: any);
|
|
7
|
-
parse(xml: string, parent?: any, dir?: string): any[];
|
|
8
|
-
getParent(node: any): any;
|
|
9
|
-
addListener(evt: string, func: (node: {
|
|
10
|
-
[k: string]: any;
|
|
11
|
-
}, parent?: {
|
|
12
|
-
[k: string]: any;
|
|
13
|
-
}) => void): void;
|
|
14
|
-
removeListener(evt: string, func: (node: {
|
|
15
|
-
[k: string]: any;
|
|
16
|
-
}, parent?: {
|
|
17
|
-
[k: string]: any;
|
|
18
|
-
}) => void): void;
|
|
19
|
-
on(evt: string, func: (node: {
|
|
20
|
-
[k: string]: any;
|
|
21
|
-
}, parent?: {
|
|
22
|
-
[k: string]: any;
|
|
23
|
-
}) => void): void;
|
|
24
|
-
off(evt: string, func: (node: {
|
|
25
|
-
[k: string]: any;
|
|
26
|
-
}, parent?: {
|
|
27
|
-
[k: string]: any;
|
|
28
|
-
}) => void): void;
|
|
29
|
-
private $addListener;
|
|
30
|
-
private $removeListener;
|
|
31
|
-
private emit;
|
|
32
|
-
}
|