From 1ae6921e531feb9b9e4db3f4d331a5a8b1beeb33 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 13 Nov 2016 11:05:04 -0700 Subject: [PATCH 1/2] Make view.setHint() trigger change --- src/ol/view.js | 1 + test/spec/ol/view.test.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/ol/view.js b/src/ol/view.js index 6155efd98c..0f6fdd1eea 100644 --- a/src/ol/view.js +++ b/src/ol/view.js @@ -826,6 +826,7 @@ ol.View.prototype.setHint = function(hint, delta) { this.hints_[hint] += delta; ol.DEBUG && console.assert(this.hints_[hint] >= 0, 'Hint at %s must be positive, was %s', hint, this.hints_[hint]); + this.changed(); return this.hints_[hint]; }; diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index 2f97a6547d..2301a7c124 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -301,6 +301,35 @@ describe('ol.View', function() { }); + describe('#setHint()', function() { + + it('changes a view hint', function() { + var view = new ol.View({ + center: [0, 0], + zoom: 0 + }); + + expect(view.getHints()).to.eql([0, 0]); + + view.setHint(ol.View.Hint.INTERACTING, 1); + expect(view.getHints()).to.eql([0, 1]); + }); + + it('triggers the change event', function(done) { + var view = new ol.View({ + center: [0, 0], + zoom: 0 + }); + + view.on('change', function() { + expect(view.getHints()).to.eql([0, 1]); + done(); + }); + view.setHint(ol.View.Hint.INTERACTING, 1); + }); + + }); + describe('#animate()', function() { var originalRequestAnimationFrame = window.requestAnimationFrame; From 8401d22f28061ab89a9e57f77c647902b9269593 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 13 Nov 2016 11:11:05 -0700 Subject: [PATCH 2/2] Setting a view hint triggers change --- src/ol/interaction/dragpan.js | 3 --- src/ol/interaction/mousewheelzoom.js | 1 - src/ol/interaction/pinchrotate.js | 1 - src/ol/interaction/pinchzoom.js | 1 - src/ol/view.js | 1 - 5 files changed, 7 deletions(-) diff --git a/src/ol/interaction/dragpan.js b/src/ol/interaction/dragpan.js index a8f51e7e82..9e8b52d979 100644 --- a/src/ol/interaction/dragpan.js +++ b/src/ol/interaction/dragpan.js @@ -110,9 +110,6 @@ ol.interaction.DragPan.handleUpEvent_ = function(mapBrowserEvent) { duration: 500, easing: ol.easing.easeOut }); - } else { - // the view is not updated, force a render - map.render(); } view.setHint(ol.View.Hint.INTERACTING, -1); return false; diff --git a/src/ol/interaction/mousewheelzoom.js b/src/ol/interaction/mousewheelzoom.js index 6de7da4c1e..6b74cd1acd 100644 --- a/src/ol/interaction/mousewheelzoom.js +++ b/src/ol/interaction/mousewheelzoom.js @@ -223,7 +223,6 @@ ol.interaction.MouseWheelZoom.prototype.decrementInteractingHint_ = function() { this.trackpadTimeoutId_ = undefined; var view = this.getMap().getView(); view.setHint(ol.View.Hint.INTERACTING, -1); - view.changed(); // notify listeners of the hint change }; diff --git a/src/ol/interaction/pinchrotate.js b/src/ol/interaction/pinchrotate.js index fec785c726..3d3188ded7 100644 --- a/src/ol/interaction/pinchrotate.js +++ b/src/ol/interaction/pinchrotate.js @@ -157,7 +157,6 @@ ol.interaction.PinchRotate.handleDownEvent_ = function(mapBrowserEvent) { if (!this.handlingDownUpSequence) { map.getView().setHint(ol.View.Hint.INTERACTING, 1); } - map.render(); return true; } else { return false; diff --git a/src/ol/interaction/pinchzoom.js b/src/ol/interaction/pinchzoom.js index af625df117..ac0bc45f3a 100644 --- a/src/ol/interaction/pinchzoom.js +++ b/src/ol/interaction/pinchzoom.js @@ -140,7 +140,6 @@ ol.interaction.PinchZoom.handleDownEvent_ = function(mapBrowserEvent) { if (!this.handlingDownUpSequence) { map.getView().setHint(ol.View.Hint.INTERACTING, 1); } - map.render(); return true; } else { return false; diff --git a/src/ol/view.js b/src/ol/view.js index 0f6fdd1eea..5b5ef4550f 100644 --- a/src/ol/view.js +++ b/src/ol/view.js @@ -280,7 +280,6 @@ ol.View.prototype.cancelAnimations = function() { } } this.animations_.length = 0; - this.changed(); // notify that the hint changed }; /**