mapbox / mapbox/mapbox-gl-js

Keep `feature.id` as `cluster_id` even when `promoteId` is set to something else

Open
#10,094 3 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :lady_beetle: needs investigation :mag:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

## Motivation

Currently trying to add a hover effect to my clusters, but `setFeatureState` cannot target the clusters as they do not have any ID. The reason being my `promoteId` is set to a custom property from my GeoJSON source.

## Design Alternatives

**Suggestion 1**

Ignore `promoteId` for cluster features.

**Suggestion 2 - follow the spec**

The [style spec](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#geojson-promoteId) says that you can target individual layers for `promoteId`, but this is false. Setting `promoteId` as following does not work:

```
...
promoteId: {
'some_layer_id': 'some_prop',
'cluster_layer_id': 'cluster_id',
},
...
```

If this was to work as the style spec suggests, it would solve the problem.

## Design

As suggestion 2 is already following the spec, I assume that would be the _most correct way_ of implementing it, but I don't see any drawbacks with suggestion 1.
Suggestion 1 has the advantage of working without having to specify layer source ids - this can be especially painful if you have a lot of layers you need to target.

### Mock-Up

It will not make any changes, except following the spec if that suggestion is chosen.

### Concepts

Should add a note in the spec that clusters will use `cluster_id` instead of `promoteId`, if suggestion 1 is accepted.

### Implementation

I do not have enough knowledge of the mapbox internals to answer this 😅

---

**End notes**

Thanks for taking the time to read my suggestion. If there already is a solution to my problem, I've not found it and would love to be pointed in the right direction. Even so the spec _do_ tell me something that is not true, so I believe this will need to be solved either way. In any case, thanks again, and if my issue has problems, or I misunderstood some of the headers, please correct me! 😁

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the GeoJSON source handling for promoteId and clustering, then trace how cluster_id is exposed to setFeatureState. Compare that behavior with the style spec's per-layer promoteId example. Done means cluster features retain cluster_id as feature.id, or the documented per-layer behavior works consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.