(function(e){functionr(e,t){if(!t.steps)thrownewError("steps option missing");this.options=t,this.running=!1,this._tick=this._tick.bind(this),this._t0=+(newDate),this.callback=e,this._time=0,_.defaults(this.options,{animationDelay:0,maxDelta:.2,loop:!0}),this.rescale()}e.torque=e.torque||{};vart=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||function(e){setTimeout(e,16)},n=window.requestAnimationFrame||window.mozCancelAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||function(e){};r.prototype={start:function(){this.running=!0,t(this._tick)},isRunning:function(){returnthis.running},stop:function(){this.pause(),this.time(0)},time:function(e){if(!arguments.length)returnthis._time;this._time=e;vart=this.range(this.domain(this._time));this.callback(t)},toggle:function(){this.running?this.pause():this.start()},rescale:function(){returnthis.domainInv=torque.math.linear(this.options.animationDelay,this.options.animationDelay+this.options.animationDuration),this.domain=this.domainInv.invert(),this.range=torque.math.linear(0,this.options.steps),this.rangeInv=this.range.invert(),this.time(this._time),this},duration:function(e){returnarguments.length?(this.options.animationDuration=e,this.time()>e&&this.time(0),this.rescale(),this):this.options.animationDuration},steps:function(e){returnthis.options.steps=e,this.rescale()},step:function(e){if(arguments.length===0)returnthis.range(this.domain(this._time));this._time=this.domainInv(this.rangeInv(e))},pause:function(){this.running=!1,n(this._tick)},_tick:function(){vare=+(newDate),n=(e-this._t0)*.001;n=Math.min(this.options.maxDelta,n),this._t0=e,this._time+=n,this.time(this._time),this.step()>=this.options.steps&&(this._time=0),this.running&&t(this._tick)}},e.torque.Animator=r})(typeofexports=="undefined"?this:exports),function(e){e.torque=e.torque||{};vart={version:"1.0.0",style:{"comp-op":{css:"comp-op","default-value":"src-over","default-meaning":"add the current layer on top of other layers",doc:"Composite operation. This defines how this layer should behave relative to layers atop or below it.",type:["src","src-over","dst-over","src-in","dst-in","src-out","dst-out","src-atop","dst-atop","xor","darken","lighten"]}},layer:{"buffer-size":{"default-value":"0",type:"float","default-meaning":"No buffer will be used",doc:"Extra tolerance around the Layer extent (in pixels) used to when querying and (potentially) clipping the layer data during rendering"},"-torque-frame-count":{css:"-torque-frame-count","default-value":"128",type:"number","default-meaning":"the data is broken into 128 time frames",doc:"Number of animation steps/frames used in the animation. If the data contains a fewere number of total frames, the lesser value will be used."},"-torque-resolution":{css:"-torque-resolution","default-value":"2",type:"number","default-meaning":"",doc:"Spatial resolution in pixels. A resolution of 1 means no spatial aggregation of the data. Any other resolution of N results in spatial aggregation into cells of NxN pixels. The value N must be power of 2"},"-torque-animation-duration":{css:"-torque-animation-duration","default-value":"30",type:"number","default-meaning":"the animation lasts 30 seconds",doc:"Animation duration in seconds"},"-torque-aggregation-function":{css:"-torque-aggregation-function","default-value":"count(cartodb_id)",type:"string","default-meaning":"the value for each cell is the count of points in that cell",doc:"A function used to calculate a value from the aggregate data for each cell. See -torque-resolution"},"-torque-time-attribute":{css:"-torque-time-attribute","default-value":"time",type:"string","default-meaning":"the data column in your table that is of a time based type",doc:"The table column that contains the time information used create the animation"},"-torque-data-aggregation":{css:"-torque-data-aggregation","default-value":"linear",type:["cumulative"],"default-meaning":"previous values are discarded",doc:"Alinearanimation
.on({zoomend:this._resumeOnZoom},this),L.CanvasLayer.prototype.onAdd.call(this,e)},onRemove:function(e){this._removeTileLoader(),e.off({zoomend:this._clearCaches,zoomstart:this._pauseOnZoom},this),e.off({zoomend:this._resumeOnZoom},this),L.CanvasLayer.prototype.onRemove.call(this,e)},_pauseOnZoom:function(){this.wasRunning=this.isRunning(),this.wasRunning&&this.pause()},_resumeOnZoom:function(){this.wasRunning&&this.play()},hide:function(){returnthis.hidden?this:(this.pause(),this.clear(),this.hidden=!0,this)},show:function(){returnthis.hidden?(this.hidden=!1,this.play(),this):this},setSQL:function(e){if(!this.provider||!this.provider.setSQL)thrownewError("this provider does not support SQL");returnthis.provider.setSQL(e),this._reloadTiles(),this},setBlendMode:function(e){this.renderer.setBlendMode(e),this.redraw()},setSteps:function(e){this.provider.setSteps(e),this._reloadTiles()},setColumn:function(e,t){this.provider.setColumn(e,t),this._reloadTiles()},getTimeBounds:function(){returnthis.provider&&this.provider.getKeySpan()},clear:function(){vare=this.getCanvas();e.width=e.width},render:function(){if(this.hidden)return;vare,t,n,r=this.getCanvas();r.width=r.width;vari=r.getContext("2d");for(einthis._tiles)t=this._tiles[e],t&&(this.animator.isRunning()&&(t._tileCache=null),n=this.getTilePos(t.coord),i.setTransform(1,0,0,1,n.x,n.y),t._tileCache?this.renderer._ctx.drawImage(t._tileCache,0,0):this.renderer.renderTile(t,this.key));if(!this.animator.isRunning()&&this.key===this.prevRenderedKey){vars=this.renderer.TILE_SIZE;for(einthis._tiles){t=this._tiles[e];if(t&&!t._tileCache){varo=t._tileCache=document.createElement("canvas");o.width=o.height=s,n=this.getTilePos(t.coord),o.getContext("2d").drawImage(this.getCanvas(),n.x,n.y,s,s,0,0,s,s)}}}this.prevRenderedKey=this.key},setKey:function(e,t){this.key=e,this.animator.step(e),this._clearTileCaches(),this.redraw(t&&t.direct),this.fire("change:time",{time:this.getTime(),step:this.key})},setStep:function(e){if(e===undefined||e.length!==undefined)thrownewError("setTime only accept scalars");this.setKey(e)},stepToTime:function(e){vart=this.provider.getKeySpan(),n=t.start+(t.end-t.start)*(e/this.provider.getSteps());returnnewDate(n)},getStep:function(){returnthis.key},getTime:function(){returnthis.stepToTime(this.key)},getTimeSpan:function(){vare=this.provider.getKeySpan()},setCartoCSS:function(e){if(!this.renderer)thrownewError("renderer is not valid");vart=(newcarto.RendererJS).render(e);this.renderer.setShader(t);varn=torque.common.TorqueLayer.optionsFromLayer(t.findLayer({name:"Map"}));returnthis.provider.setCartoCSS&&this.provider.setCartoCSS(e),this.provider.setOptions(n)&&this._reloadTiles(),_.extend(this.options,n),n.animationDuration&&this.animator.duration(n.animationDuration),this.redraw(),this},getActivePointsBBox:function(e){vart=[];for(varninthis._tiles){varr=this._tiles[n];t=t.concat(this.renderer.getActivePointsBBox(r,e))}returnt},getValueForPos:function(e,t,n){n=n===undefined?this.key:n;varr,i,s,o=null,u,a;for(rinthis._tiles){i=this._tiles[r],s=this.getTilePos(i.coord),u=e-s.x,a=t-s.y,u>=0&&a>=0&&u<this.renderer.TILE_SIZE&&a<=this.renderer.TILE_SIZE&&(o=this.renderer.getValueFor(i,n,u,a));if(o!==null)returno}returnnull}}));