2013-01-03 71 views
5

我在地圖上使用geoJSON繪製了多個點。當你點擊一個點時,地圖會放大到一點,並在另一個div中拉出一些信息。當我在mouseover事件上放置一個彈出窗口時,我的點擊功能不再起作用。在mouseover上彈出的單張消除點擊事件

這裏是我的點擊功能:

function fillInfo(e) { 
     var layer = e.target; 

     document.getElementById('infoBox').innerHTML = '<h2>' + layer.feature.properties.name + '</h2>' + '<h3>' + layer.feature.properties.address + '</h3></p>' 
     } 
     //Variable to set zoom level on click 
     var southLat = layer.feature.geometry.coordinates[0] + .022438; 
     var southLong = layer.feature.geometry.coordinates[1] - .003235; 

     var northLat = layer.feature.geometry.coordinates[0] - .022438; 
     var northLong = layer.feature.geometry.coordinates[1] + .003235; 

     map.fitBounds([[southLong, southLat], [northLong, northLat]]); 


    }​ 

這裏是我的鼠標懸停功能:

 function highlightFeature(e) { 
     var layer = e.target; 

     layer.bindPopup(layer.feature.properties.name) 
      .openPopup(); 


     layer.setStyle({ 
      weight: 5, 
      color: '#666', 
      dashArray: '', 
      fillOpacity: 0.7 
     }); 



     if (!L.Browser.ie && !L.Browser.opera) { 
      layer.bringToFront(); 
     } 

    } 

在這裏,我打電話給他們:

function onEachFeature(feature, layer) { 
     layer.on({ 
      click: fillInfo, 
      mouseover: highlightFeature, 
      mouseout: resetHighlight 
     }); 
    } 

這得到彈出罰款工作滾動,但該點不再響應點擊事件。

回答

2

有一個彈出偏移屬性,默認設置爲[0,6],因此彈出窗口覆蓋點(包含白色向下箭頭的節點比箭頭大),並且您將無法點擊該點。

設置彈出窗口的偏移選項:

layer.bindPopup(layer.feature.properties.name,{offset:new L.Point(0,0)}) 
.openPopup(); 

提供給L.Point的第二個參數是最重要的y座標,減少這種說法向上移動彈出。

+0

是的,那是它!太棒了,感謝您的幫助! – user1410712