Skip to content

Commit

Permalink
Accounting for IDs of cluster features when the promoteID properties …
Browse files Browse the repository at this point in the history
…is set (#4899)

* Accounting for IDs of cluster features when the promoteID properties is set

* feature collection for testing clusters

* First crack at a test

* sorta getting there but not really

* Not sure why these are failing

* This should be working

* No logging please

* Reverting back to before I accidentally changed the default linter

* This is a better approach I think

* These three tests are passing

* These tests look good to go

* updated changelog

* Probably should keep this

* Some updates from PR feedback

* Try this test

* Think I was trying to cover to much with this test

* Don't need this anymore

* Silly update to restart the pipeline
  • Loading branch information
popkinj authored Nov 6, 2024
1 parent 138ed60 commit 91e4945
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## main

### ✨ Features and improvements
- When clustering circles and the promoteId is set to some parameter, the promoted ID is used on non-clustered features and the cluster_id is used on clustered features. Previously the ID was undefined for non-clustered features.
- Support Terrain in Globe projection ([#4976](https://github.com/maplibre/maplibre-gl-js/pull/4976))
- Improved performance of the `coveringTiles` (tile culling) function for globe ([#4937](https://github.com/maplibre/maplibre-gl-js/pull/4937))
- _...Add new stuff here..._
Expand Down
31 changes: 31 additions & 0 deletions src/data/feature_index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {FeatureIndex} from './feature_index';
import {OverscaledTileID} from '../source/tile_id';
import type {VectorTileFeature} from '@mapbox/vector-tile';

describe('FeatureIndex', () => {
describe('getId', () => {
const tileID = new OverscaledTileID(0, 0, 0, 0, 0);

test('uses cluster_id when cluster is true and id is undefined', () => {
const featureIndex = new FeatureIndex(tileID, 'someProperty');
const feature = {
properties: {
cluster: true,
cluster_id: '123',
promoteId: 'someProperty',
someProperty: undefined
},
geometry: {
type: 'Point',
coordinates: [0, 0]
},
extent: 4096,
type: 1,
loadGeometry: () => [],
toGeoJSON: () => ({})
} as unknown as VectorTileFeature;

expect(featureIndex.getId(feature, 'sourceLayer')).toBe(123); // cluster_id converted to number
});
});
});
5 changes: 5 additions & 0 deletions src/data/feature_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ export class FeatureIndex {
const propName = typeof this.promoteId === 'string' ? this.promoteId : this.promoteId[sourceLayerId];
id = feature.properties[propName] as string | number;
if (typeof id === 'boolean') id = Number(id);

// When cluster is true, the id is the cluster_id even though promoteId is set
if (id === undefined && feature.properties?.cluster && this.promoteId) {
id = Number(feature.properties.cluster_id);
}
}
return id;
}
Expand Down

0 comments on commit 91e4945

Please sign in to comment.