【问题标题】:Changing the threshold to activate mouseover event in leaflet更改阈值以激活传单中的鼠标悬停事件
【发布时间】:2016-07-26 17:36:05
【问题描述】:

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

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

【问题讨论】:

    标签: javascript leaflet


    【解决方案1】:

    听起来像是 Leaflet.GeometryUtil 插件的工作:

    Leaflet 几何图形的实用程序集合(线性参考等)

    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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-27
      • 1970-01-01
      • 2018-08-13
      • 1970-01-01
      相关资源
      最近更新 更多