torque/dist/torque.js

3 lines
84 KiB
JavaScript
Raw Normal View History

2015-10-21 21:56:01 +08:00
!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
2015-11-06 19:49:42 +08:00
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!="undefi
);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_te