@maplibre/geojson-vt 6.3.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.
@@ -10,6 +10,7 @@ export declare class GeoJSONVT {
10
10
  private source?;
11
11
  private unlocated?;
12
12
  private tileIndex;
13
+ private nextId;
13
14
  constructor(data: GeoJSON.GeoJSON, options?: GeoJSONVTOptions);
14
15
  private initializeIndex;
15
16
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"geojsonvt.d.ts","sourceRoot":"","sources":["../src/geojsonvt.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkB,KAAK,mBAAmB,EAAC,MAAM,cAAc,CAAC;AAGvE,OAAO,KAAK,EAAC,qBAAqB,EAAgD,gBAAgB,EAAE,aAAa,EAAC,MAAM,eAAe,CAAC;AAExI,eAAO,MAAM,cAAc,EAAE,gBAgB5B,CAAC;AAEF;;GAEG;AACH,qBAAa,SAAS;IAClB,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,qBAAqB,CAAwB;IAErD,OAAO,CAAC,MAAM,CAAC,CAA6B;IAC5C,OAAO,CAAC,SAAS,CAAC,CAAwC;IAC1D,OAAO,CAAC,SAAS,CAAqB;gBAE1B,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,gBAAgB;IAkC7D,OAAO,CAAC,eAAe;IAMvB;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,aAAa,GAAG,IAAI;IAUzF;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,mBAAmB,EAAE,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,KAAK,OAAO;IAqBpF;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAkBpB;;OAEG;IACH,OAAO,IAAI,OAAO,C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AGG;IACH,UAAU,CAAC,IAAI,EAAE,mBAAmB,EAAE,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,KAAK,OAAO;IAwBpF;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAkBpB;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,OAAO;IAK1B;;;;OAIG;IACH,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,gBAAgB,CAAC,gBAAgB,CAAC;IAazF;;;;OAIG;IACH,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIzD;;;;OAIG;IACH,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,qBAAqB,EAAE,GAAG,IAAI;IAIrE;;;;;;OAMG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI;CAG9G"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maplibre/geojson-vt",
3
- "version": "6.3.0",
3
+ "version": "6.3.1",
4
4
  "description": "Slice GeoJSON data into vector tiles efficiently",
5
5
  "type": "module",
6
6
  "exports": {
@@ -27,15 +27,15 @@
27
27
  "@eslint/js": "^10.0.1",
28
28
  "@types/benchmark": "^2.1.5",
29
29
  "@types/geojson": "^7946.0.16",
30
- "@types/node": "^26.6.5",
31
- "@vitest/coverage-v8": "^5.0.3",
30
+ "@types/node": "^26.6.6",
31
+ "@vitest/coverage-v8": "^5.1.0",
32
32
  "benchmark": "^2.1.4",
33
- "eslint": "^10.12.0",
34
- "rolldown": "^1.2.13",
33
+ "eslint": "^10.14.0",
34
+ "rolldown": "^1.3.0",
35
35
  "tsx": "^4.23.15",
36
36
  "typedoc": "^0.28.20",
37
37
  "typescript": "^6.0.3",
38
- "typescript-eslint": "^8.71.1",
38
+ "typescript-eslint": "^8.72.1",
39
39
  "vitest": "^5.0.3"
40
40
  },
41
41
  "license": "ISC",
package/src/clip.ts CHANGED
@@ -50,7 +50,6 @@ export function clip(features: GeoJSONVTInternalFeature[], scale: number, start:
50
50
  }
51
51
 
52
52
  switch (feature.type) {
53
- case 'Point':
54
53
  case 'MultiPoint': {
55
54
  clipPointFeature(feature, clipped, start, end, axis);
56
55
  continue;
package/src/difference.ts CHANGED
@@ -105,7 +105,8 @@ export function applySourceDiff(source: GeoJSONVTInternalFeature[], dataDiff: Ge
105
105
  }
106
106
 
107
107
  if (diff.add.size) {
108
- let addFeatures = convertToInternal({type: 'FeatureCollection', features: Array.from(diff.add.values())}, options, unlocated);
108
+ // added features keep their own ids, as generated ids are given to them before the diff is applied
109
+ let addFeatures = convertToInternal({type: 'FeatureCollection', features: Array.from(diff.add.values())}, {...options, generateId: false}, unlocated);
109
110
  addFeatures = wrap(addFeatures, options);
110
111
  affected = affected.concat(addFeatures);
111
112
  source = source.concat(addFeatures);
@@ -291,6 +291,18 @@ test('updateData leaves a feature without a geometry removed by removeAll when a
291
291
  expect(index.getTile(0, 0, 0).features.map(feature => feature.id)).toEqual(['kept']);
292
292
  });
293
293
 
294
+ test('updateData gives each feature added with generateId a new id that is not reused and can be removed', () => {
295
+ const point = (x: number): GeoJSON.Feature => ({type: 'Feature', properties: {x}, geometry: {type: 'Point', coordinates: [x, 0]}});
296
+ const index = new GeoJSONVT({type: 'FeatureCollection', features: [point(0), point(1)]}, {updateable: true, generateId: true});
297
+
298
+ index.updateData({add: [point(2), point(3)]});
299
+ index.updateData({remove: [0]});
300
+ index.updateData({add: [point(4)]});
301
+ index.updateData({remove: [2]});
302
+
303
+ expect((index.getData() as GeoJSON.FeatureCollection).features.map(feature => [feature.id, feature.properties.x])).toEqual([[1, 1], [3, 3], [4, 4]]);
304
+ });
305
+
294
306
  test('updateData keeps the property changes made to a feature while it has no geometry', () => {
295
307
  const renamed: GeoJSON.Feature = {type: 'Feature', id: 'renamed', properties: {name: 'before'}, geometry: null};
296
308
  const index = new GeoJSONVT({type: 'FeatureCollection', features: [renamed]}, {updateable: true});
package/src/geojsonvt.ts CHANGED
@@ -35,6 +35,7 @@ export class GeoJSONVT {
35
35
  private source?: GeoJSONVTInternalFeature[];
36
36
  private unlocated?: Map<string | number, GeoJSON.Feature>;
37
37
  private tileIndex: GeoJSONVTTileIndex;
38
+ private nextId: number;
38
39
 
39
40
  constructor(data: GeoJSON.GeoJSON, options?: GeoJSONVTOptions) {
40
41
  options = this.options = Object.assign({}, defaultOptions, options);
@@ -50,6 +51,9 @@ export class GeoJSONVT {
50
51
  // for updateable indexes, keep the properties of the features without coordinates, so that an update can give them some
51
52
  if (options.updateable) this.unlocated = new Map();
52
53
 
54
+ // with generateId, features added by an update get ids after the ones generated here
55
+ this.nextId = data.type === 'FeatureCollection' ? data.features.length : 1;
56
+
53
57
  // projects and adds simplification info
54
58
  let features = convertToInternal(data, options, this.unlocated);
55
59
 
@@ -102,6 +106,9 @@ export class GeoJSONVT {
102
106
 
103
107
  if (!options.updateable) throw new Error('to update tile geojson `updateable` option must be set to true');
104
108
 
109
+ // give added features new generated ids, so none of them share or reuse an id
110
+ if (options.generateId && diff.add) diff = {...diff, add: diff.add.map(feature => ({...feature, id: this.nextId++}))};
111
+
105
112
  // apply diff and collect affected features and updated source that will be used to invalidate tiles
106
113
  let {affected, source} = applySourceDiff(this.source, diff, options, this.unlocated);
107
114