From 4ed644feaa065b9954b9d9c7a0d66457cd09cc89 Mon Sep 17 00:00:00 2001 From: Dani Carrion Date: Tue, 23 Jun 2015 14:43:44 +0200 Subject: [PATCH] renderer and provider are loaded before options.ready is defined, to prevent them from being called before their initialization --- lib/torque/leaflet/torque.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/torque/leaflet/torque.js b/lib/torque/leaflet/torque.js index 7d2c5b7..1882773 100644 --- a/lib/torque/leaflet/torque.js +++ b/lib/torque/leaflet/torque.js @@ -66,6 +66,9 @@ L.TorqueLayer = L.CanvasLayer.extend({ this.options.renderer = this.options.renderer || 'point'; this.options.provider = this.options.provider || 'windshaft'; + this.provider = new this.providers[this.options.provider](options); + this.renderer = new this.renderers[this.options.renderer](this.getCanvas(), options); + options.ready = function() { self.fire("change:bounds", { bounds: self.provider.getBounds() @@ -78,9 +81,6 @@ L.TorqueLayer = L.CanvasLayer.extend({ self.setKey(self.key); }; - this.provider = new this.providers[this.options.provider](options); - this.renderer = new this.renderers[this.options.renderer](this.getCanvas(), options); - this.renderer.on("allIconsLoaded", this.render.bind(this)); @@ -279,7 +279,7 @@ L.TorqueLayer = L.CanvasLayer.extend({ }, /** - * helper function, does the same than ``setKey`` but only + * helper function, does the same than ``setKey`` but only * accepts scalars. */ setStep: function(time) { @@ -290,17 +290,17 @@ L.TorqueLayer = L.CanvasLayer.extend({ }, /** - * transform from animation step to Date object + * transform from animation step to Date object * that contains the animation time * - * ``step`` should be between 0 and ``steps - 1`` + * ``step`` should be between 0 and ``steps - 1`` */ stepToTime: function(step) { var times = this.provider.getKeySpan(); var time = times.start + (times.end - times.start)*(step/this.provider.getSteps()); return new Date(time); }, - + timeToStep: function(timestamp) { if (typeof timestamp === "Date") timestamp = timestamp.getTime(); if (!this.provider) return 0;