简体   繁体   中英

MapBox get div element of Marker

I am initially pushing MapBox Marker objects to an array via:

var el = document.createElement('div' + index);
el.className = 'marker';
deviceMarkers.push(new mapboxgl.Marker(el, { offset: [-50 / 2, -50 / 2] }).setLngLat([device.lat, device.lon]).addTo(map));

Elsewhere in the code, I extract the marker via:

var deviceMarker = deviceMarkers[index];

I would like to be able to get 'el' from deviceMarker object, in order to alter the icon size, orientation etc. dynamically. How can I extract 'el' as the original div?

You can use deviceMarker.getElement() – this function is currently undocumented but public. I will work on getting it added to the documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM