2016-07-26 62 views
1

我目前有一個鼠標懸停功能,可以在小冊子地圖中正常工作。我想知道是否有一種簡單的方法可以改變彈出窗口時的閾值。因爲鼠標光標必須直接位於該點(這是點數據)才能激活彈出窗口。理想情況下,此閾值會更大,以便在特徵的合理附近(可能爲幾個像素)內的鼠標懸停將激活彈出窗口。這裏是我現有的代碼:更改閾值以激活小冊子中的鼠標懸停事件

layer.on({ 
     mouseover: function(){ 
     this.openPopup(); 
    }, 
    mouseout: function(){ 
     this.closePopup(); 
    }, 
    click: function(){ 
     $("#panel").html(popupContent); 
    } 
}); 

回答

1

聽起來像是Leaflet.GeometryUtil插件工作:

爲單張幾何實用程序集(線性參考等)

map.on("mousemove", function(event) { 
    var result = L.GeometryUtil.closestLayerSnap(
    map, 
    all, // array of layers that can be "snapped" to. 
    event.latlng, // mouse position. 
    30); // distance in pixels under which snapping occurs. 

    if (result) { 
    result.layer.fire("mouseover"); 
    } // Note: since the mouse may never go "over" the marker, 
    // it may never go "out", hence never trigger "mouseout" event. 
}); 

演示:https://jsfiddle.net/3v7hd2vx/50/