mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
11.17k stars 2.22k forks source link

querySourceFeatures returns the data doubled #13034

Open nurp opened 9 months ago

nurp commented 9 months ago

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?

stepankuzmin commented 9 months ago

Hi @nurp,

Thanks for creating an issue. It looks like a bug.

two3d commented 4 months ago

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 : Screenshot 2024-06-05 at 10-43-10 Add custom icons with Markers

duplicate