Skip to content

Commit

Permalink
Smooth zoom on scroll (#1288)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress authored Jan 11, 2021
1 parent a830ba1 commit 53390c9
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/utils/map-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import MapState from './map-state';
import {LinearInterpolator} from './transition';
import TransitionManager, {TRANSITION_EVENTS} from './transition-manager';
import debounce from './debounce';

const NO_TRANSITION_PROPS = {
transitionDuration: 0
Expand Down Expand Up @@ -68,7 +67,6 @@ export default class MapController {

constructor() {
this.handleEvent = this.handleEvent.bind(this);
this._onWheelEnd = debounce(this._onWheelEnd, 100);
}

/**
Expand Down Expand Up @@ -315,16 +313,16 @@ export default class MapController {
}

const newMapState = this.mapState.zoom({pos, scale});
this.updateViewport(newMapState, NO_TRANSITION_PROPS, {isZooming: true});
// Wheel events are discrete, let's wait a little before resetting isZooming
this._onWheelEnd();
this.updateViewport(
newMapState,
Object.assign({}, LINEAR_TRANSITION_PROPS, {
transitionInterpolator: new LinearInterpolator({around: pos})
}),
{isZooming: true}
);
return true;
}

_onWheelEnd() {
this.setState({isZooming: false});
}

// Default handler for the `pinchstart` event.
_onPinchStart(event) {
const pos = this.getCenter(event);
Expand Down

0 comments on commit 53390c9

Please sign in to comment.