cesium-examples/map/2d/build/release/baidu-map-lineGradient.min.js

1 line
7.5 KiB
JavaScript
Raw Normal View History

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.LineGradient=e()}(this,function(){"use strict";function u(t){this.options=t||{},this.paneName=this.options.paneName||"labelPane",this.zIndex=this.options.zIndex||0,this._map=t.map,this._lastDrawTime=null,this.show()}(u.prototype=new BMap.Overlay).initialize=function(t){this._map=t;var e=this.canvas=document.createElement("canvas"),i=this.ctx=this.canvas.getContext("2d");e.style.cssText="position:absolute;left:0;top:0;z-index:"+this.zIndex+";",this.adjustSize(),this.adjustRatio(i),t.getPanes()[this.paneName].appendChild(e);var n=this;return t.addEventListener("resize",function(){n.adjustSize(),n._draw()}),this.canvas},u.prototype.adjustSize=function(){var t=this._map.getSize(),e=this.canvas;e.width=t.width,e.height=t.height,e.style.width=e.width+"px",e.style.height=e.height+"px"},u.prototype.adjustRatio=function(t){var e=t.backingStorePixelRatio||t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1,i=(window.devicePixelRatio||1)/e,n=t.canvas.width,o=t.canvas.height;t.canvas.width=n*i,t.canvas.height=o*i,t.canvas.style.width=n+"px",t.canvas.style.height=o+"px",t.scale(i,i)},u.prototype.draw=function(){var t=this;clearTimeout(t.timeoutID),t.timeoutID=setTimeout(function(){t._draw()},15)},u.prototype._draw=function(){var t=this._map,e=t.getSize(),i=t.getCenter();if(i){var n=t.pointToOverlayPixel(i);this.canvas.style.left=n.x-e.width/2+"px",this.canvas.style.top=n.y-e.height/2+"px",this.dispatchEvent("draw"),this.options.update&&this.options.update.call(this)}},u.prototype.getContainer=function(){return this.canvas},u.prototype.show=function(){this.canvas||this._map.addOverlay(this),this.canvas.style.display="block"},u.prototype.hide=function(){this.canvas.style.display="none"},u.prototype.setZIndex=function(t){this.canvas.style.zIndex=t},u.prototype.getZIndex=function(){return this.zIndex};var r={merge:function(e,i){Object.keys(e).forEach(function(t){i[t]=e[t]})},getDistance:function(t,e){return Math.sqrt((t[0]-e[0])*(t[0]-e[0])+(t[1]-e[1])*(t[1]-e[1]))},containStroke:function(t,e,i,n,o,a,s){if(0===o)return!1;var l=o,r=0;if(e+l<s&&n+l<s||s<e-l&&s<n-l||t+l<a&&i+l<a||a<t-l&&a<i-l)return!1;if(t===i)return Math.abs(a-t)<=l/2;var h=(r=(e-n)/(t-i))*a-s+(t*n-i*e)/(t-i);return h*h/(r*r+1)<=l/2*l/2},isPointInRect:function(t,e){var i=e.wn,n=e.es;return t.x>=i.x&&t.x<=n.x&&t.y>=i.y&&t.y<=n.y},isPointInCircle:function(t,e,i){return this.getDistanceNew(t,e)<=i},getDistanceNew:function(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}},e="undefined"==typeof window?{}:window,f=e.requestAnimationFrame||e.mozRequestAnimationFrame||e.webkitRequestAnimationFrame||e.msRequestAnimationFrame||function(t){return e.setTimeout(t,1e3/60)},t=function(i,t){var o=this;o.map=i,o.lines=[],o.pixelList=[];var a={lineWidth:1},n=null,s=null,l=!0,r=i.getSize().width,h=i.getSize().height;function p(t){this.name=t.name,this.label=t.label,this.labelColor=t.labelColor,this.path=t.path,this.step=0}p.prototype.getPointList=function(){var e=[],t=this.path;return t&&0<t.length&&t.forEach(function(t){e.push({code:t.code,name:t.name,location:t.location,pixel:i.pointToPixel(t.location),height:t.height,value:t.value,time:t.time,color:t.color})}),e},p.prototype.draw=function(t){for(var e=this.pixelList||this.getPointList(),i=0,n=e.length;i<n-1;i++)t.save(),t.beginPath(),t.lineWidth=a.lineWidth,t.strokeStyle=e[i].color,t.moveTo(e[i].pixel.x,e[i].pixel.y),t.lineTo(e[i+1].pixel.x,e[i+1].pixel.y),t.stroke(),t.closePath(),t.restore();var o=e[e.length-1];t.font="bold 14px Arial",t.textAlign="left",t.textBaseline="middle",t.fillStyle=this.labelColor,t.fillText(this.label,o.pixel.x,o.pixel.y)},p.prototype.drawMoveCircle=function(t){var e=this.pixelList||this.getPointList();t.save(),t.fillStyle="#fff",t.shadowColor="#fff",t.shadowBlur=5,t.beginPath(),t.arc(e[this.step].pixel.x,e[this.step].pixel.y,3,0,2*Math.PI,!0),t.fill(),t.closePath(),t.res