openlayers / ol2

OpenLayers v2 - deprecated!
Other
1.47k stars 770 forks source link

Handler.MouseWheel: wrong zooming with cumulative, interval, maxDelta #1274

Open ukiz opened 10 years ago

ukiz commented 10 years ago

Set up MouseWheel with {cumulative: true, interval: 50, maxDelta: 4}. When zooming with mouse wheel with a delta=5, the map eventually zooms with a delta=1 (while it should zoom with delta=maxDelta). Actually, zoomTo is called twice, first with delta=4 (as it should), then with delta=1 (from initial zoom level).

This can be observed in http://openlayers.org/dev/examples/mousewheel-interval.html - make sure to uncheck and then check again the cumulative option, as cumulative=false by default (so the example page shows wrong state initially) and then try to zoom with mouse wheel with a delta=7 - the map zooms in correctly first, but then back out.

Here is a solution that works for me: Handler.MouseWheel.js, line 190:

if(this.interval && Math.abs(this.delta) < this.maxDelta) {

replace with:

if(this.interval) {
fbuchinger commented 10 years ago

Wouldn't this change break the maxDelta functionality? (trigger a zoom for a large mousewheel movement even if the scroll timeout interval is still active).

ukiz commented 10 years ago

The only change in the functionality is that - for a large mousewheel movement - instead of an immediate wheelZoom, another timeout interval is issued (so it will never break from the timeout interval). This behaviour seems ok to me, as long as it limits the maximum delta returned from the handler, which I see as the most important purpose of maxDelta.