Search code examples
mapbox-gl-jsmapbox-marker

How to get a reference to markers autogenerated by the creation of the symbol layer?


I need to perform automated actions on individual markers on my map, but based on all the answers I'm finding online I will first need to store references to my markers in my script. However, I am not creating the markers explicitly. Instead it seems the markers are being generated when I load a collection of points from geojson using the map.addSource() and map.addLayer() methods.

For an MCVE see here.

How can I get references to the generated markers using this method?


Solution

  • You are confusing Markers (HTML elements that sit above the map) with a symbol layer (graphical elements that exist within the map). Symbol layers don't generate markers, and there are no "references" to get.