I have a simple Leaflet
map to which I've added two functionalities:
-
measure tool using leaflet.measure plugin;
-
WMS getFeatureInfo popup using the L.TileLayer.BetterWMS plugin;
The default map behaviour in this context shows both popups – measure popup
and info popup
.
Screenshot:
I have added the code to jsFiddle.
So my question is:
How can I prevent the info popup from showing up while using the measure tool?
Edit
I managed to disable the popup by using
$( ".leaflet-control-measure" ).click(function() {
map.off('click', layer.getFeatureInfo, layer);
});
but now I need to turn them back on. I tried using jQuery toggle()
, but something weird happens to the measure button.
$(".leaflet-control-measure").toggle(function() {
map.off('click', layer.getFeatureInfo, layer);
} , function() {
map.on('click', layer.getFeatureInfo, layer);
});
Best Answer
IvanSanchez's answer got me on the right track. The
L.TileLayer.BetterWMS
plugin uses the following methods to enable/disable thegetFeatureInfo
popups:So I had to toggle between these two states. I managed to do that by binding a click event on the
leaflet-control-measure
button:I used the
oddClick
approach because apparently the jQuery.toggle()
has been deprecated.jsFiddle here.