@loaders.gl/mvt 4.0.0-beta.2 → 4.0.0-beta.3
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/{dist.min.js → dist.dev.js} +2353 -1734
- package/dist/helpers/binary-util-functions.js.map +1 -0
- package/dist/helpers/mapbox-util-functions.js.map +1 -0
- package/dist/index.cjs +1800 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/{esm/lib → lib}/binary-vector-tile/vector-tile-feature.js +12 -13
- package/dist/lib/binary-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/{esm/lib → lib}/binary-vector-tile/vector-tile-layer.js +9 -10
- package/dist/lib/binary-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/{esm/lib/mapbox-vector-tile → lib/binary-vector-tile}/vector-tile.js +2 -3
- package/dist/lib/binary-vector-tile/vector-tile.js.map +1 -0
- package/dist/{esm/lib → lib}/geojson-tiler/clip.js +4 -5
- package/dist/lib/geojson-tiler/clip.js.map +1 -0
- package/dist/{esm/lib → lib}/geojson-tiler/convert.js +2 -2
- package/dist/lib/geojson-tiler/convert.js.map +1 -0
- package/dist/lib/geojson-tiler/feature.js.map +1 -0
- package/dist/{esm/lib → lib}/geojson-tiler/geojson-tiler.js +11 -12
- package/dist/lib/geojson-tiler/geojson-tiler.js.map +1 -0
- package/dist/lib/geojson-tiler/simplify.js.map +1 -0
- package/dist/lib/geojson-tiler/tile.js.map +1 -0
- package/dist/lib/geojson-tiler/transform.js.map +1 -0
- package/dist/{esm/lib → lib}/geojson-tiler/wrap.js +5 -6
- package/dist/lib/geojson-tiler/wrap.js.map +1 -0
- package/dist/{esm/lib → lib}/mapbox-vector-tile/vector-tile-feature.js +12 -13
- package/dist/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -0
- package/dist/{esm/lib → lib}/mapbox-vector-tile/vector-tile-layer.js +9 -10
- package/dist/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -0
- package/dist/{esm/lib/binary-vector-tile → lib/mapbox-vector-tile}/vector-tile.js +2 -3
- package/dist/lib/mapbox-vector-tile/vector-tile.js.map +1 -0
- package/dist/{esm/lib → lib}/parse-mvt.js +2 -2
- package/dist/lib/parse-mvt.js.map +1 -0
- package/dist/lib/parse-tilejson.js.map +1 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/{esm/mvt-loader.js → mvt-loader.js} +2 -2
- package/dist/mvt-loader.js.map +1 -0
- package/dist/mvt-source.d.ts +28 -0
- package/dist/mvt-source.d.ts.map +1 -0
- package/dist/mvt-source.js +100 -0
- package/dist/mvt-source.js.map +1 -0
- package/dist/mvt-worker.js +267 -103
- package/dist/{esm/tilejson-loader.js → tilejson-loader.js} +2 -2
- package/dist/tilejson-loader.js.map +1 -0
- package/dist/{esm/workers → workers}/mvt-worker.js +1 -1
- package/dist/workers/mvt-worker.js.map +1 -0
- package/package.json +19 -10
- package/src/index.ts +2 -0
- package/src/mvt-source.ts +110 -0
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/es5/bundle.js +0 -6
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/helpers/binary-util-functions.js +0 -82
- package/dist/es5/helpers/binary-util-functions.js.map +0 -1
- package/dist/es5/helpers/mapbox-util-functions.js +0 -50
- package/dist/es5/helpers/mapbox-util-functions.js.map +0 -1
- package/dist/es5/index.js +0 -33
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +0 -168
- package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +0 -62
- package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/es5/lib/binary-vector-tile/vector-tile.js +0 -28
- package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/clip.js +0 -237
- package/dist/es5/lib/geojson-tiler/clip.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/convert.js +0 -161
- package/dist/es5/lib/geojson-tiler/convert.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/feature.js +0 -62
- package/dist/es5/lib/geojson-tiler/feature.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js +0 -186
- package/dist/es5/lib/geojson-tiler/geojson-tiler.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/simplify.js +0 -52
- package/dist/es5/lib/geojson-tiler/simplify.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/tile.js +0 -121
- package/dist/es5/lib/geojson-tiler/tile.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/transform.js +0 -50
- package/dist/es5/lib/geojson-tiler/transform.js.map +0 -1
- package/dist/es5/lib/geojson-tiler/wrap.js +0 -122
- package/dist/es5/lib/geojson-tiler/wrap.js.map +0 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +0 -184
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +0 -62
- package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +0 -28
- package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
- package/dist/es5/lib/parse-mvt.js +0 -144
- package/dist/es5/lib/parse-mvt.js.map +0 -1
- package/dist/es5/lib/parse-tilejson.js +0 -186
- package/dist/es5/lib/parse-tilejson.js.map +0 -1
- package/dist/es5/lib/types.js +0 -2
- package/dist/es5/lib/types.js.map +0 -1
- package/dist/es5/mvt-loader.js +0 -57
- package/dist/es5/mvt-loader.js.map +0 -1
- package/dist/es5/tilejson-loader.js +0 -50
- package/dist/es5/tilejson-loader.js.map +0 -1
- package/dist/es5/workers/mvt-worker.js +0 -6
- package/dist/es5/workers/mvt-worker.js.map +0 -1
- package/dist/esm/bundle.js +0 -4
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/helpers/binary-util-functions.js.map +0 -1
- package/dist/esm/helpers/mapbox-util-functions.js.map +0 -1
- package/dist/esm/index.js +0 -4
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/LICENSE.txt +0 -31
- package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/esm/lib/binary-vector-tile/vector-tile.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/LICENSE +0 -19
- package/dist/esm/lib/geojson-tiler/clip.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/convert.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/feature.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/geojson-tiler.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/simplify.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/tile.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/transform.js.map +0 -1
- package/dist/esm/lib/geojson-tiler/wrap.js.map +0 -1
- package/dist/esm/lib/mapbox-vector-tile/LICENSE.txt +0 -31
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-feature.js.map +0 -1
- package/dist/esm/lib/mapbox-vector-tile/vector-tile-layer.js.map +0 -1
- package/dist/esm/lib/mapbox-vector-tile/vector-tile.js.map +0 -1
- package/dist/esm/lib/parse-mvt.js.map +0 -1
- package/dist/esm/lib/parse-tilejson.js.map +0 -1
- package/dist/esm/lib/types.js.map +0 -1
- package/dist/esm/mvt-loader.js.map +0 -1
- package/dist/esm/tilejson-loader.js.map +0 -1
- package/dist/esm/workers/mvt-worker.js.map +0 -1
- package/src/bundle.ts +0 -4
- /package/dist/{esm/helpers → helpers}/binary-util-functions.js +0 -0
- /package/dist/{esm/helpers → helpers}/mapbox-util-functions.js +0 -0
- /package/dist/{es5/lib → lib}/binary-vector-tile/LICENSE.txt +0 -0
- /package/dist/{es5/lib → lib}/geojson-tiler/LICENSE +0 -0
- /package/dist/{esm/lib → lib}/geojson-tiler/feature.js +0 -0
- /package/dist/{esm/lib → lib}/geojson-tiler/simplify.js +0 -0
- /package/dist/{esm/lib → lib}/geojson-tiler/tile.js +0 -0
- /package/dist/{esm/lib → lib}/geojson-tiler/transform.js +0 -0
- /package/dist/{es5/lib → lib}/mapbox-vector-tile/LICENSE.txt +0 -0
- /package/dist/{esm/lib → lib}/parse-tilejson.js +0 -0
- /package/dist/{esm/lib → lib}/types.js +0 -0
|
@@ -1,969 +1,136 @@
|
|
|
1
|
-
(()
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
+
else if (typeof exports === 'object') exports['loader'] = factory();
|
|
6
|
+
else root['loader'] = factory();})(globalThis, function () {
|
|
7
|
+
"use strict";
|
|
8
|
+
var __exports__ = (() => {
|
|
2
9
|
var __create = Object.create;
|
|
3
10
|
var __defProp = Object.defineProperty;
|
|
4
11
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
12
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
13
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
14
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
9
|
-
var __esm = (fn, res) => function __init() {
|
|
10
|
-
return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
|
|
11
|
-
};
|
|
12
15
|
var __commonJS = (cb, mod) => function __require() {
|
|
13
|
-
return mod || (0, cb[
|
|
16
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
14
17
|
};
|
|
15
18
|
var __export = (target, all) => {
|
|
16
|
-
__markAsModule(target);
|
|
17
19
|
for (var name in all)
|
|
18
20
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
21
|
};
|
|
20
|
-
var
|
|
21
|
-
if (
|
|
22
|
-
for (let key of __getOwnPropNames(
|
|
23
|
-
if (!__hasOwnProp.call(
|
|
24
|
-
__defProp(
|
|
22
|
+
var __copyProps = (to, from, except, desc) => {
|
|
23
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
24
|
+
for (let key of __getOwnPropNames(from))
|
|
25
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
26
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
27
|
}
|
|
26
|
-
return
|
|
27
|
-
};
|
|
28
|
-
var __toModule = (module) => {
|
|
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);
|
|
28
|
+
return to;
|
|
30
29
|
};
|
|
30
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
31
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
32
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
33
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
34
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
35
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
36
|
+
mod
|
|
37
|
+
));
|
|
38
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
39
|
|
|
32
|
-
// ../../node_modules
|
|
33
|
-
var
|
|
34
|
-
"../../node_modules
|
|
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
|
-
|
|
40
|
+
// ../../node_modules/ieee754/index.js
|
|
41
|
+
var require_ieee754 = __commonJS({
|
|
42
|
+
"../../node_modules/ieee754/index.js"(exports) {
|
|
43
|
+
exports.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
44
|
+
var e, m;
|
|
45
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
46
|
+
var eMax = (1 << eLen) - 1;
|
|
47
|
+
var eBias = eMax >> 1;
|
|
48
|
+
var nBits = -7;
|
|
49
|
+
var i2 = isLE ? nBytes - 1 : 0;
|
|
50
|
+
var d = isLE ? -1 : 1;
|
|
51
|
+
var s = buffer[offset + i2];
|
|
52
|
+
i2 += d;
|
|
53
|
+
e = s & (1 << -nBits) - 1;
|
|
54
|
+
s >>= -nBits;
|
|
55
|
+
nBits += eLen;
|
|
56
|
+
for (; nBits > 0; e = e * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
|
|
57
|
+
}
|
|
58
|
+
m = e & (1 << -nBits) - 1;
|
|
59
|
+
e >>= -nBits;
|
|
60
|
+
nBits += mLen;
|
|
61
|
+
for (; nBits > 0; m = m * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
|
|
62
|
+
}
|
|
63
|
+
if (e === 0) {
|
|
64
|
+
e = 1 - eBias;
|
|
65
|
+
} else if (e === eMax) {
|
|
66
|
+
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
67
|
+
} else {
|
|
68
|
+
m = m + Math.pow(2, mLen);
|
|
69
|
+
e = e - eBias;
|
|
70
|
+
}
|
|
71
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
72
|
+
};
|
|
73
|
+
exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
74
|
+
var e, m, c;
|
|
75
|
+
var eLen = nBytes * 8 - mLen - 1;
|
|
76
|
+
var eMax = (1 << eLen) - 1;
|
|
77
|
+
var eBias = eMax >> 1;
|
|
78
|
+
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
79
|
+
var i2 = isLE ? 0 : nBytes - 1;
|
|
80
|
+
var d = isLE ? 1 : -1;
|
|
81
|
+
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
82
|
+
value = Math.abs(value);
|
|
83
|
+
if (isNaN(value) || value === Infinity) {
|
|
84
|
+
m = isNaN(value) ? 1 : 0;
|
|
85
|
+
e = eMax;
|
|
86
|
+
} else {
|
|
87
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
88
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
89
|
+
e--;
|
|
90
|
+
c *= 2;
|
|
91
|
+
}
|
|
92
|
+
if (e + eBias >= 1) {
|
|
93
|
+
value += rt / c;
|
|
94
|
+
} else {
|
|
95
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
96
|
+
}
|
|
97
|
+
if (value * c >= 2) {
|
|
98
|
+
e++;
|
|
99
|
+
c /= 2;
|
|
100
|
+
}
|
|
101
|
+
if (e + eBias >= eMax) {
|
|
102
|
+
m = 0;
|
|
103
|
+
e = eMax;
|
|
104
|
+
} else if (e + eBias >= 1) {
|
|
105
|
+
m = (value * c - 1) * Math.pow(2, mLen);
|
|
106
|
+
e = e + eBias;
|
|
107
|
+
} else {
|
|
108
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
109
|
+
e = 0;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
for (; mLen >= 8; buffer[offset + i2] = m & 255, i2 += d, m /= 256, mLen -= 8) {
|
|
113
|
+
}
|
|
114
|
+
e = e << mLen | m;
|
|
115
|
+
eLen += mLen;
|
|
116
|
+
for (; eLen > 0; buffer[offset + i2] = e & 255, i2 += d, e /= 256, eLen -= 8) {
|
|
117
|
+
}
|
|
118
|
+
buffer[offset + i2 - d] |= s * 128;
|
|
119
|
+
};
|
|
84
120
|
}
|
|
85
121
|
});
|
|
86
122
|
|
|
87
|
-
// ../../node_modules
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
let minX;
|
|
99
|
-
let minY;
|
|
100
|
-
let x2;
|
|
101
|
-
let y2;
|
|
102
|
-
if (hasHoles)
|
|
103
|
-
outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas);
|
|
104
|
-
if (positions.length > 80 * dim) {
|
|
105
|
-
minX = maxX = positions[0];
|
|
106
|
-
minY = maxY = positions[1];
|
|
107
|
-
for (let i2 = dim; i2 < outerLen; i2 += dim) {
|
|
108
|
-
x2 = positions[i2];
|
|
109
|
-
y2 = positions[i2 + 1];
|
|
110
|
-
if (x2 < minX)
|
|
111
|
-
minX = x2;
|
|
112
|
-
if (y2 < minY)
|
|
113
|
-
minY = y2;
|
|
114
|
-
if (x2 > maxX)
|
|
115
|
-
maxX = x2;
|
|
116
|
-
if (y2 > maxY)
|
|
117
|
-
maxY = y2;
|
|
118
|
-
}
|
|
119
|
-
invSize = Math.max(maxX - minX, maxY - minY);
|
|
120
|
-
invSize = invSize !== 0 ? 1 / invSize : 0;
|
|
121
|
-
}
|
|
122
|
-
earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
|
|
123
|
-
return triangles;
|
|
124
|
-
}
|
|
125
|
-
function linkedList(data, start, end, dim, clockwise, area2) {
|
|
126
|
-
let i2;
|
|
127
|
-
let last;
|
|
128
|
-
if (area2 === void 0) {
|
|
129
|
-
area2 = getPolygonSignedArea(data, {
|
|
130
|
-
start,
|
|
131
|
-
end,
|
|
132
|
-
size: dim
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
if (clockwise === area2 < 0) {
|
|
136
|
-
for (i2 = start; i2 < end; i2 += dim)
|
|
137
|
-
last = insertNode(i2, data[i2], data[i2 + 1], last);
|
|
138
|
-
} else {
|
|
139
|
-
for (i2 = end - dim; i2 >= start; i2 -= dim)
|
|
140
|
-
last = insertNode(i2, data[i2], data[i2 + 1], last);
|
|
141
|
-
}
|
|
142
|
-
if (last && equals(last, last.next)) {
|
|
143
|
-
removeNode(last);
|
|
144
|
-
last = last.next;
|
|
145
|
-
}
|
|
146
|
-
return last;
|
|
147
|
-
}
|
|
148
|
-
function filterPoints(start, end) {
|
|
149
|
-
if (!start)
|
|
150
|
-
return start;
|
|
151
|
-
if (!end)
|
|
152
|
-
end = start;
|
|
153
|
-
let p = start;
|
|
154
|
-
let again;
|
|
155
|
-
do {
|
|
156
|
-
again = false;
|
|
157
|
-
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
|
|
158
|
-
removeNode(p);
|
|
159
|
-
p = end = p.prev;
|
|
160
|
-
if (p === p.next)
|
|
161
|
-
break;
|
|
162
|
-
again = true;
|
|
163
|
-
} else {
|
|
164
|
-
p = p.next;
|
|
165
|
-
}
|
|
166
|
-
} while (again || p !== end);
|
|
167
|
-
return end;
|
|
168
|
-
}
|
|
169
|
-
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
170
|
-
if (!ear)
|
|
171
|
-
return;
|
|
172
|
-
if (!pass && invSize)
|
|
173
|
-
indexCurve(ear, minX, minY, invSize);
|
|
174
|
-
let stop = ear;
|
|
175
|
-
let prev;
|
|
176
|
-
let next;
|
|
177
|
-
while (ear.prev !== ear.next) {
|
|
178
|
-
prev = ear.prev;
|
|
179
|
-
next = ear.next;
|
|
180
|
-
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
|
181
|
-
triangles.push(prev.i / dim);
|
|
182
|
-
triangles.push(ear.i / dim);
|
|
183
|
-
triangles.push(next.i / dim);
|
|
184
|
-
removeNode(ear);
|
|
185
|
-
ear = next.next;
|
|
186
|
-
stop = next.next;
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
ear = next;
|
|
190
|
-
if (ear === stop) {
|
|
191
|
-
if (!pass) {
|
|
192
|
-
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
|
|
193
|
-
} else if (pass === 1) {
|
|
194
|
-
ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
|
|
195
|
-
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
|
|
196
|
-
} else if (pass === 2) {
|
|
197
|
-
splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
|
198
|
-
}
|
|
199
|
-
break;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
function isEar(ear) {
|
|
204
|
-
const a = ear.prev;
|
|
205
|
-
const b = ear;
|
|
206
|
-
const c = ear.next;
|
|
207
|
-
if (area(a, b, c) >= 0)
|
|
208
|
-
return false;
|
|
209
|
-
let p = ear.next.next;
|
|
210
|
-
while (p !== ear.prev) {
|
|
211
|
-
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)
|
|
212
|
-
return false;
|
|
213
|
-
p = p.next;
|
|
214
|
-
}
|
|
215
|
-
return true;
|
|
216
|
-
}
|
|
217
|
-
function isEarHashed(ear, minX, minY, invSize) {
|
|
218
|
-
const a = ear.prev;
|
|
219
|
-
const b = ear;
|
|
220
|
-
const c = ear.next;
|
|
221
|
-
if (area(a, b, c) >= 0)
|
|
222
|
-
return false;
|
|
223
|
-
const minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x;
|
|
224
|
-
const minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y;
|
|
225
|
-
const maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x;
|
|
226
|
-
const maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
|
|
227
|
-
const minZ = zOrder(minTX, minTY, minX, minY, invSize);
|
|
228
|
-
const maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
|
|
229
|
-
let p = ear.prevZ;
|
|
230
|
-
let n = ear.nextZ;
|
|
231
|
-
while (p && p.z >= minZ && n && n.z <= maxZ) {
|
|
232
|
-
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)
|
|
233
|
-
return false;
|
|
234
|
-
p = p.prevZ;
|
|
235
|
-
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)
|
|
236
|
-
return false;
|
|
237
|
-
n = n.nextZ;
|
|
238
|
-
}
|
|
239
|
-
while (p && p.z >= minZ) {
|
|
240
|
-
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)
|
|
241
|
-
return false;
|
|
242
|
-
p = p.prevZ;
|
|
243
|
-
}
|
|
244
|
-
while (n && n.z <= maxZ) {
|
|
245
|
-
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)
|
|
246
|
-
return false;
|
|
247
|
-
n = n.nextZ;
|
|
248
|
-
}
|
|
249
|
-
return true;
|
|
250
|
-
}
|
|
251
|
-
function cureLocalIntersections(start, triangles, dim) {
|
|
252
|
-
let p = start;
|
|
253
|
-
do {
|
|
254
|
-
const a = p.prev;
|
|
255
|
-
const b = p.next.next;
|
|
256
|
-
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
|
257
|
-
triangles.push(a.i / dim);
|
|
258
|
-
triangles.push(p.i / dim);
|
|
259
|
-
triangles.push(b.i / dim);
|
|
260
|
-
removeNode(p);
|
|
261
|
-
removeNode(p.next);
|
|
262
|
-
p = start = b;
|
|
263
|
-
}
|
|
264
|
-
p = p.next;
|
|
265
|
-
} while (p !== start);
|
|
266
|
-
return filterPoints(p);
|
|
267
|
-
}
|
|
268
|
-
function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
|
269
|
-
let a = start;
|
|
270
|
-
do {
|
|
271
|
-
let b = a.next.next;
|
|
272
|
-
while (b !== a.prev) {
|
|
273
|
-
if (a.i !== b.i && isValidDiagonal(a, b)) {
|
|
274
|
-
let c = splitPolygon(a, b);
|
|
275
|
-
a = filterPoints(a, a.next);
|
|
276
|
-
c = filterPoints(c, c.next);
|
|
277
|
-
earcutLinked(a, triangles, dim, minX, minY, invSize);
|
|
278
|
-
earcutLinked(c, triangles, dim, minX, minY, invSize);
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
b = b.next;
|
|
282
|
-
}
|
|
283
|
-
a = a.next;
|
|
284
|
-
} while (a !== start);
|
|
285
|
-
}
|
|
286
|
-
function eliminateHoles(data, holeIndices, outerNode, dim, areas) {
|
|
287
|
-
const queue = [];
|
|
288
|
-
let i2;
|
|
289
|
-
let len;
|
|
290
|
-
let start;
|
|
291
|
-
let end;
|
|
292
|
-
let list;
|
|
293
|
-
for (i2 = 0, len = holeIndices.length; i2 < len; i2++) {
|
|
294
|
-
start = holeIndices[i2] * dim;
|
|
295
|
-
end = i2 < len - 1 ? holeIndices[i2 + 1] * dim : data.length;
|
|
296
|
-
list = linkedList(data, start, end, dim, false, areas && areas[i2 + 1]);
|
|
297
|
-
if (list === list.next)
|
|
298
|
-
list.steiner = true;
|
|
299
|
-
queue.push(getLeftmost(list));
|
|
300
|
-
}
|
|
301
|
-
queue.sort(compareX);
|
|
302
|
-
for (i2 = 0; i2 < queue.length; i2++) {
|
|
303
|
-
eliminateHole(queue[i2], outerNode);
|
|
304
|
-
outerNode = filterPoints(outerNode, outerNode.next);
|
|
305
|
-
}
|
|
306
|
-
return outerNode;
|
|
307
|
-
}
|
|
308
|
-
function compareX(a, b) {
|
|
309
|
-
return a.x - b.x;
|
|
310
|
-
}
|
|
311
|
-
function eliminateHole(hole, outerNode) {
|
|
312
|
-
outerNode = findHoleBridge(hole, outerNode);
|
|
313
|
-
if (outerNode) {
|
|
314
|
-
const b = splitPolygon(outerNode, hole);
|
|
315
|
-
filterPoints(outerNode, outerNode.next);
|
|
316
|
-
filterPoints(b, b.next);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
function findHoleBridge(hole, outerNode) {
|
|
320
|
-
let p = outerNode;
|
|
321
|
-
const hx = hole.x;
|
|
322
|
-
const hy = hole.y;
|
|
323
|
-
let qx = -Infinity;
|
|
324
|
-
let m;
|
|
325
|
-
do {
|
|
326
|
-
if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
|
|
327
|
-
const x2 = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
|
|
328
|
-
if (x2 <= hx && x2 > qx) {
|
|
329
|
-
qx = x2;
|
|
330
|
-
if (x2 === hx) {
|
|
331
|
-
if (hy === p.y)
|
|
332
|
-
return p;
|
|
333
|
-
if (hy === p.next.y)
|
|
334
|
-
return p.next;
|
|
335
|
-
}
|
|
336
|
-
m = p.x < p.next.x ? p : p.next;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
p = p.next;
|
|
340
|
-
} while (p !== outerNode);
|
|
341
|
-
if (!m)
|
|
342
|
-
return null;
|
|
343
|
-
if (hx === qx)
|
|
344
|
-
return m;
|
|
345
|
-
const stop = m;
|
|
346
|
-
const mx = m.x;
|
|
347
|
-
const my = m.y;
|
|
348
|
-
let tanMin = Infinity;
|
|
349
|
-
let tan;
|
|
350
|
-
p = m;
|
|
351
|
-
do {
|
|
352
|
-
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)) {
|
|
353
|
-
tan = Math.abs(hy - p.y) / (hx - p.x);
|
|
354
|
-
if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
|
|
355
|
-
m = p;
|
|
356
|
-
tanMin = tan;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
p = p.next;
|
|
360
|
-
} while (p !== stop);
|
|
361
|
-
return m;
|
|
362
|
-
}
|
|
363
|
-
function sectorContainsSector(m, p) {
|
|
364
|
-
return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
|
|
365
|
-
}
|
|
366
|
-
function indexCurve(start, minX, minY, invSize) {
|
|
367
|
-
let p = start;
|
|
368
|
-
do {
|
|
369
|
-
if (p.z === null)
|
|
370
|
-
p.z = zOrder(p.x, p.y, minX, minY, invSize);
|
|
371
|
-
p.prevZ = p.prev;
|
|
372
|
-
p.nextZ = p.next;
|
|
373
|
-
p = p.next;
|
|
374
|
-
} while (p !== start);
|
|
375
|
-
p.prevZ.nextZ = null;
|
|
376
|
-
p.prevZ = null;
|
|
377
|
-
sortLinked(p);
|
|
378
|
-
}
|
|
379
|
-
function sortLinked(list) {
|
|
380
|
-
let e;
|
|
381
|
-
let i2;
|
|
382
|
-
let inSize = 1;
|
|
383
|
-
let numMerges;
|
|
384
|
-
let p;
|
|
385
|
-
let pSize;
|
|
386
|
-
let q;
|
|
387
|
-
let qSize;
|
|
388
|
-
let tail;
|
|
389
|
-
do {
|
|
390
|
-
p = list;
|
|
391
|
-
list = null;
|
|
392
|
-
tail = null;
|
|
393
|
-
numMerges = 0;
|
|
394
|
-
while (p) {
|
|
395
|
-
numMerges++;
|
|
396
|
-
q = p;
|
|
397
|
-
pSize = 0;
|
|
398
|
-
for (i2 = 0; i2 < inSize; i2++) {
|
|
399
|
-
pSize++;
|
|
400
|
-
q = q.nextZ;
|
|
401
|
-
if (!q)
|
|
402
|
-
break;
|
|
403
|
-
}
|
|
404
|
-
qSize = inSize;
|
|
405
|
-
while (pSize > 0 || qSize > 0 && q) {
|
|
406
|
-
if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
|
|
407
|
-
e = p;
|
|
408
|
-
p = p.nextZ;
|
|
409
|
-
pSize--;
|
|
410
|
-
} else {
|
|
411
|
-
e = q;
|
|
412
|
-
q = q.nextZ;
|
|
413
|
-
qSize--;
|
|
414
|
-
}
|
|
415
|
-
if (tail)
|
|
416
|
-
tail.nextZ = e;
|
|
417
|
-
else
|
|
418
|
-
list = e;
|
|
419
|
-
e.prevZ = tail;
|
|
420
|
-
tail = e;
|
|
421
|
-
}
|
|
422
|
-
p = q;
|
|
423
|
-
}
|
|
424
|
-
tail.nextZ = null;
|
|
425
|
-
inSize *= 2;
|
|
426
|
-
} while (numMerges > 1);
|
|
427
|
-
return list;
|
|
428
|
-
}
|
|
429
|
-
function zOrder(x2, y2, minX, minY, invSize) {
|
|
430
|
-
x2 = 32767 * (x2 - minX) * invSize;
|
|
431
|
-
y2 = 32767 * (y2 - minY) * invSize;
|
|
432
|
-
x2 = (x2 | x2 << 8) & 16711935;
|
|
433
|
-
x2 = (x2 | x2 << 4) & 252645135;
|
|
434
|
-
x2 = (x2 | x2 << 2) & 858993459;
|
|
435
|
-
x2 = (x2 | x2 << 1) & 1431655765;
|
|
436
|
-
y2 = (y2 | y2 << 8) & 16711935;
|
|
437
|
-
y2 = (y2 | y2 << 4) & 252645135;
|
|
438
|
-
y2 = (y2 | y2 << 2) & 858993459;
|
|
439
|
-
y2 = (y2 | y2 << 1) & 1431655765;
|
|
440
|
-
return x2 | y2 << 1;
|
|
441
|
-
}
|
|
442
|
-
function getLeftmost(start) {
|
|
443
|
-
let p = start;
|
|
444
|
-
let leftmost = start;
|
|
445
|
-
do {
|
|
446
|
-
if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
|
|
447
|
-
leftmost = p;
|
|
448
|
-
p = p.next;
|
|
449
|
-
} while (p !== start);
|
|
450
|
-
return leftmost;
|
|
451
|
-
}
|
|
452
|
-
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
|
|
453
|
-
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;
|
|
454
|
-
}
|
|
455
|
-
function isValidDiagonal(a, b) {
|
|
456
|
-
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);
|
|
457
|
-
}
|
|
458
|
-
function area(p, q, r) {
|
|
459
|
-
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
|
460
|
-
}
|
|
461
|
-
function equals(p1, p2) {
|
|
462
|
-
return p1.x === p2.x && p1.y === p2.y;
|
|
463
|
-
}
|
|
464
|
-
function intersects(p1, q1, p2, q2) {
|
|
465
|
-
const o1 = sign(area(p1, q1, p2));
|
|
466
|
-
const o2 = sign(area(p1, q1, q2));
|
|
467
|
-
const o3 = sign(area(p2, q2, p1));
|
|
468
|
-
const o4 = sign(area(p2, q2, q1));
|
|
469
|
-
if (o1 !== o2 && o3 !== o4)
|
|
470
|
-
return true;
|
|
471
|
-
if (o1 === 0 && onSegment(p1, p2, q1))
|
|
472
|
-
return true;
|
|
473
|
-
if (o2 === 0 && onSegment(p1, q2, q1))
|
|
474
|
-
return true;
|
|
475
|
-
if (o3 === 0 && onSegment(p2, p1, q2))
|
|
476
|
-
return true;
|
|
477
|
-
if (o4 === 0 && onSegment(p2, q1, q2))
|
|
478
|
-
return true;
|
|
479
|
-
return false;
|
|
480
|
-
}
|
|
481
|
-
function onSegment(p, q, r) {
|
|
482
|
-
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);
|
|
483
|
-
}
|
|
484
|
-
function sign(num) {
|
|
485
|
-
return num > 0 ? 1 : num < 0 ? -1 : 0;
|
|
486
|
-
}
|
|
487
|
-
function intersectsPolygon(a, b) {
|
|
488
|
-
let p = a;
|
|
489
|
-
do {
|
|
490
|
-
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))
|
|
491
|
-
return true;
|
|
492
|
-
p = p.next;
|
|
493
|
-
} while (p !== a);
|
|
494
|
-
return false;
|
|
495
|
-
}
|
|
496
|
-
function locallyInside(a, b) {
|
|
497
|
-
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;
|
|
498
|
-
}
|
|
499
|
-
function middleInside(a, b) {
|
|
500
|
-
let p = a;
|
|
501
|
-
let inside = false;
|
|
502
|
-
const px = (a.x + b.x) / 2;
|
|
503
|
-
const py = (a.y + b.y) / 2;
|
|
504
|
-
do {
|
|
505
|
-
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)
|
|
506
|
-
inside = !inside;
|
|
507
|
-
p = p.next;
|
|
508
|
-
} while (p !== a);
|
|
509
|
-
return inside;
|
|
510
|
-
}
|
|
511
|
-
function splitPolygon(a, b) {
|
|
512
|
-
const a2 = new Node(a.i, a.x, a.y);
|
|
513
|
-
const b2 = new Node(b.i, b.x, b.y);
|
|
514
|
-
const an = a.next;
|
|
515
|
-
const bp = b.prev;
|
|
516
|
-
a.next = b;
|
|
517
|
-
b.prev = a;
|
|
518
|
-
a2.next = an;
|
|
519
|
-
an.prev = a2;
|
|
520
|
-
b2.next = a2;
|
|
521
|
-
a2.prev = b2;
|
|
522
|
-
bp.next = b2;
|
|
523
|
-
b2.prev = bp;
|
|
524
|
-
return b2;
|
|
525
|
-
}
|
|
526
|
-
function insertNode(i2, x2, y2, last) {
|
|
527
|
-
const p = new Node(i2, x2, y2);
|
|
528
|
-
if (!last) {
|
|
529
|
-
p.prev = p;
|
|
530
|
-
p.next = p;
|
|
531
|
-
} else {
|
|
532
|
-
p.next = last.next;
|
|
533
|
-
p.prev = last;
|
|
534
|
-
last.next.prev = p;
|
|
535
|
-
last.next = p;
|
|
536
|
-
}
|
|
537
|
-
return p;
|
|
538
|
-
}
|
|
539
|
-
function removeNode(p) {
|
|
540
|
-
p.next.prev = p.prev;
|
|
541
|
-
p.prev.next = p.next;
|
|
542
|
-
if (p.prevZ)
|
|
543
|
-
p.prevZ.nextZ = p.nextZ;
|
|
544
|
-
if (p.nextZ)
|
|
545
|
-
p.nextZ.prevZ = p.prevZ;
|
|
546
|
-
}
|
|
547
|
-
function Node(i2, x2, y2) {
|
|
548
|
-
this.i = i2;
|
|
549
|
-
this.x = x2;
|
|
550
|
-
this.y = y2;
|
|
551
|
-
this.prev = null;
|
|
552
|
-
this.next = null;
|
|
553
|
-
this.z = null;
|
|
554
|
-
this.prevZ = null;
|
|
555
|
-
this.nextZ = null;
|
|
556
|
-
this.steiner = false;
|
|
557
|
-
}
|
|
558
|
-
var init_earcut = __esm({
|
|
559
|
-
"../../node_modules/@math.gl/polygon/dist/esm/earcut.js"() {
|
|
560
|
-
init_polygon_utils();
|
|
561
|
-
}
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
// ../../node_modules/@math.gl/polygon/dist/esm/utils.js
|
|
565
|
-
var init_utils = __esm({
|
|
566
|
-
"../../node_modules/@math.gl/polygon/dist/esm/utils.js"() {
|
|
567
|
-
}
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
// ../../node_modules/@math.gl/polygon/dist/esm/lineclip.js
|
|
571
|
-
var init_lineclip = __esm({
|
|
572
|
-
"../../node_modules/@math.gl/polygon/dist/esm/lineclip.js"() {
|
|
573
|
-
init_utils();
|
|
574
|
-
}
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
// ../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js
|
|
578
|
-
var init_cut_by_grid = __esm({
|
|
579
|
-
"../../node_modules/@math.gl/polygon/dist/esm/cut-by-grid.js"() {
|
|
580
|
-
init_lineclip();
|
|
581
|
-
init_utils();
|
|
582
|
-
}
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
// ../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js
|
|
586
|
-
var init_cut_by_mercator_bounds = __esm({
|
|
587
|
-
"../../node_modules/@math.gl/polygon/dist/esm/cut-by-mercator-bounds.js"() {
|
|
588
|
-
init_cut_by_grid();
|
|
589
|
-
init_utils();
|
|
590
|
-
}
|
|
591
|
-
});
|
|
592
|
-
|
|
593
|
-
// ../../node_modules/@math.gl/polygon/dist/esm/index.js
|
|
594
|
-
var init_esm = __esm({
|
|
595
|
-
"../../node_modules/@math.gl/polygon/dist/esm/index.js"() {
|
|
596
|
-
init_polygon();
|
|
597
|
-
init_polygon_utils();
|
|
598
|
-
init_earcut();
|
|
599
|
-
init_lineclip();
|
|
600
|
-
init_cut_by_grid();
|
|
601
|
-
init_cut_by_mercator_bounds();
|
|
602
|
-
init_polygon();
|
|
603
|
-
}
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
// ../gis/src/lib/flat-geojson-to-binary.ts
|
|
607
|
-
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
608
|
-
const propArrayTypes = extractNumericPropTypes(features);
|
|
609
|
-
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
610
|
-
return fillArrays(features, {
|
|
611
|
-
propArrayTypes,
|
|
612
|
-
...geometryInfo
|
|
613
|
-
}, {
|
|
614
|
-
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
615
|
-
PositionDataType: options ? options.PositionDataType : Float32Array,
|
|
616
|
-
triangulate: options ? options.triangulate : true
|
|
617
|
-
});
|
|
618
|
-
}
|
|
619
|
-
function extractNumericPropTypes(features) {
|
|
620
|
-
const propArrayTypes = {};
|
|
621
|
-
for (const feature of features) {
|
|
622
|
-
if (feature.properties) {
|
|
623
|
-
for (const key in feature.properties) {
|
|
624
|
-
const val = feature.properties[key];
|
|
625
|
-
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
return propArrayTypes;
|
|
630
|
-
}
|
|
631
|
-
function fillArrays(features, geometryInfo, options) {
|
|
632
|
-
const {
|
|
633
|
-
pointPositionsCount,
|
|
634
|
-
pointFeaturesCount,
|
|
635
|
-
linePositionsCount,
|
|
636
|
-
linePathsCount,
|
|
637
|
-
lineFeaturesCount,
|
|
638
|
-
polygonPositionsCount,
|
|
639
|
-
polygonObjectsCount,
|
|
640
|
-
polygonRingsCount,
|
|
641
|
-
polygonFeaturesCount,
|
|
642
|
-
propArrayTypes,
|
|
643
|
-
coordLength
|
|
644
|
-
} = geometryInfo;
|
|
645
|
-
const { numericPropKeys = [], PositionDataType = Float32Array, triangulate = true } = options;
|
|
646
|
-
const hasGlobalId = features[0] && "id" in features[0];
|
|
647
|
-
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
648
|
-
const points = {
|
|
649
|
-
type: "Point",
|
|
650
|
-
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
651
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
652
|
-
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
653
|
-
numericProps: {},
|
|
654
|
-
properties: [],
|
|
655
|
-
fields: []
|
|
656
|
-
};
|
|
657
|
-
const lines = {
|
|
658
|
-
type: "LineString",
|
|
659
|
-
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
660
|
-
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
661
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
662
|
-
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
663
|
-
numericProps: {},
|
|
664
|
-
properties: [],
|
|
665
|
-
fields: []
|
|
666
|
-
};
|
|
667
|
-
const polygons = {
|
|
668
|
-
type: "Polygon",
|
|
669
|
-
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
670
|
-
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
671
|
-
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
672
|
-
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
673
|
-
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
674
|
-
numericProps: {},
|
|
675
|
-
properties: [],
|
|
676
|
-
fields: []
|
|
677
|
-
};
|
|
678
|
-
if (triangulate) {
|
|
679
|
-
polygons.triangles = [];
|
|
680
|
-
}
|
|
681
|
-
for (const object of [points, lines, polygons]) {
|
|
682
|
-
for (const propName of numericPropKeys) {
|
|
683
|
-
const T = propArrayTypes[propName];
|
|
684
|
-
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
688
|
-
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
689
|
-
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
690
|
-
const indexMap = {
|
|
691
|
-
pointPosition: 0,
|
|
692
|
-
pointFeature: 0,
|
|
693
|
-
linePosition: 0,
|
|
694
|
-
linePath: 0,
|
|
695
|
-
lineFeature: 0,
|
|
696
|
-
polygonPosition: 0,
|
|
697
|
-
polygonObject: 0,
|
|
698
|
-
polygonRing: 0,
|
|
699
|
-
polygonFeature: 0,
|
|
700
|
-
feature: 0
|
|
701
|
-
};
|
|
702
|
-
for (const feature of features) {
|
|
703
|
-
const geometry = feature.geometry;
|
|
704
|
-
const properties = feature.properties || {};
|
|
705
|
-
switch (geometry.type) {
|
|
706
|
-
case "Point":
|
|
707
|
-
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
708
|
-
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
709
|
-
if (hasGlobalId) {
|
|
710
|
-
points.fields.push({ id: feature.id });
|
|
711
|
-
}
|
|
712
|
-
indexMap.pointFeature++;
|
|
713
|
-
break;
|
|
714
|
-
case "LineString":
|
|
715
|
-
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
716
|
-
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
717
|
-
if (hasGlobalId) {
|
|
718
|
-
lines.fields.push({ id: feature.id });
|
|
719
|
-
}
|
|
720
|
-
indexMap.lineFeature++;
|
|
721
|
-
break;
|
|
722
|
-
case "Polygon":
|
|
723
|
-
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
724
|
-
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
725
|
-
if (hasGlobalId) {
|
|
726
|
-
polygons.fields.push({ id: feature.id });
|
|
727
|
-
}
|
|
728
|
-
indexMap.polygonFeature++;
|
|
729
|
-
break;
|
|
730
|
-
default:
|
|
731
|
-
throw new Error("Invalid geometry type");
|
|
732
|
-
}
|
|
733
|
-
indexMap.feature++;
|
|
734
|
-
}
|
|
735
|
-
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
736
|
-
}
|
|
737
|
-
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
738
|
-
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
739
|
-
const nPositions = geometry.data.length / coordLength;
|
|
740
|
-
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
741
|
-
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
742
|
-
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
743
|
-
indexMap.pointPosition += nPositions;
|
|
744
|
-
}
|
|
745
|
-
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
746
|
-
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
747
|
-
const nPositions = geometry.data.length / coordLength;
|
|
748
|
-
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
749
|
-
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
750
|
-
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
751
|
-
for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
|
|
752
|
-
const start = geometry.indices[i2];
|
|
753
|
-
const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
|
|
754
|
-
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
755
|
-
indexMap.linePosition += (end - start) / coordLength;
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
759
|
-
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
760
|
-
const nPositions = geometry.data.length / coordLength;
|
|
761
|
-
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
762
|
-
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
763
|
-
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
764
|
-
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
765
|
-
const startPosition = indexMap.polygonPosition;
|
|
766
|
-
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
767
|
-
const areas = geometry.areas[l];
|
|
768
|
-
const indices = geometry.indices[l];
|
|
769
|
-
const nextIndices = geometry.indices[l + 1];
|
|
770
|
-
for (let i2 = 0, il = indices.length; i2 < il; ++i2) {
|
|
771
|
-
const start = indices[i2];
|
|
772
|
-
const end = i2 === il - 1 ? nextIndices === void 0 ? geometry.data.length : nextIndices[0] : indices[i2 + 1];
|
|
773
|
-
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
774
|
-
indexMap.polygonPosition += (end - start) / coordLength;
|
|
775
|
-
}
|
|
776
|
-
const endPosition = indexMap.polygonPosition;
|
|
777
|
-
triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
function triangulatePolygon(polygons, areas, indices, {
|
|
781
|
-
startPosition,
|
|
782
|
-
endPosition,
|
|
783
|
-
coordLength
|
|
784
|
-
}) {
|
|
785
|
-
if (!polygons.triangles) {
|
|
786
|
-
return;
|
|
787
|
-
}
|
|
788
|
-
const start = startPosition * coordLength;
|
|
789
|
-
const end = endPosition * coordLength;
|
|
790
|
-
const polygonPositions = polygons.positions.subarray(start, end);
|
|
791
|
-
const offset = indices[0];
|
|
792
|
-
const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
|
|
793
|
-
const triangles = earcut(polygonPositions, holes, coordLength, areas);
|
|
794
|
-
for (let t = 0, tl = triangles.length; t < tl; ++t) {
|
|
795
|
-
polygons.triangles.push(startPosition + triangles[t]);
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
function wrapProps(obj, size) {
|
|
799
|
-
const returnObj = {};
|
|
800
|
-
for (const key in obj) {
|
|
801
|
-
returnObj[key] = { value: obj[key], size };
|
|
802
|
-
}
|
|
803
|
-
return returnObj;
|
|
804
|
-
}
|
|
805
|
-
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
806
|
-
const binaryFeatures = {
|
|
807
|
-
points: {
|
|
808
|
-
...points,
|
|
809
|
-
positions: { value: points.positions, size: coordLength },
|
|
810
|
-
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
811
|
-
featureIds: { value: points.featureIds, size: 1 },
|
|
812
|
-
numericProps: wrapProps(points.numericProps, 1)
|
|
813
|
-
},
|
|
814
|
-
lines: {
|
|
815
|
-
...lines,
|
|
816
|
-
positions: { value: lines.positions, size: coordLength },
|
|
817
|
-
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
818
|
-
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
819
|
-
featureIds: { value: lines.featureIds, size: 1 },
|
|
820
|
-
numericProps: wrapProps(lines.numericProps, 1)
|
|
821
|
-
},
|
|
822
|
-
polygons: {
|
|
823
|
-
...polygons,
|
|
824
|
-
positions: { value: polygons.positions, size: coordLength },
|
|
825
|
-
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
826
|
-
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
827
|
-
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
828
|
-
featureIds: { value: polygons.featureIds, size: 1 },
|
|
829
|
-
numericProps: wrapProps(polygons.numericProps, 1)
|
|
830
|
-
}
|
|
831
|
-
};
|
|
832
|
-
if (binaryFeatures.polygons && polygons.triangles) {
|
|
833
|
-
binaryFeatures.polygons.triangles = { value: new Uint32Array(polygons.triangles), size: 1 };
|
|
834
|
-
}
|
|
835
|
-
return binaryFeatures;
|
|
836
|
-
}
|
|
837
|
-
function fillNumericProperties(object, properties, index, length2) {
|
|
838
|
-
for (const numericPropName in object.numericProps) {
|
|
839
|
-
if (numericPropName in properties) {
|
|
840
|
-
const value = properties[numericPropName];
|
|
841
|
-
object.numericProps[numericPropName].fill(value, index, index + length2);
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
function keepStringProperties(properties, numericKeys) {
|
|
846
|
-
const props = {};
|
|
847
|
-
for (const key in properties) {
|
|
848
|
-
if (!numericKeys.includes(key)) {
|
|
849
|
-
props[key] = properties[key];
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
return props;
|
|
853
|
-
}
|
|
854
|
-
function deduceArrayType(x2, constructor) {
|
|
855
|
-
if (constructor === Array || !Number.isFinite(x2)) {
|
|
856
|
-
return Array;
|
|
857
|
-
}
|
|
858
|
-
return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
|
|
859
|
-
}
|
|
860
|
-
var init_flat_geojson_to_binary = __esm({
|
|
861
|
-
"../gis/src/lib/flat-geojson-to-binary.ts"() {
|
|
862
|
-
init_esm();
|
|
863
|
-
}
|
|
864
|
-
});
|
|
865
|
-
|
|
866
|
-
// ../gis/src/index.ts
|
|
867
|
-
var init_src = __esm({
|
|
868
|
-
"../gis/src/index.ts"() {
|
|
869
|
-
init_flat_geojson_to_binary();
|
|
870
|
-
}
|
|
871
|
-
});
|
|
872
|
-
|
|
873
|
-
// ../../node_modules/ieee754/index.js
|
|
874
|
-
var require_ieee754 = __commonJS({
|
|
875
|
-
"../../node_modules/ieee754/index.js"(exports) {
|
|
876
|
-
exports.read = function(buffer, offset, isLE, mLen, nBytes) {
|
|
877
|
-
var e, m;
|
|
878
|
-
var eLen = nBytes * 8 - mLen - 1;
|
|
879
|
-
var eMax = (1 << eLen) - 1;
|
|
880
|
-
var eBias = eMax >> 1;
|
|
881
|
-
var nBits = -7;
|
|
882
|
-
var i2 = isLE ? nBytes - 1 : 0;
|
|
883
|
-
var d = isLE ? -1 : 1;
|
|
884
|
-
var s = buffer[offset + i2];
|
|
885
|
-
i2 += d;
|
|
886
|
-
e = s & (1 << -nBits) - 1;
|
|
887
|
-
s >>= -nBits;
|
|
888
|
-
nBits += eLen;
|
|
889
|
-
for (; nBits > 0; e = e * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
|
|
890
|
-
}
|
|
891
|
-
m = e & (1 << -nBits) - 1;
|
|
892
|
-
e >>= -nBits;
|
|
893
|
-
nBits += mLen;
|
|
894
|
-
for (; nBits > 0; m = m * 256 + buffer[offset + i2], i2 += d, nBits -= 8) {
|
|
895
|
-
}
|
|
896
|
-
if (e === 0) {
|
|
897
|
-
e = 1 - eBias;
|
|
898
|
-
} else if (e === eMax) {
|
|
899
|
-
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
900
|
-
} else {
|
|
901
|
-
m = m + Math.pow(2, mLen);
|
|
902
|
-
e = e - eBias;
|
|
903
|
-
}
|
|
904
|
-
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
905
|
-
};
|
|
906
|
-
exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
|
|
907
|
-
var e, m, c;
|
|
908
|
-
var eLen = nBytes * 8 - mLen - 1;
|
|
909
|
-
var eMax = (1 << eLen) - 1;
|
|
910
|
-
var eBias = eMax >> 1;
|
|
911
|
-
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
912
|
-
var i2 = isLE ? 0 : nBytes - 1;
|
|
913
|
-
var d = isLE ? 1 : -1;
|
|
914
|
-
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
915
|
-
value = Math.abs(value);
|
|
916
|
-
if (isNaN(value) || value === Infinity) {
|
|
917
|
-
m = isNaN(value) ? 1 : 0;
|
|
918
|
-
e = eMax;
|
|
919
|
-
} else {
|
|
920
|
-
e = Math.floor(Math.log(value) / Math.LN2);
|
|
921
|
-
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
922
|
-
e--;
|
|
923
|
-
c *= 2;
|
|
924
|
-
}
|
|
925
|
-
if (e + eBias >= 1) {
|
|
926
|
-
value += rt / c;
|
|
927
|
-
} else {
|
|
928
|
-
value += rt * Math.pow(2, 1 - eBias);
|
|
929
|
-
}
|
|
930
|
-
if (value * c >= 2) {
|
|
931
|
-
e++;
|
|
932
|
-
c /= 2;
|
|
933
|
-
}
|
|
934
|
-
if (e + eBias >= eMax) {
|
|
935
|
-
m = 0;
|
|
936
|
-
e = eMax;
|
|
937
|
-
} else if (e + eBias >= 1) {
|
|
938
|
-
m = (value * c - 1) * Math.pow(2, mLen);
|
|
939
|
-
e = e + eBias;
|
|
940
|
-
} else {
|
|
941
|
-
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
942
|
-
e = 0;
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
for (; mLen >= 8; buffer[offset + i2] = m & 255, i2 += d, m /= 256, mLen -= 8) {
|
|
946
|
-
}
|
|
947
|
-
e = e << mLen | m;
|
|
948
|
-
eLen += mLen;
|
|
949
|
-
for (; eLen > 0; buffer[offset + i2] = e & 255, i2 += d, e /= 256, eLen -= 8) {
|
|
950
|
-
}
|
|
951
|
-
buffer[offset + i2 - d] |= s * 128;
|
|
952
|
-
};
|
|
953
|
-
}
|
|
954
|
-
});
|
|
955
|
-
|
|
956
|
-
// ../../node_modules/pbf/index.js
|
|
957
|
-
var require_pbf = __commonJS({
|
|
958
|
-
"../../node_modules/pbf/index.js"(exports, module) {
|
|
959
|
-
"use strict";
|
|
960
|
-
module.exports = Pbf;
|
|
961
|
-
var ieee754 = require_ieee754();
|
|
962
|
-
function Pbf(buf) {
|
|
963
|
-
this.buf = ArrayBuffer.isView && ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0);
|
|
964
|
-
this.pos = 0;
|
|
965
|
-
this.type = 0;
|
|
966
|
-
this.length = this.buf.length;
|
|
123
|
+
// ../../node_modules/pbf/index.js
|
|
124
|
+
var require_pbf = __commonJS({
|
|
125
|
+
"../../node_modules/pbf/index.js"(exports, module) {
|
|
126
|
+
"use strict";
|
|
127
|
+
module.exports = Pbf;
|
|
128
|
+
var ieee754 = require_ieee754();
|
|
129
|
+
function Pbf(buf) {
|
|
130
|
+
this.buf = ArrayBuffer.isView && ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0);
|
|
131
|
+
this.pos = 0;
|
|
132
|
+
this.type = 0;
|
|
133
|
+
this.length = this.buf.length;
|
|
967
134
|
}
|
|
968
135
|
Pbf.Varint = 0;
|
|
969
136
|
Pbf.Fixed64 = 1;
|
|
@@ -977,6 +144,7 @@
|
|
|
977
144
|
destroy: function() {
|
|
978
145
|
this.buf = null;
|
|
979
146
|
},
|
|
147
|
+
// === READING =================================================================
|
|
980
148
|
readFields: function(readField, result, end) {
|
|
981
149
|
end = end || this.length;
|
|
982
150
|
while (this.pos < end) {
|
|
@@ -1001,6 +169,7 @@
|
|
|
1001
169
|
this.pos += 4;
|
|
1002
170
|
return val;
|
|
1003
171
|
},
|
|
172
|
+
// 64-bit int handling is based on github.com/dpw/node-buffer-more-ints (MIT-licensed)
|
|
1004
173
|
readFixed64: function() {
|
|
1005
174
|
var val = readUInt32(this.buf, this.pos) + readUInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;
|
|
1006
175
|
this.pos += 8;
|
|
@@ -1067,6 +236,7 @@
|
|
|
1067
236
|
this.pos = end;
|
|
1068
237
|
return buffer;
|
|
1069
238
|
},
|
|
239
|
+
// verbose for performance reasons; doesn't affect gzipped size
|
|
1070
240
|
readPackedVarint: function(arr, isSigned) {
|
|
1071
241
|
if (this.type !== Pbf.Bytes)
|
|
1072
242
|
return arr.push(this.readVarint(isSigned));
|
|
@@ -1162,6 +332,7 @@
|
|
|
1162
332
|
else
|
|
1163
333
|
throw new Error("Unimplemented type: " + type);
|
|
1164
334
|
},
|
|
335
|
+
// === WRITING =================================================================
|
|
1165
336
|
writeTag: function(tag, type) {
|
|
1166
337
|
this.writeVarint(tag << 3 | type);
|
|
1167
338
|
},
|
|
@@ -1479,132 +650,1019 @@
|
|
|
1479
650
|
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1480
651
|
pbf.writeFixed64(arr[i2]);
|
|
1481
652
|
}
|
|
1482
|
-
function writePackedSFixed64(arr, pbf) {
|
|
1483
|
-
for (var i2 = 0; i2 < arr.length; i2++)
|
|
1484
|
-
pbf.writeSFixed64(arr[i2]);
|
|
653
|
+
function writePackedSFixed64(arr, pbf) {
|
|
654
|
+
for (var i2 = 0; i2 < arr.length; i2++)
|
|
655
|
+
pbf.writeSFixed64(arr[i2]);
|
|
656
|
+
}
|
|
657
|
+
function readUInt32(buf, pos) {
|
|
658
|
+
return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + buf[pos + 3] * 16777216;
|
|
659
|
+
}
|
|
660
|
+
function writeInt32(buf, val, pos) {
|
|
661
|
+
buf[pos] = val;
|
|
662
|
+
buf[pos + 1] = val >>> 8;
|
|
663
|
+
buf[pos + 2] = val >>> 16;
|
|
664
|
+
buf[pos + 3] = val >>> 24;
|
|
665
|
+
}
|
|
666
|
+
function readInt32(buf, pos) {
|
|
667
|
+
return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + (buf[pos + 3] << 24);
|
|
668
|
+
}
|
|
669
|
+
function readUtf8(buf, pos, end) {
|
|
670
|
+
var str = "";
|
|
671
|
+
var i2 = pos;
|
|
672
|
+
while (i2 < end) {
|
|
673
|
+
var b0 = buf[i2];
|
|
674
|
+
var c = null;
|
|
675
|
+
var bytesPerSequence = b0 > 239 ? 4 : b0 > 223 ? 3 : b0 > 191 ? 2 : 1;
|
|
676
|
+
if (i2 + bytesPerSequence > end)
|
|
677
|
+
break;
|
|
678
|
+
var b1, b2, b3;
|
|
679
|
+
if (bytesPerSequence === 1) {
|
|
680
|
+
if (b0 < 128) {
|
|
681
|
+
c = b0;
|
|
682
|
+
}
|
|
683
|
+
} else if (bytesPerSequence === 2) {
|
|
684
|
+
b1 = buf[i2 + 1];
|
|
685
|
+
if ((b1 & 192) === 128) {
|
|
686
|
+
c = (b0 & 31) << 6 | b1 & 63;
|
|
687
|
+
if (c <= 127) {
|
|
688
|
+
c = null;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
} else if (bytesPerSequence === 3) {
|
|
692
|
+
b1 = buf[i2 + 1];
|
|
693
|
+
b2 = buf[i2 + 2];
|
|
694
|
+
if ((b1 & 192) === 128 && (b2 & 192) === 128) {
|
|
695
|
+
c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63;
|
|
696
|
+
if (c <= 2047 || c >= 55296 && c <= 57343) {
|
|
697
|
+
c = null;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
} else if (bytesPerSequence === 4) {
|
|
701
|
+
b1 = buf[i2 + 1];
|
|
702
|
+
b2 = buf[i2 + 2];
|
|
703
|
+
b3 = buf[i2 + 3];
|
|
704
|
+
if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) {
|
|
705
|
+
c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
|
|
706
|
+
if (c <= 65535 || c >= 1114112) {
|
|
707
|
+
c = null;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
if (c === null) {
|
|
712
|
+
c = 65533;
|
|
713
|
+
bytesPerSequence = 1;
|
|
714
|
+
} else if (c > 65535) {
|
|
715
|
+
c -= 65536;
|
|
716
|
+
str += String.fromCharCode(c >>> 10 & 1023 | 55296);
|
|
717
|
+
c = 56320 | c & 1023;
|
|
718
|
+
}
|
|
719
|
+
str += String.fromCharCode(c);
|
|
720
|
+
i2 += bytesPerSequence;
|
|
721
|
+
}
|
|
722
|
+
return str;
|
|
723
|
+
}
|
|
724
|
+
function readUtf8TextDecoder(buf, pos, end) {
|
|
725
|
+
return utf8TextDecoder.decode(buf.subarray(pos, end));
|
|
726
|
+
}
|
|
727
|
+
function writeUtf8(buf, str, pos) {
|
|
728
|
+
for (var i2 = 0, c, lead; i2 < str.length; i2++) {
|
|
729
|
+
c = str.charCodeAt(i2);
|
|
730
|
+
if (c > 55295 && c < 57344) {
|
|
731
|
+
if (lead) {
|
|
732
|
+
if (c < 56320) {
|
|
733
|
+
buf[pos++] = 239;
|
|
734
|
+
buf[pos++] = 191;
|
|
735
|
+
buf[pos++] = 189;
|
|
736
|
+
lead = c;
|
|
737
|
+
continue;
|
|
738
|
+
} else {
|
|
739
|
+
c = lead - 55296 << 10 | c - 56320 | 65536;
|
|
740
|
+
lead = null;
|
|
741
|
+
}
|
|
742
|
+
} else {
|
|
743
|
+
if (c > 56319 || i2 + 1 === str.length) {
|
|
744
|
+
buf[pos++] = 239;
|
|
745
|
+
buf[pos++] = 191;
|
|
746
|
+
buf[pos++] = 189;
|
|
747
|
+
} else {
|
|
748
|
+
lead = c;
|
|
749
|
+
}
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
752
|
+
} else if (lead) {
|
|
753
|
+
buf[pos++] = 239;
|
|
754
|
+
buf[pos++] = 191;
|
|
755
|
+
buf[pos++] = 189;
|
|
756
|
+
lead = null;
|
|
757
|
+
}
|
|
758
|
+
if (c < 128) {
|
|
759
|
+
buf[pos++] = c;
|
|
760
|
+
} else {
|
|
761
|
+
if (c < 2048) {
|
|
762
|
+
buf[pos++] = c >> 6 | 192;
|
|
763
|
+
} else {
|
|
764
|
+
if (c < 65536) {
|
|
765
|
+
buf[pos++] = c >> 12 | 224;
|
|
766
|
+
} else {
|
|
767
|
+
buf[pos++] = c >> 18 | 240;
|
|
768
|
+
buf[pos++] = c >> 12 & 63 | 128;
|
|
769
|
+
}
|
|
770
|
+
buf[pos++] = c >> 6 & 63 | 128;
|
|
771
|
+
}
|
|
772
|
+
buf[pos++] = c & 63 | 128;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
return pos;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
// src/index.ts
|
|
781
|
+
var src_exports = {};
|
|
782
|
+
__export(src_exports, {
|
|
783
|
+
GeoJSONTiler: () => GeoJSONTiler,
|
|
784
|
+
MVTLoader: () => MVTLoader,
|
|
785
|
+
MVTSource: () => MVTSource,
|
|
786
|
+
MVTWorkerLoader: () => MVTWorkerLoader,
|
|
787
|
+
TileJSONLoader: () => TileJSONLoader
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
// ../../node_modules/@babel/runtime/helpers/esm/typeof.js
|
|
791
|
+
function _typeof(obj) {
|
|
792
|
+
"@babel/helpers - typeof";
|
|
793
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
794
|
+
return typeof obj2;
|
|
795
|
+
} : function(obj2) {
|
|
796
|
+
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
797
|
+
}, _typeof(obj);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// ../../node_modules/@babel/runtime/helpers/esm/toPrimitive.js
|
|
801
|
+
function _toPrimitive(input, hint) {
|
|
802
|
+
if (_typeof(input) !== "object" || input === null)
|
|
803
|
+
return input;
|
|
804
|
+
var prim = input[Symbol.toPrimitive];
|
|
805
|
+
if (prim !== void 0) {
|
|
806
|
+
var res = prim.call(input, hint || "default");
|
|
807
|
+
if (_typeof(res) !== "object")
|
|
808
|
+
return res;
|
|
809
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
810
|
+
}
|
|
811
|
+
return (hint === "string" ? String : Number)(input);
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// ../../node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
|
|
815
|
+
function _toPropertyKey(arg) {
|
|
816
|
+
var key = _toPrimitive(arg, "string");
|
|
817
|
+
return _typeof(key) === "symbol" ? key : String(key);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
// ../../node_modules/@babel/runtime/helpers/esm/defineProperty.js
|
|
821
|
+
function _defineProperty(obj, key, value) {
|
|
822
|
+
key = _toPropertyKey(key);
|
|
823
|
+
if (key in obj) {
|
|
824
|
+
Object.defineProperty(obj, key, {
|
|
825
|
+
value,
|
|
826
|
+
enumerable: true,
|
|
827
|
+
configurable: true,
|
|
828
|
+
writable: true
|
|
829
|
+
});
|
|
830
|
+
} else {
|
|
831
|
+
obj[key] = value;
|
|
832
|
+
}
|
|
833
|
+
return obj;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
// ../../node_modules/@math.gl/polygon/dist/polygon-utils.js
|
|
837
|
+
var DimIndex = {
|
|
838
|
+
x: 0,
|
|
839
|
+
y: 1,
|
|
840
|
+
z: 2
|
|
841
|
+
};
|
|
842
|
+
function getPolygonSignedArea(points, options = {}) {
|
|
843
|
+
const {
|
|
844
|
+
start = 0,
|
|
845
|
+
end = points.length,
|
|
846
|
+
plane = "xy"
|
|
847
|
+
} = options;
|
|
848
|
+
const dim = options.size || 2;
|
|
849
|
+
let area2 = 0;
|
|
850
|
+
const i0 = DimIndex[plane[0]];
|
|
851
|
+
const i1 = DimIndex[plane[1]];
|
|
852
|
+
for (let i2 = start, j = end - dim; i2 < end; i2 += dim) {
|
|
853
|
+
area2 += (points[i2 + i0] - points[j + i0]) * (points[i2 + i1] + points[j + i1]);
|
|
854
|
+
j = i2;
|
|
855
|
+
}
|
|
856
|
+
return area2 / 2;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// ../../node_modules/@math.gl/polygon/dist/earcut.js
|
|
860
|
+
function earcut(positions, holeIndices, dim = 2, areas, plane = "xy") {
|
|
861
|
+
const hasHoles = holeIndices && holeIndices.length;
|
|
862
|
+
const outerLen = hasHoles ? holeIndices[0] * dim : positions.length;
|
|
863
|
+
let outerNode = linkedList(positions, 0, outerLen, dim, true, areas && areas[0], plane);
|
|
864
|
+
const triangles = [];
|
|
865
|
+
if (!outerNode || outerNode.next === outerNode.prev)
|
|
866
|
+
return triangles;
|
|
867
|
+
let invSize;
|
|
868
|
+
let maxX;
|
|
869
|
+
let maxY;
|
|
870
|
+
let minX;
|
|
871
|
+
let minY;
|
|
872
|
+
let x2;
|
|
873
|
+
let y2;
|
|
874
|
+
if (hasHoles)
|
|
875
|
+
outerNode = eliminateHoles(positions, holeIndices, outerNode, dim, areas, plane);
|
|
876
|
+
if (positions.length > 80 * dim) {
|
|
877
|
+
minX = maxX = positions[0];
|
|
878
|
+
minY = maxY = positions[1];
|
|
879
|
+
for (let i2 = dim; i2 < outerLen; i2 += dim) {
|
|
880
|
+
x2 = positions[i2];
|
|
881
|
+
y2 = positions[i2 + 1];
|
|
882
|
+
if (x2 < minX)
|
|
883
|
+
minX = x2;
|
|
884
|
+
if (y2 < minY)
|
|
885
|
+
minY = y2;
|
|
886
|
+
if (x2 > maxX)
|
|
887
|
+
maxX = x2;
|
|
888
|
+
if (y2 > maxY)
|
|
889
|
+
maxY = y2;
|
|
890
|
+
}
|
|
891
|
+
invSize = Math.max(maxX - minX, maxY - minY);
|
|
892
|
+
invSize = invSize !== 0 ? 32767 / invSize : 0;
|
|
893
|
+
}
|
|
894
|
+
earcutLinked(outerNode, triangles, dim, minX, minY, invSize, 0);
|
|
895
|
+
return triangles;
|
|
896
|
+
}
|
|
897
|
+
function linkedList(data, start, end, dim, clockwise, area2, plane) {
|
|
898
|
+
let i2;
|
|
899
|
+
let last;
|
|
900
|
+
if (area2 === void 0) {
|
|
901
|
+
area2 = getPolygonSignedArea(data, {
|
|
902
|
+
start,
|
|
903
|
+
end,
|
|
904
|
+
size: dim,
|
|
905
|
+
plane
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
let i0 = DimIndex[plane[0]];
|
|
909
|
+
let i1 = DimIndex[plane[1]];
|
|
910
|
+
if (clockwise === area2 < 0) {
|
|
911
|
+
for (i2 = start; i2 < end; i2 += dim)
|
|
912
|
+
last = insertNode(i2, data[i2 + i0], data[i2 + i1], last);
|
|
913
|
+
} else {
|
|
914
|
+
for (i2 = end - dim; i2 >= start; i2 -= dim)
|
|
915
|
+
last = insertNode(i2, data[i2 + i0], data[i2 + i1], last);
|
|
916
|
+
}
|
|
917
|
+
if (last && equals(last, last.next)) {
|
|
918
|
+
removeNode(last);
|
|
919
|
+
last = last.next;
|
|
920
|
+
}
|
|
921
|
+
return last;
|
|
922
|
+
}
|
|
923
|
+
function filterPoints(start, end) {
|
|
924
|
+
if (!start)
|
|
925
|
+
return start;
|
|
926
|
+
if (!end)
|
|
927
|
+
end = start;
|
|
928
|
+
let p = start;
|
|
929
|
+
let again;
|
|
930
|
+
do {
|
|
931
|
+
again = false;
|
|
932
|
+
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
|
|
933
|
+
removeNode(p);
|
|
934
|
+
p = end = p.prev;
|
|
935
|
+
if (p === p.next)
|
|
936
|
+
break;
|
|
937
|
+
again = true;
|
|
938
|
+
} else {
|
|
939
|
+
p = p.next;
|
|
940
|
+
}
|
|
941
|
+
} while (again || p !== end);
|
|
942
|
+
return end;
|
|
943
|
+
}
|
|
944
|
+
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
|
945
|
+
if (!ear)
|
|
946
|
+
return;
|
|
947
|
+
if (!pass && invSize)
|
|
948
|
+
indexCurve(ear, minX, minY, invSize);
|
|
949
|
+
let stop = ear;
|
|
950
|
+
let prev;
|
|
951
|
+
let next;
|
|
952
|
+
while (ear.prev !== ear.next) {
|
|
953
|
+
prev = ear.prev;
|
|
954
|
+
next = ear.next;
|
|
955
|
+
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
|
956
|
+
triangles.push(prev.i / dim | 0);
|
|
957
|
+
triangles.push(ear.i / dim | 0);
|
|
958
|
+
triangles.push(next.i / dim | 0);
|
|
959
|
+
removeNode(ear);
|
|
960
|
+
ear = next.next;
|
|
961
|
+
stop = next.next;
|
|
962
|
+
continue;
|
|
963
|
+
}
|
|
964
|
+
ear = next;
|
|
965
|
+
if (ear === stop) {
|
|
966
|
+
if (!pass) {
|
|
967
|
+
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
|
|
968
|
+
} else if (pass === 1) {
|
|
969
|
+
ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
|
|
970
|
+
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
|
|
971
|
+
} else if (pass === 2) {
|
|
972
|
+
splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
|
973
|
+
}
|
|
974
|
+
break;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
function isEar(ear) {
|
|
979
|
+
const a = ear.prev;
|
|
980
|
+
const b = ear;
|
|
981
|
+
const c = ear.next;
|
|
982
|
+
if (area(a, b, c) >= 0)
|
|
983
|
+
return false;
|
|
984
|
+
const ax = a.x;
|
|
985
|
+
const bx = b.x;
|
|
986
|
+
const cx = c.x;
|
|
987
|
+
const ay = a.y;
|
|
988
|
+
const by = b.y;
|
|
989
|
+
const cy = c.y;
|
|
990
|
+
const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx;
|
|
991
|
+
const y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy;
|
|
992
|
+
const x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx;
|
|
993
|
+
const y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
|
|
994
|
+
let p = c.next;
|
|
995
|
+
while (p !== a) {
|
|
996
|
+
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
997
|
+
return false;
|
|
998
|
+
p = p.next;
|
|
999
|
+
}
|
|
1000
|
+
return true;
|
|
1001
|
+
}
|
|
1002
|
+
function isEarHashed(ear, minX, minY, invSize) {
|
|
1003
|
+
const a = ear.prev;
|
|
1004
|
+
const b = ear;
|
|
1005
|
+
const c = ear.next;
|
|
1006
|
+
if (area(a, b, c) >= 0)
|
|
1007
|
+
return false;
|
|
1008
|
+
const ax = a.x;
|
|
1009
|
+
const bx = b.x;
|
|
1010
|
+
const cx = c.x;
|
|
1011
|
+
const ay = a.y;
|
|
1012
|
+
const by = b.y;
|
|
1013
|
+
const cy = c.y;
|
|
1014
|
+
const x0 = ax < bx ? ax < cx ? ax : cx : bx < cx ? bx : cx;
|
|
1015
|
+
const y0 = ay < by ? ay < cy ? ay : cy : by < cy ? by : cy;
|
|
1016
|
+
const x1 = ax > bx ? ax > cx ? ax : cx : bx > cx ? bx : cx;
|
|
1017
|
+
const y1 = ay > by ? ay > cy ? ay : cy : by > cy ? by : cy;
|
|
1018
|
+
const minZ = zOrder(x0, y0, minX, minY, invSize);
|
|
1019
|
+
const maxZ = zOrder(x1, y1, minX, minY, invSize);
|
|
1020
|
+
let p = ear.prevZ;
|
|
1021
|
+
let n = ear.nextZ;
|
|
1022
|
+
while (p && p.z >= minZ && n && n.z <= maxZ) {
|
|
1023
|
+
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
1024
|
+
return false;
|
|
1025
|
+
p = p.prevZ;
|
|
1026
|
+
if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
1027
|
+
return false;
|
|
1028
|
+
n = n.nextZ;
|
|
1029
|
+
}
|
|
1030
|
+
while (p && p.z >= minZ) {
|
|
1031
|
+
if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
|
|
1032
|
+
return false;
|
|
1033
|
+
p = p.prevZ;
|
|
1034
|
+
}
|
|
1035
|
+
while (n && n.z <= maxZ) {
|
|
1036
|
+
if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
|
|
1037
|
+
return false;
|
|
1038
|
+
n = n.nextZ;
|
|
1039
|
+
}
|
|
1040
|
+
return true;
|
|
1041
|
+
}
|
|
1042
|
+
function cureLocalIntersections(start, triangles, dim) {
|
|
1043
|
+
let p = start;
|
|
1044
|
+
do {
|
|
1045
|
+
const a = p.prev;
|
|
1046
|
+
const b = p.next.next;
|
|
1047
|
+
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
|
1048
|
+
triangles.push(a.i / dim | 0);
|
|
1049
|
+
triangles.push(p.i / dim | 0);
|
|
1050
|
+
triangles.push(b.i / dim | 0);
|
|
1051
|
+
removeNode(p);
|
|
1052
|
+
removeNode(p.next);
|
|
1053
|
+
p = start = b;
|
|
1485
1054
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1055
|
+
p = p.next;
|
|
1056
|
+
} while (p !== start);
|
|
1057
|
+
return filterPoints(p);
|
|
1058
|
+
}
|
|
1059
|
+
function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
|
1060
|
+
let a = start;
|
|
1061
|
+
do {
|
|
1062
|
+
let b = a.next.next;
|
|
1063
|
+
while (b !== a.prev) {
|
|
1064
|
+
if (a.i !== b.i && isValidDiagonal(a, b)) {
|
|
1065
|
+
let c = splitPolygon(a, b);
|
|
1066
|
+
a = filterPoints(a, a.next);
|
|
1067
|
+
c = filterPoints(c, c.next);
|
|
1068
|
+
earcutLinked(a, triangles, dim, minX, minY, invSize, 0);
|
|
1069
|
+
earcutLinked(c, triangles, dim, minX, minY, invSize, 0);
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
b = b.next;
|
|
1488
1073
|
}
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1074
|
+
a = a.next;
|
|
1075
|
+
} while (a !== start);
|
|
1076
|
+
}
|
|
1077
|
+
function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
|
|
1078
|
+
const queue = [];
|
|
1079
|
+
let i2;
|
|
1080
|
+
let len;
|
|
1081
|
+
let start;
|
|
1082
|
+
let end;
|
|
1083
|
+
let list;
|
|
1084
|
+
for (i2 = 0, len = holeIndices.length; i2 < len; i2++) {
|
|
1085
|
+
start = holeIndices[i2] * dim;
|
|
1086
|
+
end = i2 < len - 1 ? holeIndices[i2 + 1] * dim : data.length;
|
|
1087
|
+
list = linkedList(data, start, end, dim, false, areas && areas[i2 + 1], plane);
|
|
1088
|
+
if (list === list.next)
|
|
1089
|
+
list.steiner = true;
|
|
1090
|
+
queue.push(getLeftmost(list));
|
|
1091
|
+
}
|
|
1092
|
+
queue.sort(compareX);
|
|
1093
|
+
for (i2 = 0; i2 < queue.length; i2++) {
|
|
1094
|
+
outerNode = eliminateHole(queue[i2], outerNode);
|
|
1095
|
+
}
|
|
1096
|
+
return outerNode;
|
|
1097
|
+
}
|
|
1098
|
+
function compareX(a, b) {
|
|
1099
|
+
return a.x - b.x;
|
|
1100
|
+
}
|
|
1101
|
+
function eliminateHole(hole, outerNode) {
|
|
1102
|
+
const bridge = findHoleBridge(hole, outerNode);
|
|
1103
|
+
if (!bridge) {
|
|
1104
|
+
return outerNode;
|
|
1105
|
+
}
|
|
1106
|
+
const bridgeReverse = splitPolygon(bridge, hole);
|
|
1107
|
+
filterPoints(bridgeReverse, bridgeReverse.next);
|
|
1108
|
+
return filterPoints(bridge, bridge.next);
|
|
1109
|
+
}
|
|
1110
|
+
function findHoleBridge(hole, outerNode) {
|
|
1111
|
+
let p = outerNode;
|
|
1112
|
+
const hx = hole.x;
|
|
1113
|
+
const hy = hole.y;
|
|
1114
|
+
let qx = -Infinity;
|
|
1115
|
+
let m;
|
|
1116
|
+
do {
|
|
1117
|
+
if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
|
|
1118
|
+
const x2 = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
|
|
1119
|
+
if (x2 <= hx && x2 > qx) {
|
|
1120
|
+
qx = x2;
|
|
1121
|
+
m = p.x < p.next.x ? p : p.next;
|
|
1122
|
+
if (x2 === hx)
|
|
1123
|
+
return m;
|
|
1124
|
+
}
|
|
1494
1125
|
}
|
|
1495
|
-
|
|
1496
|
-
|
|
1126
|
+
p = p.next;
|
|
1127
|
+
} while (p !== outerNode);
|
|
1128
|
+
if (!m)
|
|
1129
|
+
return null;
|
|
1130
|
+
const stop = m;
|
|
1131
|
+
const mx = m.x;
|
|
1132
|
+
const my = m.y;
|
|
1133
|
+
let tanMin = Infinity;
|
|
1134
|
+
let tan;
|
|
1135
|
+
p = m;
|
|
1136
|
+
do {
|
|
1137
|
+
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)) {
|
|
1138
|
+
tan = Math.abs(hy - p.y) / (hx - p.x);
|
|
1139
|
+
if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
|
|
1140
|
+
m = p;
|
|
1141
|
+
tanMin = tan;
|
|
1142
|
+
}
|
|
1497
1143
|
}
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1144
|
+
p = p.next;
|
|
1145
|
+
} while (p !== stop);
|
|
1146
|
+
return m;
|
|
1147
|
+
}
|
|
1148
|
+
function sectorContainsSector(m, p) {
|
|
1149
|
+
return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
|
|
1150
|
+
}
|
|
1151
|
+
function indexCurve(start, minX, minY, invSize) {
|
|
1152
|
+
let p = start;
|
|
1153
|
+
do {
|
|
1154
|
+
if (p.z === 0)
|
|
1155
|
+
p.z = zOrder(p.x, p.y, minX, minY, invSize);
|
|
1156
|
+
p.prevZ = p.prev;
|
|
1157
|
+
p.nextZ = p.next;
|
|
1158
|
+
p = p.next;
|
|
1159
|
+
} while (p !== start);
|
|
1160
|
+
p.prevZ.nextZ = null;
|
|
1161
|
+
p.prevZ = null;
|
|
1162
|
+
sortLinked(p);
|
|
1163
|
+
}
|
|
1164
|
+
function sortLinked(list) {
|
|
1165
|
+
let e;
|
|
1166
|
+
let i2;
|
|
1167
|
+
let inSize = 1;
|
|
1168
|
+
let numMerges;
|
|
1169
|
+
let p;
|
|
1170
|
+
let pSize;
|
|
1171
|
+
let q;
|
|
1172
|
+
let qSize;
|
|
1173
|
+
let tail;
|
|
1174
|
+
do {
|
|
1175
|
+
p = list;
|
|
1176
|
+
list = null;
|
|
1177
|
+
tail = null;
|
|
1178
|
+
numMerges = 0;
|
|
1179
|
+
while (p) {
|
|
1180
|
+
numMerges++;
|
|
1181
|
+
q = p;
|
|
1182
|
+
pSize = 0;
|
|
1183
|
+
for (i2 = 0; i2 < inSize; i2++) {
|
|
1184
|
+
pSize++;
|
|
1185
|
+
q = q.nextZ;
|
|
1186
|
+
if (!q)
|
|
1506
1187
|
break;
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
|
-
} else if (bytesPerSequence === 3) {
|
|
1521
|
-
b1 = buf[i2 + 1];
|
|
1522
|
-
b2 = buf[i2 + 2];
|
|
1523
|
-
if ((b1 & 192) === 128 && (b2 & 192) === 128) {
|
|
1524
|
-
c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63;
|
|
1525
|
-
if (c <= 2047 || c >= 55296 && c <= 57343) {
|
|
1526
|
-
c = null;
|
|
1527
|
-
}
|
|
1528
|
-
}
|
|
1529
|
-
} else if (bytesPerSequence === 4) {
|
|
1530
|
-
b1 = buf[i2 + 1];
|
|
1531
|
-
b2 = buf[i2 + 2];
|
|
1532
|
-
b3 = buf[i2 + 3];
|
|
1533
|
-
if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) {
|
|
1534
|
-
c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
|
|
1535
|
-
if (c <= 65535 || c >= 1114112) {
|
|
1536
|
-
c = null;
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
if (c === null) {
|
|
1541
|
-
c = 65533;
|
|
1542
|
-
bytesPerSequence = 1;
|
|
1543
|
-
} else if (c > 65535) {
|
|
1544
|
-
c -= 65536;
|
|
1545
|
-
str += String.fromCharCode(c >>> 10 & 1023 | 55296);
|
|
1546
|
-
c = 56320 | c & 1023;
|
|
1188
|
+
}
|
|
1189
|
+
qSize = inSize;
|
|
1190
|
+
while (pSize > 0 || qSize > 0 && q) {
|
|
1191
|
+
if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
|
|
1192
|
+
e = p;
|
|
1193
|
+
p = p.nextZ;
|
|
1194
|
+
pSize--;
|
|
1195
|
+
} else {
|
|
1196
|
+
e = q;
|
|
1197
|
+
q = q.nextZ;
|
|
1198
|
+
qSize--;
|
|
1547
1199
|
}
|
|
1548
|
-
|
|
1549
|
-
|
|
1200
|
+
if (tail)
|
|
1201
|
+
tail.nextZ = e;
|
|
1202
|
+
else
|
|
1203
|
+
list = e;
|
|
1204
|
+
e.prevZ = tail;
|
|
1205
|
+
tail = e;
|
|
1206
|
+
}
|
|
1207
|
+
p = q;
|
|
1208
|
+
}
|
|
1209
|
+
tail.nextZ = null;
|
|
1210
|
+
inSize *= 2;
|
|
1211
|
+
} while (numMerges > 1);
|
|
1212
|
+
return list;
|
|
1213
|
+
}
|
|
1214
|
+
function zOrder(x2, y2, minX, minY, invSize) {
|
|
1215
|
+
x2 = (x2 - minX) * invSize | 0;
|
|
1216
|
+
y2 = (y2 - minY) * invSize | 0;
|
|
1217
|
+
x2 = (x2 | x2 << 8) & 16711935;
|
|
1218
|
+
x2 = (x2 | x2 << 4) & 252645135;
|
|
1219
|
+
x2 = (x2 | x2 << 2) & 858993459;
|
|
1220
|
+
x2 = (x2 | x2 << 1) & 1431655765;
|
|
1221
|
+
y2 = (y2 | y2 << 8) & 16711935;
|
|
1222
|
+
y2 = (y2 | y2 << 4) & 252645135;
|
|
1223
|
+
y2 = (y2 | y2 << 2) & 858993459;
|
|
1224
|
+
y2 = (y2 | y2 << 1) & 1431655765;
|
|
1225
|
+
return x2 | y2 << 1;
|
|
1226
|
+
}
|
|
1227
|
+
function getLeftmost(start) {
|
|
1228
|
+
let p = start;
|
|
1229
|
+
let leftmost = start;
|
|
1230
|
+
do {
|
|
1231
|
+
if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
|
|
1232
|
+
leftmost = p;
|
|
1233
|
+
p = p.next;
|
|
1234
|
+
} while (p !== start);
|
|
1235
|
+
return leftmost;
|
|
1236
|
+
}
|
|
1237
|
+
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
|
|
1238
|
+
return (cx - px) * (ay - py) >= (ax - px) * (cy - py) && (ax - px) * (by - py) >= (bx - px) * (ay - py) && (bx - px) * (cy - py) >= (cx - px) * (by - py);
|
|
1239
|
+
}
|
|
1240
|
+
function isValidDiagonal(a, b) {
|
|
1241
|
+
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);
|
|
1242
|
+
}
|
|
1243
|
+
function area(p, q, r) {
|
|
1244
|
+
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
|
1245
|
+
}
|
|
1246
|
+
function equals(p1, p2) {
|
|
1247
|
+
return p1.x === p2.x && p1.y === p2.y;
|
|
1248
|
+
}
|
|
1249
|
+
function intersects(p1, q1, p2, q2) {
|
|
1250
|
+
const o1 = sign(area(p1, q1, p2));
|
|
1251
|
+
const o2 = sign(area(p1, q1, q2));
|
|
1252
|
+
const o3 = sign(area(p2, q2, p1));
|
|
1253
|
+
const o4 = sign(area(p2, q2, q1));
|
|
1254
|
+
if (o1 !== o2 && o3 !== o4)
|
|
1255
|
+
return true;
|
|
1256
|
+
if (o1 === 0 && onSegment(p1, p2, q1))
|
|
1257
|
+
return true;
|
|
1258
|
+
if (o2 === 0 && onSegment(p1, q2, q1))
|
|
1259
|
+
return true;
|
|
1260
|
+
if (o3 === 0 && onSegment(p2, p1, q2))
|
|
1261
|
+
return true;
|
|
1262
|
+
if (o4 === 0 && onSegment(p2, q1, q2))
|
|
1263
|
+
return true;
|
|
1264
|
+
return false;
|
|
1265
|
+
}
|
|
1266
|
+
function onSegment(p, q, r) {
|
|
1267
|
+
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);
|
|
1268
|
+
}
|
|
1269
|
+
function sign(num) {
|
|
1270
|
+
return num > 0 ? 1 : num < 0 ? -1 : 0;
|
|
1271
|
+
}
|
|
1272
|
+
function intersectsPolygon(a, b) {
|
|
1273
|
+
let p = a;
|
|
1274
|
+
do {
|
|
1275
|
+
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))
|
|
1276
|
+
return true;
|
|
1277
|
+
p = p.next;
|
|
1278
|
+
} while (p !== a);
|
|
1279
|
+
return false;
|
|
1280
|
+
}
|
|
1281
|
+
function locallyInside(a, b) {
|
|
1282
|
+
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;
|
|
1283
|
+
}
|
|
1284
|
+
function middleInside(a, b) {
|
|
1285
|
+
let p = a;
|
|
1286
|
+
let inside = false;
|
|
1287
|
+
const px = (a.x + b.x) / 2;
|
|
1288
|
+
const py = (a.y + b.y) / 2;
|
|
1289
|
+
do {
|
|
1290
|
+
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)
|
|
1291
|
+
inside = !inside;
|
|
1292
|
+
p = p.next;
|
|
1293
|
+
} while (p !== a);
|
|
1294
|
+
return inside;
|
|
1295
|
+
}
|
|
1296
|
+
function splitPolygon(a, b) {
|
|
1297
|
+
const a2 = new Vertex(a.i, a.x, a.y);
|
|
1298
|
+
const b2 = new Vertex(b.i, b.x, b.y);
|
|
1299
|
+
const an = a.next;
|
|
1300
|
+
const bp = b.prev;
|
|
1301
|
+
a.next = b;
|
|
1302
|
+
b.prev = a;
|
|
1303
|
+
a2.next = an;
|
|
1304
|
+
an.prev = a2;
|
|
1305
|
+
b2.next = a2;
|
|
1306
|
+
a2.prev = b2;
|
|
1307
|
+
bp.next = b2;
|
|
1308
|
+
b2.prev = bp;
|
|
1309
|
+
return b2;
|
|
1310
|
+
}
|
|
1311
|
+
function insertNode(i2, x2, y2, last) {
|
|
1312
|
+
const p = new Vertex(i2, x2, y2);
|
|
1313
|
+
if (!last) {
|
|
1314
|
+
p.prev = p;
|
|
1315
|
+
p.next = p;
|
|
1316
|
+
} else {
|
|
1317
|
+
p.next = last.next;
|
|
1318
|
+
p.prev = last;
|
|
1319
|
+
last.next.prev = p;
|
|
1320
|
+
last.next = p;
|
|
1321
|
+
}
|
|
1322
|
+
return p;
|
|
1323
|
+
}
|
|
1324
|
+
function removeNode(p) {
|
|
1325
|
+
p.next.prev = p.prev;
|
|
1326
|
+
p.prev.next = p.next;
|
|
1327
|
+
if (p.prevZ)
|
|
1328
|
+
p.prevZ.nextZ = p.nextZ;
|
|
1329
|
+
if (p.nextZ)
|
|
1330
|
+
p.nextZ.prevZ = p.prevZ;
|
|
1331
|
+
}
|
|
1332
|
+
var Vertex = class {
|
|
1333
|
+
constructor(i2, x2, y2) {
|
|
1334
|
+
_defineProperty(this, "i", void 0);
|
|
1335
|
+
_defineProperty(this, "x", void 0);
|
|
1336
|
+
_defineProperty(this, "y", void 0);
|
|
1337
|
+
_defineProperty(this, "prev", null);
|
|
1338
|
+
_defineProperty(this, "next", null);
|
|
1339
|
+
_defineProperty(this, "z", 0);
|
|
1340
|
+
_defineProperty(this, "prevZ", null);
|
|
1341
|
+
_defineProperty(this, "nextZ", null);
|
|
1342
|
+
_defineProperty(this, "steiner", false);
|
|
1343
|
+
this.i = i2;
|
|
1344
|
+
this.x = x2;
|
|
1345
|
+
this.y = y2;
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1349
|
+
// ../gis/src/lib/flat-geojson-to-binary.ts
|
|
1350
|
+
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
1351
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
1352
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1353
|
+
return fillArrays(features, {
|
|
1354
|
+
propArrayTypes,
|
|
1355
|
+
...geometryInfo
|
|
1356
|
+
}, {
|
|
1357
|
+
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
1358
|
+
PositionDataType: options ? options.PositionDataType : Float32Array,
|
|
1359
|
+
triangulate: options ? options.triangulate : true
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
function extractNumericPropTypes(features) {
|
|
1363
|
+
const propArrayTypes = {};
|
|
1364
|
+
for (const feature of features) {
|
|
1365
|
+
if (feature.properties) {
|
|
1366
|
+
for (const key in feature.properties) {
|
|
1367
|
+
const val = feature.properties[key];
|
|
1368
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
1550
1369
|
}
|
|
1551
|
-
return str;
|
|
1552
1370
|
}
|
|
1553
|
-
|
|
1554
|
-
|
|
1371
|
+
}
|
|
1372
|
+
return propArrayTypes;
|
|
1373
|
+
}
|
|
1374
|
+
function fillArrays(features, geometryInfo, options) {
|
|
1375
|
+
const {
|
|
1376
|
+
pointPositionsCount,
|
|
1377
|
+
pointFeaturesCount,
|
|
1378
|
+
linePositionsCount,
|
|
1379
|
+
linePathsCount,
|
|
1380
|
+
lineFeaturesCount,
|
|
1381
|
+
polygonPositionsCount,
|
|
1382
|
+
polygonObjectsCount,
|
|
1383
|
+
polygonRingsCount,
|
|
1384
|
+
polygonFeaturesCount,
|
|
1385
|
+
propArrayTypes,
|
|
1386
|
+
coordLength
|
|
1387
|
+
} = geometryInfo;
|
|
1388
|
+
const {
|
|
1389
|
+
numericPropKeys = [],
|
|
1390
|
+
PositionDataType = Float32Array,
|
|
1391
|
+
triangulate = true
|
|
1392
|
+
} = options;
|
|
1393
|
+
const hasGlobalId = features[0] && "id" in features[0];
|
|
1394
|
+
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
1395
|
+
const points = {
|
|
1396
|
+
type: "Point",
|
|
1397
|
+
positions: new PositionDataType(pointPositionsCount * coordLength),
|
|
1398
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
|
|
1399
|
+
featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
|
|
1400
|
+
numericProps: {},
|
|
1401
|
+
properties: [],
|
|
1402
|
+
fields: []
|
|
1403
|
+
};
|
|
1404
|
+
const lines = {
|
|
1405
|
+
type: "LineString",
|
|
1406
|
+
pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
|
|
1407
|
+
positions: new PositionDataType(linePositionsCount * coordLength),
|
|
1408
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
|
|
1409
|
+
featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
|
|
1410
|
+
numericProps: {},
|
|
1411
|
+
properties: [],
|
|
1412
|
+
fields: []
|
|
1413
|
+
};
|
|
1414
|
+
const polygons = {
|
|
1415
|
+
type: "Polygon",
|
|
1416
|
+
polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
|
|
1417
|
+
primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
|
|
1418
|
+
positions: new PositionDataType(polygonPositionsCount * coordLength),
|
|
1419
|
+
globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
|
|
1420
|
+
featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
|
|
1421
|
+
numericProps: {},
|
|
1422
|
+
properties: [],
|
|
1423
|
+
fields: []
|
|
1424
|
+
};
|
|
1425
|
+
if (triangulate) {
|
|
1426
|
+
polygons.triangles = [];
|
|
1427
|
+
}
|
|
1428
|
+
for (const object of [points, lines, polygons]) {
|
|
1429
|
+
for (const propName of numericPropKeys) {
|
|
1430
|
+
const T = propArrayTypes[propName];
|
|
1431
|
+
object.numericProps[propName] = new T(object.positions.length / coordLength);
|
|
1555
1432
|
}
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1433
|
+
}
|
|
1434
|
+
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
1435
|
+
polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
|
|
1436
|
+
polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
|
|
1437
|
+
const indexMap = {
|
|
1438
|
+
pointPosition: 0,
|
|
1439
|
+
pointFeature: 0,
|
|
1440
|
+
linePosition: 0,
|
|
1441
|
+
linePath: 0,
|
|
1442
|
+
lineFeature: 0,
|
|
1443
|
+
polygonPosition: 0,
|
|
1444
|
+
polygonObject: 0,
|
|
1445
|
+
polygonRing: 0,
|
|
1446
|
+
polygonFeature: 0,
|
|
1447
|
+
feature: 0
|
|
1448
|
+
};
|
|
1449
|
+
for (const feature of features) {
|
|
1450
|
+
const geometry = feature.geometry;
|
|
1451
|
+
const properties = feature.properties || {};
|
|
1452
|
+
switch (geometry.type) {
|
|
1453
|
+
case "Point":
|
|
1454
|
+
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
1455
|
+
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1456
|
+
if (hasGlobalId) {
|
|
1457
|
+
points.fields.push({
|
|
1458
|
+
id: feature.id
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
indexMap.pointFeature++;
|
|
1462
|
+
break;
|
|
1463
|
+
case "LineString":
|
|
1464
|
+
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
1465
|
+
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1466
|
+
if (hasGlobalId) {
|
|
1467
|
+
lines.fields.push({
|
|
1468
|
+
id: feature.id
|
|
1469
|
+
});
|
|
1586
1470
|
}
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
buf[pos++] = c >> 18 | 240;
|
|
1597
|
-
buf[pos++] = c >> 12 & 63 | 128;
|
|
1598
|
-
}
|
|
1599
|
-
buf[pos++] = c >> 6 & 63 | 128;
|
|
1600
|
-
}
|
|
1601
|
-
buf[pos++] = c & 63 | 128;
|
|
1471
|
+
indexMap.lineFeature++;
|
|
1472
|
+
break;
|
|
1473
|
+
case "Polygon":
|
|
1474
|
+
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
1475
|
+
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
1476
|
+
if (hasGlobalId) {
|
|
1477
|
+
polygons.fields.push({
|
|
1478
|
+
id: feature.id
|
|
1479
|
+
});
|
|
1602
1480
|
}
|
|
1603
|
-
|
|
1604
|
-
|
|
1481
|
+
indexMap.polygonFeature++;
|
|
1482
|
+
break;
|
|
1483
|
+
default:
|
|
1484
|
+
throw new Error("Invalid geometry type");
|
|
1605
1485
|
}
|
|
1486
|
+
indexMap.feature++;
|
|
1606
1487
|
}
|
|
1607
|
-
|
|
1488
|
+
return makeAccessorObjects(points, lines, polygons, coordLength);
|
|
1489
|
+
}
|
|
1490
|
+
function handlePoint(geometry, points, indexMap, coordLength, properties) {
|
|
1491
|
+
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
1492
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1493
|
+
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
1494
|
+
points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1495
|
+
points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
|
|
1496
|
+
indexMap.pointPosition += nPositions;
|
|
1497
|
+
}
|
|
1498
|
+
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
1499
|
+
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
1500
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1501
|
+
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
1502
|
+
lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1503
|
+
lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
|
|
1504
|
+
for (let i2 = 0, il = geometry.indices.length; i2 < il; ++i2) {
|
|
1505
|
+
const start = geometry.indices[i2];
|
|
1506
|
+
const end = i2 === il - 1 ? geometry.data.length : geometry.indices[i2 + 1];
|
|
1507
|
+
lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
|
|
1508
|
+
indexMap.linePosition += (end - start) / coordLength;
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
|
|
1512
|
+
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
1513
|
+
const nPositions = geometry.data.length / coordLength;
|
|
1514
|
+
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
1515
|
+
polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1516
|
+
polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
|
|
1517
|
+
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
1518
|
+
const startPosition = indexMap.polygonPosition;
|
|
1519
|
+
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
1520
|
+
const areas = geometry.areas[l];
|
|
1521
|
+
const indices = geometry.indices[l];
|
|
1522
|
+
const nextIndices = geometry.indices[l + 1];
|
|
1523
|
+
for (let i2 = 0, il = indices.length; i2 < il; ++i2) {
|
|
1524
|
+
const start = indices[i2];
|
|
1525
|
+
const end = i2 === il - 1 ? (
|
|
1526
|
+
// last line, so either read to:
|
|
1527
|
+
nextIndices === void 0 ? geometry.data.length : nextIndices[0]
|
|
1528
|
+
) : indices[i2 + 1];
|
|
1529
|
+
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
1530
|
+
indexMap.polygonPosition += (end - start) / coordLength;
|
|
1531
|
+
}
|
|
1532
|
+
const endPosition = indexMap.polygonPosition;
|
|
1533
|
+
triangulatePolygon(polygons, areas, indices, {
|
|
1534
|
+
startPosition,
|
|
1535
|
+
endPosition,
|
|
1536
|
+
coordLength
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
function triangulatePolygon(polygons, areas, indices, {
|
|
1541
|
+
startPosition,
|
|
1542
|
+
endPosition,
|
|
1543
|
+
coordLength
|
|
1544
|
+
}) {
|
|
1545
|
+
if (!polygons.triangles) {
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
const start = startPosition * coordLength;
|
|
1549
|
+
const end = endPosition * coordLength;
|
|
1550
|
+
const polygonPositions = polygons.positions.subarray(start, end);
|
|
1551
|
+
const offset = indices[0];
|
|
1552
|
+
const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
|
|
1553
|
+
const triangles = earcut(polygonPositions, holes, coordLength, areas);
|
|
1554
|
+
for (let t = 0, tl = triangles.length; t < tl; ++t) {
|
|
1555
|
+
polygons.triangles.push(startPosition + triangles[t]);
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
function wrapProps(obj, size) {
|
|
1559
|
+
const returnObj = {};
|
|
1560
|
+
for (const key in obj) {
|
|
1561
|
+
returnObj[key] = {
|
|
1562
|
+
value: obj[key],
|
|
1563
|
+
size
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
return returnObj;
|
|
1567
|
+
}
|
|
1568
|
+
function makeAccessorObjects(points, lines, polygons, coordLength) {
|
|
1569
|
+
const binaryFeatures = {
|
|
1570
|
+
points: {
|
|
1571
|
+
...points,
|
|
1572
|
+
positions: {
|
|
1573
|
+
value: points.positions,
|
|
1574
|
+
size: coordLength
|
|
1575
|
+
},
|
|
1576
|
+
globalFeatureIds: {
|
|
1577
|
+
value: points.globalFeatureIds,
|
|
1578
|
+
size: 1
|
|
1579
|
+
},
|
|
1580
|
+
featureIds: {
|
|
1581
|
+
value: points.featureIds,
|
|
1582
|
+
size: 1
|
|
1583
|
+
},
|
|
1584
|
+
numericProps: wrapProps(points.numericProps, 1)
|
|
1585
|
+
},
|
|
1586
|
+
lines: {
|
|
1587
|
+
...lines,
|
|
1588
|
+
positions: {
|
|
1589
|
+
value: lines.positions,
|
|
1590
|
+
size: coordLength
|
|
1591
|
+
},
|
|
1592
|
+
pathIndices: {
|
|
1593
|
+
value: lines.pathIndices,
|
|
1594
|
+
size: 1
|
|
1595
|
+
},
|
|
1596
|
+
globalFeatureIds: {
|
|
1597
|
+
value: lines.globalFeatureIds,
|
|
1598
|
+
size: 1
|
|
1599
|
+
},
|
|
1600
|
+
featureIds: {
|
|
1601
|
+
value: lines.featureIds,
|
|
1602
|
+
size: 1
|
|
1603
|
+
},
|
|
1604
|
+
numericProps: wrapProps(lines.numericProps, 1)
|
|
1605
|
+
},
|
|
1606
|
+
polygons: {
|
|
1607
|
+
...polygons,
|
|
1608
|
+
positions: {
|
|
1609
|
+
value: polygons.positions,
|
|
1610
|
+
size: coordLength
|
|
1611
|
+
},
|
|
1612
|
+
polygonIndices: {
|
|
1613
|
+
value: polygons.polygonIndices,
|
|
1614
|
+
size: 1
|
|
1615
|
+
},
|
|
1616
|
+
primitivePolygonIndices: {
|
|
1617
|
+
value: polygons.primitivePolygonIndices,
|
|
1618
|
+
size: 1
|
|
1619
|
+
},
|
|
1620
|
+
globalFeatureIds: {
|
|
1621
|
+
value: polygons.globalFeatureIds,
|
|
1622
|
+
size: 1
|
|
1623
|
+
},
|
|
1624
|
+
featureIds: {
|
|
1625
|
+
value: polygons.featureIds,
|
|
1626
|
+
size: 1
|
|
1627
|
+
},
|
|
1628
|
+
numericProps: wrapProps(polygons.numericProps, 1)
|
|
1629
|
+
}
|
|
1630
|
+
// triangles not expected
|
|
1631
|
+
};
|
|
1632
|
+
if (binaryFeatures.polygons && polygons.triangles) {
|
|
1633
|
+
binaryFeatures.polygons.triangles = {
|
|
1634
|
+
value: new Uint32Array(polygons.triangles),
|
|
1635
|
+
size: 1
|
|
1636
|
+
};
|
|
1637
|
+
}
|
|
1638
|
+
return binaryFeatures;
|
|
1639
|
+
}
|
|
1640
|
+
function fillNumericProperties(object, properties, index, length2) {
|
|
1641
|
+
for (const numericPropName in object.numericProps) {
|
|
1642
|
+
if (numericPropName in properties) {
|
|
1643
|
+
const value = properties[numericPropName];
|
|
1644
|
+
object.numericProps[numericPropName].fill(value, index, index + length2);
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
function keepStringProperties(properties, numericKeys) {
|
|
1649
|
+
const props = {};
|
|
1650
|
+
for (const key in properties) {
|
|
1651
|
+
if (!numericKeys.includes(key)) {
|
|
1652
|
+
props[key] = properties[key];
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
return props;
|
|
1656
|
+
}
|
|
1657
|
+
function deduceArrayType(x2, constructor) {
|
|
1658
|
+
if (constructor === Array || !Number.isFinite(x2)) {
|
|
1659
|
+
return Array;
|
|
1660
|
+
}
|
|
1661
|
+
return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
// src/lib/parse-mvt.ts
|
|
1665
|
+
var import_pbf = __toESM(require_pbf(), 1);
|
|
1608
1666
|
|
|
1609
1667
|
// src/helpers/mapbox-util-functions.ts
|
|
1610
1668
|
function classifyRings(rings) {
|
|
@@ -1660,175 +1718,198 @@
|
|
|
1660
1718
|
feature.properties[key] = value;
|
|
1661
1719
|
}
|
|
1662
1720
|
}
|
|
1663
|
-
var init_mapbox_util_functions = __esm({
|
|
1664
|
-
"src/helpers/mapbox-util-functions.ts"() {
|
|
1665
|
-
}
|
|
1666
|
-
});
|
|
1667
1721
|
|
|
1668
1722
|
// src/lib/mapbox-vector-tile/vector-tile-feature.ts
|
|
1669
|
-
var VectorTileFeature
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1723
|
+
var VectorTileFeature = class {
|
|
1724
|
+
static get types() {
|
|
1725
|
+
return ["Unknown", "Point", "LineString", "Polygon"];
|
|
1726
|
+
}
|
|
1727
|
+
constructor(pbf, end, extent, keys, values) {
|
|
1728
|
+
this.properties = {};
|
|
1729
|
+
this.extent = extent;
|
|
1730
|
+
this.type = 0;
|
|
1731
|
+
this.id = null;
|
|
1732
|
+
this._pbf = pbf;
|
|
1733
|
+
this._geometry = -1;
|
|
1734
|
+
this._keys = keys;
|
|
1735
|
+
this._values = values;
|
|
1736
|
+
pbf.readFields(readFeature, this, end);
|
|
1737
|
+
}
|
|
1738
|
+
// eslint-disable-next-line complexity, max-statements
|
|
1739
|
+
loadGeometry() {
|
|
1740
|
+
const pbf = this._pbf;
|
|
1741
|
+
pbf.pos = this._geometry;
|
|
1742
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1743
|
+
let cmd2 = 1;
|
|
1744
|
+
let length2 = 0;
|
|
1745
|
+
let x2 = 0;
|
|
1746
|
+
let y2 = 0;
|
|
1747
|
+
const lines = [];
|
|
1748
|
+
let line;
|
|
1749
|
+
while (pbf.pos < end) {
|
|
1750
|
+
if (length2 <= 0) {
|
|
1751
|
+
const cmdLen2 = pbf.readVarint();
|
|
1752
|
+
cmd2 = cmdLen2 & 7;
|
|
1753
|
+
length2 = cmdLen2 >> 3;
|
|
1687
1754
|
}
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
const lines = [];
|
|
1697
|
-
let line;
|
|
1698
|
-
while (pbf.pos < end) {
|
|
1699
|
-
if (length2 <= 0) {
|
|
1700
|
-
const cmdLen2 = pbf.readVarint();
|
|
1701
|
-
cmd2 = cmdLen2 & 7;
|
|
1702
|
-
length2 = cmdLen2 >> 3;
|
|
1703
|
-
}
|
|
1704
|
-
length2--;
|
|
1705
|
-
if (cmd2 === 1 || cmd2 === 2) {
|
|
1706
|
-
x2 += pbf.readSVarint();
|
|
1707
|
-
y2 += pbf.readSVarint();
|
|
1708
|
-
if (cmd2 === 1) {
|
|
1709
|
-
if (line)
|
|
1710
|
-
lines.push(line);
|
|
1711
|
-
line = [];
|
|
1712
|
-
}
|
|
1713
|
-
if (line)
|
|
1714
|
-
line.push([x2, y2]);
|
|
1715
|
-
} else if (cmd2 === 7) {
|
|
1716
|
-
if (line) {
|
|
1717
|
-
line.push(line[0].slice());
|
|
1718
|
-
}
|
|
1719
|
-
} else {
|
|
1720
|
-
throw new Error(`unknown command ${cmd2}`);
|
|
1721
|
-
}
|
|
1755
|
+
length2--;
|
|
1756
|
+
if (cmd2 === 1 || cmd2 === 2) {
|
|
1757
|
+
x2 += pbf.readSVarint();
|
|
1758
|
+
y2 += pbf.readSVarint();
|
|
1759
|
+
if (cmd2 === 1) {
|
|
1760
|
+
if (line)
|
|
1761
|
+
lines.push(line);
|
|
1762
|
+
line = [];
|
|
1722
1763
|
}
|
|
1723
1764
|
if (line)
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
const pbf = this._pbf;
|
|
1729
|
-
pbf.pos = this._geometry;
|
|
1730
|
-
const end = pbf.readVarint() + pbf.pos;
|
|
1731
|
-
let cmd2 = 1;
|
|
1732
|
-
let length2 = 0;
|
|
1733
|
-
let x2 = 0;
|
|
1734
|
-
let y2 = 0;
|
|
1735
|
-
let x1 = Infinity;
|
|
1736
|
-
let x22 = -Infinity;
|
|
1737
|
-
let y1 = Infinity;
|
|
1738
|
-
let y22 = -Infinity;
|
|
1739
|
-
while (pbf.pos < end) {
|
|
1740
|
-
if (length2 <= 0) {
|
|
1741
|
-
const cmdLen2 = pbf.readVarint();
|
|
1742
|
-
cmd2 = cmdLen2 & 7;
|
|
1743
|
-
length2 = cmdLen2 >> 3;
|
|
1744
|
-
}
|
|
1745
|
-
length2--;
|
|
1746
|
-
if (cmd2 === 1 || cmd2 === 2) {
|
|
1747
|
-
x2 += pbf.readSVarint();
|
|
1748
|
-
y2 += pbf.readSVarint();
|
|
1749
|
-
if (x2 < x1)
|
|
1750
|
-
x1 = x2;
|
|
1751
|
-
if (x2 > x22)
|
|
1752
|
-
x22 = x2;
|
|
1753
|
-
if (y2 < y1)
|
|
1754
|
-
y1 = y2;
|
|
1755
|
-
if (y2 > y22)
|
|
1756
|
-
y22 = y2;
|
|
1757
|
-
} else if (cmd2 !== 7) {
|
|
1758
|
-
throw new Error(`unknown command ${cmd2}`);
|
|
1759
|
-
}
|
|
1765
|
+
line.push([x2, y2]);
|
|
1766
|
+
} else if (cmd2 === 7) {
|
|
1767
|
+
if (line) {
|
|
1768
|
+
line.push(line[0].slice());
|
|
1760
1769
|
}
|
|
1761
|
-
|
|
1770
|
+
} else {
|
|
1771
|
+
throw new Error(`unknown command ${cmd2}`);
|
|
1762
1772
|
}
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
if (
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
},
|
|
1802
|
-
properties: this.properties
|
|
1803
|
-
};
|
|
1804
|
-
if (this.id !== null) {
|
|
1805
|
-
result.id = this.id;
|
|
1806
|
-
}
|
|
1807
|
-
return result;
|
|
1773
|
+
}
|
|
1774
|
+
if (line)
|
|
1775
|
+
lines.push(line);
|
|
1776
|
+
return lines;
|
|
1777
|
+
}
|
|
1778
|
+
// eslint-disable-next-line max-statements
|
|
1779
|
+
bbox() {
|
|
1780
|
+
const pbf = this._pbf;
|
|
1781
|
+
pbf.pos = this._geometry;
|
|
1782
|
+
const end = pbf.readVarint() + pbf.pos;
|
|
1783
|
+
let cmd2 = 1;
|
|
1784
|
+
let length2 = 0;
|
|
1785
|
+
let x2 = 0;
|
|
1786
|
+
let y2 = 0;
|
|
1787
|
+
let x1 = Infinity;
|
|
1788
|
+
let x22 = -Infinity;
|
|
1789
|
+
let y1 = Infinity;
|
|
1790
|
+
let y22 = -Infinity;
|
|
1791
|
+
while (pbf.pos < end) {
|
|
1792
|
+
if (length2 <= 0) {
|
|
1793
|
+
const cmdLen2 = pbf.readVarint();
|
|
1794
|
+
cmd2 = cmdLen2 & 7;
|
|
1795
|
+
length2 = cmdLen2 >> 3;
|
|
1796
|
+
}
|
|
1797
|
+
length2--;
|
|
1798
|
+
if (cmd2 === 1 || cmd2 === 2) {
|
|
1799
|
+
x2 += pbf.readSVarint();
|
|
1800
|
+
y2 += pbf.readSVarint();
|
|
1801
|
+
if (x2 < x1)
|
|
1802
|
+
x1 = x2;
|
|
1803
|
+
if (x2 > x22)
|
|
1804
|
+
x22 = x2;
|
|
1805
|
+
if (y2 < y1)
|
|
1806
|
+
y1 = y2;
|
|
1807
|
+
if (y2 > y22)
|
|
1808
|
+
y22 = y2;
|
|
1809
|
+
} else if (cmd2 !== 7) {
|
|
1810
|
+
throw new Error(`unknown command ${cmd2}`);
|
|
1808
1811
|
}
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
+
}
|
|
1813
|
+
return [x1, y1, x22, y22];
|
|
1814
|
+
}
|
|
1815
|
+
_toGeoJSON(transform) {
|
|
1816
|
+
let coords = this.loadGeometry();
|
|
1817
|
+
let type = VectorTileFeature.types[this.type];
|
|
1818
|
+
let i2;
|
|
1819
|
+
let j;
|
|
1820
|
+
switch (this.type) {
|
|
1821
|
+
case 1:
|
|
1822
|
+
const points = [];
|
|
1823
|
+
for (i2 = 0; i2 < coords.length; i2++) {
|
|
1824
|
+
points[i2] = coords[i2][0];
|
|
1825
|
+
}
|
|
1826
|
+
coords = points;
|
|
1827
|
+
transform(coords, this);
|
|
1828
|
+
break;
|
|
1829
|
+
case 2:
|
|
1830
|
+
for (i2 = 0; i2 < coords.length; i2++) {
|
|
1831
|
+
transform(coords[i2], this);
|
|
1812
1832
|
}
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
const p = line[j];
|
|
1820
|
-
p[0] = (p[0] + x0) * 360 / size - 180;
|
|
1821
|
-
const y22 = 180 - (p[1] + y0) * 360 / size;
|
|
1822
|
-
p[1] = 360 / Math.PI * Math.atan(Math.exp(y22 * Math.PI / 180)) - 90;
|
|
1833
|
+
break;
|
|
1834
|
+
case 3:
|
|
1835
|
+
coords = classifyRings(coords);
|
|
1836
|
+
for (i2 = 0; i2 < coords.length; i2++) {
|
|
1837
|
+
for (j = 0; j < coords[i2].length; j++) {
|
|
1838
|
+
transform(coords[i2][j], this);
|
|
1823
1839
|
}
|
|
1824
1840
|
}
|
|
1825
|
-
|
|
1826
|
-
|
|
1841
|
+
break;
|
|
1842
|
+
}
|
|
1843
|
+
if (coords.length === 1) {
|
|
1844
|
+
coords = coords[0];
|
|
1845
|
+
} else {
|
|
1846
|
+
type = `Multi${type}`;
|
|
1847
|
+
}
|
|
1848
|
+
const result = {
|
|
1849
|
+
type: "Feature",
|
|
1850
|
+
geometry: {
|
|
1851
|
+
type,
|
|
1852
|
+
coordinates: coords
|
|
1853
|
+
},
|
|
1854
|
+
properties: this.properties
|
|
1827
1855
|
};
|
|
1856
|
+
if (this.id !== null) {
|
|
1857
|
+
result.id = this.id;
|
|
1858
|
+
}
|
|
1859
|
+
return result;
|
|
1828
1860
|
}
|
|
1829
|
-
|
|
1861
|
+
toGeoJSON(options) {
|
|
1862
|
+
if (typeof options === "function") {
|
|
1863
|
+
return this._toGeoJSON(options);
|
|
1864
|
+
}
|
|
1865
|
+
const {
|
|
1866
|
+
x: x2,
|
|
1867
|
+
y: y2,
|
|
1868
|
+
z
|
|
1869
|
+
} = options;
|
|
1870
|
+
const size = this.extent * Math.pow(2, z);
|
|
1871
|
+
const x0 = this.extent * x2;
|
|
1872
|
+
const y0 = this.extent * y2;
|
|
1873
|
+
function project2(line) {
|
|
1874
|
+
for (let j = 0; j < line.length; j++) {
|
|
1875
|
+
const p = line[j];
|
|
1876
|
+
p[0] = (p[0] + x0) * 360 / size - 180;
|
|
1877
|
+
const y22 = 180 - (p[1] + y0) * 360 / size;
|
|
1878
|
+
p[1] = 360 / Math.PI * Math.atan(Math.exp(y22 * Math.PI / 180)) - 90;
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
return this._toGeoJSON(project2);
|
|
1882
|
+
}
|
|
1883
|
+
};
|
|
1830
1884
|
|
|
1831
1885
|
// src/lib/mapbox-vector-tile/vector-tile-layer.ts
|
|
1886
|
+
var VectorTileLayer = class {
|
|
1887
|
+
constructor(pbf, end) {
|
|
1888
|
+
this.version = 1;
|
|
1889
|
+
this.name = "";
|
|
1890
|
+
this.extent = 4096;
|
|
1891
|
+
this.length = 0;
|
|
1892
|
+
this._pbf = pbf;
|
|
1893
|
+
this._keys = [];
|
|
1894
|
+
this._values = [];
|
|
1895
|
+
this._features = [];
|
|
1896
|
+
pbf.readFields(readLayer, this, end);
|
|
1897
|
+
this.length = this._features.length;
|
|
1898
|
+
}
|
|
1899
|
+
/**
|
|
1900
|
+
* return feature `i` from this layer as a `VectorTileFeature`
|
|
1901
|
+
* @param index
|
|
1902
|
+
* @returns feature
|
|
1903
|
+
*/
|
|
1904
|
+
feature(i2) {
|
|
1905
|
+
if (i2 < 0 || i2 >= this._features.length) {
|
|
1906
|
+
throw new Error("feature index out of bounds");
|
|
1907
|
+
}
|
|
1908
|
+
this._pbf.pos = this._features[i2];
|
|
1909
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
1910
|
+
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
|
|
1911
|
+
}
|
|
1912
|
+
};
|
|
1832
1913
|
function readLayer(tag, layer, pbf) {
|
|
1833
1914
|
if (layer && pbf) {
|
|
1834
1915
|
if (tag === 15)
|
|
@@ -1854,36 +1935,13 @@
|
|
|
1854
1935
|
}
|
|
1855
1936
|
return value;
|
|
1856
1937
|
}
|
|
1857
|
-
var VectorTileLayer;
|
|
1858
|
-
var init_vector_tile_layer = __esm({
|
|
1859
|
-
"src/lib/mapbox-vector-tile/vector-tile-layer.ts"() {
|
|
1860
|
-
init_vector_tile_feature();
|
|
1861
|
-
VectorTileLayer = class {
|
|
1862
|
-
constructor(pbf, end) {
|
|
1863
|
-
this.version = 1;
|
|
1864
|
-
this.name = "";
|
|
1865
|
-
this.extent = 4096;
|
|
1866
|
-
this.length = 0;
|
|
1867
|
-
this._pbf = pbf;
|
|
1868
|
-
this._keys = [];
|
|
1869
|
-
this._values = [];
|
|
1870
|
-
this._features = [];
|
|
1871
|
-
pbf.readFields(readLayer, this, end);
|
|
1872
|
-
this.length = this._features.length;
|
|
1873
|
-
}
|
|
1874
|
-
feature(i2) {
|
|
1875
|
-
if (i2 < 0 || i2 >= this._features.length) {
|
|
1876
|
-
throw new Error("feature index out of bounds");
|
|
1877
|
-
}
|
|
1878
|
-
this._pbf.pos = this._features[i2];
|
|
1879
|
-
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
1880
|
-
return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values);
|
|
1881
|
-
}
|
|
1882
|
-
};
|
|
1883
|
-
}
|
|
1884
|
-
});
|
|
1885
1938
|
|
|
1886
1939
|
// src/lib/mapbox-vector-tile/vector-tile.ts
|
|
1940
|
+
var VectorTile = class {
|
|
1941
|
+
constructor(pbf, end) {
|
|
1942
|
+
this.layers = pbf.readFields(readTile, {}, end);
|
|
1943
|
+
}
|
|
1944
|
+
};
|
|
1887
1945
|
function readTile(tag, layers, pbf) {
|
|
1888
1946
|
if (tag === 3) {
|
|
1889
1947
|
if (pbf) {
|
|
@@ -1894,17 +1952,6 @@
|
|
|
1894
1952
|
}
|
|
1895
1953
|
}
|
|
1896
1954
|
}
|
|
1897
|
-
var VectorTile;
|
|
1898
|
-
var init_vector_tile = __esm({
|
|
1899
|
-
"src/lib/mapbox-vector-tile/vector-tile.ts"() {
|
|
1900
|
-
init_vector_tile_layer();
|
|
1901
|
-
VectorTile = class {
|
|
1902
|
-
constructor(pbf, end) {
|
|
1903
|
-
this.layers = pbf.readFields(readTile, {}, end);
|
|
1904
|
-
}
|
|
1905
|
-
};
|
|
1906
|
-
}
|
|
1907
|
-
});
|
|
1908
1955
|
|
|
1909
1956
|
// src/helpers/binary-util-functions.ts
|
|
1910
1957
|
function classifyRings2(geom) {
|
|
@@ -1954,7 +2001,12 @@
|
|
|
1954
2001
|
areas.push(ringAreas);
|
|
1955
2002
|
if (polygon.length)
|
|
1956
2003
|
polygons.push(polygon);
|
|
1957
|
-
return {
|
|
2004
|
+
return {
|
|
2005
|
+
type,
|
|
2006
|
+
areas,
|
|
2007
|
+
indices: polygons,
|
|
2008
|
+
data: geom.data
|
|
2009
|
+
};
|
|
1958
2010
|
}
|
|
1959
2011
|
function project(data, x0, y0, size) {
|
|
1960
2012
|
for (let j = 0, jl = data.length; j < jl; j += 2) {
|
|
@@ -1983,118 +2035,167 @@
|
|
|
1983
2035
|
feature.properties[key] = value;
|
|
1984
2036
|
}
|
|
1985
2037
|
}
|
|
1986
|
-
var init_binary_util_functions = __esm({
|
|
1987
|
-
"src/helpers/binary-util-functions.ts"() {
|
|
1988
|
-
init_esm();
|
|
1989
|
-
}
|
|
1990
|
-
});
|
|
1991
2038
|
|
|
1992
2039
|
// src/lib/binary-vector-tile/vector-tile-feature.ts
|
|
1993
|
-
var endPos
|
|
1994
|
-
var
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
if (cmd === 1) {
|
|
2032
|
-
indices.push(i);
|
|
2033
|
-
}
|
|
2034
|
-
data.push(x, y);
|
|
2035
|
-
i += 2;
|
|
2036
|
-
} else if (cmd === 7) {
|
|
2037
|
-
if (i > 0) {
|
|
2038
|
-
const start = indices[indices.length - 1];
|
|
2039
|
-
data.push(data[start], data[start + 1]);
|
|
2040
|
-
i += 2;
|
|
2041
|
-
}
|
|
2042
|
-
} else {
|
|
2043
|
-
throw new Error(`unknown command ${cmd}`);
|
|
2044
|
-
}
|
|
2045
|
-
}
|
|
2046
|
-
return { data, indices };
|
|
2040
|
+
var endPos;
|
|
2041
|
+
var cmd;
|
|
2042
|
+
var cmdLen;
|
|
2043
|
+
var length;
|
|
2044
|
+
var x;
|
|
2045
|
+
var y;
|
|
2046
|
+
var i;
|
|
2047
|
+
var VectorTileFeature2 = class {
|
|
2048
|
+
// eslint-disable-next-line max-params
|
|
2049
|
+
constructor(pbf, end, extent, keys, values, geometryInfo) {
|
|
2050
|
+
this.properties = {};
|
|
2051
|
+
this.extent = extent;
|
|
2052
|
+
this.type = 0;
|
|
2053
|
+
this.id = null;
|
|
2054
|
+
this._pbf = pbf;
|
|
2055
|
+
this._geometry = -1;
|
|
2056
|
+
this._keys = keys;
|
|
2057
|
+
this._values = values;
|
|
2058
|
+
this._geometryInfo = geometryInfo;
|
|
2059
|
+
pbf.readFields(readFeature2, this, end);
|
|
2060
|
+
}
|
|
2061
|
+
// eslint-disable-next-line complexity, max-statements
|
|
2062
|
+
loadGeometry() {
|
|
2063
|
+
const pbf = this._pbf;
|
|
2064
|
+
pbf.pos = this._geometry;
|
|
2065
|
+
endPos = pbf.readVarint() + pbf.pos;
|
|
2066
|
+
cmd = 1;
|
|
2067
|
+
length = 0;
|
|
2068
|
+
x = 0;
|
|
2069
|
+
y = 0;
|
|
2070
|
+
i = 0;
|
|
2071
|
+
const indices = [];
|
|
2072
|
+
const data = [];
|
|
2073
|
+
while (pbf.pos < endPos) {
|
|
2074
|
+
if (length <= 0) {
|
|
2075
|
+
cmdLen = pbf.readVarint();
|
|
2076
|
+
cmd = cmdLen & 7;
|
|
2077
|
+
length = cmdLen >> 3;
|
|
2047
2078
|
}
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
case 1:
|
|
2055
|
-
this._geometryInfo.pointFeaturesCount++;
|
|
2056
|
-
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
2057
|
-
geometry = { type: "Point", ...geom };
|
|
2058
|
-
break;
|
|
2059
|
-
case 2:
|
|
2060
|
-
this._geometryInfo.lineFeaturesCount++;
|
|
2061
|
-
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
2062
|
-
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
2063
|
-
geometry = { type: "LineString", ...geom };
|
|
2064
|
-
break;
|
|
2065
|
-
case 3:
|
|
2066
|
-
geometry = classifyRings2(geom);
|
|
2067
|
-
this._geometryInfo.polygonFeaturesCount++;
|
|
2068
|
-
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
2069
|
-
for (const indices of geometry.indices) {
|
|
2070
|
-
this._geometryInfo.polygonRingsCount += indices.length;
|
|
2071
|
-
}
|
|
2072
|
-
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
2073
|
-
break;
|
|
2074
|
-
default:
|
|
2075
|
-
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
2079
|
+
length--;
|
|
2080
|
+
if (cmd === 1 || cmd === 2) {
|
|
2081
|
+
x += pbf.readSVarint();
|
|
2082
|
+
y += pbf.readSVarint();
|
|
2083
|
+
if (cmd === 1) {
|
|
2084
|
+
indices.push(i);
|
|
2076
2085
|
}
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2086
|
+
data.push(x, y);
|
|
2087
|
+
i += 2;
|
|
2088
|
+
} else if (cmd === 7) {
|
|
2089
|
+
if (i > 0) {
|
|
2090
|
+
const start = indices[indices.length - 1];
|
|
2091
|
+
data.push(data[start], data[start + 1]);
|
|
2092
|
+
i += 2;
|
|
2080
2093
|
}
|
|
2081
|
-
|
|
2094
|
+
} else {
|
|
2095
|
+
throw new Error(`unknown command ${cmd}`);
|
|
2082
2096
|
}
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2097
|
+
}
|
|
2098
|
+
return {
|
|
2099
|
+
data,
|
|
2100
|
+
indices
|
|
2101
|
+
};
|
|
2102
|
+
}
|
|
2103
|
+
/**
|
|
2104
|
+
*
|
|
2105
|
+
* @param transform
|
|
2106
|
+
* @returns result
|
|
2107
|
+
*/
|
|
2108
|
+
_toBinaryCoordinates(transform) {
|
|
2109
|
+
const geom = this.loadGeometry();
|
|
2110
|
+
let geometry;
|
|
2111
|
+
transform(geom.data, this);
|
|
2112
|
+
const coordLength = 2;
|
|
2113
|
+
switch (this.type) {
|
|
2114
|
+
case 1:
|
|
2115
|
+
this._geometryInfo.pointFeaturesCount++;
|
|
2116
|
+
this._geometryInfo.pointPositionsCount += geom.indices.length;
|
|
2117
|
+
geometry = {
|
|
2118
|
+
type: "Point",
|
|
2119
|
+
...geom
|
|
2120
|
+
};
|
|
2121
|
+
break;
|
|
2122
|
+
case 2:
|
|
2123
|
+
this._geometryInfo.lineFeaturesCount++;
|
|
2124
|
+
this._geometryInfo.linePathsCount += geom.indices.length;
|
|
2125
|
+
this._geometryInfo.linePositionsCount += geom.data.length / coordLength;
|
|
2126
|
+
geometry = {
|
|
2127
|
+
type: "LineString",
|
|
2128
|
+
...geom
|
|
2129
|
+
};
|
|
2130
|
+
break;
|
|
2131
|
+
case 3:
|
|
2132
|
+
geometry = classifyRings2(geom);
|
|
2133
|
+
this._geometryInfo.polygonFeaturesCount++;
|
|
2134
|
+
this._geometryInfo.polygonObjectsCount += geometry.indices.length;
|
|
2135
|
+
for (const indices of geometry.indices) {
|
|
2136
|
+
this._geometryInfo.polygonRingsCount += indices.length;
|
|
2086
2137
|
}
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2138
|
+
this._geometryInfo.polygonPositionsCount += geometry.data.length / coordLength;
|
|
2139
|
+
break;
|
|
2140
|
+
default:
|
|
2141
|
+
throw new Error(`Invalid geometry type: ${this.type}`);
|
|
2142
|
+
}
|
|
2143
|
+
const result = {
|
|
2144
|
+
type: "Feature",
|
|
2145
|
+
geometry,
|
|
2146
|
+
properties: this.properties
|
|
2093
2147
|
};
|
|
2148
|
+
if (this.id !== null) {
|
|
2149
|
+
result.id = this.id;
|
|
2150
|
+
}
|
|
2151
|
+
return result;
|
|
2094
2152
|
}
|
|
2095
|
-
|
|
2153
|
+
toBinaryCoordinates(options) {
|
|
2154
|
+
if (typeof options === "function") {
|
|
2155
|
+
return this._toBinaryCoordinates(options);
|
|
2156
|
+
}
|
|
2157
|
+
const {
|
|
2158
|
+
x: x2,
|
|
2159
|
+
y: y2,
|
|
2160
|
+
z
|
|
2161
|
+
} = options;
|
|
2162
|
+
const size = this.extent * Math.pow(2, z);
|
|
2163
|
+
const x0 = this.extent * x2;
|
|
2164
|
+
const y0 = this.extent * y2;
|
|
2165
|
+
return this._toBinaryCoordinates((data) => project(data, x0, y0, size));
|
|
2166
|
+
}
|
|
2167
|
+
};
|
|
2096
2168
|
|
|
2097
2169
|
// src/lib/binary-vector-tile/vector-tile-layer.ts
|
|
2170
|
+
var VectorTileLayer2 = class {
|
|
2171
|
+
constructor(pbf, end) {
|
|
2172
|
+
this.version = 1;
|
|
2173
|
+
this.name = "";
|
|
2174
|
+
this.extent = 4096;
|
|
2175
|
+
this.length = 0;
|
|
2176
|
+
this._pbf = pbf;
|
|
2177
|
+
this._keys = [];
|
|
2178
|
+
this._values = [];
|
|
2179
|
+
this._features = [];
|
|
2180
|
+
pbf.readFields(readLayer2, this, end);
|
|
2181
|
+
this.length = this._features.length;
|
|
2182
|
+
}
|
|
2183
|
+
/**
|
|
2184
|
+
* return feature `i` from this layer as a `VectorTileFeature`
|
|
2185
|
+
*
|
|
2186
|
+
* @param index
|
|
2187
|
+
* @param geometryInfo
|
|
2188
|
+
* @returns {VectorTileFeature}
|
|
2189
|
+
*/
|
|
2190
|
+
feature(i2, geometryInfo) {
|
|
2191
|
+
if (i2 < 0 || i2 >= this._features.length) {
|
|
2192
|
+
throw new Error("feature index out of bounds");
|
|
2193
|
+
}
|
|
2194
|
+
this._pbf.pos = this._features[i2];
|
|
2195
|
+
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
2196
|
+
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
2197
|
+
}
|
|
2198
|
+
};
|
|
2098
2199
|
function readLayer2(tag, layer, pbf) {
|
|
2099
2200
|
if (layer && pbf) {
|
|
2100
2201
|
if (tag === 15)
|
|
@@ -2116,40 +2217,17 @@
|
|
|
2116
2217
|
const end = pbf.readVarint() + pbf.pos;
|
|
2117
2218
|
while (pbf.pos < end) {
|
|
2118
2219
|
const tag = pbf.readVarint() >> 3;
|
|
2119
|
-
value = tag === 1 ? pbf.readString() : tag === 2 ? pbf.readFloat() : tag === 3 ? pbf.readDouble() : tag === 4 ? pbf.readVarint64() : tag === 5 ? pbf.readVarint() : tag === 6 ? pbf.readSVarint() : tag === 7 ? pbf.readBoolean() : null;
|
|
2120
|
-
}
|
|
2121
|
-
return value;
|
|
2122
|
-
}
|
|
2123
|
-
var VectorTileLayer2;
|
|
2124
|
-
var init_vector_tile_layer2 = __esm({
|
|
2125
|
-
"src/lib/binary-vector-tile/vector-tile-layer.ts"() {
|
|
2126
|
-
init_vector_tile_feature2();
|
|
2127
|
-
VectorTileLayer2 = class {
|
|
2128
|
-
constructor(pbf, end) {
|
|
2129
|
-
this.version = 1;
|
|
2130
|
-
this.name = "";
|
|
2131
|
-
this.extent = 4096;
|
|
2132
|
-
this.length = 0;
|
|
2133
|
-
this._pbf = pbf;
|
|
2134
|
-
this._keys = [];
|
|
2135
|
-
this._values = [];
|
|
2136
|
-
this._features = [];
|
|
2137
|
-
pbf.readFields(readLayer2, this, end);
|
|
2138
|
-
this.length = this._features.length;
|
|
2139
|
-
}
|
|
2140
|
-
feature(i2, geometryInfo) {
|
|
2141
|
-
if (i2 < 0 || i2 >= this._features.length) {
|
|
2142
|
-
throw new Error("feature index out of bounds");
|
|
2143
|
-
}
|
|
2144
|
-
this._pbf.pos = this._features[i2];
|
|
2145
|
-
const end = this._pbf.readVarint() + this._pbf.pos;
|
|
2146
|
-
return new VectorTileFeature2(this._pbf, end, this.extent, this._keys, this._values, geometryInfo);
|
|
2147
|
-
}
|
|
2148
|
-
};
|
|
2220
|
+
value = tag === 1 ? pbf.readString() : tag === 2 ? pbf.readFloat() : tag === 3 ? pbf.readDouble() : tag === 4 ? pbf.readVarint64() : tag === 5 ? pbf.readVarint() : tag === 6 ? pbf.readSVarint() : tag === 7 ? pbf.readBoolean() : null;
|
|
2149
2221
|
}
|
|
2150
|
-
|
|
2222
|
+
return value;
|
|
2223
|
+
}
|
|
2151
2224
|
|
|
2152
2225
|
// src/lib/binary-vector-tile/vector-tile.ts
|
|
2226
|
+
var VectorTile2 = class {
|
|
2227
|
+
constructor(pbf, end) {
|
|
2228
|
+
this.layers = pbf.readFields(readTile2, {}, end);
|
|
2229
|
+
}
|
|
2230
|
+
};
|
|
2153
2231
|
function readTile2(tag, layers, pbf) {
|
|
2154
2232
|
if (tag === 3) {
|
|
2155
2233
|
if (pbf) {
|
|
@@ -2160,17 +2238,6 @@
|
|
|
2160
2238
|
}
|
|
2161
2239
|
}
|
|
2162
2240
|
}
|
|
2163
|
-
var VectorTile2;
|
|
2164
|
-
var init_vector_tile2 = __esm({
|
|
2165
|
-
"src/lib/binary-vector-tile/vector-tile.ts"() {
|
|
2166
|
-
init_vector_tile_layer2();
|
|
2167
|
-
VectorTile2 = class {
|
|
2168
|
-
constructor(pbf, end) {
|
|
2169
|
-
this.layers = pbf.readFields(readTile2, {}, end);
|
|
2170
|
-
}
|
|
2171
|
-
};
|
|
2172
|
-
}
|
|
2173
|
-
});
|
|
2174
2241
|
|
|
2175
2242
|
// src/lib/parse-mvt.ts
|
|
2176
2243
|
function parseMVT(arrayBuffer, options) {
|
|
@@ -2178,7 +2245,10 @@
|
|
|
2178
2245
|
const shape = options?.gis?.format || options?.mvt?.shape || options?.shape;
|
|
2179
2246
|
switch (shape) {
|
|
2180
2247
|
case "columnar-table":
|
|
2181
|
-
return {
|
|
2248
|
+
return {
|
|
2249
|
+
shape: "columnar-table",
|
|
2250
|
+
data: parseToBinary(arrayBuffer, mvtOptions)
|
|
2251
|
+
};
|
|
2182
2252
|
case "geojson-table": {
|
|
2183
2253
|
const table = {
|
|
2184
2254
|
shape: "geojson-table",
|
|
@@ -2260,7 +2330,9 @@
|
|
|
2260
2330
|
throw new Error("mvt options required");
|
|
2261
2331
|
}
|
|
2262
2332
|
const wgs84Coordinates = options.mvt?.coordinates === "wgs84";
|
|
2263
|
-
const {
|
|
2333
|
+
const {
|
|
2334
|
+
tileIndex
|
|
2335
|
+
} = options.mvt;
|
|
2264
2336
|
const hasTileIndex = tileIndex && Number.isFinite(tileIndex.x) && Number.isFinite(tileIndex.y) && Number.isFinite(tileIndex.z);
|
|
2265
2337
|
if (wgs84Coordinates && !hasTileIndex) {
|
|
2266
2338
|
throw new Error("MVT Loader: WGS84 coordinates need tileIndex property");
|
|
@@ -2268,21 +2340,29 @@
|
|
|
2268
2340
|
return options.mvt;
|
|
2269
2341
|
}
|
|
2270
2342
|
function getDecodedFeature(feature, options, layerName) {
|
|
2271
|
-
const decodedFeature = feature.toGeoJSON(
|
|
2343
|
+
const decodedFeature = feature.toGeoJSON(
|
|
2344
|
+
// @ts-expect-error What is going on here?
|
|
2345
|
+
options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinates
|
|
2346
|
+
);
|
|
2272
2347
|
if (options.layerProperty) {
|
|
2273
2348
|
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2274
2349
|
}
|
|
2275
2350
|
return decodedFeature;
|
|
2276
2351
|
}
|
|
2277
2352
|
function getDecodedFeatureBinary(feature, options, layerName) {
|
|
2278
|
-
const decodedFeature = feature.toBinaryCoordinates(
|
|
2353
|
+
const decodedFeature = feature.toBinaryCoordinates(
|
|
2354
|
+
// @ts-expect-error What is going on here?
|
|
2355
|
+
options.coordinates === "wgs84" ? options.tileIndex : transformToLocalCoordinatesBinary
|
|
2356
|
+
);
|
|
2279
2357
|
if (options.layerProperty && decodedFeature.properties) {
|
|
2280
2358
|
decodedFeature.properties[options.layerProperty] = layerName;
|
|
2281
2359
|
}
|
|
2282
2360
|
return decodedFeature;
|
|
2283
2361
|
}
|
|
2284
2362
|
function transformToLocalCoordinates(line, feature) {
|
|
2285
|
-
const {
|
|
2363
|
+
const {
|
|
2364
|
+
extent
|
|
2365
|
+
} = feature;
|
|
2286
2366
|
for (let i2 = 0; i2 < line.length; i2++) {
|
|
2287
2367
|
const p = line[i2];
|
|
2288
2368
|
p[0] /= extent;
|
|
@@ -2290,59 +2370,50 @@
|
|
|
2290
2370
|
}
|
|
2291
2371
|
}
|
|
2292
2372
|
function transformToLocalCoordinatesBinary(data, feature) {
|
|
2293
|
-
const {
|
|
2373
|
+
const {
|
|
2374
|
+
extent
|
|
2375
|
+
} = feature;
|
|
2294
2376
|
for (let i2 = 0, il = data.length; i2 < il; ++i2) {
|
|
2295
2377
|
data[i2] /= extent;
|
|
2296
2378
|
}
|
|
2297
2379
|
}
|
|
2298
|
-
var import_pbf;
|
|
2299
|
-
var init_parse_mvt = __esm({
|
|
2300
|
-
"src/lib/parse-mvt.ts"() {
|
|
2301
|
-
init_src();
|
|
2302
|
-
import_pbf = __toModule(require_pbf());
|
|
2303
|
-
init_vector_tile();
|
|
2304
|
-
init_vector_tile2();
|
|
2305
|
-
}
|
|
2306
|
-
});
|
|
2307
2380
|
|
|
2308
2381
|
// src/mvt-loader.ts
|
|
2309
|
-
var VERSION
|
|
2310
|
-
var
|
|
2311
|
-
"
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
};
|
|
2336
|
-
MVTLoader = {
|
|
2337
|
-
...MVTWorkerLoader,
|
|
2338
|
-
parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options),
|
|
2339
|
-
parseSync: parseMVT,
|
|
2340
|
-
binary: true
|
|
2341
|
-
};
|
|
2382
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2383
|
+
var MVTWorkerLoader = {
|
|
2384
|
+
name: "Mapbox Vector Tile",
|
|
2385
|
+
id: "mvt",
|
|
2386
|
+
module: "mvt",
|
|
2387
|
+
version: VERSION,
|
|
2388
|
+
// Note: ArcGIS uses '.pbf' extension and 'application/octet-stream'
|
|
2389
|
+
extensions: ["mvt", "pbf"],
|
|
2390
|
+
mimeTypes: [
|
|
2391
|
+
// https://www.iana.org/assignments/media-types/application/vnd.mapbox-vector-tile
|
|
2392
|
+
"application/vnd.mapbox-vector-tile",
|
|
2393
|
+
"application/x-protobuf"
|
|
2394
|
+
// 'application/octet-stream'
|
|
2395
|
+
],
|
|
2396
|
+
worker: true,
|
|
2397
|
+
category: "geometry",
|
|
2398
|
+
options: {
|
|
2399
|
+
mvt: {
|
|
2400
|
+
shape: "geojson",
|
|
2401
|
+
coordinates: "local",
|
|
2402
|
+
layerProperty: "layerName",
|
|
2403
|
+
layers: void 0,
|
|
2404
|
+
tileIndex: null
|
|
2405
|
+
}
|
|
2342
2406
|
}
|
|
2343
|
-
}
|
|
2407
|
+
};
|
|
2408
|
+
var MVTLoader = {
|
|
2409
|
+
...MVTWorkerLoader,
|
|
2410
|
+
parse: async (arrayBuffer, options) => parseMVT(arrayBuffer, options),
|
|
2411
|
+
parseSync: parseMVT,
|
|
2412
|
+
binary: true
|
|
2413
|
+
};
|
|
2344
2414
|
|
|
2345
2415
|
// src/lib/parse-tilejson.ts
|
|
2416
|
+
var isObject = (x2) => x2 !== null && typeof x2 === "object";
|
|
2346
2417
|
function parseTileJSON(jsonMetadata) {
|
|
2347
2418
|
if (!jsonMetadata || !isObject(jsonMetadata)) {
|
|
2348
2419
|
return null;
|
|
@@ -2420,10 +2491,7 @@
|
|
|
2420
2491
|
function parseBounds(bounds) {
|
|
2421
2492
|
const result = fromArrayOrString(bounds);
|
|
2422
2493
|
if (Array.isArray(result) && result.length === 4 && [result[0], result[2]].every(isLng) && [result[1], result[3]].every(isLat)) {
|
|
2423
|
-
return [
|
|
2424
|
-
[result[0], result[1]],
|
|
2425
|
-
[result[2], result[3]]
|
|
2426
|
-
];
|
|
2494
|
+
return [[result[0], result[1]], [result[2], result[3]]];
|
|
2427
2495
|
}
|
|
2428
2496
|
return void 0;
|
|
2429
2497
|
}
|
|
@@ -2455,10 +2523,41 @@
|
|
|
2455
2523
|
}
|
|
2456
2524
|
return null;
|
|
2457
2525
|
}
|
|
2526
|
+
var attrTypeMap = {
|
|
2527
|
+
number: {
|
|
2528
|
+
type: "float32"
|
|
2529
|
+
},
|
|
2530
|
+
numeric: {
|
|
2531
|
+
type: "float32"
|
|
2532
|
+
},
|
|
2533
|
+
string: {
|
|
2534
|
+
type: "utf8"
|
|
2535
|
+
},
|
|
2536
|
+
vachar: {
|
|
2537
|
+
type: "utf8"
|
|
2538
|
+
},
|
|
2539
|
+
float: {
|
|
2540
|
+
type: "float32"
|
|
2541
|
+
},
|
|
2542
|
+
int: {
|
|
2543
|
+
type: "int32"
|
|
2544
|
+
},
|
|
2545
|
+
int4: {
|
|
2546
|
+
type: "int32"
|
|
2547
|
+
},
|
|
2548
|
+
boolean: {
|
|
2549
|
+
type: "boolean"
|
|
2550
|
+
},
|
|
2551
|
+
bool: {
|
|
2552
|
+
type: "boolean"
|
|
2553
|
+
}
|
|
2554
|
+
};
|
|
2458
2555
|
function attributeToField(attribute = {}) {
|
|
2459
2556
|
const fieldTypes = attributeTypeToFieldType(attribute.type);
|
|
2460
2557
|
return {
|
|
2461
2558
|
name: attribute.attribute,
|
|
2559
|
+
// what happens if attribute type is string...
|
|
2560
|
+
// filterProps: getFilterProps(fieldTypes.type, attribute),
|
|
2462
2561
|
...fieldTypes
|
|
2463
2562
|
};
|
|
2464
2563
|
}
|
|
@@ -2466,74 +2565,614 @@
|
|
|
2466
2565
|
const type = aType.toLowerCase();
|
|
2467
2566
|
if (!type || !attrTypeMap[type]) {
|
|
2468
2567
|
}
|
|
2469
|
-
return attrTypeMap[type] || {
|
|
2568
|
+
return attrTypeMap[type] || {
|
|
2569
|
+
type: "string"
|
|
2570
|
+
};
|
|
2470
2571
|
}
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2572
|
+
|
|
2573
|
+
// src/tilejson-loader.ts
|
|
2574
|
+
var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2575
|
+
var TileJSONLoader = {
|
|
2576
|
+
name: "TileJSON",
|
|
2577
|
+
id: "tilejson",
|
|
2578
|
+
module: "pmtiles",
|
|
2579
|
+
version: VERSION2,
|
|
2580
|
+
worker: true,
|
|
2581
|
+
extensions: ["json"],
|
|
2582
|
+
mimeTypes: ["application/json"],
|
|
2583
|
+
text: true,
|
|
2584
|
+
options: {
|
|
2585
|
+
tilejson: {}
|
|
2586
|
+
},
|
|
2587
|
+
parse: async (arrayBuffer, options) => {
|
|
2588
|
+
const jsonString = new TextDecoder().decode(arrayBuffer);
|
|
2589
|
+
const json = JSON.parse(jsonString);
|
|
2590
|
+
return parseTileJSON(json);
|
|
2591
|
+
},
|
|
2592
|
+
parseTextSync: (text, options) => {
|
|
2593
|
+
const json = JSON.parse(text);
|
|
2594
|
+
return parseTileJSON(json);
|
|
2595
|
+
}
|
|
2596
|
+
};
|
|
2597
|
+
|
|
2598
|
+
// ../loader-utils/src/lib/env-utils/assert.ts
|
|
2599
|
+
function assert(condition, message) {
|
|
2600
|
+
if (!condition) {
|
|
2601
|
+
throw new Error(message || "loader assertion failed.");
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
|
|
2605
|
+
// ../loader-utils/src/lib/env-utils/globals.ts
|
|
2606
|
+
var globals = {
|
|
2607
|
+
self: typeof self !== "undefined" && self,
|
|
2608
|
+
window: typeof window !== "undefined" && window,
|
|
2609
|
+
global: typeof global !== "undefined" && global,
|
|
2610
|
+
document: typeof document !== "undefined" && document
|
|
2611
|
+
};
|
|
2612
|
+
var self_ = globals.self || globals.window || globals.global || {};
|
|
2613
|
+
var window_ = globals.window || globals.self || globals.global || {};
|
|
2614
|
+
var global_ = globals.global || globals.self || globals.window || {};
|
|
2615
|
+
var document_ = globals.document || {};
|
|
2616
|
+
var isBrowser = (
|
|
2617
|
+
// @ts-ignore process does not exist on browser
|
|
2618
|
+
Boolean(typeof process !== "object" || String(process) !== "[object process]" || process.browser)
|
|
2619
|
+
);
|
|
2620
|
+
var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
2621
|
+
var nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
2622
|
+
|
|
2623
|
+
// ../loader-utils/src/lib/path-utils/file-aliases.ts
|
|
2624
|
+
var pathPrefix = "";
|
|
2625
|
+
var fileAliases = {};
|
|
2626
|
+
function resolvePath(filename) {
|
|
2627
|
+
for (const alias in fileAliases) {
|
|
2628
|
+
if (filename.startsWith(alias)) {
|
|
2629
|
+
const replacement = fileAliases[alias];
|
|
2630
|
+
filename = filename.replace(alias, replacement);
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
if (!filename.startsWith("http://") && !filename.startsWith("https://")) {
|
|
2634
|
+
filename = `${pathPrefix}${filename}`;
|
|
2635
|
+
}
|
|
2636
|
+
return filename;
|
|
2637
|
+
}
|
|
2638
|
+
|
|
2639
|
+
// ../loader-utils/src/lib/sources/data-source.ts
|
|
2640
|
+
var DataSource = class {
|
|
2641
|
+
/** A resolved fetch function extracted from loadOptions prop */
|
|
2642
|
+
/** The actual load options, if calling a loaders.gl loader */
|
|
2643
|
+
_needsRefresh = true;
|
|
2644
|
+
constructor(props) {
|
|
2645
|
+
this.props = {
|
|
2646
|
+
...props
|
|
2647
|
+
};
|
|
2648
|
+
this.loadOptions = {
|
|
2649
|
+
...props.loadOptions
|
|
2503
2650
|
};
|
|
2651
|
+
this.fetch = getFetchFunction(this.loadOptions);
|
|
2504
2652
|
}
|
|
2505
|
-
|
|
2653
|
+
setProps(props) {
|
|
2654
|
+
this.props = Object.assign(this.props, props);
|
|
2655
|
+
this.setNeedsRefresh();
|
|
2656
|
+
}
|
|
2657
|
+
/** Mark this data source as needing a refresh (redraw) */
|
|
2658
|
+
setNeedsRefresh() {
|
|
2659
|
+
this._needsRefresh = true;
|
|
2660
|
+
}
|
|
2661
|
+
/**
|
|
2662
|
+
* Does this data source need refreshing?
|
|
2663
|
+
* @note The specifics of the refresh mechanism depends on type of data source
|
|
2664
|
+
*/
|
|
2665
|
+
getNeedsRefresh(clear = true) {
|
|
2666
|
+
const needsRefresh = this._needsRefresh;
|
|
2667
|
+
if (clear) {
|
|
2668
|
+
this._needsRefresh = false;
|
|
2669
|
+
}
|
|
2670
|
+
return needsRefresh;
|
|
2671
|
+
}
|
|
2672
|
+
};
|
|
2673
|
+
function getFetchFunction(options) {
|
|
2674
|
+
const fetchFunction = options?.fetch;
|
|
2675
|
+
if (fetchFunction && typeof fetchFunction === "function") {
|
|
2676
|
+
return (url, fetchOptions2) => fetchFunction(url, fetchOptions2);
|
|
2677
|
+
}
|
|
2678
|
+
const fetchOptions = options?.fetch;
|
|
2679
|
+
if (fetchOptions && typeof fetchOptions !== "function") {
|
|
2680
|
+
return (url) => fetch(url, fetchOptions);
|
|
2681
|
+
}
|
|
2682
|
+
return (url) => fetch(url);
|
|
2683
|
+
}
|
|
2506
2684
|
|
|
2507
|
-
// src/
|
|
2508
|
-
var
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
}
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2685
|
+
// ../images/src/lib/utils/version.ts
|
|
2686
|
+
var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2687
|
+
|
|
2688
|
+
// ../images/src/lib/category-api/image-type.ts
|
|
2689
|
+
var {
|
|
2690
|
+
_parseImageNode
|
|
2691
|
+
} = globalThis;
|
|
2692
|
+
var IMAGE_SUPPORTED = typeof Image !== "undefined";
|
|
2693
|
+
var IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== "undefined";
|
|
2694
|
+
var NODE_IMAGE_SUPPORTED = Boolean(_parseImageNode);
|
|
2695
|
+
var DATA_SUPPORTED = isBrowser ? true : NODE_IMAGE_SUPPORTED;
|
|
2696
|
+
function isImageTypeSupported(type) {
|
|
2697
|
+
switch (type) {
|
|
2698
|
+
case "auto":
|
|
2699
|
+
return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;
|
|
2700
|
+
case "imagebitmap":
|
|
2701
|
+
return IMAGE_BITMAP_SUPPORTED;
|
|
2702
|
+
case "image":
|
|
2703
|
+
return IMAGE_SUPPORTED;
|
|
2704
|
+
case "data":
|
|
2705
|
+
return DATA_SUPPORTED;
|
|
2706
|
+
default:
|
|
2707
|
+
throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`);
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
function getDefaultImageType() {
|
|
2711
|
+
if (IMAGE_BITMAP_SUPPORTED) {
|
|
2712
|
+
return "imagebitmap";
|
|
2713
|
+
}
|
|
2714
|
+
if (IMAGE_SUPPORTED) {
|
|
2715
|
+
return "image";
|
|
2716
|
+
}
|
|
2717
|
+
if (DATA_SUPPORTED) {
|
|
2718
|
+
return "data";
|
|
2719
|
+
}
|
|
2720
|
+
throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js");
|
|
2721
|
+
}
|
|
2722
|
+
|
|
2723
|
+
// ../images/src/lib/category-api/parsed-image-api.ts
|
|
2724
|
+
function getImageType(image) {
|
|
2725
|
+
const format = getImageTypeOrNull(image);
|
|
2726
|
+
if (!format) {
|
|
2727
|
+
throw new Error("Not an image");
|
|
2728
|
+
}
|
|
2729
|
+
return format;
|
|
2730
|
+
}
|
|
2731
|
+
function getImageData(image) {
|
|
2732
|
+
switch (getImageType(image)) {
|
|
2733
|
+
case "data":
|
|
2734
|
+
return image;
|
|
2735
|
+
case "image":
|
|
2736
|
+
case "imagebitmap":
|
|
2737
|
+
const canvas = document.createElement("canvas");
|
|
2738
|
+
const context = canvas.getContext("2d");
|
|
2739
|
+
if (!context) {
|
|
2740
|
+
throw new Error("getImageData");
|
|
2741
|
+
}
|
|
2742
|
+
canvas.width = image.width;
|
|
2743
|
+
canvas.height = image.height;
|
|
2744
|
+
context.drawImage(image, 0, 0);
|
|
2745
|
+
return context.getImageData(0, 0, image.width, image.height);
|
|
2746
|
+
default:
|
|
2747
|
+
throw new Error("getImageData");
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
2750
|
+
function getImageTypeOrNull(image) {
|
|
2751
|
+
if (typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) {
|
|
2752
|
+
return "imagebitmap";
|
|
2753
|
+
}
|
|
2754
|
+
if (typeof Image !== "undefined" && image instanceof Image) {
|
|
2755
|
+
return "image";
|
|
2756
|
+
}
|
|
2757
|
+
if (image && typeof image === "object" && image.data && image.width && image.height) {
|
|
2758
|
+
return "data";
|
|
2759
|
+
}
|
|
2760
|
+
return null;
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
// ../images/src/lib/parsers/svg-utils.ts
|
|
2764
|
+
var SVG_DATA_URL_PATTERN = /^data:image\/svg\+xml/;
|
|
2765
|
+
var SVG_URL_PATTERN = /\.svg((\?|#).*)?$/;
|
|
2766
|
+
function isSVG(url) {
|
|
2767
|
+
return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url));
|
|
2768
|
+
}
|
|
2769
|
+
function getBlobOrSVGDataUrl(arrayBuffer, url) {
|
|
2770
|
+
if (isSVG(url)) {
|
|
2771
|
+
const textDecoder = new TextDecoder();
|
|
2772
|
+
let xmlText = textDecoder.decode(arrayBuffer);
|
|
2773
|
+
try {
|
|
2774
|
+
if (typeof unescape === "function" && typeof encodeURIComponent === "function") {
|
|
2775
|
+
xmlText = unescape(encodeURIComponent(xmlText));
|
|
2533
2776
|
}
|
|
2777
|
+
} catch (error) {
|
|
2778
|
+
throw new Error(error.message);
|
|
2779
|
+
}
|
|
2780
|
+
const src = `data:image/svg+xml;base64,${btoa(xmlText)}`;
|
|
2781
|
+
return src;
|
|
2782
|
+
}
|
|
2783
|
+
return getBlob(arrayBuffer, url);
|
|
2784
|
+
}
|
|
2785
|
+
function getBlob(arrayBuffer, url) {
|
|
2786
|
+
if (isSVG(url)) {
|
|
2787
|
+
throw new Error("SVG cannot be parsed directly to imagebitmap");
|
|
2788
|
+
}
|
|
2789
|
+
return new Blob([new Uint8Array(arrayBuffer)]);
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2792
|
+
// ../images/src/lib/parsers/parse-to-image.ts
|
|
2793
|
+
async function parseToImage(arrayBuffer, options, url) {
|
|
2794
|
+
const blobOrDataUrl = getBlobOrSVGDataUrl(arrayBuffer, url);
|
|
2795
|
+
const URL = self.URL || self.webkitURL;
|
|
2796
|
+
const objectUrl = typeof blobOrDataUrl !== "string" && URL.createObjectURL(blobOrDataUrl);
|
|
2797
|
+
try {
|
|
2798
|
+
return await loadToImage(objectUrl || blobOrDataUrl, options);
|
|
2799
|
+
} finally {
|
|
2800
|
+
if (objectUrl) {
|
|
2801
|
+
URL.revokeObjectURL(objectUrl);
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
async function loadToImage(url, options) {
|
|
2806
|
+
const image = new Image();
|
|
2807
|
+
image.src = url;
|
|
2808
|
+
if (options.image && options.image.decode && image.decode) {
|
|
2809
|
+
await image.decode();
|
|
2810
|
+
return image;
|
|
2811
|
+
}
|
|
2812
|
+
return await new Promise((resolve, reject) => {
|
|
2813
|
+
try {
|
|
2814
|
+
image.onload = () => resolve(image);
|
|
2815
|
+
image.onerror = (err) => reject(new Error(`Could not load image ${url}: ${err}`));
|
|
2816
|
+
} catch (error) {
|
|
2817
|
+
reject(error);
|
|
2818
|
+
}
|
|
2819
|
+
});
|
|
2820
|
+
}
|
|
2821
|
+
|
|
2822
|
+
// ../images/src/lib/parsers/parse-to-image-bitmap.ts
|
|
2823
|
+
var EMPTY_OBJECT = {};
|
|
2824
|
+
var imagebitmapOptionsSupported = true;
|
|
2825
|
+
async function parseToImageBitmap(arrayBuffer, options, url) {
|
|
2826
|
+
let blob;
|
|
2827
|
+
if (isSVG(url)) {
|
|
2828
|
+
const image = await parseToImage(arrayBuffer, options, url);
|
|
2829
|
+
blob = image;
|
|
2830
|
+
} else {
|
|
2831
|
+
blob = getBlob(arrayBuffer, url);
|
|
2832
|
+
}
|
|
2833
|
+
const imagebitmapOptions = options && options.imagebitmap;
|
|
2834
|
+
return await safeCreateImageBitmap(blob, imagebitmapOptions);
|
|
2835
|
+
}
|
|
2836
|
+
async function safeCreateImageBitmap(blob, imagebitmapOptions = null) {
|
|
2837
|
+
if (isEmptyObject(imagebitmapOptions) || !imagebitmapOptionsSupported) {
|
|
2838
|
+
imagebitmapOptions = null;
|
|
2839
|
+
}
|
|
2840
|
+
if (imagebitmapOptions) {
|
|
2841
|
+
try {
|
|
2842
|
+
return await createImageBitmap(blob, imagebitmapOptions);
|
|
2843
|
+
} catch (error) {
|
|
2844
|
+
console.warn(error);
|
|
2845
|
+
imagebitmapOptionsSupported = false;
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
return await createImageBitmap(blob);
|
|
2849
|
+
}
|
|
2850
|
+
function isEmptyObject(object) {
|
|
2851
|
+
for (const key in object || EMPTY_OBJECT) {
|
|
2852
|
+
return false;
|
|
2853
|
+
}
|
|
2854
|
+
return true;
|
|
2855
|
+
}
|
|
2856
|
+
|
|
2857
|
+
// ../images/src/lib/category-api/parse-isobmff-binary.ts
|
|
2858
|
+
function getISOBMFFMediaType(buffer) {
|
|
2859
|
+
if (!checkString(buffer, "ftyp", 4)) {
|
|
2860
|
+
return null;
|
|
2861
|
+
}
|
|
2862
|
+
if ((buffer[8] & 96) === 0) {
|
|
2863
|
+
return null;
|
|
2864
|
+
}
|
|
2865
|
+
return decodeMajorBrand(buffer);
|
|
2866
|
+
}
|
|
2867
|
+
function decodeMajorBrand(buffer) {
|
|
2868
|
+
const brandMajor = getUTF8String(buffer, 8, 12).replace("\0", " ").trim();
|
|
2869
|
+
switch (brandMajor) {
|
|
2870
|
+
case "avif":
|
|
2871
|
+
case "avis":
|
|
2872
|
+
return {
|
|
2873
|
+
extension: "avif",
|
|
2874
|
+
mimeType: "image/avif"
|
|
2875
|
+
};
|
|
2876
|
+
default:
|
|
2877
|
+
return null;
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
function getUTF8String(array, start, end) {
|
|
2881
|
+
return String.fromCharCode(...array.slice(start, end));
|
|
2882
|
+
}
|
|
2883
|
+
function stringToBytes(string) {
|
|
2884
|
+
return [...string].map((character) => character.charCodeAt(0));
|
|
2885
|
+
}
|
|
2886
|
+
function checkString(buffer, header, offset = 0) {
|
|
2887
|
+
const headerBytes = stringToBytes(header);
|
|
2888
|
+
for (let i2 = 0; i2 < headerBytes.length; ++i2) {
|
|
2889
|
+
if (headerBytes[i2] !== buffer[i2 + offset]) {
|
|
2890
|
+
return false;
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
return true;
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2896
|
+
// ../images/src/lib/category-api/binary-image-api.ts
|
|
2897
|
+
var BIG_ENDIAN = false;
|
|
2898
|
+
var LITTLE_ENDIAN = true;
|
|
2899
|
+
function getBinaryImageMetadata(binaryData) {
|
|
2900
|
+
const dataView = toDataView(binaryData);
|
|
2901
|
+
return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView) || getISOBMFFMetadata(dataView);
|
|
2902
|
+
}
|
|
2903
|
+
function getISOBMFFMetadata(binaryData) {
|
|
2904
|
+
const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData);
|
|
2905
|
+
const mediaType = getISOBMFFMediaType(buffer);
|
|
2906
|
+
if (!mediaType) {
|
|
2907
|
+
return null;
|
|
2908
|
+
}
|
|
2909
|
+
return {
|
|
2910
|
+
mimeType: mediaType.mimeType,
|
|
2911
|
+
// TODO - decode width and height
|
|
2912
|
+
width: 0,
|
|
2913
|
+
height: 0
|
|
2914
|
+
};
|
|
2915
|
+
}
|
|
2916
|
+
function getPngMetadata(binaryData) {
|
|
2917
|
+
const dataView = toDataView(binaryData);
|
|
2918
|
+
const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 2303741511;
|
|
2919
|
+
if (!isPng) {
|
|
2920
|
+
return null;
|
|
2921
|
+
}
|
|
2922
|
+
return {
|
|
2923
|
+
mimeType: "image/png",
|
|
2924
|
+
width: dataView.getUint32(16, BIG_ENDIAN),
|
|
2925
|
+
height: dataView.getUint32(20, BIG_ENDIAN)
|
|
2926
|
+
};
|
|
2927
|
+
}
|
|
2928
|
+
function getGifMetadata(binaryData) {
|
|
2929
|
+
const dataView = toDataView(binaryData);
|
|
2930
|
+
const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 1195984440;
|
|
2931
|
+
if (!isGif) {
|
|
2932
|
+
return null;
|
|
2933
|
+
}
|
|
2934
|
+
return {
|
|
2935
|
+
mimeType: "image/gif",
|
|
2936
|
+
width: dataView.getUint16(6, LITTLE_ENDIAN),
|
|
2937
|
+
height: dataView.getUint16(8, LITTLE_ENDIAN)
|
|
2938
|
+
};
|
|
2939
|
+
}
|
|
2940
|
+
function getBmpMetadata(binaryData) {
|
|
2941
|
+
const dataView = toDataView(binaryData);
|
|
2942
|
+
const isBmp = dataView.byteLength >= 14 && dataView.getUint16(0, BIG_ENDIAN) === 16973 && dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
|
|
2943
|
+
if (!isBmp) {
|
|
2944
|
+
return null;
|
|
2945
|
+
}
|
|
2946
|
+
return {
|
|
2947
|
+
mimeType: "image/bmp",
|
|
2948
|
+
width: dataView.getUint32(18, LITTLE_ENDIAN),
|
|
2949
|
+
height: dataView.getUint32(22, LITTLE_ENDIAN)
|
|
2950
|
+
};
|
|
2951
|
+
}
|
|
2952
|
+
function getJpegMetadata(binaryData) {
|
|
2953
|
+
const dataView = toDataView(binaryData);
|
|
2954
|
+
const isJpeg = dataView.byteLength >= 3 && dataView.getUint16(0, BIG_ENDIAN) === 65496 && dataView.getUint8(2) === 255;
|
|
2955
|
+
if (!isJpeg) {
|
|
2956
|
+
return null;
|
|
2957
|
+
}
|
|
2958
|
+
const {
|
|
2959
|
+
tableMarkers,
|
|
2960
|
+
sofMarkers
|
|
2961
|
+
} = getJpegMarkers();
|
|
2962
|
+
let i2 = 2;
|
|
2963
|
+
while (i2 + 9 < dataView.byteLength) {
|
|
2964
|
+
const marker = dataView.getUint16(i2, BIG_ENDIAN);
|
|
2965
|
+
if (sofMarkers.has(marker)) {
|
|
2966
|
+
return {
|
|
2967
|
+
mimeType: "image/jpeg",
|
|
2968
|
+
height: dataView.getUint16(i2 + 5, BIG_ENDIAN),
|
|
2969
|
+
// Number of lines
|
|
2970
|
+
width: dataView.getUint16(i2 + 7, BIG_ENDIAN)
|
|
2971
|
+
// Number of pixels per line
|
|
2972
|
+
};
|
|
2973
|
+
}
|
|
2974
|
+
if (!tableMarkers.has(marker)) {
|
|
2975
|
+
return null;
|
|
2976
|
+
}
|
|
2977
|
+
i2 += 2;
|
|
2978
|
+
i2 += dataView.getUint16(i2, BIG_ENDIAN);
|
|
2979
|
+
}
|
|
2980
|
+
return null;
|
|
2981
|
+
}
|
|
2982
|
+
function getJpegMarkers() {
|
|
2983
|
+
const tableMarkers = /* @__PURE__ */ new Set([65499, 65476, 65484, 65501, 65534]);
|
|
2984
|
+
for (let i2 = 65504; i2 < 65520; ++i2) {
|
|
2985
|
+
tableMarkers.add(i2);
|
|
2986
|
+
}
|
|
2987
|
+
const sofMarkers = /* @__PURE__ */ new Set([65472, 65473, 65474, 65475, 65477, 65478, 65479, 65481, 65482, 65483, 65485, 65486, 65487, 65502]);
|
|
2988
|
+
return {
|
|
2989
|
+
tableMarkers,
|
|
2990
|
+
sofMarkers
|
|
2991
|
+
};
|
|
2992
|
+
}
|
|
2993
|
+
function toDataView(data) {
|
|
2994
|
+
if (data instanceof DataView) {
|
|
2995
|
+
return data;
|
|
2996
|
+
}
|
|
2997
|
+
if (ArrayBuffer.isView(data)) {
|
|
2998
|
+
return new DataView(data.buffer);
|
|
2999
|
+
}
|
|
3000
|
+
if (data instanceof ArrayBuffer) {
|
|
3001
|
+
return new DataView(data);
|
|
3002
|
+
}
|
|
3003
|
+
throw new Error("toDataView");
|
|
3004
|
+
}
|
|
3005
|
+
|
|
3006
|
+
// ../images/src/lib/parsers/parse-to-node-image.ts
|
|
3007
|
+
async function parseToNodeImage(arrayBuffer, options) {
|
|
3008
|
+
const {
|
|
3009
|
+
mimeType
|
|
3010
|
+
} = getBinaryImageMetadata(arrayBuffer) || {};
|
|
3011
|
+
const _parseImageNode2 = globalThis._parseImageNode;
|
|
3012
|
+
assert(_parseImageNode2);
|
|
3013
|
+
return await _parseImageNode2(arrayBuffer, mimeType);
|
|
3014
|
+
}
|
|
3015
|
+
|
|
3016
|
+
// ../images/src/lib/parsers/parse-image.ts
|
|
3017
|
+
async function parseImage(arrayBuffer, options, context) {
|
|
3018
|
+
options = options || {};
|
|
3019
|
+
const imageOptions = options.image || {};
|
|
3020
|
+
const imageType = imageOptions.type || "auto";
|
|
3021
|
+
const {
|
|
3022
|
+
url
|
|
3023
|
+
} = context || {};
|
|
3024
|
+
const loadType = getLoadableImageType(imageType);
|
|
3025
|
+
let image;
|
|
3026
|
+
switch (loadType) {
|
|
3027
|
+
case "imagebitmap":
|
|
3028
|
+
image = await parseToImageBitmap(arrayBuffer, options, url);
|
|
3029
|
+
break;
|
|
3030
|
+
case "image":
|
|
3031
|
+
image = await parseToImage(arrayBuffer, options, url);
|
|
3032
|
+
break;
|
|
3033
|
+
case "data":
|
|
3034
|
+
image = await parseToNodeImage(arrayBuffer, options);
|
|
3035
|
+
break;
|
|
3036
|
+
default:
|
|
3037
|
+
assert(false);
|
|
3038
|
+
}
|
|
3039
|
+
if (imageType === "data") {
|
|
3040
|
+
image = getImageData(image);
|
|
3041
|
+
}
|
|
3042
|
+
return image;
|
|
3043
|
+
}
|
|
3044
|
+
function getLoadableImageType(type) {
|
|
3045
|
+
switch (type) {
|
|
3046
|
+
case "auto":
|
|
3047
|
+
case "data":
|
|
3048
|
+
return getDefaultImageType();
|
|
3049
|
+
default:
|
|
3050
|
+
isImageTypeSupported(type);
|
|
3051
|
+
return type;
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
|
|
3055
|
+
// ../images/src/image-loader.ts
|
|
3056
|
+
var EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp", "bmp", "ico", "svg", "avif"];
|
|
3057
|
+
var MIME_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif", "image/bmp", "image/vnd.microsoft.icon", "image/svg+xml"];
|
|
3058
|
+
var DEFAULT_IMAGE_LOADER_OPTIONS = {
|
|
3059
|
+
image: {
|
|
3060
|
+
type: "auto",
|
|
3061
|
+
decode: true
|
|
3062
|
+
// if format is HTML
|
|
3063
|
+
}
|
|
3064
|
+
// imagebitmap: {} - passes (platform dependent) parameters to ImageBitmap constructor
|
|
3065
|
+
};
|
|
3066
|
+
var ImageLoader = {
|
|
3067
|
+
id: "image",
|
|
3068
|
+
module: "images",
|
|
3069
|
+
name: "Images",
|
|
3070
|
+
version: VERSION3,
|
|
3071
|
+
mimeTypes: MIME_TYPES,
|
|
3072
|
+
extensions: EXTENSIONS,
|
|
3073
|
+
parse: parseImage,
|
|
3074
|
+
// TODO: byteOffset, byteLength;
|
|
3075
|
+
tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],
|
|
3076
|
+
options: DEFAULT_IMAGE_LOADER_OPTIONS
|
|
3077
|
+
};
|
|
3078
|
+
|
|
3079
|
+
// src/mvt-source.ts
|
|
3080
|
+
var MVTSource = class extends DataSource {
|
|
3081
|
+
schema = "tms";
|
|
3082
|
+
constructor(props) {
|
|
3083
|
+
super(props);
|
|
3084
|
+
this.props = props;
|
|
3085
|
+
this.url = resolvePath(props.url);
|
|
3086
|
+
this.getTileData = this.getTileData.bind(this);
|
|
3087
|
+
this.metadata = this.getMetadata();
|
|
3088
|
+
}
|
|
3089
|
+
// @ts-ignore - Metadata type misalignment
|
|
3090
|
+
async getMetadata() {
|
|
3091
|
+
const metadataUrl = this.getMetadataUrl();
|
|
3092
|
+
const response = await this.fetch(metadataUrl);
|
|
3093
|
+
if (!response.ok) {
|
|
3094
|
+
return null;
|
|
3095
|
+
}
|
|
3096
|
+
const tileJSON = await response.text();
|
|
3097
|
+
const metadata = TileJSONLoader.parseTextSync?.(JSON.stringify(tileJSON)) || null;
|
|
3098
|
+
return metadata;
|
|
3099
|
+
}
|
|
3100
|
+
async getTile(tileParams) {
|
|
3101
|
+
const {
|
|
3102
|
+
x: x2,
|
|
3103
|
+
y: y2,
|
|
3104
|
+
zoom: z
|
|
3105
|
+
} = tileParams;
|
|
3106
|
+
const tileUrl = this.getTileURL(x2, y2, z);
|
|
3107
|
+
const response = await this.fetch(tileUrl);
|
|
3108
|
+
if (!response.ok) {
|
|
3109
|
+
return null;
|
|
3110
|
+
}
|
|
3111
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
3112
|
+
return arrayBuffer;
|
|
3113
|
+
}
|
|
3114
|
+
// Tile Source interface implementation: deck.gl compatible API
|
|
3115
|
+
// TODO - currently only handles image tiles, not vector tiles
|
|
3116
|
+
async getTileData(tileParams) {
|
|
3117
|
+
const {
|
|
3118
|
+
x: x2,
|
|
3119
|
+
y: y2,
|
|
3120
|
+
z
|
|
3121
|
+
} = tileParams.index;
|
|
3122
|
+
const metadata = await this.metadata;
|
|
3123
|
+
switch (metadata.mimeType || "application/vnd.mapbox-vector-tile") {
|
|
3124
|
+
case "application/vnd.mapbox-vector-tile":
|
|
3125
|
+
return await this.getVectorTile({
|
|
3126
|
+
x: x2,
|
|
3127
|
+
y: y2,
|
|
3128
|
+
zoom: z,
|
|
3129
|
+
layers: []
|
|
3130
|
+
});
|
|
3131
|
+
default:
|
|
3132
|
+
return await this.getImageTile({
|
|
3133
|
+
x: x2,
|
|
3134
|
+
y: y2,
|
|
3135
|
+
zoom: z,
|
|
3136
|
+
layers: []
|
|
3137
|
+
});
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
// ImageTileSource interface implementation
|
|
3141
|
+
async getImageTile(tileParams) {
|
|
3142
|
+
const arrayBuffer = await this.getTile(tileParams);
|
|
3143
|
+
return arrayBuffer ? await ImageLoader.parse(arrayBuffer, this.loadOptions) : null;
|
|
3144
|
+
}
|
|
3145
|
+
// VectorTileSource interface implementation
|
|
3146
|
+
async getVectorTile(tileParams) {
|
|
3147
|
+
const arrayBuffer = await this.getTile(tileParams);
|
|
3148
|
+
const loadOptions = {
|
|
3149
|
+
shape: "geojson-table",
|
|
3150
|
+
mvt: {
|
|
3151
|
+
coordinates: "wgs84",
|
|
3152
|
+
tileIndex: {
|
|
3153
|
+
x: tileParams.x,
|
|
3154
|
+
y: tileParams.y,
|
|
3155
|
+
z: tileParams.zoom
|
|
3156
|
+
},
|
|
3157
|
+
...this.loadOptions?.mvt
|
|
3158
|
+
},
|
|
3159
|
+
...this.loadOptions
|
|
2534
3160
|
};
|
|
3161
|
+
return arrayBuffer ? await MVTLoader.parse(arrayBuffer, loadOptions) : null;
|
|
2535
3162
|
}
|
|
2536
|
-
|
|
3163
|
+
getMetadataUrl() {
|
|
3164
|
+
return `${this.url}/tilejson.json`;
|
|
3165
|
+
}
|
|
3166
|
+
getTileURL(x2, y2, z) {
|
|
3167
|
+
switch (this.schema) {
|
|
3168
|
+
case "xyz":
|
|
3169
|
+
return `${this.url}/${x2}/${y2}/${z}`;
|
|
3170
|
+
case "tms":
|
|
3171
|
+
default:
|
|
3172
|
+
return `${this.url}/${z}/${x2}/${y2}`;
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
};
|
|
2537
3176
|
|
|
2538
3177
|
// src/lib/geojson-tiler/simplify.ts
|
|
2539
3178
|
function simplify(coords, first, last, sqTolerance) {
|
|
@@ -2583,14 +3222,11 @@
|
|
|
2583
3222
|
dy = py - y2;
|
|
2584
3223
|
return dx * dx + dy * dy;
|
|
2585
3224
|
}
|
|
2586
|
-
var init_simplify = __esm({
|
|
2587
|
-
"src/lib/geojson-tiler/simplify.ts"() {
|
|
2588
|
-
}
|
|
2589
|
-
});
|
|
2590
3225
|
|
|
2591
3226
|
// src/lib/geojson-tiler/feature.ts
|
|
2592
3227
|
function createFeature(id, type, geom, tags) {
|
|
2593
3228
|
const feature = {
|
|
3229
|
+
// eslint-disable-next-line
|
|
2594
3230
|
id: id == null ? null : id,
|
|
2595
3231
|
type,
|
|
2596
3232
|
geometry: geom,
|
|
@@ -2623,10 +3259,6 @@
|
|
|
2623
3259
|
feature.maxY = Math.max(feature.maxY, geom[i2 + 1]);
|
|
2624
3260
|
}
|
|
2625
3261
|
}
|
|
2626
|
-
var init_feature = __esm({
|
|
2627
|
-
"src/lib/geojson-tiler/feature.ts"() {
|
|
2628
|
-
}
|
|
2629
|
-
});
|
|
2630
3262
|
|
|
2631
3263
|
// src/lib/geojson-tiler/convert.ts
|
|
2632
3264
|
function convert(data, options) {
|
|
@@ -2638,7 +3270,9 @@
|
|
|
2638
3270
|
} else if (data.type === "Feature") {
|
|
2639
3271
|
convertFeature(features, data, options);
|
|
2640
3272
|
} else {
|
|
2641
|
-
convertFeature(features, {
|
|
3273
|
+
convertFeature(features, {
|
|
3274
|
+
geometry: data
|
|
3275
|
+
}, options);
|
|
2642
3276
|
}
|
|
2643
3277
|
return features;
|
|
2644
3278
|
}
|
|
@@ -2740,12 +3374,6 @@
|
|
|
2740
3374
|
const y22 = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
|
|
2741
3375
|
return y22 < 0 ? 0 : y22 > 1 ? 1 : y22;
|
|
2742
3376
|
}
|
|
2743
|
-
var init_convert = __esm({
|
|
2744
|
-
"src/lib/geojson-tiler/convert.ts"() {
|
|
2745
|
-
init_simplify();
|
|
2746
|
-
init_feature();
|
|
2747
|
-
}
|
|
2748
|
-
});
|
|
2749
3377
|
|
|
2750
3378
|
// src/lib/geojson-tiler/clip.ts
|
|
2751
3379
|
function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
|
|
@@ -2911,11 +3539,6 @@
|
|
|
2911
3539
|
addPoint(out, ax + (bx - ax) * t, y2, 1);
|
|
2912
3540
|
return t;
|
|
2913
3541
|
}
|
|
2914
|
-
var init_clip = __esm({
|
|
2915
|
-
"src/lib/geojson-tiler/clip.ts"() {
|
|
2916
|
-
init_feature();
|
|
2917
|
-
}
|
|
2918
|
-
});
|
|
2919
3542
|
|
|
2920
3543
|
// src/lib/geojson-tiler/wrap.ts
|
|
2921
3544
|
function wrap(features, options) {
|
|
@@ -2973,12 +3596,6 @@
|
|
|
2973
3596
|
}
|
|
2974
3597
|
return newPoints;
|
|
2975
3598
|
}
|
|
2976
|
-
var init_wrap = __esm({
|
|
2977
|
-
"src/lib/geojson-tiler/wrap.ts"() {
|
|
2978
|
-
init_clip();
|
|
2979
|
-
init_feature();
|
|
2980
|
-
}
|
|
2981
|
-
});
|
|
2982
3599
|
|
|
2983
3600
|
// src/lib/geojson-tiler/transform.ts
|
|
2984
3601
|
function transformTile(tile, extent) {
|
|
@@ -3012,10 +3629,6 @@
|
|
|
3012
3629
|
function transformPoint(x2, y2, extent, z2, tx, ty) {
|
|
3013
3630
|
return [Math.round(extent * (x2 * z2 - tx)), Math.round(extent * (y2 * z2 - ty))];
|
|
3014
3631
|
}
|
|
3015
|
-
var init_transform = __esm({
|
|
3016
|
-
"src/lib/geojson-tiler/transform.ts"() {
|
|
3017
|
-
}
|
|
3018
|
-
});
|
|
3019
3632
|
|
|
3020
3633
|
// src/lib/geojson-tiler/tile.ts
|
|
3021
3634
|
function createTile(features, z, tx, ty, options) {
|
|
@@ -3122,207 +3735,213 @@
|
|
|
3122
3735
|
}
|
|
3123
3736
|
}
|
|
3124
3737
|
}
|
|
3125
|
-
var init_tile = __esm({
|
|
3126
|
-
"src/lib/geojson-tiler/tile.ts"() {
|
|
3127
|
-
}
|
|
3128
|
-
});
|
|
3129
3738
|
|
|
3130
3739
|
// src/lib/geojson-tiler/geojson-tiler.ts
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3740
|
+
var DEFAULT_OPTIONS = {
|
|
3741
|
+
maxZoom: 14,
|
|
3742
|
+
// max zoom to preserve detail on
|
|
3743
|
+
indexMaxZoom: 5,
|
|
3744
|
+
// max zoom in the tile index
|
|
3745
|
+
indexMaxPoints: 1e5,
|
|
3746
|
+
// max number of points per tile in the tile index
|
|
3747
|
+
tolerance: 3,
|
|
3748
|
+
// simplification tolerance (higher means simpler)
|
|
3749
|
+
extent: 4096,
|
|
3750
|
+
// tile extent
|
|
3751
|
+
buffer: 64,
|
|
3752
|
+
// tile buffer on each side
|
|
3753
|
+
lineMetrics: false,
|
|
3754
|
+
// whether to calculate line metrics
|
|
3755
|
+
// @ts-expect-error Ensures all these required params have defaults
|
|
3756
|
+
promoteId: void 0,
|
|
3757
|
+
// name of a feature property to be promoted to feature.id
|
|
3758
|
+
generateId: false,
|
|
3759
|
+
// whether to generate feature ids. Cannot be used with promoteId
|
|
3760
|
+
debug: 0
|
|
3761
|
+
// logging level (0, 1 or 2)
|
|
3762
|
+
};
|
|
3763
|
+
var GeoJSONTiler = class {
|
|
3764
|
+
// tiles and tileCoords are part of the public API
|
|
3765
|
+
tiles = {};
|
|
3766
|
+
tileCoords = [];
|
|
3767
|
+
stats = {};
|
|
3768
|
+
total = 0;
|
|
3769
|
+
constructor(data, options) {
|
|
3770
|
+
this.options = {
|
|
3771
|
+
...DEFAULT_OPTIONS,
|
|
3772
|
+
...options
|
|
3153
3773
|
};
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3774
|
+
options = this.options;
|
|
3775
|
+
const debug = options.debug;
|
|
3776
|
+
if (debug)
|
|
3777
|
+
console.time("preprocess data");
|
|
3778
|
+
if (this.options.maxZoom < 0 || this.options.maxZoom > 24) {
|
|
3779
|
+
throw new Error("maxZoom should be in the 0-24 range");
|
|
3780
|
+
}
|
|
3781
|
+
if (options.promoteId && this.options.generateId) {
|
|
3782
|
+
throw new Error("promoteId and generateId cannot be used together.");
|
|
3783
|
+
}
|
|
3784
|
+
let features = convert(data, options);
|
|
3785
|
+
if (debug) {
|
|
3786
|
+
console.timeEnd("preprocess data");
|
|
3787
|
+
console.log("index: maxZoom: %d, maxPoints: %d", options.indexMaxZoom, options.indexMaxPoints);
|
|
3788
|
+
console.time("generate tiles");
|
|
3789
|
+
}
|
|
3790
|
+
features = wrap(features, this.options);
|
|
3791
|
+
if (features.length) {
|
|
3792
|
+
this.splitTile(features, 0, 0, 0);
|
|
3793
|
+
}
|
|
3794
|
+
if (debug) {
|
|
3795
|
+
if (features.length) {
|
|
3796
|
+
console.log("features: %d, points: %d", this.tiles[0].numFeatures, this.tiles[0].numPoints);
|
|
3797
|
+
}
|
|
3798
|
+
console.timeEnd("generate tiles");
|
|
3799
|
+
console.log("tiles generated:", this.total, JSON.stringify(this.stats));
|
|
3800
|
+
}
|
|
3801
|
+
}
|
|
3802
|
+
/**
|
|
3803
|
+
* Get a tile at the specified index
|
|
3804
|
+
* @param z
|
|
3805
|
+
* @param x
|
|
3806
|
+
* @param y
|
|
3807
|
+
* @returns
|
|
3808
|
+
*/
|
|
3809
|
+
// eslint-disable-next-line complexity, max-statements
|
|
3810
|
+
getTile(z, x2, y2) {
|
|
3811
|
+
const {
|
|
3812
|
+
extent,
|
|
3813
|
+
debug
|
|
3814
|
+
} = this.options;
|
|
3815
|
+
if (z < 0 || z > 24) {
|
|
3816
|
+
return null;
|
|
3817
|
+
}
|
|
3818
|
+
const z2 = 1 << z;
|
|
3819
|
+
x2 = x2 + z2 & z2 - 1;
|
|
3820
|
+
const id = toID(z, x2, y2);
|
|
3821
|
+
if (this.tiles[id]) {
|
|
3822
|
+
return transformTile(this.tiles[id], extent);
|
|
3823
|
+
}
|
|
3824
|
+
if (debug > 1)
|
|
3825
|
+
console.log("drilling down to z%d-%d-%d", z, x2, y2);
|
|
3826
|
+
let z0 = z;
|
|
3827
|
+
let x0 = x2;
|
|
3828
|
+
let y0 = y2;
|
|
3829
|
+
let parent;
|
|
3830
|
+
while (!parent && z0 > 0) {
|
|
3831
|
+
z0--;
|
|
3832
|
+
x0 = x0 >> 1;
|
|
3833
|
+
y0 = y0 >> 1;
|
|
3834
|
+
parent = this.tiles[toID(z0, x0, y0)];
|
|
3835
|
+
}
|
|
3836
|
+
if (!parent || !parent.source) {
|
|
3837
|
+
return null;
|
|
3838
|
+
}
|
|
3839
|
+
if (debug > 1) {
|
|
3840
|
+
console.log("found parent tile z%d-%d-%d", z0, x0, y0);
|
|
3841
|
+
console.time("drilling down");
|
|
3842
|
+
}
|
|
3843
|
+
this.splitTile(parent.source, z0, x0, y0, z, x2, y2);
|
|
3844
|
+
if (debug > 1) {
|
|
3845
|
+
console.timeEnd("drilling down");
|
|
3846
|
+
}
|
|
3847
|
+
return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
|
|
3848
|
+
}
|
|
3849
|
+
/**
|
|
3850
|
+
* splits features from a parent tile to sub-tiles.
|
|
3851
|
+
* @param z, x, and y are the coordinates of the parent tile
|
|
3852
|
+
* @param cz, cx, and cy are the coordinates of the target tile
|
|
3853
|
+
*
|
|
3854
|
+
* If no target tile is specified, splitting stops when we reach the maximum
|
|
3855
|
+
* zoom or the number of points is low as specified in the options.
|
|
3856
|
+
*/
|
|
3857
|
+
// eslint-disable-next-line max-params, max-statements, complexity
|
|
3858
|
+
splitTile(features, z, x2, y2, cz, cx, cy) {
|
|
3859
|
+
const stack = [features, z, x2, y2];
|
|
3860
|
+
const options = this.options;
|
|
3861
|
+
const debug = options.debug;
|
|
3862
|
+
while (stack.length) {
|
|
3863
|
+
y2 = stack.pop();
|
|
3864
|
+
x2 = stack.pop();
|
|
3865
|
+
z = stack.pop();
|
|
3866
|
+
features = stack.pop();
|
|
3867
|
+
const z2 = 1 << z;
|
|
3868
|
+
const id = toID(z, x2, y2);
|
|
3869
|
+
let tile = this.tiles[id];
|
|
3870
|
+
if (!tile) {
|
|
3871
|
+
if (debug > 1) {
|
|
3872
|
+
console.time("creation");
|
|
3180
3873
|
}
|
|
3874
|
+
tile = this.tiles[id] = createTile(features, z, x2, y2, options);
|
|
3875
|
+
this.tileCoords.push({
|
|
3876
|
+
z,
|
|
3877
|
+
x: x2,
|
|
3878
|
+
y: y2
|
|
3879
|
+
});
|
|
3181
3880
|
if (debug) {
|
|
3182
|
-
if (
|
|
3183
|
-
console.log("features: %d, points: %d",
|
|
3881
|
+
if (debug > 1) {
|
|
3882
|
+
console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)", z, x2, y2, tile.numFeatures, tile.numPoints, tile.numSimplified);
|
|
3883
|
+
console.timeEnd("creation");
|
|
3184
3884
|
}
|
|
3185
|
-
|
|
3186
|
-
|
|
3885
|
+
const key = `z${z}`;
|
|
3886
|
+
this.stats[key] = (this.stats[key] || 0) + 1;
|
|
3887
|
+
this.total++;
|
|
3187
3888
|
}
|
|
3188
3889
|
}
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
if (z
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
const
|
|
3197
|
-
if (
|
|
3198
|
-
|
|
3199
|
-
}
|
|
3200
|
-
if (debug > 1)
|
|
3201
|
-
console.log("drilling down to z%d-%d-%d", z, x2, y2);
|
|
3202
|
-
let z0 = z;
|
|
3203
|
-
let x0 = x2;
|
|
3204
|
-
let y0 = y2;
|
|
3205
|
-
let parent;
|
|
3206
|
-
while (!parent && z0 > 0) {
|
|
3207
|
-
z0--;
|
|
3208
|
-
x0 = x0 >> 1;
|
|
3209
|
-
y0 = y0 >> 1;
|
|
3210
|
-
parent = this.tiles[toID(z0, x0, y0)];
|
|
3211
|
-
}
|
|
3212
|
-
if (!parent || !parent.source) {
|
|
3213
|
-
return null;
|
|
3214
|
-
}
|
|
3215
|
-
if (debug > 1) {
|
|
3216
|
-
console.log("found parent tile z%d-%d-%d", z0, x0, y0);
|
|
3217
|
-
console.time("drilling down");
|
|
3218
|
-
}
|
|
3219
|
-
this.splitTile(parent.source, z0, x0, y0, z, x2, y2);
|
|
3220
|
-
if (debug > 1) {
|
|
3221
|
-
console.timeEnd("drilling down");
|
|
3222
|
-
}
|
|
3223
|
-
return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
|
|
3890
|
+
tile.source = features;
|
|
3891
|
+
if (cz === void 0) {
|
|
3892
|
+
if (z === options.indexMaxZoom || tile.numPoints <= options.indexMaxPoints)
|
|
3893
|
+
continue;
|
|
3894
|
+
} else if (z === options.maxZoom || z === cz) {
|
|
3895
|
+
continue;
|
|
3896
|
+
} else if (cz !== void 0) {
|
|
3897
|
+
const zoomSteps = cz - z;
|
|
3898
|
+
if (x2 !== cx >> zoomSteps || y2 !== cy >> zoomSteps)
|
|
3899
|
+
continue;
|
|
3224
3900
|
}
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)", z, x2, y2, tile.numFeatures, tile.numPoints, tile.numSimplified);
|
|
3246
|
-
console.timeEnd("creation");
|
|
3247
|
-
}
|
|
3248
|
-
const key = `z${z}`;
|
|
3249
|
-
this.stats[key] = (this.stats[key] || 0) + 1;
|
|
3250
|
-
this.total++;
|
|
3251
|
-
}
|
|
3252
|
-
}
|
|
3253
|
-
tile.source = features;
|
|
3254
|
-
if (cz === void 0) {
|
|
3255
|
-
if (z === options.indexMaxZoom || tile.numPoints <= options.indexMaxPoints)
|
|
3256
|
-
continue;
|
|
3257
|
-
} else if (z === options.maxZoom || z === cz) {
|
|
3258
|
-
continue;
|
|
3259
|
-
} else if (cz !== void 0) {
|
|
3260
|
-
const zoomSteps = cz - z;
|
|
3261
|
-
if (x2 !== cx >> zoomSteps || y2 !== cy >> zoomSteps)
|
|
3262
|
-
continue;
|
|
3263
|
-
}
|
|
3264
|
-
tile.source = null;
|
|
3265
|
-
if (features.length === 0)
|
|
3266
|
-
continue;
|
|
3267
|
-
if (debug > 1)
|
|
3268
|
-
console.time("clipping");
|
|
3269
|
-
const k1 = 0.5 * options.buffer / options.extent;
|
|
3270
|
-
const k2 = 0.5 - k1;
|
|
3271
|
-
const k3 = 0.5 + k1;
|
|
3272
|
-
const k4 = 1 + k1;
|
|
3273
|
-
let tl = null;
|
|
3274
|
-
let bl = null;
|
|
3275
|
-
let tr = null;
|
|
3276
|
-
let br = null;
|
|
3277
|
-
let left = clip(features, z2, x2 - k1, x2 + k3, 0, tile.minX, tile.maxX, options);
|
|
3278
|
-
let right = clip(features, z2, x2 + k2, x2 + k4, 0, tile.minX, tile.maxX, options);
|
|
3279
|
-
features = null;
|
|
3280
|
-
if (left) {
|
|
3281
|
-
tl = clip(left, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
|
|
3282
|
-
bl = clip(left, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
|
|
3283
|
-
left = null;
|
|
3284
|
-
}
|
|
3285
|
-
if (right) {
|
|
3286
|
-
tr = clip(right, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
|
|
3287
|
-
br = clip(right, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
|
|
3288
|
-
right = null;
|
|
3289
|
-
}
|
|
3290
|
-
if (debug > 1)
|
|
3291
|
-
console.timeEnd("clipping");
|
|
3292
|
-
stack.push(tl || [], z + 1, x2 * 2, y2 * 2);
|
|
3293
|
-
stack.push(bl || [], z + 1, x2 * 2, y2 * 2 + 1);
|
|
3294
|
-
stack.push(tr || [], z + 1, x2 * 2 + 1, y2 * 2);
|
|
3295
|
-
stack.push(br || [], z + 1, x2 * 2 + 1, y2 * 2 + 1);
|
|
3296
|
-
}
|
|
3901
|
+
tile.source = null;
|
|
3902
|
+
if (features.length === 0)
|
|
3903
|
+
continue;
|
|
3904
|
+
if (debug > 1)
|
|
3905
|
+
console.time("clipping");
|
|
3906
|
+
const k1 = 0.5 * options.buffer / options.extent;
|
|
3907
|
+
const k2 = 0.5 - k1;
|
|
3908
|
+
const k3 = 0.5 + k1;
|
|
3909
|
+
const k4 = 1 + k1;
|
|
3910
|
+
let tl = null;
|
|
3911
|
+
let bl = null;
|
|
3912
|
+
let tr = null;
|
|
3913
|
+
let br = null;
|
|
3914
|
+
let left = clip(features, z2, x2 - k1, x2 + k3, 0, tile.minX, tile.maxX, options);
|
|
3915
|
+
let right = clip(features, z2, x2 + k2, x2 + k4, 0, tile.minX, tile.maxX, options);
|
|
3916
|
+
features = null;
|
|
3917
|
+
if (left) {
|
|
3918
|
+
tl = clip(left, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
|
|
3919
|
+
bl = clip(left, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
|
|
3920
|
+
left = null;
|
|
3297
3921
|
}
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
var init_src2 = __esm({
|
|
3311
|
-
"src/index.ts"() {
|
|
3312
|
-
init_mvt_loader();
|
|
3313
|
-
init_tilejson_loader();
|
|
3314
|
-
init_geojson_tiler();
|
|
3315
|
-
}
|
|
3316
|
-
});
|
|
3317
|
-
|
|
3318
|
-
// src/bundle.ts
|
|
3319
|
-
var require_bundle = __commonJS({
|
|
3320
|
-
"src/bundle.ts"(exports, module) {
|
|
3321
|
-
var moduleExports = (init_src2(), src_exports);
|
|
3322
|
-
globalThis.loaders = globalThis.loaders || {};
|
|
3323
|
-
module.exports = Object.assign(globalThis.loaders, moduleExports);
|
|
3922
|
+
if (right) {
|
|
3923
|
+
tr = clip(right, z2, y2 - k1, y2 + k3, 1, tile.minY, tile.maxY, options);
|
|
3924
|
+
br = clip(right, z2, y2 + k2, y2 + k4, 1, tile.minY, tile.maxY, options);
|
|
3925
|
+
right = null;
|
|
3926
|
+
}
|
|
3927
|
+
if (debug > 1)
|
|
3928
|
+
console.timeEnd("clipping");
|
|
3929
|
+
stack.push(tl || [], z + 1, x2 * 2, y2 * 2);
|
|
3930
|
+
stack.push(bl || [], z + 1, x2 * 2, y2 * 2 + 1);
|
|
3931
|
+
stack.push(tr || [], z + 1, x2 * 2 + 1, y2 * 2);
|
|
3932
|
+
stack.push(br || [], z + 1, x2 * 2 + 1, y2 * 2 + 1);
|
|
3933
|
+
}
|
|
3324
3934
|
}
|
|
3325
|
-
}
|
|
3326
|
-
|
|
3935
|
+
};
|
|
3936
|
+
function toID(z, x2, y2) {
|
|
3937
|
+
return ((1 << z) * y2 + x2) * 32 + z;
|
|
3938
|
+
}
|
|
3939
|
+
return __toCommonJS(src_exports);
|
|
3327
3940
|
})();
|
|
3328
|
-
/*!
|
|
3941
|
+
/*! Bundled license information:
|
|
3942
|
+
|
|
3943
|
+
ieee754/index.js:
|
|
3944
|
+
(*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
|
3945
|
+
*/
|
|
3946
|
+
return __exports__;
|
|
3947
|
+
});
|