Giter VIP home page Giter VIP logo

Comments (8)

aprilandjan avatar aprilandjan commented on June 19, 2024 1

@ping-spike hi, thanks for your feedback!

It seems that once we add popup to the layer/polygon, the click on it will be captured first and stops further event propagation, thus makes the measure layer cannot get the click event to draw line (Leaflet/Leaflet#765).

How ever, we can bypass that though some tricky methods. For example, when start measuring, loop through all layers and remove their click event handlers to prevent them from responding to click; and then, after finish measuring, we add back their click event handlers to keep its original behavior.

from leaflet.measure.

aprilandjan avatar aprilandjan commented on June 19, 2024 1

I wrote some experimental code in branch [feat/disable-other-clicks-while-measuring] (https://github.com/aprilandjan/leaflet.measure/tree/feat/disable-other-clicks-while-measuring), add an option disableOtherClicksWhileMeasuring to implement that, please have a try.

Here's the tricky:

  //  the cached clicks for other layers
  _cachedClicks: [],

  //  try to remove click event handlers of other layers
  _removeOtherLayersClicks: function (layer) {
    if (layer === this._layerPaint) {
      return;
    }
    var loop = function (childLayer) {
      if (childLayer._events && childLayer._events.click) {
        this._cachedClicks.push({
          layer: childLayer,
          click: childLayer._events.click,
        });
        childLayer._events.click = undefined;
      }
      if (childLayer.eachLayer) {
        this._removeOtherLayersClicks(childLayer);
      }
    }.bind(this);
    layer.eachLayer(loop);
  },

  //  try to bring back the click event handlers
  _addOtherLayersClicks: function () {
    this._cachedClicks.forEach(function (cached) {
      var layer = cached.layer;
      var click = cached.click;
      layer._events.click = click;
    });
  },

from leaflet.measure.

aprilandjan avatar aprilandjan commented on June 19, 2024 1

@ping-spike you are welcome 😄

from leaflet.measure.

ping-spike avatar ping-spike commented on June 19, 2024

Example of measure working ok if you go beyond a layer:

Screen Shot 2020-08-18 at 20 12 44

from leaflet.measure.

ping-spike avatar ping-spike commented on June 19, 2024

But if you try to click on the layer / polygon area to end the measure, instead of ending the measure the info balloon appears for that map layer / polygon:

Screen Shot 2020-08-18 at 20 13 36

from leaflet.measure.

ping-spike avatar ping-spike commented on June 19, 2024

Is there a way to disable clicks on visible layers when the measure tool is turned on, then re-enable clicks on the layers when it is turned off again? 🤔

from leaflet.measure.

ping-spike avatar ping-spike commented on June 19, 2024

Agreed, sounds tricky 😬

We almost need an interactive: false being applied to each active layer 🤔

Any pointers that I could experiment with?

from leaflet.measure.

ping-spike avatar ping-spike commented on June 19, 2024

Amazing work!

Tested and seems to work perfectly 👏

If I'm mid-measure and zoom the map in or out it seems to re-enable the layer clickability again. But hey, that's a minor.

This is fantastic, thanks for the seriously quick response times :)

from leaflet.measure.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.