Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

javascript - Mapbox Filter is not giving Correct result, when using promoteId

Good Day,

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

JSFiddle:

https://jsfiddle.net/dollysingh3192/w6bzsx84/7/

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
                    }
             ]
}

Working

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

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

Working GIF: enter image description here

Not Working

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: enter image description here

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:(Don't know why it works). LINK

Please guide. Am I doing anything wrong here?

https://jsfiddle.net/dollysingh3192/w6bzsx84/7/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To get properties data use get

Try it this way

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

Update:

To fitler on id/promoteId

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

https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/#id


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...