torque/dist/torque.js

3 lines
71 KiB
JavaScript
Raw Normal View History

2014-12-19 18:01:04 +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.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()},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},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._time=0,this.options.loop||this.stop()),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-valu
_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},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){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,
,"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"};c.prototype={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=l(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})},clearSpriteCache:function(){this._sprites=[]},generateSprite:function(e,t,n){var o=s.metric("torque.renderer.point.generateSprite").start(),u=e.getStyle({value:t},n),a=u["marker-width"];if(!a)return null;if(u["marker-opacity"]===0&&!u["marker-line-opacity"])return null;var f=this._createCanvas(),l=(u["marker-line-width"]||0)+a*2,c=f.getContext("2d"),h=c.width=f.width=c.height=f.height=Math.ceil(l);c.translate(h/2,h/2);if(u["point-file"]||u["marker-file"])i.renderSprite(c,u);else{var p=u["marker-type"];p&&p==="rectangle"?i.renderRectangle(c,u):i.renderPoint(c,u)}o.end(!0);if(r.flags.sprites_to_images){var d=this._createImage();return d.src=f.toDataURL(),d}return f},renderTile:function(e,t){var n=s.metric("torque.renderer.point.renderLayers").start(),r=this._shader.getLayers();for(var i=0,o=r.length;i<o;++i){var u=r[i];if(u.name()!=="Map"){var a=this._sprites[i]||(this._sprites[i]={});for(var f=0;f<u.frames().length;++f){var l=u.frames()[f],c=a[l]||(a[l]=[]);this._renderTile(e,t-l,l,c,u)}}}n.end(!0)},_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},_renderTile:function(e,t,n,i,o,u){if(!this._canvas)return;var a=s.metric("torque.renderer.point.renderTile").start(),f=this._ctx,c=l(o.eval("comp-op"))||this.options.blendmode;c&&(f.globalCompositeOperation=c),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];if(p){var d=e.timeIndex[t];for(var v=0;v<p;++v){var m=e.renderDataPos[d+v],g=e.renderData[d+v];if(g){var y=i[g];y===undefined&&(y=i[g]=this.generateSprite(o,g,r.extend({zoom:e.z,"frame-offset":n},u)));if(y){var b=e.x[m]-(y.width>>1),w=h-e.y[m];f.drawImage(y,b,w-(y.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}},t.exports=c}).call(this,typeof global!="undefined"?global:typeof self!="undefined"?self:typeof window!="undefined"?window:{})},{"../":10,"../profiler":17,"./cartocss_render":22,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; }"," [va