@maplibre/geojson-vt 6.0.4 → 6.0.5
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/clip.d.ts.map +1 -1
- package/dist/convert.d.ts.map +1 -1
- package/dist/deconvert.d.ts +1 -1
- package/dist/deconvert.d.ts.map +1 -1
- package/dist/definitions.d.ts +12 -5
- package/dist/definitions.d.ts.map +1 -1
- package/dist/difference.d.ts +1 -1
- package/dist/difference.d.ts.map +1 -1
- package/dist/feature.d.ts +2 -1
- package/dist/feature.d.ts.map +1 -1
- package/dist/geojson-vt-dev.js +87 -58
- package/dist/geojson-vt.js +1 -1
- package/dist/geojson-vt.mjs +87 -58
- package/dist/geojson-vt.mjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/tile.d.ts.map +1 -1
- package/dist/wrap.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/clip.test.ts +21 -22
- package/src/clip.ts +37 -35
- package/src/convert.ts +17 -16
- package/src/deconvert.test.ts +7 -7
- package/src/deconvert.ts +8 -4
- package/src/definitions.ts +7 -5
- package/src/difference.test.ts +2 -2
- package/src/difference.ts +3 -3
- package/src/feature.ts +16 -6
- package/src/index.ts +3 -2
- package/src/tile.ts +6 -6
- package/src/wrap.ts +38 -18
package/dist/clip.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clip.d.ts","sourceRoot":"","sources":["../src/clip.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAyN,gBAAgB,
|
|
1
|
+
{"version":3,"file":"clip.d.ts","sourceRoot":"","sources":["../src/clip.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAyN,gBAAgB,EAA+B,MAAM,eAAe,CAAC;AAEpU,0BAAkB,QAAQ;IACtB,CAAC,IAAI;IACL,CAAC,IAAI;CACR;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,wBAAwB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,wBAAwB,EAAE,GAAG,IAAI,CA2DlN"}
|
package/dist/convert.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,wBAAwB,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,wBAAwB,EAAE,gBAAgB,EAAa,MAAM,eAAe,CAAC;AAE1F;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,gBAAgB,GAAG,wBAAwB,EAAE,CAiB9G;AA8JD;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,UAEjC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,UAIjC"}
|
package/dist/deconvert.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare function convertToGeoJSON(source: GeoJSONVTInternalFeature[]): Ge
|
|
|
7
7
|
* Converts a single internal feature to GeoJSON format.
|
|
8
8
|
*/
|
|
9
9
|
export declare function featureToGeoJSON(feature: GeoJSONVTInternalFeature): GeoJSON.Feature;
|
|
10
|
-
export declare function unprojectPoints(coords: number[]): GeoJSON.Position[];
|
|
10
|
+
export declare function unprojectPoints(coords: number[] | Float64Array): GeoJSON.Position[];
|
|
11
11
|
/**
|
|
12
12
|
* Convert spherical mercator in [0..1] range to longitude
|
|
13
13
|
*/
|
package/dist/deconvert.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deconvert.d.ts","sourceRoot":"","sources":["../src/deconvert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,eAAe,CAAC;AAE5D;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,wBAAwB,EAAE,GAAG,OAAO,CAAC,OAAO,CAOpF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,OAAO,CAWnF;
|
|
1
|
+
{"version":3,"file":"deconvert.d.ts","sourceRoot":"","sources":["../src/deconvert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,eAAe,CAAC;AAE5D;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,wBAAwB,EAAE,GAAG,OAAO,CAAC,OAAO,CAOpF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,OAAO,CAWnF;AAwCD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,CAQnF;AAMD;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAG5C"}
|
package/dist/definitions.d.ts
CHANGED
|
@@ -76,7 +76,14 @@ export type GeoJSONToTileOptions = GeoJSONVTOptions & {
|
|
|
76
76
|
*/
|
|
77
77
|
clip?: boolean;
|
|
78
78
|
};
|
|
79
|
-
export type
|
|
79
|
+
export type SliceArray = {
|
|
80
|
+
points: number[];
|
|
81
|
+
start?: number;
|
|
82
|
+
end?: number;
|
|
83
|
+
size?: number;
|
|
84
|
+
};
|
|
85
|
+
export type SliceFixedArray = {
|
|
86
|
+
points: number[] | Float64Array;
|
|
80
87
|
start?: number;
|
|
81
88
|
end?: number;
|
|
82
89
|
size?: number;
|
|
@@ -99,19 +106,19 @@ export type GeoJSONVTInternalMultiPointFeature = PartialGeoJSONVTFeature & {
|
|
|
99
106
|
};
|
|
100
107
|
export type GeoJSONVTInternalLineStringFeature = PartialGeoJSONVTFeature & {
|
|
101
108
|
type: 'LineString';
|
|
102
|
-
geometry:
|
|
109
|
+
geometry: SliceFixedArray;
|
|
103
110
|
};
|
|
104
111
|
export type GeoJSONVTInternalMultiLineStringFeature = PartialGeoJSONVTFeature & {
|
|
105
112
|
type: 'MultiLineString';
|
|
106
|
-
geometry:
|
|
113
|
+
geometry: SliceFixedArray[];
|
|
107
114
|
};
|
|
108
115
|
export type GeoJSONVTInternalPolygonFeature = PartialGeoJSONVTFeature & {
|
|
109
116
|
type: 'Polygon';
|
|
110
|
-
geometry:
|
|
117
|
+
geometry: SliceFixedArray[];
|
|
111
118
|
};
|
|
112
119
|
export type GeoJSONVTInternalMultiPolygonFeature = PartialGeoJSONVTFeature & {
|
|
113
120
|
type: 'MultiPolygon';
|
|
114
|
-
geometry:
|
|
121
|
+
geometry: SliceFixedArray[][];
|
|
115
122
|
};
|
|
116
123
|
export type GeoJSONVTInternalFeature = GeoJSONVTInternalPointFeature | GeoJSONVTInternalMultiPointFeature | GeoJSONVTInternalLineStringFeature | GeoJSONVTInternalMultiLineStringFeature | GeoJSONVTInternalPolygonFeature | GeoJSONVTInternalMultiPolygonFeature;
|
|
117
124
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../src/definitions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC3B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;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E,MAAM,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACjG;;;OAGG;IACH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,iBAAiB,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvE,CAAC"}
|
package/dist/difference.d.ts
CHANGED
|
@@ -69,6 +69,6 @@ export declare function applySourceDiff(source: GeoJSONVTInternalFeature[], data
|
|
|
69
69
|
/**
|
|
70
70
|
* Convert a GeoJSON Source Diff to an idempotent hashed representation using Sets and Maps
|
|
71
71
|
*/
|
|
72
|
-
export declare function diffToHashed(diff: GeoJSONVTSourceDiff): HashedGeoJSONVTSourceDiff;
|
|
72
|
+
export declare function diffToHashed(diff: GeoJSONVTSourceDiff, options: GeoJSONVTOptions): HashedGeoJSONVTSourceDiff;
|
|
73
73
|
export {};
|
|
74
74
|
//# sourceMappingURL=difference.d.ts.map
|
package/dist/difference.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"difference.d.ts","sourceRoot":"","sources":["../src/difference.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,g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MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IAC7B,GAAG,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACvD,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,oBAAoB,CAAC,CAAC;CACtD,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,wBAAwB,EAAE,EAAE,QAAQ,EAAE,mBAAmB,EAAE,OAAO,EAAE,gBAAgB,GAAG,qBAAqB,CA6DnJ;AAqED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,gBAAgB,GAAG,yBAAyB,CAe5G"}
|
package/dist/feature.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GeoJSONVTInternalFeature, GeoJSONVTInternalLineStringFeature, GeoJSONVTInternalMultiLineStringFeature, GeoJSONVTInternalMultiPointFeature, GeoJSONVTInternalMultiPolygonFeature, GeoJSONVTInternalPointFeature, GeoJSONVTInternalPolygonFeature } from "./definitions";
|
|
1
|
+
import type { GeoJSONVTInternalFeature, GeoJSONVTInternalLineStringFeature, GeoJSONVTInternalMultiLineStringFeature, GeoJSONVTInternalMultiPointFeature, GeoJSONVTInternalMultiPolygonFeature, GeoJSONVTInternalPointFeature, GeoJSONVTInternalPolygonFeature, SliceArray } from "./definitions";
|
|
2
2
|
type FeatureTypeMap = {
|
|
3
3
|
Point: GeoJSONVTInternalPointFeature["geometry"];
|
|
4
4
|
MultiPoint: GeoJSONVTInternalMultiPointFeature["geometry"];
|
|
@@ -16,5 +16,6 @@ type FeatureTypeMap = {
|
|
|
16
16
|
* @returns the created feature
|
|
17
17
|
*/
|
|
18
18
|
export declare function createFeature<T extends GeoJSONVTInternalFeature["type"]>(id: number | string | undefined, type: T, geom: FeatureTypeMap[T], tags: GeoJSON.GeoJsonProperties): GeoJSONVTInternalFeature;
|
|
19
|
+
export declare function optimizeLineMemory(line: SliceArray): void;
|
|
19
20
|
export {};
|
|
20
21
|
//# sourceMappingURL=feature.d.ts.map
|
package/dist/feature.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../src/feature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,kCAAkC,EAAE,uCAAuC,EAAE,kCAAkC,EAAE,oCAAoC,EAAE,6BAA6B,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"feature.d.ts","sourceRoot":"","sources":["../src/feature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,kCAAkC,EAAE,uCAAuC,EAAE,kCAAkC,EAAE,oCAAoC,EAAE,6BAA6B,EAAE,+BAA+B,EAAE,UAAU,EAAmB,MAAM,eAAe,CAAC;AAElT,KAAK,cAAc,GAAG;IAClB,KAAK,EAAE,6BAA6B,CAAC,UAAU,CAAC,CAAC;IACjD,UAAU,EAAE,kCAAkC,CAAC,UAAU,CAAC,CAAC;IAC3D,UAAU,EAAE,kCAAkC,CAAC,UAAU,CAAC,CAAC;IAC3D,eAAe,EAAE,uCAAuC,CAAC,UAAU,CAAC,CAAC;IACrE,OAAO,EAAE,+BAA+B,CAAC,UAAU,CAAC,CAAC;IACrD,YAAY,EAAE,oCAAoC,CAAC,UAAU,CAAC,CAAC;CAClE,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,wBAAwB,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,iBAAiB,GAAG,wBAAwB,CA6CtM;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,QAKlD"}
|
package/dist/geojson-vt-dev.js
CHANGED
|
@@ -99,27 +99,35 @@ function createFeature(id, type, geom, tags) {
|
|
|
99
99
|
switch (data.type) {
|
|
100
100
|
case 'Point':
|
|
101
101
|
case 'MultiPoint':
|
|
102
|
-
case 'LineString':
|
|
103
102
|
calcLineBBox(feature, data.geom);
|
|
104
103
|
break;
|
|
104
|
+
case 'LineString':
|
|
105
|
+
calcLineBBox(feature, data.geom.points);
|
|
106
|
+
break;
|
|
105
107
|
case 'Polygon':
|
|
106
108
|
// the outer ring (ie [0]) contains all inner rings
|
|
107
|
-
calcLineBBox(feature, data.geom[0]);
|
|
109
|
+
calcLineBBox(feature, data.geom[0].points);
|
|
108
110
|
break;
|
|
109
111
|
case 'MultiLineString':
|
|
110
112
|
for (const line of data.geom) {
|
|
111
|
-
calcLineBBox(feature, line);
|
|
113
|
+
calcLineBBox(feature, line.points);
|
|
112
114
|
}
|
|
113
115
|
break;
|
|
114
116
|
case 'MultiPolygon':
|
|
115
117
|
for (const polygon of data.geom) {
|
|
116
118
|
// the outer ring (ie [0]) contains all inner rings
|
|
117
|
-
calcLineBBox(feature, polygon[0]);
|
|
119
|
+
calcLineBBox(feature, polygon[0].points);
|
|
118
120
|
}
|
|
119
121
|
break;
|
|
120
122
|
}
|
|
121
123
|
return feature;
|
|
122
124
|
}
|
|
125
|
+
function optimizeLineMemory(line) {
|
|
126
|
+
const lineImmutable = line;
|
|
127
|
+
if (line.points.length > 64) {
|
|
128
|
+
lineImmutable.points = new Float64Array(line.points);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
123
131
|
function calcLineBBox(feature, geom) {
|
|
124
132
|
for (let i = 0; i < geom.length; i += 3) {
|
|
125
133
|
feature.minX = Math.min(feature.minX, geom[i]);
|
|
@@ -217,7 +225,7 @@ function convertMultiPointFeature(features, id, geom, properties) {
|
|
|
217
225
|
features.push(createFeature(id, 'MultiPoint', out, properties));
|
|
218
226
|
}
|
|
219
227
|
function convertLineStringFeature(features, id, geom, tolerance, properties) {
|
|
220
|
-
const out = [];
|
|
228
|
+
const out = { points: [] };
|
|
221
229
|
convertLine(geom.coordinates, out, tolerance, false);
|
|
222
230
|
features.push(createFeature(id, 'LineString', out, properties));
|
|
223
231
|
}
|
|
@@ -225,7 +233,7 @@ function convertMultiLineStringFeature(features, id, geom, tolerance, options, p
|
|
|
225
233
|
if (options.lineMetrics) {
|
|
226
234
|
// explode into linestrings to be able to track metrics
|
|
227
235
|
for (const line of geom.coordinates) {
|
|
228
|
-
const out = [];
|
|
236
|
+
const out = { points: [] };
|
|
229
237
|
convertLine(line, out, tolerance, false);
|
|
230
238
|
features.push(createFeature(id, 'LineString', out, properties));
|
|
231
239
|
}
|
|
@@ -256,7 +264,7 @@ function convertLine(ring, out, tolerance, isPolygon) {
|
|
|
256
264
|
for (let j = 0; j < ring.length; j++) {
|
|
257
265
|
const x = projectX(ring[j][0]);
|
|
258
266
|
const y = projectY(ring[j][1]);
|
|
259
|
-
out.push(x, y, 0);
|
|
267
|
+
out.points.push(x, y, 0);
|
|
260
268
|
if (j > 0) {
|
|
261
269
|
if (isPolygon) {
|
|
262
270
|
size += (x0 * y - x * y0) / 2; // area
|
|
@@ -268,18 +276,19 @@ function convertLine(ring, out, tolerance, isPolygon) {
|
|
|
268
276
|
x0 = x;
|
|
269
277
|
y0 = y;
|
|
270
278
|
}
|
|
271
|
-
const last = out.length - 3;
|
|
272
|
-
out[2] = 1;
|
|
279
|
+
const last = out.points.length - 3;
|
|
280
|
+
out.points[2] = 1;
|
|
273
281
|
if (tolerance > 0)
|
|
274
|
-
simplify(out, 0, last, tolerance);
|
|
275
|
-
out[last + 2] = 1;
|
|
282
|
+
simplify(out.points, 0, last, tolerance);
|
|
283
|
+
out.points[last + 2] = 1;
|
|
284
|
+
optimizeLineMemory(out);
|
|
276
285
|
out.size = Math.abs(size);
|
|
277
286
|
out.start = 0;
|
|
278
287
|
out.end = out.size;
|
|
279
288
|
}
|
|
280
289
|
function convertLines(rings, out, tolerance, isPolygon) {
|
|
281
290
|
for (let i = 0; i < rings.length; i++) {
|
|
282
|
-
const geom = [];
|
|
291
|
+
const geom = { points: [] };
|
|
283
292
|
convertLine(rings[i], geom, tolerance, isPolygon);
|
|
284
293
|
out.push(geom);
|
|
285
294
|
}
|
|
@@ -335,21 +344,25 @@ function geometryToGeoJSON(feature) {
|
|
|
335
344
|
coordinates: unprojectPoint(geometry[0], geometry[1])
|
|
336
345
|
};
|
|
337
346
|
case 'MultiPoint':
|
|
338
|
-
case 'LineString':
|
|
339
347
|
return {
|
|
340
348
|
type: type,
|
|
341
349
|
coordinates: unprojectPoints(geometry)
|
|
342
350
|
};
|
|
351
|
+
case 'LineString':
|
|
352
|
+
return {
|
|
353
|
+
type: type,
|
|
354
|
+
coordinates: unprojectPoints(geometry.points)
|
|
355
|
+
};
|
|
343
356
|
case 'MultiLineString':
|
|
344
357
|
case 'Polygon':
|
|
345
358
|
return {
|
|
346
359
|
type: type,
|
|
347
|
-
coordinates: geometry.map(ring => unprojectPoints(ring))
|
|
360
|
+
coordinates: geometry.map(ring => unprojectPoints(ring.points))
|
|
348
361
|
};
|
|
349
362
|
case 'MultiPolygon':
|
|
350
363
|
return {
|
|
351
364
|
type: type,
|
|
352
|
-
coordinates: geometry.map(polygon => polygon.map(ring => unprojectPoints(ring)))
|
|
365
|
+
coordinates: geometry.map(polygon => polygon.map(ring => unprojectPoints(ring.points)))
|
|
353
366
|
};
|
|
354
367
|
}
|
|
355
368
|
}
|
|
@@ -514,12 +527,12 @@ function clipLine(geom, newGeom, start, end, axis, isPolygon, trackMetrics) {
|
|
|
514
527
|
const intersect = axis === AxisType.X ? intersectX : intersectY;
|
|
515
528
|
let len = geom.start;
|
|
516
529
|
let segLen, t;
|
|
517
|
-
for (let i = 0; i < geom.length - 3; i += 3) {
|
|
518
|
-
const ax = geom[i];
|
|
519
|
-
const ay = geom[i + 1];
|
|
520
|
-
const az = geom[i + 2];
|
|
521
|
-
const bx = geom[i + 3];
|
|
522
|
-
const by = geom[i + 4];
|
|
530
|
+
for (let i = 0; i < geom.points.length - 3; i += 3) {
|
|
531
|
+
const ax = geom.points[i];
|
|
532
|
+
const ay = geom.points[i + 1];
|
|
533
|
+
const az = geom.points[i + 2];
|
|
534
|
+
const bx = geom.points[i + 3];
|
|
535
|
+
const by = geom.points[i + 4];
|
|
523
536
|
const a = axis === AxisType.X ? ax : ay;
|
|
524
537
|
const b = axis === AxisType.X ? bx : by;
|
|
525
538
|
let exited = false;
|
|
@@ -542,7 +555,7 @@ function clipLine(geom, newGeom, start, end, axis, isPolygon, trackMetrics) {
|
|
|
542
555
|
}
|
|
543
556
|
}
|
|
544
557
|
else {
|
|
545
|
-
addPoint(slice, ax, ay, az);
|
|
558
|
+
addPoint(slice.points, ax, ay, az);
|
|
546
559
|
}
|
|
547
560
|
if (b < start && a >= start) {
|
|
548
561
|
// <--|--- | or <--|-----|--- (line exits the clip region on the left)
|
|
@@ -564,29 +577,31 @@ function clipLine(geom, newGeom, start, end, axis, isPolygon, trackMetrics) {
|
|
|
564
577
|
len += segLen;
|
|
565
578
|
}
|
|
566
579
|
// add the last point
|
|
567
|
-
let last = geom.length - 3;
|
|
568
|
-
const ax = geom[last];
|
|
569
|
-
const ay = geom[last + 1];
|
|
570
|
-
const az = geom[last + 2];
|
|
580
|
+
let last = geom.points.length - 3;
|
|
581
|
+
const ax = geom.points[last];
|
|
582
|
+
const ay = geom.points[last + 1];
|
|
583
|
+
const az = geom.points[last + 2];
|
|
571
584
|
const a = axis === AxisType.X ? ax : ay;
|
|
572
585
|
if (a >= start && a <= end)
|
|
573
|
-
addPoint(slice, ax, ay, az);
|
|
586
|
+
addPoint(slice.points, ax, ay, az);
|
|
574
587
|
// close the polygon if its endpoints are not the same after clipping
|
|
575
|
-
last = slice.length - 3;
|
|
576
|
-
if (isPolygon && last >= 3 && (slice[last] !== slice[0] || slice[last + 1] !== slice[1])) {
|
|
577
|
-
addPoint(slice, slice[0], slice[1], slice[2]);
|
|
588
|
+
last = slice.points.length - 3;
|
|
589
|
+
if (isPolygon && last >= 3 && (slice.points[last] !== slice.points[0] || slice.points[last + 1] !== slice.points[1])) {
|
|
590
|
+
addPoint(slice.points, slice.points[0], slice.points[1], slice.points[2]);
|
|
578
591
|
}
|
|
579
592
|
// add the final slice
|
|
580
|
-
if (slice.length) {
|
|
593
|
+
if (slice.points.length) {
|
|
594
|
+
optimizeLineMemory(slice);
|
|
581
595
|
newGeom.push(slice);
|
|
582
596
|
}
|
|
583
597
|
}
|
|
584
598
|
function newSlice(line) {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
599
|
+
return {
|
|
600
|
+
points: [],
|
|
601
|
+
size: line.size,
|
|
602
|
+
start: line.start,
|
|
603
|
+
end: line.end
|
|
604
|
+
};
|
|
590
605
|
}
|
|
591
606
|
function clipLines(geom, newGeom, start, end, axis, isPolygon) {
|
|
592
607
|
for (const line of geom) {
|
|
@@ -598,12 +613,12 @@ function addPoint(out, x, y, z) {
|
|
|
598
613
|
}
|
|
599
614
|
function intersectX(out, ax, ay, bx, by, x) {
|
|
600
615
|
const t = (x - ax) / (bx - ax);
|
|
601
|
-
addPoint(out, x, ay + (by - ay) * t, 1);
|
|
616
|
+
addPoint(out.points, x, ay + (by - ay) * t, 1);
|
|
602
617
|
return t;
|
|
603
618
|
}
|
|
604
619
|
function intersectY(out, ax, ay, bx, by, y) {
|
|
605
620
|
const t = (y - ay) / (by - ay);
|
|
606
|
-
addPoint(out, ax + (bx - ax) * t, y, 1);
|
|
621
|
+
addPoint(out.points, ax + (bx - ax) * t, y, 1);
|
|
607
622
|
return t;
|
|
608
623
|
}
|
|
609
624
|
|
|
@@ -626,9 +641,13 @@ function shiftFeatureCoords(features, offset) {
|
|
|
626
641
|
for (const feature of features) {
|
|
627
642
|
switch (feature.type) {
|
|
628
643
|
case 'Point':
|
|
629
|
-
case 'MultiPoint':
|
|
644
|
+
case 'MultiPoint': {
|
|
645
|
+
const newGeometry = shiftPointCoords(feature.geometry, offset);
|
|
646
|
+
newFeatures.push(createFeature(feature.id, feature.type, newGeometry, feature.tags));
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
630
649
|
case 'LineString': {
|
|
631
|
-
const newGeometry =
|
|
650
|
+
const newGeometry = shiftLineCoords(feature.geometry, offset);
|
|
632
651
|
newFeatures.push(createFeature(feature.id, feature.type, newGeometry, feature.tags));
|
|
633
652
|
continue;
|
|
634
653
|
}
|
|
@@ -636,7 +655,7 @@ function shiftFeatureCoords(features, offset) {
|
|
|
636
655
|
case 'Polygon': {
|
|
637
656
|
const newGeometry = [];
|
|
638
657
|
for (const line of feature.geometry) {
|
|
639
|
-
newGeometry.push(
|
|
658
|
+
newGeometry.push(shiftLineCoords(line, offset));
|
|
640
659
|
}
|
|
641
660
|
newFeatures.push(createFeature(feature.id, feature.type, newGeometry, feature.tags));
|
|
642
661
|
continue;
|
|
@@ -646,7 +665,7 @@ function shiftFeatureCoords(features, offset) {
|
|
|
646
665
|
for (const polygon of feature.geometry) {
|
|
647
666
|
const newPolygon = [];
|
|
648
667
|
for (const line of polygon) {
|
|
649
|
-
newPolygon.push(
|
|
668
|
+
newPolygon.push(shiftLineCoords(line, offset));
|
|
650
669
|
}
|
|
651
670
|
newGeometry.push(newPolygon);
|
|
652
671
|
}
|
|
@@ -657,17 +676,27 @@ function shiftFeatureCoords(features, offset) {
|
|
|
657
676
|
}
|
|
658
677
|
return newFeatures;
|
|
659
678
|
}
|
|
660
|
-
function
|
|
661
|
-
const
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
newPoints.start = points.start;
|
|
665
|
-
newPoints.end = points.end;
|
|
679
|
+
function shiftPointCoords(coords, offset) {
|
|
680
|
+
const newCoords = [];
|
|
681
|
+
for (let i = 0; i < coords.length; i += 3) {
|
|
682
|
+
newCoords.push(coords[i] + offset, coords[i + 1], coords[i + 2]);
|
|
666
683
|
}
|
|
667
|
-
|
|
668
|
-
|
|
684
|
+
return newCoords;
|
|
685
|
+
}
|
|
686
|
+
function shiftLineCoords(line, offset) {
|
|
687
|
+
const newLine = {
|
|
688
|
+
points: [],
|
|
689
|
+
size: line.size
|
|
690
|
+
};
|
|
691
|
+
if (line.start !== undefined) {
|
|
692
|
+
newLine.start = line.start;
|
|
693
|
+
newLine.end = line.end;
|
|
669
694
|
}
|
|
670
|
-
|
|
695
|
+
for (let i = 0; i < line.points.length; i += 3) {
|
|
696
|
+
newLine.points.push(line.points[i] + offset, line.points[i + 1], line.points[i + 2]);
|
|
697
|
+
}
|
|
698
|
+
optimizeLineMemory(newLine);
|
|
699
|
+
return newLine;
|
|
671
700
|
}
|
|
672
701
|
|
|
673
702
|
/**
|
|
@@ -679,7 +708,7 @@ function shiftCoords(points, offset) {
|
|
|
679
708
|
*/
|
|
680
709
|
function applySourceDiff(source, dataDiff, options) {
|
|
681
710
|
// convert diff to sets/maps for o(1) lookups
|
|
682
|
-
const diff = diffToHashed(dataDiff);
|
|
711
|
+
const diff = diffToHashed(dataDiff, options);
|
|
683
712
|
// collection for features that will be affected by this update and used to invalidate tiles
|
|
684
713
|
let affected = [];
|
|
685
714
|
if (diff.removeAll) {
|
|
@@ -790,7 +819,7 @@ function applyPropertyUpdates(tags, update) {
|
|
|
790
819
|
/**
|
|
791
820
|
* Convert a GeoJSON Source Diff to an idempotent hashed representation using Sets and Maps
|
|
792
821
|
*/
|
|
793
|
-
function diffToHashed(diff) {
|
|
822
|
+
function diffToHashed(diff, options) {
|
|
794
823
|
if (!diff)
|
|
795
824
|
return {
|
|
796
825
|
remove: new Set(),
|
|
@@ -800,7 +829,7 @@ function diffToHashed(diff) {
|
|
|
800
829
|
const hashed = {
|
|
801
830
|
removeAll: diff.removeAll,
|
|
802
831
|
remove: new Set(diff.remove || []),
|
|
803
|
-
add: new Map(diff.add?.map(feature => [feature.id, feature])),
|
|
832
|
+
add: new Map(diff.add?.map(feature => [options.promoteId ? feature.properties[options.promoteId] : feature.id, feature])),
|
|
804
833
|
update: new Map(diff.update?.map(update => [update.id, update]))
|
|
805
834
|
};
|
|
806
835
|
return hashed;
|
|
@@ -1705,14 +1734,14 @@ function addMultiPolygonTileFeature(tile, feature, tolerance) {
|
|
|
1705
1734
|
function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
|
|
1706
1735
|
const sqTolerance = tolerance * tolerance;
|
|
1707
1736
|
if (tolerance > 0 && (geom.size < (isPolygon ? sqTolerance : tolerance))) {
|
|
1708
|
-
tile.numPoints += geom.length / 3;
|
|
1737
|
+
tile.numPoints += geom.points.length / 3;
|
|
1709
1738
|
return;
|
|
1710
1739
|
}
|
|
1711
1740
|
const ring = [];
|
|
1712
|
-
for (let i = 0; i < geom.length; i += 3) {
|
|
1713
|
-
if (tolerance === 0 || geom[i + 2] > sqTolerance) {
|
|
1741
|
+
for (let i = 0; i < geom.points.length; i += 3) {
|
|
1742
|
+
if (tolerance === 0 || geom.points[i + 2] > sqTolerance) {
|
|
1714
1743
|
tile.numSimplified++;
|
|
1715
|
-
ring.push(geom[i], geom[i + 1]);
|
|
1744
|
+
ring.push(geom.points[i], geom.points[i + 1]);
|
|
1716
1745
|
}
|
|
1717
1746
|
tile.numPoints++;
|
|
1718
1747
|
}
|
package/dist/geojson-vt.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).geojsonvt={})}(this,(function(t){"use strict";function e(t,o,s,i){let r=i;const a=o+(s-o>>1);let u,c=s-o;const l=t[o],h=t[o+1],d=t[s],p=t[s+1];for(let e=o+3;e<s;e+=3){const o=n(t[e],t[e+1],l,h,d,p);if(o>r)u=e,r=o;else if(o===r){const t=Math.abs(e-a);t<c&&(u=e,c=t)}}r>i&&(u-o>3&&e(t,o,u,i),t[u+2]=r,s-u>3&&e(t,u,s,i))}function n(t,e,n,o,s,i){let r=s-n,a=i-o;if(0!==r||0!==a){const u=((t-n)*r+(e-o)*a)/(r*r+a*a);u>1?(n=s,o=i):u>0&&(n+=r*u,o+=a*u)}return r=t-n,a=e-o,r*r+a*a}function o(t,e,n,o){const i={type:e,geom:n},r={id:null==t?null:t,type:i.type,geometry:i.geom,tags:o,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};switch(i.type){case"Point":case"MultiPoint":case"LineString":s(r,i.geom);break;case"Polygon":s(r,i.geom[0]);break;case"MultiLineString":for(const t of i.geom)s(r,t);break;case"MultiPolygon":for(const t of i.geom)s(r,t[0])}return r}function s(t,e){for(let n=0;n<e.length;n+=3)t.minX=Math.min(t.minX,e[n]),t.minY=Math.min(t.minY,e[n+1]),t.maxX=Math.max(t.maxX,e[n]),t.maxY=Math.max(t.maxY,e[n+1])}function i(t,e){const n=[];switch(t.type){case"FeatureCollection":for(let o=0;o<t.features.length;o++)r(n,t.features[o],e,o);break;case"Feature":r(n,t,e);break;default:r(n,{geometry:t,properties:void 0},e)}return n}function r(t,e,n,s){if(!e.geometry)return;if("GeometryCollection"===e.geometry.type)return void function(t,e,n,o,s){for(const i of n.geometries)r(t,{id:e.id,geometry:i,properties:e.properties},o,s)}(t,e,e.geometry,n,s);const i=e.geometry.coordinates;if(!i?.length)return;const h=function(t,e,n){if(e.promoteId)return t.properties?.[e.promoteId];if(e.generateId)return n||0;return t.id}(e,n,s),d=Math.pow(n.tolerance/((1<<n.maxZoom)*n.extent),2);switch(e.geometry.type){case"Point":return void function(t,e,n,s){const i=[];i.push(c(n.coordinates[0]),l(n.coordinates[1]),0),t.push(o(e,"Point",i,s))}(t,h,e.geometry,e.properties);case"MultiPoint":return void function(t,e,n,s){const i=[];for(const t of n.coordinates)i.push(c(t[0]),l(t[1]),0);t.push(o(e,"MultiPoint",i,s))}(t,h,e.geometry,e.properties);case"LineString":return void function(t,e,n,s,i){const r=[];a(n.coordinates,r,s,!1),t.push(o(e,"LineString",r,i))}(t,h,e.geometry,d,e.properties);case"MultiLineString":return void function(t,e,n,s,i,r){if(i.lineMetrics)for(const i of n.coordinates){const n=[];a(i,n,s,!1),t.push(o(e,"LineString",n,r))}else{const i=[];u(n.coordinates,i,s,!1),t.push(o(e,"MultiLineString",i,r))}}(t,h,e.geometry,d,n,e.properties);case"Polygon":return void function(t,e,n,s,i){const r=[];u(n.coordinates,r,s,!0),t.push(o(e,"Polygon",r,i))}(t,h,e.geometry,d,e.properties);case"MultiPolygon":return void function(t,e,n,s,i){const r=[];for(const t of n.coordinates){const e=[];u(t,e,s,!0),r.push(e)}t.push(o(e,"MultiPolygon",r,i))}(t,h,e.geometry,d,e.properties);default:throw new Error("Input data is not a valid GeoJSON object.")}}function a(t,n,o,s){let i,r,a=0;for(let e=0;e<t.length;e++){const o=c(t[e][0]),u=l(t[e][1]);n.push(o,u,0),e>0&&(a+=s?(i*u-o*r)/2:Math.sqrt(Math.pow(o-i,2)+Math.pow(u-r,2))),i=o,r=u}const u=n.length-3;n[2]=1,o>0&&e(n,0,u,o),n[u+2]=1,n.size=Math.abs(a),n.start=0,n.end=n.size}function u(t,e,n,o){for(let s=0;s<t.length;s++){const i=[];a(t[s],i,n,o),e.push(i)}}function c(t){return t/360+.5}function l(t){const e=Math.sin(t*Math.PI/180),n=.5-.25*Math.log((1+e)/(1-e))/Math.PI;return n<0?0:n>1?1:n}function h(t){const e={type:"Feature",geometry:d(t),properties:t.tags};return null!=t.id&&(e.id=t.id),e}function d(t){const{type:e,geometry:n}=t;switch(e){case"Point":return{type:e,coordinates:f(n[0],n[1])};case"MultiPoint":case"LineString":return{type:e,coordinates:p(n)};case"MultiLineString":case"Polygon":return{type:e,coordinates:n.map((t=>p(t)))};case"MultiPolygon":return{type:e,coordinates:n.map((t=>t.map((t=>p(t)))))}}}function p(t){const e=[];for(let n=0;n<t.length;n+=3)e.push(f(t[n],t[n+1]));return e}function f(t,e){return[g(t),m(e)]}function g(t){return 360*(t-.5)}function m(t){const e=(180-360*t)*Math.PI/180;return 360*Math.atan(Math.exp(e))/Math.PI-90}var y;function x(t,e,n,o,s,i,r,a){if(o/=e,i>=(n/=e)&&r<o)return t;if(r<n||i>=o)return null;const u=[];for(const e of t){const t=s===y.X?e.minX:e.minY,i=s===y.X?e.maxX:e.maxY;if(t>=n&&i<o)u.push(e);else if(!(i<n||t>=o))switch(e.type){case"Point":case"MultiPoint":M(e,u,n,o,s);continue;case"LineString":w(e,u,n,o,s,a);continue;case"MultiLineString":P(e,u,n,o,s);continue;case"Polygon":I(e,u,n,o,s);continue;case"MultiPolygon":v(e,u,n,o,s);continue}}return u.length?u:null}function M(t,e,n,s,i){const r=[];if(function(t,e,n,o,s){for(let i=0;i<t.length;i+=3){const r=t[i+s];r>=n&&r<=o&&A(e,t[i],t[i+1],t[i+2])}}(t.geometry,r,n,s,i),!r.length)return;const a=3===r.length?"Point":"MultiPoint";e.push(o(t.id,a,r,t.tags))}function w(t,e,n,s,i,r){const a=[];if(b(t.geometry,a,n,s,i,!1,r.lineMetrics),a.length)if(r.lineMetrics)for(const n of a)e.push(o(t.id,"LineString",n,t.tags));else a.length>1?e.push(o(t.id,"MultiLineString",a,t.tags)):e.push(o(t.id,"LineString",a[0],t.tags))}function P(t,e,n,s,i){const r=[];z(t.geometry,r,n,s,i,!1),r.length&&(1!==r.length?e.push(o(t.id,"MultiLineString",r,t.tags)):e.push(o(t.id,"LineString",r[0],t.tags)))}function I(t,e,n,s,i){const r=[];z(t.geometry,r,n,s,i,!0),r.length&&e.push(o(t.id,"Polygon",r,t.tags))}function v(t,e,n,s,i){const r=[];for(const e of t.geometry){const t=[];z(e,t,n,s,i,!0),t.length&&r.push(t)}r.length&&e.push(o(t.id,"MultiPolygon",r,t.tags))}function b(t,e,n,o,s,i,r){let a=S(t);const u=s===y.X?E:T;let c,l,h=t.start;for(let d=0;d<t.length-3;d+=3){const p=t[d],f=t[d+1],g=t[d+2],m=t[d+3],x=t[d+4],M=s===y.X?p:f,w=s===y.X?m:x;let P=!1;r&&(c=Math.sqrt(Math.pow(p-m,2)+Math.pow(f-x,2))),M<n?w>n&&(l=u(a,p,f,m,x,n),r&&(a.start=h+c*l)):M>o?w<o&&(l=u(a,p,f,m,x,o),r&&(a.start=h+c*l)):A(a,p,f,g),w<n&&M>=n&&(l=u(a,p,f,m,x,n),P=!0),w>o&&M<=o&&(l=u(a,p,f,m,x,o),P=!0),!i&&P&&(r&&(a.end=h+c*l),e.push(a),a=S(t)),r&&(h+=c)}let d=t.length-3;const p=t[d],f=t[d+1],g=t[d+2],m=s===y.X?p:f;m>=n&&m<=o&&A(a,p,f,g),d=a.length-3,i&&d>=3&&(a[d]!==a[0]||a[d+1]!==a[1])&&A(a,a[0],a[1],a[2]),a.length&&e.push(a)}function S(t){const e=[];return e.size=t.size,e.start=t.start,e.end=t.end,e}function z(t,e,n,o,s,i){for(const r of t)b(r,e,n,o,s,i,!1)}function A(t,e,n,o){t.push(e,n,o)}function E(t,e,n,o,s,i){const r=(i-e)/(o-e);return A(t,i,n+(s-n)*r,1),r}function T(t,e,n,o,s,i){const r=(i-n)/(s-n);return A(t,e+(o-e)*r,i,1),r}function X(t,e){const n=e.buffer/e.extent;let o=t;const s=x(t,1,-1-n,n,y.X,-1,2,e),i=x(t,1,1-n,2+n,y.X,-1,2,e);return s||i?(o=x(t,1,-n,1+n,y.X,-1,2,e)||[],s&&(o=Y(s,1).concat(o)),i&&(o=o.concat(Y(i,-1))),o):o}function Y(t,e){const n=[];for(const s of t)switch(s.type){case"Point":case"MultiPoint":case"LineString":{const t=L(s.geometry,e);n.push(o(s.id,s.type,t,s.tags));continue}case"MultiLineString":case"Polygon":{const t=[];for(const n of s.geometry)t.push(L(n,e));n.push(o(s.id,s.type,t,s.tags));continue}case"MultiPolygon":{const t=[];for(const n of s.geometry){const o=[];for(const t of n)o.push(L(t,e));t.push(o)}n.push(o(s.id,s.type,t,s.tags));continue}}return n}function L(t,e){const n=[];n.size=t.size,void 0!==t.start&&(n.start=t.start,n.end=t.end);for(let o=0;o<t.length;o+=3)n.push(t[o]+e,t[o+1],t[o+2]);return n}function O(t,e,n){const o=function(t){if(!t)return{remove:new Set,add:new Map,update:new Map};const e={removeAll:t.removeAll,remove:new Set(t.remove||[]),add:new Map(t.add?.map((t=>[t.id,t]))),update:new Map(t.update?.map((t=>[t.id,t])))};return e}(e);let s=[];if(o.removeAll&&(s=t,t=[]),o.remove.size||o.add.size){const e=[];for(const n of t)(o.remove.has(n.id)||o.add.has(n.id))&&e.push(n);if(e.length){s.push(...e);const n=new Set(e.map((t=>t.id)));t=t.filter((t=>!n.has(t.id)))}if(o.add.size){let e=i({type:"FeatureCollection",features:Array.from(o.add.values())},n);e=X(e,n),s.push(...e),t.push(...e)}}if(o.update.size)for(const[e,i]of o.update){const o=[],r=[];for(const n of t)n.id===e?o.push(n):r.push(n);if(!o.length)continue;const a=C(o,i,n);a.length&&(s.push(...o,...a),r.push(...a),t=r)}return{affected:s,source:t}}function C(t,e,n){const o=!!e.newGeometry,s=e.removeAllProperties||e.removeProperties?.length>0||e.addOrUpdateProperties?.length>0;if(o){const o=t[0];let r=i({type:"FeatureCollection",features:[{type:"Feature",id:o.id,geometry:e.newGeometry,properties:s?_(o.tags,e):o.tags}]},n);return r=X(r,n),r}if(s){const n=[];for(const o of t){const t={...o};t.tags=_(t.tags,e),n.push(t)}return n}return[]}function _(t,e){if(e.removeAllProperties)return{};const n={...t||{}};if(e.removeProperties)for(const t of e.removeProperties)delete n[t];if(e.addOrUpdateProperties)for(const{key:t,value:o}of e.addOrUpdateProperties)n[t]=o;return n}!function(t){t[t.X=0]="X",t[t.Y=1]="Y"}(y||(y={}));const Z=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class F{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,n]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const o=n>>4;if(1!==o)throw new Error(`Got v${o} data when expected v1.`);const s=Z[15&n];if(!s)throw new Error("Unrecognized array type.");const[i]=new Uint16Array(t,2,1),[r]=new Uint32Array(t,4,1);return new F(r,i,s,t)}constructor(t,e=64,n=Float64Array,o){if(isNaN(t)||t<0)throw new Error(`Unpexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.ArrayType=n,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const s=Z.indexOf(this.ArrayType),i=2*t*this.ArrayType.BYTES_PER_ELEMENT,r=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-r%8)%8;if(s<0)throw new Error(`Unexpected typed array class: ${n}.`);o&&o instanceof ArrayBuffer?(this.data=o,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+r+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+i+r+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+r+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+s]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const n=this._pos>>1;return this.ids[n]=n,this.coords[this._pos++]=t,this.coords[this._pos++]=e,n}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return U(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,n,o){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:s,coords:i,nodeSize:r}=this,a=[0,s.length-1,0],u=[];for(;a.length;){const c=a.pop()||0,l=a.pop()||0,h=a.pop()||0;if(l-h<=r){for(let r=h;r<=l;r++){const a=i[2*r],c=i[2*r+1];a>=t&&a<=n&&c>=e&&c<=o&&u.push(s[r])}continue}const d=h+l>>1,p=i[2*d],f=i[2*d+1];p>=t&&p<=n&&f>=e&&f<=o&&u.push(s[d]),(0===c?t<=p:e<=f)&&(a.push(h),a.push(d-1),a.push(1-c)),(0===c?n>=p:o>=f)&&(a.push(d+1),a.push(l),a.push(1-c))}return u}within(t,e,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:o,coords:s,nodeSize:i}=this,r=[0,o.length-1,0],a=[],u=n*n;for(;r.length;){const c=r.pop()||0,l=r.pop()||0,h=r.pop()||0;if(l-h<=i){for(let n=h;n<=l;n++)k(s[2*n],s[2*n+1],t,e)<=u&&a.push(o[n]);continue}const d=h+l>>1,p=s[2*d],f=s[2*d+1];k(p,f,t,e)<=u&&a.push(o[d]),(0===c?t-n<=p:e-n<=f)&&(r.push(h),r.push(d-1),r.push(1-c)),(0===c?t+n>=p:e+n>=f)&&(r.push(d+1),r.push(l),r.push(1-c))}return a}}function U(t,e,n,o,s,i){if(s-o<=n)return;const r=o+s>>1;D(t,e,r,o,s,i),U(t,e,n,o,r-1,1-i),U(t,e,n,r+1,s,1-i)}function D(t,e,n,o,s,i){for(;s>o;){if(s-o>600){const r=s-o+1,a=n-o+1,u=Math.log(r),c=.5*Math.exp(2*u/3),l=.5*Math.sqrt(u*c*(r-c)/r)*(a-r/2<0?-1:1);D(t,e,n,Math.max(o,Math.floor(n-a*c/r+l)),Math.min(s,Math.floor(n+(r-a)*c/r+l)),i)}const r=e[2*n+i];let a=o,u=s;for(j(t,e,o,n),e[2*s+i]>r&&j(t,e,o,s);a<u;){for(j(t,e,a,u),a++,u--;e[2*a+i]<r;)a++;for(;e[2*u+i]>r;)u--}e[2*o+i]===r?j(t,e,o,u):(u++,j(t,e,u,s)),u<=n&&(o=u+1),n<=u&&(s=u-1)}}function j(t,e,n,o){N(t,n,o),N(e,2*n,2*o),N(e,2*n+1,2*o+1)}function N(t,e,n){const o=t[e];t[e]=t[n],t[n]=o}function k(t,e,n,o){const s=t-n,i=e-o;return s*s+i*i}const $={minZoom:0,maxZoom:16,minPoints:2,radius:40,extent:512,nodeSize:64,log:!1,generateId:!1,reduce:null,map:t=>t},G=3,B=5,J=6;class q{constructor(t){this.options=Object.assign(Object.create($),t),this.trees=new Array(this.options.maxZoom+1),this.stride=this.options.reduce?7:6,this.clusterProps=[],this.points=[]}load(t){const e=[];for(const n of t){if(!n.geometry)continue;const[t,o]=n.geometry.coordinates,[s,i]=[c(t),l(o)],r={id:n.id,type:"Point",geometry:[s,i],tags:n.properties};e.push(r)}this.createIndex(e)}initialize(t){const e=[];for(const n of t)"Point"===n.type&&e.push(n);this.createIndex(e)}updateIndex(t,e,n){this.options=Object.assign(Object.create($),n.clusterOptions),this.initialize(t)}createIndex(t){const{log:e,minZoom:n,maxZoom:o}=this.options;e&&console.time("total time");const s=`prepare ${t.length} points`;e&&console.time(s),this.points=t;const i=[];for(let e=0;e<t.length;e++){const n=t[e];if(!n?.geometry)continue;let[o,s]=n.geometry;o=Math.fround(o),s=Math.fround(s),i.push(o,s,1/0,e,-1,1),this.options.reduce&&i.push(0)}let r=this.trees[o+1]=this.createTree(i);e&&console.timeEnd(s);for(let t=o;t>=n;t--){const n=Date.now();r=this.trees[t]=this.createTree(this.cluster(r,t)),e&&console.log("z%d: %d clusters in %dms",t,r.numItems,Date.now()-n)}e&&console.timeEnd("total time")}getClusters(t,e){return this.getClustersInternal(t,e).map((t=>h(t)))}getClustersInternal(t,e){let n=((t[0]+180)%360+360)%360-180;const o=Math.max(-90,Math.min(90,t[1]));let s=180===t[2]?180:((t[2]+180)%360+360)%360-180;const i=Math.max(-90,Math.min(90,t[3]));if(t[2]-t[0]>=360)n=-180,s=180;else if(n>s){const t=this.getClustersInternal([n,o,180,i],e),r=this.getClustersInternal([-180,o,s,i],e);return t.concat(r)}const r=this.trees[this.limitZoom(e)],a=r.range(c(n),l(i),c(s),l(o)),u=r.flatData,h=[];for(const t of a){const e=this.stride*t;h.push(u[e+B]>1?R(u,e,this.clusterProps):this.points[u[e+G]])}return h}getChildren(t){const e=this.getOriginId(t),n=this.getOriginZoom(t),o=new Error("No cluster with the specified id: "+t),s=this.trees[n];if(!s)throw o;const i=s.flatData;if(e*this.stride>=i.length)throw o;const r=this.options.radius/(this.options.extent*Math.pow(2,n-1)),a=i[e*this.stride],u=i[e*this.stride+1],c=s.within(a,u,r),l=[];for(const e of c){const n=e*this.stride;i[n+4]===t&&l.push(i[n+B]>1?V(i,n,this.clusterProps):h(this.points[i[n+G]]))}if(0===l.length)throw o;return l}getLeaves(t,e,n){e=e||10,n=n||0;const o=[];return this.appendLeaves(o,t,e,n,0),o}getTile(t,e,n){const o=this.trees[this.limitZoom(t)];if(!o)return null;const s=Math.pow(2,t),{extent:i,radius:r}=this.options,a=r/i,u=(n-a)/s,c=(n+1+a)/s,l={transformed:!0,features:[],source:null,x:e,y:n,z:t};return this.addTileFeatures(o.range((e-a)/s,u,(e+1+a)/s,c),o.flatData,e,n,s,l),0===e&&this.addTileFeatures(o.range(1-a/s,u,1,c),o.flatData,s,n,s,l),e===s-1&&this.addTileFeatures(o.range(0,u,a/s,c),o.flatData,-1,n,s,l),l}getClusterExpansionZoom(t){return this.getOriginZoom(t)}appendLeaves(t,e,n,o,s){const i=this.getChildren(e);for(const e of i){const i=e.properties;if(i?.cluster?s+i.point_count<=o?s+=i.point_count:s=this.appendLeaves(t,i.cluster_id,n,o,s):s<o?s++:t.push(e),t.length===n)break}return s}createTree(t){const e=new F(t.length/this.stride|0,this.options.nodeSize,Float32Array);for(let n=0;n<t.length;n+=this.stride)e.add(t[n],t[n+1]);return e.finish(),e.flatData=t,e.data=null,e}addTileFeatures(t,e,n,o,s,i){for(const r of t){const t=r*this.stride,a=e[t+B]>1;let u,c,l;if(a)u=K(e,t,this.clusterProps),c=e[t],l=e[t+1];else{const n=this.points[e[t+G]];u=n.tags,[c,l]=n.geometry}const h={type:1,geometry:[[Math.round(this.options.extent*(c*s-n)),Math.round(this.options.extent*(l*s-o))]],tags:u};let d;d=a||this.options.generateId?e[t+G]:this.points[e[t+G]].id,void 0!==d&&(h.id=d),i.features.push(h)}}limitZoom(t){return Math.max(this.options.minZoom,Math.min(Math.floor(+t),this.options.maxZoom+1))}cluster(t,e){const{radius:n,extent:o,reduce:s,minPoints:i}=this.options,r=n/(o*Math.pow(2,e)),a=t.flatData,u=[],c=this.stride;for(let n=0;n<a.length;n+=c){if(a[n+2]<=e)continue;a[n+2]=e;const o=a[n],l=a[n+1],h=t.within(a[n],a[n+1],r),d=a[n+B];let p=d;for(const t of h){const n=t*c;a[n+2]>e&&(p+=a[n+B])}if(p>d&&p>=i){let t,i=o*d,r=l*d,f=-1;const g=(n/c<<5)+(e+1)+this.points.length;for(const o of h){const u=o*c;if(a[u+2]<=e)continue;a[u+2]=e;const l=a[u+B];i+=a[u]*l,r+=a[u+1]*l,a[u+4]=g,s&&(t||(t=this.map(a,n,!0),f=this.clusterProps.length,this.clusterProps.push(t)),s(t,this.map(a,u)))}a[n+4]=g,u.push(i/p,r/p,1/0,g,-1,p),s&&u.push(f)}else{for(let t=0;t<c;t++)u.push(a[n+t]);if(p>1)for(const t of h){const n=t*c;if(!(a[n+2]<=e)){a[n+2]=e;for(let t=0;t<c;t++)u.push(a[n+t])}}}}return u}getOriginId(t){return t-this.points.length>>5}getOriginZoom(t){return(t-this.points.length)%32}map(t,e,n){if(t[e+B]>1){const o=this.clusterProps[t[e+J]];return n?Object.assign({},o):o}const o=this.points[t[e+G]].tags,s=this.options.map(o);return n&&s===o?Object.assign({},s):s}}function R(t,e,n){return{id:t[e+G],type:"Point",tags:K(t,e,n),geometry:[t[e],t[e+1]]}}function V(t,e,n){return{type:"Feature",id:t[e+G],properties:K(t,e,n),geometry:{type:"Point",coordinates:[g(t[e]),m(t[e+1])]}}}function K(t,e,n){const o=t[e+B],s=o>=1e4?`${Math.round(o/1e3)}k`:o>=1e3?Math.round(o/100)/10+"k":o,i=t[e+J],r=-1===i?{}:Object.assign({},n[i]);return Object.assign(r,{cluster:!0,cluster_id:t[e+G],point_count:o,point_count_abbreviated:s})}const H="geojsonvt_clip_start",Q="geojsonvt_clip_end";function W(t,e,n,o,s){const i=e===s.maxZoom?0:s.tolerance/((1<<e)*s.extent),r={transformed:!1,features:[],source:null,x:n,y:o,z:e,minX:2,minY:1,maxX:-1,maxY:0,numPoints:0,numSimplified:0,numFeatures:t.length};for(const e of t)tt(r,e,i,s);return r}function tt(t,e,n,o){switch(t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),e.type){case"Point":case"MultiPoint":return void function(t,e){const n=[];for(let o=0;o<e.geometry.length;o+=3)n.push(e.geometry[o],e.geometry[o+1]),t.numPoints++,t.numSimplified++;if(!n.length)return;const o={type:1,tags:e.tags||null,geometry:n};null!==e.id&&(o.id=e.id);t.features.push(o)}(t,e);case"LineString":return void function(t,e,n,o){const s=[];if(et(s,e.geometry,t,n,!1,!1),!s.length)return;let i=e.tags||null;if(o.lineMetrics){i={};for(const t in e.tags)i[t]=e.tags[t];i[H]=e.geometry.start/e.geometry.size,i[Q]=e.geometry.end/e.geometry.size}const r={type:2,tags:i,geometry:s};null!==e.id&&(r.id=e.id);t.features.push(r)}(t,e,n,o);case"MultiLineString":case"Polygon":return void function(t,e,n){const o=[];for(let s=0;s<e.geometry.length;s++)et(o,e.geometry[s],t,n,"Polygon"===e.type,0===s);if(!o.length)return;const s={type:"Polygon"===e.type?3:2,tags:e.tags||null,geometry:o};null!==e.id&&(s.id=e.id);t.features.push(s)}(t,e,n);case"MultiPolygon":return void function(t,e,n){const o=[];for(let s=0;s<e.geometry.length;s++){const i=e.geometry[s];for(let e=0;e<i.length;e++)et(o,i[e],t,n,!0,0===e)}if(!o.length)return;const s={type:3,tags:e.tags||null,geometry:o};null!==e.id&&(s.id=e.id);t.features.push(s)}(t,e,n)}}function et(t,e,n,o,s,i){const r=o*o;if(o>0&&e.size<(s?r:o))return void(n.numPoints+=e.length/3);const a=[];for(let t=0;t<e.length;t+=3)(0===o||e[t+2]>r)&&(n.numSimplified++,a.push(e[t],e[t+1])),n.numPoints++;s&&function(t,e){let n=0;for(let e=0,o=t.length,s=o-2;e<o;s=e,e+=2)n+=(t[e]-t[s])*(t[e+1]+t[s+1]);if(n>0!==e)return;for(let e=0,n=t.length;e<n/2;e+=2){const o=t[e],s=t[e+1];t[e]=t[n-2-e],t[e+1]=t[n-1-e],t[n-2-e]=o,t[n-1-e]=s}}(a,i),t.push(a)}function nt(t,e){if(t.transformed)return t;const n=1<<t.z,o=t.x,s=t.y;for(const i of t.features)1===i.type?ot(i,e,n,o,s):st(i,e,n,o,s);return t.transformed=!0,t}function ot(t,e,n,o,s){const i=t,r=t.geometry,a=[];for(let t=0;t<r.length;t+=2)a.push(it(r[t],r[t+1],e,n,o,s));return i.geometry=a,i}function st(t,e,n,o,s){const i=t,r=t.geometry,a=[];for(const t of r){const i=[];for(let r=0;r<t.length;r+=2)i.push(it(t[r],t[r+1],e,n,o,s));a.push(i)}return i.geometry=a,i}function it(t,e,n,o,s,i){return[Math.round(n*(t*o-s)),Math.round(n*(e*o-i))]}class rt{constructor(t){this.options=t,this.stats={},this.total=0,this.tiles={},this.tileCoords=[],this.stats={},this.total=0}initialize(t){this.splitTile(t,0,0,0),this.options.debug&&(t.length&&console.log("features: %d, points: %d",this.tiles[0].numFeatures,this.tiles[0].numPoints),console.timeEnd("generate tiles"),console.log("tiles generated:",this.total,JSON.stringify(this.stats)))}updateIndex(t,e,n){n.debug>1&&(console.log("invalidating tiles"),console.time("invalidating")),this.invalidateTiles(e),n.debug>1&&console.timeEnd("invalidating");const[o,s,i]=[0,0,0],r=W(t,o,s,i,n);r.source=t;const a=at(o,s,i);if(this.tiles[a]=r,this.tileCoords.push({z:o,x:s,y:i,id:a}),n.debug){const t=`z${o}`;this.stats[t]=(this.stats[t]||0)+1,this.total++}}getClusterExpansionZoom(t){return null}getChildren(t){return null}getLeaves(t,e,n){return null}getTile(t,e,n){const{extent:o,debug:s}=this.options,i=1<<t,r=at(t,e=e+i&i-1,n);if(this.tiles[r])return nt(this.tiles[r],o);s>1&&console.log("drilling down to z%d-%d-%d",t,e,n);let a,u=t,c=e,l=n;for(;!a&&u>0;)u--,c>>=1,l>>=1,a=this.tiles[at(u,c,l)];return a?.source?(s>1&&(console.log("found parent tile z%d-%d-%d",u,c,l),console.time("drilling down")),this.splitTile(a.source,u,c,l,t,e,n),s>1&&console.timeEnd("drilling down"),this.tiles[r]?nt(this.tiles[r],o):null):null}splitTile(t,e,n,o,s,i,r){const a=[t,e,n,o],u=this.options,c=u.debug;for(;a.length;){o=a.pop(),n=a.pop(),e=a.pop(),t=a.pop();const l=1<<e,h=at(e,n,o);let d=this.tiles[h];if(!d&&(c>1&&console.time("creation"),d=this.tiles[h]=W(t,e,n,o,u),this.tileCoords.push({z:e,x:n,y:o,id:h}),c)){c>1&&(console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)",e,n,o,d.numFeatures,d.numPoints,d.numSimplified),console.timeEnd("creation"));const t=`z${e}`;this.stats[t]=(this.stats[t]||0)+1,this.total++}if(d.source=t,null==s){if(e===u.indexMaxZoom||d.numPoints<=u.indexMaxPoints)continue}else{if(e===u.maxZoom||e===s)continue;if(null!=s){const t=s-e;if(n!==i>>t||o!==r>>t)continue}}if(d.source=null,!t.length)continue;c>1&&console.time("clipping");const p=.5*u.buffer/u.extent,f=.5-p,g=.5+p,m=1+p;let M=null,w=null,P=null,I=null;const v=x(t,l,n-p,n+g,y.X,d.minX,d.maxX,u),b=x(t,l,n+f,n+m,y.X,d.minX,d.maxX,u);v&&(M=x(v,l,o-p,o+g,y.Y,d.minY,d.maxY,u),w=x(v,l,o+f,o+m,y.Y,d.minY,d.maxY,u)),b&&(P=x(b,l,o-p,o+g,y.Y,d.minY,d.maxY,u),I=x(b,l,o+f,o+m,y.Y,d.minY,d.maxY,u)),c>1&&console.timeEnd("clipping"),a.push(M||[],e+1,2*n,2*o),a.push(w||[],e+1,2*n,2*o+1),a.push(P||[],e+1,2*n+1,2*o),a.push(I||[],e+1,2*n+1,2*o+1)}}invalidateTiles(t){if(!t.length)return;const e=this.options,{debug:n}=e;let o=1/0,s=-1/0,i=1/0,r=-1/0;for(const e of t)o=Math.min(o,e.minX),s=Math.max(s,e.maxX),i=Math.min(i,e.minY),r=Math.max(r,e.maxY);const a=e.buffer/e.extent,u=new Set;for(const e in this.tiles){const c=this.tiles[e],l=1<<c.z,h=(c.x-a)/l,d=(c.x+1+a)/l,p=(c.y-a)/l,f=(c.y+1+a)/l;if(s<h||o>=d||r<p||i>=f)continue;let g=!1;for(const e of t)if(e.maxX>=h&&e.minX<d&&e.maxY>=p&&e.minY<f){g=!0;break}if(g){if(n){n>1&&console.log("invalidate tile z%d-%d-%d (features: %d, points: %d, simplified: %d)",c.z,c.x,c.y,c.numFeatures,c.numPoints,c.numSimplified);const t=`z${c.z}`;this.stats[t]=(this.stats[t]||0)-1,this.total--}delete this.tiles[e],u.add(e)}}u.size&&(this.tileCoords=this.tileCoords.filter((t=>!u.has(t.id))))}}function at(t,e,n){return 32*((1<<t)*n+e)+t}const ut={maxZoom:14,indexMaxZoom:5,indexMaxPoints:1e5,tolerance:3,extent:4096,buffer:64,lineMetrics:!1,promoteId:null,generateId:!1,updateable:!1,cluster:!1,clusterOptions:$,debug:0};t.GEOJSONVT_CLIP_END=Q,t.GEOJSONVT_CLIP_START=H,t.GeoJSONVT=class{get tiles(){return this.tileIndex?.tiles??{}}get stats(){return this.tileIndex.stats}get total(){return this.tileIndex.total}constructor(t,e){const n=(e=this.options=Object.assign({},ut,e)).debug;if(n&&console.time("preprocess data"),e.maxZoom<0||e.maxZoom>24)throw new Error("maxZoom should be in the 0-24 range");if(e.promoteId&&e.generateId)throw new Error("promoteId and generateId cannot be used together.");let o=i(t,e);n&&(console.timeEnd("preprocess data"),console.log("index: maxZoom: %d, maxPoints: %d",e.indexMaxZoom,e.indexMaxPoints),console.time("generate tiles")),o=X(o,e),e.updateable&&(this.source=o),this.initializeIndex(o,e)}initializeIndex(t,e){this.tileIndex=e.cluster?new q(e.clusterOptions):new rt(e),t.length&&this.tileIndex.initialize(t)}getTile(t,e,n){return e=+e,n=+n,(t=+t)<0||t>24?null:this.tileIndex.getTile(t,e,n)}updateData(t,e){const n=this.options;if(!n.updateable)throw new Error("to update tile geojson `updateable` option must be set to true");let{affected:o,source:s}=O(this.source,t,n);e&&({affected:o,source:s}=this.filterUpdate(s,o,e)),o.length&&(this.source=s,this.tileIndex.updateIndex(s,o,n))}filterUpdate(t,e,n){const o=new Set;for(const s of t)null!=s.id&&(n(h(s))||(e.push(s),o.add(s.id)));return{affected:e,source:t=t.filter((t=>!o.has(t.id)))}}getData(){if(!this.options.updateable)throw new Error("to retrieve data the `updateable` option must be set to true");return{type:"FeatureCollection",features:this.source.map((t=>h(t)))}}updateClusterOptions(t,e){const n=this.options.cluster;this.options.cluster=t,this.options.clusterOptions=e,n!=t?this.initializeIndex(this.source,this.options):this.tileIndex.updateIndex(this.source,[],this.options)}getClusterExpansionZoom(t){return this.tileIndex.getClusterExpansionZoom(t)}getClusterChildren(t){return this.tileIndex.getChildren(t)}getClusterLeaves(t,e,n){return this.tileIndex.getLeaves(t,e,n)}},t.Supercluster=q,t.geoJSONToTile=function(t,e,n,o,s={}){s={...ut,...s};const{wrap:r=!1,clip:a=!1}=s;let u=i(t,s);if(r&&(u=X(u,s)),a||s.lineMetrics){const t=1<<e,i=s.buffer/s.extent,r=x(u,t,n-i,n+1+i,y.X,-1,2,s);u=x(r||[],t,o-i,o+1+i,y.Y,-1,2,s)}return nt(W(u??[],e,n,o,s),s.extent)}}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).geojsonvt={})}(this,(function(t){"use strict";function e(t,o,s,i){let r=i;const a=o+(s-o>>1);let u,c=s-o;const l=t[o],h=t[o+1],p=t[s],d=t[s+1];for(let e=o+3;e<s;e+=3){const o=n(t[e],t[e+1],l,h,p,d);if(o>r)u=e,r=o;else if(o===r){const t=Math.abs(e-a);t<c&&(u=e,c=t)}}r>i&&(u-o>3&&e(t,o,u,i),t[u+2]=r,s-u>3&&e(t,u,s,i))}function n(t,e,n,o,s,i){let r=s-n,a=i-o;if(0!==r||0!==a){const u=((t-n)*r+(e-o)*a)/(r*r+a*a);u>1?(n=s,o=i):u>0&&(n+=r*u,o+=a*u)}return r=t-n,a=e-o,r*r+a*a}function o(t,e,n,o){const s={type:e,geom:n},r={id:null==t?null:t,type:s.type,geometry:s.geom,tags:o,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};switch(s.type){case"Point":case"MultiPoint":i(r,s.geom);break;case"LineString":i(r,s.geom.points);break;case"Polygon":i(r,s.geom[0].points);break;case"MultiLineString":for(const t of s.geom)i(r,t.points);break;case"MultiPolygon":for(const t of s.geom)i(r,t[0].points)}return r}function s(t){const e=t;t.points.length>64&&(e.points=new Float64Array(t.points))}function i(t,e){for(let n=0;n<e.length;n+=3)t.minX=Math.min(t.minX,e[n]),t.minY=Math.min(t.minY,e[n+1]),t.maxX=Math.max(t.maxX,e[n]),t.maxY=Math.max(t.maxY,e[n+1])}function r(t,e){const n=[];switch(t.type){case"FeatureCollection":for(let o=0;o<t.features.length;o++)a(n,t.features[o],e,o);break;case"Feature":a(n,t,e);break;default:a(n,{geometry:t,properties:void 0},e)}return n}function a(t,e,n,s){if(!e.geometry)return;if("GeometryCollection"===e.geometry.type)return void function(t,e,n,o,s){for(const i of n.geometries)a(t,{id:e.id,geometry:i,properties:e.properties},o,s)}(t,e,e.geometry,n,s);const i=e.geometry.coordinates;if(!i?.length)return;const r=function(t,e,n){if(e.promoteId)return t.properties?.[e.promoteId];if(e.generateId)return n||0;return t.id}(e,n,s),p=Math.pow(n.tolerance/((1<<n.maxZoom)*n.extent),2);switch(e.geometry.type){case"Point":return void function(t,e,n,s){const i=[];i.push(l(n.coordinates[0]),h(n.coordinates[1]),0),t.push(o(e,"Point",i,s))}(t,r,e.geometry,e.properties);case"MultiPoint":return void function(t,e,n,s){const i=[];for(const t of n.coordinates)i.push(l(t[0]),h(t[1]),0);t.push(o(e,"MultiPoint",i,s))}(t,r,e.geometry,e.properties);case"LineString":return void function(t,e,n,s,i){const r={points:[]};u(n.coordinates,r,s,!1),t.push(o(e,"LineString",r,i))}(t,r,e.geometry,p,e.properties);case"MultiLineString":return void function(t,e,n,s,i,r){if(i.lineMetrics)for(const i of n.coordinates){const n={points:[]};u(i,n,s,!1),t.push(o(e,"LineString",n,r))}else{const i=[];c(n.coordinates,i,s,!1),t.push(o(e,"MultiLineString",i,r))}}(t,r,e.geometry,p,n,e.properties);case"Polygon":return void function(t,e,n,s,i){const r=[];c(n.coordinates,r,s,!0),t.push(o(e,"Polygon",r,i))}(t,r,e.geometry,p,e.properties);case"MultiPolygon":return void function(t,e,n,s,i){const r=[];for(const t of n.coordinates){const e=[];c(t,e,s,!0),r.push(e)}t.push(o(e,"MultiPolygon",r,i))}(t,r,e.geometry,p,e.properties);default:throw new Error("Input data is not a valid GeoJSON object.")}}function u(t,n,o,i){let r,a,u=0;for(let e=0;e<t.length;e++){const o=l(t[e][0]),s=h(t[e][1]);n.points.push(o,s,0),e>0&&(u+=i?(r*s-o*a)/2:Math.sqrt(Math.pow(o-r,2)+Math.pow(s-a,2))),r=o,a=s}const c=n.points.length-3;n.points[2]=1,o>0&&e(n.points,0,c,o),n.points[c+2]=1,s(n),n.size=Math.abs(u),n.start=0,n.end=n.size}function c(t,e,n,o){for(let s=0;s<t.length;s++){const i={points:[]};u(t[s],i,n,o),e.push(i)}}function l(t){return t/360+.5}function h(t){const e=Math.sin(t*Math.PI/180),n=.5-.25*Math.log((1+e)/(1-e))/Math.PI;return n<0?0:n>1?1:n}function p(t){const e={type:"Feature",geometry:d(t),properties:t.tags};return null!=t.id&&(e.id=t.id),e}function d(t){const{type:e,geometry:n}=t;switch(e){case"Point":return{type:e,coordinates:g(n[0],n[1])};case"MultiPoint":return{type:e,coordinates:f(n)};case"LineString":return{type:e,coordinates:f(n.points)};case"MultiLineString":case"Polygon":return{type:e,coordinates:n.map((t=>f(t.points)))};case"MultiPolygon":return{type:e,coordinates:n.map((t=>t.map((t=>f(t.points)))))}}}function f(t){const e=[];for(let n=0;n<t.length;n+=3)e.push(g(t[n],t[n+1]));return e}function g(t,e){return[m(t),y(e)]}function m(t){return 360*(t-.5)}function y(t){const e=(180-360*t)*Math.PI/180;return 360*Math.atan(Math.exp(e))/Math.PI-90}var x;function M(t,e,n,o,s,i,r,a){if(o/=e,i>=(n/=e)&&r<o)return t;if(r<n||i>=o)return null;const u=[];for(const e of t){const t=s===x.X?e.minX:e.minY,i=s===x.X?e.maxX:e.maxY;if(t>=n&&i<o)u.push(e);else if(!(i<n||t>=o))switch(e.type){case"Point":case"MultiPoint":w(e,u,n,o,s);continue;case"LineString":P(e,u,n,o,s,a);continue;case"MultiLineString":I(e,u,n,o,s);continue;case"Polygon":v(e,u,n,o,s);continue;case"MultiPolygon":b(e,u,n,o,s);continue}}return u.length?u:null}function w(t,e,n,s,i){const r=[];if(function(t,e,n,o,s){for(let i=0;i<t.length;i+=3){const r=t[i+s];r>=n&&r<=o&&E(e,t[i],t[i+1],t[i+2])}}(t.geometry,r,n,s,i),!r.length)return;const a=3===r.length?"Point":"MultiPoint";e.push(o(t.id,a,r,t.tags))}function P(t,e,n,s,i,r){const a=[];if(S(t.geometry,a,n,s,i,!1,r.lineMetrics),a.length)if(r.lineMetrics)for(const n of a)e.push(o(t.id,"LineString",n,t.tags));else a.length>1?e.push(o(t.id,"MultiLineString",a,t.tags)):e.push(o(t.id,"LineString",a[0],t.tags))}function I(t,e,n,s,i){const r=[];A(t.geometry,r,n,s,i,!1),r.length&&(1!==r.length?e.push(o(t.id,"MultiLineString",r,t.tags)):e.push(o(t.id,"LineString",r[0],t.tags)))}function v(t,e,n,s,i){const r=[];A(t.geometry,r,n,s,i,!0),r.length&&e.push(o(t.id,"Polygon",r,t.tags))}function b(t,e,n,s,i){const r=[];for(const e of t.geometry){const t=[];A(e,t,n,s,i,!0),t.length&&r.push(t)}r.length&&e.push(o(t.id,"MultiPolygon",r,t.tags))}function S(t,e,n,o,i,r,a){let u=z(t);const c=i===x.X?T:X;let l,h,p=t.start;for(let s=0;s<t.points.length-3;s+=3){const d=t.points[s],f=t.points[s+1],g=t.points[s+2],m=t.points[s+3],y=t.points[s+4],M=i===x.X?d:f,w=i===x.X?m:y;let P=!1;a&&(l=Math.sqrt(Math.pow(d-m,2)+Math.pow(f-y,2))),M<n?w>n&&(h=c(u,d,f,m,y,n),a&&(u.start=p+l*h)):M>o?w<o&&(h=c(u,d,f,m,y,o),a&&(u.start=p+l*h)):E(u.points,d,f,g),w<n&&M>=n&&(h=c(u,d,f,m,y,n),P=!0),w>o&&M<=o&&(h=c(u,d,f,m,y,o),P=!0),!r&&P&&(a&&(u.end=p+l*h),e.push(u),u=z(t)),a&&(p+=l)}let d=t.points.length-3;const f=t.points[d],g=t.points[d+1],m=t.points[d+2],y=i===x.X?f:g;y>=n&&y<=o&&E(u.points,f,g,m),d=u.points.length-3,r&&d>=3&&(u.points[d]!==u.points[0]||u.points[d+1]!==u.points[1])&&E(u.points,u.points[0],u.points[1],u.points[2]),u.points.length&&(s(u),e.push(u))}function z(t){return{points:[],size:t.size,start:t.start,end:t.end}}function A(t,e,n,o,s,i){for(const r of t)S(r,e,n,o,s,i,!1)}function E(t,e,n,o){t.push(e,n,o)}function T(t,e,n,o,s,i){const r=(i-e)/(o-e);return E(t.points,i,n+(s-n)*r,1),r}function X(t,e,n,o,s,i){const r=(i-n)/(s-n);return E(t.points,e+(o-e)*r,i,1),r}function Y(t,e){const n=e.buffer/e.extent;let o=t;const s=M(t,1,-1-n,n,x.X,-1,2,e),i=M(t,1,1-n,2+n,x.X,-1,2,e);return s||i?(o=M(t,1,-n,1+n,x.X,-1,2,e)||[],s&&(o=L(s,1).concat(o)),i&&(o=o.concat(L(i,-1))),o):o}function L(t,e){const n=[];for(const s of t)switch(s.type){case"Point":case"MultiPoint":{const t=O(s.geometry,e);n.push(o(s.id,s.type,t,s.tags));continue}case"LineString":{const t=C(s.geometry,e);n.push(o(s.id,s.type,t,s.tags));continue}case"MultiLineString":case"Polygon":{const t=[];for(const n of s.geometry)t.push(C(n,e));n.push(o(s.id,s.type,t,s.tags));continue}case"MultiPolygon":{const t=[];for(const n of s.geometry){const o=[];for(const t of n)o.push(C(t,e));t.push(o)}n.push(o(s.id,s.type,t,s.tags));continue}}return n}function O(t,e){const n=[];for(let o=0;o<t.length;o+=3)n.push(t[o]+e,t[o+1],t[o+2]);return n}function C(t,e){const n={points:[],size:t.size};void 0!==t.start&&(n.start=t.start,n.end=t.end);for(let o=0;o<t.points.length;o+=3)n.points.push(t.points[o]+e,t.points[o+1],t.points[o+2]);return s(n),n}function _(t,e,n){const o=function(t,e){if(!t)return{remove:new Set,add:new Map,update:new Map};const n={removeAll:t.removeAll,remove:new Set(t.remove||[]),add:new Map(t.add?.map((t=>[e.promoteId?t.properties[e.promoteId]:t.id,t]))),update:new Map(t.update?.map((t=>[t.id,t])))};return n}(e,n);let s=[];if(o.removeAll&&(s=t,t=[]),o.remove.size||o.add.size){const e=[];for(const n of t)(o.remove.has(n.id)||o.add.has(n.id))&&e.push(n);if(e.length){s.push(...e);const n=new Set(e.map((t=>t.id)));t=t.filter((t=>!n.has(t.id)))}if(o.add.size){let e=r({type:"FeatureCollection",features:Array.from(o.add.values())},n);e=Y(e,n),s.push(...e),t.push(...e)}}if(o.update.size)for(const[e,i]of o.update){const o=[],r=[];for(const n of t)n.id===e?o.push(n):r.push(n);if(!o.length)continue;const a=Z(o,i,n);a.length&&(s.push(...o,...a),r.push(...a),t=r)}return{affected:s,source:t}}function Z(t,e,n){const o=!!e.newGeometry,s=e.removeAllProperties||e.removeProperties?.length>0||e.addOrUpdateProperties?.length>0;if(o){const o=t[0];let i=r({type:"FeatureCollection",features:[{type:"Feature",id:o.id,geometry:e.newGeometry,properties:s?F(o.tags,e):o.tags}]},n);return i=Y(i,n),i}if(s){const n=[];for(const o of t){const t={...o};t.tags=F(t.tags,e),n.push(t)}return n}return[]}function F(t,e){if(e.removeAllProperties)return{};const n={...t||{}};if(e.removeProperties)for(const t of e.removeProperties)delete n[t];if(e.addOrUpdateProperties)for(const{key:t,value:o}of e.addOrUpdateProperties)n[t]=o;return n}!function(t){t[t.X=0]="X",t[t.Y=1]="Y"}(x||(x={}));const U=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class D{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,n]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const o=n>>4;if(1!==o)throw new Error(`Got v${o} data when expected v1.`);const s=U[15&n];if(!s)throw new Error("Unrecognized array type.");const[i]=new Uint16Array(t,2,1),[r]=new Uint32Array(t,4,1);return new D(r,i,s,t)}constructor(t,e=64,n=Float64Array,o){if(isNaN(t)||t<0)throw new Error(`Unpexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.ArrayType=n,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const s=U.indexOf(this.ArrayType),i=2*t*this.ArrayType.BYTES_PER_ELEMENT,r=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-r%8)%8;if(s<0)throw new Error(`Unexpected typed array class: ${n}.`);o&&o instanceof ArrayBuffer?(this.data=o,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+r+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+i+r+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+r+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+s]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const n=this._pos>>1;return this.ids[n]=n,this.coords[this._pos++]=t,this.coords[this._pos++]=e,n}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return j(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,n,o){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:s,coords:i,nodeSize:r}=this,a=[0,s.length-1,0],u=[];for(;a.length;){const c=a.pop()||0,l=a.pop()||0,h=a.pop()||0;if(l-h<=r){for(let r=h;r<=l;r++){const a=i[2*r],c=i[2*r+1];a>=t&&a<=n&&c>=e&&c<=o&&u.push(s[r])}continue}const p=h+l>>1,d=i[2*p],f=i[2*p+1];d>=t&&d<=n&&f>=e&&f<=o&&u.push(s[p]),(0===c?t<=d:e<=f)&&(a.push(h),a.push(p-1),a.push(1-c)),(0===c?n>=d:o>=f)&&(a.push(p+1),a.push(l),a.push(1-c))}return u}within(t,e,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:o,coords:s,nodeSize:i}=this,r=[0,o.length-1,0],a=[],u=n*n;for(;r.length;){const c=r.pop()||0,l=r.pop()||0,h=r.pop()||0;if(l-h<=i){for(let n=h;n<=l;n++)G(s[2*n],s[2*n+1],t,e)<=u&&a.push(o[n]);continue}const p=h+l>>1,d=s[2*p],f=s[2*p+1];G(d,f,t,e)<=u&&a.push(o[p]),(0===c?t-n<=d:e-n<=f)&&(r.push(h),r.push(p-1),r.push(1-c)),(0===c?t+n>=d:e+n>=f)&&(r.push(p+1),r.push(l),r.push(1-c))}return a}}function j(t,e,n,o,s,i){if(s-o<=n)return;const r=o+s>>1;N(t,e,r,o,s,i),j(t,e,n,o,r-1,1-i),j(t,e,n,r+1,s,1-i)}function N(t,e,n,o,s,i){for(;s>o;){if(s-o>600){const r=s-o+1,a=n-o+1,u=Math.log(r),c=.5*Math.exp(2*u/3),l=.5*Math.sqrt(u*c*(r-c)/r)*(a-r/2<0?-1:1);N(t,e,n,Math.max(o,Math.floor(n-a*c/r+l)),Math.min(s,Math.floor(n+(r-a)*c/r+l)),i)}const r=e[2*n+i];let a=o,u=s;for(k(t,e,o,n),e[2*s+i]>r&&k(t,e,o,s);a<u;){for(k(t,e,a,u),a++,u--;e[2*a+i]<r;)a++;for(;e[2*u+i]>r;)u--}e[2*o+i]===r?k(t,e,o,u):(u++,k(t,e,u,s)),u<=n&&(o=u+1),n<=u&&(s=u-1)}}function k(t,e,n,o){$(t,n,o),$(e,2*n,2*o),$(e,2*n+1,2*o+1)}function $(t,e,n){const o=t[e];t[e]=t[n],t[n]=o}function G(t,e,n,o){const s=t-n,i=e-o;return s*s+i*i}const B={minZoom:0,maxZoom:16,minPoints:2,radius:40,extent:512,nodeSize:64,log:!1,generateId:!1,reduce:null,map:t=>t},J=3,q=5,R=6;class V{constructor(t){this.options=Object.assign(Object.create(B),t),this.trees=new Array(this.options.maxZoom+1),this.stride=this.options.reduce?7:6,this.clusterProps=[],this.points=[]}load(t){const e=[];for(const n of t){if(!n.geometry)continue;const[t,o]=n.geometry.coordinates,[s,i]=[l(t),h(o)],r={id:n.id,type:"Point",geometry:[s,i],tags:n.properties};e.push(r)}this.createIndex(e)}initialize(t){const e=[];for(const n of t)"Point"===n.type&&e.push(n);this.createIndex(e)}updateIndex(t,e,n){this.options=Object.assign(Object.create(B),n.clusterOptions),this.initialize(t)}createIndex(t){const{log:e,minZoom:n,maxZoom:o}=this.options;e&&console.time("total time");const s=`prepare ${t.length} points`;e&&console.time(s),this.points=t;const i=[];for(let e=0;e<t.length;e++){const n=t[e];if(!n?.geometry)continue;let[o,s]=n.geometry;o=Math.fround(o),s=Math.fround(s),i.push(o,s,1/0,e,-1,1),this.options.reduce&&i.push(0)}let r=this.trees[o+1]=this.createTree(i);e&&console.timeEnd(s);for(let t=o;t>=n;t--){const n=Date.now();r=this.trees[t]=this.createTree(this.cluster(r,t)),e&&console.log("z%d: %d clusters in %dms",t,r.numItems,Date.now()-n)}e&&console.timeEnd("total time")}getClusters(t,e){return this.getClustersInternal(t,e).map((t=>p(t)))}getClustersInternal(t,e){let n=((t[0]+180)%360+360)%360-180;const o=Math.max(-90,Math.min(90,t[1]));let s=180===t[2]?180:((t[2]+180)%360+360)%360-180;const i=Math.max(-90,Math.min(90,t[3]));if(t[2]-t[0]>=360)n=-180,s=180;else if(n>s){const t=this.getClustersInternal([n,o,180,i],e),r=this.getClustersInternal([-180,o,s,i],e);return t.concat(r)}const r=this.trees[this.limitZoom(e)],a=r.range(l(n),h(i),l(s),h(o)),u=r.flatData,c=[];for(const t of a){const e=this.stride*t;c.push(u[e+q]>1?K(u,e,this.clusterProps):this.points[u[e+J]])}return c}getChildren(t){const e=this.getOriginId(t),n=this.getOriginZoom(t),o=new Error("No cluster with the specified id: "+t),s=this.trees[n];if(!s)throw o;const i=s.flatData;if(e*this.stride>=i.length)throw o;const r=this.options.radius/(this.options.extent*Math.pow(2,n-1)),a=i[e*this.stride],u=i[e*this.stride+1],c=s.within(a,u,r),l=[];for(const e of c){const n=e*this.stride;i[n+4]===t&&l.push(i[n+q]>1?H(i,n,this.clusterProps):p(this.points[i[n+J]]))}if(0===l.length)throw o;return l}getLeaves(t,e,n){e=e||10,n=n||0;const o=[];return this.appendLeaves(o,t,e,n,0),o}getTile(t,e,n){const o=this.trees[this.limitZoom(t)];if(!o)return null;const s=Math.pow(2,t),{extent:i,radius:r}=this.options,a=r/i,u=(n-a)/s,c=(n+1+a)/s,l={transformed:!0,features:[],source:null,x:e,y:n,z:t};return this.addTileFeatures(o.range((e-a)/s,u,(e+1+a)/s,c),o.flatData,e,n,s,l),0===e&&this.addTileFeatures(o.range(1-a/s,u,1,c),o.flatData,s,n,s,l),e===s-1&&this.addTileFeatures(o.range(0,u,a/s,c),o.flatData,-1,n,s,l),l}getClusterExpansionZoom(t){return this.getOriginZoom(t)}appendLeaves(t,e,n,o,s){const i=this.getChildren(e);for(const e of i){const i=e.properties;if(i?.cluster?s+i.point_count<=o?s+=i.point_count:s=this.appendLeaves(t,i.cluster_id,n,o,s):s<o?s++:t.push(e),t.length===n)break}return s}createTree(t){const e=new D(t.length/this.stride|0,this.options.nodeSize,Float32Array);for(let n=0;n<t.length;n+=this.stride)e.add(t[n],t[n+1]);return e.finish(),e.flatData=t,e.data=null,e}addTileFeatures(t,e,n,o,s,i){for(const r of t){const t=r*this.stride,a=e[t+q]>1;let u,c,l;if(a)u=Q(e,t,this.clusterProps),c=e[t],l=e[t+1];else{const n=this.points[e[t+J]];u=n.tags,[c,l]=n.geometry}const h={type:1,geometry:[[Math.round(this.options.extent*(c*s-n)),Math.round(this.options.extent*(l*s-o))]],tags:u};let p;p=a||this.options.generateId?e[t+J]:this.points[e[t+J]].id,void 0!==p&&(h.id=p),i.features.push(h)}}limitZoom(t){return Math.max(this.options.minZoom,Math.min(Math.floor(+t),this.options.maxZoom+1))}cluster(t,e){const{radius:n,extent:o,reduce:s,minPoints:i}=this.options,r=n/(o*Math.pow(2,e)),a=t.flatData,u=[],c=this.stride;for(let n=0;n<a.length;n+=c){if(a[n+2]<=e)continue;a[n+2]=e;const o=a[n],l=a[n+1],h=t.within(a[n],a[n+1],r),p=a[n+q];let d=p;for(const t of h){const n=t*c;a[n+2]>e&&(d+=a[n+q])}if(d>p&&d>=i){let t,i=o*p,r=l*p,f=-1;const g=(n/c<<5)+(e+1)+this.points.length;for(const o of h){const u=o*c;if(a[u+2]<=e)continue;a[u+2]=e;const l=a[u+q];i+=a[u]*l,r+=a[u+1]*l,a[u+4]=g,s&&(t||(t=this.map(a,n,!0),f=this.clusterProps.length,this.clusterProps.push(t)),s(t,this.map(a,u)))}a[n+4]=g,u.push(i/d,r/d,1/0,g,-1,d),s&&u.push(f)}else{for(let t=0;t<c;t++)u.push(a[n+t]);if(d>1)for(const t of h){const n=t*c;if(!(a[n+2]<=e)){a[n+2]=e;for(let t=0;t<c;t++)u.push(a[n+t])}}}}return u}getOriginId(t){return t-this.points.length>>5}getOriginZoom(t){return(t-this.points.length)%32}map(t,e,n){if(t[e+q]>1){const o=this.clusterProps[t[e+R]];return n?Object.assign({},o):o}const o=this.points[t[e+J]].tags,s=this.options.map(o);return n&&s===o?Object.assign({},s):s}}function K(t,e,n){return{id:t[e+J],type:"Point",tags:Q(t,e,n),geometry:[t[e],t[e+1]]}}function H(t,e,n){return{type:"Feature",id:t[e+J],properties:Q(t,e,n),geometry:{type:"Point",coordinates:[m(t[e]),y(t[e+1])]}}}function Q(t,e,n){const o=t[e+q],s=o>=1e4?`${Math.round(o/1e3)}k`:o>=1e3?Math.round(o/100)/10+"k":o,i=t[e+R],r=-1===i?{}:Object.assign({},n[i]);return Object.assign(r,{cluster:!0,cluster_id:t[e+J],point_count:o,point_count_abbreviated:s})}const W="geojsonvt_clip_start",tt="geojsonvt_clip_end";function et(t,e,n,o,s){const i=e===s.maxZoom?0:s.tolerance/((1<<e)*s.extent),r={transformed:!1,features:[],source:null,x:n,y:o,z:e,minX:2,minY:1,maxX:-1,maxY:0,numPoints:0,numSimplified:0,numFeatures:t.length};for(const e of t)nt(r,e,i,s);return r}function nt(t,e,n,o){switch(t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),e.type){case"Point":case"MultiPoint":return void function(t,e){const n=[];for(let o=0;o<e.geometry.length;o+=3)n.push(e.geometry[o],e.geometry[o+1]),t.numPoints++,t.numSimplified++;if(!n.length)return;const o={type:1,tags:e.tags||null,geometry:n};null!==e.id&&(o.id=e.id);t.features.push(o)}(t,e);case"LineString":return void function(t,e,n,o){const s=[];if(ot(s,e.geometry,t,n,!1,!1),!s.length)return;let i=e.tags||null;if(o.lineMetrics){i={};for(const t in e.tags)i[t]=e.tags[t];i[W]=e.geometry.start/e.geometry.size,i[tt]=e.geometry.end/e.geometry.size}const r={type:2,tags:i,geometry:s};null!==e.id&&(r.id=e.id);t.features.push(r)}(t,e,n,o);case"MultiLineString":case"Polygon":return void function(t,e,n){const o=[];for(let s=0;s<e.geometry.length;s++)ot(o,e.geometry[s],t,n,"Polygon"===e.type,0===s);if(!o.length)return;const s={type:"Polygon"===e.type?3:2,tags:e.tags||null,geometry:o};null!==e.id&&(s.id=e.id);t.features.push(s)}(t,e,n);case"MultiPolygon":return void function(t,e,n){const o=[];for(let s=0;s<e.geometry.length;s++){const i=e.geometry[s];for(let e=0;e<i.length;e++)ot(o,i[e],t,n,!0,0===e)}if(!o.length)return;const s={type:3,tags:e.tags||null,geometry:o};null!==e.id&&(s.id=e.id);t.features.push(s)}(t,e,n)}}function ot(t,e,n,o,s,i){const r=o*o;if(o>0&&e.size<(s?r:o))return void(n.numPoints+=e.points.length/3);const a=[];for(let t=0;t<e.points.length;t+=3)(0===o||e.points[t+2]>r)&&(n.numSimplified++,a.push(e.points[t],e.points[t+1])),n.numPoints++;s&&function(t,e){let n=0;for(let e=0,o=t.length,s=o-2;e<o;s=e,e+=2)n+=(t[e]-t[s])*(t[e+1]+t[s+1]);if(n>0!==e)return;for(let e=0,n=t.length;e<n/2;e+=2){const o=t[e],s=t[e+1];t[e]=t[n-2-e],t[e+1]=t[n-1-e],t[n-2-e]=o,t[n-1-e]=s}}(a,i),t.push(a)}function st(t,e){if(t.transformed)return t;const n=1<<t.z,o=t.x,s=t.y;for(const i of t.features)1===i.type?it(i,e,n,o,s):rt(i,e,n,o,s);return t.transformed=!0,t}function it(t,e,n,o,s){const i=t,r=t.geometry,a=[];for(let t=0;t<r.length;t+=2)a.push(at(r[t],r[t+1],e,n,o,s));return i.geometry=a,i}function rt(t,e,n,o,s){const i=t,r=t.geometry,a=[];for(const t of r){const i=[];for(let r=0;r<t.length;r+=2)i.push(at(t[r],t[r+1],e,n,o,s));a.push(i)}return i.geometry=a,i}function at(t,e,n,o,s,i){return[Math.round(n*(t*o-s)),Math.round(n*(e*o-i))]}class ut{constructor(t){this.options=t,this.stats={},this.total=0,this.tiles={},this.tileCoords=[],this.stats={},this.total=0}initialize(t){this.splitTile(t,0,0,0),this.options.debug&&(t.length&&console.log("features: %d, points: %d",this.tiles[0].numFeatures,this.tiles[0].numPoints),console.timeEnd("generate tiles"),console.log("tiles generated:",this.total,JSON.stringify(this.stats)))}updateIndex(t,e,n){n.debug>1&&(console.log("invalidating tiles"),console.time("invalidating")),this.invalidateTiles(e),n.debug>1&&console.timeEnd("invalidating");const[o,s,i]=[0,0,0],r=et(t,o,s,i,n);r.source=t;const a=ct(o,s,i);if(this.tiles[a]=r,this.tileCoords.push({z:o,x:s,y:i,id:a}),n.debug){const t=`z${o}`;this.stats[t]=(this.stats[t]||0)+1,this.total++}}getClusterExpansionZoom(t){return null}getChildren(t){return null}getLeaves(t,e,n){return null}getTile(t,e,n){const{extent:o,debug:s}=this.options,i=1<<t,r=ct(t,e=e+i&i-1,n);if(this.tiles[r])return st(this.tiles[r],o);s>1&&console.log("drilling down to z%d-%d-%d",t,e,n);let a,u=t,c=e,l=n;for(;!a&&u>0;)u--,c>>=1,l>>=1,a=this.tiles[ct(u,c,l)];return a?.source?(s>1&&(console.log("found parent tile z%d-%d-%d",u,c,l),console.time("drilling down")),this.splitTile(a.source,u,c,l,t,e,n),s>1&&console.timeEnd("drilling down"),this.tiles[r]?st(this.tiles[r],o):null):null}splitTile(t,e,n,o,s,i,r){const a=[t,e,n,o],u=this.options,c=u.debug;for(;a.length;){o=a.pop(),n=a.pop(),e=a.pop(),t=a.pop();const l=1<<e,h=ct(e,n,o);let p=this.tiles[h];if(!p&&(c>1&&console.time("creation"),p=this.tiles[h]=et(t,e,n,o,u),this.tileCoords.push({z:e,x:n,y:o,id:h}),c)){c>1&&(console.log("tile z%d-%d-%d (features: %d, points: %d, simplified: %d)",e,n,o,p.numFeatures,p.numPoints,p.numSimplified),console.timeEnd("creation"));const t=`z${e}`;this.stats[t]=(this.stats[t]||0)+1,this.total++}if(p.source=t,null==s){if(e===u.indexMaxZoom||p.numPoints<=u.indexMaxPoints)continue}else{if(e===u.maxZoom||e===s)continue;if(null!=s){const t=s-e;if(n!==i>>t||o!==r>>t)continue}}if(p.source=null,!t.length)continue;c>1&&console.time("clipping");const d=.5*u.buffer/u.extent,f=.5-d,g=.5+d,m=1+d;let y=null,w=null,P=null,I=null;const v=M(t,l,n-d,n+g,x.X,p.minX,p.maxX,u),b=M(t,l,n+f,n+m,x.X,p.minX,p.maxX,u);v&&(y=M(v,l,o-d,o+g,x.Y,p.minY,p.maxY,u),w=M(v,l,o+f,o+m,x.Y,p.minY,p.maxY,u)),b&&(P=M(b,l,o-d,o+g,x.Y,p.minY,p.maxY,u),I=M(b,l,o+f,o+m,x.Y,p.minY,p.maxY,u)),c>1&&console.timeEnd("clipping"),a.push(y||[],e+1,2*n,2*o),a.push(w||[],e+1,2*n,2*o+1),a.push(P||[],e+1,2*n+1,2*o),a.push(I||[],e+1,2*n+1,2*o+1)}}invalidateTiles(t){if(!t.length)return;const e=this.options,{debug:n}=e;let o=1/0,s=-1/0,i=1/0,r=-1/0;for(const e of t)o=Math.min(o,e.minX),s=Math.max(s,e.maxX),i=Math.min(i,e.minY),r=Math.max(r,e.maxY);const a=e.buffer/e.extent,u=new Set;for(const e in this.tiles){const c=this.tiles[e],l=1<<c.z,h=(c.x-a)/l,p=(c.x+1+a)/l,d=(c.y-a)/l,f=(c.y+1+a)/l;if(s<h||o>=p||r<d||i>=f)continue;let g=!1;for(const e of t)if(e.maxX>=h&&e.minX<p&&e.maxY>=d&&e.minY<f){g=!0;break}if(g){if(n){n>1&&console.log("invalidate tile z%d-%d-%d (features: %d, points: %d, simplified: %d)",c.z,c.x,c.y,c.numFeatures,c.numPoints,c.numSimplified);const t=`z${c.z}`;this.stats[t]=(this.stats[t]||0)-1,this.total--}delete this.tiles[e],u.add(e)}}u.size&&(this.tileCoords=this.tileCoords.filter((t=>!u.has(t.id))))}}function ct(t,e,n){return 32*((1<<t)*n+e)+t}const lt={maxZoom:14,indexMaxZoom:5,indexMaxPoints:1e5,tolerance:3,extent:4096,buffer:64,lineMetrics:!1,promoteId:null,generateId:!1,updateable:!1,cluster:!1,clusterOptions:B,debug:0};t.GEOJSONVT_CLIP_END=tt,t.GEOJSONVT_CLIP_START=W,t.GeoJSONVT=class{get tiles(){return this.tileIndex?.tiles??{}}get stats(){return this.tileIndex.stats}get total(){return this.tileIndex.total}constructor(t,e){const n=(e=this.options=Object.assign({},lt,e)).debug;if(n&&console.time("preprocess data"),e.maxZoom<0||e.maxZoom>24)throw new Error("maxZoom should be in the 0-24 range");if(e.promoteId&&e.generateId)throw new Error("promoteId and generateId cannot be used together.");let o=r(t,e);n&&(console.timeEnd("preprocess data"),console.log("index: maxZoom: %d, maxPoints: %d",e.indexMaxZoom,e.indexMaxPoints),console.time("generate tiles")),o=Y(o,e),e.updateable&&(this.source=o),this.initializeIndex(o,e)}initializeIndex(t,e){this.tileIndex=e.cluster?new V(e.clusterOptions):new ut(e),t.length&&this.tileIndex.initialize(t)}getTile(t,e,n){return e=+e,n=+n,(t=+t)<0||t>24?null:this.tileIndex.getTile(t,e,n)}updateData(t,e){const n=this.options;if(!n.updateable)throw new Error("to update tile geojson `updateable` option must be set to true");let{affected:o,source:s}=_(this.source,t,n);e&&({affected:o,source:s}=this.filterUpdate(s,o,e)),o.length&&(this.source=s,this.tileIndex.updateIndex(s,o,n))}filterUpdate(t,e,n){const o=new Set;for(const s of t)null!=s.id&&(n(p(s))||(e.push(s),o.add(s.id)));return{affected:e,source:t=t.filter((t=>!o.has(t.id)))}}getData(){if(!this.options.updateable)throw new Error("to retrieve data the `updateable` option must be set to true");return{type:"FeatureCollection",features:this.source.map((t=>p(t)))}}updateClusterOptions(t,e){const n=this.options.cluster;this.options.cluster=t,this.options.clusterOptions=e,n!=t?this.initializeIndex(this.source,this.options):this.tileIndex.updateIndex(this.source,[],this.options)}getClusterExpansionZoom(t){return this.tileIndex.getClusterExpansionZoom(t)}getClusterChildren(t){return this.tileIndex.getChildren(t)}getClusterLeaves(t,e,n){return this.tileIndex.getLeaves(t,e,n)}},t.Supercluster=V,t.geoJSONToTile=function(t,e,n,o,s={}){s={...lt,...s};const{wrap:i=!1,clip:a=!1}=s;let u=r(t,s);if(i&&(u=Y(u,s)),a||s.lineMetrics){const t=1<<e,i=s.buffer/s.extent,r=M(u,t,n-i,n+1+i,x.X,-1,2,s);u=M(r||[],t,o-i,o+1+i,x.Y,-1,2,s)}return st(et(u??[],e,n,o,s),s.extent)}}));
|