From 5b85f8ecc993367e1a1fb476b6278fed3fda255a Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 13 Nov 2016 10:25:20 -0700 Subject: [PATCH 1/2] Render on view changes --- src/ol/map.js | 14 +++++++++++++- test/spec/ol/map.test.js | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/ol/map.js b/src/ol/map.js index 91ef5674ee..fe14b3aed9 100644 --- a/src/ol/map.js +++ b/src/ol/map.js @@ -216,6 +216,12 @@ ol.Map = function(options) { */ this.viewPropertyListenerKey_ = null; + /** + * @private + * @type {?ol.EventsKey} + */ + this.viewChangeListenerKey_ = null; + /** * @private * @type {Array.} @@ -1102,11 +1108,18 @@ ol.Map.prototype.handleViewChanged_ = function() { ol.events.unlistenByKey(this.viewPropertyListenerKey_); this.viewPropertyListenerKey_ = null; } + if (this.viewChangeListenerKey_) { + ol.events.unlistenByKey(this.viewChangeListenerKey_); + this.viewChangeListenerKey_ = null; + } var view = this.getView(); if (view) { this.viewPropertyListenerKey_ = ol.events.listen( view, ol.ObjectEventType.PROPERTYCHANGE, this.handleViewPropertyChanged_, this); + this.viewChangeListenerKey_ = ol.events.listen( + view, ol.events.EventType.CHANGE, + this.handleViewPropertyChanged_, this); } this.render(); }; @@ -1221,7 +1234,6 @@ ol.Map.prototype.removeOverlay = function(overlay) { * @private */ ol.Map.prototype.renderFrame_ = function(time) { - var i, ii, viewState; var size = this.getSize(); diff --git a/test/spec/ol/map.test.js b/test/spec/ol/map.test.js index f92a44b6e2..f2cc852f38 100644 --- a/test/spec/ol/map.test.js +++ b/test/spec/ol/map.test.js @@ -160,6 +160,23 @@ describe('ol.Map', function() { document.body.removeChild(target); }); + it('is called when the view.changed() is called', function() { + var view = map.getView(); + + var spy = sinon.spy(map, 'render'); + view.changed(); + expect(spy.callCount).to.be(1); + }); + + it('is not called on view changes after the view has been removed', function() { + var view = map.getView(); + map.setView(null); + + var spy = sinon.spy(map, 'render'); + view.changed(); + expect(spy.callCount).to.be(0); + }); + it('calls renderFrame_ and results in an postrender event', function(done) { var spy = sinon.spy(map, 'renderFrame_'); From 0ac620c817f5628bc30da58c8f95f93ba01cef78 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 13 Nov 2016 10:25:45 -0700 Subject: [PATCH 2/2] Set interacting hint during trackpad scroll --- src/ol/interaction/mousewheelzoom.js | 32 +++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/ol/interaction/mousewheelzoom.js b/src/ol/interaction/mousewheelzoom.js index 04acd0388d..6de7da4c1e 100644 --- a/src/ol/interaction/mousewheelzoom.js +++ b/src/ol/interaction/mousewheelzoom.js @@ -1,6 +1,7 @@ goog.provide('ol.interaction.MouseWheelZoom'); goog.require('ol'); +goog.require('ol.View'); goog.require('ol.easing'); goog.require('ol.events.EventType'); goog.require('ol.has'); @@ -73,6 +74,18 @@ ol.interaction.MouseWheelZoom = function(opt_options) { */ this.mode_ = undefined; + /** + * Trackpad events separated by this delay will be considered separate + * interactions. + * @type {number} + */ + this.trackpadEventGap_ = 400; + + /** + * @type {number|undefined} + */ + this.trackpadTimeoutId_ = undefined; + /** * The number of delta values per zoom level * @private @@ -143,7 +156,7 @@ ol.interaction.MouseWheelZoom.handleEvent = function(mapBrowserEvent) { this.startTime_ = now; } - if (!this.mode_ || now - this.startTime_ > 400) { + if (!this.mode_ || now - this.startTime_ > this.trackpadEventGap_) { this.mode_ = Math.abs(delta) < 4 ? ol.interaction.MouseWheelZoom.Mode.TRACKPAD : ol.interaction.MouseWheelZoom.Mode.WHEEL; @@ -151,6 +164,12 @@ ol.interaction.MouseWheelZoom.handleEvent = function(mapBrowserEvent) { if (this.mode_ === ol.interaction.MouseWheelZoom.Mode.TRACKPAD) { var view = map.getView(); + if (this.trackpadTimeoutId_) { + clearTimeout(this.trackpadTimeoutId_); + } else { + view.setHint(ol.View.Hint.INTERACTING, 1); + } + this.trackpadTimeoutId_ = setTimeout(this.decrementInteractingHint_.bind(this), this.trackpadEventGap_); var resolution = view.getResolution() * Math.pow(2, delta / this.trackpadDeltaPerZoom_); var minResolution = view.getMinResolution(); var maxResolution = view.getMaxResolution(); @@ -197,6 +216,17 @@ ol.interaction.MouseWheelZoom.handleEvent = function(mapBrowserEvent) { }; +/** + * @private + */ +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 +}; + + /** * @private * @param {ol.Map} map Map.