更改阈值以激活传单中的鼠标悬停事件



我目前有一个鼠标悬停功能,可以在传单地图中正常工作。我想知道是否有一种简单的方法可以改变鼠标悬停时弹出的阈值。按原样,鼠标光标必须直接位于点上(这是点数据)才能激活弹出窗口。理想情况下,这个阈值会更大,这样鼠标悬停在功能合理的附近,可能只有几个像素,就会激活弹出窗口。这是我现有的代码:

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

听起来像是传单的工作。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/

最新更新