@maplibre/geojson-vt 6.2.0 → 6.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/dist/clip.d.ts.map +1 -1
- package/dist/cluster-tile-index.d.ts +12 -9
- package/dist/cluster-tile-index.d.ts.map +1 -1
- package/dist/convert.d.ts +2 -9
- package/dist/convert.d.ts.map +1 -1
- package/dist/deconvert.d.ts +4 -11
- package/dist/deconvert.d.ts.map +1 -1
- package/dist/definitions.d.ts +38 -10
- package/dist/definitions.d.ts.map +1 -1
- package/dist/difference.d.ts +2 -1
- package/dist/difference.d.ts.map +1 -1
- package/dist/geojson-vt-dev.js +287 -162
- package/dist/geojson-vt.js +1 -1
- package/dist/geojson-vt.mjs +285 -161
- package/dist/geojson-vt.mjs.map +1 -1
- package/dist/geojsonvt.d.ts +9 -4
- package/dist/geojsonvt.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/tile-index.d.ts +4 -3
- package/dist/tile-index.d.ts.map +1 -1
- package/dist/world-coordinate-helper.d.ts +13 -0
- package/dist/world-coordinate-helper.d.ts.map +1 -0
- package/package.json +6 -6
- package/src/clip.ts +0 -1
- package/src/cluster-tile-index.test.ts +28 -8
- package/src/cluster-tile-index.ts +53 -27
- package/src/convert.ts +45 -47
- package/src/deconvert.test.ts +4 -4
- package/src/deconvert.ts +15 -31
- package/src/definitions.ts +39 -10
- package/src/difference.ts +49 -19
- package/src/geojson-to-tile.ts +2 -2
- package/src/geojsonvt.test.ts +183 -20
- package/src/geojsonvt.ts +31 -10
- package/src/index.ts +2 -1
- package/src/tile-index.ts +8 -6
- package/src/world-coordinate-helper.ts +63 -0
- package/src/wrap.ts +1 -1
package/dist/geojson-vt-dev.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.geojsonvt = {})));
|
|
5
5
|
})(this, function(exports) {
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
7
|
-
|
|
7
|
+
// src/simplify.ts
|
|
8
8
|
/**
|
|
9
9
|
* calculate simplification data using optimized Douglas-Peucker algorithm
|
|
10
10
|
* @param coords - flat array of coordinates
|
|
@@ -78,8 +78,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
78
78
|
return dx * dx + dy * dy;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
//#region src/feature.ts
|
|
81
|
+
// src/feature.ts
|
|
83
82
|
/**
|
|
84
83
|
*
|
|
85
84
|
* @param id - the feature's ID
|
|
@@ -134,32 +133,88 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
134
133
|
}
|
|
135
134
|
}
|
|
136
135
|
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
// src/world-coordinate-helper.ts
|
|
137
|
+
/**
|
|
138
|
+
* Longitude and latitude, which spherical mercator puts in the world square.
|
|
139
|
+
*/
|
|
140
|
+
var MercatorWorldCoordinateHelper = class {
|
|
141
|
+
projectX(lng) {
|
|
142
|
+
return lng / 360 + .5;
|
|
143
|
+
}
|
|
144
|
+
projectY(lat) {
|
|
145
|
+
const sin = Math.sin(lat * Math.PI / 180);
|
|
146
|
+
const y = .5 - .25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
|
|
147
|
+
return y < 0 ? 0 : y > 1 ? 1 : y;
|
|
148
|
+
}
|
|
149
|
+
unprojectX(x) {
|
|
150
|
+
return (x - .5) * 360;
|
|
151
|
+
}
|
|
152
|
+
unprojectY(y) {
|
|
153
|
+
const y2 = (180 - y * 360) * Math.PI / 180;
|
|
154
|
+
return 360 * Math.atan(Math.exp(y2)) / Math.PI - 90;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Positions in the unit square already, see `coordinates` in {@link GeoJSONVTOptions}.
|
|
159
|
+
*/
|
|
160
|
+
var IdentityWorldCoordinateHelper = class {
|
|
161
|
+
projectX(x) {
|
|
162
|
+
return x;
|
|
163
|
+
}
|
|
164
|
+
projectY(y) {
|
|
165
|
+
return y;
|
|
166
|
+
}
|
|
167
|
+
unprojectX(x) {
|
|
168
|
+
return x;
|
|
169
|
+
}
|
|
170
|
+
unprojectY(y) {
|
|
171
|
+
return y;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const mercatorWorldCoordinateHelper = new MercatorWorldCoordinateHelper();
|
|
175
|
+
const identityWorldCoordinateHelper = new IdentityWorldCoordinateHelper();
|
|
176
|
+
function getWorldCoordinateHelper(coordinates) {
|
|
177
|
+
return coordinates === "unitSquare" ? identityWorldCoordinateHelper : mercatorWorldCoordinateHelper;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/convert.ts
|
|
139
181
|
const MAX_GEOMETRY_COLLECTION_DEPTH = 1024;
|
|
140
182
|
/**
|
|
141
183
|
* converts GeoJSON to internal source features (an intermediate projected JSON vector format with simplification data)
|
|
142
184
|
* @param data
|
|
143
185
|
* @param options
|
|
186
|
+
* @param unlocated - the features without coordinates, by id: a feature with an id that converts to nothing is set in it, and one that converts to something is deleted from it
|
|
144
187
|
* @returns
|
|
145
188
|
*/
|
|
146
|
-
function convertToInternal(data, options) {
|
|
189
|
+
function convertToInternal(data, options, unlocated) {
|
|
147
190
|
const features = [];
|
|
148
191
|
switch (data.type) {
|
|
149
192
|
case "FeatureCollection":
|
|
150
|
-
for (let i = 0; i < data.features.length; i++)
|
|
193
|
+
for (let i = 0; i < data.features.length; i++) convertFeature(features, data.features[i], options, unlocated, i);
|
|
151
194
|
break;
|
|
152
195
|
case "Feature":
|
|
153
|
-
|
|
196
|
+
convertFeature(features, data, options, unlocated);
|
|
154
197
|
break;
|
|
155
|
-
default:
|
|
198
|
+
default: convertFeature(features, {
|
|
156
199
|
type: "Feature",
|
|
157
200
|
geometry: data,
|
|
158
201
|
properties: void 0
|
|
159
|
-
}, options);
|
|
202
|
+
}, options, unlocated);
|
|
160
203
|
}
|
|
161
204
|
return features;
|
|
162
205
|
}
|
|
206
|
+
function convertFeature(features, geojson, options, unlocated, index) {
|
|
207
|
+
const count = features.length;
|
|
208
|
+
featureToInternal(features, geojson, options, index);
|
|
209
|
+
if (!unlocated) return;
|
|
210
|
+
const id = getFeatureId(geojson, options, index);
|
|
211
|
+
if (id == null) return;
|
|
212
|
+
if (features.length > count) unlocated.delete(id);
|
|
213
|
+
else unlocated.set(id, {
|
|
214
|
+
...geojson,
|
|
215
|
+
id
|
|
216
|
+
});
|
|
217
|
+
}
|
|
163
218
|
function featureToInternal(features, geojson, options, index, depth = 0) {
|
|
164
219
|
if (!geojson.geometry) return;
|
|
165
220
|
if (depth > MAX_GEOMETRY_COLLECTION_DEPTH) throw new Error("GeometryCollection nesting exceeds supported depth: 1024");
|
|
@@ -170,25 +225,25 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
170
225
|
if (!geojson.geometry.coordinates?.length) return;
|
|
171
226
|
const id = getFeatureId(geojson, options, index);
|
|
172
227
|
const tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
|
|
173
|
-
const
|
|
228
|
+
const worldCoordinateHelper = getWorldCoordinateHelper(options.coordinates);
|
|
174
229
|
switch (geojson.geometry.type) {
|
|
175
230
|
case "Point":
|
|
176
|
-
convertPointFeature(features, id, geojson.geometry,
|
|
231
|
+
convertPointFeature(features, id, geojson.geometry, worldCoordinateHelper, geojson.properties);
|
|
177
232
|
return;
|
|
178
233
|
case "MultiPoint":
|
|
179
|
-
convertMultiPointFeature(features, id, geojson.geometry,
|
|
234
|
+
convertMultiPointFeature(features, id, geojson.geometry, worldCoordinateHelper, geojson.properties);
|
|
180
235
|
return;
|
|
181
236
|
case "LineString":
|
|
182
|
-
convertLineStringFeature(features, id, geojson.geometry, tolerance,
|
|
237
|
+
convertLineStringFeature(features, id, geojson.geometry, tolerance, worldCoordinateHelper, geojson.properties);
|
|
183
238
|
return;
|
|
184
239
|
case "MultiLineString":
|
|
185
|
-
convertMultiLineStringFeature(features, id, geojson.geometry, tolerance,
|
|
240
|
+
convertMultiLineStringFeature(features, id, geojson.geometry, tolerance, worldCoordinateHelper, options, geojson.properties);
|
|
186
241
|
return;
|
|
187
242
|
case "Polygon":
|
|
188
|
-
convertPolygonFeature(features, id, geojson.geometry, tolerance,
|
|
243
|
+
convertPolygonFeature(features, id, geojson.geometry, tolerance, worldCoordinateHelper, geojson.properties);
|
|
189
244
|
return;
|
|
190
245
|
case "MultiPolygon":
|
|
191
|
-
convertMultiPolygonFeature(features, id, geojson.geometry, tolerance,
|
|
246
|
+
convertMultiPolygonFeature(features, id, geojson.geometry, tolerance, worldCoordinateHelper, geojson.properties);
|
|
192
247
|
return;
|
|
193
248
|
default: throw new Error("Input data is not a valid GeoJSON object.");
|
|
194
249
|
}
|
|
@@ -206,55 +261,55 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
206
261
|
properties: geojson.properties
|
|
207
262
|
}, options, index, depth);
|
|
208
263
|
}
|
|
209
|
-
function convertPointFeature(features, id, geom,
|
|
264
|
+
function convertPointFeature(features, id, geom, worldCoordinateHelper, properties) {
|
|
210
265
|
const out = [];
|
|
211
|
-
out.push(projectX(geom.coordinates[0]
|
|
266
|
+
out.push(worldCoordinateHelper.projectX(geom.coordinates[0]), worldCoordinateHelper.projectY(geom.coordinates[1]), 0);
|
|
212
267
|
features.push(createFeature(id, "Point", out, properties));
|
|
213
268
|
}
|
|
214
|
-
function convertMultiPointFeature(features, id, geom,
|
|
269
|
+
function convertMultiPointFeature(features, id, geom, worldCoordinateHelper, properties) {
|
|
215
270
|
const out = [];
|
|
216
|
-
for (const coords of geom.coordinates) out.push(projectX(coords[0]
|
|
271
|
+
for (const coords of geom.coordinates) out.push(worldCoordinateHelper.projectX(coords[0]), worldCoordinateHelper.projectY(coords[1]), 0);
|
|
217
272
|
features.push(createFeature(id, "MultiPoint", out, properties));
|
|
218
273
|
}
|
|
219
|
-
function convertLineStringFeature(features, id, geom, tolerance,
|
|
274
|
+
function convertLineStringFeature(features, id, geom, tolerance, worldCoordinateHelper, properties) {
|
|
220
275
|
const out = { points: [] };
|
|
221
|
-
convertLine(geom.coordinates, out, tolerance, false,
|
|
276
|
+
convertLine(geom.coordinates, out, tolerance, false, worldCoordinateHelper);
|
|
222
277
|
features.push(createFeature(id, "LineString", out, properties));
|
|
223
278
|
}
|
|
224
|
-
function convertMultiLineStringFeature(features, id, geom, tolerance,
|
|
279
|
+
function convertMultiLineStringFeature(features, id, geom, tolerance, worldCoordinateHelper, options, properties) {
|
|
225
280
|
if (options.lineMetrics) for (const line of geom.coordinates) {
|
|
226
281
|
const out = { points: [] };
|
|
227
|
-
convertLine(line, out, tolerance, false,
|
|
282
|
+
convertLine(line, out, tolerance, false, worldCoordinateHelper);
|
|
228
283
|
features.push(createFeature(id, "LineString", out, properties));
|
|
229
284
|
}
|
|
230
285
|
else {
|
|
231
286
|
const out = [];
|
|
232
|
-
convertLines(geom.coordinates, out, tolerance, false,
|
|
287
|
+
convertLines(geom.coordinates, out, tolerance, false, worldCoordinateHelper);
|
|
233
288
|
features.push(createFeature(id, "MultiLineString", out, properties));
|
|
234
289
|
}
|
|
235
290
|
}
|
|
236
|
-
function convertPolygonFeature(features, id, geom, tolerance,
|
|
291
|
+
function convertPolygonFeature(features, id, geom, tolerance, worldCoordinateHelper, properties) {
|
|
237
292
|
const out = [];
|
|
238
|
-
convertLines(geom.coordinates, out, tolerance, true,
|
|
293
|
+
convertLines(geom.coordinates, out, tolerance, true, worldCoordinateHelper);
|
|
239
294
|
features.push(createFeature(id, "Polygon", out, properties));
|
|
240
295
|
}
|
|
241
|
-
function convertMultiPolygonFeature(features, id, geom, tolerance,
|
|
296
|
+
function convertMultiPolygonFeature(features, id, geom, tolerance, worldCoordinateHelper, properties) {
|
|
242
297
|
const out = [];
|
|
243
298
|
for (const polygon of geom.coordinates) {
|
|
244
299
|
const polygonOut = [];
|
|
245
|
-
convertLines(polygon, polygonOut, tolerance, true,
|
|
300
|
+
convertLines(polygon, polygonOut, tolerance, true, worldCoordinateHelper);
|
|
246
301
|
if (!polygonOut.length) continue;
|
|
247
302
|
out.push(polygonOut);
|
|
248
303
|
}
|
|
249
304
|
if (!out.length) return;
|
|
250
305
|
features.push(createFeature(id, "MultiPolygon", out, properties));
|
|
251
306
|
}
|
|
252
|
-
function convertLine(ring, out, tolerance, isPolygon,
|
|
307
|
+
function convertLine(ring, out, tolerance, isPolygon, worldCoordinateHelper) {
|
|
253
308
|
let x0, y0;
|
|
254
309
|
let size = 0;
|
|
255
310
|
for (let j = 0; j < ring.length; j++) {
|
|
256
|
-
const x = projectX(ring[j][0]
|
|
257
|
-
const y = projectY(ring[j][1]
|
|
311
|
+
const x = worldCoordinateHelper.projectX(ring[j][0]);
|
|
312
|
+
const y = worldCoordinateHelper.projectY(ring[j][1]);
|
|
258
313
|
out.points.push(x, y, 0);
|
|
259
314
|
if (j > 0) {
|
|
260
315
|
if (isPolygon) size += (x0 * y - x * y0) / 2;
|
|
@@ -272,48 +327,31 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
272
327
|
out.start = 0;
|
|
273
328
|
out.end = out.size;
|
|
274
329
|
}
|
|
275
|
-
function convertLines(rings, out, tolerance, isPolygon,
|
|
330
|
+
function convertLines(rings, out, tolerance, isPolygon, worldCoordinateHelper) {
|
|
276
331
|
for (let i = 0; i < rings.length; i++) {
|
|
277
332
|
const geom = { points: [] };
|
|
278
|
-
convertLine(rings[i], geom, tolerance, isPolygon,
|
|
333
|
+
convertLine(rings[i], geom, tolerance, isPolygon, worldCoordinateHelper);
|
|
279
334
|
out.push(geom);
|
|
280
335
|
}
|
|
281
336
|
}
|
|
282
|
-
/**
|
|
283
|
-
* Convert longitude to spherical mercator in [0..1] range, or keep a world coordinate as it is
|
|
284
|
-
*/
|
|
285
|
-
function projectX(x, worldCoordinates = false) {
|
|
286
|
-
if (worldCoordinates) return x;
|
|
287
|
-
return x / 360 + .5;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Convert latitude to spherical mercator in [0..1] range, or keep a world coordinate as it is
|
|
291
|
-
*/
|
|
292
|
-
function projectY(y, worldCoordinates = false) {
|
|
293
|
-
if (worldCoordinates) return y;
|
|
294
|
-
const sin = Math.sin(y * Math.PI / 180);
|
|
295
|
-
const y2 = .5 - .25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
|
|
296
|
-
return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
|
|
297
|
-
}
|
|
298
337
|
|
|
299
|
-
|
|
300
|
-
//#region src/deconvert.ts
|
|
338
|
+
// src/deconvert.ts
|
|
301
339
|
/**
|
|
302
340
|
* Converts internal source features back to GeoJSON format.
|
|
303
341
|
*/
|
|
304
|
-
function convertToGeoJSON(source,
|
|
342
|
+
function convertToGeoJSON(source, worldCoordinateHelper = mercatorWorldCoordinateHelper) {
|
|
305
343
|
return {
|
|
306
344
|
type: "FeatureCollection",
|
|
307
|
-
features: source.map((feature) => featureToGeoJSON(feature,
|
|
345
|
+
features: source.map((feature) => featureToGeoJSON(feature, worldCoordinateHelper))
|
|
308
346
|
};
|
|
309
347
|
}
|
|
310
348
|
/**
|
|
311
349
|
* Converts a single internal feature to GeoJSON format.
|
|
312
350
|
*/
|
|
313
|
-
function featureToGeoJSON(feature,
|
|
351
|
+
function featureToGeoJSON(feature, worldCoordinateHelper = mercatorWorldCoordinateHelper) {
|
|
314
352
|
const geojsonFeature = {
|
|
315
353
|
type: "Feature",
|
|
316
|
-
geometry: geometryToGeoJSON(feature,
|
|
354
|
+
geometry: geometryToGeoJSON(feature, worldCoordinateHelper),
|
|
317
355
|
properties: feature.tags
|
|
318
356
|
};
|
|
319
357
|
if (feature.id != null) geojsonFeature.id = feature.id;
|
|
@@ -322,58 +360,42 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
322
360
|
/**
|
|
323
361
|
* Converts a single internal feature geometry to GeoJSON format.
|
|
324
362
|
*/
|
|
325
|
-
function geometryToGeoJSON(feature,
|
|
363
|
+
function geometryToGeoJSON(feature, worldCoordinateHelper) {
|
|
326
364
|
const { type, geometry } = feature;
|
|
327
365
|
switch (type) {
|
|
328
366
|
case "Point": return {
|
|
329
367
|
type,
|
|
330
|
-
coordinates: unprojectPoint(geometry[0], geometry[1],
|
|
368
|
+
coordinates: unprojectPoint(geometry[0], geometry[1], worldCoordinateHelper)
|
|
331
369
|
};
|
|
332
370
|
case "MultiPoint": return {
|
|
333
371
|
type,
|
|
334
|
-
coordinates: unprojectPoints(geometry,
|
|
372
|
+
coordinates: unprojectPoints(geometry, worldCoordinateHelper)
|
|
335
373
|
};
|
|
336
374
|
case "LineString": return {
|
|
337
375
|
type,
|
|
338
|
-
coordinates: unprojectPoints(geometry.points,
|
|
376
|
+
coordinates: unprojectPoints(geometry.points, worldCoordinateHelper)
|
|
339
377
|
};
|
|
340
378
|
case "MultiLineString":
|
|
341
379
|
case "Polygon": return {
|
|
342
380
|
type,
|
|
343
|
-
coordinates: geometry.map((ring) => unprojectPoints(ring.points,
|
|
381
|
+
coordinates: geometry.map((ring) => unprojectPoints(ring.points, worldCoordinateHelper))
|
|
344
382
|
};
|
|
345
383
|
case "MultiPolygon": return {
|
|
346
384
|
type,
|
|
347
|
-
coordinates: geometry.map((polygon) => polygon.map((ring) => unprojectPoints(ring.points,
|
|
385
|
+
coordinates: geometry.map((polygon) => polygon.map((ring) => unprojectPoints(ring.points, worldCoordinateHelper)))
|
|
348
386
|
};
|
|
349
387
|
}
|
|
350
388
|
}
|
|
351
|
-
function unprojectPoints(coords,
|
|
389
|
+
function unprojectPoints(coords, worldCoordinateHelper = mercatorWorldCoordinateHelper) {
|
|
352
390
|
const result = [];
|
|
353
|
-
for (let i = 0; i < coords.length; i += 3) result.push(unprojectPoint(coords[i], coords[i + 1],
|
|
391
|
+
for (let i = 0; i < coords.length; i += 3) result.push(unprojectPoint(coords[i], coords[i + 1], worldCoordinateHelper));
|
|
354
392
|
return result;
|
|
355
393
|
}
|
|
356
|
-
function unprojectPoint(x, y,
|
|
357
|
-
return [unprojectX(x
|
|
358
|
-
}
|
|
359
|
-
/**
|
|
360
|
-
* Convert spherical mercator in [0..1] range to longitude, or keep a world coordinate as it is
|
|
361
|
-
*/
|
|
362
|
-
function unprojectX(x, worldCoordinates = false) {
|
|
363
|
-
if (worldCoordinates) return x;
|
|
364
|
-
return (x - .5) * 360;
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Convert spherical mercator in [0..1] range to latitude, or keep a world coordinate as it is
|
|
368
|
-
*/
|
|
369
|
-
function unprojectY(y, worldCoordinates = false) {
|
|
370
|
-
if (worldCoordinates) return y;
|
|
371
|
-
const y2 = (180 - y * 360) * Math.PI / 180;
|
|
372
|
-
return 360 * Math.atan(Math.exp(y2)) / Math.PI - 90;
|
|
394
|
+
function unprojectPoint(x, y, worldCoordinateHelper) {
|
|
395
|
+
return [worldCoordinateHelper.unprojectX(x), worldCoordinateHelper.unprojectY(y)];
|
|
373
396
|
}
|
|
374
397
|
|
|
375
|
-
|
|
376
|
-
//#region src/clip.ts
|
|
398
|
+
// src/clip.ts
|
|
377
399
|
/**
|
|
378
400
|
* clip features between two vertical or horizontal axis-parallel lines:
|
|
379
401
|
* | |
|
|
@@ -404,7 +426,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
404
426
|
}
|
|
405
427
|
if (max < start || min >= end) continue;
|
|
406
428
|
switch (feature.type) {
|
|
407
|
-
case "Point":
|
|
408
429
|
case "MultiPoint":
|
|
409
430
|
clipPointFeature(feature, clipped, start, end, axis);
|
|
410
431
|
continue;
|
|
@@ -558,10 +579,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
558
579
|
return t;
|
|
559
580
|
}
|
|
560
581
|
|
|
561
|
-
|
|
562
|
-
//#region src/wrap.ts
|
|
582
|
+
// src/wrap.ts
|
|
563
583
|
function wrap(features, options) {
|
|
564
|
-
if (options.
|
|
584
|
+
if (!options.wrap) return features;
|
|
565
585
|
const buffer = options.buffer / options.extent;
|
|
566
586
|
let merged = features;
|
|
567
587
|
const left = clip(features, 1, -1 - buffer, buffer, 0, -1, 2, options);
|
|
@@ -625,23 +645,25 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
625
645
|
return newLine;
|
|
626
646
|
}
|
|
627
647
|
|
|
628
|
-
|
|
629
|
-
//#region src/difference.ts
|
|
648
|
+
// src/difference.ts
|
|
630
649
|
/**
|
|
631
650
|
* Applies a GeoJSON Source Diff to an existing set of simplified features
|
|
632
651
|
* @param source
|
|
633
652
|
* @param dataDiff
|
|
634
653
|
* @param options
|
|
654
|
+
* @param unlocated - the features without coordinates, by id, so that an update can give them some
|
|
635
655
|
* @returns
|
|
636
656
|
*/
|
|
637
|
-
function applySourceDiff(source, dataDiff, options) {
|
|
657
|
+
function applySourceDiff(source, dataDiff, options, unlocated) {
|
|
638
658
|
const diff = diffToHashed(dataDiff, options);
|
|
639
659
|
let affected = [];
|
|
640
660
|
if (diff.removeAll) {
|
|
641
661
|
affected = source;
|
|
642
662
|
source = [];
|
|
663
|
+
unlocated?.clear();
|
|
643
664
|
}
|
|
644
665
|
if (diff.remove.size || diff.add.size) {
|
|
666
|
+
for (const id of diff.remove) unlocated?.delete(id);
|
|
645
667
|
const removeFeatures = [];
|
|
646
668
|
for (const feature of source) if (diff.remove.has(feature.id) || diff.add.has(feature.id)) removeFeatures.push(feature);
|
|
647
669
|
if (removeFeatures.length) {
|
|
@@ -653,7 +675,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
653
675
|
let addFeatures = convertToInternal({
|
|
654
676
|
type: "FeatureCollection",
|
|
655
677
|
features: Array.from(diff.add.values())
|
|
656
|
-
},
|
|
678
|
+
}, {
|
|
679
|
+
...options,
|
|
680
|
+
generateId: false
|
|
681
|
+
}, unlocated);
|
|
657
682
|
addFeatures = wrap(addFeatures, options);
|
|
658
683
|
affected = affected.concat(addFeatures);
|
|
659
684
|
source = source.concat(addFeatures);
|
|
@@ -666,8 +691,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
666
691
|
else keepFeatures.push(feature);
|
|
667
692
|
for (const [id, update] of diff.update) {
|
|
668
693
|
const oldFeatures = oldFeaturesMap.get(id);
|
|
669
|
-
if (!oldFeatures || oldFeatures.length === 0)
|
|
670
|
-
|
|
694
|
+
if (!oldFeatures || oldFeatures.length === 0) {
|
|
695
|
+
if (!unlocated?.has(id)) continue;
|
|
696
|
+
const locatedFeatures = getUpdatedUnlocatedFeatures(id, update, options, unlocated);
|
|
697
|
+
affected = affected.concat(locatedFeatures);
|
|
698
|
+
keepFeatures = keepFeatures.concat(locatedFeatures);
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
const updatedFeatures = getUpdatedFeatures(oldFeatures, update, options, unlocated);
|
|
671
702
|
affected = affected.concat(oldFeatures, updatedFeatures);
|
|
672
703
|
keepFeatures = keepFeatures.concat(updatedFeatures);
|
|
673
704
|
}
|
|
@@ -683,29 +714,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
683
714
|
* @param vtFeatures - the original features
|
|
684
715
|
* @param update - the update object to apply
|
|
685
716
|
* @param options - the options to use for the wrap method
|
|
717
|
+
* @param unlocated - the features without coordinates, by id, which a new geometry without coordinates adds the feature to
|
|
686
718
|
* @returns Updated features. If geometry is updated, returns new feature(s) converted from geojson and wrapped, with the id the feature already has. If only properties are updated, returns feature(s) with tags updated.
|
|
687
719
|
*/
|
|
688
|
-
function getUpdatedFeatures(vtFeatures, update, options) {
|
|
720
|
+
function getUpdatedFeatures(vtFeatures, update, options, unlocated) {
|
|
689
721
|
const changeGeometry = !!update.newGeometry;
|
|
690
|
-
const changeProps = update
|
|
722
|
+
const changeProps = hasPropertyChanges(update);
|
|
691
723
|
if (changeGeometry) {
|
|
692
724
|
const vtFeature = vtFeatures[0];
|
|
693
|
-
const
|
|
694
|
-
|
|
695
|
-
id: vtFeature.id,
|
|
696
|
-
geometry: update.newGeometry,
|
|
697
|
-
properties: changeProps ? applyPropertyUpdates(vtFeature.tags, update) : vtFeature.tags
|
|
698
|
-
};
|
|
699
|
-
let features = convertToInternal({
|
|
700
|
-
type: "FeatureCollection",
|
|
701
|
-
features: [geojsonFeature]
|
|
702
|
-
}, {
|
|
703
|
-
...options,
|
|
704
|
-
promoteId: void 0,
|
|
705
|
-
generateId: false
|
|
706
|
-
});
|
|
707
|
-
features = wrap(features, options);
|
|
708
|
-
return features;
|
|
725
|
+
const properties = changeProps ? applyPropertyUpdates(vtFeature.tags, update) : vtFeature.tags;
|
|
726
|
+
return convertNewGeometry(vtFeature.id, update.newGeometry, properties, options, unlocated);
|
|
709
727
|
}
|
|
710
728
|
if (changeProps) {
|
|
711
729
|
const updated = [];
|
|
@@ -719,6 +737,44 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
719
737
|
return vtFeatures;
|
|
720
738
|
}
|
|
721
739
|
/**
|
|
740
|
+
* Gets the features an update gives a feature without coordinates: none, unless its new geometry has some.
|
|
741
|
+
* Its property changes apply either way.
|
|
742
|
+
*/
|
|
743
|
+
function getUpdatedUnlocatedFeatures(id, update, options, unlocated) {
|
|
744
|
+
const feature = unlocated.get(id);
|
|
745
|
+
const properties = hasPropertyChanges(update) ? applyPropertyUpdates(feature.properties, update) : feature.properties;
|
|
746
|
+
if (!update.newGeometry) {
|
|
747
|
+
unlocated.set(id, {
|
|
748
|
+
...feature,
|
|
749
|
+
properties
|
|
750
|
+
});
|
|
751
|
+
return [];
|
|
752
|
+
}
|
|
753
|
+
return convertNewGeometry(id, update.newGeometry, properties, options, unlocated);
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Converts the new geometry of a feature to internal format, keeping the id the feature already has
|
|
757
|
+
*/
|
|
758
|
+
function convertNewGeometry(id, geometry, properties, options, unlocated) {
|
|
759
|
+
const features = convertToInternal({
|
|
760
|
+
type: "FeatureCollection",
|
|
761
|
+
features: [{
|
|
762
|
+
type: "Feature",
|
|
763
|
+
id,
|
|
764
|
+
geometry,
|
|
765
|
+
properties
|
|
766
|
+
}]
|
|
767
|
+
}, {
|
|
768
|
+
...options,
|
|
769
|
+
promoteId: void 0,
|
|
770
|
+
generateId: false
|
|
771
|
+
}, unlocated);
|
|
772
|
+
return wrap(features, options);
|
|
773
|
+
}
|
|
774
|
+
function hasPropertyChanges(update) {
|
|
775
|
+
return update.removeAllProperties || update.removeProperties?.length > 0 || update.addOrUpdateProperties?.length > 0;
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
722
778
|
* helper to apply property updates from a diff update object to a properties object
|
|
723
779
|
*/
|
|
724
780
|
function applyPropertyUpdates(tags, update) {
|
|
@@ -745,8 +801,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
745
801
|
};
|
|
746
802
|
}
|
|
747
803
|
|
|
748
|
-
|
|
749
|
-
//#region node_modules/kdbush/index.js
|
|
804
|
+
// node_modules/kdbush/index.js
|
|
750
805
|
const ARRAY_TYPES = [
|
|
751
806
|
Int8Array,
|
|
752
807
|
Uint8Array,
|
|
@@ -1031,8 +1086,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1031
1086
|
return dx * dx + dy * dy;
|
|
1032
1087
|
}
|
|
1033
1088
|
|
|
1034
|
-
|
|
1035
|
-
//#region src/cluster-tile-index.ts
|
|
1089
|
+
// src/cluster-tile-index.ts
|
|
1036
1090
|
const defaultClusterOptions = {
|
|
1037
1091
|
minZoom: 0,
|
|
1038
1092
|
maxZoom: 16,
|
|
@@ -1043,7 +1097,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1043
1097
|
log: false,
|
|
1044
1098
|
generateId: false,
|
|
1045
1099
|
reduce: null,
|
|
1046
|
-
map: (props) => props
|
|
1100
|
+
map: (props) => props,
|
|
1101
|
+
coordinates: "lngLat",
|
|
1102
|
+
wrap: true
|
|
1047
1103
|
};
|
|
1048
1104
|
/**
|
|
1049
1105
|
* The highest zoom level to cluster on. A cluster id keeps its zoom level in five bits.
|
|
@@ -1083,9 +1139,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1083
1139
|
* This class allow clustering of geojson points.
|
|
1084
1140
|
*/
|
|
1085
1141
|
var ClusterTileIndex = class {
|
|
1086
|
-
constructor(options
|
|
1142
|
+
constructor(options) {
|
|
1087
1143
|
this.options = createOptions(options);
|
|
1088
|
-
this.
|
|
1144
|
+
this.worldCoordinateHelper = getWorldCoordinateHelper(this.options.coordinates);
|
|
1089
1145
|
this.trees = new Array(this.options.maxZoom + 1);
|
|
1090
1146
|
this.stride = this.options.reduce ? 5 : 4;
|
|
1091
1147
|
this.clusterProps = [];
|
|
@@ -1102,8 +1158,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1102
1158
|
if (!point.geometry) continue;
|
|
1103
1159
|
const positions = point.geometry.type === "MultiPoint" ? point.geometry.coordinates : [point.geometry.coordinates];
|
|
1104
1160
|
for (const [lng, lat] of positions) {
|
|
1105
|
-
const [x, y] = [projectX(lng, this.
|
|
1106
|
-
if (this.
|
|
1161
|
+
const [x, y] = [this.worldCoordinateHelper.projectX(lng), this.worldCoordinateHelper.projectY(lat)];
|
|
1162
|
+
if (!this.options.wrap && !isInWorld([x, y])) continue;
|
|
1107
1163
|
const feature = {
|
|
1108
1164
|
id: point.id,
|
|
1109
1165
|
type: "Point",
|
|
@@ -1125,14 +1181,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1125
1181
|
const points = [];
|
|
1126
1182
|
for (const feature of features) {
|
|
1127
1183
|
if (feature.type === "Point") {
|
|
1128
|
-
if (this.
|
|
1184
|
+
if (!this.options.wrap && !isInWorld(feature.geometry)) continue;
|
|
1129
1185
|
points.push(feature);
|
|
1130
1186
|
continue;
|
|
1131
1187
|
}
|
|
1132
1188
|
if (feature.type !== "MultiPoint") continue;
|
|
1133
1189
|
for (let i = 0; i < feature.geometry.length; i += 3) {
|
|
1134
1190
|
const geometry = [feature.geometry[i], feature.geometry[i + 1]];
|
|
1135
|
-
if (this.
|
|
1191
|
+
if (!this.options.wrap && !isInWorld(geometry)) continue;
|
|
1136
1192
|
points.push({
|
|
1137
1193
|
id: feature.id,
|
|
1138
1194
|
type: "Point",
|
|
@@ -1149,7 +1205,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1149
1205
|
* @param features
|
|
1150
1206
|
*/
|
|
1151
1207
|
updateIndex(features, _affected, options) {
|
|
1152
|
-
this.options = createOptions(
|
|
1208
|
+
this.options = createOptions({
|
|
1209
|
+
...options.clusterOptions,
|
|
1210
|
+
coordinates: this.options.coordinates,
|
|
1211
|
+
wrap: this.options.wrap
|
|
1212
|
+
});
|
|
1153
1213
|
this.initialize(features);
|
|
1154
1214
|
}
|
|
1155
1215
|
/**
|
|
@@ -1197,11 +1257,61 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1197
1257
|
}
|
|
1198
1258
|
/**
|
|
1199
1259
|
* Returns clusters and/or points within a bounding box at a given zoom level.
|
|
1200
|
-
* @param bbox - Bounding box in `[westLng, southLat, eastLng, northLat]` order, or `[minX, minY, maxX, maxY]` in
|
|
1260
|
+
* @param bbox - Bounding box in `[westLng, southLat, eastLng, northLat]` order, or `[minX, minY, maxX, maxY]` in the unit square with `coordinates: 'unitSquare'`.
|
|
1261
|
+
* In a world that wraps, the box can reach across the antimeridian. In one that doesn't, only its part inside the world counts.
|
|
1201
1262
|
* @param zoom - Zoom level to query.
|
|
1202
1263
|
*/
|
|
1203
1264
|
getClusters(bbox, zoom) {
|
|
1204
|
-
return (this.
|
|
1265
|
+
return (!this.options.wrap ? this.getClustersInWorld(bbox, zoom) : this.options.coordinates === "unitSquare" ? this.getClustersAcrossEdge(bbox, zoom) : this.getClustersInternal(bbox, zoom)).map((f) => featureToGeoJSON(f, this.worldCoordinateHelper));
|
|
1266
|
+
}
|
|
1267
|
+
/**
|
|
1268
|
+
* The clusters and points in the part of a box inside a world that ends at its edges.
|
|
1269
|
+
*/
|
|
1270
|
+
getClustersInWorld(bbox, zoom) {
|
|
1271
|
+
const lngLat = this.options.coordinates !== "unitSquare";
|
|
1272
|
+
const y1 = this.worldCoordinateHelper.projectY(lngLat ? Math.max(-90, Math.min(90, bbox[1])) : bbox[1]);
|
|
1273
|
+
const y2 = this.worldCoordinateHelper.projectY(lngLat ? Math.max(-90, Math.min(90, bbox[3])) : bbox[3]);
|
|
1274
|
+
const minX = Math.max(0, this.worldCoordinateHelper.projectX(bbox[0]));
|
|
1275
|
+
const maxX = Math.min(1, this.worldCoordinateHelper.projectX(bbox[2]));
|
|
1276
|
+
if (minX > maxX) return [];
|
|
1277
|
+
return this.getClustersInRange([
|
|
1278
|
+
minX,
|
|
1279
|
+
Math.min(y1, y2),
|
|
1280
|
+
maxX,
|
|
1281
|
+
Math.max(y1, y2)
|
|
1282
|
+
], zoom);
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* The clusters and points in a box of a unit square that wraps, where the box can reach across its left or right edge.
|
|
1286
|
+
*/
|
|
1287
|
+
getClustersAcrossEdge([minX, minY, maxX, maxY], zoom) {
|
|
1288
|
+
if (maxX < minX) maxX += 1;
|
|
1289
|
+
if (maxX - minX >= 1) return this.getClustersInRange([
|
|
1290
|
+
0,
|
|
1291
|
+
minY,
|
|
1292
|
+
1,
|
|
1293
|
+
maxY
|
|
1294
|
+
], zoom);
|
|
1295
|
+
const shift = Math.floor(minX);
|
|
1296
|
+
const west = minX - shift;
|
|
1297
|
+
const east = maxX - shift;
|
|
1298
|
+
if (east <= 1) return this.getClustersInRange([
|
|
1299
|
+
west,
|
|
1300
|
+
minY,
|
|
1301
|
+
east,
|
|
1302
|
+
maxY
|
|
1303
|
+
], zoom);
|
|
1304
|
+
return this.getClustersInRange([
|
|
1305
|
+
west,
|
|
1306
|
+
minY,
|
|
1307
|
+
1,
|
|
1308
|
+
maxY
|
|
1309
|
+
], zoom).concat(this.getClustersInRange([
|
|
1310
|
+
0,
|
|
1311
|
+
minY,
|
|
1312
|
+
east - 1,
|
|
1313
|
+
maxY
|
|
1314
|
+
], zoom));
|
|
1205
1315
|
}
|
|
1206
1316
|
getClustersInternal(bbox, zoom) {
|
|
1207
1317
|
let minLng = ((bbox[0] + 180) % 360 + 360) % 360 - 180;
|
|
@@ -1227,10 +1337,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1227
1337
|
return easternHem.concat(westernHem);
|
|
1228
1338
|
}
|
|
1229
1339
|
return this.getClustersInRange([
|
|
1230
|
-
projectX(minLng),
|
|
1231
|
-
projectY(maxLat),
|
|
1232
|
-
projectX(maxLng),
|
|
1233
|
-
projectY(minLat)
|
|
1340
|
+
this.worldCoordinateHelper.projectX(minLng),
|
|
1341
|
+
this.worldCoordinateHelper.projectY(maxLat),
|
|
1342
|
+
this.worldCoordinateHelper.projectX(maxLng),
|
|
1343
|
+
this.worldCoordinateHelper.projectY(minLat)
|
|
1234
1344
|
], zoom);
|
|
1235
1345
|
}
|
|
1236
1346
|
/**
|
|
@@ -1268,7 +1378,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1268
1378
|
const children = [];
|
|
1269
1379
|
for (const id of ids) {
|
|
1270
1380
|
const k = id * this.stride;
|
|
1271
|
-
if (data[k + OFFSET_PARENT] === clusterId) children.push(data[k + OFFSET_NUM] > 1 ? getClusterGeoJSON(coords, id, data, k, this.clusterProps, this.
|
|
1381
|
+
if (data[k + OFFSET_PARENT] === clusterId) children.push(data[k + OFFSET_NUM] > 1 ? getClusterGeoJSON(coords, id, data, k, this.clusterProps, this.worldCoordinateHelper) : featureToGeoJSON(this.points[data[k + OFFSET_ID]], this.worldCoordinateHelper));
|
|
1272
1382
|
}
|
|
1273
1383
|
if (children.length === 0) throw clusterError;
|
|
1274
1384
|
return children;
|
|
@@ -1296,7 +1406,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1296
1406
|
const tree = this.trees[this.limitZoom(z)];
|
|
1297
1407
|
if (!tree) return null;
|
|
1298
1408
|
const z2 = Math.pow(2, z);
|
|
1299
|
-
if (this.
|
|
1409
|
+
if (!this.options.wrap && (x < 0 || x >= z2 || y < 0 || y >= z2)) return null;
|
|
1300
1410
|
const { extent, radius } = this.options;
|
|
1301
1411
|
const p = radius / extent;
|
|
1302
1412
|
const top = encode((y - p) / z2);
|
|
@@ -1310,8 +1420,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1310
1420
|
z
|
|
1311
1421
|
};
|
|
1312
1422
|
this.addTileFeatures(tree.range(encode((x - p) / z2), top, encode((x + 1 + p) / z2), bottom), tree, x, y, z2, tile);
|
|
1313
|
-
if (
|
|
1314
|
-
if (
|
|
1423
|
+
if (this.options.wrap && x === 0) this.addTileFeatures(tree.range(encode(1 - p / z2), top, encode(1), bottom), tree, z2, y, z2, tile);
|
|
1424
|
+
if (this.options.wrap && x === z2 - 1) this.addTileFeatures(tree.range(encode(0), top, encode(p / z2), bottom), tree, -1, y, z2, tile);
|
|
1315
1425
|
return tile;
|
|
1316
1426
|
}
|
|
1317
1427
|
/**
|
|
@@ -1494,14 +1604,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1494
1604
|
geometry: [decode(coords[index * 2]), decode(coords[index * 2 + 1])]
|
|
1495
1605
|
};
|
|
1496
1606
|
}
|
|
1497
|
-
function getClusterGeoJSON(coords, index, data, i, clusterProps,
|
|
1607
|
+
function getClusterGeoJSON(coords, index, data, i, clusterProps, worldCoordinateHelper) {
|
|
1498
1608
|
return {
|
|
1499
1609
|
type: "Feature",
|
|
1500
1610
|
id: data[i + OFFSET_ID],
|
|
1501
1611
|
properties: getClusterProperties(data, i, clusterProps),
|
|
1502
1612
|
geometry: {
|
|
1503
1613
|
type: "Point",
|
|
1504
|
-
coordinates: [unprojectX(decode(coords[index * 2])
|
|
1614
|
+
coordinates: [worldCoordinateHelper.unprojectX(decode(coords[index * 2])), worldCoordinateHelper.unprojectY(decode(coords[index * 2 + 1]))]
|
|
1505
1615
|
}
|
|
1506
1616
|
};
|
|
1507
1617
|
}
|
|
@@ -1521,8 +1631,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1521
1631
|
return geometry[0] >= 0 && geometry[0] <= 1 && geometry[1] >= 0 && geometry[1] <= 1;
|
|
1522
1632
|
}
|
|
1523
1633
|
|
|
1524
|
-
|
|
1525
|
-
//#region src/tile.ts
|
|
1634
|
+
// src/tile.ts
|
|
1526
1635
|
const GEOJSONVT_CLIP_START = "geojsonvt_clip_start";
|
|
1527
1636
|
const GEOJSONVT_CLIP_END = "geojsonvt_clip_end";
|
|
1528
1637
|
/**
|
|
@@ -1669,8 +1778,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1669
1778
|
}
|
|
1670
1779
|
}
|
|
1671
1780
|
|
|
1672
|
-
|
|
1673
|
-
//#region src/transform.ts
|
|
1781
|
+
// src/transform.ts
|
|
1674
1782
|
/**
|
|
1675
1783
|
* Transforms the coordinates of each feature in the given tile from
|
|
1676
1784
|
* mercator-projected space into (extent x extent) tile space.
|
|
@@ -1718,8 +1826,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1718
1826
|
return [Math.round(extent * (x * z2 - tx)), Math.round(extent * (y * z2 - ty))];
|
|
1719
1827
|
}
|
|
1720
1828
|
|
|
1721
|
-
|
|
1722
|
-
//#region src/tile-index.ts
|
|
1829
|
+
// src/tile-index.ts
|
|
1723
1830
|
var TileIndex = class {
|
|
1724
1831
|
constructor(options) {
|
|
1725
1832
|
this.options = options;
|
|
@@ -1784,7 +1891,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1784
1891
|
getTile(z, x, y) {
|
|
1785
1892
|
const { extent, debug } = this.options;
|
|
1786
1893
|
const z2 = 1 << z;
|
|
1787
|
-
if (this.options.
|
|
1894
|
+
if (!this.options.wrap && (x < 0 || x >= z2)) return null;
|
|
1788
1895
|
x = x + z2 & z2 - 1;
|
|
1789
1896
|
const id = toID(z, x, y);
|
|
1790
1897
|
if (this.tiles[id]) return transformTile(this.tiles[id], extent);
|
|
@@ -1810,14 +1917,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1810
1917
|
return transformTile(this.tiles[id], extent);
|
|
1811
1918
|
}
|
|
1812
1919
|
/**
|
|
1813
|
-
* The features the top tile starts from
|
|
1814
|
-
* and only what lies inside the world square and its buffer
|
|
1815
|
-
*
|
|
1920
|
+
* The features the top tile starts from. A world that wraps keeps them all left and right, where wrapping already
|
|
1921
|
+
* put them inside, and one that doesn't only what lies inside the world square and its buffer. Positions in the
|
|
1922
|
+
* unit square are also cut above and below in a world that wraps, where lng/lat is clamped already. The index keeps
|
|
1923
|
+
* the rest, so an update can still move a feature in from outside.
|
|
1816
1924
|
*/
|
|
1817
1925
|
clipToWorld(features) {
|
|
1818
|
-
|
|
1926
|
+
const { wrap, coordinates } = this.options;
|
|
1927
|
+
if (wrap && coordinates !== "unitSquare") return features;
|
|
1819
1928
|
const buffer = this.options.buffer / this.options.extent;
|
|
1820
|
-
const inX = clip(features, 1, -buffer, 1 + buffer, 0, -Infinity, Infinity, this.options) || [];
|
|
1929
|
+
const inX = wrap ? features : clip(features, 1, -buffer, 1 + buffer, 0, -Infinity, Infinity, this.options) || [];
|
|
1821
1930
|
return clip(inX, 1, -buffer, 1 + buffer, 1, -Infinity, Infinity, this.options) || [];
|
|
1822
1931
|
}
|
|
1823
1932
|
/**
|
|
@@ -1959,8 +2068,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1959
2068
|
return ((1 << z) * y + x) * 32 + z;
|
|
1960
2069
|
}
|
|
1961
2070
|
|
|
1962
|
-
|
|
1963
|
-
//#region src/geojsonvt.ts
|
|
2071
|
+
// src/geojsonvt.ts
|
|
1964
2072
|
const defaultOptions = {
|
|
1965
2073
|
maxZoom: 14,
|
|
1966
2074
|
indexMaxZoom: 5,
|
|
@@ -1975,7 +2083,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1975
2083
|
cluster: false,
|
|
1976
2084
|
clusterOptions: defaultClusterOptions,
|
|
1977
2085
|
debug: 0,
|
|
1978
|
-
|
|
2086
|
+
coordinates: "lngLat",
|
|
2087
|
+
wrap: true
|
|
1979
2088
|
};
|
|
1980
2089
|
/**
|
|
1981
2090
|
* Main class for creating and managing a vector tile index from GeoJSON data.
|
|
@@ -1983,11 +2092,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1983
2092
|
var GeoJSONVT = class {
|
|
1984
2093
|
constructor(data, options) {
|
|
1985
2094
|
options = this.options = Object.assign({}, defaultOptions, options);
|
|
2095
|
+
this.worldCoordinateHelper = getWorldCoordinateHelper(options.coordinates);
|
|
1986
2096
|
const debug = options.debug;
|
|
1987
2097
|
if (debug) console.time("preprocess data");
|
|
1988
2098
|
if (options.maxZoom < 0 || options.maxZoom > 24) throw new Error("maxZoom should be in the 0-24 range");
|
|
1989
2099
|
if (options.promoteId && options.generateId) throw new Error("promoteId and generateId cannot be used together.");
|
|
1990
|
-
|
|
2100
|
+
if (options.updateable) this.unlocated = /* @__PURE__ */ new Map();
|
|
2101
|
+
this.nextId = data.type === "FeatureCollection" ? data.features.length : 1;
|
|
2102
|
+
let features = convertToInternal(data, options, this.unlocated);
|
|
1991
2103
|
if (debug) {
|
|
1992
2104
|
console.timeEnd("preprocess data");
|
|
1993
2105
|
console.log("index: maxZoom: %d, maxPoints: %d", options.indexMaxZoom, options.indexMaxPoints);
|
|
@@ -1998,7 +2110,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
1998
2110
|
this.initializeIndex(features, options);
|
|
1999
2111
|
}
|
|
2000
2112
|
initializeIndex(features, options) {
|
|
2001
|
-
this.tileIndex = options.cluster ? new ClusterTileIndex(
|
|
2113
|
+
this.tileIndex = options.cluster ? new ClusterTileIndex({
|
|
2114
|
+
...options.clusterOptions,
|
|
2115
|
+
coordinates: options.coordinates,
|
|
2116
|
+
wrap: options.wrap
|
|
2117
|
+
}) : new TileIndex(options);
|
|
2002
2118
|
if (!features.length) return;
|
|
2003
2119
|
this.tileIndex.initialize(features);
|
|
2004
2120
|
}
|
|
@@ -2023,24 +2139,34 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2023
2139
|
updateData(diff, filter) {
|
|
2024
2140
|
const options = this.options;
|
|
2025
2141
|
if (!options.updateable) throw new Error("to update tile geojson `updateable` option must be set to true");
|
|
2026
|
-
|
|
2142
|
+
if (options.generateId && diff.add) diff = {
|
|
2143
|
+
...diff,
|
|
2144
|
+
add: diff.add.map((feature) => ({
|
|
2145
|
+
...feature,
|
|
2146
|
+
id: this.nextId++
|
|
2147
|
+
}))
|
|
2148
|
+
};
|
|
2149
|
+
let { affected, source } = applySourceDiff(this.source, diff, options, this.unlocated);
|
|
2027
2150
|
if (filter) ({affected, source} = this.filterUpdate(source, affected, filter));
|
|
2028
2151
|
if (!affected.length) return;
|
|
2029
2152
|
this.source = source;
|
|
2030
2153
|
this.tileIndex.updateIndex(source, affected, options);
|
|
2031
2154
|
}
|
|
2032
2155
|
/**
|
|
2033
|
-
* Filter an update using a predicate function
|
|
2156
|
+
* Filter an update using a predicate function, the features an update emptied included, so that one the filter
|
|
2157
|
+
* rejects can't come back with a later update. A feature without a geometry at all isn't passed to the predicate.
|
|
2158
|
+
* Returns the affected and updated source features.
|
|
2034
2159
|
*/
|
|
2035
2160
|
filterUpdate(source, affected, predicate) {
|
|
2036
2161
|
const removeIds = /* @__PURE__ */ new Set();
|
|
2037
2162
|
for (const feature of source) {
|
|
2038
2163
|
if (feature.id == void 0) continue;
|
|
2039
|
-
if (predicate(featureToGeoJSON(feature, this.
|
|
2164
|
+
if (predicate(featureToGeoJSON(feature, this.worldCoordinateHelper))) continue;
|
|
2040
2165
|
affected.push(feature);
|
|
2041
2166
|
removeIds.add(feature.id);
|
|
2042
2167
|
}
|
|
2043
2168
|
source = source.filter((feature) => !removeIds.has(feature.id));
|
|
2169
|
+
for (const [id, feature] of this.unlocated ?? []) if (feature.geometry && !predicate(feature)) this.unlocated.delete(id);
|
|
2044
2170
|
return {
|
|
2045
2171
|
affected,
|
|
2046
2172
|
source
|
|
@@ -2051,12 +2177,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2051
2177
|
*/
|
|
2052
2178
|
getData() {
|
|
2053
2179
|
if (!this.options.updateable) throw new Error("to retrieve data the `updateable` option must be set to true");
|
|
2054
|
-
return convertToGeoJSON(this.source, this.
|
|
2180
|
+
return convertToGeoJSON(this.source, this.worldCoordinateHelper);
|
|
2055
2181
|
}
|
|
2056
2182
|
/**
|
|
2057
2183
|
* Update supercluster options and regenerate the index.
|
|
2058
2184
|
* @param cluster - whether to enable clustering
|
|
2059
|
-
* @param clusterOptions - {@link SuperclusterOptions}
|
|
2185
|
+
* @param clusterOptions - {@link SuperclusterOptions} without `coordinates` and `wrap`, which come from the index options
|
|
2060
2186
|
*/
|
|
2061
2187
|
updateClusterOptions(cluster, clusterOptions) {
|
|
2062
2188
|
const wasCluster = this.options.cluster;
|
|
@@ -2096,8 +2222,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2096
2222
|
}
|
|
2097
2223
|
};
|
|
2098
2224
|
|
|
2099
|
-
|
|
2100
|
-
//#region src/geojson-to-tile.ts
|
|
2225
|
+
// src/geojson-to-tile.ts
|
|
2101
2226
|
/**
|
|
2102
2227
|
* Converts GeoJSON data directly to a single vector tile without building a tile index.
|
|
2103
2228
|
*
|
|
@@ -2133,9 +2258,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2133
2258
|
function geoJSONToTile(data, z, x, y, options = {}) {
|
|
2134
2259
|
options = {
|
|
2135
2260
|
...defaultOptions,
|
|
2261
|
+
wrap: false,
|
|
2136
2262
|
...options
|
|
2137
2263
|
};
|
|
2138
|
-
const { wrap: shouldWrap
|
|
2264
|
+
const { wrap: shouldWrap, clip: shouldClip = false } = options;
|
|
2139
2265
|
let features = convertToInternal(data, options);
|
|
2140
2266
|
if (shouldWrap) features = wrap(features, options);
|
|
2141
2267
|
if (shouldClip || options.lineMetrics) {
|
|
@@ -2147,7 +2273,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2147
2273
|
return transformTile(createTile(features ?? [], z, x, y, options), options.extent);
|
|
2148
2274
|
}
|
|
2149
2275
|
|
|
2150
|
-
//#endregion
|
|
2151
2276
|
exports.GEOJSONVT_CLIP_END = GEOJSONVT_CLIP_END;
|
|
2152
2277
|
exports.GEOJSONVT_CLIP_START = GEOJSONVT_CLIP_START;
|
|
2153
2278
|
exports.GeoJSONVT = GeoJSONVT;
|