From 97b3ff049945973bb86cc3d79e76bbe7b9ae2cc3 Mon Sep 17 00:00:00 2001 From: Michel Beaudouin-Lafon Date: Mon, 1 May 2017 14:09:44 +0200 Subject: [PATCH 1/2] Added View#getInteracting() to the api, similar to View#getAnimating() to access the hints --- src/ol/view.js | 10 ++++++++++ test/spec/ol/view.test.js | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/ol/view.js b/src/ol/view.js index 333efca9f4..1a5b19377d 100644 --- a/src/ol/view.js +++ b/src/ol/view.js @@ -317,6 +317,16 @@ ol.View.prototype.getAnimating = function() { }; +/** + * Determine if the user is interacting with the view, such as panning or zooming. + * @return {boolean} The view is being interacted with. + * @api + */ +ol.View.prototype.getInteracting = function() { + return this.getHints()[ol.ViewHint.INTERACTING] > 0; +}; + + /** * Cancel any ongoing animations. * @api diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index cf06ec2fea..138c4b9ad5 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -310,9 +310,11 @@ describe('ol.View', function() { }); expect(view.getHints()).to.eql([0, 0]); + expect(view.getInteracting()).to.eql(0); view.setHint(ol.ViewHint.INTERACTING, 1); expect(view.getHints()).to.eql([0, 1]); + expect(view.getInteracting()).to.eql(1); }); it('triggers the change event', function(done) { @@ -323,6 +325,7 @@ describe('ol.View', function() { view.on('change', function() { expect(view.getHints()).to.eql([0, 1]); + expect(view.getInteracting()).to.eql(1); done(); }); view.setHint(ol.ViewHint.INTERACTING, 1); From 944f0df981e7b590b8e21d428ae78292419a6f50 Mon Sep 17 00:00:00 2001 From: Michel Beaudouin-Lafon Date: Mon, 1 May 2017 17:09:27 +0200 Subject: [PATCH 2/2] Fixed test to compare to true/false rather than 0/1 --- test/spec/ol/view.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index 138c4b9ad5..255bc0a6d5 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -310,11 +310,11 @@ describe('ol.View', function() { }); expect(view.getHints()).to.eql([0, 0]); - expect(view.getInteracting()).to.eql(0); + expect(view.getInteracting()).to.eql(false); view.setHint(ol.ViewHint.INTERACTING, 1); expect(view.getHints()).to.eql([0, 1]); - expect(view.getInteracting()).to.eql(1); + expect(view.getInteracting()).to.eql(true); }); it('triggers the change event', function(done) { @@ -325,7 +325,7 @@ describe('ol.View', function() { view.on('change', function() { expect(view.getHints()).to.eql([0, 1]); - expect(view.getInteracting()).to.eql(1); + expect(view.getInteracting()).to.eql(true); done(); }); view.setHint(ol.ViewHint.INTERACTING, 1);