@maplibre/geojson-vt 6.3.2 → 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.
- package/dist/clip.d.ts.map +1 -1
- package/dist/cluster-tile-index.d.ts +8 -0
- package/dist/cluster-tile-index.d.ts.map +1 -1
- package/dist/convert.d.ts.map +1 -1
- package/dist/deconvert.d.ts +0 -1
- package/dist/deconvert.d.ts.map +1 -1
- package/dist/definitions.d.ts +66 -25
- package/dist/definitions.d.ts.map +1 -1
- package/dist/feature.d.ts +16 -12
- package/dist/feature.d.ts.map +1 -1
- package/dist/geojson-vt-dev.js +602 -453
- package/dist/geojson-vt.js +1 -1
- package/dist/geojson-vt.mjs +599 -450
- package/dist/geojson-vt.mjs.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/simplify.d.ts +1 -1
- package/dist/simplify.d.ts.map +1 -1
- package/dist/tile-index.d.ts.map +1 -1
- package/dist/tile.d.ts +5 -2
- package/dist/tile.d.ts.map +1 -1
- package/dist/transform.d.ts +5 -6
- package/dist/transform.d.ts.map +1 -1
- package/dist/wrap.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/clip.test.ts +52 -32
- package/src/clip.ts +225 -143
- package/src/cluster-tile-index.ts +29 -21
- package/src/convert.ts +78 -65
- package/src/deconvert.test.ts +29 -28
- package/src/deconvert.ts +51 -23
- package/src/definitions.ts +69 -17
- package/src/difference.test.ts +38 -75
- package/src/feature.ts +53 -51
- package/src/geojson-to-tile.ts +1 -1
- package/src/geojsonvt.test.ts +113 -0
- package/src/index.ts +1 -17
- package/src/simplify.ts +2 -2
- package/src/tile-index.test.ts +3 -9
- package/src/tile-index.ts +11 -10
- package/src/tile.ts +212 -92
- package/src/transform.test.ts +2 -3
- package/src/transform.ts +24 -99
- package/src/wrap.ts +12 -73
package/src/difference.test.ts
CHANGED
|
@@ -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]
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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(
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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,
|
|
1
|
+
import type { GeoJSONVTInternalFeature, GeoJSONVTInternalPointFeature, GeoJSONVTSourceCoords } from "./definitions";
|
|
2
2
|
|
|
3
|
-
type
|
|
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
|
|
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
|
|
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
|
|
27
|
-
geometry:
|
|
16
|
+
type,
|
|
17
|
+
geometry: geom,
|
|
28
18
|
tags,
|
|
29
19
|
minX: Infinity,
|
|
30
20
|
minY: Infinity,
|
|
31
21
|
maxX: -Infinity,
|
|
32
|
-
maxY: -Infinity
|
|
33
|
-
|
|
22
|
+
maxY: -Infinity,
|
|
23
|
+
worldOffset: 0
|
|
24
|
+
} as Extract<GeometryFeature, {type: T}>;
|
|
34
25
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
break;
|
|
26
|
+
if (type === 'MultiPoint') {
|
|
27
|
+
calcBBox(feature, geom, 0, geom.length);
|
|
28
|
+
return feature;
|
|
29
|
+
}
|
|
40
30
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
calcLineBBox(feature, data.geom[0].points);
|
|
48
|
-
break;
|
|
39
|
+
return feature;
|
|
40
|
+
}
|
|
49
41
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
60
|
+
export function getMinX(feature: GeoJSONVTInternalFeature): number {
|
|
61
|
+
return feature.type === 'Point' ? feature.x : feature.minX;
|
|
65
62
|
}
|
|
66
63
|
|
|
67
|
-
export function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
|
75
|
-
for (let i =
|
|
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]);
|
package/src/geojson-to-tile.ts
CHANGED
|
@@ -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
|
|
57
|
+
return transformTile(createTile(features ?? [], z, x, y, options, Float64Array));
|
|
58
58
|
}
|
package/src/geojsonvt.test.ts
CHANGED
|
@@ -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,
|
|
@@ -435,3 +464,87 @@ test('a unit square without wrap leaves the positions of a MultiPoint outside th
|
|
|
435
464
|
|
|
436
465
|
expect(index.getTile(0, 0, 0).features.map(feature => feature.geometry)).toEqual([[[507, 256]]]);
|
|
437
466
|
});
|
|
467
|
+
|
|
468
|
+
test('leaves out the empty rings of a polygon and the empty lines of a MultiLineString', () => {
|
|
469
|
+
const ring = [[0, 0], [10, 0], [10, 10], [0, 0]];
|
|
470
|
+
const data: GeoJSON.FeatureCollection = {
|
|
471
|
+
type: 'FeatureCollection',
|
|
472
|
+
features: [
|
|
473
|
+
{type: 'Feature', id: 'polygon', properties: {}, geometry: {type: 'Polygon', coordinates: [[], ring, []]}},
|
|
474
|
+
{type: 'Feature', id: 'polygons', properties: {}, geometry: {type: 'MultiPolygon', coordinates: [[[]], [ring, []]]}},
|
|
475
|
+
{type: 'Feature', id: 'lines', properties: {}, geometry: {type: 'MultiLineString', coordinates: [[], [[20, 0], [30, 5]]]}}
|
|
476
|
+
]
|
|
477
|
+
};
|
|
478
|
+
const ringsOf = (index: GeoJSONVT) => (index.getData() as GeoJSON.FeatureCollection<GeoJSON.Polygon>).features.map(feature => [feature.id, feature.geometry.type, feature.geometry.coordinates.length]);
|
|
479
|
+
|
|
480
|
+
const index = new GeoJSONVT(data, {updateable: true, tolerance: 0});
|
|
481
|
+
expect(ringsOf(index)).toEqual([['polygon', 'Polygon', 1], ['polygons', 'MultiPolygon', 1], ['lines', 'MultiLineString', 1]]);
|
|
482
|
+
expect(index.getTile(0, 0, 0).features.map(feature => feature.geometry.length)).toEqual([1, 1, 1]);
|
|
483
|
+
|
|
484
|
+
const withMetrics = new GeoJSONVT(data, {updateable: true, tolerance: 0, lineMetrics: true});
|
|
485
|
+
expect(ringsOf(withMetrics)).toEqual([['polygon', 'Polygon', 1], ['polygons', 'MultiPolygon', 1], ['lines', 'LineString', 2]]);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
test('takes a polygon or a MultiLineString with only empty rings as a feature without coordinates', () => {
|
|
489
|
+
const data: GeoJSON.FeatureCollection = {
|
|
490
|
+
type: 'FeatureCollection',
|
|
491
|
+
features: [
|
|
492
|
+
{type: 'Feature', id: 'polygon', properties: {}, geometry: {type: 'Polygon', coordinates: [[]]}},
|
|
493
|
+
{type: 'Feature', id: 'lines', properties: {}, geometry: {type: 'MultiLineString', coordinates: [[]]}}
|
|
494
|
+
]
|
|
495
|
+
};
|
|
496
|
+
const index = new GeoJSONVT(data, {updateable: true, tolerance: 0});
|
|
497
|
+
|
|
498
|
+
expect((index.getData() as GeoJSON.FeatureCollection).features).toEqual([]);
|
|
499
|
+
expect(index.getTile(0, 0, 0)).toBeNull();
|
|
500
|
+
|
|
501
|
+
index.updateData({update: [{id: 'polygon', newGeometry: {type: 'Point', coordinates: [0, 0]}}]});
|
|
502
|
+
expect((index.getData() as GeoJSON.FeatureCollection).features.map(feature => feature.id)).toEqual(['polygon']);
|
|
503
|
+
});
|
|
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 {
|
|
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;
|
package/src/tile-index.test.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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 {
|
|
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]
|
|
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]
|
|
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
|
|
264
|
-
maxX = Math.max(maxX, feature
|
|
265
|
-
minY = Math.min(minY, feature
|
|
266
|
-
maxY = Math.max(maxY, feature
|
|
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
|
|
296
|
-
feature
|
|
296
|
+
if (getMaxX(feature) >= tileMinX && getMinX(feature) < tileMaxX &&
|
|
297
|
+
getMaxY(feature) >= tileMinY && getMinY(feature) < tileMaxY) {
|
|
297
298
|
intersects = true;
|
|
298
299
|
break;
|
|
299
300
|
}
|