(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.torque=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i=end)throw new Error("start must be smaller than end");this.start=start;this.end=end};AnimatorStepsRange.prototype={diff:function(){return this.end-this.start},isLast:function(step){return(step|0)===this.end}};module.exports=AnimatorStepsRange},{}],2:[function(require,module,exports){(function(global){var torque=require("./");var AnimatorStepsRange=require("./animator-steps-range");var requestAnimationFrame=global.requestAnimationFrame||global.mozRequestAnimationFrame||global.webkitRequestAnimationFrame||global.msRequestAnimationFrame||function(callback){return global.setTimeout(callback,1e3/60)};var cancelAnimationFrame=global.cancelAnimationFrame||global.mozCancelAnimationFrame||global.webkitCancelAnimationFrame||global.msCancelAnimationFrame||function(id){clearTimeout(id)};function Animator(callback,options){if(!options.steps){throw new Error("steps option missing")}this.options=options;this.running=false;this._tick=this._tick.bind(this);this._t0=+new Date;this.callback=callback;this._time=0;this.itemsReady=false;this.options=torque.extend({animationDelay:0,maxDelta:.2,loop:options.loop===undefined?true:options.loop},this.options);this.steps(options.steps)}Animator.prototype={start:function(){this.running=true;requestAnimationFrame(this._tick);this.options.onStart&&this.options.onStart();if(this.stepsRange().diff()===1){this.running=false}},isRunning:function(){return this.running},stop:function(){this.pause();this.time(this.stepsRange().start);this.options.onStop&&this.options.onStop()},time:function(_){if(!arguments.length)return this._time;this._time=_;var t=this.range(this.domain(this._time));this.callback(t)},toggle:function(){if(this.running){this.pause()}else{this.start()}},rescale:function(){this.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._defaultStepsRange.end);this.rangeInv=this.range.invert();this.time(this._time);this.running?this.start():this.pause();return this},duration:function(_){if(!arguments.length)return this.options.animationDuration;this.options.animationDuration=_;if(this.time()>_){this.time(0)}this.rescale();return this},steps:function(_){this.options.steps=_;this._defaultStepsRange=new AnimatorStepsRange(0,_);return this.rescale()},stepsRange:function(start,end){if(arguments.length===2){if(startthis._defaultStepsRange.end)throw new Error("end must be within default steps range");this._customStepsRange=new AnimatorStepsRange(start,end);this.options.onStepsRange&&this.options.onStepsRange();var step=this.step()|0;if(stepend){this.step(start)}}return this._customStepsRange||this._defaultStepsRange},removeCustomStepsRange:function(){this._customStepsRange=undefined;this.options.onStepsRange&&this.options.onStepsRange()},step:function(s){if(arguments.length===0)return this.range(this.domain(this._time));this._time=this.domainInv(this.rangeInv(s))},pause:function(){this.running=false;cancelAnimationFrame(this._tick);this.options.onPause&&this.options.onPause()},_tick:function(){var t1=+new Date;var delta=(t1-this._t0)*.001;delta=Math.min(this.options.maxDelta,delta);this._t0=t1;this._time+=delta;var stepsRange=this.stepsRange();if(stepsRange.isLast(this.step())){if(!this.options.loop){this.time(this.options.animationDuration);this.pause()}else{this.step(stepsRange.start)}}if(this.running){this.time(this._time);requestAnimationFrame(this._tick)}}};module.exports=Animator}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./":11,"./animator-steps-range":1}],3:[function(require,module,exports){var _torque_reference_latest={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-clear-color":{css:"-torque-clear-color",type:"color","default-value":"rgba(255, 255, 255, 0)","default-meaning":"full clear",doc:"color used to clear canvas on each frame"},"-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:"A linear animation will discard previous values while a cumulative animation will accumulate them until it restarts"}},symbolizers:{"*":{"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"]},opacity:{css:"opacity",type:"float",doc:"An alpha value for the style (which means an alpha applied to all features in separate buffer and then composited back to main buffer)","default-value":1,"default-meaning":"no separate buffer will be used and no alpha will be applied to the style after rendering"}},trail:{steps:{css:"trail-steps",type:"float","default-value":1,"default-meaning":"no trail steps",doc:"How many steps of trails are going to be rendered"}},polygon:{fill:{css:"polygon-fill",type:"color","default-value":"rgba(128,128,128,1)","default-meaning":"gray and fully opaque (alpha = 1), same as rgb(128,128,128)",doc:"Fill color to assign to a polygon"},"fill-opacity":{css:"polygon-opacity",type:"float",doc:"The opacity of the polygon","default-value":1,"default-meaning":"opaque"}},line:{stroke:{css:"line-color","default-value":"rgba(0,0,0,1)",type:"color","default-meaning":"black and fully opaque (alpha = 1), same as rgb(0,0,0)",doc:"The color of a drawn line"},"stroke-width":{css:"line-width","default-value":1,type:"float",doc:"The width of a line in pixels"},"stroke-opacity":{css:"line-opacity","default-value":1,type:"float","default-meaning":"opaque",doc:"The opacity of a line"},"stroke-linejoin":{css:"line-join","default-value":"miter",type:["miter","round","bevel"],doc:"The behavior of lines when joining"},"stroke-linecap":{css:"line-cap","default-value":"butt",type:["butt","round","square"],doc:"The display of line endings"}},markers:{file:{css:"marker-file",doc:"An SVG file that this marker shows at each placement. If no file is given, the marker will show an ellipse.","default-value":"","default-meaning":"An ellipse or circle, if width equals height",type:"uri"},opacity:{css:"marker-opacity",doc:"The overall opacity of the marker, if set, overrides both the opacity of both the fill and stroke","default-value":1,"default-meaning":"The stroke-opacity and fill-opacity will be used",type:"float"},"fill-opacity":{css:"marker-fill-opacity",doc:"The fill opacity of the marker","default-value":1,"default-meaning":"opaque",type:"float"},stroke:{css:"marker-line-color",doc:"The color of the stroke around a marker shape.","default-value":"black",type:"color"},"stroke-width":{css:"marker-line-width",doc:"The width of the stroke around a marker shape, in pixels. This is positioned on the boundary, so high values can cover the area itself.",type:"float"},"stroke-opacity":{css:"marker-line-opacity","default-value":1,"default-meaning":"opaque",doc:"The opacity of a line",type:"float"},fill:{css:"marker-fill","default-value":"blue",doc:"The color of the area of the marker.",type:"color"},"marker-type":{css:"marker-type",type:["rectangle","ellipse"],"default-value":"ellipse",doc:"The default marker-type. If a SVG file is not given as the marker-file parameter, the renderer provides either an rectangle or an ellipse (a circle if height is equal to width)"},width:{css:"marker-width","default-value":10,doc:"The width of the marker, if using one of the default types.",type:"float"}},point:{file:{css:"point-file",type:"uri",required:false,"default-value":"none",doc:"Image file to represent a point"},opacity:{css:"point-opacity",type:"float","default-value":1,"default-meaning":"Fully opaque",doc:"A value from 0 to 1 to control the opacity of the point"}}},colors:{aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],grey:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50],transparent:[0,0,0,0]}};module.exports={version:{latest:_torque_reference_latest,"1.0.0":_torque_reference_latest}}},{}],4:[function(require,module,exports){(function(global){var carto=global.carto||require("carto");function TorqueLayer(){}TorqueLayer.prototype={};TorqueLayer.optionsFromLayer=function(mapConfig){var opts={};if(!mapConfig)return opts;var attrs={"buffer-size":"buffer-size","-torque-frame-count":"steps","-torque-resolution":"resolution","-torque-animation-duration":"animationDuration","-torque-aggregation-function":"countby","-torque-time-attribute":"column","-torque-data-aggregation":"data_aggregation"};for(var i in attrs){var v=mapConfig.eval(i);if(v!==undefined){var a=attrs[i];opts[a]=v}}return opts};TorqueLayer.optionsFromCartoCSS=function(cartocss){var shader=(new carto.RendererJS).render(cartocss);var mapConfig=shader.findLayer({name:"Map"});return TorqueLayer.optionsFromLayer(mapConfig)};module.exports.TorqueLayer=TorqueLayer}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{carto:undefined}],5:[function(require,module,exports){(function(global){var Event={};Event.on=function(evt,callback){var cb=this._evt_callbacks=this._evt_callbacks||{};var l=cb[evt]||(cb[evt]=[]);l.push(callback);return this};Event.trigger=function(evt){var c=this._evt_callbacks&&this._evt_callbacks[evt];for(var i=0;c&&imapSize){divTopLeft.x-=mapSize}this.canvas.style[CanvasLayer.CSS_TRANSFORM_]="translate("+Math.round(divTopLeft.x)+"px,"+Math.round(divTopLeft.y)+"px)";this.scheduleUpdate()};CanvasLayer.prototype.update_=function(){this.requestAnimationFrameId_=null;if(!this.isAdded_){return}if(this.isAnimated_){this.scheduleUpdate()}if(this.needsResize_&&this.resizeHandler_){this.needsResize_=false;this.resizeHandler_()}if(this.updateHandler_){this.updateHandler_()}};CanvasLayer.prototype.getTopLeft=function(){return this.topLeft_};CanvasLayer.prototype.scheduleUpdate=function(){if(this.isAdded_&&!this.requestAnimationFrameId_){this.requestAnimationFrameId_=this.requestAnimFrame_.call(window,this.requestUpdateFunction_)}};module.exports=CanvasLayer},{}],7:[function(require,module,exports){function CanvasTileLayer(canvas_setup,render){this.tileSize=new google.maps.Size(256,256);this.maxZoom=19;this.name="Tile #s";this.alt="Canvas tile layer";this.tiles={};this.canvas_setup=canvas_setup;this.render=render;if(!render){this.render=canvas_setup}}CanvasTileLayer.prototype.create_tile_canvas=function(coord,zoom,ownerDocument){var canvas=ownerDocument.createElement("canvas");var hit_canvas=ownerDocument.createElement("canvas");canvas.style.border=hit_canvas.style.border="none";canvas.style.margin=hit_canvas.style.margin="0";canvas.style.padding=hit_canvas.style.padding="0";var ctx=canvas.getContext("2d");ctx.width=canvas.width=this.tileSize.width;ctx.height=canvas.height=this.tileSize.height;var hit_ctx=hit_canvas.getContext("2d");hit_canvas.width=hit_ctx.width=this.tileSize.width;hit_canvas.height=hit_ctx.height=this.tileSize.height;var tile_id=coord.x+"_"+coord.y+"_"+zoom;canvas.setAttribute("id",tile_id);hit_canvas.setAttribute("id",tile_id);if(tile_id in this.tiles)delete this.tiles[tile_id];this.tiles[tile_id]={canvas:canvas,ctx:ctx,hit_canvas:hit_canvas,hit_ctx:hit_ctx,coord:coord,zoom:zoom,primitives:null};if(this.canvas_setup)this.canvas_setup(this.tiles[tile_id],coord,zoom);return canvas};CanvasTileLayer.prototype.each=function(callback){for(var t in this.tiles){var tile=this.tiles[t];callback(tile)}};CanvasTileLayer.prototype.recreate=function(){for(var t in this.tiles){var tile=this.tiles[t];this.canvas_setup(tile,tile.coord,tile.zoom)}};CanvasTileLayer.prototype.redraw_tile=function(tile){this.render(tile,tile.coord,tile.zoom)};CanvasTileLayer.prototype.redraw=function(){for(var t in this.tiles){var tile=this.tiles[t];this.render(tile,tile.coord,tile.zoom)}};CanvasTileLayer.prototype.getTile=function(coord,zoom,ownerDocument){return this.create_tile_canvas(coord,zoom,ownerDocument)};CanvasTileLayer.prototype.releaseTile=function(tile){var id=tile.getAttribute("id");delete this.tiles[id]};module.exports=CanvasTileLayer},{}],8:[function(require,module,exports){function GMapsTileLoader(){}GMapsTileLoader.prototype={_initTileLoader:function(map,projection){this._map=map;this._projection=projection;this._tiles={};this._tilesLoading={};this._tilesToLoad=0;this._updateTiles=this._updateTiles.bind(this);this._listeners=[];this._listeners.push(google.maps.event.addListener(this._map,"dragend",this._updateTiles),google.maps.event.addListener(this._map,"zoom_changed",this._updateTiles));this.tileSize=256;this._updateTiles()},_removeTileLoader:function(){this._listeners.forEach(function(listener){google.maps.event.removeListener(listener)});this._removeTiles()},_removeTiles:function(){for(var key in this._tiles){this._removeTile(key)}},_reloadTiles:function(){this._removeTiles();this._updateTiles()},_updateTiles:function(){if(!this._map){return}var bounds=this._map.getBounds();var zoom=this._map.getZoom();var tileSize=this.tileSize;var mzoom=1<seTilePoint.x||yseTilePoint.y){this._removeTile(key)}}}},_removeTile:function(key){this.onTileRemoved&&this.onTileRemoved(this._tiles[key]);delete this._tiles[key];delete this._tilesLoading[key]},_tileKey:function(tilePoint){return tilePoint.x+":"+tilePoint.y+":"+tilePoint.zoom},_tileShouldBeLoaded:function(tilePoint){var k=this._tileKey(tilePoint);return!(k in this._tiles)&&!(k in this._tilesLoading)},_tileLoaded:function(tilePoint,tileData){this._tilesToLoad--;var k=tilePoint.x+":"+tilePoint.y+":"+tilePoint.zoom;this._tiles[k]=tileData;delete this._tilesLoading[k];if(this._tilesToLoad===0){this.onTilesLoaded&&this.onTilesLoaded()}},getTilePos:function(tilePoint){var limit=1<=0&&yy>=0&&xx=0){this.cancelAnimationFrame.call(window,this.currentAnimationFrame)}this.currentAnimationFrame=this.requestAnimationFrame.call(window,this.render)},redraw:function(direct){var domPosition=L.DomUtil.getPosition(this._map.getPanes().mapPane);if(domPosition){L.DomUtil.setPosition(this._canvas,{x:-domPosition.x,y:-domPosition.y})}if(direct){this.render()}else{this._render()}},onResize:function(){},render:function(){throw new Error("render function should be implemented")}})},{"./leaflet_tileloader_mixin":14}],13:[function(require,module,exports){if(typeof L!=="undefined"){require("./torque")}},{"./torque":15}],14:[function(require,module,exports){L.Mixin.TileLoader={_initTileLoader:function(){this._tilesLoading={};this._tilesToLoad=0;this._map.on({moveend:this._updateTiles},this);this._updateTiles()},_removeTileLoader:function(){this._map.off({moveend:this._updateTiles},this);this._removeTiles()},_updateTiles:function(){if(!this._map){return}var bounds=this._map.getPixelBounds(),zoom=this._map.getZoom(),tileSize=this.options.tileSize;if(zoom>this.options.maxZoom||zoombounds.max.x||ybounds.max.y){this._removeTile(key)}}}},_removeTile:function(key){this.fire("tileRemoved",this._tiles[key]);delete this._tiles[key];delete this._tilesLoading[key]},_tileKey:function(tilePoint){return tilePoint.x+":"+tilePoint.y+":"+tilePoint.zoom},_tileShouldBeLoaded:function(tilePoint){var k=this._tileKey(tilePoint);return!(k in this._tiles)&&!(k in this._tilesLoading)},_tileLoaded:function(tilePoint,tileData){this._tilesToLoad--;var k=tilePoint.x+":"+tilePoint.y+":"+tilePoint.zoom;this._tiles[k]=tileData;delete this._tilesLoading[k];if(this._tilesToLoad===0){this.fire("tilesLoaded")}},getTilePos:function(tilePoint){tilePoint=new L.Point(tilePoint.x,tilePoint.y);var origin=this._map._getTopLeftPoint(this._map.getCenter()),tileSize=this.options.tileSize;return tilePoint.multiplyBy(tileSize).subtract(origin)},_addTilesFromCenterOut:function(bounds){var queue=[],center=bounds.getCenter(),zoom=this._map.getZoom();zoom=Math.round(zoom);var j,i,point;for(j=bounds.min.y;j<=bounds.max.y;j++){for(i=bounds.min.x;i<=bounds.max.x;i++){point=new L.Point(i,j);point.zoom=zoom;if(this._tileShouldBeLoaded(point)){queue.push(point)}}}var tilesToLoad=queue.length;if(tilesToLoad===0){return}queue.sort(function(a,b){return a.distanceTo(center)-b.distanceTo(center)});this._tilesToLoad+=tilesToLoad;for(i=0;i0&&h>0){c.getContext("2d").drawImage(this.getCanvas(),x,y,w,h,x-pos.x,y-pos.y,w,h)}}}}this.prevRenderedKey=this.getKey()},setKey:function(key,options){this.setKeys([key],options)},getKeys:function(){return this.keys},setKeys:function(keys,options){this.keys=keys;this.animator.step(this.getKey());this._clearTileCaches();this.redraw(options&&options.direct);this.fire("change:time",{time:this.getTime(),step:this.getKey(),start:this.getKey(),end:this.getLastKey()})},getKey:function(){return this.keys[0]},getLastKey:function(){return this.keys[this.keys.length-1]},setStep:function(time){if(time===undefined||time.length!==undefined){throw new Error("setTime only accept scalars")}this.setKey(time)},renderRange:function(start,end){this.pause();var keys=[];for(var i=start;i<=end;i++){keys.push(i)}this.setKeys(keys)},resetRenderRange:function(){this.stop();this.play()},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;var times=this.provider.getKeySpan();var step=this.provider.getSteps()*(timestamp-times.start)/(times.end-times.start);return step},getStep:function(){return this.getKey()},getTime:function(){return this.stepToTime(this.getKey())},getTimeSpan:function(){return this.provider.getKeySpan()},setCartoCSS:function(cartocss){if(!this.renderer)throw new Error("renderer is not valid");if(this.provider&&this.provider.options.named_map){console.log("Torque layer: CartoCSS style on named maps is read-only");return false}this.renderer.setCartoCSS(cartocss,function(){var options=torque.common.TorqueLayer.optionsFromLayer(this.renderer._shader.findLayer({name:"Map"}));this.provider.setCartoCSS&&this.provider.setCartoCSS(cartocss);if(this.provider.setOptions(options)){this._reloadTiles()}torque.extend(this.options,options);if(options.animationDuration){this.animator.duration(options.animationDuration)}this._clearCaches();this.redraw();return this}.bind(this))},getActivePointsBBox:function(step){var positions=[];for(var t in this._tiles){var tile=this._tiles[t];positions=positions.concat(this.renderer.getActivePointsBBox(tile,step))}return positions},getValues:function(step){var values=[];step=step===undefined?this.getKey():step;var t,tile;for(t in this._tiles){tile=this._tiles[t];this.renderer.getValues(tile,step,values)}return values},getValueForPos:function(x,y,step){step=step===undefined?this.getKey():step;var t,tile,pos,value=null,xx,yy;for(t in this._tiles){tile=this._tiles[t];pos=this.getTilePos(tile.coord);xx=x-pos.x;yy=y-pos.y;if(xx>=0&&yy>=0&&xx=0){this.cancelAnimationFrame.call(window,this.currentAnimationFrame)}this.currentAnimationFrame=this.requestAnimationFrame.call(window,this.render)};ol.CanvasLayer.prototype.getCanvas=function(){return this._canvas};ol.CanvasLayer.prototype.getAttribution=function(){return this.options.attribution};ol.CanvasLayer.prototype.draw=function(){return this._render()};ol.CanvasLayer.prototype.redraw=function(direct){if(direct){this.render()}else{this._render()}};module.exports=ol.CanvasLayer},{"./ol_tileloader_mixin":20}],19:[function(require,module,exports){if(typeof ol!=="undefined"){require("./torque")}},{"./torque":21}],20:[function(require,module,exports){ol.TileLoader=function(tileSize,maxZoom){this._tileSize=tileSize;this._tiles={};this._tilesLoading={};this._tilesToLoad=0;this._updateTiles=this._updateTiles.bind(this);this._tileGrid=ol.tilegrid.createXYZ({maxZoom:maxZoom,tileSize:tileSize})};ol.TileLoader.prototype._initTileLoader=function(map){this._map=map;this._view=map.getView();this._centerChangedId=this._view.on("change:center",function(e){this._updateTiles()},this);this._postcomposeKey=undefined;this._resolutionChangedId=this._view.on("change:resolution",function(evt){this._currentResolution=this._view.getResolution();if(this._postcomposeKey)return;this.fire("mapZoomStart");this._postcomposeKey=this._map.on("postcompose",function(evt){if(evt.frameState.viewState.resolution===this._currentResolution){this._updateTiles();this._map.unByKey(this._postcomposeKey);this._postcomposeKey=undefined;this.fire("mapZoomEnd")}},this)},this);this._updateTiles()};ol.TileLoader.prototype._removeTileLoader=function(){this._view.unByKey(this._centerChangedId);this._view.unByKey(this._resolutionChangedId);this._removeTiles()};ol.TileLoader.prototype._removeTiles=function(){for(var key in this._tiles){this._removeTile(key)}};ol.TileLoader.prototype._reloadTiles=function(){this._removeTiles();this._updateTiles()};ol.TileLoader.prototype._updateTiles=function(){if(!this._map){return}var zoom=this._tileGrid.getZForResolution(this._view.getResolution());var extent=this._view.calculateExtent(this._map.getSize());var tileRange=this._requestTilesForExtentAndZ(extent,zoom);this._removeOtherTiles(tileRange)};ol.TileLoader.prototype._removeOtherTiles=function(tileRange){var kArr,x,y,z,key;var zoom=this._tileGrid.getZForResolution(this._view.getResolution());for(key in this._tiles){if(this._tiles.hasOwnProperty(key)){kArr=key.split(":");x=parseInt(kArr[0],10);y=parseInt(kArr[1],10);z=parseInt(kArr[2],10);if(z!==zoom||xtileRange.maxX||-y-1tileRange.maxY){this._removeTile(key)}}}};ol.TileLoader.prototype._removeTile=function(key){this.fire("tileRemoved",this._tiles[key]);delete this._tiles[key];delete this._tilesLoading[key]};ol.TileLoader.prototype._tileKey=function(tilePoint){return tilePoint.x+":"+tilePoint.y+":"+tilePoint.zoom};ol.TileLoader.prototype._tileShouldBeLoaded=function(tilePoint){var k=this._tileKey(tilePoint);return!(k in this._tiles)&&!(k in this._tilesLoading)};ol.TileLoader.prototype._removeFromTilesLoading=function(tilePoint){this._tilesToLoad--;var k=this._tileKey(tilePoint);delete this._tilesLoading[k];if(this._tilesToLoad===0){this.fire("tilesLoaded")}};ol.TileLoader.prototype._tileLoaded=function(tilePoint,tileData){var k=this._tileKey(tilePoint);this._tiles[k]=tileData};ol.TileLoader.prototype.getTilePos=function(tilePoint){var zoom=this._tileGrid.getZForResolution(this._view.getResolution());var extent=this._tileGrid.getTileCoordExtent([zoom,tilePoint.x,-tilePoint.y-1]);var topLeft=this._map.getPixelFromCoordinate([extent[0],extent[3]]);return{x:topLeft[0],y:topLeft[1]}};ol.TileLoader.prototype._requestTilesForExtentAndZ=function(extent,zoom){var queue=[];var tileCoords=[];this._tileGrid.forEachTileCoord(extent,zoom,function(coord){tileCoords.push(coord);var point={x:coord[1],y:-coord[2]-1,zoom:coord[0]};if(this._tileShouldBeLoaded(point)){queue.push(point)}}.bind(this));var tilesToLoad=queue.length;if(tilesToLoad>0){this._tilesToLoad+=tilesToLoad;for(var i=0;i=0&&yy>=0&&xx1){Profiler.new_value(this.name,this.count);this.count=0;this.start()}}};Profiler.metric=function(name){return new Metric(name)};module.exports=Profiler},{}],23:[function(require,module,exports){module.exports={json:require("./json"),JsonArray:require("./jsonarray"),windshaft:require("./windshaft"),tileJSON:require("./tilejson")}},{"./json":24,"./jsonarray":25,"./tilejson":26,"./windshaft":27}],24:[function(require,module,exports){var torque=require("../");var Profiler=require("../profiler");var Uint8Array=torque.types.Uint8Array;var Int32Array=torque.types.Int32Array;var Uint32Array=torque.types.Uint32Array;function format(str){for(var i=1;i>0);self.options.data_steps=data.num_steps>>0;self.options.step=self.options.step||1;self.options.bounds=[[data.ymin,data.xmin],[data.ymax,data.xmax]];self._setReady(true)},{parseJSON:true,no_cdn:true})},{parseJSON:true,no_cdn:true})}};module.exports=json},{"../":11,"../profiler":22}],25:[function(require,module,exports){var torque=require("../");var Profiler=require("../profiler");var Uint8Array=torque.types.Uint8Array;var Int32Array=torque.types.Int32Array;var Uint32Array=torque.types.Uint32Array;function format(str,attrs){for(var i=1;i=0?st["marker-fill-opacity"]:1;if(ctx.globalAlpha>0){ctx.fill()}}if(st["marker-line-color"]&&st["marker-line-width"]&&st["marker-line-width"]>LINEWIDTH_MIN_VALUE){ctx.globalAlpha=st["marker-line-opacity"]>=0?st["marker-line-opacity"]:1;if(st["marker-line-width"]!==undefined){ctx.lineWidth=st["marker-line-width"]}ctx.strokeStyle=st["marker-line-color"];if(ctx.globalAlpha>0){ctx.stroke()}}}function renderRectangle(ctx,st){ctx.fillStyle=st["marker-fill"];var pixel_size=st["marker-width"];var w=pixel_size*2;if(st["marker-fill"]){if(st["marker-fill-opacity"]!==undefined||st["marker-opacity"]!==undefined){ctx.globalAlpha=st["marker-fill-opacity"]||st["marker-opacity"]}ctx.fillRect(-pixel_size,-pixel_size,w,w)}ctx.globalAlpha=1;if(st["marker-line-color"]&&st["marker-line-width"]){if(st["marker-line-opacity"]){ctx.globalAlpha=st["marker-line-opacity"]}if(st["marker-line-width"]){ctx.lineWidth=st["marker-line-width"]}ctx.strokeStyle=st["marker-line-color"];if(ctx.globalAlpha>0){ctx.strokeRect(-pixel_size,-pixel_size,w,w)}}}function renderSprite(ctx,img,st){if(img.complete){if(st["marker-fill-opacity"]!==undefined||st["marker-opacity"]!==undefined){ctx.globalAlpha=st["marker-fill-opacity"]||st["marker-opacity"]}ctx.drawImage(img,0,0,Math.min(img.width,MAX_SPRITE_RADIUS),Math.min(img.height,MAX_SPRITE_RADIUS))}}module.exports={renderPoint:renderPoint,renderSprite:renderSprite,renderRectangle:renderRectangle,MAX_SPRITE_RADIUS:MAX_SPRITE_RADIUS}},{}],29:[function(require,module,exports){var d3=require("d3");var jenks=require("turf-jenks");function TorqueDataSource(tiles){this.tiles=tiles}module.exports=TorqueDataSource;TorqueDataSource.prototype.getName=function(){return"TorqueDataSource"};TorqueDataSource.prototype.getRamp=function(column,bins,method,callback){var ramp=[];var error=null;var values=Object.keys(this.tiles).map(function(t){return this.tiles[t].renderData}.bind(this)).reduce(function(p,c,i){for(var i=0;iramp[length-1]})))}}}else{error=new Error("Quantification method "+method+" is not supported")}callback(error,ramp)}},{d3:undefined,"turf-jenks":undefined}],30:[function(require,module,exports){module.exports={cartocss:require("./cartocss_render"),Point:require("./point"),Rectangle:require("./rectangle")}},{"./cartocss_render":28,"./point":31,"./rectangle":32}],31:[function(require,module,exports){(function(global){var torque=require("../");var cartocss=require("./cartocss_render");var Profiler=require("../profiler");var carto=global.carto||require("carto");var Filters=require("./torque_filters");var turbocarto=require("turbo-carto");var CartoDatasource=require("./datasource");var ERROR_IMG_URL="http://s3.amazonaws.com/com.cartodb.assets.static/error.svg";var DEFAULT_CARTOCSS=["#layer {"," marker-fill: #662506;"," marker-width: 4;"," [value > 1] { marker-fill: #FEE391; }"," [value > 2] { marker-fill: #FEC44F; }"," [value > 3] { marker-fill: #FE9929; }"," [value > 4] { marker-fill: #EC7014; }"," [value > 5] { marker-fill: #CC4C02; }"," [value > 6] { marker-fill: #993404; }"," [value > 7] { marker-fill: #662506; }","}"].join("\n");var COMP_OP_TO_CANVAS={difference:"difference",src:"source-over",exclusion:"exclusion",dst:"destination-in",multiply:"multiply",contrast:"contrast","src-over":"source-over",screen:"screen",invert:"invert","dst-over":"destination-over",overlay:"overlay","invert-rgb":"invert","src-in":"source-in",darken:"darken","dst-in":"destination-in",lighten:"lighten","src-out":"source-out","color-dodge":"color-dodge",hue:"hue","dst-out":"destination-out","color-burn":"color-burn",saturation:"saturation","src-atop":"source-atop","hard-light":"hard-light",color:"color","dst-atop":"destination-atop","soft-light":"soft-light",xor:"xor"};function compop2canvas(compop){return COMP_OP_TO_CANVAS[compop]||compop}function PointRenderer(canvas,options){if(!canvas){throw new Error("canvas can't be undefined")}this.options=options;this.layer=options.layer;this._canvas=canvas;this._ctx=canvas.getContext("2d");this._sprites=[];this._shader=null;this._icons={};this._iconsToLoad=0;this._filters=new Filters(this._canvas,{canvasClass:options.canvasClass});this.style=this.options.cartocss||DEFAULT_CARTOCSS;this.setCartoCSS(this.style);this.TILE_SIZE=256;this._style=null;this._gradients={};this._forcePoints=false}torque.extend(PointRenderer.prototype,torque.Event,{clearCanvas:function(){if(this._Map){var canvas=this._canvas;var color=this._Map["-torque-clear-color"];var ctx=this._ctx;if(color==="rgba(255, 255, 255, 0)"||!color){ctx.save();ctx.setTransform(1,0,0,1,0,0);ctx.clearRect(0,0,canvas.width,canvas.height);ctx.restore()}else{ctx.setTransform(1,0,0,1,0,0);var compop=this._Map["comp-op"];ctx.globalCompositeOperation=compop2canvas(compop)||compop;ctx.fillStyle=color;ctx.fillRect(0,0,canvas.width,canvas.height)}}},setCanvas:function(canvas){this._canvas=canvas;this._ctx=canvas.getContext("2d")},setCartoCSS:function(cartocss,callback){var self=this;this.style=cartocss;if(PointRenderer.isTurboCarto(cartocss)){var datasource=new CartoDatasource(self.layer._tiles);turbocarto(cartocss,datasource,function(err,parsedCartoCSS){if(err){return callback(err,null)}self.setShader((new carto.RendererJS).render(parsedCartoCSS));self.layer.redraw();self.layer.animator.start();callback&&callback()})}else{self.setShader((new carto.RendererJS).render(cartocss));callback&&callback()}},setShader:function(shader){this._sprites=[];this._shader=shader;this._Map=this._shader.getDefault().getStyle({},{zoom:0});var img_names=this._shader.getImageURLs();if(this.layer&&this.layer.showLimitErrors){img_names.push(ERROR_IMG_URL)}this._preloadIcons(img_names)},clearSpriteCache:function(){this._sprites=[]},generateSprite:function(shader,value,shaderVars){var self=this;var prof=Profiler.metric("torque.renderer.point.generateSprite").start();var st=shader.getStyle({value:value},shaderVars);if(this._style===null||this._style!==st){this._style=st}var pointSize=st["marker-width"];if(!pointSize){return null}if(st["marker-opacity"]===0&&!st["marker-line-opacity"]){return null}var canvas=this._createCanvas();var ctx=canvas.getContext("2d");var markerFile=st["marker-file"]||st["point-file"];var qualifiedUrl=markerFile&&this._qualifyURL(markerFile);if(qualifiedUrl&&this._iconsToLoad<=0&&this._icons[qualifiedUrl]){var img=this._icons[qualifiedUrl];var dWidth=Math.min(st["marker-width"]*2||img.width,cartocss.MAX_SPRITE_RADIUS*2);var dHeight=Math.min((st["marker-height"]||dWidth)*(img.width/img.height),cartocss.MAX_SPRITE_RADIUS*2);canvas.width=ctx.width=dWidth;canvas.height=ctx.height=dHeight;ctx.scale(dWidth/img.width,dHeight/img.height);cartocss.renderSprite(ctx,img,st)}else{var canvasSize=(st["marker-line-width"]||0)+pointSize*2;var w=ctx.width=canvas.width=ctx.height=canvas.height=Math.ceil(canvasSize);ctx.translate(w/2,w/2);var mt=st["marker-type"];if(mt&&mt==="rectangle"){cartocss.renderRectangle(ctx,st)}else{cartocss.renderPoint(ctx,st)}}prof.end(true);if(torque.flags.sprites_to_images){var i=this._createImage();i.src=canvas.toDataURL();return i}return canvas},renderTile:function(tile,keys,callback){if(tile&&tile.error){this._renderErrorTile(tile);return false}if(this._iconsToLoad>0){this.on("allIconsLoaded",function(){this.renderTile.apply(this,[tile,keys,callback])});return false}if(typeof keys.length==="undefined"){keys=[keys]}var prof=Profiler.metric("torque.renderer.point.renderLayers").start();var layers=this._shader.getLayers();for(var i=0,n=layers.length;itile.maxDate){key=tile.maxDate}var tileMax=this.options.resolution*(this.TILE_SIZE/this.options.resolution-1);var activePixels=tile.timeCount[key];var anchor=this.options.resolution/2;if(activePixels){var pixelIndex=tile.timeIndex[key];for(var p=0;p>1)+anchor;var y=tileMax-tile.y[posIdx]+anchor;ctx.drawImage(sp,x,y-(sp.height>>1))}}}}prof.end(true)},setBlendMode:function(b){this.options.blendmode=b},getActivePointsBBox:function(tile,step){var positions=[];var mercator=new torque.Mercator;var tileMax=this.options.resolution*(this.TILE_SIZE/this.options.resolution-1);var activePixels=tile.timeCount[step];var pixelIndex=tile.timeIndex[step];for(var p=0;p>1;var tileMax=this.options.resolution*(this.TILE_SIZE/this.options.resolution-1);var activePixels=tile.timeCount[step];var pixelIndex=tile.timeIndex[step];for(var p=0;p=0&&dx=0&&dy0&&!this._forcePoints){var qualifiedImageUrlSet=Object.keys(img_names.reduce(function(imgNamesMap,imgName){var qualifiedUrl=self._qualifyURL(imgName);if(!self._icons[qualifiedUrl]){imgNamesMap[qualifiedUrl]=true}return imgNamesMap},{}));var filtered=self._shader.getLayers().some(function(layer){return typeof layer.shader["image-filters"]!=="undefined"});this._iconsToLoad+=qualifiedImageUrlSet.length;qualifiedImageUrlSet.forEach(function(qualifiedImageUrl){self._icons[qualifiedImageUrl]=null;var img=self._createImage();if(filtered){img.crossOrigin="Anonymous"}self._setImageSrc(img,qualifiedImageUrl,function(err){if(err){self._forcePoints=true;self.clearSpriteCache();self._iconsToLoad=0;self.fire("allIconsLoaded");if(filtered){console.info("Only CORS-enabled, or same domain image-files can be used in combination with image-filters")}console.error("Couldn't get marker-file "+qualifiedImageUrl)}else{self._icons[qualifiedImageUrl]=img;self._iconsToLoad--;if(self._iconsToLoad<=0){self.clearSpriteCache();self.fire("allIconsLoaded")}}})})}else{this.fire("allIconsLoaded")}},applyFilters:function(){if(this._style){if(this._style["image-filters"]){function gradientKey(imf){var hash="";for(var i=0;i 10] { polygon-fill: #FFFF00; }"," [value > 100] { polygon-fill: #FFCC00; }"," [value > 1000] { polygon-fill: #FE9929; }"," [value > 10000] { polygon-fill: #FF6600; }"," [value > 100000] { polygon-fill: #FF3300; }","}"].join("\n");var TAU=Math.PI*2;function RectanbleRenderer(canvas,options){this.options=options;carto.tree.Reference.set(torque["torque-reference"]);this.setCanvas(canvas);this.setCartoCSS(this.options.cartocss||DEFAULT_CARTOCSS)}RectanbleRenderer.prototype={setCartoCSS:function(cartocss){this._cartoCssStyle=(new carto.RendererJS).render(cartocss);if(this._cartoCssStyle.getLayers().length>1){throw new Error("only one CartoCSS layer is supported")}this._shader=this._cartoCssStyle.getLayers()[0].shader},setCanvas:function(canvas){if(!canvas)return;this._canvas=canvas;this._ctx=canvas.getContext("2d")},accumulate:function(tile,keys){var prof=Profiler.metric("RectangleRender:accumulate").start();var x,y,posIdx,p,k,key,activePixels,pixelIndex;var res=this.options.resolution;var s=256/res;var accum=new Float32Array(s*s);if(typeof keys!=="object"){keys=[keys]}for(k=0;k=200&&status<300||status===304||status===429){callback(req)}else{callback(null)}}"onload"in req?req.onload=req.onerror=respond:req.onreadystatechange=function(){req.readyState>3&&respond()};req.onprogress=function(){};req.responseType=options.responseType;if(options.data){req.setRequestHeader("Content-type","application/json");req.setRequestHeader("Accept","*")}req.send(options.data);return req}function post(url,data,callback){return get(url,callback,{data:data,method:"POST"})}module.exports={get:get,post:post,jsonp:jsonp,lastCall:function(){return lastCall}}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./core":5}]},{},[11])(11)});