5

In Leaflet, is it possible to define a marker or polyline with {clickable:false}, so that a click is passed through to whatever lies beneath - be it the map or a clickable geometry object?

At the moment I solve this problem by making the marker/polyline clickable and passing the event onwards myself. But this leads to the mouse cursor always showing as the hand symbol. Ideally, the mouse cursor should look like the normal pointer or the hand, depending on whether what is beneath the marker/polyline is clickable.

4

2 回答 2

0

这可能不是您正在寻找的答案,但您可以使用 featureGroups 让所有可点击的折线都出现在前面,以便显示操作。

var lg_noclick = new L.FeatureGroup().addTo(map);
var lg_click = new L.FeatureGroup().addTo(map);
// Add lines
lg_click.bringToFront();

更新的小提琴

此外,如果您有能力事先了解您的行,那么添加行时的正确顺序也将起作用。

于 2013-09-09T06:47:56.290 回答
0

我知道这并不理想,但它很适合我的情况,所以它也可能对你有好处。

这会隐藏图标并在第二次使用mouseentermouseleave事件后将其恢复:

$('.leaflet-marker-icon').mouseenter(function() {
  $(this).hide();
});

$('.leaflet-marker-icon').mouseleave(function() {
  $(this).delay(1000).show(0);
});
于 2014-03-25T16:11:14.740 回答