1 line
29 KiB
JavaScript
1 line
29 KiB
JavaScript
(function(e){function r(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._animFrame=null,this._time=0,this.domain=s(this.options.animationDelay,this.options.animationDelay,this.options.animationDuration),this.range=o(0,this.options.steps)}function i(e,t){return function(n){return Math.max(Math.min(n,t),e)}}function s(e,t){var n=i(0,1);return function(r){return n((r-e)/(t-e))}}function o(e,t){var n=i(e,t);return function(r){return n(e*(1-r)+r*t)}}var t=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,n=window.requestAnimationFrame||window.mozCancelAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame;r.prototype={start:function(){this.running=!0,this._animFrame=t(this._tick)},stop:function(){this.running=!0,n(this._animFrame)},_tick:function(){var e=+(new Date),n=(e-this._t0)*.001;this._t0=e,this._time+=n,this.callback(this.range(this.domain(this._time))),this._animFrame=t(this._tick)}}})(typeof exports=="undefined"?this:exports),function(e){e.torque=e.torque||{};var t={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"]}},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"}},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"}},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]}};e.torque["torque-reference"]={version:{latest:t,"1.0.0":t}}}(typeof exports=="undefined"?this:exports),function(e){function n(){}function r(e){this.t0=null,this.name=e,this.count=0}var t=1024;n.metrics={},n.get=function(e){return n.metrics[e]||{max:0,min:1e7,avg:0,total:0,count:0,history:typeof Float32Array!="undefined"?new Float32Array(t):[]}},n.new_value=function(e,r){var i=n.metrics[e]=n.get(e);i.max=Math.max(i.max,r),i.min=Math.min(i.min,r),i.total+=r,++i.count,i.avg=i.total/i.count,i.history[i.count%t]=r},n.print_stats=function(){for(k in n.metrics){var e=n.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)}},r.prototype={start:function(){this.t0=+(new Date)},_elapsed:function(){return+(new Date)-this.t0},end:function(){this.t0!==null&&(n.new_value(this.name,this._elapsed()),this.t0=null)},inc:function(e){e=e===undefined?1:e,n.new_value(this.name,n.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&&(n.new_value(this.name,this.count),this.count=0,this.start())}},n.metric=function(e){return new r(e)},e.Profiler=n}(typeof exports=="undefined"?this:exports),function(e){function n(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}e.torque=e.torque||{};var t=e.torque.providers=e.torque.providers||{},r=function(e){this._ready=!1,this._tileQueue=[],this.options=e;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.getKeySpan():this._ready=!0};r.prototype={proccessTile:function(e,t,n){var r=new Uint8Array(e.length),i=new Uint8Array(e.length),s=0,o=0;for(var u=0;u<e.length;++u){var a=e[u];s+=a.dates__uint16.length,o=Math.max(o,a.dates__uint16.length)}var f=new Int32Array(o),l=new Int32Array(o),c=new Uint8Array(s),h=new Uint32Array(s),p=[];for(var u=0;u<e.length;++u){var a=e[u];r[u]=a.x__uint8,i[u]=a.y__uint8;var s=e[u].dates__uint16,d=e[u].vals__uint8;for(var v=0,m=s.length;v<m;++v){var g=p[s[v]]||(p[s[v]]=[]);g.push([u,d[v]])}}var y=0,b=0;for(var w=0;w<o;++w){var E=0,S=p[w];if(S)for(var u=0;u<S.length;++u){var g=S[u];++E,h[y]=g[0],c[y]=g[1],++y}f[w]=b,l[w]=E,b+=E}return{x:r,y:i,coord:{x:t.x,y:t.y,z:n},timeCount:l,timeIndex:f,renderDataPos:h,renderData:c}},url:function(){return this.options.url||"http://"+this.options.user+".cartodb.com/api/v2/sql"},sql:function(e,t,n){n=n||{},torque.net.get(this.url()+"?q="+encodeURIComponent(e),function(e){n.parseJSON&&(e=JSON.parse(e.responseText)),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()},_processQueue:function(){var e;while(e=this._tileQueue.pop())this._getTileData.apply(this,e)},_getTileData:function(e,t,r){this.table=this.options.table;var i=1<<t,s=this.options.column;this.options.is_time&&(s=n("date_part('epoch', {column})",this.options));var o="WITH par AS ( SELECT CDB_XYZ_Resolution({zoom})*{resolution} as res, 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 {table} i, par p WHERE i.the_geom_webmercator && p.ext GROUP BY g, d) SELECT least((st_x(g)-st_xmin(p.ext))/p.res, 255) x__uint8, least((st_y(g)-st_ymin(p.ext))/p.res, 255) y__uint8, array_agg(c) vals__uint8, array_agg(d) dates__uint16 FROM cte, par p GROUP BY x__uint8, y__uint8",u=n(o,this.options,{zoom:t,x:e.x,y:e.y,column_conv:s}),a=this;this.sql(u,function(n){var i=JSON.parse(n.responseText).rows;r(a.proccessTile(i,e,t))})},getKeySpan:function(){var e,t,r,i;this.options.is_time?(r="date_part('epoch', max({column}))",i="date_part('epoch', min({column}))"):(r="max({0})",i="min({0})"),e=n(r,{column:this.options.column}),t=n(i,{column:this.options.column});var s=n("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, {max_col} max, {min_col} min FROM {table}",{max_col:e,min_col:t,table:this.options.table}),o=this;this.sql(s,function(e){e=e.rows[0],o.options.start=e.min,o.options.step=(e.max-e.min)/o.options.steps,o._setReady(!0)},{parseJSON:!0})}},torque.providers.json=r}(typeof exports=="undefined"?this:exports),function(e){function n(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}e.torque=e.torque||{};var t=e.torque.providers=e.torque.providers||{},i=function(e){this.options=e};i.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 u(e){var t=3,n={x:e.data[0]*o.options.resolution,y:e.data[1]*o.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(o.options.cummulative)for(var r=1;r<n.valuesCount;++r)n.values[r]+=n.values[r-1];return n}var r,i=new Uint8Array(e.length),s=new Uint8Array(e.length),o=this;for(r=0;r<e.length;++r)e[r]=u(e[r]);var a=0,f=0;for(r=0;r<e.length;++r){var l=e[r];a+=l.times.length;for(var c=0;c<l.times.length;++c)f=Math.max(f,l.times[c])}var h=new Int32Array(f+1),p=new Int32Array(f+1),d=new Uint8Array(a),v=new Uint32Array(a),m={};for(var r=0;r<e.length;++r){var l=e[r];i[r]=l.x,s[r]=l.y;var a=l.times,g=l.values;for(var y=0,b=a.length;y<b;++y){var w=m[a[y]]||(m[a[y]]=[]);w.push([r,g[y]])}}var E=0,S=0,x=0;for(var x=0;x<=f;++x){var T=0,N=m[x];if(N)for(var r=0;r<N.length;++r){var w=N[r];++T,v[E]=w[0],d[E]=w[1],++E}h[x]=S,p[x]=T,S+=T}return{x:i,y:s,coord:{x:t.x,y:t.y,z:n},timeCount:p,timeIndex:h,renderDataPos:v,renderData:d}},url:function(){return this.options.url},getTile:function(e,t,n){var r=this.url();r=r.replace("{x}",e.x).replace("{y}",e.y).replace("{z}",t);var i=this,s=Profiler.metric("jsonarray:fetch time");s.start(),torque.net.get(r,function(e){s.end(),e&&(e=JSON.parse(e.responseText)),n(e)})},getTileData:function(e,t,n){var r=this.url();r=r.replace("{x}",e.x).replace("{y}",e.y).replace("{z}",t);var i=this,s=Profiler.metric("jsonarray:fetch time");s.start(),torque.net.get(r,function(r){s.end();var o=null,u=Profiler.metric("jsonarray:processing time");try{u.start();var a=JSON.parse(r.responseText).rows;o=i.proccessTile(a,e,t),u.end()}catch(f){u.end(),console.error("problem parsing JSON on ",e,t)}o&&n(o)})}},torque.providers.JsonArray=i}(typeof exports=="undefined"?this:exports),function(e){function n(e,t){var n=new XMLHttpRequest;return n.onreadystatechange=function(){n.readyState==4&&(n.status==200?t(n):t(null))},n.open("GET",e,!0),n.send(null),n}var t=e.torque=e.torque||{};t.net=t.net||{},t.net={get:n}}(typeof exports=="undefined"?this:exports),function(e){function n(e,n){e.fillStyle=n.fillStyle,e.strokStyle=n.strokStyle;var r=n["point-radius"];e.beginPath(),e.arc(0,0,r,0,t,!0,!0),e.closePath(),n.fillStyle&&(n.fillOpacity&&(e.globalAlpha=n.fillOpacity),e.fill()),e.globalAlpha=1,n.strokeStyle&&(n.strokeOpacity&&(e.globalAlpha=n.strokeOpacity),n.lineWidth&&(e.lineWidth=n.lineWidth),e.strokeStyle=n.strokeStyle,e.stroke())}function r(e,t){var n=t["point-file"]||t["marker-file"],r=n.height/n.width,i=t["point-radius"]||n.width,s=t["point-radius"]||t["marker-height"]||i*r;e.drawImage(n,0,0,i,s)}e.torque=e.torque||{};var t=Math.PI*2;e.torque.cartocss=e.torque.cartocss||{},e.torque.cartocss={renderPoint:n,renderSprite:r}}(typeof exports=="undefined"?this:exports),function(e){function r(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.setCartoCSS(this.options.cartocss||n)}e.torque=e.torque||{},e.torque.renderer=e.torque.renderer||{};var t=Math.PI*2,n=["#layer {"," marker-fill: #662506;"," marker-width: 20;"," [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");r.prototype={setCanvas:function(e){this._canvas=e,this._ctx=e.getContext("2d")},setCartoCSS:function(e){this._sprites={},this._cartoCssStyle=(new carto.RendererJS).render(e);if(this._cartoCssStyle.getLayers().length>1)throw new Error("only one CartoCSS layer is supported");this._shader=this._cartoCssStyle.getLayers()[0]},generateSprite:function(e,t){var n=this._shader.getStyle("canvas-2d",{value:e},{zoom:t.zoom}),r=n["point-radius"];if(!r)throw new Error("marker-width property should be set");var i=r*2,s=document.createElement("canvas"),o=s.getContext("2d");return o.width=s.width=i,o.height=s.height=i,o.translate(r,r),n["point-file"]||n["marker-fil"]?torque.cartocss.renderSprite(o,n):torque.cartocss.renderPoint(o,n),s},renderTile:function(e,t){if(!this._canvas)return;var n=this._ctx,r=this.options.resolution,i=this._sprites,s=e.timeCount[t];this.options.blendmode&&(n.globalCompositeOperation=this.options.blendmode);if(s){var o=e.timeIndex[t];for(var u=0;u<s;++u){var a=e.renderDataPos[o+u],f=e.renderData[o+u];if(f){var l=i[f];l||(l=i[f]=this.generateSprite(f,e));var c=e.x[a]-(l.width>>1),h=e.y[a]-(l.height>>1);n.drawImage(l,c*r,255-h*r)}}}}},e.torque.renderer.Point=r}(typeof exports=="undefined"?this:exports),function(e){function r(e,n){this.options=n,carto.tree.Reference.set(torque["torque-reference"]),this.setCanvas(e),this.setCartoCSS(this.options.cartocss||t)}e.torque=e.torque||{},e.torque.renderer=e.torque.renderer||{};var t=["#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"),n=Math.PI*2;r.prototype={setCartoCSS:function(e){this._cartoCssStyle=(new carto.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,r,i,s,o,u,a,f,l=this.options.resolution,c=256/l,h=new Float32Array(c*c);typeof t!="object"&&(t=[t]);for(o=0;o<t.length;++o){u=t[o],a=e.timeCount[u];if(a){f=e.timeIndex[u];for(s=0;s<a;++s)i=e.renderDataPos[f+s],n=e.x[i]/l,r=e.y[i]/l,h[n*c+r]+=e.renderData[f+s]}}return h},renderTileAccum:function(e,t,n){var r,i,s,o=this.options.resolution,u=this._ctx,a=256/o|0,f=a*a,l=this._colors;for(var c=0;c<f;++c){var h=c,p=e[c];p&&(i=h/a|0,s=h%a,r=this._shader["polygon-fill"]({value:p},{zoom:0}),u.fillStyle=r,u.fillRect(i*o,256-o-s*o,o,o))}},renderTile:function(e,t,n,r){if(!this._canvas)return;var i=this.options.resolution,s=this._ctx,o=this._colors,u=e.timeCount[t];if(u){var a=this._canvas.width,f=this._canvas.height,l=e.timeIndex[t];for(var c=0;c<activePixels;++c){var h=e.renderDataPos[l+c],p=e.renderData[l+c];if(p){var d=o[Math.min(p,o.length-1)],v=e.x[h],m=e.y[h];s.fillStyle=d,s.fillRect(v,m,i,i)}}}}},e.torque.renderer.Rectangle=r}(typeof exports=="undefined"?this:exports);if(typeof google!="undefined"&&typeof google.maps!="undefined"){function CanvasLayer(e){function n(e,t){return function(){t.apply(e)}}this.isAdded_=!1,this.isAnimated_=!1,this.paneName_=CanvasLayer.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)}CanvasLayer.prototype=new google.maps.OverlayView,CanvasLayer.DEFAULT_PANE_NAME_="overlayLayer",CanvasLayer.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]}(),CanvasLayer.prototype.requestAnimFrame_=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(e){return window.setTimeout(e,1e3/60)},CanvasLayer.prototype.cancelAnimFrame_=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||function(e){},CanvasLayer.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.map!==undefined&&this.setMap(e.map)},CanvasLayer.prototype.setAnimate=function(e){this.isAnimated_=!!e,this.isAnimated_&&this.scheduleUpdate()},CanvasLayer.prototype.isAnimated=function(){return this.isAnimated_},CanvasLayer.prototype.setPaneName=function(e){this.paneName_=e,this.setPane_()},CanvasLayer.prototype.getPaneName=function(){return this.paneName_},CanvasLayer.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)},CanvasLayer.prototype.setResizeHandler=function(e){this.resizeHandler_=e},CanvasLayer.prototype.setUpdateHandler=function(e){this.updateHandler_=e},CanvasLayer.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_()},CanvasLayer.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)},CanvasLayer.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()},CanvasLayer.prototype.draw=function(){this.repositionCanvas_()},CanvasLayer.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_);this.canvas.style[CanvasLayer.CSS_TRANSFORM_]="translate("+Math.round(n.x)+"px,"+Math.round(n.y)+"px)",this.scheduleUpdate()},CanvasLayer.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_()},CanvasLayer.prototype.getTopLeft=function(){return this.topLeft_},CanvasLayer.prototype.scheduleUpdate=function(){this.isAdded_&&!this.requestAnimationFrameId_&&(this.requestAnimationFrameId_=this.requestAnimFrame_.call(window,this.requestUpdateFunction_))}}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},initialize:function(e){var t=this;this.render=this.render.bind(this),L.Util.setOptions(this,e),this._canvas=document.createElement("canvas"),this._ctx=this._canvas.getContext("2d");var n=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame;this.requestAnimationFrame=n},onAdd:function(e){this._map=e,this._staticPane=e._createPane("leaflet-tile-pane",e._container),this._staticPane.appendChild(this._canvas),e.on({viewreset:this._reset},this),e.on("move",this._render,this),this.options.tileLoader&&this._initTileLoader(),this._reset()},getCanvas:function(){return this._canvas},draw:function(){return this._reset()},onRemove:function(e){e._container.removeChild(this._staticPane),e.off({viewreset:this._reset,move:this._render},this)},addTo:function(e){return e.addLayer(this),this},setOpacity:function(e){return this.options.opacity=e,this._updateOpacity(),this},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,this.onResize(),this._render()},_updateOpacity:function(){},_render:function(){this.requestAnimationFrame.call(window,this.render)},redraw:function(){this._render()},onResize:function(){},render:function(){throw new Error("render function should be implemented")}}),L.Mixin.TileLoader={_initTileLoader:function(){this._tiles={},this._tilesToLoad=0,this._map.on({moveend:this._updateTiles},this),this._updateTiles()},_removeTileLoader:function(){map.off({moveend:this._updateTiles},this)},_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)},_removeOtherTiles:function(e){var t,n,r,i;for(i in this._tiles)this._tiles.hasOwnProperty(i)&&(t=i.split(":"),n=parseInt(t[0],10),r=parseInt(t[1],10),(n<e.min.x||n>e.max.x||r<e.min.y||r>e.max.y)&&this._removeTile(i))},_removeTile:function(e){this.fire("tileRemoved",this._tiles[e]),delete this._tiles[e]},_tileShouldBeLoaded:function(e){return!(e.x+":"+e.y+":"+e.zoom in this._tiles)},_tileLoaded:function(e,t){this._tilesToLoad--,this._tiles[e.x+":"+e.y+":"+e.zoom]=t,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++)this.fire("tileAdded",t[s])}},L.TorqueLayer=L.CanvasLayer.extend({providers:{sql_api:torque.providers.json,url_template:torque.providers.jsonarray},renderers:{point:torque.renderer.Point,pixel:torque.renderer.Rectangle},initialize:function(e){var t=this;e.tileLoader=!0,this.key=0,L.CanvasLayer.prototype.initialize.call(this,e),this.options.renderer=this.options.renderer||"point",this.provider=new this.providers[this.options.provider](e),this.renderer=new this.renderers[this.options.renderer](this.getCanvas(),e),this.on("tileAdded",function(e){var n=this.provider.getTileData(e,e.zoom,function(n){t._tileLoaded(e,n),t.redraw()})},this)},render:function(){var e,t,n,r=this.getCanvas();r.width=r.width;var i=r.getContext("2d");if(typeof this.key=="number")for(e in this._tiles)t=this._tiles[e],n=this.getTilePos(t.coord),i.setTransform(1,0,0,1,n.x,n.y),this.renderer.renderTile(t,this.key,n.x,n.y);else for(e in this._tiles){t=this._tiles[e],n=this.getTilePos(t.coord);var s=this.renderer.accumulate(t,this.key);i.setTransform(1,0,0,1,n.x,n.y),this.renderer.renderTileAccum(s,0,0)}},setKey:function(e){this.key=e,this.redraw()}}),L.TiledTorqueLayer=L.TileLayer.Canvas.extend({providers:{sql_api:torque.providers.json,url_template:torque.providers.JsonArray},renderers:{point:torque.renderer.Point,pixel:torque.renderer.Rectangle},initialize:function(e){var t=this;this.key=0,e.async=!0,L.TileLayer.Canvas.prototype.initialize.call(this,e),this.options.renderer=this.options.renderer||"pixel",this.provider=new this.providers[this.options.provider](e),this.renderer=new this.renderers[this.options.renderer](null,e)},_tileLoaded:function(e,t,n){this._tiles[t.x+":"+t.y]!==undefined&&(this._tiles[t.x+":"+t.y].data=n,this.drawTile(e)),L.TileLayer.Canvas.prototype._tileLoaded.call(this)},redraw:function(){for(var e in this._tiles)this._redrawTile(this._tiles[e])},_loadTile:function(e,t){var n=this;L.TileLayer.Canvas.prototype._loadTile.apply(this,arguments),this.provider.getTileData(t,this._map.getZoom(),function(r){n._tileLoaded(e,t,r),L.DomUtil.addClass(e,"leaflet-tile-loaded")})},drawTile:function(e){var t=e;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()}}); |