mapbox / mapbox/mapbox-gl-js

query*Features should preserve non-integer feature IDs

Open
#2,716 39 comments 42 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature :green_apple:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Here's a jsbin demonstrating the issue:
https://jsbin.com/bafewapela/edit?html,console,output

The GeoJSON spec [states](http://geojson.org/geojson-spec.html#feature-objects) that features may have a top-level id property:

> If a feature has a commonly used identifier, that identifier should be included as a member of the feature object with the name "id".

However, when I have a source with such a feature:

``` javascript
var markers = {
"type": "FeatureCollection",
"features": [{
"id": "my-feature-id", // <--- feature has an ID
"type": "Feature",
"properties": {
"marker-symbol": "theatre",
},
"geometry": {
"type": "Point",
"coordinates": [-77.038659, 38.931567]
}
}]
};
```

add it to the map and then get features back via `queryRenderedFeatures`, the `id` is gone. The `properties` and `geometry` properties are there, but `id` is not. It would be really helpful if this special property were preserved.

The workaround is to duplicate IDs into `properties.id` before adding features to the map, but this creates extra work and contradicts the GeoJSON spec.

**mapbox-gl-js version**: 0.19.1

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 reproducing the missing top-level id with the JSBin example and trace the queryRenderedFeatures entry point. Verify how feature data is assembled, then preserve non-integer feature IDs in the returned features without requiring properties.id; done means the string ID remains available in queryRenderedFeatures results.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
api, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.