-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to finish a measure over the top of a layer #8
Comments
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? 🤔 |
@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. |
Agreed, sounds tricky 😬 We almost need an Any pointers that I could experiment with? |
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 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;
});
}, |
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 :) |
@ping-spike you are welcome 😄 |
If you have any layers displayed on the map, you can start a measure to the left of the layer (eg. polygon) and end it beyond the polygon, but you can not end the measurement ON the polygon.
The text was updated successfully, but these errors were encountered: