text: !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).windLayer=e()}(this,function(){"use strict";function l(c){void 0===c&&(c={}),this.params=c;var T=this;function e(t){t.projection||(t.projection="EPSG:4326"),T.MIN_VELOCITY_INTENSITY=t.minVelocity||0,T.MAX_VELOCITY_INTENSITY=t.maxVelocity||10,T.VELOCITY_SCALE=(t.velocityScale||.005)*(Math.pow(window.devicePixelRatio,1/3)||1),T.MAX_PARTICLE_AGE=t.particleAge||90,T.PARTICLE_LINE_WIDTH=t.lineWidth||1,T.PARTICLE_MULTIPLIER=t.particleMultiplier||1/300,T.PARTICLE_REDUCTION=Math.pow(window.devicePixelRatio,1/3)||1.6,T.FRAME_RATE=t.frameRate||16,T.COLOR_SCALE=t.colorScale||a,T.OVERLAY_COLOR_SCALE=t.overlayColorScale||n,T.OVERLAY_ALPHA=Math.floor(153)}T.canvas=c.canvas;var a=["rgb(36,104, 180)","rgb(60,157, 194)","rgb(128,205,193 )","rgb(151,218,168 )","rgb(198,231,181)","rgb(238,247,217)","rgb(255,238,159)","rgb(252,217,125)","rgb(255,182,100)","rgb(252,150,75)","rgb(250,112,52)","rgb(245,64,32)","rgb(237,45,28)","rgb(220,24,32)","rgb(180,0,35)"],n=[[193,[37,4,42]],[206,[41,10,130]],[219,[81,40,40]],[233.15,[192,37,149]],[255.372,[70,215,215]],[273.15,[21,84,187]],[275.15,[24,132,14]],[291,[247,251,59]],[298,[235,167,21]],[311,[230,71,39]],[328,[88,27,67]]];function i(t,e,a,n,i,r){var o=1-t,h=1-e;return a*o*h+n*t*h+i*o*e+r*t*e}function r(t,e,a,n,i,r){var o=1-t,h=1-e,s=o*h,u=t*h,l=o*e,c=t*e,d=a[0]*s+n[0]*u+i[0]*l+r[0]*c,p=a[1]*s+n[1]*u+i[1]*l+r[1]*c;return[d,p,Math.sqrt(d*d+p*p)]}function s(t){var e=null,a=null,n=null;return t.forEach(function(t){switch(t.header.parameterCategory+","+t.header.parameterNumber){case"1,2":case"2,2":e=t;break;case"1,3":case"2,3":a=t;break;default:n=t}}),null!=n?function(t){L=!1;var e=t.data;return{header:t.header,interpolate:i,data:function(t){return e[t]}}}(n):function(t,e){L=!0;var a=t.data,n=e.data;return{header:t.header,data:function(t){return[a[t],n[t]]},interpolate:r}}(e,a)}e(c),window.FRAME_TIME=1e3/T.FRAME_RATE;var p,f,u,m,v,g,w,l,d,o=[NaN,NaN,null],h=T.params.data,L=!0,M=function(t,e){if(!f)return null;var a,n=y(t-m,360)/g,i=(v-e)/w,r=Math.floor(n),o=r+1,h=Math.floor(i),s=h+1;if(a=f[h]){var u=a[r],l=a[o];if(R(u)&&R(l)&&(a=f[s])){var c=a[r],d=a[o];if(R(c)&&R(d))return p.interpolate(n-r,i-h,u,l,c,d)}}return null},R=function(t){return null!=t},y=function(t,e){return t-e*Math.floor(t/e)},_=function(t,e,a){return(function(t,e){return Math.max(e[0],Math.min(t,e[1]))}(t,[e,a])-e)/(a-e)},E=function(t,e){var a=t[0],n=t[1],i=t[2],r=e[0]-a,o=e[1]-n,h=e[2]-i;return function(t,e){return[Math.floor(a+t*r),Math.floor(n+t*o),Math.floor(i+t*h),e]}};function P(t){for(var i=[],r=[],o=[],e=0;e<t.length-1;e++)i.push(t[e+1][0]),r.push(E(t[e][1],t[e+1][1])),o.push([t[e][0],t[e+1][0]]);return function(t,e){var a;for(a=0;a<i.length-1&&!(t<=i[a]);a++);var n=o[a];return r[a](_(t,n[0],n[1]),e)}}function b(n,i,t,e){function r(t,e){var a=n[Math.round(t)];return a&&a[Math.round(e)]||o}r.release=function(){n=[]},r.randomize=function(t){for(var e,a,n=0;null===r(e=Math.round(Math.floor(Math.random()*i.width)+i.x),a=Math.round(Math.floor(Math.random()*i.height)+i.y))[2]&&n++<30;);return t.x=e,t.y=a,t},r.overlay=t.imageData,e(i,r)}function x(t){return t/180*Math.PI}function A(t){return t/(Math.PI/180)}var S,O=function(t,e,a,n,i,r){var o=2*Math.PI,h="EPSG:4326"===T.params.projection?5:Math.pow(10,-5.2),s=e<0?h:-h,u=a<0?h:-h,l=V(a,e+s,r),c=V(a+u,e,r),d=Math.cos(a/360*o);return[(l[0]-n)/s/d,(l[1]-i)/s/d,(c[0]-n)/u,(c[1]-i)/u]};function I(t){return Math.log(Math.tan(t/2+Math.PI/4))}function C(y,_,E,a){var x=function(t){var e=document.createElement("canvas"),i=t.width,a=t.height;e.width=i,e.height=a;var n=e.getContext("2d");n.fillStyle="rgba(255, 0, 0, 1)",n.fill();var r=n.getImageData(0,0,i,a),o=r.data;return{imageData:r,isVisible:function(t,e){return 0<o[3+4*(e*i+t)]},set:function(t,e,a){var n=4*(e*i+t);return o[n]=a[0],o[1+n]=a[1],o[2+n]=a[2],o[3+n]=a[3],this}}}(_),A={},t=(E.south-E.north)*(E.west-E.east),I=T.VELOCITY_SCALE*Math.pow(t,.4),C=[],n=_.x;function i(t){for(var e,a,n,i,r,o,h,s,u,l,c,d=[],p=_.y;p<=_.yMax;p+=2){var f=S(t,p,E),m=[0,0,0,0];if(f){var v=f[0],g=f[1];if(isFinite(v)){var w=y.interpolate(v,g),M=null;w&&(L?(e=A,a=v,n=g,i=t,r=p,o=I,s=E,void 0,u=(h=w)[0]*o,l=h[1]*o,c=O(e,a,n,i,r,s),h[0]=c[0]*u+c[2]*l,h[1]=c[1]*u+c[3]*l,w=h,d[p+1]=d[p]=w):M=w),R(M)&&(m=P(T.OVERLAY_COLOR_SCALE)(M,OVERLAY_ALPHA))}}x.set(t,p,m).set(t+1,p,m).set(t,p+1,m).set(t+1,p+1,m)}C[t+1]=C[t]=d}!function t(){for(var e=Date.now();n<_.width;)if(i(n),n+=2,1e3<Date.now()-e)return void setTimeout(t,25);b(C,_,x,a)}()}function D(n,h){var e,a,s=(e=T.MIN_VELOCITY_INTENSITY,a=T.MAX_VELOCITY_INTENSITY,T.COLOR_SCALE.indexFor=function(t){return Math.max(0,Math.min(T.COLOR_SCALE.length-1,Math.round((t-e)/(a-e)*(T.COLOR_SCALE.length-1))))},T.COLOR_SCALE),u=s.map(function(){return[]}),t=Math.round(n.width*n.height*T.PARTICLE_MULTIPLIER);/android|blackberry|iemobile|ipad|iphone|ipod|opera mini|webos/i.test(navigator.userAgent)&&(t*=T.PARTICLE_REDUCTION);for(var i=[],r=0;r<t;r++)i.push(h.randomize({age:Math.floor(Math.random()*T.MAX_PARTICLE_AGE)+0}));var o=T.canvas.getContext("2d");o.lineWidth=T.PARTICLE_LINE_WIDTH,o.fillStyle="rgba(0, 0, 0, 0.97)",o.globalAlpha=.6;var l=Date.now();!function t(){N=requestAnimationFrame(t);var e=Date.now(),a=e-l;a>FRAME_TIME&&(l=e-a%FRAME_TIME,u.forEach(function(t){t.length=0}),i.forEach(function(t){t.age>T.MAX_PARTICLE_AGE&&(h.randomize(t).age=0);var e=t.x,a=t.y,n=h(e,a),i=n[2];if(null===i)t.age=T.MAX_PARTICLE_AGE;else{var r=e+n[0],o=a+n[1];null!==h(r,o)[2]?(t.xt=r,t.yt=o,u[s.indexFor(i)].push(t)):(t.x=r,t.y=o)}t.age+=1}),o.globalCompositeOperation="destination-in",o.fillRect(n.x,n.y,n.width,n.height),o.globalCompositeOperation="lighter",o.globalAlpha=.9,u.forEach(function(t,e){0<t.length&&(o.beginPath(),o.strokeStyle=s[e],t.forEach(function(t){o.moveTo(t.x,t.y),o.lineTo(t.xt,t.yt),t.x=t.xt,t.y=t.yt}),o.stroke())}),c.onDraw&&c.onDraw())}()}S="EPSG:4326"===T.params.projection?function(t,e,a){var n=a.east-a.west,i=a.south-a.north,r=A(a.north)+e/a.height*A(i);return[A(a.west)+t/a.width*A(n),r]}:function(t,e,a){var n=a.east-a.west,i=a.width/A(n)*360/(2*Math.PI),r=i/2*Math.log((1+Math.sin(a.south))/(1-Math.sin(a.south))),o=(a.height+r-e)/i,h=180/Math.PI*(2*Math.atan(Math.exp(o))-Math.PI/2);return[A(a.west)+t/a.width*A(n),h]};var N,V=function(t,e,a){var n=I(a.south),i=I(a.north),r=a.width/(a.east-a.west),o=a.height/(i-n),h=I(x(t));return[(x(e)-a.west)*r,h=(i-h)*o]},z=function(e,a,n,t){var i={south:x(t[0][1]),north:x(t[1][1]),east:x(t[1][0]),west:x(t[0][0]),width:a,height:n};F(),function(t,e){var a=(p=s(t)).header;m=a.lo1,v=Math.max(a.la2,a.la1),g=a.dx,w=a.dy,l=a.nx,d=a.ny,(u=new Date(a.refTime)).setHours(u.getHours()+a.forecastTime),f=[];for(var n=0,i=360<=Math.floor(l*g),r=0;r<d;r++){for(var o=[],h=0;h<l;h++,n++)o[h]=p.data(n);i&&o.push(o[0]),f[r]=o}e({date:u,interpolate:M})}(h,function(t){C(t,function(t,e,a){var n=t[0],i=t[1],r=Math.round(n[0]),o=Math.max(Math.floor(n[1],0),0);Math.min(Math.ceil(i[0],e),e-1);return{x:r,y:o,xMax:e,yMax:Math.min(Math.ceil(i[1],a),a-1),width:e,height:a}}(e,a,n),i,function(t,e){W.field=e,L?D(t,e):function(t,e){if(e){var a=c.canvas,n=a.width,i=a.height,r=a.getContext("2d");r.clearRect(0,0,n,i),r.putImageData(e.overlay,0,0)}}(0,e)})})},F=function(){W.field&&W.field.release(),N&&cancelAnimationFrame(N)},W={params:T.params,start:z,stop:F,update:function(t,e,a,n,i){delete T.params.data,T.params.data=t,i&&z(e,a,n,i)},shift:function(t,e){var a=T.canvas,n=a.width,i=a.height,r=a.getContext("2d");if(t<n&&e<i){var o=function(t,e){return Math.max(0,Math.min(t,e))},h=r.getImageData(o(n,-t),o(i,-e),o(n,n-t),o(i,i-e));r.clearRect(0,0,n,i),r.putImageData(h,o(n,t),o(i,e));for(var s=0,u=particles.length;s<u;s++)particles[s].x+=t,particles[s].y+=e}},createField:b,interpolatePoint:M,setData:function(t){h=t},updateParams:function(t){T.params=t,e(T.params)},getParams:function(){return T.params},buildParams:e};return W}window.requestAnimationFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){return window.setTimeout(t,1e3/window.FRAME_RATE)},window.cancelAnimationFrame||(window.cancelAnimationFrame=function(t){clearTimeout(t)});var i=function(t){return t/.514},r=function(t){return 3.6*t},n="undefined"==typeof window?{}:window;return n.BMap||(n.BMap={}),n.BMap.Overlay||(n.BMap.Overlay=function(){return function(){}}()),function(a){function t(t,e){void 0===e&&(e={}),a.call(this,e),this.options=e,this.paneName=this.options.paneName||"mapPane",this.context=this.options.context||"2d",this.zIndex=this.options.zIndex||0,this.mixBlendMode=this.options.mixBlendMode||null,this.enableMassClear=this.options.enableMassClear,this._map=e.map,this._lastDrawTime=null,this.canvas=null,this.data=t,this._windy=null,this.show()}return a&&(t.__proto__=a),((t.prototype=Object.create(a&&a.prototype)).constructor=t).prototype.getData=function(){return this.data},t.prototype.setData=function(t){this.data=t,this._map&&this.data&&this._draw()},t.prototype._getExtent=function(){var t=this._map.getSize(),e=this._map.getBounds().getNorthEast(),a=this._map.getBounds().getSouthWest();return[[[0,0],[t.width,t.height]],t.width,t.height,[[a.lng,a.lat],[e.lng,e.lat]]]},t.prototype.appendTo=function(t){if(!t)throw new Error("not map object");t.addOverlay(this)},t.prototype.initialize=function(t){var e=this;this._map=t;var a=this.canvas=document.createElement("canvas");return a.style.cssText="position:absolute; left:0; top:0; z-index: "+this.zIndex+" ;user-select:none;",a.style.mixBlendMode=this.mixBlendMode,this.adjustSize(),t.getPanes()[this.paneName].appendChild(a),t.addEventListener("resize",function(){e.adjustSize(),e._draw()}),this.canvas},t.prototype.adjustSize=function(){var t=this._map.getSize(),e=this.canvas,a=this.devicePixelRatio=n.devicePixelRatio||1;e.width=t.width*a,e.height=t.height*a,"2d"===this.context&&e.getContext(this.context).scale(a,a),e.style.width=t.width+"px",e.style.height=t.height+"px"},t.prototype.draw=function(){var t=this;clearTimeout(t.timeoutID),t.timeoutID=setTimeout(function(){t._draw()},15)},t.prototype._draw=function(){var t=this._map,e=t.getSize(),a=t.getCenter();if(a){var n=t.pointToOverlayPixel(a);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),this.render(this.canvas)}},t.prototype.render=function(t){var e=this._getExtent();if(!this.getData()||!e)return this;if(t&&!this._windy){var a=this.options,n=a.minVelocity,i=a.maxVelocity,r=a.velocityScale,o=a.particleAge,h=a.lineWidth,s=a.particleMultiplier,u=a.colorScale;this._windy=new l({canvas:t,data:this.getData(),onDraw:function(){},minVelocity:n,maxVelocity:i,velocityScale:r,particleAge:o,lineWidth:h,particleMultiplier:s,colorScale:u}),this._windy.start(e[0],e[1],e[2],e[3])}else t&&this._windy&&this._windy.start(e[0],e[1],e[2],e[3]);return this},t.prototype.getContainer=function(){return this.canvas},t.prototype.setZIndex=function(t){this.zIndex=t,this.canvas.style.zIndex=this.zIndex},t.prototype.getZIndex=function(){return this.zIndex},t.prototype.getPointData=function(t){var e=this._windy.interpolatePoint(t[0],t[1]);if(e&&!isNaN(e[0])&&!isNaN(e[1])&&e[2])return{direction:function(t,e,a){a.endsWith("CCW")&&(e=0<e?e=-e:Math.abs(e));var n=Math.sqrt(Math.pow(t,2)+Math.pow(e,2)),i=180*Math.atan2(t/n,e/n)/Math.PI+180;return"bearingCW"!==a&&"meteoCCW"!==a||360<=(i+=180)&&(i-=360),i}(e[0],e[1],this.options.angleConvention||"bearingCCW"),speed:function(t,e,a){var n=Math.sqrt(Math.pow(t,2)+Math.pow(e,2));return"k/h"===a?r(n):"kt"===a?i(n):n}(e[0],e[1],this.options.speedUnit)}},t.prototype.clearWind=function(){this._windy&&this._windy.stop()},t.prototype.updateParams=function(t){if(this.options=Object.assign(this.options,t),this._windy){var e=this.options,a=e.minVelocity,n=e.maxVelocity,i=e.velocityScale,r=e.particleAge,o=e.lineWidth,h=e.particleMultiplier,s=e.colorScale;this._windy&&(this._windy.updateParams({minVelocity:a,maxVelocity:n,velocityScale:i,particleAge:r,lineWidth:o,particleMultiplier:h,colorScale:s}),this._map&&this.canvas&&this.data&&this.render(this.canvas))}return this},t.prototype.getParams=function(){return this._windy&&this._windy.getParams()},t}(n.BMap.Overlay)});
  