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

don't stop animation on map resize #6636

Merged
merged 4 commits into from
Jun 27, 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
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();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this related to the resize fix or something separate?
No need to split it out if it's separate, I'm just wondering if I'm missing a relation between this and the resize bug.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I needed this so that scrolling on the map cancelled an active flyTo.

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