From c7a57998814acd30a017d76272bad44703546a8b Mon Sep 17 00:00:00 2001 From: javi Date: Fri, 21 Mar 2014 15:56:38 +0100 Subject: [PATCH] pause on zoom --- lib/torque/leaflet/torque.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/torque/leaflet/torque.js b/lib/torque/leaflet/torque.js index 954b739..470f4b2 100644 --- a/lib/torque/leaflet/torque.js +++ b/lib/torque/leaflet/torque.js @@ -88,7 +88,12 @@ L.TorqueLayer = L.CanvasLayer.extend({ onAdd: function (map) { map.on({ - 'zoomend': this._clearCaches + 'zoomend': this._clearCaches, + 'zoomstart': this._pauseOnZoom, + }, this); + + map.on({ + 'zoomend': this._resumeOnZoom }, this); L.CanvasLayer.prototype.onAdd.call(this, map); }, @@ -96,11 +101,28 @@ L.TorqueLayer = L.CanvasLayer.extend({ onRemove: function(map) { this._removeTileLoader(); map.off({ - 'zoomend': this._clearCaches + 'zoomend': this._clearCaches, + 'zoomstart': this._pauseOnZoom, + }, this); + map.off({ + 'zoomend': this._resumeOnZoom }, this); L.CanvasLayer.prototype.onRemove.call(this, map); }, + _pauseOnZoom: function() { + this.wasRunning = this.isRunning(); + if (this.wasRunning) { + this.pause(); + } + }, + + _resumeOnZoom: function() { + if (this.wasRunning) { + this.play(); + } + }, + hide: function() { if(this.hidden) return this; this.pause();