UNPKG

weather-te

Version:

A light weather visualization library.

1 lines 138 kB
var t={Temp:"temp",Pressure:"pressure",Humidity:"humidity",Visibility:"Visibility",Rain:"rain",Wind:"wind",Waves:"waves",WaterTemp:"waterTemp",SeaCurrents:"seaCurrents",WindGust:"windGust",SolarRadiation:"solarRadiation",CloudSurface:"cloudSurface",SnowDepth:"snowDepth"},e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},e(t,r)};function r(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}"function"==typeof SuppressedError&&SuppressedError;var n=function(){this.visible=!0},o={exports:{}};!function(t){var e=function(){var t={},e=Math.PI/180,r=180/Math.PI,n=6378137,o=20037508.342789244;function i(t){return Number(t)===t&&t%1!=0}function a(e){if(e=e||{},this.size=e.size||256,this.expansion=!0===e.antimeridian?2:1,!t[this.size]){var r=this.size,n=t[this.size]={};n.Bc=[],n.Cc=[],n.zc=[],n.Ac=[];for(var o=0;o<30;o++)n.Bc.push(r/360),n.Cc.push(r/(2*Math.PI)),n.zc.push(r/2),n.Ac.push(r),r*=2}this.Bc=t[this.size].Bc,this.Cc=t[this.size].Cc,this.zc=t[this.size].zc,this.Ac=t[this.size].Ac}return a.prototype.px=function(t,r){if(i(r)){var n=this.size*Math.pow(2,r),o=n/2,a=n/360,s=n/(2*Math.PI),l=n,u=Math.min(Math.max(Math.sin(e*t[1]),-.9999),.9999),c=o+t[0]*a,d=o+.5*Math.log((1+u)/(1-u))*-s;return c>l*this.expansion&&(c=l*this.expansion),d>l&&(d=l),[c,d]}o=this.zc[r],u=Math.min(Math.max(Math.sin(e*t[1]),-.9999),.9999),c=Math.round(o+t[0]*this.Bc[r]),d=Math.round(o+.5*Math.log((1+u)/(1-u))*-this.Cc[r]);return c>this.Ac[r]*this.expansion&&(c=this.Ac[r]*this.expansion),d>this.Ac[r]&&(d=this.Ac[r]),[c,d]},a.prototype.ll=function(t,e){if(i(e)){var n=this.size*Math.pow(2,e),o=n/360,a=n/(2*Math.PI),s=n/2,l=(t[1]-s)/-a;return[(t[0]-s)/o,r*(2*Math.atan(Math.exp(l))-.5*Math.PI)]}l=(t[1]-this.zc[e])/-this.Cc[e];return[(t[0]-this.zc[e])/this.Bc[e],r*(2*Math.atan(Math.exp(l))-.5*Math.PI)]},a.prototype.bbox=function(t,e,r,n,o){n&&(e=Math.pow(2,r)-1-e);var i=[t*this.size,(+e+1)*this.size],a=[(+t+1)*this.size,e*this.size],s=this.ll(i,r).concat(this.ll(a,r));return"900913"===o?this.convert(s,"900913"):s},a.prototype.xyz=function(t,e,r,n){"900913"===n&&(t=this.convert(t,"WGS84"));var o=[t[0],t[1]],i=[t[2],t[3]],a=this.px(o,e),s=this.px(i,e),l=[Math.floor(a[0]/this.size),Math.floor((s[0]-1)/this.size)],u=[Math.floor(s[1]/this.size),Math.floor((a[1]-1)/this.size)],c={minX:Math.min.apply(Math,l)<0?0:Math.min.apply(Math,l),minY:Math.min.apply(Math,u)<0?0:Math.min.apply(Math,u),maxX:Math.max.apply(Math,l),maxY:Math.max.apply(Math,u)};if(r){var d={minY:Math.pow(2,e)-1-c.maxY,maxY:Math.pow(2,e)-1-c.minY};c.minY=d.minY,c.maxY=d.maxY}return c},a.prototype.convert=function(t,e){return"900913"===e?this.forward(t.slice(0,2)).concat(this.forward(t.slice(2,4))):this.inverse(t.slice(0,2)).concat(this.inverse(t.slice(2,4)))},a.prototype.forward=function(t){var r=[n*t[0]*e,n*Math.log(Math.tan(.25*Math.PI+.5*t[1]*e))];return r[0]>o&&(r[0]=o),r[0]<-o&&(r[0]=-o),r[1]>o&&(r[1]=o),r[1]<-o&&(r[1]=-o),r},a.prototype.inverse=function(t){return[t[0]*r/n,(.5*Math.PI-2*Math.atan(Math.exp(-t[1]/n)))*r]},a}();t.exports=e}(o);var i=o.exports,a="web",s=a,l=function(){function t(){}return t.setWx=function(){s="wx"},t.createCanvas2d=function(t){return t||(t={type:"2d"}),s===a?document.createElement("canvas"):uni.createOffscreenCanvas(t)},t.createCanvasGL=function(t){return t||(t={type:"webgl"}),s===a?document.createElement("canvas"):uni.createOffscreenCanvas(t)},t}(),u=20037508.342789244,c=2*u,d=c/8,p=256,h=new i({size:p});function v(t,e,r){var n=new Image;n.crossOrigin="anonymous",n.onload=function(){return e(n)},n.onerror=r||function(t){},n.src=t}function f(e,r){var n=l.createCanvas2d();n.width=e.width,n.height=e.height;var o=n.getContext("2d");o.drawImage(e,0,0);for(var i=o.getImageData(0,0,n.width,n.height).data,a=[],s=[],u=0,c=i.length/4;u<c;u++){var d=4*u,p=i[d],h=i[d+1];r===t.Wind?(a[u]=.2*p-25,s[u]=.2*h-25):r===t.SeaCurrents&&(0===p&&0===h?(a[u]=null,s[u]=null):(a[u]=.04*p-5,s[u]=.04*h-5))}return[{header:{nx:1440,ny:721,lo1:-180,la1:90,lo2:179.75,la2:-90,dx:.25,dy:.25,parameterCategory:2,parameterNumber:2},data:a},{header:{nx:1440,ny:721,lo1:-180,la1:90,lo2:179.75,la2:-90,dx:.25,dy:.25,parameterCategory:2,parameterNumber:3},data:s}]}function g(t,e,r){return[Math.round((e-t[0])/t[1]),Math.round((r-t[3])/t[5])]}function m(t){return~~((t+u)/d)}function x(t){return~~((u-t)/d)}function w(t,e){return t<0?w(t+e,e):t>=e?w(t-e,e):t}function y(t){return parseFloat(Math.log2(c/t/256).toFixed(6))}function _(t,e,r){t+=u,e=u-e;var n=256*Math.pow(2,r),o=c/n;return[t/o,e/o]}function b(t,e,r){return void 0===r&&(r=3),~~(t/(256*Math.pow(2,e)/Math.pow(2,r)))}function T(t,e,r){return t/(256*e/r)}function C(t,e,r){void 0===r&&(r=3);var n=t.southWestX,o=t.southWestY,i=t.northEastX,a=t.northEastY,s=Math.pow(2,e),l=Math.pow(2,r);return{southWestX:T(n,s,l),southWestY:T(o,s,l),northEastX:T(i,s,l),northEastY:T(a,s,l)}}function A(t,e,r,n){void 0===n&&(n=3);var o=Math.pow(2,r),i=Math.pow(2,n),a=t/(256*o/i);return a>i-1&&(a%=i),a<0&&(a=i+a%i),{cx:a,cy:e/(256*o/i)}}function L(t){var e=256*Math.pow(2,t[2])/2,r=!1;return t[1]>e&&(r=!0),r}function E(t,e,r,n){var o=Math.pow(2,r),i=256*Math.pow(2,n)/o;return[i*t,i*e,i]}function k(t,e,r,n,o,i){var a=256*Math.pow(2,o),s=256*Math.pow(2,i);return[Math.round(t*s/a),Math.round(e*s/a),Math.round(r*s/a),Math.round(n*s/a)]}function P(t,e){var r=p*Math.pow(2,e);return[t.southWestX/r,t.northEastX/r,t.northEastY/r,t.southWestY/r]}function R(t,e){var r=e[0],n=e[1],o=e[2],i=e[3];return[(t.southWestX-r)/o,(t.northEastX-r)/o,(t.northEastY-n)/i,(t.southWestY-n)/i]}function M(t,e){var r=h.ll([t.southWestX,t.southWestY],e),n=h.ll([t.northEastX,t.northEastY],e);return{southWestX:r[0],southWestY:r[1],northEastX:n[0],northEastY:n[1]}}function B(t,e){var r=t[0],n=t[1],o=U(r),i=o[0],a=o[1],s=h.px([i,n],e),l=s[0],u=s[1];return[l+a*(p*Math.pow(2,e)),u]}function F(t,e){var r=t[0],n=t[1],o=function(t,e){void 0===e&&(e=0);return t<0?U(t,e):[t,e]}(r),i=o[0],a=o[1],s=h.px([i,n],e),l=s[0],u=s[1];return[l+a*(p*Math.pow(2,e)),u]}function S(t,e,r){var n=t[0],o=t[1],i=e[0],a=e[1],s=U(n),l=s[0],u=s[1],c=U(i),d=c[0],v=c[1],f=h.px([l,o],r),g=f[0],m=f[1],x=h.px([d,a],r),w=x[0],y=x[1],_=p*Math.pow(2,r);return[[g+u*_,m],[w+v*_,y]]}function U(t,e){return void 0===e&&(e=0),t>180?U(t-360,e+1):t<-180?U(t+360,e-1):[t,e]}function D(){var t=(new Date).getTime().toString();return t.substring(6,t.length)+Math.random().toString(36).substring(2,6)}var z,I,W,X,Y=Object.freeze({__proto__:null,loadImage:v,loadImageWx:function(t,e,r){var n=l.createCanvas2d({type:"2d",width:257,height:257});n.getContext("2d");var o=n.createImage();o.onload=function(){return e(o)},o.src=t},loadSvg:function(t,e,r){var n=new XMLHttpRequest;n.addEventListener("load",(function(){var t=n.responseXML.documentElement.cloneNode(!0);e(t)})),n.open("GET",t),n.send()},getVectorJsonFromImage:f,wrap:function(t,e,r){var n=r-e,o=((t-e)%n+n)%n+e;return o===e?r:o},lonLat2pixel:g,lonLatExtent2canvasCS:function(t,e,r,n,o){var i=g(t,e,o),a=i[0],s=i[1],l=g(t,n,r);return[a,s,l[0]-a,l[1]-s]},tileX:m,tileY:x,tileRange:function(t){var e=t[0],r=t[1],n=t[2],o=t[3];return[m(e),x(r),m(n),x(o)]},formatXY:w,getTransform:function(t,e,r){var n=e/r;return[t[0],n,0,t[3],0,-n]},zoomFromResolution3857:y,pixelFrom3857:_,tileRangeAmap:function(t,e){var r=t[0],n=t[1],o=t[2],i=t[3];return[b(r,e),b(n,e),b(o,e),b(i,e)]},tileIndexFromWorldPixelAndZoom:b,tileIndexFromWorldPixel:T,extentFromPixelToTile:C,canvasXYFromWorldXY:A,checkNorthOrSouth:L,xyz2Amap:function(t,e,r,n){var o=Math.pow(2,r),i=256*Math.pow(2,n)/o;return[[i*t,i*e],[i*(t+1),i*(e+1)]]},xyz2Amap2:E,source2world:k,extent2UV:P,extent2AreaUV:R,extent2extent4326:M,px:B,px2:F,px3:S,formatLon:U,convert:function(t,e){return h.convert(t,e)},genUUID:D}),N={},V={},O={};function G(t,e,r,n,o){for(var i=t.data,a=n?n.data:null,s=t.data.length,l=0;l<s;l+=4){var u=void 0;if(!r)throw new Error("no decodeStrategy");u=r(l/4,i[l],i[l+1],i[l+2]),a&&o&&(a[l]=o[u],a[l+1]=o[u+1],a[l+2]=o[u+2],a[l+3]=o[u+3])}}function q(t){var e=t/16,r=Math.floor(e),n=0;return r>0&&(n=Math.pow(2,r+3)),((t-16*r)*((Math.pow(2,r+4)-n)/16)+n)/10}function Z(t,e,r,n,o,i){G(t,0,(function(t,r){return e[t]={r:r,value:r*i+o},4*r}),r,n)}function H(e){switch(e){case t.Temp:return"°C";case t.Pressure:return"hPa";case t.Humidity:return"%";case t.Visibility:return"km";case t.Wind:return"m/s";case t.Rain:return"mm";case t.WaterTemp:return"°C";case t.Waves:return"m";case t.SeaCurrents:case t.WindGust:return"m/s";case t.SolarRadiation:return"W/m^2";case t.CloudSurface:return"%";case t.SnowDepth:return"m"}return""}function j(e,r,n,o){var i;if(257===e.width)i=I;else if(2049===e.width)i=X;else{var a=l.createCanvas2d();a.width=e.width,a.height=e.height,i=a.getContext("2d")}i.drawImage(e,0,0);var s=i.getImageData(0,0,e.width,e.height),u=null,c=null,d=null;return o&&((c=(u=l.createCanvas2d()).getContext("2d")).canvas.width=e.width,c.canvas.height=e.height,c.imageSmoothingQuality="high",d=c.createImageData(e.width,e.height)),N[n]?Z(s,r,d,o,N[n].min,N[n].step):V[n]?function(t,e,r,n,o,i,a){G(t,0,(function(t,r,n,s){var l,u,c;return r<10&&n<10?(l=125,u=125,c=0):(l=i*r+o,u=i*n+o,c=Math.sqrt(l*l+u*u)),e[t]={r:l,g:u,b:s,value:c},4*Math.floor(c*a)}),r,n)}(s,r,d,o,V[n].min,V[n].step,V[n].slope):O[n]?function(t,e,r,n,o,i){G(t,0,(function(t,r,n){var a=o(r,n);return e[t]={r:r,g:n,value:a},i?i(r,n,a):4*r}),r,n)}(s,r,d,o,O[n].gray2value,O[n].gray2Color):n===t.Rain?function(t,e,r,n){G(t,0,(function(t,r){return e[t]={r:r,value:q(r)},4*r}),r,n)}(s,r,d,o):n===t.Temp?Z(s,r,d,o,-70,.5):n===t.Pressure?Z(s,r,d,o,930,.5):n===t.Humidity?Z(s,r,d,o,0,.5):n===t.Visibility?Z(s,r,d,o,0,.1):n===t.Waves?Z(s,r,d,o,0,.05):n===t.WaterTemp?Z(s,r,d,o,-10,.2):n===t.WindGust?Z(s,r,d,o,0,.1):n===t.SolarRadiation?Z(s,r,d,o,0,5):n===t.CloudSurface?Z(s,r,d,o,0,.5):n===t.SnowDepth&&Z(s,r,d,o,0,.0125),c&&c.putImageData(d,0,0),u}function $(t,e,r){return t[0]*r+e}function Q(e,r){var n=0;return N[r]?n=$(e,N[r].min,N[r].step):V[r]?n=function(t,e,r){var n=t[0],o=t[1];if(n<10&&o<10)return 0;var i=r*n+e,a=r*o+e;return Math.sqrt(i*i+a*a)}(e,V[r].min,V[r].step):O[r]?n=function(t,e){return e(t[0],t[1])}(e,O[r].gray2value):r===t.Rain?n=q(e[0]):r===t.Temp?n=$(e,-70,.5):r===t.Pressure?n=$(e,930,.5):r===t.Humidity?n=$(e,0,.5):r===t.Visibility?n=$(e,0,.1):r===t.Waves?n=$(e,0,.05):r===t.WaterTemp?n=$(e,-10,.2):r===t.WindGust?n=$(e,0,.1):r===t.SolarRadiation?n=$(e,0,5):r===t.CloudSurface?n=$(e,0,.5):r===t.SnowDepth&&(n=$(e,0,.0125)),n}function K(t,e,r){N[t]={min:e,step:r}}function J(t,e,r,n){V[t]={min:e,step:r,slope:n}}function tt(t,e,r){O[t]={gray2value:e,gray2color:r}}function et(){return V}J(t.Wind,-25,.2,8),J(t.SeaCurrents,-5,.04,100);var rt=function(){function t(t){this.sourceZoom=3,this.sourceTileSize=Math.pow(2,this.sourceZoom),this.renderCallbackArray=[],void 0===t.zoom&&(t.zoom=3);var e=t.zoom;this.sourceZoom=e;var r=Math.pow(2,e);this.sourceTileSize=r;for(var n=new Array(this.sourceTileSize*this.sourceTileSize),o=r-1;o>=0;--o)for(var i=r-1;i>=0;--i){n[o*r+i]={tileXYZ:[i,o,e],pixelXYS:[0,0,0],image:null,isLoaded:!1,isDecoded:!1,decodeArr:null}}this.url=t.url,this.factor=t.factor,this.onerror=t.onerror,this.tileArray=n}return t.prototype.setConfig=function(t){if(void 0===t.zoom&&(t.zoom=3),this.url!==t.url){this.url=t.url,this.factor=t.factor,this.onerror=t.onerror;var e=t.zoom;this.sourceZoom=e;var r=Math.pow(2,e);if(this.sourceTileSize=r,this.tileArray.length<r*r){this.tileArray=new Array(this.sourceTileSize*this.sourceTileSize);for(var n=this.tileArray,o=r-1;o>=0;--o)for(var i=r-1;i>=0;--i){n[o*r+i]={tileXYZ:[i,o,e],pixelXYS:[0,0,0],image:null,isLoaded:!1,isDecoded:!1,decodeArr:null}}}else for(var a=(n=this.tileArray).length-1;a>=0;--a)n[a].image=null,n[a].isDecoded=!1,n[a].canvas=null,n[a].texture=null;this.renderCallbackArray=[]}},t.prototype.getFactor=function(){return this.factor},t.prototype.addRenderCallback=function(t){this.renderCallbackArray.push(t)},t.prototype.loadByExtent=function(t,e){var r=this;if(this.url){this.copyArray=[];for(var n=this.sourceZoom,o=this.sourceTileSize,i=this.tileArray,a=C(t,e,n),s=a.southWestX,l=a.southWestY,u=a.northEastX,c=a.northEastY,d=(Math.floor(l)-Math.floor(c)+1)*Math.floor(Math.floor(u)-Math.floor(s)+1),p=function(t){for(var e=w(t,o),a=function(a){var s=w(a,o),l=e*o+s;i[l].image?h.tileLoadedCallback(l,a,t,n,d):h.loadTile(s,e,h.sourceZoom,(function(e){i[l].image=e,r.tileLoadedCallback(l,a,t,n,d)}),(function(e){i[l].image=null,r.tileLoadedCallback(l,a,t,n,d),r.onerror&&r.onerror(e)}))},l=Math.floor(s);l<=Math.floor(u);l+=1)a(l)},h=this,v=Math.floor(c);v<=Math.floor(l);v+=1)p(v)}},t.prototype.decodeTextByViewPixel=function(t,e,r){return this.decodeTextByWorldPixel(e.southWestX+t[0],e.northEastY+t[1],r)},t.prototype.decodeByViewPixel=function(t,e,r){return this.decodeByWorldPixel(e.southWestX+t[0],e.northEastY+t[1],r)},t.prototype.decodeTextByWorldPixel=function(t,e,r){return parseFloat(this.decodeByWorldPixel(t,e,r).value.toFixed(1))+H(this.factor)},t.prototype.decodeTextByLngLat=function(t,e){return parseFloat(this.decodeByLngLat(t,e).value.toFixed(2))+H(this.factor)},t.prototype.decodeByLngLat=function(t,e){var r=t[0],n=t[1];r=U(r)[0];var o=this.tileArray[0].image,i=o.width-1,a=o.height-1,s=i*this.sourceTileSize,l=a*this.sourceTileSize,u=F([r,n],e+1),c=F([180,-90],e+1),d=u[0]/c[0]*s,p=u[1]/c[1]*l,h=Math.floor(d/i),v=Math.floor(p/a)*this.sourceTileSize+h,f=d%i,g=p%a;if(v>this.tileArray.length-1)return null;var m=document.createElement("canvas");m.width=i+1,m.height=a+1;var x=m.getContext("2d");x.imageSmoothingQuality="high",x.drawImage(this.tileArray[v].image,0,0);var w=x.getImageData(Math.round(f),Math.round(g),1,1);return{rgba:w.data,value:Q(w.data,this.factor)}},t.prototype.decodeByWorldPixel=function(t,e,r){var n=A(t,e,r,this.sourceZoom),o=~~n.cx,i=~~n.cy*this.sourceTileSize+o;if(i>this.tileArray.length-1||i<0)return null;var a=this.tileArray[i];if(!a.isDecoded){if(!a.image)return null;a.decodeArr=new Array(a.image.width*a.image.height),a.canvas=j(a.image,a.decodeArr,this.factor),a.isDecoded=!0}var s=a.image.width-1,l=n.cx.toString().split("."),u=(n.cx-parseInt(l[0],10))*s,c=Math.round(u),d=n.cy.toString().split("."),p=(n.cy-parseInt(d[0],10))*s,h=Math.round(p);return a.decodeArr[h*(s+1)+c]},t.prototype.tileLoadedCallback=function(t,e,r,n,o){this.copyArray.push(t,e,r,n),this.copyArray.length===4*o&&this.allLoadedCallback()},t.prototype.allLoadedCallback=function(){for(var t=0,e=this.renderCallbackArray.length;t<e;t++)this.renderCallbackArray[t](this.tileArray,this.copyArray)},t.prototype.loadTile=function(t,e,r,n,o){var i=this.url.replace(/{x}/,"".concat(t));v(i=(i=i.replace(/{y}/,"".concat(e))).replace(/{z}/,"".concat(r)),n,o)},t.prototype.clear=function(){this.url=void 0},t.idw=function(t,e){for(var r=0,n=0,o=0;o<t.length;o++){var i=Math.pow(e[o],2);r+=t[o].value/i,n+=1/i}return{r:0,g:0,value:r/n}},t}();function nt(t){console.error(t)}const ot=/ERROR:\s*\d+:(\d+)/gi;function it(t,e=""){const r=[...e.matchAll(ot)],n=new Map(r.map(((t,n)=>{const o=parseInt(t[1]),i=r[n+1],a=i?i.index:e.length;return[o-1,e.substring(t.index,a)]})));return t.split("\n").map(((t,e)=>{const r=n.get(e);return`${e+1}: ${t}${r?`\n\n^^^ ${r}`:""}`})).join("\n")}function at(t,e,r,n){const o=n||nt,i=t.createShader(r);t.shaderSource(i,e),t.compileShader(i);if(!t.getShaderParameter(i,t.COMPILE_STATUS)){const r=t.getShaderInfoLog(i);return o(`Error compiling shader: ${r}\n${it(e,r)}`),t.deleteShader(i),null}return i}const st=["VERTEX_SHADER","FRAGMENT_SHADER"];function lt(t,e,r,n,o){const i=[];for(let r=0;r<e.length;++r)i.push(at(t,e[r],t[st[r]],o));return function(t,e,r,n,o){const i=o||nt,a=t.createProgram();if(e.forEach((function(e){t.attachShader(a,e)})),r&&r.forEach((function(e,r){t.bindAttribLocation(a,n?n[r]:r,e)})),t.linkProgram(a),!t.getProgramParameter(a,t.LINK_STATUS))return i(`Error in program linking: ${t.getProgramInfoLog(a)}\n${e.map((e=>{const r=it(t.getShaderSource(e));return`${t.getShaderParameter(e,t.SHADER_TYPE)}:\n${r}`})).join("\n")}`),t.deleteProgram(a),null;return a}(t,i,r,n,o)}var ut=function(){function t(){this.visible=!0,this.layerCanvas=l.createCanvasGL(),this.layerSize=new Int32Array(2)}return t.prototype.resize=function(){if(this.size){var t=this.size;this.layerSize[0]===t[0]&&this.layerSize[1]===t[1]||(this.layerCanvas.width=t[0],this.layerCanvas.height=t[1],this.layerSize[0]=t[0],this.layerSize[1]=t[1],this.layerCanvas.width=t[0],this.layerCanvas.height=t[1],this.layerSize[0]=t[0],this.layerSize[1]=t[1])}},t.prototype.setView=function(t,e,r,n){this.extent=t,this.extent4326=M(t,e),this.zoom=e,this.size=r,this.pixelRadio=n,this.worldSize=256*Math.pow(2,e),this.resize()},t.prototype.show=function(){this.visible=!0},t}(),ct=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.tiled=!0,e}return r(e,t),e.prototype.render=function(){this.visible&&(this.tiled&&this.compute(),this.prepare(),this.draw(),this.refresh&&this.refresh())},e.prototype.setQueue=function(t,e,r,n){this.tileChunks=t,this.copyArray=e,this.factor=r,this.mapColors=n,this.render()},e.prototype.compute=function(){for(var t=this.copyArray,e=[],r=0,n=t.length;r<n;r+=4){var o=E(t[r+1],t[r+2],t[r+3],this.zoom),i=o[0],a=o[1],s=o[2];e.push(t[r],i,a,s)}this.pixelXYArray=e},e}(ut);function dt(t,e,r){var n=t.createShader(e);if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new Error(t.getShaderInfoLog(n));return n}function pt(t,e,r){var n=t.createProgram(),o=dt(t,t.VERTEX_SHADER,e),i=dt(t,t.FRAGMENT_SHADER,r);if(t.attachShader(n,o),t.attachShader(n,i),t.linkProgram(n),!t.getProgramParameter(n,t.LINK_STATUS))throw new Error(t.getProgramInfoLog(n));for(var a={program:n},s=t.getProgramParameter(n,t.ACTIVE_ATTRIBUTES),l=0;l<s;l++){var u=t.getActiveAttrib(n,l);a[u.name]=t.getAttribLocation(n,u.name)}var c=t.getProgramParameter(n,t.ACTIVE_UNIFORMS);for(l=0;l<c;l++){var d=t.getActiveUniform(n,l);a[d.name]=t.getUniformLocation(n,d.name)}return a}function ht(t,e,r,n,o,i,a){var s=t.createTexture();return t.bindTexture(t.TEXTURE_2D,s),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,e),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,n),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,n),o instanceof Uint8Array?t.texImage2D(t.TEXTURE_2D,0,t.RGBA,i,a,0,t.RGBA,t.UNSIGNED_BYTE,o):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,o),t.bindTexture(t.TEXTURE_2D,null),s}function vt(t,e,r){t.activeTexture(t.TEXTURE0+r),t.bindTexture(t.TEXTURE_2D,e)}function ft(t,e){var r=t.createBuffer();return t.bindBuffer(t.ARRAY_BUFFER,r),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW),r}function gt(t,e,r,n,o){void 0===o&&(o=WebGLRenderingContext.FLOAT),t.bindBuffer(t.ARRAY_BUFFER,e),t.enableVertexAttribArray(r),t.vertexAttribPointer(r,n,o,!1,0,0)}function mt(t,e,r){t.bindFramebuffer(t.FRAMEBUFFER,e),r&&t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r,0)}var xt="\nattribute vec2 a_position; // 输入像素坐标\nattribute vec2 a_texCoord; // 输入纹理坐标\nuniform vec2 u_resolution; // Used to pass in the resolution of the canvas\nvarying vec2 v_texCoord; // Used to pass the texture coordinates to the fragment shader\n\nvoid main() {\n // convert the position from pixels to 0.0 to 1.0\n vec2 zeroToOne = a_position / u_resolution;\n\n // convert from 0->1 to 0->2\n vec2 zeroToTwo = zeroToOne * 2.0;\n\n // convert from 0->2 to -1->+1 (clipspace)\n vec2 clipSpace = zeroToTwo - 1.0;\n\n gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); // 已经是裁剪空间坐标,坐标方向和纹理坐标一致\n\n // pass the texCoord to the fragment shader\n // The GPU will interpolate this value between points.\n v_texCoord = a_texCoord;\n}",wt="\nprecision highp float;\nuniform sampler2D u_image;// 灰度\nuniform sampler2D u_color;// 色值映射\nvarying vec2 v_texCoord;// 坐标\n\nvoid main() {\n vec4 rgba = texture2D(u_image, v_texCoord);\n // 用灰度r转色斑rgba\n //vec4 color = texture2D(u_color, vec2(rgba.r, 0.5));\n float f = 1.0 - rgba.b;\n vec4 color = texture2D(u_color, vec2(rgba.r, 0.5)) * f;\n gl_FragColor = color;\n}",yt="\nprecision highp float;\nuniform sampler2D u_image;\nuniform vec2 u_range_uv;\nuniform vec2 u_range_s;\nuniform sampler2D u_color;\nvarying vec2 v_texCoord;\n\nvoid main() {\n // 用矢量uv转灰度r\n vec4 uv = texture2D(u_image, v_texCoord);\n float u = uv.r * (u_range_uv.y - u_range_uv.x) + u_range_uv.x;\n float v = uv.g * (u_range_uv.y - u_range_uv.x) + u_range_uv.x;\n float s = sqrt(u * u + v * v);\n float r = (s - u_range_s.x) / (u_range_s.y - u_range_s.x);\n // 用灰度r转色斑rgba\n float f = 1.0 - uv.b;\n vec4 color = texture2D(u_color, vec2(r, 0.5)) * f;\n // 输出\n gl_FragColor = color;\n}\n",_t=function(t){function e(){var e=t.call(this)||this;if(e.gl=e.layerCanvas.getContext("webgl"),!e.gl)throw new Error("cannot get webgl context!");return e.scalarProgram=lt(e.gl,[xt,wt]),e.sPositionBuffer=e.bufferInitPixelCoord(e.scalarProgram),e.bufferInitTextureCoord(e.scalarProgram),e.sResolutionLocation=e.gl.getUniformLocation(e.scalarProgram,"u_resolution"),e.sImageLocation=e.gl.getUniformLocation(e.scalarProgram,"u_image"),e.sColorMapLocation=e.gl.getUniformLocation(e.scalarProgram,"u_color"),e.vectorProgram=lt(e.gl,[xt,yt]),e.vPositionBuffer=e.bufferInitPixelCoord(e.vectorProgram),e.bufferInitTextureCoord(e.vectorProgram),e.vResolutionLocation=e.gl.getUniformLocation(e.vectorProgram,"u_resolution"),e.vImageLocation=e.gl.getUniformLocation(e.vectorProgram,"u_image"),e.vColorMapLocation=e.gl.getUniformLocation(e.vectorProgram,"u_color"),e.vRangeUVLocation=e.gl.getUniformLocation(e.vectorProgram,"u_range_uv"),e.vRangeSLocation=e.gl.getUniformLocation(e.vectorProgram,"u_range_s"),e}return r(e,t),e.prototype.setLayerCanvas=function(t){this.layerCanvas=t,this.gl=t.getContext("webgl"),this.scalarProgram=lt(this.gl,[xt,wt]),this.sPositionBuffer=this.bufferInitPixelCoord(this.scalarProgram),this.bufferInitTextureCoord(this.scalarProgram),this.sResolutionLocation=this.gl.getUniformLocation(this.scalarProgram,"u_resolution"),this.sImageLocation=this.gl.getUniformLocation(this.scalarProgram,"u_image"),this.sColorMapLocation=this.gl.getUniformLocation(this.scalarProgram,"u_color"),this.vectorProgram=lt(this.gl,[xt,yt]),this.vPositionBuffer=this.bufferInitPixelCoord(this.vectorProgram),this.bufferInitTextureCoord(this.vectorProgram),this.vResolutionLocation=this.gl.getUniformLocation(this.vectorProgram,"u_resolution"),this.vImageLocation=this.gl.getUniformLocation(this.vectorProgram,"u_image"),this.vColorMapLocation=this.gl.getUniformLocation(this.vectorProgram,"u_color"),this.vRangeUVLocation=this.gl.getUniformLocation(this.vectorProgram,"u_range_uv"),this.vRangeSLocation=this.gl.getUniformLocation(this.vectorProgram,"u_range_s")},e.prototype.prepare=function(){for(var t=this.gl,e=this.pixelXYArray,r=0,n=e.length;r<n;r+=4){var o=this.tileChunks[e[r]];o.texture||o.image&&(o.texture=ht(t,t.NEAREST,t.LINEAR,t.CLAMP_TO_EDGE,o.image,o.image.width,o.image.height))}var i=this.mapColors.canvas;this.mapColors.texture=ht(t,t.NEAREST,t.LINEAR,t.CLAMP_TO_EDGE,i,i.width,i.height)},e.prototype.draw=function(){var t=this.gl;t.viewport(0,0,t.canvas.width,t.canvas.height),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT);var e=this.vPositionBuffer,r=this.sImageLocation;if(et()[this.factor]){var n=et()[this.factor];this.useVectorProgram([n.min,255*n.step+n.min],[0,255/n.slope]),r=this.vImageLocation}else this.useScalarProgram();this.drawTile(e,r),t.bindTexture(t.TEXTURE_2D,null)},e.prototype.drawTile=function(t,e){for(var r=this.pixelXYArray,n=0,o=r.length;n<o;n+=4){var i=(r[n+1]-this.extent.southWestX)*this.pixelRadio,a=(r[n+2]-this.extent.northEastY)*this.pixelRadio,s=r[n+3]*this.pixelRadio,l=this.tileChunks[r[n]];l.texture&&this.renderTile(l.texture,i,a,s,t,e)}},e.prototype.clear=function(){var t=this.gl;t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT)},e.prototype.bufferInitPixelCoord=function(t){var e=this.gl,r=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,r);var n=e.getAttribLocation(t,"a_position");return e.enableVertexAttribArray(n),e.vertexAttribPointer(n,2,e.FLOAT,!1,0,0),r},e.prototype.bufferInitTextureCoord=function(t){var e=this.gl,r=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),e.STATIC_DRAW);var n=e.getAttribLocation(t,"a_texCoord");e.enableVertexAttribArray(n),e.vertexAttribPointer(n,2,e.FLOAT,!1,0,0)},e.prototype.renderTile=function(t,e,r,n,o,i){var a=this.gl;a.bindBuffer(a.ARRAY_BUFFER,o),this.setSquare(a,e,r,n),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,t),a.uniform1i(i,0),a.drawArrays(a.TRIANGLES,0,6)},e.prototype.useScalarProgram=function(){var t=this.gl;t.useProgram(this.scalarProgram),t.bindBuffer(t.ARRAY_BUFFER,this.sPositionBuffer),t.uniform2f(this.sResolutionLocation,t.canvas.width,t.canvas.height),t.uniform1i(this.sImageLocation,0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,this.mapColors.texture),t.uniform1i(this.sColorMapLocation,1)},e.prototype.useVectorProgram=function(t,e){var r=this.gl;r.useProgram(this.vectorProgram),r.bindBuffer(r.ARRAY_BUFFER,this.vPositionBuffer),r.uniform2f(this.vResolutionLocation,r.canvas.width,r.canvas.height),r.uniform1i(this.vImageLocation,0),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,this.mapColors.texture),r.uniform1i(this.vColorMapLocation,1),r.uniform2f(this.vRangeUVLocation,t[0],t[1]),r.uniform2f(this.vRangeSLocation,e[0],e[1])},e.prototype.setSquare=function(t,e,r,n){this.setSquareBase(t,e,r,n,n)},e.prototype.setSquareBase=function(t,e,r,n,o){var i=e,a=e+n,s=r,l=r+o;t.bufferData(t.ARRAY_BUFFER,new Float32Array([i,s,a,s,i,l,i,l,a,s,a,l]),t.STATIC_DRAW)},e}(ct);function bt(t){var e=l.createCanvas2d();e.width=256,e.height=1;var r=e.getContext("2d"),n=r.createLinearGradient(0,0,256,1);return t.forEach((function(t){var e=t[0],r=t[1];n.addColorStop(e,r)})),r.fillStyle=n,r.fillRect(0,0,256,1),{canvas:e,data:r.getImageData(0,0,256,1).data}}var Tt={temp:void 0,pressure:void 0,rain:void 0,humidity:void 0,visibility:void 0,wind:void 0,waves:void 0,waterTemp:void 0,seacurrent:void 0,windGust:void 0,solarRadiation:void 0,cloudSurface:void 0,snowDepth:void 0,getColorRamp:bt};Tt.temp=bt([[0,"rgb(149, 137, 211)"],[100/255,"rgb(149, 137, 211)"],[110/255,"rgb(150, 209, 216)"],[120/255,"rgb(129, 204, 197)"],[130/255,"rgb(103, 180, 186)"],[140/255,"rgb(95, 143, 197)"],[150/255,"rgb(80, 140, 62)"],[160/255,"rgb(121, 146, 28)"],[170/255,"rgb(171, 161, 14)"],[180/255,"rgb(223, 177, 6)"],[190/255,"rgb(243, 150, 6)"],[200/255,"rgb(236, 95, 21)"],[210/255,"rgb(190, 65, 18)"],[220/255,"rgb(138, 43, 10)"],[1,"rgb(138, 43, 10)"]]),Tt.pressure=bt([[0,"rgb(0, 103, 148)"],[100/255,"rgb(0, 103, 148)"],[110/255,"rgb(0, 103, 148)"],[120/255,"rgb(0, 103, 148)"],[130/255,"rgb(0, 117, 147)"],[140/255,"rgb(18, 134, 147)"],[150/255,"rgb(72, 154, 152)"],[160/255,"rgb(140, 178, 168)"],[170/255,"rgb(178, 176, 157)"],[180/255,"rgb(167, 142, 99)"],[190/255,"rgb(163, 111, 63)"],[200/255,"rgb(160, 82, 44)"],[1,"rgb(160, 82, 44)"]]),Tt.rain=bt([[0,"#a3a8af"],[41/255,"#81cd71"],[57/255,"#6ec569"],[70/255,"#68c19a"],[79/255,"#5db7c6"],[87/255,"#5fabd9"],[95/255,"#6199dc"],[104/255,"#6488e0"],[111/255,"#6973e4"],[127/255,"#9a84e7"],[132/255,"#f2a0e5"],[141/255,"#dc80c9"],[148/255,"#c15da8"],[1,"#b24a97"]]),Tt.humidity=bt([[0,"rgb(174, 110, 56)"],[30/255,"rgb(174, 110, 56)"],[60/255,"rgb(174, 110, 56)"],[90/255,"rgb(174, 146, 56)"],[100/255,"rgb(105, 174, 56)"],[130/255,"rgb(54, 175, 148)"],[160/255,"rgb(56, 158, 174)"],[170/255,"rgb(56, 142, 174)"],[180/255,"rgb(56, 133, 174)"],[190/255,"rgb(56, 111, 166)"],[200/255,"rgb(56, 71, 116)"],[1,"rgb(56, 71, 116)"]]),Tt.visibility=bt([[0,"rgb(164, 89, 164)"],[8/255,"rgb(164, 89, 164)"],[27/255,"rgb(168, 86, 86)"],[60/255,"rgb(89, 99, 164)"],[110/255,"rgb(70, 180, 74)"],[160/255,"rgb(91, 158, 85)"],[1,"rgb(91, 158, 85)"]]),Tt.wind=bt([[0,"rgb(98, 113, 184)"],[12/255,"rgb(61, 110, 163)"],[24/255,"rgb(74, 148, 170)"],[32/255,"rgb(74, 146, 148)"],[40/255,"rgb(77, 142, 124)"],[60/255,"rgb(76, 164, 76)"],[80/255,"rgb(103, 164, 54)"],[100/255,"rgb(162, 135, 64)"],[120/255,"rgb(162, 109, 92)"],[140/255,"rgb(141, 63, 92)"],[160/255,"rgb(151, 75, 145)"],[200/255,"rgb(95, 100, 160)"],[240/255,"rgb(91, 136, 161)"],[1,"rgb(91, 136, 161)"]]),Tt.waves=bt([[0,"rgb(50,158,186)"],[5/255,"rgb(50,158,186)"],[10/255,"rgb(50,158,186)"],[15/255,"rgb(48,128,164)"],[20/255,"rgb(48,99,142)"],[25/255,"rgb(52,101,166)"],[30/255,"rgb(56,104,192)"],[35/255,"rgb(56,83,169)"],[40/255,"rgb(57,61,143)"],[60/255,"rgb(172,68,196)"],[80/255,"rgb(134,48,49)"],[120/255,"rgb(194,76,91)"],[150/255,"rgb(192,118,105)"],[180/255,"rgb(192,162,157)"],[210/255,"rgb(192,162,157)"],[1,"rgb(236,225,203)"]]),Tt.waterTemp=bt([[0,"rgb(95, 143, 197)"],[50/255,"rgb(95, 143, 197)"],[75/255,"rgb(80, 140, 62)"],[100/255,"rgb(121, 146, 28)"],[125/255,"rgb(171, 161, 14)"],[150/255,"rgb(223, 177, 6)"],[175/255,"rgb(243, 150, 6)"],[200/255,"rgb(236, 95, 21)"],[225/255,"rgb(190, 65, 18)"],[250/255,"rgb(138, 43, 10)"],[1,"rgb(138, 43, 10)"]]),Tt.seacurrent=bt([[0,"rgb(72, 102, 170)"],[10/255,"rgb(61, 121, 110)"],[20/255,"rgb(50, 140, 50)"],[30/255,"rgb(140, 133, 49)"],[40/255,"rgb(143, 115, 50)"],[60/255,"rgb(117, 52, 68)"],[80/255,"rgb(107, 67, 131)"],[90/255,"rgb(67, 93, 133)"],[100/255,"rgb(73, 122, 132)"],[130/255,"rgb(115, 135, 139)"],[160/255,"rgb(144, 144, 144)"],[254/255,"rgb(144, 144, 144)"],[1,"rgb(144, 144, 144)"]]),Tt.windGust=bt([[0,"rgb(98, 113, 184)"],[10/255,"rgb(61, 110, 163)"],[20/255,"rgb(74, 148, 170)"],[30/255,"rgb(74, 146, 148)"],[40/255,"rgb(77, 142, 124)"],[60/255,"rgb(76, 164, 76)"],[80/255,"rgb(103, 164, 54)"],[100/255,"rgb(162, 135, 64)"],[120/255,"rgb(162, 109, 92)"],[140/255,"rgb(141, 63, 92)"],[160/255,"rgb(151, 75, 145)"],[200/255,"rgb(95, 100, 160)"],[240/255,"rgb(91, 136, 161)"],[1,"rgb(91, 136, 161)"]]),Tt.solarRadiation=bt([[0,"rgb(110, 110, 110)"],[25/255,"rgb(202, 72, 81)"],[50/255,"rgb(214, 100, 83)"],[75/255,"rgb(225, 126, 89)"],[100/255,"rgb(235, 151, 100)"],[125/255,"rgb(245, 175, 114)"],[150/255,"rgb(253, 199, 134)"],[175/255,"rgb(255, 223, 155)"],[200/255,"rgb(255, 246, 181)"],[1,"rgb(255, 246, 181)"]]),Tt.cloudSurface=bt([[0,"rgb(133, 130, 119)"],[50/255,"rgb(133, 130, 119)"],[75/255,"rgb(131, 133, 136)"],[100/255,"rgb(132, 140, 147)"],[120/255,"rgb(134, 145, 156)"],[140/255,"rgb(135, 150, 165)"],[170/255,"rgb(137, 157, 178)"],[200/255,"rgb(187, 187, 188)"],[1,"rgb(187, 187, 188)"]]),Tt.snowDepth=bt([[0,"rgb(70, 83, 151)"],[1.6/255,"rgb(70, 83, 151)"],[2.8/255,"rgb(67, 97, 160)"],[4/255,"rgb(64, 113, 164)"],[6/255,"rgb(62, 139, 166)"],[8/255,"rgb(65, 163, 167)"],[24/255,"rgb(95, 154, 56)"],[40/255,"rgb(168, 169, 65)"],[60/255,"rgb(171, 134, 62)"],[80/255,"rgb(172, 95, 62)"],[160/255,"rgb(174, 62, 86)"],[240/255,"rgb(177, 60, 116)"],[1,"rgb(177, 60, 116)"]]);var Ct={},At=function(e){function n(){var r=e.call(this)||this;return r.renderer=new _t,r.source=null,r.setColorConfig(t.Temp,Tt.temp),r.setColorConfig(t.Pressure,Tt.pressure),r.setColorConfig(t.Humidity,Tt.humidity),r.setColorConfig(t.Visibility,Tt.visibility),r.setColorConfig(t.Rain,Tt.rain),r.setColorConfig(t.Wind,Tt.wind),r.setColorConfig(t.Waves,Tt.waves),r.setColorConfig(t.WaterTemp,Tt.waterTemp),r.setColorConfig(t.SeaCurrents,Tt.seacurrent),r.setColorConfig(t.WindGust,Tt.windGust),r.setColorConfig(t.SolarRadiation,Tt.solarRadiation),r.setColorConfig(t.CloudSurface,Tt.cloudSurface),r.setColorConfig(t.SnowDepth,Tt.snowDepth),r}return r(n,e),n.prototype.setOption=function(t){var e=this;this.source?this.source.setConfig({url:t.url,factor:t.factor,zoom:t.zoom,onerror:t.onerror}):this.source=new rt({url:t.url,factor:t.factor,zoom:t.zoom,onerror:t.onerror}),this.source.addRenderCallback((function(r,n){e.renderer.setQueue(r,n,t.factor,Ct[t.factor])}))},n.prototype.setColorConfig=function(t,e){return Ct[t]=e,this},n.prototype.setDecodeConfig=function(t,e,r,n,o){return n?tt(t,n,o):K(t,e,r),this},n.prototype.renderExtent=function(t,e,r,n){return this.renderer.setView(t,e,r,n),this.renderer.show(),this.source&&this.source.loadByExtent(t,e),this.renderer.layerCanvas},n.prototype.render4326=function(){return this.renderer.layerCanvas},n.prototype.decodeFromCanvasPixel=function(t,e,r){return this.source.decodeTextByViewPixel(t,e,r)},n}(n),Lt=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.magFilter="linear",e}return r(e,t),e.prototype.render=function(){this.visible&&this.tileChunks&&this.tileChunks[0]&&(this.compute(),this.prepare(),this.draw(),this.refresh&&this.refresh())},e.prototype.setQueue=function(t,e,r,n){this.tileChunks=t,this.copyArray=e,this.factor=r,this.mapColors=n,this.render()},e.prototype.compute=function(){this.pixelXYArray=k(this.x,this.y,this.w,this.h,this.z,this.zoom)},e}(ut),Et="\nattribute vec2 a_position;//输入像素坐标\nattribute vec2 a_texCoord;//输入纹理坐标\nuniform vec2 u_resolution;// Used to pass in the resolution of the canvas\nvarying vec2 v_texCoord;// Used to pass the texture coordinates to the fragment shader\n\nvoid main() {\n // convert the position from pixels to 0.0 to 1.0\n vec2 zeroToOne = a_position / u_resolution;\n\n // convert from 0->1 to 0->2\n vec2 zeroToTwo = zeroToOne * 2.0;\n\n // convert from 0->2 to -1->+1 (clipspace)\n vec2 clipSpace = zeroToTwo - 1.0;\n\n gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);//已经是裁剪空间坐标,坐标方向和纹理坐标一致\n\n // pass the texCoord to the fragment shader\n // The GPU will interpolate this value between points.\n v_texCoord = a_texCoord;\n}",kt=function(e){function n(){var t=e.call(this)||this;if(t.gl=t.layerCanvas.getContext("webgl"),!t.gl)throw new Error("cannot get webgl context!");return t.scalarProgram=lt(t.gl,[Et,"\nprecision highp float;\nuniform sampler2D u_image;// 灰度\nuniform sampler2D u_color;// 色值映射\nvarying vec2 v_texCoord;// 坐标\n\nvoid main() {\n vec4 rgba = texture2D(u_image, v_texCoord);\n // 用灰度r转色斑rgba\n // vec4 color = texture2D(u_color, vec2(rgba.r, 0.5));\n float f = 1.0 - rgba.b;\n vec4 color = texture2D(u_color, vec2(rgba.r, 0.5)) * f;\n gl_FragColor = color;\n}"]),t.sPositionBuffer=t.bufferInitPixelCoord(t.scalarProgram),t.bufferInitTextureCoord(t.scalarProgram),t.sResolutionLocation=t.gl.getUniformLocation(t.scalarProgram,"u_resolution"),t.sImageLocation=t.gl.getUniformLocation(t.scalarProgram,"u_image"),t.sColorMapLocation=t.gl.getUniformLocation(t.scalarProgram,"u_color"),t.vectorProgram=lt(t.gl,[Et,"\nprecision highp float;\nuniform sampler2D u_image;\nuniform vec2 u_range_uv;\nuniform vec2 u_range_s;\nuniform sampler2D u_color;\nvarying vec2 v_texCoord;\n\nvoid main() {\n // 用矢量uv转灰度r\n vec4 uv = texture2D(u_image, v_texCoord);\n float u = uv.r * (u_range_uv.y - u_range_uv.x) + u_range_uv.x;\n float v = uv.g * (u_range_uv.y - u_range_uv.x) + u_range_uv.x;\n float s = sqrt(u * u + v * v);\n float r = (s - u_range_s.x) / (u_range_s.y - u_range_s.x);\n // 用灰度r转色斑rgba\n float f = 1.0 - uv.b;\n vec4 color = texture2D(u_color, vec2(r, 0.5)) * f;\n // 输出\n gl_FragColor = color;\n}\n"]),t.vPositionBuffer=t.bufferInitPixelCoord(t.vectorProgram),t.bufferInitTextureCoord(t.vectorProgram),t.vResolutionLocation=t.gl.getUniformLocation(t.vectorProgram,"u_resolution"),t.vImageLocation=t.gl.getUniformLocation(t.vectorProgram,"u_image"),t.vColorMapLocation=t.gl.getUniformLocation(t.vectorProgram,"u_color"),t.vRangeUVLocation=t.gl.getUniformLocation(t.vectorProgram,"u_range_uv"),t.vRangeSLocation=t.gl.getUniformLocation(t.vectorProgram,"u_range_s"),t}return r(n,e),n.prototype.setLayerCanvas=function(t){},n.prototype.prepare=function(){var t=this.gl,e=this.tileChunks[0];if(!e.texture){var r="nearest"===this.magFilter?t.NEAREST:t.LINEAR;e.texture=ht(t,t.NEAREST,r,t.CLAMP_TO_EDGE,e.image,e.image.width,e.image.height)}var n=this.mapColors.canvas;this.mapColors.texture=ht(t,t.NEAREST,t.LINEAR,t.CLAMP_TO_EDGE,n,n.width,n.height)},n.prototype.draw=function(){var e=this.gl;e.viewport(0,0,e.canvas.width,e.canvas.height),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT);var r=this.vPositionBuffer,n=this.sImageLocation;this.factor===t.Wind?(this.useVectorProgram([-25,26],[0,255/8]),n=this.vImageLocation):this.factor===t.SeaCurrents?(this.useVectorProgram([-2.5,255*.02-2.5],[0,2.55]),n=this.vImageLocation):this.useScalarProgram(),this.drawSquare(r,n),e.bindTexture(e.TEXTURE_2D,null)},n.prototype.drawSquare=function(t,e){var r=this.gl;r.bindBuffer(r.ARRAY_BUFFER,t),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,this.tileChunks[0].texture),r.uniform1i(e,0);var n=this.pixelXYArray,o=n[0],i=n[1],a=n[2],s=n[3],l=(o-this.extent.southWestX)*this.pixelRadio,u=(i-this.extent.northEastY)*this.pixelRadio,c=a*this.pixelRadio,d=s*this.pixelRadio;this.setSquareBase(r,l,u,c,d),r.drawArrays(r.TRIANGLES,0,6)},n.prototype.clear=function(){this.visible=!1;var t=this.gl;t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT)},n.prototype.bufferInitPixelCoord=function(t){var e=this.gl,r=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,r);var n=e.getAttribLocation(t,"a_position");return e.enableVertexAttribArray(n),e.vertexAttribPointer(n,2,e.FLOAT,!1,0,0),r},n.prototype.bufferInitTextureCoord=function(t){var e=this.gl,r=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),e.STATIC_DRAW);var n=e.getAttribLocation(t,"a_texCoord");e.enableVertexAttribArray(n),e.vertexAttribPointer(n,2,e.FLOAT,!1,0,0)},n.prototype.useScalarProgram=function(){var t=this.gl;t.useProgram(this.scalarProgram),t.bindBuffer(t.ARRAY_BUFFER,this.sPositionBuffer),t.uniform2f(this.sResolutionLocation,t.canvas.width,t.canvas.height),t.uniform1i(this.sImageLocation,0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,this.mapColors.texture),t.uniform1i(this.sColorMapLocation,1)},n.prototype.useVectorProgram=function(t,e){var r=this.gl;r.useProgram(this.vectorProgram),r.bindBuffer(r.ARRAY_BUFFER,this.vPositionBuffer),r.uniform2f(this.vResolutionLocation,r.canvas.width,r.canvas.height),r.uniform1i(this.vImageLocation,0),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,this.mapColors.texture),r.uniform1i(this.vColorMapLocation,1),r.uniform2f(this.vRangeUVLocation,t[0],t[1]),r.uniform2f(this.vRangeSLocation,e[0],e[1])},n.prototype.setSquareWest=function(t,e,r,n,o){var i=e-(n+1)/2,a=e+(n+1)/2,s=r,l=r+o;t.bufferData(t.ARRAY_BUFFER,new Float32Array([i,s,a,s,i,l,i,l,a,s,a,l]),t.STATIC_DRAW)},n.prototype.setSquareEast=function(t,e,r,n,o){var i=e+(n+1)/2,a=e+n+(n+1)/2,s=r,l=r+o;t.bufferData(t.ARRAY_BUFFER,new Float32Array([i,s,a,s,i,l,i,l,a,s,a,l]),t.STATIC_DRAW)},n.prototype.setSquare=function(t,e,r,n){this.setSquareBase(t,e,r,n,n)},n.prototype.setSquareBase=function(t,e,r,n,o){var i=e,a=e+n,s=r,l=r+o;t.bufferData(t.ARRAY_BUFFER,new Float32Array([i,s,a,s,i,l,i,l,a,s,a,l]),t.STATIC_DRAW)},n}(Lt),Pt=function(){function t(t){this.sourceZoom=3,this.sourceTileSize=Math.pow(2,this.sourceZoom),this.renderCallbackArray=[];var e=new Array(1);this.url=t.url,this.factor=t.factor,this.tileArray=e}return t.prototype.setConfig=function(t){this.url!==t.url&&(this.url=t.url,this.factor=t.factor,this.onerror=t.onerror,this.renderCallbackArray=[])},t.prototype.getFactor=function(){return this.factor},t.prototype.addRenderCallback=function(t){this.renderCallbackArray.push(t)},t.prototype.load=function(t){var e=this;if(this.url){var r=this.tileArray;v(this.url,(function(t){r[0]={tileXYZ:[],pixelXYS:[],image:t,isDecoded:!1,isLoaded:!1,decodeArr:[],canvas:null,texture:null},e.allLoadedCallback()}),(function(){t&&t()}))}},t.prototype.decodeTextByViewPixel=function(t,e,r){return this.decodeTextByWorldPixel(e.southWestX+t[0],e.northEastY+t[1],r)},t.prototype.decodeByViewPixel=function(t,e,r){return this.decodeByWorldPixel(e.southWestX+t[0],e.northEastY+t[1],r)},t.prototype.decodeTextByWorldPixel=function(t,e,r){return parseFloat(this.decodeByWorldPixel(t,e,r).value.toFixed(1))+H(this.factor)},t.prototype.decodeByWorldPixel=function(t,e,r){var n=this.tileArray[0];if(!n.isDecoded){if(!n.image)return null;n.canvas=j(n.image,n.decodeArr,this.factor),n.isDecoded=!0}var o=k(this.x,this.y,this.w,this.h,this.z,r),i=o[0],a=o[1],s=(t-i)/o[2],l=(e-a)/o[3];if(s>1||s<0||l>1||l<0)return null;var u=s*this.w,c=Math.round(u),d=l*this.h,p=Math.round(d);return n.decodeArr[p*this.w+c]},t.prototype.clear=function(){this.url=void 0},t.prototype.allLoadedCallback=function(){for(var t=0,e=this.renderCallbackArray.length;t<e;t++)this.renderCallbackArray[t](this.tileArray,this.copyArray)},t.idw=function(t,e){for(var r=0,n=0,o=0;o<t.length;o++){var i=Math.pow(e[o],2);r+=t[o].value/i,n+=1/i}return{r:0,g:0,value:r/n}},t}(),Rt={},Mt=function(e){function n(){var r=e.call(this)||this;return r.renderer=new kt,r.source=null,r.setColorConfig(t.Temp,Tt.temp),r.setColorConfig(t.Pressure,Tt.pressure),r.setColorConfig(t.Humidity,Tt.humidity),r.setColorConfig(t.Visibility,Tt.visibility),r.setColorConfig(t.Rain,Tt.rain),r.setColorConfig(t.Wind,Tt.wind),r.setColorConfig(t.Waves,Tt.waves),r.setColorConfig(t.WaterTemp,Tt.waterTemp),r.setColorConfig(t.SeaCurrents,Tt.seacurrent),r.setColorConfig(t.WindGust,Tt.windGust),r.setColorConfig(t.SolarRadiation,Tt.solarRadiation),r.setColorConfig(t.CloudSurface,Tt.cloudSurface),r.setColorConfig(t.SnowDepth,Tt.snowDepth),r}return r(n,e),n.prototype.setOption=function(t){var e=this;this.source?this.source.setConfig({url:t.url,factor:t.factor,zoom:t.zoom,onerror:t.onerror}):this.source=new Pt({url:t.url,factor:t.factor,zoom:t.zoom,onerror:t.onerror}),this.source.z=t.zoom,this.source.x=t.x,this.source.y=t.y,this.source.w=t.w,this.source.h=t.h,this.renderer.z=t.zoom,this.renderer.x=t.x,this.renderer.y=t.y,this.renderer.w=t.w,this.renderer.h=t.h,t.magFilter&&(this.renderer.magFilter=t.magFilter),this.source.addRenderCallback((function(r,n){e.renderer.setQueue(r,n,t.factor,Rt[t.factor])})),this.source.load(t.onerror)},n.prototype.setColorConfig=function(t,e){return Rt[t]=e,this},n.prototype.setDecodeConfig=function(t,e,r,n,o){return n?tt(t,n,o):K(t,e,r),this},n.prototype.renderExtent=function(t,e,r,n){return this.renderer.setView(t,e,r,n),this.renderer.render(),this.renderer.show(),this.renderer.layerCanvas},n.prototype.renderAll=function(){return this.source&&this.source.load(),this.renderer.layerCanvas},n.prototype.decodeFromCanvasPixel=function(t,e,r){return this.source.decodeTextByViewPixel(t,e,r)},n}(n),Bt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e}(function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.FRAME_RATE=30,e.FRAME_TIME=1e3/e.FRAME_RATE,e.initialized=!0,e.requestAnimationFrameId=void 0,e.lastAnimationFrameTime=0,e}return r(e,t),e.prototype.startAnimation=function(){!this.requestAnimationFrameId&&this.initialized&&(this.lastAnimationFrameTime=Date.now(),this.animationFrameCallback()),this.startCallback&&this.startCallback()},e.prototype.stopAnimation=function(){this.requestAnimationFrameId&&(this.windowCancelAnimationFrame(),this.requestAnimationFrameId=null),this.stopCallback&&this.stopCallback()},e.prototype.animationFrameCallback=function(){this.windowAnimationFrameCallback()},e.prototype.windowAnimationFrameCallback=function(){var t=this;this.requestAnimationFrameId=window.requestAnimationFrame((function(){t.animationFrameCallback();var e=Date.now();e-t.lastAnimationFrameTime>t.FRAME_TIME&&(t.lastAnimationFrameTime=e,t.render())}))},e.prototype.windowCancelAnimationFrame=function(){window.cancelAnimationFrame(this.requestAnimationFrameId)},e.prototype.wxAnimationFrameCallback=function(){var t=this;this.requestAnimationFrameId=setTimeout((function(){t.animationFrameCallback(),t.render()}),this.FRAME_TIME)},e.prototype.wxCancelAnimationFrame=function(){clearTimeout(this.requestAnimationFrameId)},e.prototype.drawFrame=function(){},e}(ut)),Ft=function(){},St=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype.createProgram=function(t){try{var e=pt(t,"\nprecision mediump float;\n\nattribute vec2 a_pos;\n\nvarying vec2 v_tex_pos;\n\nvoid main() {\n v_tex_pos = a_pos;\n gl_Position = vec4(1.0 - 2.0 * a_pos, 0, 1);\n}\n","\nprecision mediump float;\n\nuniform sampler2D u_screen;\nuniform float u_opacity;\n\nvarying vec2 v_tex_pos;\n\nvoid main() {\n vec4 color = texture2D(u_screen, 1.0 - v_tex_pos);\n // 即使值接近 1.0 也能保证不透明度淡出的技巧\n gl_FragColor = vec4(floor(255.0 * color * u_opacity) / 255.0);\n}");if(!e||!e.program)throw new Error("Failed to create screen program");this.screenProgram=e;var r=pt(t,"\nprecision mediump float;\nattribute vec4 a_index; //粒子索引\n\nuniform sampler2D u_particles; // 下一时刻的粒子状态纹理\nuniform sampler2D u_particles1; // 当前时刻的粒子状态纹理\nuniform sampler2D u_particles2; // 上一时刻的粒子状态纹理\nuniform float u_particles_res; // 粒子状态纹理分辨率\nuniform vec4 uVPars1;\n\nuniform vec4 u_viewport;//视口在UV上的纹理坐标范围(可能大于1)\n\nvarying vec2 v_particle_pos_uv;\n\nvoid main() {\n vec4 tex0 = texture2D(u_particles, a_index.xy / u_particles_res);\n vec4 tex1 = texture2D(u_particles1, a_index.xy / u_particles_res);\n vec4 tex2 = texture2D(u_particles2, a_index.xy / u_particles_res);\n\n // 计算三个位置\n vec2 pos0 = tex0.rg / 255.0 + tex0.ba; // A\n\n // 转UV纹理坐标\n v_particle_pos_uv = vec2(\n fract(pos0.x * (u_viewport.y - u_viewport.x) + u_viewport.x),\n pos0.y * (u_viewport.w - u_viewport.z) + u_viewport.z);\n \n pos0 = vec2(pos0.x * 2.0 - 1.0, 1.0 - 2.0 * pos0.y);\n vec2 pos1 = tex1.rg / 255.0 + tex1.ba; // B\n pos1 = vec2(pos1.x * 2.0 - 1.0, 1.0 - 2.0 * pos1.y);\n vec2 pos2 = tex2.rg / 255.0 + tex2.ba; // C\n pos2 = vec2(pos2.x * 2.0 - 1.0, 1.0 - 2.0 * pos2.y);\n \n // 计算两端法向量\n vec2 dirBA = pos0 - pos1;\n vec2 dirBAN = normalize(dirBA);\n float d = length(dirBA);\n vec2 dirBARN = vec2(dirBAN.y, -dirBAN.x); // 单位法向量\n\n vec2 dirCB = pos1 - pos2;\n vec2 dirCBN = normalize(dirCB);\n float d1 = length(dirCB);\n vec2 dirCBRN = vec2(dirCBN.y, -dirCBN.x);\n\n vec2 pos = pos1;\n if (a_index.w == 1.0) {\n pos = pos0;\n }\n\n if (d > 0.05) {\n // 排除掉新生成的点\n pos.x += 10.0;\n } else if (a_index.w == 1.0) {\n pos += dirBARN * (a_index.zz * uVPars1.xy + uVPars1.zw);\n } else if (dirCB == vec2(0.0, 0.0) || d1 > 0.5) {\n pos += dirBARN * (a_index.zz * uVPars1.xy + uVPars1.zw);\n } else {\n pos += dirCBRN * (a_index.zz * uVPars1.xy + uVPars1.zw);\n }\n gl_Position = vec4(pos.xy, 0.0, 1.0); \n}\n","\nprecision mediump float;\n\nuniform sampler2D u_wind;\nuniform vec2 u_wind_min;\nuniform vec2 u_wind_max;\nuniform sampler2D u_color_ramp;\n\nvarying vec2 v_particle_pos_uv;\n\nconst highp vec4 uv0 = vec4(125/255,125/255,1.0,1.0);\n\nvec4 clampToBorderTexture(sampler2D ts, vec2 uv){\n vec4 c = texture2D(ts, uv);\n if (uv.x>1. || uv.x<0. || uv.y>1. || uv.y<0.) {\n return uv0;\n }\n return c;\n}\n\nvoid main() {\n // vec4 uv = texture2D(u_wind, v_particle_pos_uv);\n vec4 uv = clampToBorderTexture(u_wind, v_particle_pos_uv);\n vec2 velocity = mix(u_wind_min, u_wind_max, uv.rg);\n float speed_t = length(velocity) / length(u_wind_max);\n\n // 色值映射编码为 16x16\n vec2 ramp_pos = vec2(\n fract(16.0 * speed_t),\n floor(16.0 * speed_t) / 16.0);\n\n float f = 1.0 - uv.b;\n gl_FragColor = texture2D(u_color_ramp, ramp_pos) * f;\n}\n");if(!r||!r.program)throw new Error("Failed to create draw particle program");this.drawParticleProgram=r;var n=pt(t,"\nprecision mediump float;\n\nattribute vec2 a_pos;\n\nvarying vec2 v_tex_pos;\n\nvoid main() {\n v_tex_pos = a_pos;\n vec2 clipSpace = 2.0 * a_pos - 1.0;\n gl_Position = vec4(clipSpace, 0, 1);\n}\n","\nprecision highp float;\n\nuniform sampler2D u_particles;\nuniform sampler2D u_wind;\nuniform vec2 u_wind_res;\nuniform vec2 u_wind_min;\nuniform vec2 u_wind_max;\nuniform float u_rand_seed;\nuniform float u_speed_factor;\nuniform float u_drop_rate;\nuniform float u_drop_rate_bump;\nuniform vec4 u_viewport;//视口在UV上的纹理坐标范围(可能大于1)\n\nvarying vec2 v_tex_pos;\n\n// 一个用于伪随机数生成的 GLSL 函数,可以接受一对数字作为输入。\n// https://stackoverflow.com/questions/4200224/random-noise-functions-for-glsl\n// http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/\nconst vec3 rand_constants = vec3(12.9898, 78.233, 4375.85453);\n\nconst highp vec4 uv0 = vec4(125/255,125/255,1.0,1.0);\n\nfloat rand(const vec2 co) {\n float t = dot(rand_constants.xy, co);\n return fract(sin(t) * (rand_constants.z + t));\n}\n\nvec4 clampToBorderTexture(sampler2D ts, vec2 uv){\n vec4 c = texture2D(ts, uv);\n if (uv.r>1. || uv.r<0.0 || uv.g>1. || uv.g<0.) {\n return uv0;\n }\n return c;\n}\n\n// 风速查询;使用基于 4 个相邻像素的手动双线性过滤进行平滑插值\nvec2 lookup_wind(const vec2 uv) {\n // return texture2D(u_wind, uv).rg;\n vec2 px = 1.0 / u_wind_res;\n vec2 vc = (floor(uv * u_wind_res)) * px;\n vec2 f = fract(uv * u_wind_res);\n // vec2 tl = texture2D(u_wind, vc).rg;\n // vec2 tr = texture2D(u_wind, vc + vec2(px.x, 0)).rg;\n // vec2 bl = texture2D(u_wind, vc + vec2(0, px.y)).rg;\n // vec2 br = texture2D(u_wind, vc + px).rg;\n vec2 tl = clampToBorderTexture(u_wind, vc).rg;\n // vec2 tr = clampToBorderTexture(u_wind, vc + vec2(px.x, 0)).rg;\n // vec2 bl = clampToBorderTexture(u_wind, vc + vec2(0, px.y)).rg;\n // vec2 br = clampToBorderTexture(u_wind, vc + px).rg;\n // return mix(mix(tl, tr, f.x), mix(bl, br, f.x), f.y);\n return tl;\n}\n\nvoid main() {\n // 查找粒子像素颜色\n vec4 color = texture2D(u_particles, v_tex_pos);\n \n // 粒子状态 RGBA 值解码当前粒子位置,视口纹理坐标\n vec2 pos = vec2(\n color.r / 255.0 + color.b,\n color.g / 255.0 + color.a);\n \n // uv纹理坐标\n vec2 pos_