UNPKG

weatherv-patch

Version:

Weather visualization SDK - Enhanced features patch for v0.1.66

1 lines 134 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).weatherv={})}(this,(function(t){"use strict";var e={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"},n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)};function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}"function"==typeof SuppressedError&&SuppressedError;var o=function(){this.visible=!0},i={exports:{}};!function(t,e){var n=function(){var t={},e=Math.PI/180,n=180/Math.PI,r=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 n=this.size,r=t[this.size]={};r.Bc=[],r.Cc=[],r.zc=[],r.Ac=[];for(var o=0;o<30;o++)r.Bc.push(n/360),r.Cc.push(n/(2*Math.PI)),r.zc.push(n/2),r.Ac.push(n),n*=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,n){if(i(n)){var r=this.size*Math.pow(2,n),o=r/2,a=r/360,s=r/(2*Math.PI),l=r,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[n],u=Math.min(Math.max(Math.sin(e*t[1]),-.9999),.9999),c=Math.round(o+t[0]*this.Bc[n]),d=Math.round(o+.5*Math.log((1+u)/(1-u))*-this.Cc[n]);return c>this.Ac[n]*this.expansion&&(c=this.Ac[n]*this.expansion),d>this.Ac[n]&&(d=this.Ac[n]),[c,d]},a.prototype.ll=function(t,e){if(i(e)){var r=this.size*Math.pow(2,e),o=r/360,a=r/(2*Math.PI),s=r/2,l=(t[1]-s)/-a;return[(t[0]-s)/o,n*(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],n*(2*Math.atan(Math.exp(l))-.5*Math.PI)]},a.prototype.bbox=function(t,e,n,r,o){r&&(e=Math.pow(2,n)-1-e);var i=[t*this.size,(+e+1)*this.size],a=[(+t+1)*this.size,e*this.size],s=this.ll(i,n).concat(this.ll(a,n));return"900913"===o?this.convert(s,"900913"):s},a.prototype.xyz=function(t,e,n,r){"900913"===r&&(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(n){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 n=[r*t[0]*e,r*Math.log(Math.tan(.25*Math.PI+.5*t[1]*e))];return n[0]>o&&(n[0]=o),n[0]<-o&&(n[0]=-o),n[1]>o&&(n[1]=o),n[1]<-o&&(n[1]=-o),n},a.prototype.inverse=function(t){return[t[0]*n/r,(.5*Math.PI-2*Math.atan(Math.exp(-t[1]/r)))*n]},a}();t.exports=n}(i);var a=i.exports,s="web",l=s,u=function(){function t(){}return t.setWx=function(){l="wx"},t.createCanvas2d=function(t){return t||(t={type:"2d"}),l===s?document.createElement("canvas"):uni.createOffscreenCanvas(t)},t.createCanvasGL=function(t){return t||(t={type:"webgl"}),l===s?document.createElement("canvas"):uni.createOffscreenCanvas(t)},t}(),c=20037508.342789244,d=2*c,p=d/8,h=256,v=new a({size:h});function f(t,e,n){var r=new Image;r.crossOrigin="anonymous",r.onload=function(){return e(r)},r.onerror=n||function(t){},r.src=t}function g(t,n){var r=u.createCanvas2d();r.width=t.width,r.height=t.height;var o=r.getContext("2d");o.drawImage(t,0,0);for(var i=o.getImageData(0,0,r.width,r.height).data,a=[],s=[],l=0,c=i.length/4;l<c;l++){var d=4*l,p=i[d],h=i[d+1];n===e.Wind?(a[l]=.2*p-25,s[l]=.2*h-25):n===e.SeaCurrents&&(0===p&&0===h?(a[l]=null,s[l]=null):(a[l]=.04*p-5,s[l]=.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 m(t,e,n){return[Math.round((e-t[0])/t[1]),Math.round((n-t[3])/t[5])]}function x(t){return~~((t+c)/p)}function y(t){return~~((c-t)/p)}function w(t,e){return t<0?w(t+e,e):t>=e?w(t-e,e):t}function _(t){return parseFloat(Math.log2(d/t/256).toFixed(6))}function b(t,e,n){t+=c,e=c-e;var r=256*Math.pow(2,n),o=d/r;return[t/o,e/o]}function T(t,e,n){return void 0===n&&(n=3),~~(t/(256*Math.pow(2,e)/Math.pow(2,n)))}function C(t,e,n){return t/(256*e/n)}function A(t,e,n){void 0===n&&(n=3);var r=t.southWestX,o=t.southWestY,i=t.northEastX,a=t.northEastY,s=Math.pow(2,e),l=Math.pow(2,n);return{southWestX:C(r,s,l),southWestY:C(o,s,l),northEastX:C(i,s,l),northEastY:C(a,s,l)}}function E(t,e,n,r){void 0===r&&(r=3);var o=Math.pow(2,n),i=Math.pow(2,r),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 k(t){var e=256*Math.pow(2,t[2])/2,n=!1;return t[1]>e&&(n=!0),n}function R(t,e,n,r){var o=Math.pow(2,n),i=256*Math.pow(2,r)/o;return[i*t,i*e,i]}function L(t,e,n,r,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(n*s/a),Math.round(r*s/a)]}function P(t,e){var n=h*Math.pow(2,e);return[t.southWestX/n,t.northEastX/n,t.northEastY/n,t.southWestY/n]}function M(t,e){var n=e[0],r=e[1],o=e[2],i=e[3];return[(t.southWestX-n)/o,(t.northEastX-n)/o,(t.northEastY-r)/i,(t.southWestY-r)/i]}function B(t,e){var n=v.ll([t.southWestX,t.southWestY],e),r=v.ll([t.northEastX,t.northEastY],e);return{southWestX:n[0],southWestY:n[1],northEastX:r[0],northEastY:r[1]}}function F(t,e){var n=t[0],r=t[1],o=U(n),i=o[0],a=o[1],s=v.px([i,r],e),l=s[0],u=s[1];return[l+a*(h*Math.pow(2,e)),u]}function S(t,e){var n=t[0],r=t[1],o=function(t,e){void 0===e&&(e=0);return t<0?U(t,e):[t,e]}(n),i=o[0],a=o[1],s=v.px([i,r],e),l=s[0],u=s[1];return[l+a*(h*Math.pow(2,e)),u]}function D(t,e,n){var r=t[0],o=t[1],i=e[0],a=e[1],s=U(r),l=s[0],u=s[1],c=U(i),d=c[0],p=c[1],f=v.px([l,o],n),g=f[0],m=f[1],x=v.px([d,a],n),y=x[0],w=x[1],_=h*Math.pow(2,n);return[[g+u*_,m],[y+p*_,w]]}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 z(){var t=(new Date).getTime().toString();return t.substring(6,t.length)+Math.random().toString(36).substring(2,6)}var I,W,X,Y,N=Object.freeze({__proto__:null,loadImage:f,loadImageWx:function(t,e,n){var r=u.createCanvas2d({type:"2d",width:257,height:257});r.getContext("2d");var o=r.createImage();o.onload=function(){return e(o)},o.src=t},loadSvg:function(t,e,n){var r=new XMLHttpRequest;r.addEventListener("load",(function(){var t=r.responseXML.documentElement.cloneNode(!0);e(t)})),r.open("GET",t),r.send()},getVectorJsonFromImage:g,wrap:function(t,e,n){var r=n-e,o=((t-e)%r+r)%r+e;return o===e?n:o},lonLat2pixel:m,lonLatExtent2canvasCS:function(t,e,n,r,o){var i=m(t,e,o),a=i[0],s=i[1],l=m(t,r,n);return[a,s,l[0]-a,l[1]-s]},tileX:x,tileY:y,tileRange:function(t){var e=t[0],n=t[1],r=t[2],o=t[3];return[x(e),y(n),x(r),y(o)]},formatXY:w,getTransform:function(t,e,n){var r=e/n;return[t[0],r,0,t[3],0,-r]},zoomFromResolution3857:_,pixelFrom3857:b,tileRangeAmap:function(t,e){var n=t[0],r=t[1],o=t[2],i=t[3];return[T(n,e),T(r,e),T(o,e),T(i,e)]},tileIndexFromWorldPixelAndZoom:T,tileIndexFromWorldPixel:C,extentFromPixelToTile:A,canvasXYFromWorldXY:E,checkNorthOrSouth:k,xyz2Amap:function(t,e,n,r){var o=Math.pow(2,n),i=256*Math.pow(2,r)/o;return[[i*t,i*e],[i*(t+1),i*(e+1)]]},xyz2Amap2:R,source2world:L,extent2UV:P,extent2AreaUV:M,extent2extent4326:B,px:F,px2:S,px3:D,formatLon:U,convert:function(t,e){return v.convert(t,e)},genUUID:z}),V={},O={},G={};function q(t,e,n,r,o){for(var i=t.data,a=r?r.data:null,s=t.data.length,l=0;l<s;l+=4){var u=void 0;if(!n)throw new Error("no decodeStrategy");u=n(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 Z(t){var e=t/16,n=Math.floor(e),r=0;return n>0&&(r=Math.pow(2,n+3)),((t-16*n)*((Math.pow(2,n+4)-r)/16)+r)/10}function j(t,e,n,r,o,i){q(t,0,(function(t,n){return e[t]={r:n,value:n*i+o},4*n}),n,r)}function H(t){switch(t){case e.Temp:return"°C";case e.Pressure:return"hPa";case e.Humidity:return"%";case e.Visibility:return"km";case e.Wind:return"m/s";case e.Rain:return"mm";case e.WaterTemp:return"°C";case e.Waves:return"m";case e.SeaCurrents:case e.WindGust:return"m/s";case e.SolarRadiation:return"W/m^2";case e.CloudSurface:return"%";case e.SnowDepth:return"m"}return""}function $(t,n,r,o){var i;if(257===t.width)i=W;else if(2049===t.width)i=Y;else{var a=u.createCanvas2d();a.width=t.width,a.height=t.height,i=a.getContext("2d")}i.drawImage(t,0,0);var s=i.getImageData(0,0,t.width,t.height),l=null,c=null,d=null;return o&&((c=(l=u.createCanvas2d()).getContext("2d")).canvas.width=t.width,c.canvas.height=t.height,c.imageSmoothingQuality="high",d=c.createImageData(t.width,t.height)),V[r]?j(s,n,d,o,V[r].min,V[r].step):O[r]?function(t,e,n,r,o,i,a){q(t,0,(function(t,n,r,s){var l,u,c;return n<10&&r<10?(l=125,u=125,c=0):(l=i*n+o,u=i*r+o,c=Math.sqrt(l*l+u*u)),e[t]={r:l,g:u,b:s,value:c},4*Math.floor(c*a)}),n,r)}(s,n,d,o,O[r].min,O[r].step,O[r].slope):G[r]?function(t,e,n,r,o,i){q(t,0,(function(t,n,r){var a=o(n,r);return e[t]={r:n,g:r,value:a},i?i(n,r,a):4*n}),n,r)}(s,n,d,o,G[r].gray2value,G[r].gray2Color):r===e.Rain?function(t,e,n,r){q(t,0,(function(t,n){return e[t]={r:n,value:Z(n)},4*n}),n,r)}(s,n,d,o):r===e.Temp?j(s,n,d,o,-70,.5):r===e.Pressure?j(s,n,d,o,930,.5):r===e.Humidity?j(s,n,d,o,0,.5):r===e.Visibility?j(s,n,d,o,0,.1):r===e.Waves?j(s,n,d,o,0,.05):r===e.WaterTemp?j(s,n,d,o,-10,.2):r===e.WindGust?j(s,n,d,o,0,.1):r===e.SolarRadiation?j(s,n,d,o,0,5):r===e.CloudSurface?j(s,n,d,o,0,.5):r===e.SnowDepth&&j(s,n,d,o,0,.0125),c&&c.putImageData(d,0,0),l}function Q(t,e,n){return t[0]*n+e}function K(t,n){var r=0;return V[n]?r=Q(t,V[n].min,V[n].step):O[n]?r=function(t,e,n){var r=t[0],o=t[1];if(r<10&&o<10)return 0;var i=n*r+e,a=n*o+e;return Math.sqrt(i*i+a*a)}(t,O[n].min,O[n].step):G[n]?r=function(t,e){return e(t[0],t[1])}(t,G[n].gray2value):n===e.Rain?r=Z(t[0]):n===e.Temp?r=Q(t,-70,.5):n===e.Pressure?r=Q(t,930,.5):n===e.Humidity?r=Q(t,0,.5):n===e.Visibility?r=Q(t,0,.1):n===e.Waves?r=Q(t,0,.05):n===e.WaterTemp?r=Q(t,-10,.2):n===e.WindGust?r=Q(t,0,.1):n===e.SolarRadiation?r=Q(t,0,5):n===e.CloudSurface?r=Q(t,0,.5):n===e.SnowDepth&&(r=Q(t,0,.0125)),r}function J(t,e,n){V[t]={min:e,step:n}}function tt(t,e,n,r){O[t]={min:e,step:n,slope:r}}function et(t,e,n){G[t]={gray2value:e,gray2color:n}}function nt(){return O}tt(e.Wind,-25,.2,8),tt(e.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 n=Math.pow(2,e);this.sourceTileSize=n;for(var r=new Array(this.sourceTileSize*this.sourceTileSize),o=n-1;o>=0;--o)for(var i=n-1;i>=0;--i){r[o*n+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=r}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 n=Math.pow(2,e);if(this.sourceTileSize=n,this.tileArray.length<n*n){this.tileArray=new Array(this.sourceTileSize*this.sourceTileSize);for(var r=this.tileArray,o=n-1;o>=0;--o)for(var i=n-1;i>=0;--i){r[o*n+i]={tileXYZ:[i,o,e],pixelXYS:[0,0,0],image:null,isLoaded:!1,isDecoded:!1,decodeArr:null}}}else for(var a=(r=this.tileArray).length-1;a>=0;--a)r[a].image=null,r[a].isDecoded=!1,r[a].canvas=null,r[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 n=this;if(this.url){this.copyArray=[];for(var r=this.sourceZoom,o=this.sourceTileSize,i=this.tileArray,a=A(t,e,r),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,r,d):h.loadTile(s,e,h.sourceZoom,(function(e){i[l].image=e,n.tileLoadedCallback(l,a,t,r,d)}),(function(e){i[l].image=null,n.tileLoadedCallback(l,a,t,r,d),n.onerror&&n.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,n){return this.decodeTextByWorldPixel(e.southWestX+t[0],e.northEastY+t[1],n)},t.prototype.decodeByViewPixel=function(t,e,n){return this.decodeByWorldPixel(e.southWestX+t[0],e.northEastY+t[1],n)},t.prototype.decodeTextByWorldPixel=function(t,e,n){return parseFloat(this.decodeByWorldPixel(t,e,n).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 n=t[0],r=t[1];n=U(n)[0];var o=this.tileArray[0].image,i=o.width-1,a=o.height-1,s=i*this.sourceTileSize,l=a*this.sourceTileSize,u=S([n,r],e+1),c=S([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 y=x.getImageData(Math.round(f),Math.round(g),1,1);return{rgba:y.data,value:K(y.data,this.factor)}},t.prototype.decodeByWorldPixel=function(t,e,n){var r=E(t,e,n,this.sourceZoom),o=~~r.cx,i=~~r.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=$(a.image,a.decodeArr,this.factor),a.isDecoded=!0}var s=a.image.width-1,l=r.cx.toString().split("."),u=(r.cx-parseInt(l[0],10))*s,c=Math.round(u),d=r.cy.toString().split("."),p=(r.cy-parseInt(d[0],10))*s,h=Math.round(p);return a.decodeArr[h*(s+1)+c]},t.prototype.tileLoadedCallback=function(t,e,n,r,o){this.copyArray.push(t,e,n,r),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,n,r,o){var i=this.url.replace(/{x}/,"".concat(t));f(i=(i=i.replace(/{y}/,"".concat(e))).replace(/{z}/,"".concat(n)),r,o)},t.prototype.clear=function(){this.url=void 0},t.idw=function(t,e){for(var n=0,r=0,o=0;o<t.length;o++){var i=Math.pow(e[o],2);n+=t[o].value/i,r+=1/i}return{r:0,g:0,value:n/r}},t}();function ot(t){console.error(t)}const it=/ERROR:\s*\d+:(\d+)/gi;function at(t,e=""){const n=[...e.matchAll(it)],r=new Map(n.map(((t,r)=>{const o=parseInt(t[1]),i=n[r+1],a=i?i.index:e.length;return[o-1,e.substring(t.index,a)]})));return t.split("\n").map(((t,e)=>{const n=r.get(e);return`${e+1}: ${t}${n?`\n\n^^^ ${n}`:""}`})).join("\n")}function st(t,e,n,r){const o=r||ot,i=t.createShader(n);t.shaderSource(i,e),t.compileShader(i);if(!t.getShaderParameter(i,t.COMPILE_STATUS)){const n=t.getShaderInfoLog(i);return o(`Error compiling shader: ${n}\n${at(e,n)}`),t.deleteShader(i),null}return i}const lt=["VERTEX_SHADER","FRAGMENT_SHADER"];function ut(t,e,n,r,o){const i=[];for(let n=0;n<e.length;++n)i.push(st(t,e[n],t[lt[n]],o));return function(t,e,n,r,o){const i=o||ot,a=t.createProgram();if(e.forEach((function(e){t.attachShader(a,e)})),n&&n.forEach((function(e,n){t.bindAttribLocation(a,r?r[n]:n,e)})),t.linkProgram(a),!t.getProgramParameter(a,t.LINK_STATUS))return i(`Error in program linking: ${t.getProgramInfoLog(a)}\n${e.map((e=>{const n=at(t.getShaderSource(e));return`${t.getShaderParameter(e,t.SHADER_TYPE)}:\n${n}`})).join("\n")}`),t.deleteProgram(a),null;return a}(t,i,n,r,o)}var ct=function(){function t(){this.visible=!0,this.layerCanvas=u.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,n,r){this.extent=t,this.extent4326=B(t,e),this.zoom=e,this.size=n,this.pixelRadio=r,this.worldSize=256*Math.pow(2,e),this.resize()},t.prototype.show=function(){this.visible=!0},t}(),dt=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,n,r){this.tileChunks=t,this.copyArray=e,this.factor=n,this.mapColors=r,this.render()},e.prototype.compute=function(){for(var t=this.copyArray,e=[],n=0,r=t.length;n<r;n+=4){var o=R(t[n+1],t[n+2],t[n+3],this.zoom),i=o[0],a=o[1],s=o[2];e.push(t[n],i,a,s)}this.pixelXYArray=e},e}(ct);function pt(t,e,n){var r=t.createShader(e);if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new Error(t.getShaderInfoLog(r));return r}function ht(t,e,n){var r=t.createProgram(),o=pt(t,t.VERTEX_SHADER,e),i=pt(t,t.FRAGMENT_SHADER,n);if(t.attachShader(r,o),t.attachShader(r,i),t.linkProgram(r),!t.getProgramParameter(r,t.LINK_STATUS))throw new Error(t.getProgramInfoLog(r));for(var a={program:r},s=t.getProgramParameter(r,t.ACTIVE_ATTRIBUTES),l=0;l<s;l++){var u=t.getActiveAttrib(r,l);a[u.name]=t.getAttribLocation(r,u.name)}var c=t.getProgramParameter(r,t.ACTIVE_UNIFORMS);for(l=0;l<c;l++){var d=t.getActiveUniform(r,l);a[d.name]=t.getUniformLocation(r,d.name)}return a}function vt(t,e,n,r,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,n),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,r),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 ft(t,e,n){t.activeTexture(t.TEXTURE0+n),t.bindTexture(t.TEXTURE_2D,e)}function gt(t,e){var n=t.createBuffer();return t.bindBuffer(t.ARRAY_BUFFER,n),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW),n}function mt(t,e,n,r,o){void 0===o&&(o=WebGLRenderingContext.FLOAT),t.bindBuffer(t.ARRAY_BUFFER,e),t.enableVertexAttribArray(n),t.vertexAttribPointer(n,r,o,!1,0,0)}function xt(t,e,n){t.bindFramebuffer(t.FRAMEBUFFER,e),n&&t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,n,0)}var yt="\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}",_t="\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",bt=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=ut(e.gl,[yt,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=ut(e.gl,[yt,_t]),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=ut(this.gl,[yt,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=ut(this.gl,[yt,_t]),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,n=0,r=e.length;n<r;n+=4){var o=this.tileChunks[e[n]];o.texture||o.image&&(o.texture=vt(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=vt(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,n=this.sImageLocation;if(nt()[this.factor]){var r=nt()[this.factor];this.useVectorProgram([r.min,255*r.step+r.min],[0,255/r.slope]),n=this.vImageLocation}else this.useScalarProgram();this.drawTile(e,n),t.bindTexture(t.TEXTURE_2D,null)},e.prototype.drawTile=function(t,e){for(var n=this.pixelXYArray,r=0,o=n.length;r<o;r+=4){var i=(n[r+1]-this.extent.southWestX)*this.pixelRadio,a=(n[r+2]-this.extent.northEastY)*this.pixelRadio,s=n[r+3]*this.pixelRadio,l=this.tileChunks[n[r]];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,n=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,n);var r=e.getAttribLocation(t,"a_position");return e.enableVertexAttribArray(r),e.vertexAttribPointer(r,2,e.FLOAT,!1,0,0),n},e.prototype.bufferInitTextureCoord=function(t){var e=this.gl,n=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,n),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),e.STATIC_DRAW);var r=e.getAttribLocation(t,"a_texCoord");e.enableVertexAttribArray(r),e.vertexAttribPointer(r,2,e.FLOAT,!1,0,0)},e.prototype.renderTile=function(t,e,n,r,o,i){var a=this.gl;a.bindBuffer(a.ARRAY_BUFFER,o),this.setSquare(a,e,n,r),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 n=this.gl;n.useProgram(this.vectorProgram),n.bindBuffer(n.ARRAY_BUFFER,this.vPositionBuffer),n.uniform2f(this.vResolutionLocation,n.canvas.width,n.canvas.height),n.uniform1i(this.vImageLocation,0),n.activeTexture(n.TEXTURE1),n.bindTexture(n.TEXTURE_2D,this.mapColors.texture),n.uniform1i(this.vColorMapLocation,1),n.uniform2f(this.vRangeUVLocation,t[0],t[1]),n.uniform2f(this.vRangeSLocation,e[0],e[1])},e.prototype.setSquare=function(t,e,n,r){this.setSquareBase(t,e,n,r,r)},e.prototype.setSquareBase=function(t,e,n,r,o){var i=e,a=e+r,s=n,l=n+o;t.bufferData(t.ARRAY_BUFFER,new Float32Array([i,s,a,s,i,l,i,l,a,s,a,l]),t.STATIC_DRAW)},e}(dt);function Tt(t){var e=u.createCanvas2d();e.width=256,e.height=1;var n=e.getContext("2d"),r=n.createLinearGradient(0,0,256,1);return t.forEach((function(t){var e=t[0],n=t[1];r.addColorStop(e,n)})),n.fillStyle=r,n.fillRect(0,0,256,1),{canvas:e,data:n.getImageData(0,0,256,1).data}}var Ct={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:Tt};Ct.temp=Tt([[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)"]]),Ct.pressure=Tt([[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)"]]),Ct.rain=Tt([[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"]]),Ct.humidity=Tt([[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)"]]),Ct.visibility=Tt([[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)"]]),Ct.wind=Tt([[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)"]]),Ct.waves=Tt([[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)"]]),Ct.waterTemp=Tt([[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)"]]),Ct.seacurrent=Tt([[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)"]]),Ct.windGust=Tt([[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)"]]),Ct.solarRadiation=Tt([[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)"]]),Ct.cloudSurface=Tt([[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)"]]),Ct.snowDepth=Tt([[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 At={},Et=function(t){function n(){var n=t.call(this)||this;return n.renderer=new bt,n.source=null,n.setColorConfig(e.Temp,Ct.temp),n.setColorConfig(e.Pressure,Ct.pressure),n.setColorConfig(e.Humidity,Ct.humidity),n.setColorConfig(e.Visibility,Ct.visibility),n.setColorConfig(e.Rain,Ct.rain),n.setColorConfig(e.Wind,Ct.wind),n.setColorConfig(e.Waves,Ct.waves),n.setColorConfig(e.WaterTemp,Ct.waterTemp),n.setColorConfig(e.SeaCurrents,Ct.seacurrent),n.setColorConfig(e.WindGust,Ct.windGust),n.setColorConfig(e.SolarRadiation,Ct.solarRadiation),n.setColorConfig(e.CloudSurface,Ct.cloudSurface),n.setColorConfig(e.SnowDepth,Ct.snowDepth),n}return r(n,t),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(n,r){e.renderer.setQueue(n,r,t.factor,At[t.factor])}))},n.prototype.setColorConfig=function(t,e){return At[t]=e,this},n.prototype.setDecodeConfig=function(t,e,n,r,o){return r?et(t,r,o):J(t,e,n),this},n.prototype.renderExtent=function(t,e,n,r){return this.renderer.setView(t,e,n,r),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,n){return this.source.decodeTextByViewPixel(t,e,n)},n}(o),kt=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,n,r){this.tileChunks=t,this.copyArray=e,this.factor=n,this.mapColors=r,this.render()},e.prototype.compute=function(){this.pixelXYArray=L(this.x,this.y,this.w,this.h,this.z,this.zoom)},e}(ct),Rt="\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}",Lt=function(t){function n(){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=ut(e.gl,[Rt,"\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}"]),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=ut(e.gl,[Rt,"\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"]),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(n,t),n.prototype.setLayerCanvas=function(t){},n.prototype.prepare=function(){var t=this.gl,e=this.tileChunks[0];if(!e.texture){var n="nearest"===this.magFilter?t.NEAREST:t.LINEAR;e.texture=vt(t,t.NEAREST,n,t.CLAMP_TO_EDGE,e.image,e.image.width,e.image.height)}var r=this.mapColors.canvas;this.mapColors.texture=vt(t,t.NEAREST,t.LINEAR,t.CLAMP_TO_EDGE,r,r.width,r.height)},n.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 n=this.vPositionBuffer,r=this.sImageLocation;this.factor===e.Wind?(this.useVectorProgram([-25,26],[0,255/8]),r=this.vImageLocation):this.factor===e.SeaCurrents?(this.useVectorProgram([-2.5,255*.02-2.5],[0,2.55]),r=this.vImageLocation):this.useScalarProgram(),this.drawSquare(n,r),t.bindTexture(t.TEXTURE_2D,null)},n.prototype.drawSquare=function(t,e){var n=this.gl;n.bindBuffer(n.ARRAY_BUFFER,t),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,this.tileChunks[0].texture),n.uniform1i(e,0);var r=this.pixelXYArray,o=r[0],i=r[1],a=r[2],s=r[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(n,l,u,c,d),n.drawArrays(n.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,n=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,n);var r=e.getAttribLocation(t,"a_position");return e.enableVertexAttribArray(r),e.vertexAttribPointer(r,2,e.FLOAT,!1,0,0),n},n.prototype.bufferInitTextureCoord=function(t){var e=this.gl,n=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,n),e.bufferData(e.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),e.STATIC_DRAW);var r=e.getAttribLocation(t,"a_texCoord");e.enableVertexAttribArray(r),e.vertexAttribPointer(r,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 n=this.gl;n.useProgram(this.vectorProgram),n.bindBuffer(n.ARRAY_BUFFER,this.vPositionBuffer),n.uniform2f(this.vResolutionLocation,n.canvas.width,n.canvas.height),n.uniform1i(this.vImageLocation,0),n.activeTexture(n.TEXTURE1),n.bindTexture(n.TEXTURE_2D,this.mapColors.texture),n.uniform1i(this.vColorMapLocation,1),n.uniform2f(this.vRangeUVLocation,t[0],t[1]),n.uniform2f(this.vRangeSLocation,e[0],e[1])},n.prototype.setSquareWest=function(t,e,n,r,o){var i=e-(r+1)/2,a=e+(r+1)/2,s=n,l=n+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,n,r,o){var i=e+(r+1)/2,a=e+r+(r+1)/2,s=n,l=n+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,n,r){this.setSquareBase(t,e,n,r,r)},n.prototype.setSquareBase=function(t,e,n,r,o){var i=e,a=e+r,s=n,l=n+o;t.bufferData(t.ARRAY_BUFFER,new Float32Array([i,s,a,s,i,l,i,l,a,s,a,l]),t.STATIC_DRAW)},n}(kt),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 n=this.tileArray;f(this.url,(function(t){n[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,n){return this.decodeTextByWorldPixel(e.southWestX+t[0],e.northEastY+t[1],n)},t.prototype.decodeByViewPixel=function(t,e,n){return this.decodeByWorldPixel(e.southWestX+t[0],e.northEastY+t[1],n)},t.prototype.decodeTextByWorldPixel=function(t,e,n){return parseFloat(this.decodeByWorldPixel(t,e,n).value.toFixed(1))+H(this.factor)},t.prototype.decodeByWorldPixel=function(t,e,n){var r=this.tileArray[0];if(!r.isDecoded){if(!r.image)return null;r.canvas=$(r.image,r.decodeArr,this.factor),r.isDecoded=!0}var o=L(this.x,this.y,this.w,this.h,this.z,n),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 r.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 n=0,r=0,o=0;o<t.length;o++){var i=Math.pow(e[o],2);n+=t[o].value/i,r+=1/i}return{r:0,g:0,value:n/r}},t}(),Mt={},Bt=function(t){function n(){var n=t.call(this)||this;return n.renderer=new Lt,n.source=null,n.setColorConfig(e.Temp,Ct.temp),n.setColorConfig(e.Pressure,Ct.pressure),n.setColorConfig(e.Humidity,Ct.humidity),n.setColorConfig(e.Visibility,Ct.visibility),n.setColorConfig(e.Rain,Ct.rain),n.setColorConfig(e.Wind,Ct.wind),n.setColorConfig(e.Waves,Ct.waves),n.setColorConfig(e.WaterTemp,Ct.waterTemp),n.setColorConfig(e.SeaCurrents,Ct.seacurrent),n.setColorConfig(e.WindGust,Ct.windGust),n.setColorConfig(e.SolarRadiation,Ct.solarRadiation),n.setColorConfig(e.CloudSurface,Ct.cloudSurface),n.setColorConfig(e.SnowDepth,Ct.snowDepth),n}return r(n,t),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(n,r){e.renderer.setQueue(n,r,t.factor,Mt[t.factor])})),this.source.load(t.onerror)},n.prototype.setColorConfig=function(t,e){return Mt[t]=e,this},n.prototype.setDecodeConfig=function(t,e,n,r,o){return r?et(t,r,o):J(t,e,n),this},n.prototype.renderExtent=function(t,e,n,r){return this.renderer.setView(t,e,n,r),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,n){return this.source.decodeTextByViewPixel(t,e,n)},n}(o),Ft=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}(ct),St=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e}(Ft),Dt=function(){},Ut=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype.createProgram=function(t){this.screenProgram=ht(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}"),this.drawParticleProgram=ht(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"),this.updateParticleProgram=ht(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