借用map对象存储事件,并在绑定前添加判断 if(!map[id+'-point-mouseenter']){ map[id+'-point-mouseenter']=function (e) { map.getCanvas().style.cursor = 'pointer'; if(iconId){ return } that.popup.remove() that.popup.options.info=e.features[0].properties; that.popups.forEach(function (pop) { if(pop.id&&pop.id==e.features[0].properties.content){ that.popup=pop that.popup.off('open') that.popup.on('open', function(epopup) { const closePopupSpan = document.getElementsByClassName( 'closePopupSpan' ) if (closePopupSpan.length > 0) { // 关闭气泡 closePopupSpan[0].onclick = function() { that.popup.remove() } } const popupBtnfb = document.getElementsByClassName( 'popupBtnfb' ) const popupBtnDetails = document.getElementsByClassName( 'popupBtnDetails' ) if (popupBtnfb.length > 0) { // 发布预警 popupBtnfb[0].onclick = function() { } } if (popupBtnDetails.length > 0) { // 详细信息 popupBtnDetails[0].onclick = function() { if(clickFunction){ clickFunction(e.features[0].properties) //e.features[0].properties } } } }) that.popup.addTo(map); } }) } map.off('mouseenter', id+'-point',map[id+'-point-mouseenter']) map.on('mouseenter', id+'-point', map[id+'-point-mouseenter']); }
mapbox事件重复绑定问题处理
最新推荐文章于 2024-07-19 12:58:53 发布