Skip to content

Commit

Permalink
don't stop animation on map resize (#6636)
Browse files Browse the repository at this point in the history
fix #4041
fix #4481
  • Loading branch information
andrewharvey authored and ansis committed Jun 27, 2018
1 parent 8be1075 commit 47be75c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/ui/bind_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ export default function bindHandlers(map: Map, options: {interactive: boolean, c
}

function onWheel(e: WheelEvent) {
if (options.interactive) {
map.stop();
}

const mapEvent = new MapWheelEvent('wheel', map, e);
map.fire(mapEvent);

Expand Down
7 changes: 4 additions & 3 deletions src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,12 @@ class Map extends Camera {
this.transform.resize(width, height);
this.painter.resize(width, height);

return this
.fire(new Event('movestart', eventData))
this.fire(new Event('movestart', eventData))
.fire(new Event('move', eventData))
.fire(new Event('resize', eventData))
.fire(new Event('moveend', eventData));

return this;
}

/**
Expand Down Expand Up @@ -1741,7 +1742,7 @@ class Map extends Camera {

_onWindowResize() {
if (this._trackResize) {
this.stop().resize()._update();
this.resize()._update();
}
}

Expand Down
17 changes: 15 additions & 2 deletions test/unit/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,11 @@ test('Map', (t) => {
t.test('do resize if trackResize is true (default)', (t) => {
const map = createMap(t);

t.spy(map, 'stop');
t.spy(map, '_update');
t.spy(map, 'resize');

map._onWindowResize();

t.ok(map.stop.called);
t.ok(map._update.called);
t.ok(map.resize.called);

Expand Down Expand Up @@ -1447,6 +1445,21 @@ test('Map', (t) => {
t.end();
});

t.test('continues camera animation on resize', (t) => {
const map = createMap(t),
container = map.getContainer();

map.flyTo({ center: [200, 0], duration: 100 });

Object.defineProperty(container, 'offsetWidth', {value: 250});
Object.defineProperty(container, 'offsetHeight', {value: 250});
map.resize();

t.ok(map.isMoving(), 'map is still moving after resize due to camera animation');

t.end();
});

t.end();
});

Expand Down

0 comments on commit 47be75c

Please sign in to comment.