mapbox / mapbox/mapbox-gl-js

queryRenderedFeatures filter is not giving correct result, when using promoteId.

Open
#10,257 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Good Day,

I have a geojson (similar to below) and I am facing trouble with an expression that works well when used without promoteId.

GeoJson

{
                'type': 'FeatureCollection',
                'features': [
                    {
                        "geometry": {
                            "type": "Point",
                            "coordinates": [
                                8.612079620361328,
                                -2.932969060251523
                            ]
                        },
                        "type": "Feature",
                        "properties": {
                            "id": "GMYTEORRGI5DQ",
                            "sid": "s_133",
                            "n": "15",
                            "r": "13",
                            "s": "312",
                            "sz": 5.5,
                            "m": "n",
                            "ri": 13,
                            "si": 7
                        },
                        "id": 11578
                    }
             ]
}
Expected Behavior

Below expression is working fine and extract one feature from Map(Without using promoteId):

mapInstance.queryRenderedFeatures({ layers: ['seat'], filter: ["any", ["==", ["id"], 21762]] });

Working GIF:
Jan-05-2021 22-09-22 (1)

Actual Behavior

But on using promoteId in geojson source, the expression is not working at all.

mapInstance.queryRenderedFeatures({ layers: ['seat'], filter: ["any", ["==", ["id"], "GMYTEORRGI5DQ"]] });

Not Working GIF:
Jan-05-2021 22-12-30

However, I noticed that setFilter and setFeatureState work fine with the same expression.

mapInstance.setFilter('seat', ["match", ["id"], "GMYTEORRGI5DQ", true, false]); //Works fine

GIF with setFilter:
Jan-06-2021 13-07-08

No idea why ["id"] filter works with numeric feature id(No promoteId), but ["id"] doesn't work as soon as I apply promoteId in geojson source and try to fetch the feature with string id.

JsBin Link:

Edit: I am attaching a fiddle https://jsfiddle.net/dollysingh3192/w6bzsx84/7/ where on console log on mousemove ["id"] filter returns an empty array.

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 with the queryRenderedFeatures filter behavior when a GeoJSON source uses promoteId, comparing it with the working numeric feature-id case. Reproduce the empty result from the linked fiddle, then compare the ["id"] handling used by queryRenderedFeatures, setFilter, and setFeatureState. Done means string IDs promoted from GeoJSON can be matched by queryRenderedFeatures as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.