@maplibre/geojson-vt 6.3.3 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/clip.d.ts.map +1 -1
  2. package/dist/cluster-tile-index.d.ts +8 -0
  3. package/dist/cluster-tile-index.d.ts.map +1 -1
  4. package/dist/convert.d.ts.map +1 -1
  5. package/dist/deconvert.d.ts +0 -1
  6. package/dist/deconvert.d.ts.map +1 -1
  7. package/dist/definitions.d.ts +66 -25
  8. package/dist/definitions.d.ts.map +1 -1
  9. package/dist/feature.d.ts +16 -12
  10. package/dist/feature.d.ts.map +1 -1
  11. package/dist/geojson-vt-dev.js +606 -461
  12. package/dist/geojson-vt.js +1 -1
  13. package/dist/geojson-vt.mjs +603 -458
  14. package/dist/geojson-vt.mjs.map +1 -1
  15. package/dist/index.d.ts +2 -3
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/simplify.d.ts +1 -1
  18. package/dist/simplify.d.ts.map +1 -1
  19. package/dist/tile-index.d.ts.map +1 -1
  20. package/dist/tile.d.ts +5 -2
  21. package/dist/tile.d.ts.map +1 -1
  22. package/dist/transform.d.ts +5 -6
  23. package/dist/transform.d.ts.map +1 -1
  24. package/dist/wrap.d.ts.map +1 -1
  25. package/package.json +1 -1
  26. package/src/clip.test.ts +52 -32
  27. package/src/clip.ts +225 -143
  28. package/src/cluster-tile-index.ts +29 -21
  29. package/src/convert.ts +77 -72
  30. package/src/deconvert.test.ts +29 -28
  31. package/src/deconvert.ts +51 -23
  32. package/src/definitions.ts +69 -17
  33. package/src/difference.test.ts +38 -75
  34. package/src/feature.ts +53 -51
  35. package/src/geojson-to-tile.ts +1 -1
  36. package/src/geojsonvt.test.ts +75 -0
  37. package/src/index.ts +1 -17
  38. package/src/simplify.ts +2 -2
  39. package/src/tile-index.test.ts +3 -9
  40. package/src/tile-index.ts +11 -10
  41. package/src/tile.ts +212 -92
  42. package/src/transform.test.ts +2 -3
  43. package/src/transform.ts +24 -99
  44. package/src/wrap.ts +12 -73
@@ -65,30 +65,24 @@ test('applySourceDiff: adds a feature without properties when promoteId is set',
65
65
  }, {promoteId: 'promoteId'});
66
66
 
67
67
  expect(source.length).toBe(1);
68
- expect(source[0].geometry).toEqual([0.5, 0.5, 0]);
68
+ expect(source[0]).toMatchObject({x: 0.5, y: 0.5});
69
69
  });
70
70
 
