leaftjs:点击弹出框里面字体的事件和报错map container is already initialized
1.在使用leaftjs时报错map container is already initialized。
/**解决点击弹出框报错问题
*ref1.current是渲染地图的容器
*/
const container = L.DomUtil.get(ref1.current)
if (container != null) {
container._leaflet_id = null
}
2.监听弹出框里面的事件
//这是marker里面显示的文字,添加**data**属性和calss
.bindPopup(
`<p data=${data[i]?.id} class='pp' style='color:blue'>主体:${
data[i]?.bodyName || '无'
}</p>`)
//这是全局监听点击*p*标签发生的事件,没有找到leaftjs的方法,唉,就用这个
document.addEventListener(
'click',
e => {
if (e.target.className === 'pp' && e.target.getAttribute('data')) {
//......写你的操作
}
},
true
)