[GIS] Disable Leaflet WMS getFeatureInfo popup while using the Measure tool

getfeatureinfoleafletmapcontrolwms

I have a simple Leaflet map to which I've added two functionalities:

The default map behaviour in this context shows both popups – measure popup and info popup.
Screenshot:

enter image description here

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 the getFeatureInfo popups:

  onAdd: function (map) {
    ...
    map.on('click', this.getFeatureInfo, this);
  },

  onRemove: function (map) {
    ...
    map.off('click', this.getFeatureInfo, this);
  },

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:

$(".leaflet-control-measure").click(function() {
  var oddClick = $(this).data("oddClick");
  $(this).data("oddClick", !oddClick);
  if (!oddClick) {
    map.off('click', layer.getFeatureInfo, layer);
  } else {
    map.on('click', layer.getFeatureInfo, layer);
  }
});

I used the oddClick approach because apparently the jQuery .toggle() has been deprecated.

jsFiddle here.