문제

I have to add custom cities name with a circleMarker en my map. But I want to clic throu the label because a have polygone under it There is my JS code thats add the circleMarker

var ville_label = new L.CircleMarker(
    [lat, lng], 
    { clickable: false, radius: (1/zoom)*12 }
).bindLabel(lib, { noHide: true, className: "leaflet-ville-label" })
.addTo(ville_layer);

In CSS I have disable the pointer event

.leaflet-ville-label {
    pointer-events: none;
}

But IE doesn't supprot pointer-events and the Label is a div element and not a SVG.

Somebody have a solution to disable pointer events on the static Label ?

도움이 되었습니까?

해결책 3

I have found a solution but not like I think first.

I use a mapbox lib call leaflet-pip

The procedure in detail :

  • check click event on all my labels
  • do not triger click after map drag (i already had noclick on drag start)
  • get the mouse Lat Lng with mouseEventToLatLng(e)
  • get the polygon with this lat lng
  • and finaly trigger click on the result polygon

There is my code to accomplish this :

$(".leaflet-ville-label").off("click").on("click", function(e) {
    if ($(this).hasClass("noclick")) {
        $(".leaflet-ville-label").removeClass("noclick");
        return;
    }
    for (layer_id in kml_layer._layers) {
        var under_layer = leafletPip.pointInLayer(france.mouseEventToLatLng(e), kml_layer._layers[layer_id]);
        if (under_layer.length > 0) {
            under_layer[0].fire("click");
        }
    }
});

다른 팁

Forwarding Mouse Events Through Layers might help you solve this issue. It is kinda workaround for the lack of the pointer-event in ie. Here is a nice blog entry on this issue:

Forwarding Mouse Events Through Layers

You don't need to do more than this.

As explained in Click through a DIV to underlying elements , IE 9 and 10 will forward events as long as the background of the label is transparent. IE 11 and other browsers adhere to

.leaflet-ville-label {
    pointer-events:none;
}

See http://jsfiddle.net/LHL82/7/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top