mapbox-gl-js
mapbox-gl-js copied to clipboard
querySourceFeatures returns the data doubled
I created a Style https://api.mapbox.com/styles/v1/nurp/clqxnrutg005s01pddzsbchyz.html?title=view&access_token=pk.eyJ1IjoibnVycCIsImEiOiJjajVkaWF0NnUwYTdsMnduejdpZjIydjd1In0.BTjYUbXCFa5UUhqdbficyg&zoomwheel=true&fresh=true#0.54/0/0
Uploaded my geojson source with 7 features in it.
On my javascript page, I call this and see that it returns an array of 14 objects. First 7 objects are repeated again somehow
map.querySourceFeatures('composite', { sourceLayer: 'small_data-d3ir0g'})
Is this expected or bug?
Hi @nurp,
Thanks for creating an issue. It looks like a bug.
I have the same problem, sometimes up to 4 identical markers are created for the same ‘feature’. The HTML code can become large and slow down the map.
JS file used : https://api.mapbox.com/mapbox-gl-js/v3.4.0/mapbox-gl.js
How to use :
const features = map.querySourceFeatures('markers', { filter: ['!', ['has', 'point_count']] });
To see this, override the .mapboxgl-marker CSS, like this :
.mapboxgl-marker { position: unset !important; }
The markers will overlap and you'll see them multiplied.
I'm currently getting round the problem by saving the feature IDs in a JS variable.
Here, my GEOjson collection (only 2 Points)
:
const geojson = { 'type': 'FeatureCollection', 'features': [ { 'type': 'Feature', 'properties': { 'id': 1011 }, 'geometry': { 'type': 'Point', 'coordinates': [23, 23] } }, { 'type': 'Feature', 'properties': { 'id': 1012 }, 'geometry': { 'type': 'Point', 'coordinates': [24, 24] } } ] };
Here, the capture generated :