3 lines
78 KiB
JavaScript
3 lines
78 KiB
JavaScript
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.torque=e()}}(function(){var e,t,n;return function i(e,t,n){function r(o,u){if(!t[o]){if(!e[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(s)return s(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=t[o]={exports:{}};e[o][0].call(l.exports,function(t){var n=e[o][1][t];return r(n?n:t)},l,l.exports,i,e,t,n)}return t[o].exports}var s=typeof require=="function"&&require;for(var o=0;o<n.length;o++)r(n[o]);return r}({1:[function(e,t,n){(function(n){function o(e,t){if(!t.steps)throw new Error("steps option missing");this.options=t,this.running=!1,this._tick=this._tick.bind(this),this._t0=+(new Date),this.callback=e,this._time=0,this.itemsReady=!1,this.options=r.extend({animationDelay:0,maxDelta:.2,loop:t.loop===undefined?!0:t.loop},this.options),this.rescale()}var r=e("./"),i=n.requestAnimationFrame||n.mozRequestAnimationFrame||n.webkitRequestAnimationFrame||n.msRequestAnimationFrame||function(e){return n.setTimeout(e,1e3/60)},s=n.cancelAnimationFrame||n.mozCancelAnimationFrame||n.webkitCancelAnimationFrame||n.msCancelAnimationFrame||function(e){clearTimeout(e)};o.prototype={start:function(){this.running=!0,i(this._tick),this.options.onStart&&this.options.onStart(),this.options.steps===1&&(this.running=!1)},isRunning:function(){return this.running},stop:function(){this.pause(),this.time(0),this.options.onStop&&this.options.onStop()},time:function(e){if(!arguments.length)return this._time;this._time=e;var t=this.range(this.domain(this._time));this.callback(t)},toggle:function(){this.running?this.pause():this.start()},rescale:function(){return this.domainInv=r.math.linear(this.options.animationDelay,this.options.animationDelay+this.options.animationDuration),this.domain=this.domainInv.invert(),this.range=r.math.linear(0,this.options.steps),this.rangeInv=this.range.invert(),this.time(this._time),this.running?this.start():this.pause(),this},duration:function(e){return arguments.length?(this.options.animationDuration=e,this.time()>e&&this.time(0),this.rescale(),this):this.options.animationDuration},steps:function(e){return this.options.steps=e,this.rescale()},step:function(e){if(arguments.length===0)return this.range(this.domain(this._time));this._time=this.domainInv(this.rangeInv(e))},pause:function(){this.running=!1,s(this._tick),this.options.onPause&&this.options.onPause()},_tick:function(){var e=+(new Date),t=(e-this._t0)*.001;t=Math.min(this.options.maxDelta,t),this._t0=e,this._time+=t,this.step()>=this.options.steps&&(this.options.loop?this._time=0:(this.time(this.options.animationDuration),this.pause())),this.running&&(this.time(this._time),i(this._tick))}},t.exports=o}).call(this,typeof global!="undefined"?global:typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{"./":10}],2:[function(e,t,n){var r={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:!1,"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]}};t.exports={version:{latest:r,"1.0.0":r}}},{}],3:[function(e,t,n){(function(n){function i(){}var r=n.carto||e("carto");i.prototype={},i.optionsFromLayer=function(e){var t={};if(!e)return t;var n={"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 r in n){var i=e.eval(r);if(i!==undefined){var s=n[r];t[s]=i}}return t},i.optionsFromCartoCSS=function(e){var t=(new r.RendererJS).render(e),n=t.findLayer({name:"Map"});return i.optionsFromLayer(n)},t.exports.TorqueLayer=i}).call(this,typeof global!="undefined"?global:typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{carto:undefined}],4:[function(e,t,n){(function(e){function r(){var e=arguments,t=e[0];for(var n=1;n<e.length;++n){var r=e[n];for(var i in r)t[i]=r[i]}return t}function i(e){return r({},e)}function s(e){return typeof e=="function"||!1}function o(e){return e&&typeof e=="object"&&Object.prototype.toString.call(e)=="[object Array]"}function a(){return!!document.createElement("canvas")}function f(){return typeof navigator!="undefined"?navigator.userAgent:""}var n={};n.on=function(e,t){var n=this._evt_callbacks=this._evt_callbacks||{},r=n[e]||(n[e]=[]);return r.push(t),this},n.trigger=function(e){var t=this._evt_callbacks&&this._evt_callbacks[e];for(var n=0;t&&n<t.length;++n)t[n].apply(this,Array.prototype.slice.call(arguments,1));return this},n.fire=n.trigger,n.off=function(e,t){var n=this._evt_callbacks&&this._evt_callbacks[e];if(n&&!t)return delete this._evt_callbacks[e],this;var r=[];for(var i=0;n&&i<n.length;++i)n[i]===t&&r.push(i);while((i=r.pop())!==undefined)n.splice(i,1);return this},n.callbacks=function(e){return this._evt_callbacks&&this._evt_callbacks[e]||[]};var u={Uint8Array:typeof e.Uint8Array!="undefined"?e.Uint8Array:Array,Uint8ClampedArray:typeof e.Uint8ClampedArray!="undefined"?e.Uint8ClampedArray:Array,Uint32Array:typeof e.Uint32Array!="undefined"?e.Uint32Array:Array,Int16Array:typeof e.Int16Array!="undefined"?e.Int16Array:Array,Int32Array:typeof e.Int32Array!="undefined"?e.Int32Array:Array},l={sprites_to_images:f().indexOf("Safari")===-1&&f().indexOf("Firefox")===-1};t.exports={Event:n,extend:r,clone:i,isFunction:s,isArray:o,types:u,isBrowserSupported:a,flags:l}}).call(this,typeof global!="undefined"?global:typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{}],5:[function(e,t,n){function r(e){function n(e,t){return function(){t.apply(e)}}this.isAdded_=!1,this.isAnimated_=!1,this.paneName_=r.DEFAULT_PANE_NAME_,this.updateHandler_=null,this.resizeHandler_=null,this.topLeft_=null,this.centerListener_=null,this.resizeListener_=null,this.needsResize_=!0,this.requestAnimationFrameId_=null;var t=document.createElement("canvas");t.style.position="absolute",t.style.top=0,t.style.left=0,t.style.pointerEvents="none",this.canvas=t,this.repositionFunction_=n(this,this.repositionCanvas_),this.resizeFunction_=n(this,this.resize_),this.requestUpdateFunction_=n(this,this.update_),e&&this.setOptions(e)}r.prototype=new google.maps.OverlayView,r.DEFAULT_PANE_NAME_="overlayLayer",r.CSS_TRANSFORM_=function(){var e=document.createElement("div"),t=["transform","WebkitTransform","MozTransform","OTransform","msTransform"];for(var n=0;n<t.length;n++){var r=t[n];if(e.style[r]!==undefined)return r}return t[0]}(),r.prototype.requestAnimFrame_=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(e){return window.setTimeout(e,1e3/60)},r.prototype.cancelAnimFrame_=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||function(e){},r.prototype.setOptions=function(e){e.animate!==undefined&&this.setAnimate(e.animate),e.paneName!==undefined&&this.setPane(e.paneName),e.updateHandler!==undefined&&this.setUpdateHandler(e.updateHandler),e.resizeHandler!==undefined&&this.setResizeHandler(e.resizeHandler),e.readyHandler&&(this.readyHandler=e.readyHandler)},r.prototype.setAnimate=function(e){this.isAnimated_=!!e,this.isAnimated_&&this.scheduleUpdate()},r.prototype.isAnimated=function(){return this.isAnimated_},r.prototype.setPaneName=function(e){this.paneName_=e,this.setPane_()},r.prototype.setOpacity=function(e){this.canvas.style.opacity=e},r.prototype.getOpacity=function(){return this.canvas.style.opacity},r.prototype.getPaneName=function(){return this.paneName_},r.prototype.setPane_=function(){if(!this.isAdded_)return;var e=this.getPanes();if(!e[this.paneName_])throw new Error('"'+this.paneName_+'" is not a valid MapPane name.');e[this.paneName_].appendChild(this.canvas)},r.prototype.setResizeHandler=function(e){this.resizeHandler_=e},r.prototype.setUpdateHandler=function(e){this.updateHandler_=e},r.prototype.onAdd=function(){if(this.isAdded_)return;this.isAdded_=!0,this.setPane_(),this.resizeListener_=google.maps.event.addListener(this.getMap(),"resize",this.resizeFunction_),this.centerListener_=google.maps.event.addListener(this.getMap(),"center_changed",this.repositionFunction_),this.resize_(),this.repositionCanvas_(),this.readyHandler&&this.readyHandler()},r.prototype.onRemove=function(){if(!this.isAdded_)return;this.isAdded_=!1,this.topLeft_=null,this.canvas.parentElement.removeChild(this.canvas),this.centerListener_&&(google.maps.event.removeListener(this.centerListener_),this.centerListener_=null),this.resizeListener_&&(google.maps.event.removeListener(this.resizeListener_),this.resizeListener_=null),this.requestAnimationFrameId_&&(this.cancelAnimFrame_.call(window,this.requestAnimationFrameId_),this.requestAnimationFrameId_=null)},r.prototype.resize_=function(){if(!this.isAdded_)return;var e=this.getMap(),t=e.getDiv().offsetWidth,n=e.getDiv().offsetHeight,r=this.canvas.width,i=this.canvas.height;if(r!==t||i!==n)this.canvas.width=t,this.canvas.height=n,this.canvas.style.width=t+"px",this.canvas.style.height=n+"px",this.needsResize_=!0,this.scheduleUpdate()},r.prototype.draw=function(){this.repositionCanvas_()},r.prototype.repositionCanvas_=function(){var e=this.getMap().getBounds();this.topLeft_=new google.maps.LatLng(e.getNorthEast().lat(),e.getSouthWest().lng());var t=this.getProjection(),n=t.fromLatLngToDivPixel(this.topLeft_),i=(1<<this.getMap().getZoom())*256;Math.abs(n.x)>i&&(n.x-=i),this.canvas.style[r.CSS_TRANSFORM_]="translate("+Math.round(n.x)+"px,"+Math.round(n.y)+"px)",this.scheduleUpdate()},r.prototype.update_=function(){this.requestAnimationFrameId_=null;if(!this.isAdded_)return;this.isAnimated_&&this.scheduleUpdate(),this.needsResize_&&this.resizeHandler_&&(this.needsResize_=!1,this.resizeHandler_()),this.updateHandler_&&this.updateHandler_()},r.prototype.getTopLeft=function(){return this.topLeft_},r.prototype.scheduleUpdate=function(){this.isAdded_&&!this.requestAnimationFrameId_&&(this.requestAnimationFrameId_=this.requestAnimFrame_.call(window,this.requestUpdateFunction_))},t.exports=r},{}],6:[function(e,t,n){function r(e,t){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=e,this.render=t,t||(this.render=e)}r.prototype.create_tile_canvas=function(e,t,n){var r=n.createElement("canvas"),i=n.createElement("canvas");r.style.border=i.style.border="none",r.style.margin=i.style.margin="0",r.style.padding=i.style.padding="0";var s=r.getContext("2d");s.width=r.width=this.tileSize.width,s.height=r.height=this.tileSize.height;var o=i.getContext("2d");i.width=o.width=this.tileSize.width,i.height=o.height=this.tileSize.height;var u=e.x+"_"+e.y+"_"+t;return r.setAttribute("id",u),i.setAttribute("id",u),u in this.tiles&&delete this.tiles[u],this.tiles[u]={canvas:r,ctx:s,hit_canvas:i,hit_ctx:o,coord:e,zoom:t,primitives:null},this.canvas_setup&&this.canvas_setup(this.tiles[u],e,t),r},r.prototype.each=function(e){for(var t in this.tiles){var n=this.tiles[t];e(n)}},r.prototype.recreate=function(){for(var e in this.tiles){var t=this.tiles[e];this.canvas_setup(t,t.coord,t.zoom)}},r.prototype.redraw_tile=function(e){this.render(e,e.coord,e.zoom)},r.prototype.redraw=function(){for(var e in this.tiles){var t=this.tiles[e];this.render(t,t.coord,t.zoom)}},r.prototype.getTile=function(e,t,n){return this.create_tile_canvas(e,t,n)},r.prototype.releaseTile=function(e){var t=e.getAttribute("id");delete this.tiles[t]},t.exports=r},{}],7:[function(e,t,n){function r(){}r.prototype={_initTileLoader:function(e,t){this._map=e,this._projection=t,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(e){google.maps.event.removeListener(e)}),this._removeTiles()},_removeTiles:function(){for(var e in this._tiles)this._removeTile(e)},_reloadTiles:function(){this._removeTiles(),this._updateTiles()},_updateTiles:function(){if(!this._map)return;var e=this._map.getBounds(),t=this._map.getZoom(),n=this.tileSize,r=1<<t,i=new google.maps.LatLng(e.getNorthEast().lat(),e.getSouthWest().lng()),s=new google.maps.LatLng(e.getSouthWest().lat(),e.getNorthEast().lng());this._projection=this._map.getProjection();var o=this._projection.fromLatLngToPoint(i),u=this._projection.fromLatLngToPoint(s),a=new google.maps.Point(Math.floor(o.x*r/n),Math.floor(o.y*r/n)),f=new google.maps.Point(Math.floor(u.x*r/n),Math.floor(u.y*r/n));this._addTilesFromCenterOut(a,f),this._removeOtherTiles(a,f)},_removeOtherTiles:function(e,t){var n,r,i,s,o=this._map.getZoom();for(s in this._tiles)this._tiles.hasOwnProperty(s)&&(n=s.split(":"),r=parseInt(n[0],10),i=parseInt(n[1],10),z=parseInt(n[2],10),(z!==o||r<e.x||r>t.x||i<e.y||i>t.y)&&this._removeTile(s))},_removeTile:function(e){this.onTileRemoved&&this.onTileRemoved(this._tiles[e]),delete this._tiles[e],delete this._tilesLoading[e]},_tileKey:function(e){return e.x+":"+e.y+":"+e.zoom},_tileShouldBeLoaded:function(e){var t=this._tileKey(e);return!(t in this._tiles)&&!(t in this._tilesLoading)},_tileLoaded:function(e,t){this._tilesToLoad--;var n=e.x+":"+e.y+":"+e.zoom;this._tiles[n]=t,delete this._tilesLoading[n],this._tilesToLoad===0&&this.onTilesLoaded&&this.onTilesLoaded()},getTilePos:function(e){var t=1<<this._map.getZoom();e={x:(e.x%t+t)%t,y:e.y},e=new google.maps.Point(e.x*this.tileSize,e.y*this.tileSize);var n=this._map.getBounds(),r=new google.maps.LatLng(n.getNorthEast().lat(),n.getSouthWest().lng()),i=this._map.getProjection().fromLatLngToPoint(r);return zoom=1<<this._map.getZoom(),i.x=i.x*zoom,i.y=i.y*zoom,new google.maps.Point(e.x-i.x,e.y-i.y)},_addTilesFromCenterOut:function(e,t){function f(e){var t=e.x-r.x,n=e.y-r.y;return t*t+n*n}var n=[],r=new google.maps.Point((e.x+t.x)*.5,(e.y+t.y)*.5),i=this._map.getZoom(),s,o,u;for(s=e.y;s<=t.y;s++)for(o=e.x;o<=t.x;o++)u=new google.maps.Point(o,s),u.zoom=i,this._tileShouldBeLoaded(u)&&n.push(u);var a=n.length;if(a===0)return;n.sort(function(e,t){return f(e)-f(t)}),this._tilesToLoad+=a;for(o=0;o<a;o++){var l=n[o],c=this._tileKey(l);this._tilesLoading[c]=l,this.onTileAdded&&this.onTileAdded(l)}this.onTilesLoading&&this.onTilesLoading()}},t.exports=r},{}],8:[function(e,t,n){var r={};typeof google!="undefined"&&typeof google.maps!="undefined"&&(r=e("./torque"),r.GMapsTileLoader=e("./gmaps_tileloader_mixin")),t.exports=r},{"./gmaps_tileloader_mixin":7,"./torque":9}],9:[function(e,t,n){(function(n){function a(e){var t=this;if(!i.isBrowserSupported())throw new Error("browser is not supported by torque");this.key=0,this.shader=null,this.ready=!1,this.options=i.extend({},e),this.options=i.extend({provider:"windshaft",renderer:"point",resolution:2,steps:100,visible:!0},this.options),e.cartocss&&i.extend(this.options,i.common.TorqueLayer.optionsFromCartoCSS(e.cartocss)),this.hidden=!this.options.visible,this.animator=new i.Animator(function(e){var n=e|0;t.key!==n&&t.setKey(n)},i.clone(this.options)),this.play=this.animator.start.bind(this.animator),this.stop=this.animator.stop.bind(this.animator),this.pause=this.animator.pause.bind(this.animator),this.toggle=this.animator.toggle.bind(this.animator),this.setDuration=this.animator.duration.bind(this.animator),this.isRunning=this.animator.isRunning.bind(this.animator),s.call(this,{map:this.options.map,animate:!1,updateHandler:this.render,readyHandler:this.initialize})}function f(e){this.options=i.extend({},e),o.call(this,this._loadTile.bind(this),this.drawTile.bind(this)),this.initialize(e)}var r=n.carto||e("carto"),i=e("../"),s=e("./CanvasLayer"),o=e("./canvas_tile_layer"),u=e("./gmaps_tileloader_mixin");a.prototype=i.extend({},s.prototype,u.prototype,i.Event,{providers:{sql_api:i.providers.json,url_template:i.providers.JsonArray,windshaft:i.providers.windshaft},renderers:{point:i.renderer.Point,pixel:i.renderer.Rectangle},initialize:function(){var e=this;this.onTileAdded=this.onTileAdded.bind(this),this.options.ready=function(){e.fire("change:bounds",{bounds:e.provider.getBounds()}),e.animator.steps(e.provider.getSteps()),e.animator.rescale(),e.fire("change:steps",{steps:e.provider.getSteps()}),e.setKey(e.key)},this.provider=new this.providers[this.options.provider](this.options),this.renderer=new this.renderers[this.options.renderer](this.getCanvas(),this.options),this.renderer.options.errorCallback=this.options.errorCallback,this._cacheListener=google.maps.event.addListener(this.options.map,"zoom_changed",function(){e.renderer&&e.renderer.clearSpriteCache()}),this._initTileLoader(this.options.map,this.getProjection()),this.shader&&this.renderer.setShader(this.shader)},hide:function(){return this.hidden?this:(this.pause(),this.clear(),this.hidden=!0,this)},show:function(){return this.hidden?(this.hidden=!1,this.play(),this.options.steps===1&&this.redraw(),this):this},setSQL:function(e){if(this.provider.options.named_map)throw new Error("SQL queries on named maps are read-only");if(!this.provider||!this.provider.setSQL)throw new Error("this provider does not support SQL");return this.provider.setSQL(e),this._reloadTiles(),this},setBlendMode:function(e){this.renderer&&this.renderer.setBlendMode(e),this.redraw()},setSteps:function(e){this.provider&&this.provider.setSteps(e),this.animator&&this.animator.steps(e),this._reloadTiles()},setColumn:function(e,t){this.provider&&this.provider.setColumn(e,t),this._reloadTiles()},getTimeBounds:function(){return this.provider&&this.provider.getKeySpan()},getCanvas:function(){return this.canvas},onTileAdded:function(e){var t=this;this.provider.getTileData(e,e.zoom,function(n){if(e.zoom!==t.options.map.getZoom())return;t._tileLoaded(e,n),n&&t.redraw()})},clear:function(){var e=this.canvas;e.width=e.width},render:function(){if(this.hidden)return;var e,t,n,r=this.canvas;this.renderer.clearCanvas();var i=r.getContext("2d");for(e in this._tiles)t=this._tiles[e],t&&(n=this.getTilePos(t.coord),i.setTransform(1,0,0,1,n.x,n.y),this.renderer.renderTile(t,this.key));this.renderer.applyFilters()},getActivePointsBBox:function(e){var t=[],n=this.options.resolution*(256/this.options.resolution-1);for(var r in this._tiles){var i=this._tiles[r];t=t.concat(this.renderer.getActivePointsBBox(i,e))}return t},setKey:function(e){this.key=e,this.animator.step(e),this.redraw(),this.fire("change:time",{time:this.getTime(),step:this.key})},setStep:function(e){if(e===undefined||e.length!==undefined)throw new Error("setTime only accept scalars");this.setKey(e)},stepToTime:function(e){if(!this.provider)return 0;var t=this.provider.getKeySpan(),n=t.start+(t.end-t.start)*(e/this.provider.getSteps());return new Date(n)},timeToStep:function(e){typeof e=="Date"&&(e=e.getTime());if(!this.provider)return 0;var t=this.provider.getKeySpan(),n=this.provider.getSteps()*(e-t.start)/(t.end-t.start);return n},getStep:function(){return this.key},getTime:function(){return this.stepToTime(this.key)},setCartoCSS:function(e){if(this.provider&&this.provider.options.named_map)throw new Error("CartoCSS style on named maps is read-only");var t=(new r.RendererJS).render(e);this.shader=t,this.renderer&&this.renderer.setShader(t);var n=i.common.TorqueLayer.optionsFromLayer(t.findLayer({name:"Map"}));return this.provider&&this.provider.setCartoCSS&&this.provider.setCartoCSS(e),this.provider&&this.provider.setOptions(n)&&this._reloadTiles(),i.extend(this.options,n),n.animationDuration&&this.animator.duration(n.animationDuration),this.redraw(),this},redraw:function(){this.scheduleUpdate()},onRemove:function(){this.fire("remove"),s.prototype.onRemove.call(this),this.animator.stop(),this._removeTileLoader(),google.maps.event.removeListener(this._cacheListener)},getValueForPos:function(e,t,n){n=n===undefined?this.key:n;var r,i,s,o=null,u,a;for(r in this._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)return o}return null},getValueForBBox:function(e,t,n,r){var i=e+n,s=t+r,o=0;for(_y=t;t<s;t+=this.options.resolution)for(_x=e;e<i;e+=this.options.resolution){var u=this.getValueForPos(_x,_y);if(u){var a=u.bbox,f=this.getProjection(),l=f.fromLatLngToContainerPixel(new google.maps.LatLng(a[1].lat,a[1].lon));l.x<i&&l.y<s&&(o+=u.value)}}return o},error:function(e){return this.options.errorCallback=e,this}}),f.prototype=i.extend({},o.prototype,{providers:{sql_api:i.providers.json,url_template:i.providers.JsonArray},renderers:{point:i.renderer.Point,pixel:i.renderer.Rectangle},initialize:function(e){var t=this;this.key=0,this.options.renderer=this.options.renderer||"pixel",this.options.provider=this.options.provider||"sql_api",this.provider=new this.providers[this.options.provider](e),this.renderer=new this.renderers[this.options.renderer](null,e)},_tileLoaded:function(e,t){e.data=t,this.drawTile(e)},_loadTile:function(e,t,n){var r=this,i=1<<n,s={x:(t.x%i+i)%i,y:t.y};this.provider.getTileData(s,n,function(t){r._tileLoaded(e,t)})},drawTile:function(e){var t=e.canvas;if(!e.data)return;t.width=t.width,this.renderer.setCanvas(t);var n=this.renderer.accumulate(e.data,this.key);this.renderer.renderTileAccum(n,0,0)},setKey:function(e){this.key=e,this.redraw()},setCartoCSS:function(e){if(!this.renderer)throw new Error("renderer is not valid");return this.renderer.setCartoCSS(e)}}),t.exports={GMapsTiledTorqueLayer:f,GMapsTorqueLayer:a}}).call(this,typeof global!="undefined"?global:typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{"../":10,"./CanvasLayer":5,"./canvas_tile_layer":6,"./gmaps_tileloader_mixin":7,carto:undefined}],10:[function(e,t,n){t.exports=e("./core"),t.exports.Animator=e("./animator"),t.exports.cartocss_reference=e("./cartocss_reference"),t.exports.common=e("./common"),t.exports.math=e("./math"),t.exports.Mercator=e("./mercator"),t.exports.net=e("./request"),t.exports.renderer=e("./renderer"),t.exports.providers=e("./provider"),e("./leaflet");var r=e("./gmaps");t.exports.GMapsTileLoader=r.GMapsTileLoader,t.exports.GMapsTorqueLayer=r.GMapsTorqueLayer,t.exports.GMapsTiledTorqueLayer=r.GMapsTiledTorqueLayer},{"./animator":1,"./cartocss_reference":2,"./common":3,"./core":4,"./gmaps":8,"./leaflet":12,"./math":15,"./mercator":16,"./provider":18,"./renderer":23,"./request":27}],11:[function(e,t,n){e("./leaflet_tileloader_mixin"),L.CanvasLayer=L.Class.extend({includes:[L.Mixin.Events,L.Mixin.TileLoader],options:{minZoom:0,maxZoom:28,tileSize:256,subdomains:"abc",errorTileUrl:"",attribution:"",zoomOffset:0,opacity:1,unloadInvisibleTiles:L.Browser.mobile,updateWhenIdle:L.Browser.mobile,tileLoader:!1,zoomAnimation:!0},initialize:function(e){var t=this;e=e||{},this.render=this.render.bind(this),L.Util.setOptions(this,e),this._canvas=this._createCanvas(),this.options.zoomAnimation&&(this._backCanvas=this._createCanvas()),this._ctx=this._canvas.getContext("2d"),this.currentAnimationFrame=-1,this.requestAnimationFrame=
|
|
window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||function(e){return window.setTimeout(e,1e3/60)},this.cancelAnimationFrame=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame||function(e){clearTimeout(e)}},_createCanvas:function(){var e;e=document.createElement("canvas"),e.style.position="absolute",e.style.top=0,e.style.left=0,e.style.pointerEvents="none",e.style.zIndex=this.options.zIndex||0;var t="leaflet-tile-container";return this.options.zoomAnimation&&(t+=" leaflet-zoom-animated"),e.setAttribute("class",t),e},onAdd:function(e){this._map=e;var t=this._map._panes.tilePane,n=L.DomUtil.create("div","leaflet-layer");n.appendChild(this._canvas),this.options.zoomAnimation&&(n.appendChild(this._backCanvas),this._backCanvas.style.display="none"),t.appendChild(n),this._container=n,e.dragging._draggable.on("predrag",function(){var t=e.dragging._draggable;L.DomUtil.setPosition(this._canvas,{x:-t._newPos.x,y:-t._newPos.y})},this),e.on({viewreset:this._reset},this),e.on("move",this.redraw,this),e.on("resize",this._reset,this),this.options.zoomAnimation&&e.on({zoomanim:this._animateZoom,zoomend:this._endZoomAnim,moveend:this._reset},this),this.options.tileLoader&&this._initTileLoader(),this._reset()},_animateZoom:function(e){this._animating||(this._animating=!0);var t=this._backCanvas;t.width=this._canvas.width,t.height=this._canvas.height;var n=this._canvas._leaflet_pos||{x:0,y:0};t.getContext("2d").drawImage(this._canvas,0,0),L.DomUtil.setPosition(t,L.DomUtil.getPosition(this._canvas)),this._canvas.style.display="none",t.style.display="block";var r=this._map,i=r.getZoomScale(e.zoom),s=r._latLngToNewLayerPoint(r.getCenter(),e.zoom,e.center),o=r._latLngToNewLayerPoint(e.center,e.zoom,e.center),u={x:s.x-o.x+n.x,y:s.y-o.y+n.y},a=t,f=L.DomUtil.TRANSFORM;setTimeout(function(){a.style[f]=L.DomUtil.getTranslateString(u)+" scale("+e.scale+") "},0)},_endZoomAnim:function(){this._animating=!1,this._canvas.style.display="block",this._backCanvas.style.display="none",this._backCanvas.style[L.DomUtil.TRANSFORM]=""},getCanvas:function(){return this._canvas},getAttribution:function(){return this.options.attribution},draw:function(){return this._reset()},onRemove:function(e){this._container.parentNode.removeChild(this._container),e.off({viewreset:this._reset,move:this._render,moveend:this._reset,resize:this._reset,zoomanim:this._animateZoom,zoomend:this._endZoomAnim},this)},addTo:function(e){return e.addLayer(this),this},error:function(e){return this.provider.options.errorCallback=e,this},setOpacity:function(e){return this.options.opacity=e,this._updateOpacity(),this},setZIndex:function(e){this._canvas.style.zIndex=e,this.options.zoomAnimation&&(this._backCanvas.style.zIndex=e)},bringToFront:function(){return this},bringToBack:function(){return this},_reset:function(){var e=this._map.getSize();this._canvas.width=e.x,this._canvas.height=e.y;var t=L.DomUtil.getPosition(this._map.getPanes().mapPane);t&&L.DomUtil.setPosition(this._canvas,{x:-t.x,y:-t.y}),this.onResize(),this._render()},_updateOpacity:function(){},_render:function(){this.currentAnimationFrame>=0&&this.cancelAnimationFrame.call(window,this.currentAnimationFrame),this.currentAnimationFrame=this.requestAnimationFrame.call(window,this.render)},redraw:function(e){var t=L.DomUtil.getPosition(this._map.getPanes().mapPane);t&&L.DomUtil.setPosition(this._canvas,{x:-t.x,y:-t.y}),e?this.render():this._render()},onResize:function(){},render:function(){throw new Error("render function should be implemented")}})},{"./leaflet_tileloader_mixin":13}],12:[function(e,t,n){typeof L!="undefined"&&e("./torque")},{"./torque":14}],13:[function(e,t,n){L.Mixin.TileLoader={_initTileLoader:function(){this._tiles={},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 e=this._map.getPixelBounds(),t=this._map.getZoom(),n=this.options.tileSize;if(t>this.options.maxZoom||t<this.options.minZoom)return;var r=new L.Point(Math.floor(e.min.x/n),Math.floor(e.min.y/n)),i=new L.Point(Math.floor(e.max.x/n),Math.floor(e.max.y/n)),s=new L.Bounds(r,i);this._addTilesFromCenterOut(s),this._removeOtherTiles(s)},_removeTiles:function(e){for(var t in this._tiles)this._removeTile(t)},_reloadTiles:function(){this._removeTiles(),this._updateTiles()},_removeOtherTiles:function(e){var t,n,r,i,s,o=this._map.getZoom();for(s in this._tiles)this._tiles.hasOwnProperty(s)&&(t=s.split(":"),n=parseInt(t[0],10),r=parseInt(t[1],10),i=parseInt(t[2],10),(o!==i||n<e.min.x||n>e.max.x||r<e.min.y||r>e.max.y)&&this._removeTile(s))},_removeTile:function(e){this.fire("tileRemoved",this._tiles[e]),delete this._tiles[e],delete this._tilesLoading[e]},_tileKey:function(e){return e.x+":"+e.y+":"+e.zoom},_tileShouldBeLoaded:function(e){var t=this._tileKey(e);return!(t in this._tiles)&&!(t in this._tilesLoading)},_tileLoaded:function(e,t){this._tilesToLoad--;var n=e.x+":"+e.y+":"+e.zoom;this._tiles[n]=t,delete this._tilesLoading[n],this._tilesToLoad===0&&this.fire("tilesLoaded")},getTilePos:function(e){e=new L.Point(e.x,e.y);var t=this._map._getNewTopLeftPoint(this._map.getCenter()),n=this.options.tileSize;return e.multiplyBy(n).subtract(t)},_addTilesFromCenterOut:function(e){var t=[],n=e.getCenter(),r=this._map.getZoom(),i,s,o;for(i=e.min.y;i<=e.max.y;i++)for(s=e.min.x;s<=e.max.x;s++)o=new L.Point(s,i),o.zoom=r,this._tileShouldBeLoaded(o)&&t.push(o);var u=t.length;if(u===0)return;t.sort(function(e,t){return e.distanceTo(n)-t.distanceTo(n)}),this._tilesToLoad+=u;for(s=0;s<u;s++){var a=t[s],f=this._tileKey(a);this._tilesLoading[f]=a,this.fire("tileAdded",a)}this.fire("tilesLoading")}}},{}],14:[function(e,t,n){(function(t){var n=t.carto||e("carto"),r=e("../");e("./canvas_layer"),L.TorqueLayer=L.CanvasLayer.extend({providers:{sql_api:r.providers.json,url_template:r.providers.JsonArray,windshaft:r.providers.windshaft},renderers:{point:r.renderer.Point,pixel:r.renderer.Rectangle},initialize:function(e){var t=this;if(!r.isBrowserSupported())throw new Error("browser is not supported by torque");e.tileLoader=!0,this.key=0,this.prevRenderedKey=0,e.cartocss&&r.extend(e,r.common.TorqueLayer.optionsFromCartoCSS(e.cartocss)),e.resolution=e.resolution||2,e.steps=e.steps||100,e.visible=e.visible===undefined?!0:e.visible,this.hidden=!e.visible,this.animator=new r.Animator(function(e){var n=e|0;t.key!==n&&t.setKey(n,{direct:!0})},r.extend(r.clone(e),{onPause:function(){t.fire("pause")},onStop:function(){t.fire("stop")},onStart:function(){t.fire("play")}})),this.play=this.animator.start.bind(this.animator),this.stop=this.animator.stop.bind(this.animator),this.pause=this.animator.pause.bind(this.animator),this.toggle=this.animator.toggle.bind(this.animator),this.setDuration=this.animator.duration.bind(this.animator),this.isRunning=this.animator.isRunning.bind(this.animator),L.CanvasLayer.prototype.initialize.call(this,e),this.options.renderer=this.options.renderer||"point",this.options.provider=this.options.provider||"windshaft",this.provider=new this.providers[this.options.provider](e),this.renderer=new this.renderers[this.options.renderer](this.getCanvas(),e),e.ready=function(){t.fire("change:bounds",{bounds:t.provider.getBounds()}),t.animator.steps(t.provider.getSteps()),t.animator.rescale(),t.fire("change:steps",{steps:t.provider.getSteps()}),t.setKey(t.key)},this.renderer.on("allIconsLoaded",this.render.bind(this)),this.on("tileAdded",function(e){var n=this.provider.getTileData(e,e.zoom,function(n){if(e.zoom!==t._map.getZoom())return;t._tileLoaded(e,n),t._clearTileCaches(),n&&t.redraw()})},this)},_clearTileCaches:function(){var e,t;for(e in this._tiles)t=this._tiles[e],t&&t._tileCache&&(t._tileCache=null)},_clearCaches:function(){this.renderer&&this.renderer.clearSpriteCache(),this._clearTileCaches()},onAdd:function(e){e.on({zoomend:this._clearCaches,zoomstart:this._pauseOnZoom},this),e.on({zoomend:this._resumeOnZoom},this),L.CanvasLayer.prototype.onAdd.call(this,e)},onRemove:function(e){this.fire("remove"),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(){return this.hidden?this:(this.pause(),this.clear(),this.hidden=!0,this)},show:function(){return this.hidden?(this.hidden=!1,this.play(),this.options.steps===1&&this.redraw(),this):this},setSQL:function(e){if(this.provider.options.named_map)throw new Error("SQL queries on named maps are read-only");if(!this.provider||!this.provider.setSQL)throw new Error("this provider does not support SQL");return this.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(){return this.provider&&this.provider.getKeySpan()},clear:function(){var e=this.getCanvas();e.width=e.width},render:function(){if(this.hidden)return;var e,t,n,r=this.getCanvas();this.renderer.clearCanvas();var i=r.getContext("2d");for(e in this._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));this.renderer.applyFilters();if(!this.animator.isRunning()&&this.key===this.prevRenderedKey){var s=this.renderer.TILE_SIZE;for(e in this._tiles){t=this._tiles[e];if(t&&!t._tileCache){var o=t._tileCache=document.createElement("canvas");o.width=o.height=s,n=this.getTilePos(t.coord);var u=Math.max(0,n.x),a=Math.max(0,n.y),f=Math.min(s,this.getCanvas().width-u),l=Math.min(s,this.getCanvas().height-a);f>0&&l>0&&o.getContext("2d").drawImage(this.getCanvas(),u,a,f,l,u-n.x,a-n.y,f,l)}}}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)throw new Error("setTime only accept scalars");this.setKey(e)},stepToTime:function(e){var t=this.provider.getKeySpan(),n=t.start+(t.end-t.start)*(e/this.provider.getSteps());return new Date(n)},timeToStep:function(e){typeof e=="Date"&&(e=e.getTime());if(!this.provider)return 0;var t=this.provider.getKeySpan(),n=this.provider.getSteps()*(e-t.start)/(t.end-t.start);return n},getStep:function(){return this.key},getTime:function(){return this.stepToTime(this.key)},getTimeSpan:function(){return this.provider.getKeySpan()},setCartoCSS:function(e){if(this.provider.options.named_map)throw new Error("CartoCSS style on named maps is read-only");if(!this.renderer)throw new Error("renderer is not valid");var t=(new n.RendererJS).render(e);this.renderer.setShader(t);var i=r.common.TorqueLayer.optionsFromLayer(t.findLayer({name:"Map"}));return this.provider.setCartoCSS&&this.provider.setCartoCSS(e),this.provider.setOptions(i)&&this._reloadTiles(),r.extend(this.options,i),i.animationDuration&&this.animator.duration(i.animationDuration),this._clearCaches(),this.redraw(),this},getActivePointsBBox:function(e){var t=[];for(var n in this._tiles){var r=this._tiles[n];t=t.concat(this.renderer.getActivePointsBBox(r,e))}return t},getValueForPos:function(e,t,n){n=n===undefined?this.key:n;var r,i,s,o=null,u,a;for(r in this._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)return o}return null},getValueForBBox:function(e,t,n,r){var i=e+n,s=t+r,o=e,u=0;for(_y=t;_y<s;_y+=this.options.resolution)for(o=e;o<i;o+=this.options.resolution){var a=this.getValueForPos(o,_y);if(a){var f=a.bbox,l=this._map.latLngToContainerPoint([f[1].lat,f[1].lon]);l.x<i&&l.y<s&&(u+=a.value)}}return u},invalidate:function(){this.provider.reload()}})}).call(this,typeof global!="undefined"?global:typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{"../":10,"./canvas_layer":11,carto:undefined}],15:[function(e,t,n){function r(e,t){return function(n){return Math.max(Math.min(n,t),e)}}function i(e,t){var n=r(0,1);return function(r){return n((r-e)/(t-e))}}function s(e,t){function s(r){return n(e*(1-r)+r*t)}var n=r(e,t);return s.invert=function(){return i(e,t)},s}t.exports={clamp:r,linear:s,invLinear:i}},{}],16:[function(e,t,n){function i(e,t,n){return t!==null&&(e=Math.max(e,t)),n!==null&&(e=Math.min(e,n)),e}function s(e){return e*(Math.PI/180)}function o(e){return e/(Math.PI/180)}var r=function(e,t){this.x=e||0,this.y=t||0},u=function(){this._tileSize=256,this._pixelOrigin=new r(this._tileSize/2,this._tileSize/2),this._pixelsPerLonDegree=this._tileSize/360,this._pixelsPerLonRadian=this._tileSize/(2*Math.PI)};u.prototype._fromLatLonToPoint=function(e,t){var n=new r(0,0),o=this._pixelOrigin;n.x=o.x+t*this._pixelsPerLonDegree;var u=i(Math.sin(s(e)),-0.9999,.9999);return n.y=o.y+.5*Math.log((1+u)/(1-u))*-this._pixelsPerLonRadian,n},u.prototype._fromPointToLatLon=function(e){var t=this,n=t._pixelOrigin,r=(e.x-n.x)/t._pixelsPerLonDegree,i=(e.y-n.y)/-t._pixelsPerLonRadian,s=o(2*Math.atan(Math.exp(i))-Math.PI/2);return{lat:s,lon:r}},u.prototype._tilePixelPos=function(e,t){return{x:e*this._tileSize,y:t*this._tileSize}},u.prototype.tilePixelBBox=function(e,t,n,i,s,o){o=o||1;var u=1<<n,a=o/u;return i=(e*this._tileSize+i)/u,s=(t*this._tileSize+s)/u,[this._fromPointToLatLon(new r(i,s+a)),this._fromPointToLatLon(new r(i+a,s))]},u.prototype.tileBBox=function(e,t,n,i){var s=1<<n;i=i||0;var o=(this._tileSize+i*2)/s,u=(e*this._tileSize-i)/s,a=(t*this._tileSize-i)/s;return[this._fromPointToLatLon(new r(u,a+o)),this._fromPointToLatLon(new r(u+o,a))]},u.prototype.latLonToTilePoint=function(e,t,n,i,s){var o=1<<s,u=this._fromLatLonToPoint(e,t),a=new r(u.x*o,u.y*o),f=this._tilePixelPos(n,i);return new r(Math.round(a.x-f.x),Math.round(a.y-f.y))},t.exports=u},{}],17:[function(e,t,n){function i(){}function s(e){this.t0=null,this.name=e,this.count=0}var r=1024;i.metrics={},i.get=function(e){return i.metrics[e]||{max:0,min:Number.MAX_VALUE,avg:0,total:0,count:0,history:typeof Float32Array!="undefined"?new Float32Array(r):[]}},i.new_value=function(e,t){var n=i.metrics[e]=i.get(e);n.max=Math.max(n.max,t),n.min=Math.min(n.min,t),n.total+=t,++n.count,n.avg=n.total/n.count,n.history[n.count%r]=t},i.print_stats=function(){for(k in i.metrics){var e=i.metrics[k];console.log(" === "+k+" === "),console.log(" max: "+e.max),console.log(" min: "+e.min),console.log(" avg: "+e.avg),console.log(" count: "+e.count),console.log(" total: "+e.total)}},s.prototype={start:function(){return this.t0=+(new Date),this},_elapsed:function(){return+(new Date)-this.t0},end:function(){this.t0!==null&&(i.new_value(this.name,this._elapsed()),this.t0=null)},inc:function(e){e=e===undefined?1:e,i.new_value(this.name,i.get(this.name).count+(e?e:0))},dec:function(e){e=e===undefined?1:e,this.inc(-e)},mark:function(){++this.count;if(this.t0===null){this.start();return}var e=this._elapsed();e>1&&(i.new_value(this.name,this.count),this.count=0,this.start())}},i.metric=function(e){return new s(e)},t.exports=i},{}],18:[function(e,t,n){t.exports={json:e("./json"),JsonArray:e("./jsonarray"),windshaft:e("./windshaft")}},{"./json":19,"./jsonarray":20,"./windshaft":21}],19:[function(e,t,n){function a(e){for(var t=1;t<arguments.length;++t){var n=arguments[t];for(var r in n)e=e.replace(RegExp("\\{"+r+"\\}","g"),n[r])}return e}var r=e("../"),i=e("../profiler"),s=r.types.Uint8Array,o=r.types.Int32Array,u=r.types.Uint32Array,f=function(e){this._ready=!1,this._tileQueue=[],this.options=e,this.options.is_time=this.options.is_time===undefined?!0:this.options.is_time,this.options.tiler_protocol=e.tiler_protocol||"http",this.options.tiler_domain=e.tiler_domain||"cartodb.com",this.options.tiler_port=e.tiler_port||80,this.options.data_aggregation&&(this.options.cumulative=this.options.data_aggregation==="cumulative");if(e.resolution===undefined)throw new Error("resolution should be provided");if(e.steps===undefined)throw new Error("steps should be provided");e.start===undefined?this._fetchKeySpan():this._setReady(!0)};f.prototype={proccessTile:function(e,t,n){var r,a=new s(e.length),f=new s(e.length),l=i.metric("ProviderJSON:mem"),c=i.metric("ProviderJSON:point_count"),h=i.metric("ProviderJSON:process_time").start(),p=0,d=-1;for(r=0;r<e.length;++r){var v=e[r];p+=v.dates__uint16.length;for(var m=0;m<v.dates__uint16.length;++m)d=Math.max(d,v.dates__uint16[m])}this.options.cumulative&&(p=(1+d)*e.length);var g=this.options.cumulative?u:s,y=new o(d+1),b=new o(d+1),w=new(this.options.valueDataType||g)(p),E=new u(p);l.inc(4*d+4*d+p+p*4),c.inc(e.length);var S={};for(var r=0;r<e.length;++r){var v=e[r];a[r]=v.x__uint8*this.options.resolution,v.y__uint8===-1?f[r]=0:f[r]=v.y__uint8*this.options.resolution;var p=v.dates__uint16,x=v.vals__uint8;if(!this.options.cumulative)for(var T=0,N=p.length;T<N;++T){var C=S[p[T]]||(S[p[T]]=[]);this.options.cumulative&&(x[T]+=prev_val),prev_val=x[T],C.push([r,x[T]])}else{var k={};for(var T=0,N=p.length;T<N;++T)k[p[T]]=x[T];var L=0;for(var T=p[0];T<=d;++T){var C=S[T]||(S[T]=[]),A=k[T];A&&(L+=A),C.push([r,L])}}}var O=0,M=0,_=0;for(var _=0;_<=d;++_){var D=0,P=S[_];if(P)for(var r=0;r<P.length;++r){var C=P[r];++D,E[O]=C[0],w[O]=C[1],++O}y[_]=M,b[_]=D,M+=D}return h.end(),{x:a,y:f,z:n,coord:{x:t.x,y:t.y,z:n},timeCount:b,timeIndex:y,renderDataPos:E,renderData:w,maxDate:d}},_host:function(){var e=this.options,t=e.sql_api_port,n=(e.user_name||e.user)+"."+(e.sql_api_domain||"cartodb.com")+(t?":"+t:""),r=e.sql_api_protocol||"http";return this.options.url||r+"://"+n+"/api/v2/sql"},url:function(e){var t=this.options,n=t.sql_api_protocol||"http";if(!this.options.cdn_url)return this._host();var r=n+"://";e&&(r+=e+".");var i=t.cdn_url;if(!i.http&&!i.https)throw new Error("cdn_host should contain http and/or https entries");return r+=i[n]+"/"+(t.user_name||t.user)+"/api/v2/sql",r},_hash:function(e){var t=0;if(!e||e.length==0)return t;for(var n=0,r=e.length;n<r;++n)t=(t<<5)-t+e.charCodeAt(n)|0;return t},_extraParams:function(){if(this.options.extra_params){var e=[];for(var t in this.options.extra_params){var n=this.options.extra_params[t];n&&e.push(t+"="+encodeURIComponent(n))}return e.join("&")}return null},isHttps:function(){return this.options.sql_api_protocol&&this.options.sql_api_protocol==="https"},sql:function(e,t,n){n=n||{};var i=this.options.subdomains||"0123";this.isHttps()&&(i=[null]);var s;n.no_cdn?s=this._host():s=this.url(i[Math.abs(this._hash(e))%i.length]);var o=this._extraParams();r.net.get(s+"?q="+encodeURIComponent(e)+(o?"&"+o:""),function(e){n.parseJSON&&(e=JSON.parse(e&&e.responseText)),t&&t(e)})},getTileData:function(e,t,n){this._ready?this._getTileData(e,t,n):this._tileQueue.push([e,t,n])},_setReady:function(e){this._ready=!0,this._processQueue(),this.options.ready&&this.options.ready()},_processQueue:function(){var e;while(e=this._tileQueue.pop())this._getTileData.apply(this,e)},_getTileData:function(e,t,n){var r=i.metric("ProviderJSON:tile_fetch_time").start();this.table=this.options.table;var s=1<<t,o=this.options.column;this.options.is_time&&(o=a("date_part('epoch', {column})",this.options));var u="WITH par AS ( SELECT CDB_XYZ_Resolution({zoom})*{resolution} as res, 256/{resolution} as tile_size, CDB_XYZ_Extent({x}, {y}, {zoom}) as ext ),cte AS ( SELECT ST_SnapToGrid(i.the_geom_webmercator, p.res) g, {countby} c, floor(({column_conv} - {start})/{step}) d FROM ({_sql}) i, par p WHERE i.the_geom_webmercator && p.ext GROUP BY g, d) SELECT (st_x(g)-st_xmin(p.ext))/p.res x__uint8, (st_y(g)-st_ymin(p.ext))/p.res y__uint8, array_agg(c) vals__uint8, array_agg(d) dates__uint16 FROM cte, par p where (st_y(g)-st_ymin(p.ext))/p.res < tile_size and (st_x(g)-st_xmin(p.ext))/p.res < tile_size GROUP BY x__uint8, y__uint8",f=a(u,this.options,{zoom:t,x:e.x,y:e.y,column_conv:o,_sql:this.getSQL()}),l=this;this.sql(f,function(i){if(i){var s=JSON.parse(i.responseText).rows;n(l.proccessTile(s,e,t))}else n(null);r.end()})},getKeySpan:function(){return{start:this.options.start*1e3,end:this.options.end*1e3,step:this.options.step,steps:this.options.steps,columnType:this.options.is_time?"date":"number"}},setColumn:function(e,t){this.options.column=e,this.options.is_time=t===undefined?!0:!1,this.reload()},setResolution:function(e){this.options.resolution=e},setOptions:function(e){var t=!1;e.resolution!==undefined&&e.resolution!==this.options.resolution&&(this.options.resolution=e.resolution,t=!0),e.steps!==undefined&&e.steps!==this.options.steps&&(this.setSteps(e.steps,{silent:!0}),t=!0),e.column!==undefined&&e.column!==this.options.column&&(this.options.column=e.column,t=!0),e.countby!==undefined&&e.countby!==this.options.countby&&(this.options.countby=e.countby,t=!0);if(e.data_aggregation!==undefined){var n=e.data_aggregation==="cumulative";this.options.cumulative!==n&&(this.options.cumulative=n,t=!0)}return t&&this.reload(),t},reload:function(){this._ready=!1,this._fetchKeySpan()},setSQL:function(e){this.options.sql!=e&&(this.options.sql=e,this.reload())},getSteps:function(){return Math.min(this.options.steps,this.options.data_steps)},setSteps:function(e,t){t=t||{},this.options.steps!==e&&(this.options.steps=e,this.options.step=(this.options.end-this.options.start)/this.getSteps(),this.options.step=this.options.step||1,t.silent||this.reload())},getBounds:function(){return this.options.bounds},getSQL:function(){return this.options.sql||"select * from "+this.options.table},_tilerHost:function(){var e=this.options,t=e.user_name||e.user;return e.tiler_protocol+"://"+(t?t+".":"")+e.tiler_domain+(e.tiler_port!=""?":"+e.tiler_port:"")},_fetchUpdateAt:function(e){var t=this,n={version:"1.0.1",stat_tag:this.options.stat_tag||"torque",layers:[{type:"cartodb",options:{cartocss_version:"2.1.1",cartocss:"#layer {}",sql:this.getSQL()}}]},i=this._tilerHost()+"/tiles/layergroup",s=this._extraParams();s&&(s=s.replace("api_key=","map_key=")),i=i+"?config="+encodeURIComponent(JSON.stringify(n))+"&callback=?"+(s?"&"+s:""),r.net.jsonp(i,function(n){var r=a("select * from ({sql}) __torque_wrap_sql limit 0",{sql:t.getSQL()});t.sql(r,function(t){n&&t&&e({updated_at:n.last_updated,fields:t.fields})},{parseJSON:!0})})},_fetchKeySpan:function(){var e=this,t,n,r,i;this._fetchUpdateAt(function(s){if(!s)return;e.options.extra_params=e.options.extra_params||{},e.options.extra_params.last_updated=s.updated_at||0,e.options.extra_params.cache_policy="persist",e.options.is_time=s.fields[e.options.column].type==="date";var o=e.options.column;e.options.is_time?(r="date_part('epoch', max({column}))",i="date_part('epoch', min({column}))",o=a("date_part('epoch', {column})",e.options)):(r="max({column})",i="min({column})"),t=a(r,{column:e.options.column}),n=a(i,{column:e.options.column});var u=" SELECT st_xmax(st_envelope(st_collect(the_geom))) xmax, st_ymax(st_envelope(st_collect(the_geom))) ymax, st_xmin(st_envelope(st_collect(the_geom))) xmin, st_ymin(st_envelope(st_collect(the_geom))) ymin, count(*) as num_steps, {max_col} max_date, {min_col} min_date FROM ({sql}) __torque_wrap_sql ",f=a(u,{max_col:t,min_col:n,column:o,sql:e.getSQL()});e.sql(f,function(t){t=t.rows[0],e.options.start=t.min_date,e.options.end=t.max_date,e.options.step=(t.max_date-t.min_date)/Math.min(e.options.steps,t.num_steps>>0),e.options.data_steps=t.num_steps>>0,e.options.step=e.options.step||1,e.options.bounds=[[t.ymin,t.xmin],[t.ymax,t.xmax]],e._setReady(!0)},{parseJSON:!0,no_cdn:!0})},{parseJSON:!0,no_cdn:!0})}},t.exports=f},{"../":10,"../profiler":17}],20:[function(e,t,n){function f(e,t){for(var n=1;n<arguments.length;++n){var t=arguments[n];for(var r in t)e=e.replace(RegExp("\\{"+r+"\\}","g"),t[r])}return e}var i=e("../"),s=e("../profiler"),o=i.types.Uint8Array,u=i.types.Int32Array,a=i.types.Uint32Array,l=function(e){this.options=e};l.prototype={aggregateByKey:function(e){function t(e){var t=3,n=e.data[2],r={};for(var i=0;i<n;++i)r[e.data[t+i]]=e.data[t+n+i];return r}var n={};for(r=0;r<e.length;++r){var i=t(e[r]);for(var s in i)n[s]=n[s]||0,n[s]+=i[s]}return n},proccessTile:function(e,t,n){function l(e){var t=3,n={x:e.data[0]*f.options.resolution,y:e.data[1]*f.options.resolution,valuesCount:e.data[2],times:[],values:[]};for(var r=0;r<n.valuesCount;++r)n.times.push(e.data[t+r]),n.values.push(e.data[t+n.valuesCount+r]);if(f.options.cumulative)for(var r=1;r<n.valuesCount;++r)n.values[r]+=n.values[r-1];return n}var r,i=new o(e.length),s=new o(e.length),f=this;for(r=0;r<e.length;++r)e[r]=l(e[r]);var c=0,h=0;for(r=0;r<e.length;++r){var p=e[r];c+=p.times.length;for(var d=0;d<p.times.length;++d)h=Math.max(h,p.times[d])}var v=new u(h+1),m=new u(h+1),g=new(this.options.valueDataType||o)(c),y=new a(c),b={};for(var r=0;r<e.length;++r){var p=e[r];i[r]=p.x,s[r]=p.y;var c=p.times,w=p.values;for(var E=0,S=c.length;E<S;++E){var x=b[c[E]]||(b[c[E]]=[]);x.push([r,w[E]])}}var T=0,N=0,C=0;for(var C=0;C<=h;++C){var k=0,L=b[C];if(L)for(var r=0;r<L.length;++r){var x=L[r];++k,y[T]=x[0],g[T]=x[1],++T}v[C]=N,m[C]=k,N+=k}return{x:i,y:s,coord:{x:t.x,y:t.y,z:n},timeCount:m,timeIndex:v,renderDataPos:y,renderData:g}},url:function(){return this.options.url},tileUrl:function(e,t){var n=this.url(),r=(this.options.subdomains||"abcd")[(e.x+e.y+t)%4];return n.replace("{x}",e.x).replace("{y}",e.y).replace("{z}",t).replace("{s}",r)},getTile:function(e,t,n){var r=this.tileUrl(e,t),o=this,u=s.metric("jsonarray:fetch time");u.start(),i.net.get(r,function(e){u.end(),e&&(e=JSON.parse(e.responseText)),n(e)})},getTileData:function(e,t,n){var r=this.tileUrl(e,t),o=this,u=s.metric("jsonarray:fetch time");u.start(),i.net.get(r,function(r){u.end();var i=null,a=s.metric("jsonarray:processing time"),f=s.metric("jsonarray:parsing time");try{a.start(),f.start();var l=JSON.parse(r.responseText||r.response).rows;f.end(),i=o.proccessTile(l,e,t),a.end()}catch(c){console.error("problem parsing JSON on ",e,t)}n(i)})}},t.exports=l},{"../":10,"../profiler":17}],21:[function(e,t,n){function f(e){for(var t=1;t<arguments.length;++t){var n=arguments[t];for(var r in n)e=e.replace(RegExp("\\{"+r+"\\}","g"),n[r])}return e}var r=e("../"),i=e("../profiler"),s=r.types.Uint8Array,o=r.types.Int32Array,u=r.types.Uint32Array,a=r.types.Uint8ClampedArray,l=function(e){this._ready=!1,this._tileQueue=[],this.options=e,this.options.is_time=this.options.is_time===undefined?!0:this.options.is_time,this.options.tiler_protocol=e.tiler_protocol||"http",this.options.tiler_domain=e.tiler_domain||"cartodb.com",this.options.tiler_port=e.tiler_port||80,e.maps_api_template?this.options.maps_api_template=e.maps_api_template:this._buildMapsApiTemplate(this.options),this.options.coordinates_data_type=this.options.coordinates_data_type||s,this.options.data_aggregation&&(this.options.cumulative=this.options.data_aggregation==="cumulative");if(this.options.auth_token){var t=this.options.extra_params||(this.options.extra_params={});t.auth_token=this.options.auth_token}this.options.no_fetch_map||this._fetchMap()};l.prototype={proccessTile:function(e,t,n){var r,s=new this.options.coordinates_data_type(e.length),f=new this.options.coordinates_data_type(e.length),l=i.metric("torque.provider.windshaft.mem"),c=i.metric("torque.provider.windshaft.points"),h=i.metric("torque.provider.windshaft.process_time").start(),p=0,d=-1;for(r=0;r<e.length;++r){var v=e[r];p+=v.dates__uint16.length;for(var m=0;m<v.dates__uint16.length;++m)d=Math.max(d,v.dates__uint16[m])}this.options.cumulative&&(p=(1+d)*e.length);var g=this.options.cumulative?u:a,y=new o(d+1),b=new o(d+1),w=new(this.options.valueDataType||g)(p),E=new u(p);l.inc(4*d+4*d+p+p*4),c.inc(e.length);var S={};for(var r=0;r<e.length;++r){var v=e[r];s[r]=v.x__uint8*this.options.resolution,f[r]=v.y__uint8*this.options.resolution;var p=v.dates__uint16,x=v.vals__uint8;if(!this.options.cumulative)for(var T=0,N=p.length;T<N;++T){var C=S[p[T]]||(S[p[T]]=[]);this.options.cumulative&&(x[T]+=prev_val),prev_val=x[T],C.push([r,x[T]])}else{var k={};for(var T=0,N=p.length;T<N;++T)k[p[T]]=x[T];var L=0;for(var T=p[0];T<=d;++T){var C=S[T]||(S[T]=[]),A=k[T];A&&(L+=A),C.push([r,L])}}}var O=0,M=0,_=0;for(var _=0;_<=d;++_){var D=0,P=S[_];if(P)for(var r=0;r<P.length;++r){var C=P[r];++D,E[O]=C[0],w[O]=C[1],++O}y[_]=M,b[_]=D,M+=D}return h.end(),{x:s,y:f,z:n,coord:{x:t.x,y:t.y,z:n},timeCount:b,timeIndex:y,renderDataPos:E,renderData:w,maxDate:d}},setSteps:function(e,t){t=t||{},this.options.steps!==e&&(this.options.steps=e,this.options.step=(this.options.end-this.options.start)/this.getSteps(),this.options.step=this.options.step||1,t.silent||this.reload())},setOptions:function(e){var t=!1;e.resolution!==undefined&&e.resolution!==this.options.resolution&&(this.options.resolution=e.resolution,t=!0),e.steps!==undefined&&e.steps!==this.options.steps&&(this.setSteps(e.steps,{silent:!0}),t=!0),e.column!==undefined&&e.column!==this.options.column&&(this.options.column=e.column,t=!0),e.countby!==undefined&&e.countby!==this.options.countby&&(this.options.countby=e.countby,t=!0);if(e.data_aggregation!==undefined){var n=e.data_aggregation==="cumulative";this.options.cumulative!==n&&(this.options.cumulative=n,t=!0)}return t&&this.reload(),t},_extraParams:function(e){e=r.extend(r.extend({},e),this.options.extra_params);if(e){var t=[];for(var n in e){var i=e[n];if(i)if(r.isArray(i))for(var s=0,o=i.length;s<o;s++)t.push(n+"[]="+encodeURIComponent(i[s]));else t.push(n+"="+encodeURIComponent(i))}return t.join("&")}return null},getTileData:function(e,t,n){this._ready?this._getTileData(e,t,n):this._tileQueue.push([e,t,n])},_setReady:function(e){this._ready=!0,this._processQueue(),this.options.ready&&this.options.ready()},_processQueue:function(){var e;while(e=this._tileQueue.pop())this._getTileData.apply(this,e)},_getTileData:function(e,t,n){var s=this,o=i.metric("torque.provider.windshaft.tile.fetch").start(),u=this.options.subdomains||"0123",a=Math.pow(2,t),f=(e.x%a+a)%a,l=Math.abs(f+e.y)%u.length,c=this.templateUrl.replace("{x}",f).replace("{y}",e.y).replace("{z}",t).replace("{s}",u[l]),h=this._extraParams();r.net.get(c+(h?"?"+h:""),function(r){o.end();if(r&&r.responseText){var u=JSON.parse(r.responseText);n(s.proccessTile(u,e,t))}else i.metric("torque.provider.windshaft.tile.error").inc(),n(null)})},getKeySpan:function(){return{start:this.options.start,end:this.options.end,step:this.options.step,steps:this.options.steps,columnType:this.options.column_type}},setColumn:function(e,t){this.options.column=e,this.options.is_time=t===undefined?!0:!1,this.reload()},reload:function(){this._ready=!1,this._fetchMap()},getSteps:function(){return Math.min(this.options.steps,this.options.data_steps)},getBounds:function(){return this.options.bounds},getSQL:function(){return this.options.sql||"select * from "+this.options.table},setSQL:function(e){this.options.sql!=e&&(this.options.sql=e,this.reload())},_buildMapsApiTemplate:function(e){var t=e.user_name||e.user;e.maps_api_template=e.tiler_protocol+"://"+(t?"{user}.":"")+e.tiler_domain+(e.tiler_port!=""?":"+e.tiler_port:"")},_tilerHost:function(){var e=this.options,t=e.user_name||e.user;return e.maps_api_template.replace("{user}",t)},url:function(){var e=this.options,t=e.cdn_url,n=!t||t&&!t.http&&!t.https;if(e.no_cdn||n)return this._tilerHost();var r=this.isHttps()?"https":"http",i=r+"://";this.isHttps()||(i+="{s}.");var s=t[r];this._isUserTemplateUrl(s)||(s+="/{user}");var o=e.user_name||e.user;return i+=s.replace("{user}",o),i},_isUserTemplateUrl:function(e){return e&&e.indexOf("{user}")!==-1},isHttps:function(){return this.options.maps_api_template.indexOf("https")===0},_generateCartoCSS:function(){var e={"-torque-frame-count":this.options.steps,"-torque-resolution":this.options.resolution,"-torque-aggregation-function":"'"+this.options.countby+"'","-torque-time-attribute":"'"+this.options.column+"'","-torque-data-aggregation":this.options.cumulative?"cumulative":"linear"},t="Map{";for(var n in e)t+=n+":"+e[n]+";";return t+"}"},_fetchMap:function(e){var t=this,n={},s=this.options.dynamic_cdn?this.url().replace("{s}","0"):this._tilerHost(),o=s+"/api/v1/map",u=this.options.named_map,a={};u?(o=s+"/api/v1/map/named/"+u.name+"/jsonp",typeof u.params!="undefined"&&(n=u.params)):n={version:"1.0.1",stat_tag:this.options.stat_tag||"torque",layers
|
|
:[{type:"torque",options:{cartocss_version:"1.0.0",cartocss:this._generateCartoCSS(),sql:this.getSQL()}}]},this.options.stat_tag&&(a.stat_tag=this.options.stat_tag),extra=this._extraParams(a),extra&&(extra=extra.replace("api_key=","map_key=")),o=o+"?config="+encodeURIComponent(JSON.stringify(n))+"&callback=?"+(extra?"&"+extra:"");var f=i.metric("torque.provider.windshaft.layergroup.time").start();r.net.jsonp(o,function(e){f.end();if(e){if(e.errors){t.options.errorCallback&&t.options.errorCallback(e.errors);return}var n=Object.keys(e.metadata.torque)[0],r=e.metadata.torque[n];for(var s in r)t.options[s]=r[s];if(e.cdn_url){var o=t.options.cdn_url=t.options.cdn_url||{};o.http=e.cdn_url.http||o.http,o.https=e.cdn_url.https||o.https}t.templateUrl=t.url()+"/api/v1/map/"+e.layergroupid+"/"+n+"/{z}/{x}/{y}.json.torque",t._setReady(!0)}else i.metric("torque.provider.windshaft.layergroup.error").inc()},{callbackName:t.options.instanciateCallback})}},t.exports=l},{"../":10,"../profiler":17}],22:[function(e,t,n){function o(e,t){e.fillStyle=t["marker-fill"];var n=t["marker-width"];e.beginPath(),e.arc(0,0,n,0,r,!0,!0),e.closePath(),t["marker-opacity"]!==undefined&&(t["marker-fill-opacity"]=t["marker-line-opacity"]=t["marker-opacity"]),t["marker-fill"]&&(e.globalAlpha=t["marker-fill-opacity"]>=0?t["marker-fill-opacity"]:1,e.globalAlpha>0&&e.fill()),t["marker-line-color"]&&t["marker-line-width"]&&t["marker-line-width"]>i&&(e.globalAlpha=t["marker-line-opacity"]>=0?t["marker-line-opacity"]:1,t["marker-line-width"]!==undefined&&(e.lineWidth=t["marker-line-width"]),e.strokeStyle=t["marker-line-color"],e.globalAlpha>0&&e.stroke())}function u(e,t){e.fillStyle=t["marker-fill"];var n=t["marker-width"],r=n*2;if(t["marker-fill"]){if(t["marker-fill-opacity"]!==undefined||t["marker-opacity"]!==undefined)e.globalAlpha=t["marker-fill-opacity"]||t["marker-opacity"];e.fillRect(-n,-n,r,r)}e.globalAlpha=1,t["marker-line-color"]&&t["marker-line-width"]&&(t["marker-line-opacity"]&&(e.globalAlpha=t["marker-line-opacity"]),t["marker-line-width"]&&(e.lineWidth=t["marker-line-width"]),e.strokeStyle=t["marker-line-color"],e.globalAlpha>0&&e.strokeRect(-n,-n,r,r))}function a(e,t){var n=t["marker-width"],r=t["text-name"],i=t["text-face-name"]?t["text-face-name"]:"Droid Sans Regular",s=t["text-size"]?t["text-size"]:"10px",o=t["text-fill"]?t["text-fill"]:"white";e.fillStyle=o,e.font=s+" "+i,e.fillText(r,-n/2,n/2)}function f(e,t,n){if(t.complete){if(n["marker-fill-opacity"]!==undefined||n["marker-opacity"]!==undefined)e.globalAlpha=n["marker-fill-opacity"]||n["marker-opacity"];e.drawImage(t,0,0,Math.min(t.width,s),Math.min(t.height,s))}}var r=Math.PI*2,i=.05,s=255;t.exports={renderPoint:o,renderSprite:f,renderRectangle:u,renderText:a,MAX_SPRITE_RADIUS:s}},{}],23:[function(e,t,n){t.exports={cartocss:e("./cartocss_render"),Point:e("./point"),Rectangle:e("./rectangle")}},{"./cartocss_render":22,"./point":24,"./rectangle":25}],24:[function(e,t,n){(function(n){function c(e){return l[e]||e}function h(e,t){if(!e)throw new Error("canvas can't be undefined");this.options=t,this._canvas=e,this._ctx=e.getContext("2d"),this._sprites=[],this._shader=null,this._icons={},this._iconsToLoad=0,this._filters=new u(this._canvas,{canvasClass:t.canvasClass}),this.setCartoCSS(this.options.cartocss||f),this.TILE_SIZE=256,this._style=null,this._gradients={},this._forcePoints=!1}var r=e("../"),i=e("./cartocss_render"),s=e("../profiler"),o=n.carto||e("carto"),u=e("./torque_filters"),a=Math.PI*2,f=["#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"),l={src:"source-over","src-over":"source-over","dst-over":"destination-over","src-in":"source-in","dst-in":"destination-in","src-out":"source-out","dst-out":"destination-out","src-atop":"source-atop","dst-atop":"destination-atop",xor:"xor",darken:"darken",lighten:"lighten"};r.extend(h.prototype,r.Event,{clearCanvas:function(){var e=this._canvas,t=this._Map["-torque-clear-color"];if(t==="rgba(255, 255, 255, 0)"||!t)this._canvas.width=this._canvas.width;else{var n=this._ctx;n.setTransform(1,0,0,1,0,0);var r=this._Map["comp-op"];n.globalCompositeOperation=c(r),n.fillStyle=t,n.fillRect(0,0,e.width,e.height)}},setCanvas:function(e){this._canvas=e,this._ctx=e.getContext("2d")},setCartoCSS:function(e){this.setShader((new o.RendererJS).render(e))},setShader:function(e){this._sprites=[],this._shader=e,this._Map=this._shader.getDefault().getStyle({},{zoom:0});var t=this._shader.getImageURLs();this._preloadIcons(t)},clearSpriteCache:function(){this._sprites=[]},generateSprite:function(e,t,n){var o=this,u=s.metric("torque.renderer.point.generateSprite").start(),a=e.getStyle({value:t},n);if(this._style===null||this._style!==a)this._style=a;var f=a["marker-width"];if(!f)return null;if(a["marker-opacity"]===0&&!a["marker-line-opacity"])return null;var l=this._createCanvas(),c=l.getContext("2d"),h=a["marker-file"]||a["point-file"],p=h&&this._qualifyURL(h);if(p&&this._iconsToLoad<=0&&this._icons[p]){var d=this._icons[p],v=Math.min(a["marker-width"]*2||d.width,i.MAX_SPRITE_RADIUS*2),m=Math.min((a["marker-height"]||v)*(d.width/d.height),i.MAX_SPRITE_RADIUS*2);l.width=c.width=v,l.height=c.height=m,c.scale(v/d.width,m/d.height),i.renderSprite(c,d,a)}else{var g=(a["marker-line-width"]||0)+f*2,y=c.width=l.width=c.height=l.height=Math.ceil(g);c.translate(y/2,y/2);var b=a["marker-type"];b&&b==="rectangle"?i.renderRectangle(c,a):i.renderPoint(c,a)}a["text-name"]&&(a["text-name"]=a["text-name"].replace("{{value}}",t),i.renderText(c,a)),u.end(!0);if(r.flags.sprites_to_images){var w=this._createImage();return w.src=l.toDataURL(),w}return l},renderTile:function(e,t,n){if(this._iconsToLoad>0)return this.on("allIconsLoaded",function(){this.renderTile.apply(this,[e,t,n])}),!1;var r=s.metric("torque.renderer.point.renderLayers").start(),i=this._shader.getLayers();for(var o=0,u=i.length;o<u;++o){var a=i[o];if(a.name()!=="Map"){var f=this._sprites[o]||(this._sprites[o]={});for(var l=0;l<a.frames().length;++l){var c=a.frames()[l],h=f[c]||(f[c]=[]);this._renderTile(e,t-c,c,h,a)}}}return r.end(!0),n&&n(null)},_createCanvas:function(){return this.options.canvasClass?new this.options.canvasClass:document.createElement("canvas")},_createImage:function(){return this.options.imageClass?new this.options.imageClass:new Image},_setImageSrc:function(e,t,n){this.options.setImageSrc?this.options.setImageSrc(e,t,n):(e.onload=function(){n(null)},e.onerror=function(){n(new Error("Could not load image"))},e.src=t)},_qualifyURL:function(e){if(typeof this.options.qualifyURL!="undefined")return this.options.qualifyURL(e);var t=document.createElement("a");return t.href=e,t.href},_renderTile:function(e,t,n,i,o,u){if(!this._canvas)return;var a=s.metric("torque.renderer.point.renderTile").start(),f=this._ctx,l=c(o.eval("comp-op"))||this.options.blendmode;l&&(f.globalCompositeOperation=l),this.options.cumulative&&t>e.maxDate&&(t=e.maxDate);var h=this.options.resolution*(this.TILE_SIZE/this.options.resolution-1),p=e.timeCount[t],d=this.options.resolution/2;if(p){var v=e.timeIndex[t];for(var m=0;m<p;++m){var g=e.renderDataPos[v+m],y=e.renderData[v+m];if(y){var b=i[y];b===undefined&&(b=i[y]=this.generateSprite(o,y,r.extend({zoom:e.z,"frame-offset":n},u)));if(b){var w=e.x[g]-(b.width>>1)+d,E=h-e.y[g]+d;f.drawImage(b,w,E-(b.height>>1))}}}}a.end(!0)},setBlendMode:function(e){this.options.blendmode=e},getActivePointsBBox:function(e,t){var n=[],i=new r.Mercator,s=this.options.resolution*(this.TILE_SIZE/this.options.resolution-1),o=e.timeCount[t],u=e.timeIndex[t];for(var a=0;a<o;++a){var f=e.renderDataPos[u+a],l=e.renderData[u+a];if(l){var c=e.x[f],h=s-e.y[f];n.push(i.tilePixelBBox(e.coord.x,e.coord.y,e.coord.z,c,h))}}return n},getValueFor:function(e,t,n,i){var s=new r.Mercator,o=this.options.resolution,u=o>>1,a=this.options.resolution*(this.TILE_SIZE/this.options.resolution-1),f=e.timeCount[t],l=e.timeIndex[t];for(var c=0;c<f;++c){var h=e.renderDataPos[l+c],p=e.renderData[l+c];if(p){var d=e.x[h],v=a-e.y[h],m=n+u-d,g=i+u-v;if(m>=0&&m<o&&g>=0&&g<o)return{value:p,bbox:s.tilePixelBBox(e.coord.x,e.coord.y,e.coord.z,d-u,v-u,o)}}}return null},_preloadIcons:function(e){var t=this;if(e.length>0&&!this._forcePoints){var n=Object.keys(e.reduce(function(e,n){var r=t._qualifyURL(n);return t._icons[r]||(e[r]=!0),e},{})),r=t._shader.getLayers().some(function(e){return typeof e.shader["image-filters"]!="undefined"});this._iconsToLoad+=n.length,n.forEach(function(e){t._icons[e]=null;var n=t._createImage();r&&(n.crossOrigin="Anonymous"),t._setImageSrc(n,e,function(i){i?(t._forcePoints=!0,t.clearSpriteCache(),t._iconsToLoad=0,t.fire("allIconsLoaded"),r&&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 "+e)):(t._icons[e]=n,t._iconsToLoad--,t._iconsToLoad<=0&&(t.clearSpriteCache(),t.fire("allIconsLoaded")))})})}else this.fire("allIconsLoaded")},applyFilters:function(){if(this._style&&this._style["image-filters"]){function e(e){var t="";for(var n=0;n<e.args.length;n++){var r=e.args[n].rgb;t+=r[0]+":"+r[1]+":"+r[2]}return t}var t=this._gradients[e(this._style["image-filters"])];if(!t){function n(e){var t=e.toString(16);return t.length==1?"0"+t:t}function r(e,t,r){return"#"+n(e)+n(t)+n(r)}t={};var i=this._style["image-filters"].args,s=1/i.length;for(var o=0;o<i.length;o++){var u=s*o+s,a=i[o].rgb,f=r(a[0],a[1],a[2]);t[u]=f}this._gradients[e(this._style["image-filters"])]=t}this._filters.gradient(t),this._filters.draw()}}}),t.exports=h}).call(this,typeof global!="undefined"?global:typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{"../":10,"../profiler":17,"./cartocss_render":22,"./torque_filters":26,carto:undefined}],25:[function(e,t,n){(function(n){function o(e,t){this.options=t,r.tree.Reference.set(torque["torque-reference"]),this.setCanvas(e),this.setCartoCSS(this.options.cartocss||i)}var r=n.carto||e("carto"),i=["#layer {"," polygon-fill: #FFFF00;"," [value > 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"),s=Math.PI*2;o.prototype={setCartoCSS:function(e){this._cartoCssStyle=(new r.RendererJS).render(e);if(this._cartoCssStyle.getLayers().length>1)throw new Error("only one CartoCSS layer is supported");this._shader=this._cartoCssStyle.getLayers()[0].shader},setCanvas:function(e){if(!e)return;this._canvas=e,this._ctx=e.getContext("2d")},accumulate:function(e,t){var n=Profiler.metric("RectangleRender:accumulate").start(),r,i,s,o,u,a,f,l,c=this.options.resolution,h=256/c,p=new Float32Array(h*h);typeof t!="object"&&(t=[t]);for(u=0;u<t.length;++u){a=t[u],f=e.timeCount[a];if(f){l=e.timeIndex[a];for(o=0;o<f;++o)s=e.renderDataPos[l+o],r=e.x[s]/c,i=e.y[s]/c,p[r*h+i]+=e.renderData[l+o]}}return n.end(),p},renderTileAccum:function(e,t,n){var r=Profiler.metric("RectangleRender:renderTileAccum").start(),i,s,o,u,a=this.options.resolution,f=this._ctx,l=256/a|0,c=l*l,h=this._colors;this.options.blendmode&&(f.globalCompositeOperation=this.options.blendmode);var p=this._shader["polygon-opacity"]||function(){return 1};for(var d=0;d<c;++d){var v=d,m=e[d];m&&(s=v/l|0,o=v%l,i=this._shader["polygon-fill"]({value:m},{zoom:0}),f.fillStyle=i,u=p({value:m},{zoom:0}),u===null&&(u=1),f.globalAlpha=u,f.fillRect(s*a,256-a-o*a,a,a))}r.end()},renderTile:function(e,t,n){if(!this._canvas)return;var r=this.options.resolution,i=this._ctx,s=this._colors,o=e.timeCount[t];if(o){var u=this._canvas.width,a=this._canvas.height,f=e.timeIndex[t];for(var l=0;l<activePixels;++l){var c=e.renderDataPos[f+l],h=e.renderData[f+l];if(h){var p=s[Math.min(h,s.length-1)],d=e.x[c],v=e.y[c];i.fillStyle=p,i.fillRect(d,v,r,r)}}}return n&&n(null)}},t.exports=o}).call(this,typeof global!="undefined"?global:typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{carto:undefined}],26:[function(e,t,n){"use strict";function r(e,t){if(!(this instanceof r))return new r(e,t);t=t||{},this._canvas=e=typeof e=="string"?document.getElementById(e):e,this._ctx=e.getContext("2d"),this._width=e.width,this._height=e.height,this._max=1,this._data=[],this.canvasClass=t.canvasClass}r.prototype={defaultGradient:{.4:"blue",.6:"cyan",.7:"lime",.8:"yellow",1:"red"},gradient:function(e){var t=this._createCanvas(),n=t.getContext("2d"),r=n.createLinearGradient(0,0,0,256);t.width=1,t.height=256;for(var i in e)r.addColorStop(+i,e[i]);return n.fillStyle=r,n.fillRect(0,0,1,256),this._grad=n.getImageData(0,0,1,256).data,this},draw:function(){this._grad||this.gradient(this.defaultGradient);var e=this._ctx,t=e.getImageData(0,0,this._canvas.width,this._canvas.height);return this._colorize(t.data,this._grad),e.putImageData(t,0,0),this},_colorize:function(e,t){for(var n=3,r=e.length,i;n<r;n+=4)i=e[n]*4,i&&(e[n-3]=t[i],e[n-2]=t[i+1],e[n-1]=t[i+2])},_createCanvas:function(){return this.canvasClass?new this.canvasClass:document.createElement("canvas")}},t.exports=r},{}],27:[function(e,t,n){(function(n){function s(e,t,n){function u(){i.removeChild(s),clearTimeout(a),delete window[o]}n=n||{},n.timeout=n.timeout===undefined?1e4:n.timeout;var i=document.getElementsByTagName("head")[0],s=document.createElement("script"),o=n.callbackName||"torque_"+Date.now();r.isFunction(o)&&(o=o()),window[o]=function(){u(),t.apply(window,arguments)};var a=setTimeout(function(){u(),t.call(window,null)},n.timeout);e=e.replace("callback=?","callback="+o),s.type="text/javascript",s.src=e,s.async=!0,setTimeout(function(){i.appendChild(s)},0)}function o(e,t,r){function u(){var e=o.status,n,i=r.responseType==="arraybuffer"?o.response:o.responseText;!e&&i||e>=200&&e<300||e===304?t(o):t(null)}r=r||{method:"GET",data:null,responseType:"text"},i={url:e,callback:t};var s=XMLHttpRequest;n.XDomainRequest&&!("withCredentials"in s)&&/^(http(s)?:)?\/\//.test(e)&&(s=XDomainRequest);var o=new s;return o.open(r.method,e,!0),"onload"in o?o.onload=o.onerror=u:o.onreadystatechange=function(){o.readyState>3&&u()},o.onprogress=function(){},o.responseType=r.responseType,r.data&&(o.setRequestHeader("Content-type","application/json"),o.setRequestHeader("Accept","*")),o.send(r.data),o}function u(e,t,n){return o(e,n,{data:t,method:"POST"})}var r=e("./core"),i=null;t.exports={get:o,post:u,jsonp:s,lastCall:function(){return i}}}).call(this,typeof global!="undefined"?global:typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{"./core":4}]},{},[10])(10)}); |