71
71
  test('applySourceDiff: removes a feature by its id', () => {
72
72
  const point = {
73
73
  type: 'Point' as const,
74
74
  id: 'point',
75
- geometry: [0, 0],
76
- tags: {},
77
- minX: 0,
78
- minY: 0,
79
- maxX: 0,
80
- maxY: 0
75
+ x: 0,
76
+ y: 0,
77
+ tags: {}
81
78
  };
82
79
 
83
80
  const point2 = {
84
81
  type: 'Point' as const,
85
82
  id: 'point2',
86
- geometry: [0, 0],
87
- tags: {},
88
- minX: 0,
89
- minY: 0,
90
- maxX: 0,
91
- maxY: 0
83
+ x: 0,
84
+ y: 0,
85
+ tags: {}
92
86
  };
93
87
 
94
88
  const {source} = applySourceDiff([point, point2], {
@@ -103,23 +97,17 @@ test('applySourceDiff: removeAll clears all features', () => {
103
97
  const point = {
104
98
  type: 'Point' as const,
105
99
  id: 'point',
106
- geometry: [0, 0],
107
- tags: {},
108
- minX: 0,
109
- minY: 0,
110
- maxX: 0,
111
- maxY: 0
100
+ x: 0,
101
+ y: 0,
102
+ tags: {}
112
103
  };
113
104
 
114
105
  const point2 = {
115
106
  type: 'Point' as const,
116
107
  id: 'point2',
117
- geometry: [0, 0],
118
- tags: {},
119
- minX: 0,
120
- minY: 0,
121
- maxX: 0,
122
- maxY: 0
108
+ x: 0,
109
+ y: 0,
110
+ tags: {}
123
111
  };
124
112
 
125
113
  const source = [point, point2];
@@ -135,12 +123,9 @@ test('applySourceDiff: updates a feature geometry', () => {
135
123
  const point = {
136
124
  type: 'Point' as const,
137
125
  id: 'point',
138
- geometry: [0, 0],
139
- tags: {},
140
- minX: 0,
141
- minY: 0,
142
- maxX: 0,
143
- maxY: 0
126
+ x: 0,
127
+ y: 0,
128
+ tags: {}
144
129
  };
145
130
 
146
131
  const {source} = applySourceDiff([point], {
@@ -155,20 +140,16 @@ test('applySourceDiff: updates a feature geometry', () => {
155
140
 
156
141
  expect(source.length).toBe(1);
157
142
  expect(source[0].id).toBe('point');
158
- expect((source[0].geometry as number[])[0]).toBe(0.5027777777777778);
159
- expect((source[0].geometry as number[])[1]).toBe(0.5);
143
+ expect(source[0]).toMatchObject({x: 0.5027777777777778, y: 0.5});
160
144
  });
161
145
 
162
146
  test('applySourceDiff: keeps a generated id when updating a feature geometry', () => {
163
147
  const point = {
164
148
  type: 'Point' as const,
165
149
  id: 1,
166
- geometry: [0, 0],
167
- tags: {},
168
- minX: 0,
169
- minY: 0,
170
- maxX: 0,
171
- maxY: 0
150
+ x: 0,
151
+ y: 0,
152
+ tags: {}
172
153
  };
173
154
 
174
155
  const {source} = applySourceDiff([point], {
@@ -189,12 +170,9 @@ test('applySourceDiff: keeps a promoted id when updating a feature geometry and
189
170
  const point = {
190
171
  type: 'Point' as const,
191
172
  id: 'point',
192
- geometry: [0, 0],
193
- tags: {name: 'point'},
194
- minX: 0,
195
- minY: 0,
196
- maxX: 0,
197
- maxY: 0
173
+ x: 0,
174
+ y: 0,
175
+ tags: {name: 'point'}
198
176
  };
199
177
 
200
178
  const {source} = applySourceDiff([point], {
@@ -216,12 +194,9 @@ test('applySourceDiff: adds properties', () => {
216
194
  const point = {
217
195
  type: 'Point' as const,
218
196
  id: 'point',
219
- geometry: [0, 0],
220
- tags: {},
221
- minX: 0,
222
- minY: 0,
223
- maxX: 0,
224
- maxY: 0
197
+ x: 0,
198
+ y: 0,
199
+ tags: {}
225
200
  };
226
201
 
227
202
  const {source} = applySourceDiff([point], {
@@ -245,12 +220,9 @@ test('applySourceDiff: updates properties', () => {
245
220
  const point = {
246
221
  type: 'Point' as const,
247
222
  id: 'point',
248
- geometry: [0, 0],
249
- tags: {prop: 'value', prop2: 'value2'},
250
- minX: 0,
251
- minY: 0,
252
- maxX: 0,
253
- maxY: 0
223
+ x: 0,
224
+ y: 0,
225
+ tags: {prop: 'value', prop2: 'value2'}
254
226
  };
255
227
 
256
228
  const {source} = applySourceDiff([point], {
@@ -273,12 +245,9 @@ test('applySourceDiff: removes properties', () => {
273
245
  const point = {
274
246
  type: 'Point' as const,
275
247
  id: 'point',
276
- geometry: [0, 0],
277
- tags: {prop: 'value', prop2: 'value2'},
278
- minX: 0,
279
- minY: 0,
280
- maxX: 0,
281
- maxY: 0
248
+ x: 0,
249
+ y: 0,
250
+ tags: {prop: 'value', prop2: 'value2'}
282
251
  };
283
252
 
284
253
  const {source} = applySourceDiff([point], {
@@ -298,12 +267,9 @@ test('applySourceDiff: removes all properties', () => {
298
267
  const point = {
299
268
  type: 'Point' as const,
300
269
  id: 'point',
301
- geometry: [0, 0],
302
- tags: {prop: 'value', prop2: 'value2'},
303
- minX: 0,
304
- minY: 0,
305
- maxX: 0,
306
- maxY: 0
270
+ x: 0,
271
+ y: 0,
272
+ tags: {prop: 'value', prop2: 'value2'}
307
273
  };
308
274
 
309
275
  const {source} = applySourceDiff([point], {
@@ -321,12 +287,9 @@ test('applySourceDiff: empty update preserves properties', () => {
321
287
  const point = {
322
288
  type: 'Point' as const,
323
289
  id: 'point',
324
- geometry: [0, 0],
325
- tags: {prop: 'value', prop2: 'value2'},
326
- minX: 0,
327
- minY: 0,
328
- maxX: 0,
329
- maxY: 0
290
+ x: 0,
291
+ y: 0,
292
+ tags: {prop: 'value', prop2: 'value2'}
330
293
  };
331
294
 
332
295
  const {source} = applySourceDiff([point], {
package/src/feature.ts CHANGED
@@ -1,78 +1,80 @@
1
- import type { GeoJSONVTInternalFeature, GeoJSONVTInternalLineStringFeature, GeoJSONVTInternalMultiLineStringFeature, GeoJSONVTInternalMultiPointFeature, GeoJSONVTInternalMultiPolygonFeature, GeoJSONVTInternalPointFeature, GeoJSONVTInternalPolygonFeature, SliceArray, SliceFixedArray } from "./definitions";
1
+ import type { GeoJSONVTInternalFeature, GeoJSONVTInternalPointFeature, GeoJSONVTSourceCoords } from "./definitions";
2
2
 
3
- type FeatureTypeMap = {
4
- Point: GeoJSONVTInternalPointFeature["geometry"];
5
- MultiPoint: GeoJSONVTInternalMultiPointFeature["geometry"];
6
- LineString: GeoJSONVTInternalLineStringFeature["geometry"];
7
- MultiLineString: GeoJSONVTInternalMultiLineStringFeature["geometry"];
8
- Polygon: GeoJSONVTInternalPolygonFeature["geometry"];
9
- MultiPolygon: GeoJSONVTInternalMultiPolygonFeature["geometry"];
10
- };
3
+ type GeometryFeature = Exclude<GeoJSONVTInternalFeature, GeoJSONVTInternalPointFeature>;
11
4
 
12
5
  /**
13
- *
6
+ *
14
7
  * @param id - the feature's ID
15
8
  * @param type - the feature's type
16
- * @param geom - the feature's geometry
9
+ * @param geom - the feature's coordinates, see {@link GeoJSONVTSourceCoords}
17
10
  * @param tags - the feature's properties
18
11
  * @returns the created feature
19
12
  */
20
- export function createFeature<T extends GeoJSONVTInternalFeature["type"]>(id: number | string | undefined, type: T, geom: FeatureTypeMap[T], tags: GeoJSON.GeoJsonProperties): GeoJSONVTInternalFeature {
21
- // This is mostly for TypeScript type narrowing
22
- const data = { type, geom } as { [K in GeoJSONVTInternalFeature["type"]]: { type: K, geom: FeatureTypeMap[K] } }[GeoJSONVTInternalFeature["type"]];
23
-
13
+ export function createFeature<T extends GeometryFeature["type"]>(id: number | string | undefined, type: T, geom: GeoJSONVTSourceCoords, tags: GeoJSON.GeoJsonProperties): Extract<GeometryFeature, {type: T}> {
24
14
  const feature = {
25
15
  id: id == null ? null : id,
26
- type: data.type,
27
- geometry: data.geom,
16
+ type,
17
+ geometry: geom,
28
18
  tags,
29
19
  minX: Infinity,
30
20
  minY: Infinity,
31
21
  maxX: -Infinity,
32
- maxY: -Infinity
33
- } as GeoJSONVTInternalFeature;
22
+ maxY: -Infinity,
23
+ worldOffset: 0
24
+ } as Extract<GeometryFeature, {type: T}>;
34
25
 
35
- switch (data.type) {
36
- case 'Point':
37
- case 'MultiPoint':
38
- calcLineBBox(feature, data.geom);
39
- break;
26
+ if (type === 'MultiPoint') {
27
+ calcBBox(feature, geom, 0, geom.length);
28
+ return feature;
29
+ }
40
30
 
41
- case 'LineString':
42
- calcLineBBox(feature, data.geom.points);
43
- break;
31
+ // the outer ring of a polygon contains its holes
32
+ const outerOnly = type === 'Polygon' || type === 'MultiPolygon';
33
+ for (let i = 0; i < geom.length;) {
34
+ const end = i + 2 + geom[i] * 3;
35
+ if (!outerOnly || !isHole(geom[i + 1])) calcBBox(feature, geom, i + 2, end);
36
+ i = end;
37
+ }
44
38
 
45
- case 'Polygon':
46
- // the outer ring (ie [0]) contains all inner rings
47
- calcLineBBox(feature, data.geom[0].points);
48
- break;
39
+ return feature;
40
+ }
49
41
 
50
- case 'MultiLineString':
51
- for (const line of data.geom) {
52
- calcLineBBox(feature, line.points);
53
- }
54
- break;
42
+ /**
43
+ * Whether a polygon ring is a hole, going by the size stored before it. A hole has a negative size, which is -0
44
+ * when it has no area. An outer ring whose area is not a number has NaN, so the test is not `size >= 0`.
45
+ */
46
+ export function isHole(size: number): boolean {
47
+ return size < 0 || Object.is(size, -0);
48
+ }
55
49
 
56
- case 'MultiPolygon':
57
- for (const polygon of data.geom) {
58
- // the outer ring (ie [0]) contains all inner rings
59
- calcLineBBox(feature, polygon[0].points);
60
- }
61
- break;
62
- }
50
+ export function createPointFeature(id: number | string | undefined, x: number, y: number, tags: GeoJSON.GeoJsonProperties): GeoJSONVTInternalPointFeature {
51
+ return {
52
+ id: id == null ? null : id,
53
+ type: 'Point',
54
+ x,
55
+ y,
56
+ tags
57
+ };
58
+ }
63
59
 
64
- return feature;
60
+ export function getMinX(feature: GeoJSONVTInternalFeature): number {
61
+ return feature.type === 'Point' ? feature.x : feature.minX;
65
62
  }
66
63
 
67
- export function optimizeLineMemory(line: SliceArray) {
68
- const lineImmutable = line as SliceFixedArray;
69
- if (line.points.length > 64) {
70
- lineImmutable.points = new Float64Array(line.points);
71
- }
64
+ export function getMinY(feature: GeoJSONVTInternalFeature): number {
65
+ return feature.type === 'Point' ? feature.y : feature.minY;
66
+ }
67
+
68
+ export function getMaxX(feature: GeoJSONVTInternalFeature): number {
69
+ return feature.type === 'Point' ? feature.x : feature.maxX;
70
+ }
71
+
72
+ export function getMaxY(feature: GeoJSONVTInternalFeature): number {
73
+ return feature.type === 'Point' ? feature.y : feature.maxY;
72
74
  }
73
75
 
74
- function calcLineBBox(feature: GeoJSONVTInternalFeature, geom: number[] | Float64Array) {
75
- for (let i = 0; i < geom.length; i += 3) {
76
+ function calcBBox(feature: GeometryFeature, geom: GeoJSONVTSourceCoords, start: number, end: number) {
77
+ for (let i = start; i < end; i += 3) {
76
78
  feature.minX = Math.min(feature.minX, geom[i]);
77
79
  feature.minY = Math.min(feature.minY, geom[i + 1]);
78
80
  feature.maxX = Math.max(feature.maxX, geom[i]);
@@ -54,5 +54,5 @@ export function geoJSONToTile(data: GeoJSON.GeoJSON, z: number, x: number, y: nu
54
54
  features = clip(left || [], pow2, (y - buffer), (y + 1 + buffer), AxisType.Y, -1, 2, options);
55
55
  }
56
56
 
57
- return transformTile(createTile(features ?? [], z, x, y, options), options.extent);
57
+ return transformTile(createTile(features ?? [], z, x, y, options, Float64Array));
58
58
  }
@@ -424,6 +424,35 @@ test('clusters each position of a MultiPoint feature when clustering is on', ()
424
424
  ]);
425
425
  });
426
426
 
427
+ test('counts each point once in the clusters at the antimeridian', () => {
428
+ const data = {
429
+ type: 'FeatureCollection' as const,
430
+ features: [[179, 0], [178, 0], [-179, 0], [-178, 0]].map(coordinates => (
431
+ {type: 'Feature' as const, geometry: {type: 'Point' as const, coordinates}, properties: {}}
432
+ ))
433
+ };
434
+ const clusters = (index: GeoJSONVT) => index.getTile(0, 0, 0).features.map(feature => [feature.geometry, feature.tags.point_count]);
435
+ const expected = [
436
+ [[[510, 256]], 2],
437
+ [[[2, 256]], 2],
438
+ [[[-2, 256]], 2],
439
+ [[[514, 256]], 2]
440
+ ];
441
+
442
+ expect(clusters(new GeoJSONVT(data, {cluster: true}))).toEqual(expected);
443
+
444
+ const clusteredLater = new GeoJSONVT(data, {updateable: true});
445
+ clusteredLater.updateClusterOptions(true, {});
446
+ expect(clusters(clusteredLater)).toEqual(expected);
447
+ });
448
+
449
+ test('counts each position of a MultiPoint once in the clusters at the antimeridian', () => {
450
+ const multiPoint: GeoJSON.Feature = {type: 'Feature', properties: {}, geometry: {type: 'MultiPoint', coordinates: [[179, 0], [178, 0], [-179, 0], [-178, 0]]}};
451
+ const index = new GeoJSONVT(multiPoint, {cluster: true});
452
+
453
+ expect(index.getTile(0, 0, 0).features.map(feature => feature.tags.point_count)).toEqual([2, 2, 2, 2]);
454
+ });
455
+
427
456
  test('a unit square without wrap leaves the positions of a MultiPoint outside the world out of the clusters', () => {
428
457
  const multiPoint = {
429
458
  type: 'Feature' as const,
@@ -473,3 +502,49 @@ test('takes a polygon or a MultiLineString with only empty rings as a feature wi
473
502
  expect((index.getData() as GeoJSON.FeatureCollection).features.map(feature => feature.id)).toEqual(['polygon']);
474
503
  });
475
504
 
505
+ test('shows the positions of a MultiPoint near the antimeridian at both edges of the world', () => {
506
+ const multiPoint: GeoJSON.Feature<GeoJSON.MultiPoint> = {
507
+ type: 'Feature',
508
+ id: 3,
509
+ properties: {name: 'both sides'},
510
+ geometry: {type: 'MultiPoint', coordinates: [[179.9, 0], [179.95, 5], [-179.9, 10]]}
511
+ };
512
+ const index = new GeoJSONVT(multiPoint);
513
+
514
+ expect(index.getTile(0, 0, 0).features.map(f => f.geometry)).toEqual([
515
+ [[4097, 1934]],
516
+ [[4095, 2048], [4095, 1991], [1, 1934]],
517
+ [[-1, 2048], [-1, 1991]]
518
+ ]);
519
+ });
520
+
521
+ test('keeps a polygon whose area is not a number as a polygon of its own', () => {
522
+ const small = [[0.1, 0.1], [0.2, 0.1], [0.2, 0.2], [0.1, 0.1]];
523
+ const huge = [[1e200, 1e200], [2e200, 1e200], [2e200, 2e200], [1e200, 2e200], [1e200, 1e200]];
524
+ const index = new GeoJSONVT({type: 'MultiPolygon', coordinates: [[small], [huge]]}, {coordinates: 'unitSquare', wrap: false, updateable: true});
525
+
526
+ const [feature] = (index.getData() as GeoJSON.FeatureCollection<GeoJSON.MultiPolygon>).features;
527
+ expect(feature.geometry.coordinates.map(polygon => polygon.length)).toEqual([1, 1]);
528
+ expect(index.getTile(0, 0, 0).features[0].geometry).toHaveLength(1);
529
+ });
530
+
531
+ test('closes a clipped ring whose positions are not all numbers', () => {
532
+ const polygon: GeoJSON.Polygon = {type: 'Polygon', coordinates: [[[-100, 20], [Infinity, 30], [40, -10], [-100, 20]]]};
533
+ const index = new GeoJSONVT(polygon, {tolerance: 0});
534
+
535
+ expect(index.getTile(1, 0, 1).features.map(feature => feature.geometry)).toEqual([
536
+ [[[4160, -64], [4160, 45], [3661, -64], [4160, -64]]],
537
+ [[[4160, NaN], [-64, NaN], [4160, NaN]]]
538
+ ]);
539
+ });
540
+
541
+ test('drops a hole without area at a tolerance of the smallest number, like any ring without area', () => {
542
+ const polygon: GeoJSON.Polygon = {
543
+ type: 'Polygon',
544
+ coordinates: [[[0.1, 0.1], [0.9, 0.1], [0.9, 0.9], [0.1, 0.1]], [[0.3, 0.3], [0.4, 0.4], [0.5, 0.5], [0.3, 0.3]]]
545
+ };
546
+ const index = new GeoJSONVT(polygon, {coordinates: 'unitSquare', wrap: false, indexMaxZoom: 0, tolerance: Math.sqrt(Number.MIN_VALUE) * 4096});
547
+
548
+ expect(index.getTile(0, 0, 0).features[0].geometry).toHaveLength(1);
549
+ });
550
+
package/src/index.ts CHANGED
@@ -1,7 +1,6 @@
1
1
 
2
2
  import type {GeoJSONVTFeatureDiff, GeoJSONVTSourceDiff} from './difference';
3
- import type {GeoJSONVTInternalFeature, GeoJSONVTInternalLineStringFeature, GeoJSONVTInternalMultiLineStringFeature, GeoJSONVTInternalMultiPointFeature, GeoJSONVTInternalMultiPolygonFeature, GeoJSONVTInternalPointFeature, GeoJSONVTInternalPolygonFeature, GeoJSONVTOptions, GeoJSONToTileOptions, PartialGeoJSONVTFeature, SliceArray, SliceFixedArray, ClusterProperties, ClusterFeature, ClusterOrPointFeature, GeoJSONVTTile, GeoJSONVTFeature, GeoJSONVTFeaturePoint, GeoJSONVTFeatureNonPoint, GeoJSONVTInternalTileFeaturePoint, GeoJSONVTInternalTileFeatureNonPoint, GeoJSONVTInternalTile, GeoJSONVTInternalTileFeature, GeoJSONVTTileIndex, SuperclusterOptions, GeoJSONVTCoordinatesType} from './definitions';
4
- import type {KDBushWithData} from './cluster-tile-index';
3
+ import type {GeoJSONVTOptions, GeoJSONToTileOptions, ClusterProperties, ClusterFeature, ClusterOrPointFeature, GeoJSONVTTile, GeoJSONVTFeature, GeoJSONVTFeaturePoint, GeoJSONVTFeatureNonPoint, GeoJSONVTTileIndex, SuperclusterOptions, GeoJSONVTCoordinatesType} from './definitions';
5
4
  import {GeoJSONVT} from './geojsonvt';
6
5
  import {ClusterTileIndex} from './cluster-tile-index';
7
6
  import {geoJSONToTile} from './geojson-to-tile';
@@ -16,33 +15,18 @@ export {
16
15
  }
17
16
 
18
17
  export type {
19
- GeoJSONVTInternalFeature,
20
18
  GeoJSONVTOptions,
21
19
  GeoJSONToTileOptions,
22
- GeoJSONVTInternalTile,
23
- GeoJSONVTInternalTileFeature,
24
- PartialGeoJSONVTFeature,
25
- SliceArray,
26
- SliceFixedArray,
27
20
  GeoJSONVTTile,
28
21
  GeoJSONVTFeature,
29
22
  GeoJSONVTSourceDiff,
30
23
  GeoJSONVTFeatureDiff,
31
24
  GeoJSONVTFeaturePoint,
32
25
  GeoJSONVTFeatureNonPoint,
33
- GeoJSONVTInternalTileFeaturePoint,
34
- GeoJSONVTInternalTileFeatureNonPoint,
35
- GeoJSONVTInternalPointFeature,
36
- GeoJSONVTInternalMultiPointFeature,
37
- GeoJSONVTInternalLineStringFeature,
38
- GeoJSONVTInternalMultiLineStringFeature,
39
- GeoJSONVTInternalPolygonFeature,
40
- GeoJSONVTInternalMultiPolygonFeature,
41
26
  SuperclusterOptions,
42
27
  GeoJSONVTCoordinatesType,
43
28
  ClusterProperties,
44
29
  ClusterFeature,
45
30
  ClusterOrPointFeature,
46
- KDBushWithData,
47
31
  GeoJSONVTTileIndex
48
32
  };
package/src/simplify.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * @param last - index of the last coordinate in the segment
6
6
  * @param sqTolerance - square tolerance value
7
7
  */
8
- export function simplify(coords: number[], first: number, last: number, sqTolerance: number) {
8
+ export function simplify(coords: number[] | Float64Array, first: number, last: number, sqTolerance: number) {
9
9
  const stack = [first, last];
10
10
 
11
11
  while (stack.length) {
@@ -15,7 +15,7 @@ export function simplify(coords: number[], first: number, last: number, sqTolera
15
15
  }
16
16
  }
17
17
 
18
- function simplifySegment(coords: number[], first: number, last: number, sqTolerance: number, stack: number[]) {
18
+ function simplifySegment(coords: number[] | Float64Array, first: number, last: number, sqTolerance: number, stack: number[]) {
19
19
  let maxSqDist = sqTolerance;
20
20
  const mid = first + ((last - first) >> 1);
21
21
  let minPosToMid = last - first;
@@ -242,8 +242,7 @@ describe('Multiworld test', () => {
242
242
  let sourceFeatures = convertToInternal(rightPoint, defaultOptions);
243
243
  sourceFeatures = wrap(sourceFeatures, defaultOptions);
244
244
  vt.initialize(sourceFeatures);
245
- expect(vt.tiles[0].features[0].geometry[0]).toBe(1);
246
- expect(vt.tiles[0].features[0].geometry[1]).toBe(.5);
245
+ expect(vt.getTile(0, 0, 0).features[0].geometry).toEqual([[4096, 2048]]);
247
246
  });
248
247
 
249
248
  test('handle point only in the leftside world', () => {
@@ -251,8 +250,7 @@ describe('Multiworld test', () => {
251
250
  let sourceFeatures = convertToInternal(leftPoint, defaultOptions);
252
251
  sourceFeatures = wrap(sourceFeatures, defaultOptions);
253
252
  vt.initialize(sourceFeatures);
254
- expect(vt.tiles[0].features[0].geometry[0]).toBe(0);
255
- expect(vt.tiles[0].features[0].geometry[1]).toBe(.5);
253
+ expect(vt.getTile(0, 0, 0).features[0].geometry).toEqual([[0, 2048]]);
256
254
  });
257
255
 
258
256
  test('handle points in the leftside world and the rightside world', () => {
@@ -261,10 +259,6 @@ describe('Multiworld test', () => {
261
259
  sourceFeatures = wrap(sourceFeatures, defaultOptions);
262
260
  vt.initialize(sourceFeatures);
263
261
 
264
- expect(vt.tiles[0].features[0].geometry[0]).toBe(0);
265
- expect(vt.tiles[0].features[0].geometry[1]).toBe(.5);
266
-
267
- expect(vt.tiles[0].features[1].geometry[0]).toBe(1);
268
- expect(vt.tiles[0].features[1].geometry[1]).toBe(.5);
262
+ expect(vt.getTile(0, 0, 0).features.map(f => f.geometry)).toEqual([[[0, 2048]], [[4096, 2048]]]);
269
263
  });
270
264
  })
package/src/tile-index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AxisType, clip } from "./clip";
2
2
  import { createTile } from "./tile";
3
+ import { getMaxX, getMaxY, getMinX, getMinY } from "./feature";
3
4
  import { transformTile } from "./transform";
4
5
  import type { GeoJSONVTInternalFeature, GeoJSONVTOptions, ClusterOrPointFeature, GeoJSONVTTileIndex, GeoJSONVTInternalTile, GeoJSONVTTile } from "./definitions";
5
6
 
@@ -81,15 +82,15 @@ export class TileIndex implements GeoJSONVTTileIndex {
81
82
 
82
83
  /** {@inheritdoc} */
83
84
  getTile(z: number, x: number, y: number): GeoJSONVTTile | null {
84
- const {extent, debug} = this.options;
85
-
85
+ const {debug} = this.options;
86
+
86
87
  const z2 = 1 << z;
87
88
  if (!this.options.wrap && (x < 0 || x >= z2)) return null; // a row outside the world has no tile either
88
89
  x = (x + z2) & (z2 - 1); // wrap tile x coordinate
89
90
 
90
91
  const id = toID(z, x, y);
91
92
  if (this.tiles[id]) {
92
- return transformTile(this.tiles[id], extent);
93
+ return transformTile(this.tiles[id]);
93
94
  }
94
95
 
95
96
  if (debug > 1) console.log('drilling down to z%d-%d-%d', z, x, y);
@@ -118,7 +119,7 @@ export class TileIndex implements GeoJSONVTTileIndex {
118
119
 
119
120
  if (!this.tiles[id]) return null;
120
121
 
121
- return transformTile(this.tiles[id], extent);
122
+ return transformTile(this.tiles[id]);
122
123
  }
123
124
 
124
125
  /**
@@ -260,10 +261,10 @@ export class TileIndex implements GeoJSONVTTileIndex {
260
261
  let maxY = -Infinity;
261
262
 
262
263
  for (const feature of features) {
263
- minX = Math.min(minX, feature.minX);
264
- maxX = Math.max(maxX, feature.maxX);
265
- minY = Math.min(minY, feature.minY);
266
- maxY = Math.max(maxY, feature.maxY);
264
+ minX = Math.min(minX, getMinX(feature));
265
+ maxX = Math.max(maxX, getMaxX(feature));
266
+ minY = Math.min(minY, getMinY(feature));
267
+ maxY = Math.max(maxY, getMaxY(feature));
267
268
  }
268
269
 
269
270
  // tile buffer clipping value - not halved as in splitTile above because checking against tile's own extent
@@ -292,8 +293,8 @@ export class TileIndex implements GeoJSONVTTileIndex {
292
293
  // check if any feature intersects with the tile
293
294
  let intersects = false;
294
295
  for (const feature of features) {
295
- if (feature.maxX >= tileMinX && feature.minX < tileMaxX &&
296
- feature.maxY >= tileMinY && feature.minY < tileMaxY) {
296
+ if (getMaxX(feature) >= tileMinX && getMinX(feature) < tileMaxX &&
297
+ getMaxY(feature) >= tileMinY && getMinY(feature) < tileMaxY) {
297
298
  intersects = true;
298
299
  break;
299
300
  }