Skip to content

Commit

Permalink
Ensure drag handlers request render frames on move (#6068) (#6073)
Browse files Browse the repository at this point in the history
Closes #6063

Caused by #6005 because,
after that change, the drag handlers relied on the `move` event to
trigger a map rerender to pick up the next batch of mouse movements.

This worked fine while dragging was in progress, but after the user
paused and the render frame triggered by the last `move` event was
complete, there was nothing to re-initiate the render loop once the
mouse moved again.
  • Loading branch information
anandthakker authored Jan 29, 2018
1 parent d81d4fb commit de593c8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ui/handler/drag_pan.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class DragPanHandler {

this._map._startAnimation(this._onDragFrame, this._onDragFinished);
}

// ensure a new render frame is scheduled
this._map._update();
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/ui/handler/drag_rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ class DragRotateHandler {

this._map._startAnimation(this._onDragFrame, this._onDragFinished);
}

// ensure a new render frame is scheduled
this._map._update();
}

_onUp(e: MouseEvent | FocusEvent) {
Expand Down
34 changes: 34 additions & 0 deletions test/unit/ui/handler/drag_pan.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const test = require('mapbox-gl-js-test').test;
const util = require('../../../../src/util/util');
const window = require('../../../../src/util/window');
const Map = require('../../../../src/ui/map');
const DOM = require('../../../../src/util/dom');
const simulate = require('mapbox-gl-js-test/simulate_interaction');

function createMap(options) {
return new Map(util.extend({
container: DOM.create('div', '', window.document.body),
style: {
"version": 8,
"sources": {},
"layers": []
}
}, options));
}

test('DragPanHandler requests a new render frame after each mousemove event', (t) => {
const map = createMap();
const update = t.spy(map, '_update');

simulate.mousedown(map.getCanvas(), {bubbles: true, buttons: 2});
simulate.mousemove(map.getCanvas(), {bubbles: true, buttons: 2});
t.ok(update.callCount > 0);

// https://github.com/mapbox/mapbox-gl-js/issues/6063
update.reset();
simulate.mousemove(map.getCanvas(), {bubbles: true, buttons: 2});
t.equal(update.callCount, 1);
t.end();
});
15 changes: 15 additions & 0 deletions test/unit/ui/handler/drag_rotate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ function createMap(options) {
}, options));
}

test('DragRotateHandler requests a new render frame after each mousemove event', (t) => {
const map = createMap();
const update = t.spy(map, '_update');

simulate.mousedown(map.getCanvas(), {bubbles: true, buttons: 2, button: 2});
simulate.mousemove(map.getCanvas(), {bubbles: true, buttons: 2});
t.ok(update.callCount > 0);

// https://github.com/mapbox/mapbox-gl-js/issues/6063
update.reset();
simulate.mousemove(map.getCanvas(), {bubbles: true, buttons: 2});
t.equal(update.callCount, 1);
t.end();
});

test('DragRotateHandler rotates in response to a right-click drag', (t) => {
const map = createMap();

Expand Down

0 comments on commit de593c8

Please sign in to comment.