@loaders.gl/kml 3.1.0 → 3.1.1
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/dist/bundle.js +852 -182
- package/dist/es5/gpx-loader.js +1 -1
- package/dist/es5/kml-loader.js +1 -1
- package/dist/es5/tcx-loader.js +1 -1
- package/dist/esm/gpx-loader.js +1 -1
- package/dist/esm/kml-loader.js +1 -1
- package/dist/esm/tcx-loader.js +1 -1
- package/package.json +5 -5
package/dist/bundle.js
CHANGED
|
@@ -29,83 +29,567 @@
|
|
|
29
29
|
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
//
|
|
33
|
-
function
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js
|
|
33
|
+
function getPolygonSignedArea(points, options = {}) {
|
|
34
|
+
const {
|
|
35
|
+
start = 0,
|
|
36
|
+
end = points.length
|
|
37
|
+
} = options;
|
|
38
|
+
const dim = options.size || 2;
|
|
39
|
+
let area2 = 0;
|
|
40
|
+
for (let i = start, j = end - dim; i < end; i += dim) {
|
|
41
|
+
area2 += (points[i] - points[j]) * (points[i + 1] + points[j + 1]);
|
|
42
|
+
j = i;
|
|
43
|
+
}
|
|
44
|
+
return area2 / 2;
|
|
40
45
|
}
|
|
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
|
-
|
|
46
|
+
var init_polygon_utils = __esm({
|
|
47
|
+
"../../node_modules/@math.gl/polygon/dist/esm/polygon-utils.js"() {
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/polygon.js
|
|
52
|
+
var init_polygon = __esm({
|
|
53
|
+
"../../node_modules/@math.gl/polygon/dist/esm/polygon.js"() {
|
|
54
|
+
init_polygon_utils();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/earcut.js
|
|
59
|
+
function earcut(data, holeIndices, dim, areas) {
|
|
60
|
+
dim = dim || 2;
|
|
61
|
+
const hasHoles = holeIndices && holeIndices.length;
|
|
62
|
+
const outerLen = hasHoles ? holeIndices[0] * dim : data.length;
|
|
63
|
+
let outerNode = linkedList(data, 0, outerLen, dim, true, areas && areas[0]);
|
|
64
|
+
const triangles = [];
|
|
65
|
+
if (!outerNode || outerNode.next === outerNode.prev)
|
|
66
|
+
return triangles;
|
|
67
|
+
let invSize;
|
|
68
|
+
let maxX;
|
|
69
|
+
let maxY;
|
|
70
|
+
let minX;
|
|
71
|
+
let minY;
|
|
72
|
+
let x;
|
|
73
|
+
let y;
|
|
74
|
+
if (hasHoles)
|
|
75
|
+
outerNode = eliminateHoles(data, holeIndices, outerNode, dim, areas);
|
|
76
|
+
if (data.length > 80 * dim) {
|
|
77
|
+
minX = maxX = data[0];
|
|
78
|
+
minY = maxY = data[1];
|
|
79
|
+
for (let i = dim; i < outerLen; i += dim) {
|
|
80
|
+
x = data[i];
|
|
81
|
+
y = data[i + 1];
|
|
82
|
+
if (x < minX)
|
|
83
|
+
minX = x;
|
|
84
|
+
if (y < minY)
|
|
85
|
+
minY = y;
|
|
86
|
+
if (x > maxX)
|
|
87
|
+
maxX = x;
|
|
88
|
+
if (y > maxY)
|
|
89
|
+
maxY = y;
|
|
90
|
+
}
|
|
91
|
+
invSize = Math.max(maxX - minX, maxY - minY);
|
|
92
|
+
invSize = invSize !== 0 ? 1 / invSize : 0;
|
|
93
|
+
}
|
|
94
|
+
earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
|
|
95
|
+
return triangles;
|
|
96
|
+
}
|
|
97
|
+
function linkedList(data, start, end, dim, clockwise, area2) {
|
|
98
|
+
let i;
|
|
99
|
+
let last;
|
|
100
|
+
if (area2 === void 0) {
|
|
101
|
+
area2 = getPolygonSignedArea(data, {
|
|
102
|
+
start,
|
|
103
|
+
end,
|
|
104
|
+
size: dim
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (clockwise === area2 < 0) {
|
|
108
|
+
for (i = start; i < end; i += dim)
|
|
109
|
+
last = insertNode(i, data[i], data[i + 1], last);
|
|
110
|
+
} else {
|
|
111
|
+
for (i = end - dim; i >= start; i -= dim)
|
|
112
|
+
last = insertNode(i, data[i], data[i + 1], last);
|
|
113
|
+
}
|
|
114
|
+
if (last && equals(last, last.next)) {
|
|
115
|
+
removeNode(last);
|
|
116
|
+
last = last.next;
|
|
117
|
+
}
|
|
118
|
+
return last;
|
|
119
|
+
}
|
|
120
|
+
function filterPoints(start, end) {
|
|
121
|
+
if (!start)
|
|
122
|
+
return start;
|
|
123
|
+
if (!end)
|
|
124
|
+
end = start;
|
|
125
|
+
let p = start;
|
|
126
|
+
let again;
|
|
127
|
+
do {
|
|
128
|
+
again = false;
|
|
129
|
+
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
|
|
130
|
+
removeNode(p);
|
|
131
|
+
p = end = p.prev;
|
|
132
|
+
if (p === p.next)
|
|
85
133
|
break;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
134
|
+
again = true;
|
|
135
|
+
} else {
|
|
136
|
+
p = p.next;
|
|
137
|
+
}
|
|
138
|
+
} while (again || p !== end);
|
|
139
|
+
return end;
|
|
140
|
+
}
|
|
141
|
+
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
142
|
+
if (!ear)
|
|
143
|
+
return;
|
|
144
|
+
if (!pass && invSize)
|
|
145
|
+
indexCurve(ear, minX, minY, invSize);
|
|
146
|
+
let stop = ear;
|
|
147
|
+
let prev;
|
|
148
|
+
let next;
|
|
149
|
+
while (ear.prev !== ear.next) {
|
|
150
|
+
prev = ear.prev;
|
|
151
|
+
next = ear.next;
|
|
152
|
+
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
|
153
|
+
triangles.push(prev.i / dim);
|
|
154
|
+
triangles.push(ear.i / dim);
|
|
155
|
+
triangles.push(next.i / dim);
|
|
156
|
+
removeNode(ear);
|
|
157
|
+
ear = next.next;
|
|
158
|
+
stop = next.next;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
ear = next;
|
|
162
|
+
if (ear === stop) {
|
|
163
|
+
if (!pass) {
|
|
164
|
+
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
|
|
165
|
+
} else if (pass === 1) {
|
|
166
|
+
ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
|
|
167
|
+
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
|
|
168
|
+
} else if (pass === 2) {
|
|
169
|
+
splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
|
170
|
+
}
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function isEar(ear) {
|
|
176
|
+
const a = ear.prev;
|
|
177
|
+
const b = ear;
|
|
178
|
+
const c = ear.next;
|
|
179
|
+
if (area(a, b, c) >= 0)
|
|
180
|
+
return false;
|
|
181
|
+
let p = ear.next.next;
|
|
182
|
+
while (p !== ear.prev) {
|
|
183
|
+
if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
184
|
+
return false;
|
|
185
|
+
p = p.next;
|
|
186
|
+
}
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
function isEarHashed(ear, minX, minY, invSize) {
|
|
190
|
+
const a = ear.prev;
|
|
191
|
+
const b = ear;
|
|
192
|
+
const c = ear.next;
|
|
193
|
+
if (area(a, b, c) >= 0)
|
|
194
|
+
return false;
|
|
195
|
+
const minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x;
|
|
196
|
+
const minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y;
|
|
197
|
+
const maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x;
|
|
198
|
+
const maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
|
|
199
|
+
const minZ = zOrder(minTX, minTY, minX, minY, invSize);
|
|
200
|
+
const maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
|
|
201
|
+
let p = ear.prevZ;
|
|
202
|
+
let n = ear.nextZ;
|
|
203
|
+
while (p && p.z >= minZ && n && n.z <= maxZ) {
|
|
204
|
+
if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
205
|
+
return false;
|
|
206
|
+
p = p.prevZ;
|
|
207
|
+
if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
208
|
+
return false;
|
|
209
|
+
n = n.nextZ;
|
|
210
|
+
}
|
|
211
|
+
while (p && p.z >= minZ) {
|
|
212
|
+
if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
213
|
+
return false;
|
|
214
|
+
p = p.prevZ;
|
|
215
|
+
}
|
|
216
|
+
while (n && n.z <= maxZ) {
|
|
217
|
+
if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
218
|
+
return false;
|
|
219
|
+
n = n.nextZ;
|
|
220
|
+
}
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
function cureLocalIntersections(start, triangles, dim) {
|
|
224
|
+
let p = start;
|
|
225
|
+
do {
|
|
226
|
+
const a = p.prev;
|
|
227
|
+
const b = p.next.next;
|
|
228
|
+
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
|
229
|
+
triangles.push(a.i / dim);
|
|
230
|
+
triangles.push(p.i / dim);
|
|
231
|
+
triangles.push(b.i / dim);
|
|
232
|
+
removeNode(p);
|
|
233
|
+
removeNode(p.next);
|
|
234
|
+
p = start = b;
|
|
235
|
+
}
|
|
236
|
+
p = p.next;
|
|
237
|
+
} while (p !== start);
|
|
238
|
+
return filterPoints(p);
|
|
239
|
+
}
|
|
240
|
+
function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
|
241
|
+
let a = start;
|
|
242
|
+
do {
|
|
243
|
+
let b = a.next.next;
|
|
244
|
+
while (b !== a.prev) {
|
|
245
|
+
if (a.i !== b.i && isValidDiagonal(a, b)) {
|
|
246
|
+
let c = splitPolygon(a, b);
|
|
247
|
+
a = filterPoints(a, a.next);
|
|
248
|
+
c = filterPoints(c, c.next);
|
|
249
|
+
earcutLinked(a, triangles, dim, minX, minY, invSize);
|
|
250
|
+
earcutLinked(c, triangles, dim, minX, minY, invSize);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
b = b.next;
|
|
254
|
+
}
|
|
255
|
+
a = a.next;
|
|
256
|
+
} while (a !== start);
|
|
257
|
+
}
|
|
258
|
+
function eliminateHoles(data, holeIndices, outerNode, dim, areas) {
|
|
259
|
+
const queue = [];
|
|
260
|
+
let i;
|
|
261
|
+
let len;
|
|
262
|
+
let start;
|
|
263
|
+
let end;
|
|
264
|
+
let list;
|
|
265
|
+
for (i = 0, len = holeIndices.length; i < len; i++) {
|
|
266
|
+
start = holeIndices[i] * dim;
|
|
267
|
+
end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
|
268
|
+
list = linkedList(data, start, end, dim, false, areas && areas[i + 1]);
|
|
269
|
+
if (list === list.next)
|
|
270
|
+
list.steiner = true;
|
|
271
|
+
queue.push(getLeftmost(list));
|
|
272
|
+
}
|
|
273
|
+
queue.sort(compareX);
|
|
274
|
+
for (i = 0; i < queue.length; i++) {
|
|
275
|
+
eliminateHole(queue[i], outerNode);
|
|
276
|
+
outerNode = filterPoints(outerNode, outerNode.next);
|
|
277
|
+
}
|
|
278
|
+
return outerNode;
|
|
279
|
+
}
|
|
280
|
+
function compareX(a, b) {
|
|
281
|
+
return a.x - b.x;
|
|
282
|
+
}
|
|
283
|
+
function eliminateHole(hole, outerNode) {
|
|
284
|
+
outerNode = findHoleBridge(hole, outerNode);
|
|
285
|
+
if (outerNode) {
|
|
286
|
+
const b = splitPolygon(outerNode, hole);
|
|
287
|
+
filterPoints(outerNode, outerNode.next);
|
|
288
|
+
filterPoints(b, b.next);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function findHoleBridge(hole, outerNode) {
|
|
292
|
+
let p = outerNode;
|
|
293
|
+
const hx = hole.x;
|
|
294
|
+
const hy = hole.y;
|
|
295
|
+
let qx = -Infinity;
|
|
296
|
+
let m;
|
|
297
|
+
do {
|
|
298
|
+
if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
|
|
299
|
+
const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
|
|
300
|
+
if (x <= hx && x > qx) {
|
|
301
|
+
qx = x;
|
|
302
|
+
if (x === hx) {
|
|
303
|
+
if (hy === p.y)
|
|
304
|
+
return p;
|
|
305
|
+
if (hy === p.next.y)
|
|
306
|
+
return p.next;
|
|
93
307
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
308
|
+
m = p.x < p.next.x ? p : p.next;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
p = p.next;
|
|
312
|
+
} while (p !== outerNode);
|
|
313
|
+
if (!m)
|
|
314
|
+
return null;
|
|
315
|
+
if (hx === qx)
|
|
316
|
+
return m;
|
|
317
|
+
const stop = m;
|
|
318
|
+
const mx = m.x;
|
|
319
|
+
const my = m.y;
|
|
320
|
+
let tanMin = Infinity;
|
|
321
|
+
let tan;
|
|
322
|
+
p = m;
|
|
323
|
+
do {
|
|
324
|
+
if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
|
|
325
|
+
tan = Math.abs(hy - p.y) / (hx - p.x);
|
|
326
|
+
if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
|
|
327
|
+
m = p;
|
|
328
|
+
tanMin = tan;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
p = p.next;
|
|
332
|
+
} while (p !== stop);
|
|
333
|
+
return m;
|
|
334
|
+
}
|
|
335
|
+
function sectorContainsSector(m, p) {
|
|
336
|
+
return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
|
|
337
|
+
}
|
|
338
|
+
function indexCurve(start, minX, minY, invSize) {
|
|
339
|
+
let p = start;
|
|
340
|
+
do {
|
|
341
|
+
if (p.z === null)
|
|
342
|
+
p.z = zOrder(p.x, p.y, minX, minY, invSize);
|
|
343
|
+
p.prevZ = p.prev;
|
|
344
|
+
p.nextZ = p.next;
|
|
345
|
+
p = p.next;
|
|
346
|
+
} while (p !== start);
|
|
347
|
+
p.prevZ.nextZ = null;
|
|
348
|
+
p.prevZ = null;
|
|
349
|
+
sortLinked(p);
|
|
350
|
+
}
|
|
351
|
+
function sortLinked(list) {
|
|
352
|
+
let e;
|
|
353
|
+
let i;
|
|
354
|
+
let inSize = 1;
|
|
355
|
+
let numMerges;
|
|
356
|
+
let p;
|
|
357
|
+
let pSize;
|
|
358
|
+
let q;
|
|
359
|
+
let qSize;
|
|
360
|
+
let tail;
|
|
361
|
+
do {
|
|
362
|
+
p = list;
|
|
363
|
+
list = null;
|
|
364
|
+
tail = null;
|
|
365
|
+
numMerges = 0;
|
|
366
|
+
while (p) {
|
|
367
|
+
numMerges++;
|
|
368
|
+
q = p;
|
|
369
|
+
pSize = 0;
|
|
370
|
+
for (i = 0; i < inSize; i++) {
|
|
371
|
+
pSize++;
|
|
372
|
+
q = q.nextZ;
|
|
373
|
+
if (!q)
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
qSize = inSize;
|
|
377
|
+
while (pSize > 0 || qSize > 0 && q) {
|
|
378
|
+
if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
|
|
379
|
+
e = p;
|
|
380
|
+
p = p.nextZ;
|
|
381
|
+
pSize--;
|
|
382
|
+
} else {
|
|
383
|
+
e = q;
|
|
384
|
+
q = q.nextZ;
|
|
385
|
+
qSize--;
|
|
104
386
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
387
|
+
if (tail)
|
|
388
|
+
tail.nextZ = e;
|
|
389
|
+
else
|
|
390
|
+
list = e;
|
|
391
|
+
e.prevZ = tail;
|
|
392
|
+
tail = e;
|
|
393
|
+
}
|
|
394
|
+
p = q;
|
|
108
395
|
}
|
|
396
|
+
tail.nextZ = null;
|
|
397
|
+
inSize *= 2;
|
|
398
|
+
} while (numMerges > 1);
|
|
399
|
+
return list;
|
|
400
|
+
}
|
|
401
|
+
function zOrder(x, y, minX, minY, invSize) {
|
|
402
|
+
x = 32767 * (x - minX) * invSize;
|
|
403
|
+
y = 32767 * (y - minY) * invSize;
|
|
404
|
+
x = (x | x << 8) & 16711935;
|
|
405
|
+
x = (x | x << 4) & 252645135;
|
|
406
|
+
x = (x | x << 2) & 858993459;
|
|
407
|
+
x = (x | x << 1) & 1431655765;
|
|
408
|
+
y = (y | y << 8) & 16711935;
|
|
409
|
+
y = (y | y << 4) & 252645135;
|
|
410
|
+
y = (y | y << 2) & 858993459;
|
|
411
|
+
y = (y | y << 1) & 1431655765;
|
|
412
|
+
return x | y << 1;
|
|
413
|
+
}
|
|
414
|
+
function getLeftmost(start) {
|
|
415
|
+
let p = start;
|
|
416
|
+
let leftmost = start;
|
|
417
|
+
do {
|
|
418
|
+
if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
|
|
419
|
+
leftmost = p;
|
|
420
|
+
p = p.next;
|
|
421
|
+
} while (p !== start);
|
|
422
|
+
return leftmost;
|
|
423
|
+
}
|
|
424
|
+
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
|
|
425
|
+
return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
|
|
426
|
+
}
|
|
427
|
+
function isValidDiagonal(a, b) {
|
|
428
|
+
return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
|
|
429
|
+
}
|
|
430
|
+
function area(p, q, r) {
|
|
431
|
+
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
|
432
|
+
}
|
|
433
|
+
function equals(p1, p2) {
|
|
434
|
+
return p1.x === p2.x && p1.y === p2.y;
|
|
435
|
+
}
|
|
436
|
+
function intersects(p1, q1, p2, q2) {
|
|
437
|
+
const o1 = sign(area(p1, q1, p2));
|
|
438
|
+
const o2 = sign(area(p1, q1, q2));
|
|
439
|
+
const o3 = sign(area(p2, q2, p1));
|
|
440
|
+
const o4 = sign(area(p2, q2, q1));
|
|
441
|
+
if (o1 !== o2 && o3 !== o4)
|
|
442
|
+
return true;
|
|
443
|
+
if (o1 === 0 && onSegment(p1, p2, q1))
|
|
444
|
+
return true;
|
|
445
|
+
if (o2 === 0 && onSegment(p1, q2, q1))
|
|
446
|
+
return true;
|
|
447
|
+
if (o3 === 0 && onSegment(p2, p1, q2))
|
|
448
|
+
return true;
|
|
449
|
+
if (o4 === 0 && onSegment(p2, q1, q2))
|
|
450
|
+
return true;
|
|
451
|
+
return false;
|
|
452
|
+
}
|
|
453
|
+
function onSegment(p, q, r) {
|
|
454
|
+
return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
|
|
455
|
+
}
|
|
456
|
+
function sign(num) {
|
|
457
|
+
return num > 0 ? 1 : num < 0 ? -1 : 0;
|
|
458
|
+
}
|
|
459
|
+
function intersectsPolygon(a, b) {
|
|
460
|
+
let p = a;
|
|
461
|
+
do {
|
|
462
|
+
if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b))
|
|
463
|
+
return true;
|
|
464
|
+
p = p.next;
|
|
465
|
+
} while (p !== a);
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
function locallyInside(a, b) {
|
|
469
|
+
return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
|
|
470
|
+
}
|
|
471
|
+
function middleInside(a, b) {
|
|
472
|
+
let p = a;
|
|
473
|
+
let inside = false;
|
|
474
|
+
const px = (a.x + b.x) / 2;
|
|
475
|
+
const py = (a.y + b.y) / 2;
|
|
476
|
+
do {
|
|
477
|
+
if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)
|
|
478
|
+
inside = !inside;
|
|
479
|
+
p = p.next;
|
|
480
|
+
} while (p !== a);
|
|
481
|
+
return inside;
|
|
482
|
+
}
|
|
483
|
+
function splitPolygon(a, b) {
|
|
484
|
+
const a2 = new Node(a.i, a.x, a.y);
|
|
485
|
+
const b2 = new Node(b.i, b.x, b.y);
|
|
486
|
+
const an = a.next;
|
|
487
|
+
const bp = b.prev;
|
|
488
|
+
a.next = b;
|
|
489
|
+
b.prev = a;
|
|
490
|
+
a2.next = an;
|
|
491
|
+
an.prev = a2;
|
|
492
|
+
b2.next = a2;
|
|
493
|
+
a2.prev = b2;
|
|
494
|
+
bp.next = b2;
|
|
495
|
+
b2.prev = bp;
|
|
496
|
+
return b2;
|
|
497
|
+
}
|
|
498
|
+
function insertNode(i, x, y, last) {
|
|
499
|
+
const p = new Node(i, x, y);
|
|
500
|
+
if (!last) {
|
|
501
|
+
p.prev = p;
|
|
502
|
+
p.next = p;
|
|
503
|
+
} else {
|
|
504
|
+
p.next = last.next;
|
|
505
|
+
p.prev = last;
|
|
506
|
+
last.next.prev = p;
|
|
507
|
+
last.next = p;
|
|
508
|
+
}
|
|
509
|
+
return p;
|
|
510
|
+
}
|
|
511
|
+
function removeNode(p) {
|
|
512
|
+
p.next.prev = p.prev;
|
|
513
|
+
p.prev.next = p.next;
|
|
514
|
+
if (p.prevZ)
|
|
515
|
+
p.prevZ.nextZ = p.nextZ;
|
|
516
|
+
if (p.nextZ)
|
|
517
|
+
p.nextZ.prevZ = p.prevZ;
|
|
518
|
+
}
|
|
519
|
+
function Node(i, x, y) {
|
|
520
|
+
this.i = i;
|
|
521
|
+
this.x = x;
|
|
522
|
+
this.y = y;
|
|
523
|
+
this.prev = null;
|
|
524
|
+
this.next = null;
|
|
525
|
+
this.z = null;
|
|
526
|
+
this.prevZ = null;
|
|
527
|
+
this.nextZ = null;
|
|
528
|
+
this.steiner = false;
|
|
529
|
+
}
|
|
530
|
+
var init_earcut = __esm({
|
|
531
|
+
"../../node_modules/@math.gl/polygon/dist/esm/earcut.js"() {
|
|
532
|
+
init_polygon_utils();
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/utils.js
|
|
537
|
+
var init_utils = __esm({
|
|
538
|
+
"../../node_modules/@math.gl/polygon/dist/esm/utils.js"() {
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/lineclip.js
|
|
543
|
+
var init_lineclip = __esm({
|
|
544
|
+
"../../node_modules/@math.gl/polygon/dist/esm/lineclip.js"() {
|
|
545
|
+
init_utils();
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js
|
|
550
|
+
var init_cut_by_grid = __esm({
|
|
551
|
+
"../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js"() {
|
|
552
|
+
init_lineclip();
|
|
553
|
+
init_utils();
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js
|
|
558
|
+
var init_cut_by_mercator_bounds = __esm({
|
|
559
|
+
"../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js"() {
|
|
560
|
+
init_cut_by_grid();
|
|
561
|
+
init_utils();
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
// ../../node_modules/@math.gl/polygon/dist/esm/index.js
|
|
566
|
+
var init_esm = __esm({
|
|
567
|
+
"../../node_modules/@math.gl/polygon/dist/esm/index.js"() {
|
|
568
|
+
init_polygon();
|
|
569
|
+
init_polygon_utils();
|
|
570
|
+
init_earcut();
|
|
571
|
+
init_lineclip();
|
|
572
|
+
init_cut_by_grid();
|
|
573
|
+
init_cut_by_mercator_bounds();
|
|
574
|
+
init_polygon();
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
// ../gis/src/lib/flat-geojson-to-binary.ts
|
|
579
|
+
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
580
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
581
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
582
|
+
return fillArrays(features, {
|
|
583
|
+
propArrayTypes,
|
|
584
|
+
...geometryInfo
|
|
585
|
+
}, {
|
|
586
|
+
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
587
|
+
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
function extractNumericPropTypes(features) {
|
|
591
|
+
const propArrayTypes = {};
|
|
592
|
+
for (const feature of features) {
|
|
109
593
|
if (feature.properties) {
|
|
110
594
|
for (const key in feature.properties) {
|
|
111
595
|
const val = feature.properties[key];
|
|
@@ -113,22 +597,9 @@
|
|
|
113
597
|
}
|
|
114
598
|
}
|
|
115
599
|
}
|
|
116
|
-
return
|
|
117
|
-
coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
|
|
118
|
-
pointPositionsCount,
|
|
119
|
-
pointFeaturesCount,
|
|
120
|
-
linePositionsCount,
|
|
121
|
-
linePathsCount,
|
|
122
|
-
lineFeaturesCount,
|
|
123
|
-
polygonPositionsCount,
|
|
124
|
-
polygonObjectsCount,
|
|
125
|
-
polygonRingsCount,
|
|
126
|
-
polygonFeaturesCount,
|
|
127
|
-
numericPropKeys: Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array),
|
|
128
|
-
propArrayTypes
|
|
129
|
-
};
|
|
600
|
+
return propArrayTypes;
|
|
130
601
|
}
|
|
131
|
-
function
|
|
602
|
+
function fillArrays(features, geometryInfo, options) {
|
|
132
603
|
const {
|
|
133
604
|
pointPositionsCount,
|
|
134
605
|
pointFeaturesCount,
|
|
@@ -138,42 +609,48 @@
|
|
|
138
609
|
polygonPositionsCount,
|
|
139
610
|
polygonObjectsCount,
|
|
140
611
|
polygonRingsCount,
|
|
612
|
+
polygonFeaturesCount,
|
|
141
613
|
propArrayTypes,
|
|
142
|
-
|
|
143
|
-
} =
|
|
144
|
-
const {
|
|
614
|
+
coordLength
|
|
615
|
+
} = geometryInfo;
|
|
616
|
+
const { numericPropKeys = [], PositionDataType = Float32Array } = options;
|
|
617
|
+
const hasGlobalId = features[0] && "id" in features[0];
|
|
145
618
|
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
146
619
|
const points = {
|
|
620
|
+
type: "Point",
|
|
147
621
|
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
148
622
|
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
149
623
|
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
150
624
|
numericProps: {},
|
|
151
|
-
properties:
|
|
152
|
-
fields:
|
|
625
|
+
properties: [],
|
|
626
|
+
fields: []
|
|
153
627
|
};
|
|
154
628
|
const lines = {
|
|
155
|
-
|
|
629
|
+
type: "LineString",
|
|
156
630
|
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
631
|
+
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
157
632
|
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
158
633
|
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
159
634
|
numericProps: {},
|
|
160
|
-
properties:
|
|
161
|
-
fields:
|
|
635
|
+
properties: [],
|
|
636
|
+
fields: []
|
|
162
637
|
};
|
|
163
638
|
const polygons = {
|
|
164
|
-
|
|
639
|
+
type: "Polygon",
|
|
165
640
|
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
166
641
|
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
642
|
+
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
643
|
+
triangles: [],
|
|
167
644
|
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
168
645
|
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
169
646
|
numericProps: {},
|
|
170
|
-
properties:
|
|
171
|
-
fields:
|
|
647
|
+
properties: [],
|
|
648
|
+
fields: []
|
|
172
649
|
};
|
|
173
650
|
for (const object of [points, lines, polygons]) {
|
|
174
|
-
for (const propName of numericPropKeys
|
|
175
|
-
const
|
|
176
|
-
object.numericProps[propName] = new
|
|
651
|
+
for (const propName of numericPropKeys) {
|
|
652
|
+
const T = propArrayTypes[propName];
|
|
653
|
+
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
177
654
|
}
|
|
178
655
|
}
|
|
179
656
|
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
@@ -196,33 +673,27 @@
|
|
|
196
673
|
const properties = feature.properties || {};
|
|
197
674
|
switch (geometry.type) {
|
|
198
675
|
case "Point":
|
|
199
|
-
handlePoint(geometry
|
|
200
|
-
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
201
|
-
indexMap.pointFeature++;
|
|
202
|
-
break;
|
|
203
|
-
case "MultiPoint":
|
|
204
|
-
handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties);
|
|
676
|
+
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
205
677
|
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
678
|
+
if (hasGlobalId) {
|
|
679
|
+
points.fields.push({ id: feature.id });
|
|
680
|
+
}
|
|
206
681
|
indexMap.pointFeature++;
|
|
207
682
|
break;
|
|
208
683
|
case "LineString":
|
|
209
|
-
handleLineString(geometry
|
|
210
|
-
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
211
|
-
indexMap.lineFeature++;
|
|
212
|
-
break;
|
|
213
|
-
case "MultiLineString":
|
|
214
|
-
handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
|
|
684
|
+
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
215
685
|
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
686
|
+
if (hasGlobalId) {
|
|
687
|
+
lines.fields.push({ id: feature.id });
|
|
688
|
+
}
|
|
216
689
|
indexMap.lineFeature++;
|
|
217
690
|
break;
|
|
218
691
|
case "Polygon":
|
|
219
|
-
handlePolygon(geometry
|
|
220
|
-
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
221
|
-
indexMap.polygonFeature++;
|
|
222
|
-
break;
|
|
223
|
-
case "MultiPolygon":
|
|
224
|
-
handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
|
|
692
|
+
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
225
693
|
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
694
|
+
if (hasGlobalId) {
|
|
695
|
+
polygons.fields.push({ id: feature.id });
|
|
696
|
+
}
|
|
226
697
|
indexMap.polygonFeature++;
|
|
227
698
|
break;
|
|
228
699
|
default:
|
|
@@ -232,93 +703,105 @@
|
|
|
232
703
|
}
|
|
233
704
|
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
234
705
|
}
|
|
235
|
-
function handlePoint(
|
|
236
|
-
points.positions.set(
|
|
237
|
-
|
|
238
|
-
points
|
|
239
|
-
|
|
240
|
-
indexMap.pointPosition
|
|
706
|
+
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
707
|
+
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
708
|
+
const nPositions = geometry.data.length / coordLength;
|
|
709
|
+
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
710
|
+
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
711
|
+
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
712
|
+
indexMap.pointPosition += nPositions;
|
|
241
713
|
}
|
|
242
|
-
function
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
function handleLineString(coords, lines, indexMap, coordLength, properties) {
|
|
248
|
-
lines.pathIndices[indexMap.linePath] = indexMap.linePosition;
|
|
249
|
-
indexMap.linePath++;
|
|
250
|
-
fillCoords(lines.positions, coords, indexMap.linePosition, coordLength);
|
|
251
|
-
const nPositions = coords.length;
|
|
714
|
+
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
715
|
+
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
716
|
+
const nPositions = geometry.data.length / coordLength;
|
|
252
717
|
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
253
|
-
lines.globalFeatureIds.
|
|
254
|
-
lines.featureIds.
|
|
255
|
-
|
|
718
|
+
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
719
|
+
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
720
|
+
for (let i = 0, il = geometry.indices.length; i < il; ++i) {
|
|
721
|
+
const start = geometry.indices[i];
|
|
722
|
+
const end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
|
|
723
|
+
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
724
|
+
indexMap.linePosition += (end - start) / coordLength;
|
|
725
|
+
}
|
|
256
726
|
}
|
|
257
|
-
function
|
|
258
|
-
|
|
259
|
-
|
|
727
|
+
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
728
|
+
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
729
|
+
const nPositions = geometry.data.length / coordLength;
|
|
730
|
+
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
731
|
+
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
732
|
+
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
733
|
+
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
734
|
+
const startPosition = indexMap.polygonPosition;
|
|
735
|
+
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
736
|
+
const areas = geometry.areas[l];
|
|
737
|
+
const indices = geometry.indices[l];
|
|
738
|
+
const nextIndices = geometry.indices[l + 1];
|
|
739
|
+
for (let i = 0, il = indices.length; i < il; ++i) {
|
|
740
|
+
const start = indices[i];
|
|
741
|
+
const end = i === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i + 1];
|
|
742
|
+
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
743
|
+
indexMap.polygonPosition += (end - start) / coordLength;
|
|
744
|
+
}
|
|
745
|
+
const endPosition = indexMap.polygonPosition;
|
|
746
|
+
triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
|
|
260
747
|
}
|
|
261
748
|
}
|
|
262
|
-
function
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
749
|
+
function triangulatePolygon(polygons, areas, indices, {
|
|
750
|
+
startPosition,
|
|
751
|
+
endPosition,
|
|
752
|
+
coordLength
|
|
753
|
+
}) {
|
|
754
|
+
const start = startPosition * coordLength;
|
|
755
|
+
const end = endPosition * coordLength;
|
|
756
|
+
const polygonPositions = polygons.positions.subarray(start, end);
|
|
757
|
+
const offset = indices[0];
|
|
758
|
+
const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
|
|
759
|
+
const triangles = earcut(polygonPositions, holes, coordLength, areas);
|
|
760
|
+
for (let t = 0, tl = triangles.length; t < tl; ++t) {
|
|
761
|
+
polygons.triangles.push(startPosition + triangles[t]);
|
|
274
762
|
}
|
|
275
763
|
}
|
|
276
|
-
function
|
|
277
|
-
|
|
278
|
-
|
|
764
|
+
function wrapProps(obj, size) {
|
|
765
|
+
const returnObj = {};
|
|
766
|
+
for (const key in obj) {
|
|
767
|
+
returnObj[key] = { value: obj[key], size };
|
|
279
768
|
}
|
|
769
|
+
return returnObj;
|
|
280
770
|
}
|
|
281
771
|
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
282
|
-
|
|
772
|
+
return {
|
|
283
773
|
points: {
|
|
284
774
|
...points,
|
|
285
775
|
positions: { value: points.positions, size: coordLength },
|
|
286
776
|
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
287
777
|
featureIds: { value: points.featureIds, size: 1 },
|
|
288
|
-
|
|
778
|
+
numericProps: wrapProps(points.numericProps, 1)
|
|
289
779
|
},
|
|
290
780
|
lines: {
|
|
291
781
|
...lines,
|
|
292
|
-
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
293
782
|
positions: { value: lines.positions, size: coordLength },
|
|
783
|
+
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
294
784
|
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
295
785
|
featureIds: { value: lines.featureIds, size: 1 },
|
|
296
|
-
|
|
786
|
+
numericProps: wrapProps(lines.numericProps, 1)
|
|
297
787
|
},
|
|
298
788
|
polygons: {
|
|
299
789
|
...polygons,
|
|
790
|
+
positions: { value: polygons.positions, size: coordLength },
|
|
300
791
|
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
301
792
|
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
302
|
-
|
|
793
|
+
triangles: { value: new Uint32Array(polygons.triangles), size: 1 },
|
|
303
794
|
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
304
795
|
featureIds: { value: polygons.featureIds, size: 1 },
|
|
305
|
-
|
|
796
|
+
numericProps: wrapProps(polygons.numericProps, 1)
|
|
306
797
|
}
|
|
307
798
|
};
|
|
308
|
-
for (const geomType in returnObj) {
|
|
309
|
-
for (const numericProp in returnObj[geomType].numericProps) {
|
|
310
|
-
returnObj[geomType].numericProps[numericProp] = {
|
|
311
|
-
value: returnObj[geomType].numericProps[numericProp],
|
|
312
|
-
size: 1
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
return returnObj;
|
|
317
799
|
}
|
|
318
800
|
function fillNumericProperties(object, properties, index, length) {
|
|
319
801
|
for (const numericPropName in object.numericProps) {
|
|
320
802
|
if (numericPropName in properties) {
|
|
321
|
-
|
|
803
|
+
const value = properties[numericPropName];
|
|
804
|
+
object.numericProps[numericPropName].fill(value, index, index + length);
|
|
322
805
|
}
|
|
323
806
|
}
|
|
324
807
|
}
|
|
@@ -331,24 +814,211 @@
|
|
|
331
814
|
}
|
|
332
815
|
return props;
|
|
333
816
|
}
|
|
334
|
-
function fillCoords(array, coords, startVertex, coordLength) {
|
|
335
|
-
let index = startVertex * coordLength;
|
|
336
|
-
for (const coord of coords) {
|
|
337
|
-
array.set(coord, index);
|
|
338
|
-
index += coordLength;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
function flatten(arrays) {
|
|
342
|
-
return [].concat(...arrays);
|
|
343
|
-
}
|
|
344
817
|
function deduceArrayType(x, constructor) {
|
|
345
818
|
if (constructor === Array || !Number.isFinite(x)) {
|
|
346
819
|
return Array;
|
|
347
820
|
}
|
|
348
821
|
return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
|
|
349
822
|
}
|
|
823
|
+
var init_flat_geojson_to_binary = __esm({
|
|
824
|
+
"../gis/src/lib/flat-geojson-to-binary.ts"() {
|
|
825
|
+
init_esm();
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
// ../gis/src/lib/extract-geometry-info.ts
|
|
830
|
+
function extractGeometryInfo(features) {
|
|
831
|
+
let pointPositionsCount = 0;
|
|
832
|
+
let pointFeaturesCount = 0;
|
|
833
|
+
let linePositionsCount = 0;
|
|
834
|
+
let linePathsCount = 0;
|
|
835
|
+
let lineFeaturesCount = 0;
|
|
836
|
+
let polygonPositionsCount = 0;
|
|
837
|
+
let polygonObjectsCount = 0;
|
|
838
|
+
let polygonRingsCount = 0;
|
|
839
|
+
let polygonFeaturesCount = 0;
|
|
840
|
+
const coordLengths = new Set();
|
|
841
|
+
for (const feature of features) {
|
|
842
|
+
const geometry = feature.geometry;
|
|
843
|
+
switch (geometry.type) {
|
|
844
|
+
case "Point":
|
|
845
|
+
pointFeaturesCount++;
|
|
846
|
+
pointPositionsCount++;
|
|
847
|
+
coordLengths.add(geometry.coordinates.length);
|
|
848
|
+
break;
|
|
849
|
+
case "MultiPoint":
|
|
850
|
+
pointFeaturesCount++;
|
|
851
|
+
pointPositionsCount += geometry.coordinates.length;
|
|
852
|
+
for (const point of geometry.coordinates) {
|
|
853
|
+
coordLengths.add(point.length);
|
|
854
|
+
}
|
|
855
|
+
break;
|
|
856
|
+
case "LineString":
|
|
857
|
+
lineFeaturesCount++;
|
|
858
|
+
linePositionsCount += geometry.coordinates.length;
|
|
859
|
+
linePathsCount++;
|
|
860
|
+
for (const coord of geometry.coordinates) {
|
|
861
|
+
coordLengths.add(coord.length);
|
|
862
|
+
}
|
|
863
|
+
break;
|
|
864
|
+
case "MultiLineString":
|
|
865
|
+
lineFeaturesCount++;
|
|
866
|
+
for (const line of geometry.coordinates) {
|
|
867
|
+
linePositionsCount += line.length;
|
|
868
|
+
linePathsCount++;
|
|
869
|
+
for (const coord of line) {
|
|
870
|
+
coordLengths.add(coord.length);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
break;
|
|
874
|
+
case "Polygon":
|
|
875
|
+
polygonFeaturesCount++;
|
|
876
|
+
polygonObjectsCount++;
|
|
877
|
+
polygonRingsCount += geometry.coordinates.length;
|
|
878
|
+
const flattened = geometry.coordinates.flat();
|
|
879
|
+
polygonPositionsCount += flattened.length;
|
|
880
|
+
for (const coord of flattened) {
|
|
881
|
+
coordLengths.add(coord.length);
|
|
882
|
+
}
|
|
883
|
+
break;
|
|
884
|
+
case "MultiPolygon":
|
|
885
|
+
polygonFeaturesCount++;
|
|
886
|
+
for (const polygon of geometry.coordinates) {
|
|
887
|
+
polygonObjectsCount++;
|
|
888
|
+
polygonRingsCount += polygon.length;
|
|
889
|
+
const flattened2 = polygon.flat();
|
|
890
|
+
polygonPositionsCount += flattened2.length;
|
|
891
|
+
for (const coord of flattened2) {
|
|
892
|
+
coordLengths.add(coord.length);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
break;
|
|
896
|
+
default:
|
|
897
|
+
throw new Error(`Unsupported geometry type: ${geometry.type}`);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
return {
|
|
901
|
+
coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
|
|
902
|
+
pointPositionsCount,
|
|
903
|
+
pointFeaturesCount,
|
|
904
|
+
linePositionsCount,
|
|
905
|
+
linePathsCount,
|
|
906
|
+
lineFeaturesCount,
|
|
907
|
+
polygonPositionsCount,
|
|
908
|
+
polygonObjectsCount,
|
|
909
|
+
polygonRingsCount,
|
|
910
|
+
polygonFeaturesCount
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
var init_extract_geometry_info = __esm({
|
|
914
|
+
"../gis/src/lib/extract-geometry-info.ts"() {
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
// ../gis/src/lib/geojson-to-flat-geojson.ts
|
|
919
|
+
function geojsonToFlatGeojson(features, options = { coordLength: 2, fixRingWinding: true }) {
|
|
920
|
+
return features.map((feature) => flattenFeature(feature, options));
|
|
921
|
+
}
|
|
922
|
+
function flattenPoint(coordinates, data, indices, options) {
|
|
923
|
+
indices.push(data.length);
|
|
924
|
+
data.push(...coordinates);
|
|
925
|
+
for (let i = coordinates.length; i < options.coordLength; i++) {
|
|
926
|
+
data.push(0);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
function flattenLineString(coordinates, data, indices, options) {
|
|
930
|
+
indices.push(data.length);
|
|
931
|
+
for (const c of coordinates) {
|
|
932
|
+
data.push(...c);
|
|
933
|
+
for (let i = c.length; i < options.coordLength; i++) {
|
|
934
|
+
data.push(0);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
function flattenPolygon(coordinates, data, indices, areas, options) {
|
|
939
|
+
let count = 0;
|
|
940
|
+
const ringAreas = [];
|
|
941
|
+
const polygons = [];
|
|
942
|
+
for (const lineString of coordinates) {
|
|
943
|
+
const lineString2d = lineString.map((p) => p.slice(0, 2));
|
|
944
|
+
let area2 = getPolygonSignedArea(lineString2d.flat());
|
|
945
|
+
const ccw = area2 < 0;
|
|
946
|
+
if (options.fixRingWinding && (count === 0 && !ccw || count > 0 && ccw)) {
|
|
947
|
+
lineString.reverse();
|
|
948
|
+
area2 = -area2;
|
|
949
|
+
}
|
|
950
|
+
ringAreas.push(area2);
|
|
951
|
+
flattenLineString(lineString, data, polygons, options);
|
|
952
|
+
count++;
|
|
953
|
+
}
|
|
954
|
+
if (count > 0) {
|
|
955
|
+
areas.push(ringAreas);
|
|
956
|
+
indices.push(polygons);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
function flattenFeature(feature, options) {
|
|
960
|
+
const { geometry } = feature;
|
|
961
|
+
if (geometry.type === "GeometryCollection") {
|
|
962
|
+
throw new Error("GeometryCollection type not supported");
|
|
963
|
+
}
|
|
964
|
+
const data = [];
|
|
965
|
+
const indices = [];
|
|
966
|
+
let areas;
|
|
967
|
+
let type;
|
|
968
|
+
switch (geometry.type) {
|
|
969
|
+
case "Point":
|
|
970
|
+
type = "Point";
|
|
971
|
+
flattenPoint(geometry.coordinates, data, indices, options);
|
|
972
|
+
break;
|
|
973
|
+
case "MultiPoint":
|
|
974
|
+
type = "Point";
|
|
975
|
+
geometry.coordinates.map((c) => flattenPoint(c, data, indices, options));
|
|
976
|
+
break;
|
|
977
|
+
case "LineString":
|
|
978
|
+
type = "LineString";
|
|
979
|
+
flattenLineString(geometry.coordinates, data, indices, options);
|
|
980
|
+
break;
|
|
981
|
+
case "MultiLineString":
|
|
982
|
+
type = "LineString";
|
|
983
|
+
geometry.coordinates.map((c) => flattenLineString(c, data, indices, options));
|
|
984
|
+
break;
|
|
985
|
+
case "Polygon":
|
|
986
|
+
type = "Polygon";
|
|
987
|
+
areas = [];
|
|
988
|
+
flattenPolygon(geometry.coordinates, data, indices, areas, options);
|
|
989
|
+
break;
|
|
990
|
+
case "MultiPolygon":
|
|
991
|
+
type = "Polygon";
|
|
992
|
+
areas = [];
|
|
993
|
+
geometry.coordinates.map((c) => flattenPolygon(c, data, indices, areas, options));
|
|
994
|
+
break;
|
|
995
|
+
default:
|
|
996
|
+
throw new Error(`Unknown type: ${type}`);
|
|
997
|
+
}
|
|
998
|
+
return { ...feature, geometry: { type, indices, data, areas } };
|
|
999
|
+
}
|
|
1000
|
+
var init_geojson_to_flat_geojson = __esm({
|
|
1001
|
+
"../gis/src/lib/geojson-to-flat-geojson.ts"() {
|
|
1002
|
+
init_esm();
|
|
1003
|
+
}
|
|
1004
|
+
});
|
|
1005
|
+
|
|
1006
|
+
// ../gis/src/lib/geojson-to-binary.ts
|
|
1007
|
+
function geojsonToBinary(features, options = { fixRingWinding: true }) {
|
|
1008
|
+
const geometryInfo = extractGeometryInfo(features);
|
|
1009
|
+
const coordLength = geometryInfo.coordLength;
|
|
1010
|
+
const { fixRingWinding } = options;
|
|
1011
|
+
const flatFeatures = geojsonToFlatGeojson(features, { coordLength, fixRingWinding });
|
|
1012
|
+
return flatGeojsonToBinary(flatFeatures, geometryInfo, {
|
|
1013
|
+
numericPropKeys: options.numericPropKeys,
|
|
1014
|
+
PositionDataType: options.PositionDataType || Float32Array
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
350
1017
|
var init_geojson_to_binary = __esm({
|
|
351
1018
|
"../gis/src/lib/geojson-to-binary.ts"() {
|
|
1019
|
+
init_extract_geometry_info();
|
|
1020
|
+
init_geojson_to_flat_geojson();
|
|
1021
|
+
init_flat_geojson_to_binary();
|
|
352
1022
|
}
|
|
353
1023
|
});
|
|
354
1024
|
|
package/dist/es5/gpx-loader.js
CHANGED
|
@@ -15,7 +15,7 @@ var _gis = require("@loaders.gl/gis");
|
|
|
15
15
|
|
|
16
16
|
var _togeojson = require("@tmcw/togeojson");
|
|
17
17
|
|
|
18
|
-
var VERSION = typeof "3.1.
|
|
18
|
+
var VERSION = typeof "3.1.1" !== 'undefined' ? "3.1.1" : 'latest';
|
|
19
19
|
var GPX_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gpx";
|
|
20
20
|
var GPXLoader = {
|
|
21
21
|
name: 'GPX (GPS exchange format)',
|
package/dist/es5/kml-loader.js
CHANGED
|
@@ -15,7 +15,7 @@ var _gis = require("@loaders.gl/gis");
|
|
|
15
15
|
|
|
16
16
|
var _togeojson = require("@tmcw/togeojson");
|
|
17
17
|
|
|
18
|
-
var VERSION = typeof "3.1.
|
|
18
|
+
var VERSION = typeof "3.1.1" !== 'undefined' ? "3.1.1" : 'latest';
|
|
19
19
|
var KML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\">";
|
|
20
20
|
var KMLLoader = {
|
|
21
21
|
name: 'KML (Keyhole Markup Language)',
|
package/dist/es5/tcx-loader.js
CHANGED
|
@@ -15,7 +15,7 @@ var _gis = require("@loaders.gl/gis");
|
|
|
15
15
|
|
|
16
16
|
var _togeojson = require("@tmcw/togeojson");
|
|
17
17
|
|
|
18
|
-
var VERSION = typeof "3.1.
|
|
18
|
+
var VERSION = typeof "3.1.1" !== 'undefined' ? "3.1.1" : 'latest';
|
|
19
19
|
var TCX_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<TrainingCenterDatabase";
|
|
20
20
|
var TCXLoader = {
|
|
21
21
|
name: 'TCX (Training Center XML)',
|
package/dist/esm/gpx-loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { geojsonToBinary } from '@loaders.gl/gis';
|
|
2
2
|
import { gpx } from '@tmcw/togeojson';
|
|
3
|
-
const VERSION = typeof "3.1.
|
|
3
|
+
const VERSION = typeof "3.1.1" !== 'undefined' ? "3.1.1" : 'latest';
|
|
4
4
|
const GPX_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gpx";
|
|
5
5
|
export const GPXLoader = {
|
|
6
6
|
name: 'GPX (GPS exchange format)',
|
package/dist/esm/kml-loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { geojsonToBinary } from '@loaders.gl/gis';
|
|
2
2
|
import { kml } from '@tmcw/togeojson';
|
|
3
|
-
const VERSION = typeof "3.1.
|
|
3
|
+
const VERSION = typeof "3.1.1" !== 'undefined' ? "3.1.1" : 'latest';
|
|
4
4
|
const KML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\">";
|
|
5
5
|
export const KMLLoader = {
|
|
6
6
|
name: 'KML (Keyhole Markup Language)',
|
package/dist/esm/tcx-loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { geojsonToBinary } from '@loaders.gl/gis';
|
|
2
2
|
import { tcx } from '@tmcw/togeojson';
|
|
3
|
-
const VERSION = typeof "3.1.
|
|
3
|
+
const VERSION = typeof "3.1.1" !== 'undefined' ? "3.1.1" : 'latest';
|
|
4
4
|
const TCX_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<TrainingCenterDatabase";
|
|
5
5
|
export const TCXLoader = {
|
|
6
6
|
name: 'TCX (Training Center XML)',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/kml",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Framework-independent loader for the KML format",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@loaders.gl/gis": "3.1.
|
|
36
|
-
"@loaders.gl/loader-utils": "3.1.
|
|
37
|
-
"@loaders.gl/schema": "3.1.
|
|
35
|
+
"@loaders.gl/gis": "3.1.1",
|
|
36
|
+
"@loaders.gl/loader-utils": "3.1.1",
|
|
37
|
+
"@loaders.gl/schema": "3.1.1",
|
|
38
38
|
"@tmcw/togeojson": "^4.5.0"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "ed3c238bcb68ab5a2d4ddc64319f6f4c02a20df7"
|
|
41
41
|
}
|