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

Backport ensure drag handlers request render frames on move (#6068) #6073

Merged
merged 1 commit into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
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