Skip to content
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

Fix canvas not filtering click event after drag #4493

Merged
merged 2 commits into from
Jun 1, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Do not add canvas layers to click event targets if just dragged (fix #…
  • Loading branch information
yohanboniface committed Apr 23, 2016
commit 8ca2666c7a69d95dcd25a6782725f965d621b87e
28 changes: 28 additions & 0 deletions spec/suites/layer/vector/CanvasSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,34 @@ describe('Canvas', function () {
layer.off();
});

it("should not fire click when dragging the map on top of it", function (done) {
var downSpy = sinon.spy();
var clickSpy = sinon.spy();
var preclickSpy = sinon.spy();
layer.on('click', clickSpy);
layer.on('preclick', preclickSpy);
layer.on('mousedown', downSpy);
var hand = new Hand({
timing: 'fastframe',
onStop: function () {
// Prosthetic does not fire a click when we down+up, but it real world
// browsers would, so let's simulate it.
happen.at('click', 70, 60);
expect(downSpy.called).to.be(true);
expect(clickSpy.called).to.be(false);
expect(preclickSpy.called).to.be(false);
layer.off();
done();
}
});
var mouse = hand.growFinger('mouse');

// We move 5 pixels first to overcome the 3-pixel threshold of
// L.Draggable.
mouse.moveTo(50, 50, 0)
.down().moveBy(20, 10, 200).up();
});

});

describe("#events(interactive=false)", function () {
Expand Down
2 changes: 1 addition & 1 deletion src/layer/vector/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ L.Canvas = L.Renderer.extend({

for (var id in this._layers) {
layer = this._layers[id];
if (layer.options.interactive && layer._containsPoint(point)) {
if (layer.options.interactive && layer._containsPoint(point) && !this._map._draggableMoved(layer)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be possible to just remove the click listener while the map is dragged? I guess that would make it a bit clearer what's going on, and make it less coupled with Map's internals.

L.DomEvent._fakeStop(e);
layers.push(layer);
}
Expand Down