Comments (8)
@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.
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.
@ping-spike you are welcome 😄
from leaflet.measure.
Example of measure working ok if you go beyond a layer:
from leaflet.measure.
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:
from leaflet.measure.
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.
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leaflet.measure.