MapBox取得Marker的div元素 [英] MapBox get div element of Marker

查看:332
本文介绍了MapBox取得Marker的div元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初是通过以下方式将MapBox 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];

我希望能够从deviceMarker对象获取"el",以便动态更改图标大小,方向等.如何提取"el"作为原始div?

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?

推荐答案

您可以使用deviceMarker.getElement() –该函数目前未公开,但已公开.我将努力将其添加到文档中.

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

这篇关于MapBox取得Marker的div元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