@metoceanapi/wxtiles-leaflet 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/es/wxtiles.js +1 -1
- package/dist/web/wxtiles.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/es/wxtiles.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var ve=Object.create;var _=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols,Me=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty,ke=Object.prototype.propertyIsEnumerable;var J=(r,e,t)=>e in r?_(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Y=(r,e)=>{for(var t in e||(e={}))$.call(e,t)&&J(r,t,e[t]);if(X)for(var t of X(e))ke.call(e,t)&&J(r,t,e[t]);return r};var Ae=r=>_(r,"__esModule",{value:!0});var Je=typeof require!="undefined"?require:r=>{throw new Error('Dynamic require of "'+r+'" is not supported')};var Ie=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var _e=(r,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of De(e))!$.call(r,n)&&n!=="default"&&_(r,n,{get:()=>e[n],enumerable:!(t=Le(e,n))||t.enumerable});return r},ee=r=>_e(Ae(_(r!=null?ve(Me(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var N=Ie((rt,te)=>{te.exports=window.L});var E=ee(N());var re={comment1:["'degC': ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["'hPa': ['Pa', 1000]' -> hPa = Pa * 1000 + 0 (0 - could be ommited)",0],K:["K",1],kelvin:["K",1],F:["K",.5555555555,255.372222222],C:["K",1,273.15],degC:["K",1,273.15],"kg/m^2/s":["kg/m^2/s",1],"Kg/m^2/s":["kg/m^2/s",1],"Kg m**-2 s**-1":["kg/m^2/s",1],"Kg m^-2 s^-1":["kg/m^2/s",1],"Kg m^{-2} s^-1":["kg/m^2/s",1],"mm/h":["kg/m^2/s",.00027777777],"mm/hr":["kg/m^2/s",.00027777777],"W/m^2":["W/m^2",1],"W m^-2":["W/m^2",1],"W m^{-2}":["W/m^2",1],"W/m**2":["W/m^2",1],"W m**-2":["W/m^2",1],"m/s":["m/s",1],"m s**-1":["m/s",1],"m s^-1":["m/s",1],"m.s^{-1}":["m/s",1],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["m/s",.27777777777],"km h^-1":["m/s",.27777777777],"km h**-1":["m/s",.27777777777],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],inch:["m",.0254],Pa:["Pa",1],hPa:["Pa",100],degree:["degree",1],radian:["degree",57.3],"mg/m^3":["mg/m^3",1],"mg m^-3":["mg/m^3",1],"mg.m^-3":["mg/m^3",1],"%":["%",1],"(0 - 1)":["%",100]};var ne={none:["#00000000","#00000000"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbowzerro:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow2:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebirdzerro:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bw:["#000000ff","#ffffffff"],wb:["#ffffffff","#000000ff"],redish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]};var P={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"}};var B,se,oe;function Pe({colorStyles:r={},units:e={},colorSchemes:t={}}={}){x("WxTile lib setup: start"),B=Object.assign({},re,e),se=Object.assign({},t,ne);let n=Object.assign({},r,P);oe=Ue(n),x("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),x("WxTile lib setup is done.")}function Z(){return oe}function j(){return se}function U(r,e,t){let n=t?Object.assign({},B,t):B;if(!n||!r||!e||r===e||!n[r]||!n[e]||n[r][0]!==n[e][0]){x(r===e?"Trivial converter:":"Inconvertible units. Default converter is used:",r," -> ",e);let i=l=>l;return i.trivial=!0,i}x("Converter: From:",r," To:",e);let s=n[r][1]/n[e][1],o=(n[r][2]||0)/n[e][1]-(n[e][2]||0)/n[e][1];return o?i=>s*i+o:i=>s*i}function Ue(r){let e=Object.assign({},P);for(let s in r){let o=r[s];if(Array.isArray(o))for(let i=0;i<o.length;++i)e[s+"["+i+"]"]=Object.assign({},o[i]);else e[s]=Object.assign({},o)}let t=(s,o)=>{if(o==="base")return P.base;let i=s[o];(!i.parent||!(i.parent in s))&&(i.parent="base");let l=t(s,i.parent);return Object.assign(i,Object.assign({},l,i,{parent:"base"}))},n={};for(let s in e)n[s]=t(e,s);return n}function ie(r){let e=new Map;return t=>{let n=e.get(t);if(n===void 0){let s=r(t);return s instanceof Promise?s.then(()=>e.set(t,s)).catch(o=>{o instanceof DOMException||e.set(t,s)}):e.set(t,s),s}return n}}async function Re(r,e){let t=new Image;return t.src=URL.createObjectURL(await(await fetch(r,e.controller)).blob()),await t.decode(),URL.revokeObjectURL(t.src),t}function We(r){let{width:e,height:t}=r,n=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d");if(!n)throw"catastrophe";return n.drawImage(r,0,0),n.getImageData(0,0,e,t)}async function ae(r,e){return We(await Re(r,e))}function Fe(r,e){let t=n=>{let s=new Uint16Array(n.data.buffer),o=new Uint16Array(s.length/2);for(let a=0;a<o.length;a++)o[a]=s[a*2];let i=new Uint8Array(n.data.buffer);for(let a=0;a<8;++a)i[a]=i[a*4+2];let l=new DataView(n.data.buffer),u=l.getFloat32(0,!0),f=l.getFloat32(4,!0),b=(f-u)/65535,c=Ee(o);return{raw:o,dmin:u,dmax:f,dmul:b,integral:c,radius:0}};return ae(r,e).then(t)}function z(){let r={controller:new AbortController},e=ie(t=>Fe(t,r));return e.controllerHolder=r,e}function le(r){let e={controller:r},t=ie(n=>ae(n,e));return t.controllerHolder=e,t}function Ee(r){let e=new Uint32Array(258*258),t=new Uint32Array(258*258);e[0]=r[0],t[0]=r[0]===0?0:1;for(let n=1;n<258;++n)e[n]=r[n]+e[n-1],e[258*n]=r[258*n]+e[258*n-258],t[n]=(r[n]===0?0:1)+t[n-1],t[258*n]=(r[258*n]===0?0:1)+t[258*n-258];for(let n=1,s=259;n<258;++n,++s)for(let o=1;o<258;++o,++s)e[s]=r[s]+e[s-258]+e[s-1]-e[s-258-1],t[s]=(r[s]===0?0:1)+t[s-258]+t[s-1]-t[s-258-1];return{integral:e,integralNZ:t}}function ce(r,e){if(e<0||e===r.radius)return r;r.radius=e;let t=258,{integral:n,integralNZ:s}=r.integral;for(let o=1;o<t;o++)for(let i=1;i<t;i++){if(!r.raw[t*o+i])continue;let l=Math.min(e,i-1,t-1-i),u=Math.min(e,o-1,t-1-o),f=t*(o-u-1)+i,b=t*(o+u)+i,c=s[f-l-1],a=s[f+l],d=s[b-l-1],h=s[b+l],m=c+h-a-d,p=n[f-l-1],g=n[f+l],y=n[b-l-1],S=n[b+l],C=p+S-g-y;r.raw[o*t+i]=C/m}return r}function w(r){let e=r>>0&255,t=r>>8&255,n=r>>16&255,s=e.toString(16),o=t.toString(16),i=n.toString(16);return s=s.length===2?s:"0"+s,o=o.length===2?o:"0"+o,i=i.length===2?i:"0"+i,"#"+s+o+i}function T(r){if(r[0]==="#"){if(r.length===4)return+("0xff"+r[3]+r[3]+r[2]+r[2]+r[1]+r[1]);if(r.length===7)return+("0xff"+r[5]+r[6]+r[3]+r[4]+r[1]+r[2]);if(r.length===9)return+("0x"+r[7]+r[8]+r[5]+r[6]+r[3]+r[4]+r[1]+r[2])}return x("wrong color format",r),0}async function k(r,e){return(await fetch(r,e)).json()}function L(r,e="",t){var s;let n=document.createElement(r);return n.className=e,t&&((s=t.appendChild)==null||s.call(t,n)),n}function O(r,e,t){let n=r>>0&255,s=r>>8&255,o=r>>16&255,i=r>>>24,l=e>>0&255,u=e>>8&255,f=e>>16&255,b=e>>>24,c=n+t*(l-n),a=s+t*(u-s),d=o+t*(f-o),h=i+t*(b-i);return c|a<<8|d<<16|h<<24}function me(r,e,t){let n=[];for(let s=0;s<t;++s)n.push(s*(e-r)/(t-1)+r);return n}function ue(r,e){let t=typeof e=="number"?e:typeof e=="string"?new Date(e).getTime():e.getTime();return r.find(n=>new Date(n).getTime()>=t)||r[r.length-1]}var fe=!1;function He(r){console.log(r?"Logging on":"Logging off"),fe=r}function x(...r){fe&&console.trace(...r)}var Se=ee(N());function Ne(r,e,t){return r>t?t:r<e?e:r}var R=class{constructor(e,t,[n,s],o){let i=s-n;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let l=[];this.DataToStyle=U(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),o&&(this.DataToKnots=U(t,"knot"));let u=U(e.units,t,e.extraUnits),f=m=>~~(65535*Ne((u(m)-n)/(s-n),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((m,p)=>m[0]<p[0]?-1:m[0]>p[0]?1:0);for(let[m]of e.colorMap)l.push(f(m))}else{if(e.levels||(e.levels=me(this.DataToStyle(n),this.DataToStyle(s),10)),e.levels.sort((m,p)=>m<p?-1:m>p?1:0),!e.colors){let m=j();e.colorScheme&&e.colorScheme in m?e.colors=m[e.colorScheme]:e.colors=m.wb}for(let m of e.levels)l.push(f(m))}let b=65536,c=G(b,e);this.ticks=c.ticks;let a=c.ticks[0].data,h=c.ticks[c.ticks.length-1].data-a;for(let m=0;m<65536;++m){let p=i*m/65535+n,g=this.DataToStyle(p),y=Math.round((b-1)*(g-a)/h);y<=0?this.colorsI[m]=e.showBelowMin?c.colors[0]:0:y>=b?this.colorsI[m]=e.showAboveMax?c.colors[b-1]:0:this.colorsI[m]=c.colors[y]}this.colorsI[0]=0;for(let m=0;m<l[0];++m)this.levelIndex[m]=0;for(let m=0;m<l.length-1;m++)for(let p=l[m];p<l[m+1]+1;++p)this.levelIndex[p]=m;for(let m=l[l.length-1];m<65536;++m)this.levelIndex[m]=l.length-1}};function de(r){var t;if(r!==0&&-.1<r&&r<.1)return r.toExponential(2);let e=r.toString();return((t=e.split(".")[1])==null?void 0:t.length)>2?r.toFixed(2):e}function G(r,e){let t={size:r,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(r),ticks:[]},{colorMap:n,levels:s,colors:o}=e,i=e.fill!=="solid";if(n){let a=n[0][0],d=n[n.length-1][0]-a;for(let[h,m]of n){let p=~~((h-a)/d*(r-1)),g={data:h,dataString:de(h),color:m,pos:p};t.ticks.push(g)}for(let h=0;h<n.length-1;h++){let m=t.ticks[h].pos,p=t.ticks[h+1].pos,g=T(n[h][1]),y=i?T(n[h+1][1]):0;for(let S=m;S<p;++S)t.colors[S]=i?O(g,y,(S-m)/(p-m)):g}return t.colors[r-1]=T(n[n.length-1][1]),t}if(!o||!s)return t;let l=0,u=0,f=-1;for(let a=0;a<r;++a){let d=a*(o.length-1)/r;f!==~~d&&(f=~~d,l=T(o[f]),u=o.length>f+1?T(o[f+1]):l),t.colors[a]=i?O(l,u,d-f):l}t.colors[r-1]=T(o[o.length-1]);let b=s[0],c=(r-1)/(s[s.length-1]-b);for(let a of s){let d=~~((a-b)*c),h={data:a,dataString:de(a),color:w(t.colors[d]),pos:d};t.ticks.push(h)}return t}var Q=256,Be=2*Math.PI*6378137/Q,W=2*Math.PI*6378137/2;function Ze(r,e){let t=r/W*180,n=e/W*180;return n=180/Math.PI*(2*Math.atan(Math.exp(n*Math.PI/180))-Math.PI/2),[n,t]}function je(r,e,t){let n=ze(t),s=r*n-W,o=e*n-W;return[s,o]}function ze(r){return Be/Math.pow(2,r)}function q(r,e,t){let[n,s]=Ze(...je(r,e,t));return[s,-n]}function he(r,e){return[r*Q,e*Q]}var Oe="A".charCodeAt(0),K,D=0;async function Ge(r,e){let t;try{t=await(await fetch(r,e)).json()}catch(n){console.log("Can't load QTree:",n);return}K=A(t,{pos:0}),D=be(K),console.log("Loaded QTree, depth:",D)}function A(r,e){let t=r.charCodeAt(e.pos)-Oe;e.pos++;let n=t&1?A(r,e):null,s=t&2?A(r,e):null,o=t&4?A(r,e):null,i=t&8?A(r,e):null;return{sub:n||s||o||i?[n,s,o,i]:null}}function be(r){let e=0;if(r==null?void 0:r.sub){for(let t=0;t<4;t++)if(r.sub[t]!==null){let n=be(r.sub[t])+1;e<n&&(e=n)}}return e}var v;(function(n){n.Land="land",n.Mixed="mixed",n.Sea="sea"})(v||(v={}));function ge(r){if(!D)return v.Mixed;let e=Y({},r),t=!1;if(D<=r.z){t=!0;let n=r.z-D;e={x:r.x>>n,y:r.y>>n,z:D}}return xe(K,e,t)}function xe(r,e,t){if(r===null)return v.Land;if(t&&e.z===0)return v.Mixed;if(r.sub===null)return v.Sea;if(e.z===0)return v.Mixed;e.z--;let n=e.x>>e.z&1,o=(e.y>>e.z&1)<<1|n;return xe(r.sub[o],e,t)}function Qe(r,e){if(!e)return r;let t=.9999999/Math.pow(2,e.z),n=e.x*256*t,s=e.y*256*t,o={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:i}=o;for(let l=-1,u=0;l<=256;l++){let f=s+l*t,b=Math.floor(f),c=f-b;for(let a=-1;a<=256;a++,u++){let d=n+a*t,h=Math.floor(d),m=d-h,p=h+1+(b+1)*258,g=r.raw[p],y=r.raw[p+1],S=r.raw[p+258],C=r.raw[p+258+1];switch((g?1:0)|(y?2:0)|(S?4:0)|(C?8:0)){case 0:i[u]=0;continue;case 1:i[u]=g;continue;case 2:i[u]=y;continue;case 3:S=g,C=y;break;case 4:i[u]=S;continue;case 5:y=g,C=S;break;case 6:C=y+S>>1,g=C;break;case 7:C=y+S>>1;break;case 8:i[u]=C;continue;case 9:y=g+C>>1,S=y;break;case 10:g=y,S=C;break;case 11:S=g+C>>1;break;case 12:g=S,y=C;break;case 13:y=g+C>>1;break;case 14:g=y+S>>1;break}g=r.dmin+r.dmul*g,y=r.dmin+r.dmul*y,S=r.dmin+r.dmul*S,C=r.dmin+r.dmul*C;let I=V(g,y,m),M=V(S,C,m);i[u]=(V(I,M,c)-r.dmin)/r.dmul,i[u]===0&&(i[u]=1)}}return o}function V(r,e,t){let n=((e-r)%360+540)%360-180;return(r+n*t+360)%360}function qe(r,e){if(!e)return r;let t=.9999999/Math.pow(2,e.z),n=e.x*256*t,s=e.y*256*t,o={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:i}=o;for(let l=-1,u=0;l<=256;l++){let f=s+l*t,b=Math.floor(f),c=f-b;for(let a=-1;a<=256;a++,u++){let d=n+a*t,h=Math.floor(d),m=d-h,p=h+1+(b+1)*258,g=r.raw[p],y=r.raw[p+1],S=r.raw[p+258],C=r.raw[p+258+1];switch((g?1:0)|(y?2:0)|(S?4:0)|(C?8:0)){case 7:i[u]=m+c<1?m*(y-g)+c*(S-g)+g:0;continue;case 14:i[u]=m+c<1?0:m*(C-S)+c*(C-y)+y+S-C;continue;case 11:i[u]=c<m?(1-m)*(g-y)+c*(C-y)+y:0;continue;case 13:i[u]=c<m?0:(1-m)*(S-C)+c*(S-g)+g+C-S;continue;case 15:i[u]=m+c<1?m*(y-g)+c*(S-g)+g:m*(C-S)+c*(C-y)+y+S-C;continue;default:i[u]=0}}}return o}function Ke(r,e,t){let n=t==="land"?1:0;for(let s=3,o=0;o<256;o++)for(let i=0;i<256;i++,s+=4){let l=e.data[s]?1:0;n^l&&(r.raw[(o+1)*258+(i+1)]=0)}return r}function Ve(r){let[e,t]=he(r.x,r.y),[n,s]=q(e,t,r.z),[o,i]=q(e+256,t+256,r.z);return{west:n,north:s,east:o,south:i}}function ye({layer:r,coords:e,done:t}){let n=L("div","leaflet-tile s-tile");return n.wxtile=new pe({layer:r,coords:e,tileEl:n}),n.wxtile.load().then(s=>{s.draw(),t()}),n}var pe=class{constructor({layer:e,coords:t,tileEl:n}){this.data=[];this.sLines=[];this.coords=t,this.layer=e,this.canvasFill=L("canvas","s-tile canvas-fill",n),this.canvasSlines=L("canvas","s-tile canvas-slines",n),this.canvasVector=this.canvasFill,this.canvasFill.width=this.canvasFill.height=this.canvasSlines.width=this.canvasSlines.height=256;function s(o){let i=o.getContext("2d");if(!i)throw"error";return i}this.canvasFillCtx=s(this.canvasFill),this.imData=this.canvasFillCtx.createImageData(256,256),this.canvasSlinesCtx=s(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasSlinesCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVector(),this._drawDegree(),this._drawStaticSlines())}clearSLinesCanvas(){this.canvasSlinesCtx.clearRect(0,0,256,256)}drawSLines(e){if(this.sLines.length===0)return;let t=this.canvasSlinesCtx;if(t.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.sLines=[];return}let n=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let s=0;s<this.sLines.length;++s){let o=this.sLines[s],i=o.length-1,l=(e+(1+o[0].x)*(1+o[0].y))%30;for(let u=0;u<i;++u){let f=o[u],b=o[u+1],c=1-(l-u)/i;(c<0||c>1)&&(c=0);let a=(~~(c*255)).toString(16);t.strokeStyle=n+(a.length<2?"0"+a:a);let d=1+~~((1.2-c)*5);t.lineWidth=d,t.beginPath(),t.moveTo(f.x,f.y),t.lineTo(b.x,b.y),t.stroke()}}}getData({x:e,y:t}){if(!this.data.length)return;let n=this.data[0].raw[(t+1)*258+(e+1)];return{raw:n,data:this.data[0].dmin+this.data[0].dmul*n}}async load(){var c;let{coords:e,layer:t}=this,{boundaries:n}=t.state.meta,s=this.layer.style.mask;var o;if((s==="land"||s==="sea")&&(o=ge(e),s===o))return this.data=[],this.sLines=[],this;if(n==null?void 0:n.boundaries180){let a=Ve(e),d=h=>!(a.west>h.east||h.west>a.east||a.south>h.north||h.south>a.north);if(!n.boundaries180.some(d))return this.data=[],this.sLines=[],this}let{upCoords:i,subCoords:l}=this._splitCoords(e),u=this._coordsToURLs(i),f;try{f=await Promise.all(u.map(t.loadData))}catch(a){return this}let b=((c=t.state)==null?void 0:c.units)==="degree"?Qe:qe;if(this.data=f.map(a=>b(ce(a,this.layer.style.blurRadius),l)),this.layer.vector&&this._vectorPrepare(),s&&o===v.Mixed){let a=t.state.maskServerURI.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));try{let d=await t.loadMask(a);Ke(this.data[0],d,s)}catch(d){this.layer.style.mask=void 0,x("Can't load Mask. Turned off")}}return this.layer.vector&&this._createSLines(),this}_splitCoords(e){let t=e.z-this.layer.state.meta.maxZoom;if(t<=0)return{upCoords:e};let n={x:e.x>>>t,y:e.y>>>t,z:this.layer.state.meta.maxZoom},s={x:e.x&(1<<t)-1,y:e.y&(1<<t)-1,z:t};return{upCoords:n,subCoords:s}}_coordsToURLs(e){let t=this.layer.state.baseURL.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));return this.layer.dataSource.variables.map(n=>t.replace("{var}",n))}_vectorPrepare(){if(this.data.length!==2)throw"this.data !== 2";this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[e,t,n]=this.data;e.dmax=1.42*Math.max(-t.dmin,t.dmax,-n.dmin,n.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let s=0;s<258*258;++s){if(!t.raw[s]||!n.raw[s]){e.raw[s]=0;continue}let o=t.dmin+t.dmul*t.raw[s],i=n.dmin+n.dmul*n.raw[s];e.raw[s]=Math.sqrt(i*i+o*o)/e.dmul}}_drawFillAndIsolines(){let{imData:e}=this,{canvasFillCtx:t}=this,n=new Uint32Array(e.data.buffer),{raw:s}=this.data[0],{clut:o,style:i}=this.layer,{levelIndex:l,colorsI:u}=o;if(i.fill!=="none"){let b=u;for(let c=0,a=0,d=259;c<256;++c,d+=2)for(let h=0;h<256;++h,++a,++d)n[a]=b[s[d]]}else n.fill(0);let f=[];if(i.isolineColor!=="none"){let b=i.isolineColor[0]==="#"?T(i.isolineColor):0;for(let c=0,a=0;c<256;c+=1)for(let d=0;d<256;d+=1){let h=(c+1)*258+(d+1),m=s[h],p=s[h+1],g=s[h+258];if(!m||!p||!g)continue;let y=l[m],S=l[p],C=l[g];if(y!==S||y!==C){let H=Math.max(y,S,C),I=Math.max(m,p,g),M=c*256+d;switch(i.isolineColor){case"inverted":n[M]=~u[I]|4278190080;break;case"fill":n[M]=u[I]|4278190080;break;default:n[M]=b;break}i.isolineText&&!(++a%255)&&d>20&&d<235&&c>20&&c<235&&f.push({x:d,y:c,d:m,dr:p,db:g,mli:H})}}}if(t.putImageData(e,0,0),!f.length){t.font="1.1em Sans-serif",t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";for(let{x:b,y:c,d:a,dr:d,db:h,mli:m}of f){let p=this.layer.clut.ticks[m].dataString,g=Math.atan2(a-d,h-a);t.save(),t.translate(b,c),t.rotate(g<-1.57||g>1.57?g+3.14:g),t.strokeText(p,0,0),t.fillText(p,0,0),t.restore()}}}_drawStaticSlines(){if(!this.sLines.length||!this.layer.style.streamLineStatic)return;let{canvasSlinesCtx:e}=this;if(this.layer.style.streamLineColor==="none"){this.sLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let t=this.sLines.length;t--;){let n=this.sLines[t];for(let s=0;s<n.length-1;++s){let o=n[s],i=n[s+1];e.moveTo(o.x,o.y),e.lineTo(i.x,i.y)}}e.stroke()}_drawVector(){if(!this.layer.vector||!this.layer.clut.DataToKnots||!this.layer.style.vectorColor||this.layer.style.vectorColor==="none"||!this.layer.style.vectorType||this.layer.style.vectorType==="none")return;if(this.data.length!==3)throw"this.data.length !== 3";let[e,t,n]=this.data,{canvasVectorCtx:s}=this;switch(this.layer.style.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=this.layer.style.vectorType}s.textAlign="center",s.textBaseline="middle";let o=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0,i=32;for(let l=i/2;l<256;l+=i)for(let u=i/2;u<256;u+=i){let f=u+1+(l+1)*258;if(!e.raw[f])continue;let b=Math.atan2(t.dmin+t.raw[f]*t.dmul,n.dmin+n.raw[f]*n.dmul),c=e.dmin+e.raw[f]*e.dmul,a=this.layer.dataSource.variables[0].includes("current")?5:.2,d=Math.min(this.layer.clut.DataToKnots(c)*a,25)+65,h=String.fromCharCode(d);switch(this.layer.style.vectorColor){case"inverted":s.fillStyle=w(~this.layer.clut.colorsI[e.raw[f]]);break;case"fill":s.fillStyle=w(this.layer.clut.colorsI[e.raw[f]]);break;default:s.fillStyle=this.layer.style.vectorColor;break}s.save(),s.translate(u,l),s.rotate(b+o),s.fillText(h,0,0),s.restore()}}_drawDegree(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:e}=this,t=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle";let n=this.data[0],s="L",o=32;for(let i=o/2;i<256;i+=o)for(let l=o/2;l<256;l+=o){let u=l+1+(i+1)*258;if(!n.raw[u])continue;let b=(n.dmin+n.raw[u]*n.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=w(~this.layer.clut.colorsI[n.raw[u]]);break;case"fill":e.fillStyle=w(this.layer.clut.colorsI[n.raw[u]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(l,i),e.rotate(b+t),e.fillText(s,0,0),e.restore()}}_createSLines(){if(this.data.length!==3)throw"this.data.length !== 3";if(!this.layer.style.streamLineColor||this.layer.style.streamLineColor==="none")return;let e=this.layer.style.streamLineSpeedFactor||1;this.sLines=[];let[t,n,s]=this.data,o=Math.max(this.coords.z-this.layer.state.meta.maxZoom,0),i=Math.min(2**(o+5),128),l=~~(120+o*60);for(let u=0;u<=256;u+=i)for(let f=0;f<=256;f+=i){if(!t.raw[1+f+(1+u)*258])continue;let b=[],c=f,a=u;for(let d=0;d<=l&&c>=0&&c<=256&&a>=0&&a<=256;d++){!(d%(l/6))&&b.push({x:~~c,y:~~a});let h=~~c+1+(~~a+1)*258;if(!t.raw[h])break;c+=e*(n.dmin+n.raw[h]*n.dmul)/t.dmax,a-=e*(s.dmin+s.raw[h]*s.dmul)/t.dmax}c=f,a=u;for(let d=1;d<=l&&c>=0&&c<=256&&a>=0&&a<=256;d++){!(d%(l/6))&&b.unshift({x:~~c,y:~~a});let h=~~c+1+(~~a+1)*258;if(!t.raw[h])break;c-=e*(n.dmin+n.raw[h]*n.dmul)/t.dmax,a+=e*(s.dmin+s.raw[h]*s.dmul)/t.dmax}b.length>2&&this.sLines.push(b)}}};var Ce="setup not complete",Xe=le(new AbortController),F=class extends Se.default.GridLayer{constructor({dataSource:e,options:t,lazy:n}){super(t);this.styles=Z();this.style=Object.assign({},this.styles.base);this.loadData=z();this.loadMask=Xe;this.error=Ce;this.vector=!1;this.clut=new R(this.style,"",[0,2],!1);this.animation=!1;this.animationRedrawID=0;this.animFrame=0;this.oldMaxZoom=0;if(x("Creating a WxTilex layer:",e.name,". Params:",JSON.stringify({dataSource:e,options:t})),!e||!e.ext||!e.dataset||!e.name||!e.serverURI||!e.styleName||!Array.isArray(e.variables))throw x("dataSource is wrong!"),"dataSource is wrong!";this.dataSource=e,this.state={maskServerURI:e.maskServerURI||e.serverURI.replace(/\/data\/?/i,"/mask/{z}/{x}/{y}"),units:"undefined",baseURL:"undefined",meta:{maxZoom:0,times:["undefined"],variables:["undefined"],variablesMeta:{}},instance:"undefined",minmax:[[0,1]],originURI:"undefined",time:"undefined"},this.setupCompletePromise=new Promise(s=>{let o=()=>{x("Setup:",e.name),this.on("remove",this._onRemoveLayer,this),this.on("add",this._onAddLayer,this),this._setUpDataSet(e).then(i=>{x("Setup complete:",this.dataSource.name,". Result:",i),this._map&&n&&this._onAddLayer(),this.fire("setupcomplete",{layer:this}),s(i)})};n?this.once("add",o):o()})}createTile(e,t){return this.error&&this.error!==Ce?(setTimeout(t),Object.assign(L("div","error-tile"),{innerHTML:this.error})):this.state.baseURL==="undefined"?(setTimeout(t),L("div","error-tile")):ye({layer:this,coords:e,done:t})}getSetupCompletePromise(){return this.setupCompletePromise}getTile(e){if(!this._map||this.error)return;let t=this._map.getZoom(),{x:n,y:s}=this._map.project(e,t),o={x:~~(n/256),y:~~(s/256)},i=this._getCachedTile(o.x,o.y,t);if(!i)return;let l={x:~~(n-o.x*256),y:~~(s-o.y*256)},u=i.getData(l);if(!u)return;let{raw:f,data:b}=u,c=this.clut.colorsI[f],a=w(c),d=this.clut.DataToStyle(b);return{tile:i,data:b,raw:f,rgba:c,hexColor:a,inStyleUnits:d,tilePoint:l,units:this.style.units}}setStyle(e){if(x("setStyle(",e,") for ",this.dataSource.name),this.error){x("setStyle: failed: "+this.error);return}if(!(this.dataSource.styleName===e&&e!=="custom")){if(e&&(this.dataSource.styleName=e),e==="custom"&&this.styles.custom){(!this.styles.custom.parent||!(this.styles.custom.parent in this.styles))&&(this.styles.custom.parent="base");let t=this.styles[this.styles.custom.parent];this.styles.custom=Object.assign(Object.assign({},t),this.styles.custom)}this.dataSource.styleName in this.styles?Array.isArray(this.styles[this.dataSource.styleName])&&(this.dataSource.styleName+="[0]"):(x(`cant find the style (${this.dataSource.styleName})`),this.dataSource.styleName+="[0]",this.dataSource.styleName in this.styles||(x(`cant find the style (${this.dataSource.styleName}), default is used`),this.dataSource.styleName="base"));try{let t=this.styles[this.dataSource.styleName];this.style=Object.assign({},t);let n=this.style.streamLineColor;n!=="none"&&n.length<7&&(this.style.streamLineColor="#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]);let s=this.state.minmax[0];this.clut=new R(this.style,this.state.units,s,this.vector)}catch(t){let n="setStyle: impossible error in RawCLUT: "+t;throw x(n),n}e&&(this._checkAndStartSlinesAnimation(),this._reloadTiles()),x("setStyle(",e,'): "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete."),this.fire("setstyle",{layer:this})}}getStyle(){return this.dataSource.styleName}getStyleName(){return this.style.name}setTime(e){if(x("setTime: "+e+" for "+this.dataSource.name+" start"),this.error)return x("setTime: failed: "+this.error),Promise.resolve([]);let t=ue(this.state.meta.times,e);if(this.state.time===t)return x("setTime: the same time - skipped"),Promise.resolve([]);if(this.state.time=t,this.state.baseURL=this.state.originURI+this.state.instance+`{var}/${this.state.time}/{z}/{x}/{y}.${this.dataSource.ext}`,this.fire("settime",{layer:this,layerTime:t}),x("setTime: "+t+" for "+this.dataSource.name+" complete"),!this._tiles)return Promise.resolve([]);let n=this._reloadTiles(!1);return n.then(()=>{var o;let s=Object.values(this._tiles);for(let i of s){let l=(o=i.el)==null?void 0:o.wxtile;if(l==null?void 0:l.data.length){let[u,f]=this.state.minmax[0],{dmin:b,dmax:c}=l.data[0];(Math.abs(b-u)>.01||Math.abs(c-f)>.01)&&(this.state.minmax=l.data.map(a=>[a.dmin,a.dmax]),this.setStyle(void 0));break}}this._redrawTiles()}),n}getTime(){return this.error?(x("getTime: failed: "+this.error),this.error):this.state.time}getTimes(){return x("getTimes"),this.error?(x("getTimes: failed: "+this.error),[]):this.state.meta.times}async checkDataChanged(){if(x("checkDataChanged"),this.error)return x("checkDataChanged: failed: "+this.error),!1;let e=await k(this.state.originURI+"instances.json"),t=e[e.length-1]+"/";if(this.state.instance!==t)return!0;let n=await k(this.state.originURI+t+"meta.json");return this.state.meta.times.toString()!==n.times.toString()}reloadData(){return x("reloadData"),this._setUpDataSet(void 0)}getLegendData(e){return x("getLegendData"),(this.error||!this.clut)&&x("getLegendData: failed. "+this.dataSource.name+" : "+this.error),G(e,this.style)}setTimeAnimationMode(e=2){x("setTimeAnimationMode"),this.oldMaxZoom=this.state.meta.maxZoom;let t=this._map.getZoom(),s=(t<this.oldMaxZoom?t:this.oldMaxZoom)-e;this.state.meta.maxZoom=s<0?0:s}unsetTimeAnimationMode(){return x("unsetTimeAnimationMode"),this.oldMaxZoom&&(this.state.meta.maxZoom=this.oldMaxZoom),this._reloadTiles()}getMinMax(){let[e,t]=this.state.minmax[0];return{min:e,max:t}}setAnimation(e){return x("setAnimation"),this.animation=e,this._checkAndStartSlinesAnimation(),this.animation}_getCachedTile(e,t,n){var s,o;return(o=(s=this._tiles[`${e}:${t}:${n}`])==null?void 0:s.el)==null?void 0:o.wxtile}_ForEachTile(e){var n;let t=[];for(let s in this._tiles){let o=(n=this._tiles[s].el)==null?void 0:n.wxtile,i=o&&e(o);i&&t.push(i)}return t}async _setUpDataSet(e){e&&(this.dataSource=e),this._stopLoadingResetLoadDataFunc(),this.state.originURI=this.dataSource.serverURI+"/"+this.dataSource.dataset+"/";try{let t=await k(this.state.originURI+"instances.json");this.state.instance=t[t.length-1]+"/"}catch(t){return this.error=this.dataSource.name+": load instances.json error: "+t,x(this.error),!1}try{let t=this.state.originURI+this.state.instance+"meta.json";this.state.meta=await k(t)}catch(t){return this.error=this.dataSource.name+": load meta.json error: "+t,x(this.error),!1}if(this.vector=this.dataSource.variables.length===2,this.animation=this.vector,this.state.units=this.state.meta.variablesMeta[this.dataSource.variables[0]].units,this.state.minmax=this.dataSource.variables.map(t=>[this.state.meta.variablesMeta[t].min,this.state.meta.variablesMeta[t].max]),this.vector){let[[t,n],[s,o]]=this.state.minmax;this.state.minmax.unshift([0,1.42*Math.max(-t,n,-s,o)])}return this.error=null,e&&(this.setStyle(void 0),await this.setTime(new Date)),!0}_checkZoom(){var e;((e=this._map)==null?void 0:e.getZoom())>this.state.meta.maxZoom||this._stopLoadingResetLoadDataFunc()}_onAddLayer(){var e;x("onadd:",this.dataSource.name),(e=this._map)==null||e.on("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this.redraw(),this._checkAndStartSlinesAnimation()})}_onRemoveLayer(){var e;x("onremove:",this.dataSource.name),(e=this._map)==null||e.off("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this._stopLoadingResetLoadDataFunc(),this._stopSlinesAnimation()})}_stopLoadingResetLoadDataFunc(){this.loadData.controllerHolder.controller.abort(),this.loadData=z()}_checkAndStartSlinesAnimation(){if(this.animFrame||!this.animation||!this.vector||!this.style.streamLineColor||this.style.streamLineColor==="none")return;let e=t=>{if(!this.animation||this.style.streamLineStatic){this._stopSlinesAnimation();return}this._ForEachTile(n=>n.drawSLines(t)),this.animFrame=requestAnimationFrame(e)};e(0)}_stopSlinesAnimation(){cancelAnimationFrame(this.animFrame),this._ForEachTile(e=>e.clearSLinesCanvas()),this.animFrame=0}_redrawTiles(){this.animationRedrawID===0&&(this.animationRedrawID=requestAnimationFrame(()=>{x("_redrawTiles: requestAnimationFrame: "+this.dataSource.name),this._ForEachTile(e=>e.draw()),this.animationRedrawID=0}))}_reloadTiles(e=!0){x("_reloadTiles: start - "+this.dataSource.name),this.loadData.controllerHolder.controller.abort(),this.loadData.controllerHolder.controller=new AbortController;let t=this._ForEachTile(o=>o.load()),n=Promise.all(t),{controller:s}=this.loadData.controllerHolder;return e&&n.then(()=>s.signal.aborted||this._redrawTiles()),x("_reloadTiles: finished - "+this.dataSource.name),n}};function $e(r){return new F(r)}var we=class extends E.default.Control{constructor(e){super(e);this.URI=e.URI}onAdd(){let e=document.createElement("img");return e.src=this.URI,e.className="wxtiles-logo",e}};function Ut(r){return x("Add watermark:",JSON.stringify(r)),new we(r)}var Te=class extends E.default.GridLayer{createTile(e){let t=document.createElement("div");return t.innerHTML=[e.x,e.y,e.z].join(", "),t.style.outline="1px solid red",t}};function Rt(){return x("Add WxDebugCoordsLayer:"),new Te().setZIndex(1e3)}function Wt(r,e){return E.default.layerGroup(r.map($e),e)}export{Rt as CreateWxDebugCoordsLayer,Wt as CreateWxTilesGroupLayer,$e as CreateWxTilesLayer,Ut as CreateWxTilesWatermark,Ge as LoadQTree,Te as WxDebugLayer,j as WxGetColorSchemes,Z as WxGetColorStyles,F as WxTilesLayer,Pe as WxTilesLibSetup,He as WxTilesLogging,we as WxWatermark};
|
|
1
|
+
var ve=Object.create;var _=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols,Me=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty,ke=Object.prototype.propertyIsEnumerable;var J=(r,e,t)=>e in r?_(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Y=(r,e)=>{for(var t in e||(e={}))$.call(e,t)&&J(r,t,e[t]);if(X)for(var t of X(e))ke.call(e,t)&&J(r,t,e[t]);return r};var Ae=r=>_(r,"__esModule",{value:!0});var Je=typeof require!="undefined"?require:r=>{throw new Error('Dynamic require of "'+r+'" is not supported')};var Ie=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var _e=(r,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of De(e))!$.call(r,n)&&n!=="default"&&_(r,n,{get:()=>e[n],enumerable:!(t=Le(e,n))||t.enumerable});return r},ee=r=>_e(Ae(_(r!=null?ve(Me(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var N=Ie((rt,te)=>{te.exports=window.L});var E=ee(N());var re={comment1:["'degC': ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["'hPa': ['Pa', 1000]' -> hPa = Pa * 1000 + 0 (0 - could be ommited)",0],K:["K",1],kelvin:["K",1],F:["K",.5555555555,255.372222222],C:["K",1,273.15],degC:["K",1,273.15],"kg/m^2/s":["kg/m^2/s",1],"Kg/m^2/s":["kg/m^2/s",1],"Kg m**-2 s**-1":["kg/m^2/s",1],"Kg m^-2 s^-1":["kg/m^2/s",1],"Kg m^{-2} s^-1":["kg/m^2/s",1],"mm/h":["kg/m^2/s",.00027777777],"mm/hr":["kg/m^2/s",.00027777777],"W/m^2":["W/m^2",1],"W m^-2":["W/m^2",1],"W m^{-2}":["W/m^2",1],"W/m**2":["W/m^2",1],"W m**-2":["W/m^2",1],"m/s":["m/s",1],"m s**-1":["m/s",1],"m s^-1":["m/s",1],"m.s^{-1}":["m/s",1],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["m/s",.27777777777],"km h^-1":["m/s",.27777777777],"km h**-1":["m/s",.27777777777],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],inch:["m",.0254],Pa:["Pa",1],hPa:["Pa",100],degree:["degree",1],radian:["degree",57.3],"mg/m^3":["mg/m^3",1],"mg m^-3":["mg/m^3",1],"mg.m^-3":["mg/m^3",1],"%":["%",1],"(0 - 1)":["%",100]};var ne={none:["#00000000","#00000000"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbowzerro:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow2:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebirdzerro:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bw:["#000000ff","#ffffffff"],wb:["#ffffffff","#000000ff"],redish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]};var P={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"}};var B,se,oe;function Pe({colorStyles:r={},units:e={},colorSchemes:t={}}={}){x("WxTile lib setup: start"),B=Object.assign({},re,e),se=Object.assign({},t,ne);let n=Object.assign({},r,P);oe=Ue(n),x("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),x("WxTile lib setup is done.")}function Z(){return oe}function j(){return se}function U(r,e,t){let n=t?Object.assign({},B,t):B;if(!n||!r||!e||r===e||!n[r]||!n[e]||n[r][0]!==n[e][0]){x(r===e?"Trivial converter:":"Inconvertible units. Default converter is used:",r," -> ",e);let i=l=>l;return i.trivial=!0,i}x("Converter: From:",r," To:",e);let s=n[r][1]/n[e][1],o=(n[r][2]||0)/n[e][1]-(n[e][2]||0)/n[e][1];return o?i=>s*i+o:i=>s*i}function Ue(r){let e=Object.assign({},P);for(let s in r){let o=r[s];if(Array.isArray(o))for(let i=0;i<o.length;++i)e[s+"["+i+"]"]=Object.assign({},o[i]);else e[s]=Object.assign({},o)}let t=(s,o)=>{if(o==="base")return P.base;let i=s[o];(!i.parent||!(i.parent in s))&&(i.parent="base");let l=t(s,i.parent);return Object.assign(i,Object.assign({},l,i,{parent:"base"}))},n={};for(let s in e)n[s]=t(e,s);return n}function ie(r){let e=new Map;return t=>{let n=e.get(t);if(n===void 0){let s=r(t);return s instanceof Promise?s.then(()=>e.set(t,s)).catch(o=>{o instanceof DOMException||e.set(t,s)}):e.set(t,s),s}return n}}async function Re(r,e){let t=new Image;return t.src=URL.createObjectURL(await(await fetch(r,e.controller)).blob()),await t.decode(),URL.revokeObjectURL(t.src),t}function We(r){let{width:e,height:t}=r,n=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d");if(!n)throw"catastrophe";return n.drawImage(r,0,0),n.getImageData(0,0,e,t)}async function ae(r,e){return We(await Re(r,e))}function Fe(r,e){let t=n=>{let s=new Uint16Array(n.data.buffer),o=new Uint16Array(s.length/2);for(let a=0;a<o.length;a++)o[a]=s[a*2];let i=new Uint8Array(n.data.buffer);for(let a=0;a<8;++a)i[a]=i[a*4+2];let l=new DataView(n.data.buffer),u=l.getFloat32(0,!0),f=l.getFloat32(4,!0),b=(f-u)/65535,c=Ee(o);return{raw:o,dmin:u,dmax:f,dmul:b,integral:c,radius:0}};return ae(r,e).then(t)}function z(){let r={controller:new AbortController},e=ie(t=>Fe(t,r));return e.controllerHolder=r,e}function le(r){let e={controller:r},t=ie(n=>ae(n,e));return t.controllerHolder=e,t}function Ee(r){let e=new Uint32Array(258*258),t=new Uint32Array(258*258);e[0]=r[0],t[0]=r[0]===0?0:1;for(let n=1;n<258;++n)e[n]=r[n]+e[n-1],e[258*n]=r[258*n]+e[258*n-258],t[n]=(r[n]===0?0:1)+t[n-1],t[258*n]=(r[258*n]===0?0:1)+t[258*n-258];for(let n=1,s=259;n<258;++n,++s)for(let o=1;o<258;++o,++s)e[s]=r[s]+e[s-258]+e[s-1]-e[s-258-1],t[s]=(r[s]===0?0:1)+t[s-258]+t[s-1]-t[s-258-1];return{integral:e,integralNZ:t}}function ce(r,e){if(e<0||e===r.radius)return r;r.radius=e;let t=258,{integral:n,integralNZ:s}=r.integral;for(let o=1;o<t;o++)for(let i=1;i<t;i++){if(!r.raw[t*o+i])continue;let l=Math.min(e,i-1,t-1-i),u=Math.min(e,o-1,t-1-o),f=t*(o-u-1)+i,b=t*(o+u)+i,c=s[f-l-1],a=s[f+l],d=s[b-l-1],h=s[b+l],m=c+h-a-d,p=n[f-l-1],g=n[f+l],y=n[b-l-1],S=n[b+l],C=p+S-g-y;r.raw[o*t+i]=C/m}return r}function w(r){let e=r>>0&255,t=r>>8&255,n=r>>16&255,s=e.toString(16),o=t.toString(16),i=n.toString(16);return s=s.length===2?s:"0"+s,o=o.length===2?o:"0"+o,i=i.length===2?i:"0"+i,"#"+s+o+i}function T(r){if(r[0]==="#"){if(r.length===4)return+("0xff"+r[3]+r[3]+r[2]+r[2]+r[1]+r[1]);if(r.length===7)return+("0xff"+r[5]+r[6]+r[3]+r[4]+r[1]+r[2]);if(r.length===9)return+("0x"+r[7]+r[8]+r[5]+r[6]+r[3]+r[4]+r[1]+r[2])}return x("wrong color format",r),0}async function k(r,e){return(await fetch(r,e)).json()}function L(r,e="",t){var s;let n=document.createElement(r);return n.className=e,t&&((s=t.appendChild)==null||s.call(t,n)),n}function O(r,e,t){let n=r>>0&255,s=r>>8&255,o=r>>16&255,i=r>>>24,l=e>>0&255,u=e>>8&255,f=e>>16&255,b=e>>>24,c=n+t*(l-n),a=s+t*(u-s),d=o+t*(f-o),h=i+t*(b-i);return c|a<<8|d<<16|h<<24}function me(r,e,t){let n=[];for(let s=0;s<t;++s)n.push(s*(e-r)/(t-1)+r);return n}function ue(r,e){let t=typeof e=="number"?e:typeof e=="string"?new Date(e).getTime():e.getTime();return r.find(n=>new Date(n).getTime()>=t)||r[r.length-1]}var fe=!1;function He(r){console.log(r?"Logging on":"Logging off"),fe=r}function x(...r){fe&&console.trace(...r)}var Se=ee(N());function Ne(r,e,t){return r>t?t:r<e?e:r}var R=class{constructor(e,t,[n,s],o){let i=s-n;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let l=[];this.DataToStyle=U(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),o&&(this.DataToKnots=U(t,"knot"));let u=U(e.units,t,e.extraUnits),f=m=>~~(65535*Ne((u(m)-n)/(s-n),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((m,p)=>m[0]<p[0]?-1:m[0]>p[0]?1:0);for(let[m]of e.colorMap)l.push(f(m))}else{if(e.levels||(e.levels=me(this.DataToStyle(n),this.DataToStyle(s),10)),e.levels.sort((m,p)=>m<p?-1:m>p?1:0),!e.colors){let m=j();e.colorScheme&&e.colorScheme in m?e.colors=m[e.colorScheme]:e.colors=m.wb}for(let m of e.levels)l.push(f(m))}let b=65536,c=G(b,e);this.ticks=c.ticks;let a=c.ticks[0].data,h=c.ticks[c.ticks.length-1].data-a;for(let m=0;m<65536;++m){let p=i*m/65535+n,g=this.DataToStyle(p),y=Math.round((b-1)*(g-a)/h);y<=0?this.colorsI[m]=e.showBelowMin?c.colors[0]:0:y>=b?this.colorsI[m]=e.showAboveMax?c.colors[b-1]:0:this.colorsI[m]=c.colors[y]}this.colorsI[0]=0;for(let m=0;m<l[0];++m)this.levelIndex[m]=0;for(let m=0;m<l.length-1;m++)for(let p=l[m];p<l[m+1]+1;++p)this.levelIndex[p]=m;for(let m=l[l.length-1];m<65536;++m)this.levelIndex[m]=l.length-1}};function de(r){var t;if(r!==0&&-.1<r&&r<.1)return r.toExponential(2);let e=r.toString();return((t=e.split(".")[1])==null?void 0:t.length)>2?r.toFixed(2):e}function G(r,e){let t={size:r,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(r),ticks:[]},{colorMap:n,levels:s,colors:o}=e,i=e.fill!=="solid";if(n){let a=n[0][0],d=n[n.length-1][0]-a;for(let[h,m]of n){let p=~~((h-a)/d*(r-1)),g={data:h,dataString:de(h),color:m,pos:p};t.ticks.push(g)}for(let h=0;h<n.length-1;h++){let m=t.ticks[h].pos,p=t.ticks[h+1].pos,g=T(n[h][1]),y=i?T(n[h+1][1]):0;for(let S=m;S<p;++S)t.colors[S]=i?O(g,y,(S-m)/(p-m)):g}return t.colors[r-1]=T(n[n.length-1][1]),t}if(!o||!s)return t;let l=0,u=0,f=-1;for(let a=0;a<r;++a){let d=a*(o.length-1)/r;f!==~~d&&(f=~~d,l=T(o[f]),u=o.length>f+1?T(o[f+1]):l),t.colors[a]=i?O(l,u,d-f):l}t.colors[r-1]=T(o[o.length-1]);let b=s[0],c=(r-1)/(s[s.length-1]-b);for(let a of s){let d=~~((a-b)*c),h={data:a,dataString:de(a),color:w(t.colors[d]),pos:d};t.ticks.push(h)}return t}var Q=256,Be=2*Math.PI*6378137/Q,W=2*Math.PI*6378137/2;function Ze(r,e){let t=r/W*180,n=e/W*180;return n=180/Math.PI*(2*Math.atan(Math.exp(n*Math.PI/180))-Math.PI/2),[n,t]}function je(r,e,t){let n=ze(t),s=r*n-W,o=e*n-W;return[s,o]}function ze(r){return Be/Math.pow(2,r)}function q(r,e,t){let[n,s]=Ze(...je(r,e,t));return[s,-n]}function he(r,e){return[r*Q,e*Q]}var Oe="A".charCodeAt(0),K,D=0;async function Ge(r,e){let t;try{t=await(await fetch(r,e)).json()}catch(n){console.log("Can't load QTree:",n);return}K=A(t,{pos:0}),D=be(K),console.log("Loaded QTree, depth:",D)}function A(r,e){let t=r.charCodeAt(e.pos)-Oe;e.pos++;let n=t&1?A(r,e):null,s=t&2?A(r,e):null,o=t&4?A(r,e):null,i=t&8?A(r,e):null;return{sub:n||s||o||i?[n,s,o,i]:null}}function be(r){let e=0;if(r==null?void 0:r.sub){for(let t=0;t<4;t++)if(r.sub[t]!==null){let n=be(r.sub[t])+1;e<n&&(e=n)}}return e}var v;(function(n){n.Land="land",n.Mixed="mixed",n.Sea="sea"})(v||(v={}));function ge(r){if(!D)return v.Mixed;let e=Y({},r),t=!1;if(D<=r.z){t=!0;let n=r.z-D;e={x:r.x>>n,y:r.y>>n,z:D}}return xe(K,e,t)}function xe(r,e,t){if(r===null)return v.Land;if(t&&e.z===0)return v.Mixed;if(r.sub===null)return v.Sea;if(e.z===0)return v.Mixed;e.z--;let n=e.x>>e.z&1,o=(e.y>>e.z&1)<<1|n;return xe(r.sub[o],e,t)}function Qe(r,e){if(!e)return r;let t=.9999999/Math.pow(2,e.z),n=e.x*256*t,s=e.y*256*t,o={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:i}=o;for(let l=-1,u=0;l<=256;l++){let f=s+l*t,b=Math.floor(f),c=f-b;for(let a=-1;a<=256;a++,u++){let d=n+a*t,h=Math.floor(d),m=d-h,p=h+1+(b+1)*258,g=r.raw[p],y=r.raw[p+1],S=r.raw[p+258],C=r.raw[p+258+1];switch((g?1:0)|(y?2:0)|(S?4:0)|(C?8:0)){case 0:i[u]=0;continue;case 1:i[u]=g;continue;case 2:i[u]=y;continue;case 3:S=g,C=y;break;case 4:i[u]=S;continue;case 5:y=g,C=S;break;case 6:C=y+S>>1,g=C;break;case 7:C=y+S>>1;break;case 8:i[u]=C;continue;case 9:y=g+C>>1,S=y;break;case 10:g=y,S=C;break;case 11:S=g+C>>1;break;case 12:g=S,y=C;break;case 13:y=g+C>>1;break;case 14:g=y+S>>1;break}g=r.dmin+r.dmul*g,y=r.dmin+r.dmul*y,S=r.dmin+r.dmul*S,C=r.dmin+r.dmul*C;let I=V(g,y,m),M=V(S,C,m);i[u]=(V(I,M,c)-r.dmin)/r.dmul,i[u]===0&&(i[u]=1)}}return o}function V(r,e,t){let n=((e-r)%360+540)%360-180;return(r+n*t+360)%360}function qe(r,e){if(!e)return r;let t=.9999999/Math.pow(2,e.z),n=e.x*256*t,s=e.y*256*t,o={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:i}=o;for(let l=-1,u=0;l<=256;l++){let f=s+l*t,b=Math.floor(f),c=f-b;for(let a=-1;a<=256;a++,u++){let d=n+a*t,h=Math.floor(d),m=d-h,p=h+1+(b+1)*258,g=r.raw[p],y=r.raw[p+1],S=r.raw[p+258],C=r.raw[p+258+1];switch((g?1:0)|(y?2:0)|(S?4:0)|(C?8:0)){case 7:i[u]=m+c<1?m*(y-g)+c*(S-g)+g:0;continue;case 14:i[u]=m+c<1?0:m*(C-S)+c*(C-y)+y+S-C;continue;case 11:i[u]=c<m?(1-m)*(g-y)+c*(C-y)+y:0;continue;case 13:i[u]=c<m?0:(1-m)*(S-C)+c*(S-g)+g+C-S;continue;case 15:i[u]=m+c<1?m*(y-g)+c*(S-g)+g:m*(C-S)+c*(C-y)+y+S-C;continue;default:i[u]=0}}}return o}function Ke(r,e,t){let n=t==="land"?1:0;for(let s=3,o=0;o<256;o++)for(let i=0;i<256;i++,s+=4){let l=e.data[s]?1:0;n^l&&(r.raw[(o+1)*258+(i+1)]=0)}return r}function Ve(r){let[e,t]=he(r.x,r.y),[n,s]=q(e,t,r.z),[o,i]=q(e+256,t+256,r.z);return{west:n,north:s,east:o,south:i}}function ye({layer:r,coords:e,done:t}){let n=L("div","leaflet-tile s-tile");return n.wxtile=new pe({layer:r,coords:e,tileEl:n}),n.wxtile.load().then(s=>{s.draw(),t()}),n}var pe=class{constructor({layer:e,coords:t,tileEl:n}){this.data=[];this.sLines=[];this.coords=t,this.layer=e,this.canvasFill=L("canvas","s-tile canvas-fill",n),this.canvasSlines=L("canvas","s-tile canvas-slines",n),this.canvasVector=this.canvasFill,this.canvasFill.width=this.canvasFill.height=this.canvasSlines.width=this.canvasSlines.height=256;function s(o){let i=o.getContext("2d");if(!i)throw"error";return i}this.canvasFillCtx=s(this.canvasFill),this.imData=this.canvasFillCtx.createImageData(256,256),this.canvasSlinesCtx=s(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasSlinesCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVector(),this._drawDegree(),this._drawStaticSlines())}clearSLinesCanvas(){this.canvasSlinesCtx.clearRect(0,0,256,256)}drawSLines(e){if(this.sLines.length===0)return;let t=this.canvasSlinesCtx;if(t.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.sLines=[];return}let n=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let s=0;s<this.sLines.length;++s){let o=this.sLines[s],i=o.length-1,l=(e+(1+o[0].x)*(1+o[0].y))%30;for(let u=0;u<i;++u){let f=o[u],b=o[u+1],c=1-(l-u)/i;(c<0||c>1)&&(c=0);let a=(~~(c*255)).toString(16);t.strokeStyle=n+(a.length<2?"0"+a:a);let d=1+~~((1.2-c)*5);t.lineWidth=d,t.beginPath(),t.moveTo(f.x,f.y),t.lineTo(b.x,b.y),t.stroke()}}}getData({x:e,y:t}){if(!this.data.length)return;let n=this.data[0].raw[(t+1)*258+(e+1)];return{raw:n,data:this.data[0].dmin+this.data[0].dmul*n}}async load(){var c;let{coords:e,layer:t}=this,{boundaries:n}=t.state.meta,s=this.layer.style.mask;var o;if((s==="land"||s==="sea")&&(o=ge(e),s===o))return this.data=[],this.sLines=[],this;if(n==null?void 0:n.boundaries180){let a=Ve(e),d=h=>!(a.west>h.east||h.west>a.east||a.south>h.north||h.south>a.north);if(!n.boundaries180.some(d))return this.data=[],this.sLines=[],this}let{upCoords:i,subCoords:l}=this._splitCoords(e),u=this._coordsToURLs(i),f;try{f=await Promise.all(u.map(t.loadData))}catch(a){return this}let b=((c=t.state)==null?void 0:c.units)==="degree"?Qe:qe;if(this.data=f.map(a=>b(ce(a,this.layer.style.blurRadius),l)),this.layer.vector&&this._vectorPrepare(),s&&o===v.Mixed){let a=t.state.maskServerURI.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));try{let d=await t.loadMask(a);Ke(this.data[0],d,s)}catch(d){this.layer.style.mask=void 0,x("Can't load Mask. Turned off")}}return this.layer.vector&&this._createSLines(),this}_splitCoords(e){let t=e.z-this.layer.state.meta.maxZoom;if(t<=0)return{upCoords:e};let n={x:e.x>>>t,y:e.y>>>t,z:this.layer.state.meta.maxZoom},s={x:e.x&(1<<t)-1,y:e.y&(1<<t)-1,z:t};return{upCoords:n,subCoords:s}}_coordsToURLs(e){let t=this.layer.state.baseURL.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));return this.layer.dataSource.variables.map(n=>t.replace("{var}",n))}_vectorPrepare(){if(this.data.length!==2)throw"this.data !== 2";this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[e,t,n]=this.data;e.dmax=1.42*Math.max(-t.dmin,t.dmax,-n.dmin,n.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let s=0;s<258*258;++s){if(!t.raw[s]||!n.raw[s]){e.raw[s]=0;continue}let o=t.dmin+t.dmul*t.raw[s],i=n.dmin+n.dmul*n.raw[s];e.raw[s]=Math.sqrt(i*i+o*o)/e.dmul}}_drawFillAndIsolines(){let{imData:e}=this,{canvasFillCtx:t}=this,n=new Uint32Array(e.data.buffer),{raw:s}=this.data[0],{clut:o,style:i}=this.layer,{levelIndex:l,colorsI:u}=o;if(i.fill!=="none"){let b=u;for(let c=0,a=0,d=259;c<256;++c,d+=2)for(let h=0;h<256;++h,++a,++d)n[a]=b[s[d]]}else n.fill(0);let f=[];if(i.isolineColor!=="none"){let b=i.isolineColor[0]==="#"?T(i.isolineColor):0;for(let c=0,a=0;c<256;c+=1)for(let d=0;d<256;d+=1){let h=(c+1)*258+(d+1),m=s[h],p=s[h+1],g=s[h+258];if(!m||!p||!g)continue;let y=l[m],S=l[p],C=l[g];if(y!==S||y!==C){let H=Math.max(y,S,C),I=Math.max(m,p,g),M=c*256+d;switch(i.isolineColor){case"inverted":n[M]=~u[I]|4278190080;break;case"fill":n[M]=u[I]|4278190080;break;default:n[M]=b;break}i.isolineText&&!(++a%255)&&d>20&&d<235&&c>20&&c<235&&f.push({x:d,y:c,d:m,dr:p,db:g,mli:H})}}}if(t.putImageData(e,0,0),f.length){t.font="1.1em Sans-serif",t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";for(let{x:b,y:c,d:a,dr:d,db:h,mli:m}of f){let p=this.layer.clut.ticks[m].dataString,g=Math.atan2(a-d,h-a);t.save(),t.translate(b,c),t.rotate(g<-1.57||g>1.57?g+3.14:g),t.strokeText(p,0,0),t.fillText(p,0,0),t.restore()}}}_drawStaticSlines(){if(!this.sLines.length||!this.layer.style.streamLineStatic)return;let{canvasSlinesCtx:e}=this;if(this.layer.style.streamLineColor==="none"){this.sLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let t=this.sLines.length;t--;){let n=this.sLines[t];for(let s=0;s<n.length-1;++s){let o=n[s],i=n[s+1];e.moveTo(o.x,o.y),e.lineTo(i.x,i.y)}}e.stroke()}_drawVector(){if(!this.layer.vector||!this.layer.clut.DataToKnots||!this.layer.style.vectorColor||this.layer.style.vectorColor==="none"||!this.layer.style.vectorType||this.layer.style.vectorType==="none")return;if(this.data.length!==3)throw"this.data.length !== 3";let[e,t,n]=this.data,{canvasVectorCtx:s}=this;switch(this.layer.style.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=this.layer.style.vectorType}s.textAlign="center",s.textBaseline="middle";let o=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0,i=32;for(let l=i/2;l<256;l+=i)for(let u=i/2;u<256;u+=i){let f=u+1+(l+1)*258;if(!e.raw[f])continue;let b=Math.atan2(t.dmin+t.raw[f]*t.dmul,n.dmin+n.raw[f]*n.dmul),c=e.dmin+e.raw[f]*e.dmul,a=this.layer.dataSource.variables[0].includes("current")?5:.2,d=Math.min(this.layer.clut.DataToKnots(c)*a,25)+65,h=String.fromCharCode(d);switch(this.layer.style.vectorColor){case"inverted":s.fillStyle=w(~this.layer.clut.colorsI[e.raw[f]]);break;case"fill":s.fillStyle=w(this.layer.clut.colorsI[e.raw[f]]);break;default:s.fillStyle=this.layer.style.vectorColor;break}s.save(),s.translate(u,l),s.rotate(b+o),s.fillText(h,0,0),s.restore()}}_drawDegree(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:e}=this,t=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle";let n=this.data[0],s="L",o=32;for(let i=o/2;i<256;i+=o)for(let l=o/2;l<256;l+=o){let u=l+1+(i+1)*258;if(!n.raw[u])continue;let b=(n.dmin+n.raw[u]*n.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=w(~this.layer.clut.colorsI[n.raw[u]]);break;case"fill":e.fillStyle=w(this.layer.clut.colorsI[n.raw[u]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(l,i),e.rotate(b+t),e.fillText(s,0,0),e.restore()}}_createSLines(){if(this.data.length!==3)throw"this.data.length !== 3";if(!this.layer.style.streamLineColor||this.layer.style.streamLineColor==="none")return;let e=this.layer.style.streamLineSpeedFactor||1;this.sLines=[];let[t,n,s]=this.data,o=Math.max(this.coords.z-this.layer.state.meta.maxZoom,0),i=Math.min(2**(o+5),128),l=~~(120+o*60);for(let u=0;u<=256;u+=i)for(let f=0;f<=256;f+=i){if(!t.raw[1+f+(1+u)*258])continue;let b=[],c=f,a=u;for(let d=0;d<=l&&c>=0&&c<=256&&a>=0&&a<=256;d++){!(d%(l/6))&&b.push({x:~~c,y:~~a});let h=~~c+1+(~~a+1)*258;if(!t.raw[h])break;c+=e*(n.dmin+n.raw[h]*n.dmul)/t.dmax,a-=e*(s.dmin+s.raw[h]*s.dmul)/t.dmax}c=f,a=u;for(let d=1;d<=l&&c>=0&&c<=256&&a>=0&&a<=256;d++){!(d%(l/6))&&b.unshift({x:~~c,y:~~a});let h=~~c+1+(~~a+1)*258;if(!t.raw[h])break;c-=e*(n.dmin+n.raw[h]*n.dmul)/t.dmax,a+=e*(s.dmin+s.raw[h]*s.dmul)/t.dmax}b.length>2&&this.sLines.push(b)}}};var Ce="setup not complete",Xe=le(new AbortController),F=class extends Se.default.GridLayer{constructor({dataSource:e,options:t,lazy:n}){super(t);this.styles=Z();this.style=Object.assign({},this.styles.base);this.loadData=z();this.loadMask=Xe;this.error=Ce;this.vector=!1;this.clut=new R(this.style,"",[0,2],!1);this.animation=!1;this.animationRedrawID=0;this.animFrame=0;this.oldMaxZoom=0;if(x("Creating a WxTilex layer:",e.name,". Params:",JSON.stringify({dataSource:e,options:t})),!e||!e.ext||!e.dataset||!e.name||!e.serverURI||!e.styleName||!Array.isArray(e.variables))throw x("dataSource is wrong!"),"dataSource is wrong!";this.dataSource=e,this.state={maskServerURI:e.maskServerURI||e.serverURI.replace(/\/data\/?/i,"/mask/{z}/{x}/{y}"),units:"undefined",baseURL:"undefined",meta:{maxZoom:0,times:["undefined"],variables:["undefined"],variablesMeta:{}},instance:"undefined",minmax:[[0,1]],originURI:"undefined",time:"undefined"},this.setupCompletePromise=new Promise(s=>{let o=()=>{x("Setup:",e.name),this.on("remove",this._onRemoveLayer,this),this.on("add",this._onAddLayer,this),this._setUpDataSet(e).then(i=>{x("Setup complete:",this.dataSource.name,". Result:",i),this._map&&n&&this._onAddLayer(),this.fire("setupcomplete",{layer:this}),s(i)})};n?this.once("add",o):o()})}createTile(e,t){return this.error&&this.error!==Ce?(setTimeout(t),Object.assign(L("div","error-tile"),{innerHTML:this.error})):this.state.baseURL==="undefined"?(setTimeout(t),L("div","error-tile")):ye({layer:this,coords:e,done:t})}getSetupCompletePromise(){return this.setupCompletePromise}getTile(e){if(!this._map||this.error)return;let t=this._map.getZoom(),{x:n,y:s}=this._map.project(e,t),o={x:~~(n/256),y:~~(s/256)},i=this._getCachedTile(o.x,o.y,t);if(!i)return;let l={x:~~(n-o.x*256),y:~~(s-o.y*256)},u=i.getData(l);if(!u)return;let{raw:f,data:b}=u,c=this.clut.colorsI[f],a=w(c),d=this.clut.DataToStyle(b);return{tile:i,data:b,raw:f,rgba:c,hexColor:a,inStyleUnits:d,tilePoint:l,units:this.style.units}}setStyle(e){if(x("setStyle(",e,") for ",this.dataSource.name),this.error){x("setStyle: failed: "+this.error);return}if(!(this.dataSource.styleName===e&&e!=="custom")){if(e&&(this.dataSource.styleName=e),e==="custom"&&this.styles.custom){(!this.styles.custom.parent||!(this.styles.custom.parent in this.styles))&&(this.styles.custom.parent="base");let t=this.styles[this.styles.custom.parent];this.styles.custom=Object.assign(Object.assign({},t),this.styles.custom)}this.dataSource.styleName in this.styles?Array.isArray(this.styles[this.dataSource.styleName])&&(this.dataSource.styleName+="[0]"):(x(`cant find the style (${this.dataSource.styleName})`),this.dataSource.styleName+="[0]",this.dataSource.styleName in this.styles||(x(`cant find the style (${this.dataSource.styleName}), default is used`),this.dataSource.styleName="base"));try{let t=this.styles[this.dataSource.styleName];this.style=Object.assign({},t);let n=this.style.streamLineColor;n!=="none"&&n.length<7&&(this.style.streamLineColor="#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]);let s=this.state.minmax[0];this.clut=new R(this.style,this.state.units,s,this.vector)}catch(t){let n="setStyle: impossible error in RawCLUT: "+t;throw x(n),n}e&&(this._checkAndStartSlinesAnimation(),this._reloadTiles()),x("setStyle(",e,'): "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete."),this.fire("setstyle",{layer:this})}}getStyle(){return this.dataSource.styleName}getStyleName(){return this.style.name}setTime(e){if(x("setTime: "+e+" for "+this.dataSource.name+" start"),this.error)return x("setTime: failed: "+this.error),Promise.resolve([]);let t=ue(this.state.meta.times,e);if(this.state.time===t)return x("setTime: the same time - skipped"),Promise.resolve([]);if(this.state.time=t,this.state.baseURL=this.state.originURI+this.state.instance+`{var}/${this.state.time}/{z}/{x}/{y}.${this.dataSource.ext}`,this.fire("settime",{layer:this,layerTime:t}),x("setTime: "+t+" for "+this.dataSource.name+" complete"),!this._tiles)return Promise.resolve([]);let n=this._reloadTiles(!1);return n.then(()=>{var o;let s=Object.values(this._tiles);for(let i of s){let l=(o=i.el)==null?void 0:o.wxtile;if(l==null?void 0:l.data.length){let[u,f]=this.state.minmax[0],{dmin:b,dmax:c}=l.data[0];(Math.abs(b-u)>.01||Math.abs(c-f)>.01)&&(this.state.minmax=l.data.map(a=>[a.dmin,a.dmax]),this.setStyle(void 0));break}}this._redrawTiles()}),n}getTime(){return this.error?(x("getTime: failed: "+this.error),this.error):this.state.time}getTimes(){return x("getTimes"),this.error?(x("getTimes: failed: "+this.error),[]):this.state.meta.times}async checkDataChanged(){if(x("checkDataChanged"),this.error)return x("checkDataChanged: failed: "+this.error),!1;let e=await k(this.state.originURI+"instances.json"),t=e[e.length-1]+"/";if(this.state.instance!==t)return!0;let n=await k(this.state.originURI+t+"meta.json");return this.state.meta.times.toString()!==n.times.toString()}reloadData(){return x("reloadData"),this._setUpDataSet(void 0)}getLegendData(e){return x("getLegendData"),(this.error||!this.clut)&&x("getLegendData: failed. "+this.dataSource.name+" : "+this.error),G(e,this.style)}setTimeAnimationMode(e=2){x("setTimeAnimationMode"),this.oldMaxZoom=this.state.meta.maxZoom;let t=this._map.getZoom(),s=(t<this.oldMaxZoom?t:this.oldMaxZoom)-e;this.state.meta.maxZoom=s<0?0:s}unsetTimeAnimationMode(){return x("unsetTimeAnimationMode"),this.oldMaxZoom&&(this.state.meta.maxZoom=this.oldMaxZoom),this._reloadTiles()}getMinMax(){let[e,t]=this.state.minmax[0];return{min:e,max:t}}setAnimation(e){return x("setAnimation"),this.animation=e,this._checkAndStartSlinesAnimation(),this.animation}_getCachedTile(e,t,n){var s,o;return(o=(s=this._tiles[`${e}:${t}:${n}`])==null?void 0:s.el)==null?void 0:o.wxtile}_ForEachTile(e){var n;let t=[];for(let s in this._tiles){let o=(n=this._tiles[s].el)==null?void 0:n.wxtile,i=o&&e(o);i&&t.push(i)}return t}async _setUpDataSet(e){e&&(this.dataSource=e),this._stopLoadingResetLoadDataFunc(),this.state.originURI=this.dataSource.serverURI+"/"+this.dataSource.dataset+"/";try{let t=await k(this.state.originURI+"instances.json");this.state.instance=t[t.length-1]+"/"}catch(t){return this.error=this.dataSource.name+": load instances.json error: "+t,x(this.error),!1}try{let t=this.state.originURI+this.state.instance+"meta.json";this.state.meta=await k(t)}catch(t){return this.error=this.dataSource.name+": load meta.json error: "+t,x(this.error),!1}if(this.vector=this.dataSource.variables.length===2,this.animation=this.vector,this.state.units=this.state.meta.variablesMeta[this.dataSource.variables[0]].units,this.state.minmax=this.dataSource.variables.map(t=>[this.state.meta.variablesMeta[t].min,this.state.meta.variablesMeta[t].max]),this.vector){let[[t,n],[s,o]]=this.state.minmax;this.state.minmax.unshift([0,1.42*Math.max(-t,n,-s,o)])}return this.error=null,e&&(this.setStyle(void 0),await this.setTime(new Date)),!0}_checkZoom(){var e;((e=this._map)==null?void 0:e.getZoom())>this.state.meta.maxZoom||this._stopLoadingResetLoadDataFunc()}_onAddLayer(){var e;x("onadd:",this.dataSource.name),(e=this._map)==null||e.on("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this.redraw(),this._checkAndStartSlinesAnimation()})}_onRemoveLayer(){var e;x("onremove:",this.dataSource.name),(e=this._map)==null||e.off("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this._stopLoadingResetLoadDataFunc(),this._stopSlinesAnimation()})}_stopLoadingResetLoadDataFunc(){this.loadData.controllerHolder.controller.abort(),this.loadData=z()}_checkAndStartSlinesAnimation(){if(this.animFrame||!this.animation||!this.vector||!this.style.streamLineColor||this.style.streamLineColor==="none")return;let e=t=>{if(!this.animation||this.style.streamLineStatic){this._stopSlinesAnimation();return}this._ForEachTile(n=>n.drawSLines(t)),this.animFrame=requestAnimationFrame(e)};e(0)}_stopSlinesAnimation(){cancelAnimationFrame(this.animFrame),this._ForEachTile(e=>e.clearSLinesCanvas()),this.animFrame=0}_redrawTiles(){this.animationRedrawID===0&&(this.animationRedrawID=requestAnimationFrame(()=>{x("_redrawTiles: requestAnimationFrame: "+this.dataSource.name),this._ForEachTile(e=>e.draw()),this.animationRedrawID=0}))}_reloadTiles(e=!0){x("_reloadTiles: start - "+this.dataSource.name),this.loadData.controllerHolder.controller.abort(),this.loadData.controllerHolder.controller=new AbortController;let t=this._ForEachTile(o=>o.load()),n=Promise.all(t),{controller:s}=this.loadData.controllerHolder;return e&&n.then(()=>s.signal.aborted||this._redrawTiles()),x("_reloadTiles: finished - "+this.dataSource.name),n}};function $e(r){return new F(r)}var we=class extends E.default.Control{constructor(e){super(e);this.URI=e.URI}onAdd(){let e=document.createElement("img");return e.src=this.URI,e.className="wxtiles-logo",e}};function Ut(r){return x("Add watermark:",JSON.stringify(r)),new we(r)}var Te=class extends E.default.GridLayer{createTile(e){let t=document.createElement("div");return t.innerHTML=[e.x,e.y,e.z].join(", "),t.style.outline="1px solid red",t}};function Rt(){return x("Add WxDebugCoordsLayer:"),new Te().setZIndex(1e3)}function Wt(r,e){return E.default.layerGroup(r.map($e),e)}export{Rt as CreateWxDebugCoordsLayer,Wt as CreateWxTilesGroupLayer,$e as CreateWxTilesLayer,Ut as CreateWxTilesWatermark,Ge as LoadQTree,Te as WxDebugLayer,j as WxGetColorSchemes,Z as WxGetColorStyles,F as WxTilesLayer,Pe as WxTilesLibSetup,He as WxTilesLogging,we as WxWatermark};
|
package/dist/web/wxtiles.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var wxtilesjs=(()=>{var Ae=Object.create;var k=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames,J=Object.getOwnPropertySymbols,Pe=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty,Ue=Object.prototype.propertyIsEnumerable;var ee=(r,e,t)=>e in r?k(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,te=(r,e)=>{for(var t in e||(e={}))Y.call(e,t)&&ee(r,t,e[t]);if(J)for(var t of J(e))Ue.call(e,t)&&ee(r,t,e[t]);return r};var re=r=>k(r,"__esModule",{value:!0});var nt=typeof require!="undefined"?require:r=>{throw new Error('Dynamic require of "'+r+'" is not supported')};var Re=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),We=(r,e)=>{re(r);for(var t in e)k(r,t,{get:e[t],enumerable:!0})},Fe=(r,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of _e(e))!Y.call(r,n)&&n!=="default"&&k(r,n,{get:()=>e[n],enumerable:!(t=Ie(e,n))||t.enumerable});return r},ne=r=>Fe(re(k(r!=null?Ae(Pe(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var Z=Re((at,se)=>{se.exports=window.L});var rt={};We(rt,{CreateWxDebugCoordsLayer:()=>et,CreateWxTilesGroupLayer:()=>tt,CreateWxTilesLayer:()=>ke,CreateWxTilesWatermark:()=>Ye,LoadQTree:()=>Se,WxDebugLayer:()=>$,WxGetColorSchemes:()=>W,WxGetColorStyles:()=>R,WxTilesLayer:()=>_,WxTilesLibSetup:()=>ce,WxTilesLogging:()=>xe,WxWatermark:()=>X});var N=ne(Z());var oe={comment1:["'degC': ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["'hPa': ['Pa', 1000]' -> hPa = Pa * 1000 + 0 (0 - could be ommited)",0],K:["K",1],kelvin:["K",1],F:["K",.5555555555,255.372222222],C:["K",1,273.15],degC:["K",1,273.15],"kg/m^2/s":["kg/m^2/s",1],"Kg/m^2/s":["kg/m^2/s",1],"Kg m**-2 s**-1":["kg/m^2/s",1],"Kg m^-2 s^-1":["kg/m^2/s",1],"Kg m^{-2} s^-1":["kg/m^2/s",1],"mm/h":["kg/m^2/s",.00027777777],"mm/hr":["kg/m^2/s",.00027777777],"W/m^2":["W/m^2",1],"W m^-2":["W/m^2",1],"W m^{-2}":["W/m^2",1],"W/m**2":["W/m^2",1],"W m**-2":["W/m^2",1],"m/s":["m/s",1],"m s**-1":["m/s",1],"m s^-1":["m/s",1],"m.s^{-1}":["m/s",1],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["m/s",.27777777777],"km h^-1":["m/s",.27777777777],"km h**-1":["m/s",.27777777777],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],inch:["m",.0254],Pa:["Pa",1],hPa:["Pa",100],degree:["degree",1],radian:["degree",57.3],"mg/m^3":["mg/m^3",1],"mg m^-3":["mg/m^3",1],"mg.m^-3":["mg/m^3",1],"%":["%",1],"(0 - 1)":["%",100]};var ie={none:["#00000000","#00000000"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbowzerro:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow2:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebirdzerro:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bw:["#000000ff","#ffffffff"],wb:["#ffffffff","#000000ff"],redish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]};var U={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"}};var j,ae,le;function ce({colorStyles:r={},units:e={},colorSchemes:t={}}={}){x("WxTile lib setup: start"),j=Object.assign({},oe,e),ae=Object.assign({},t,ie);let n=Object.assign({},r,U);le=Ee(n),x("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),x("WxTile lib setup is done.")}function R(){return le}function W(){return ae}function F(r,e,t){let n=t?Object.assign({},j,t):j;if(!n||!r||!e||r===e||!n[r]||!n[e]||n[r][0]!==n[e][0]){x(r===e?"Trivial converter:":"Inconvertible units. Default converter is used:",r," -> ",e);let i=l=>l;return i.trivial=!0,i}x("Converter: From:",r," To:",e);let s=n[r][1]/n[e][1],o=(n[r][2]||0)/n[e][1]-(n[e][2]||0)/n[e][1];return o?i=>s*i+o:i=>s*i}function Ee(r){let e=Object.assign({},U);for(let s in r){let o=r[s];if(Array.isArray(o))for(let i=0;i<o.length;++i)e[s+"["+i+"]"]=Object.assign({},o[i]);else e[s]=Object.assign({},o)}let t=(s,o)=>{if(o==="base")return U.base;let i=s[o];(!i.parent||!(i.parent in s))&&(i.parent="base");let l=t(s,i.parent);return Object.assign(i,Object.assign({},l,i,{parent:"base"}))},n={};for(let s in e)n[s]=t(e,s);return n}function me(r){let e=new Map;return t=>{let n=e.get(t);if(n===void 0){let s=r(t);return s instanceof Promise?s.then(()=>e.set(t,s)).catch(o=>{o instanceof DOMException||e.set(t,s)}):e.set(t,s),s}return n}}async function He(r,e){let t=new Image;return t.src=URL.createObjectURL(await(await fetch(r,e.controller)).blob()),await t.decode(),URL.revokeObjectURL(t.src),t}function Ne(r){let{width:e,height:t}=r,n=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d");if(!n)throw"catastrophe";return n.drawImage(r,0,0),n.getImageData(0,0,e,t)}async function ue(r,e){return Ne(await He(r,e))}function Be(r,e){let t=n=>{let s=new Uint16Array(n.data.buffer),o=new Uint16Array(s.length/2);for(let a=0;a<o.length;a++)o[a]=s[a*2];let i=new Uint8Array(n.data.buffer);for(let a=0;a<8;++a)i[a]=i[a*4+2];let l=new DataView(n.data.buffer),u=l.getFloat32(0,!0),f=l.getFloat32(4,!0),b=(f-u)/65535,c=Ze(o);return{raw:o,dmin:u,dmax:f,dmul:b,integral:c,radius:0}};return ue(r,e).then(t)}function z(){let r={controller:new AbortController},e=me(t=>Be(t,r));return e.controllerHolder=r,e}function fe(r){let e={controller:r},t=me(n=>ue(n,e));return t.controllerHolder=e,t}function Ze(r){let e=new Uint32Array(258*258),t=new Uint32Array(258*258);e[0]=r[0],t[0]=r[0]===0?0:1;for(let n=1;n<258;++n)e[n]=r[n]+e[n-1],e[258*n]=r[258*n]+e[258*n-258],t[n]=(r[n]===0?0:1)+t[n-1],t[258*n]=(r[258*n]===0?0:1)+t[258*n-258];for(let n=1,s=259;n<258;++n,++s)for(let o=1;o<258;++o,++s)e[s]=r[s]+e[s-258]+e[s-1]-e[s-258-1],t[s]=(r[s]===0?0:1)+t[s-258]+t[s-1]-t[s-258-1];return{integral:e,integralNZ:t}}function de(r,e){if(e<0||e===r.radius)return r;r.radius=e;let t=258,{integral:n,integralNZ:s}=r.integral;for(let o=1;o<t;o++)for(let i=1;i<t;i++){if(!r.raw[t*o+i])continue;let l=Math.min(e,i-1,t-1-i),u=Math.min(e,o-1,t-1-o),f=t*(o-u-1)+i,b=t*(o+u)+i,c=s[f-l-1],a=s[f+l],d=s[b-l-1],h=s[b+l],m=c+h-a-d,p=n[f-l-1],g=n[f+l],y=n[b-l-1],S=n[b+l],C=p+S-g-y;r.raw[o*t+i]=C/m}return r}function w(r){let e=r>>0&255,t=r>>8&255,n=r>>16&255,s=e.toString(16),o=t.toString(16),i=n.toString(16);return s=s.length===2?s:"0"+s,o=o.length===2?o:"0"+o,i=i.length===2?i:"0"+i,"#"+s+o+i}function T(r){if(r[0]==="#"){if(r.length===4)return+("0xff"+r[3]+r[3]+r[2]+r[2]+r[1]+r[1]);if(r.length===7)return+("0xff"+r[5]+r[6]+r[3]+r[4]+r[1]+r[2]);if(r.length===9)return+("0x"+r[7]+r[8]+r[5]+r[6]+r[3]+r[4]+r[1]+r[2])}return x("wrong color format",r),0}async function A(r,e){return(await fetch(r,e)).json()}function L(r,e="",t){var s;let n=document.createElement(r);return n.className=e,t&&((s=t.appendChild)==null||s.call(t,n)),n}function O(r,e,t){let n=r>>0&255,s=r>>8&255,o=r>>16&255,i=r>>>24,l=e>>0&255,u=e>>8&255,f=e>>16&255,b=e>>>24,c=n+t*(l-n),a=s+t*(u-s),d=o+t*(f-o),h=i+t*(b-i);return c|a<<8|d<<16|h<<24}function he(r,e,t){let n=[];for(let s=0;s<t;++s)n.push(s*(e-r)/(t-1)+r);return n}function be(r,e){let t=typeof e=="number"?e:typeof e=="string"?new Date(e).getTime():e.getTime();return r.find(n=>new Date(n).getTime()>=t)||r[r.length-1]}var ge=!1;function xe(r){console.log(r?"Logging on":"Logging off"),ge=r}function x(...r){ge&&console.trace(...r)}var De=ne(Z());function je(r,e,t){return r>t?t:r<e?e:r}var E=class{constructor(e,t,[n,s],o){let i=s-n;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let l=[];this.DataToStyle=F(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),o&&(this.DataToKnots=F(t,"knot"));let u=F(e.units,t,e.extraUnits),f=m=>~~(65535*je((u(m)-n)/(s-n),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((m,p)=>m[0]<p[0]?-1:m[0]>p[0]?1:0);for(let[m]of e.colorMap)l.push(f(m))}else{if(e.levels||(e.levels=he(this.DataToStyle(n),this.DataToStyle(s),10)),e.levels.sort((m,p)=>m<p?-1:m>p?1:0),!e.colors){let m=W();e.colorScheme&&e.colorScheme in m?e.colors=m[e.colorScheme]:e.colors=m.wb}for(let m of e.levels)l.push(f(m))}let b=65536,c=G(b,e);this.ticks=c.ticks;let a=c.ticks[0].data,h=c.ticks[c.ticks.length-1].data-a;for(let m=0;m<65536;++m){let p=i*m/65535+n,g=this.DataToStyle(p),y=Math.round((b-1)*(g-a)/h);y<=0?this.colorsI[m]=e.showBelowMin?c.colors[0]:0:y>=b?this.colorsI[m]=e.showAboveMax?c.colors[b-1]:0:this.colorsI[m]=c.colors[y]}this.colorsI[0]=0;for(let m=0;m<l[0];++m)this.levelIndex[m]=0;for(let m=0;m<l.length-1;m++)for(let p=l[m];p<l[m+1]+1;++p)this.levelIndex[p]=m;for(let m=l[l.length-1];m<65536;++m)this.levelIndex[m]=l.length-1}};function ye(r){var t;if(r!==0&&-.1<r&&r<.1)return r.toExponential(2);let e=r.toString();return((t=e.split(".")[1])==null?void 0:t.length)>2?r.toFixed(2):e}function G(r,e){let t={size:r,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(r),ticks:[]},{colorMap:n,levels:s,colors:o}=e,i=e.fill!=="solid";if(n){let a=n[0][0],d=n[n.length-1][0]-a;for(let[h,m]of n){let p=~~((h-a)/d*(r-1)),g={data:h,dataString:ye(h),color:m,pos:p};t.ticks.push(g)}for(let h=0;h<n.length-1;h++){let m=t.ticks[h].pos,p=t.ticks[h+1].pos,g=T(n[h][1]),y=i?T(n[h+1][1]):0;for(let S=m;S<p;++S)t.colors[S]=i?O(g,y,(S-m)/(p-m)):g}return t.colors[r-1]=T(n[n.length-1][1]),t}if(!o||!s)return t;let l=0,u=0,f=-1;for(let a=0;a<r;++a){let d=a*(o.length-1)/r;f!==~~d&&(f=~~d,l=T(o[f]),u=o.length>f+1?T(o[f+1]):l),t.colors[a]=i?O(l,u,d-f):l}t.colors[r-1]=T(o[o.length-1]);let b=s[0],c=(r-1)/(s[s.length-1]-b);for(let a of s){let d=~~((a-b)*c),h={data:a,dataString:ye(a),color:w(t.colors[d]),pos:d};t.ticks.push(h)}return t}var Q=256,ze=2*Math.PI*6378137/Q,H=2*Math.PI*6378137/2;function Oe(r,e){let t=r/H*180,n=e/H*180;return n=180/Math.PI*(2*Math.atan(Math.exp(n*Math.PI/180))-Math.PI/2),[n,t]}function Ge(r,e,t){let n=Qe(t),s=r*n-H,o=e*n-H;return[s,o]}function Qe(r){return ze/Math.pow(2,r)}function q(r,e,t){let[n,s]=Oe(...Ge(r,e,t));return[s,-n]}function pe(r,e){return[r*Q,e*Q]}var qe="A".charCodeAt(0),K,D=0;async function Se(r,e){let t;try{t=await(await fetch(r,e)).json()}catch(n){console.log("Can't load QTree:",n);return}K=I(t,{pos:0}),D=Ce(K),console.log("Loaded QTree, depth:",D)}function I(r,e){let t=r.charCodeAt(e.pos)-qe;e.pos++;let n=t&1?I(r,e):null,s=t&2?I(r,e):null,o=t&4?I(r,e):null,i=t&8?I(r,e):null;return{sub:n||s||o||i?[n,s,o,i]:null}}function Ce(r){let e=0;if(r==null?void 0:r.sub){for(let t=0;t<4;t++)if(r.sub[t]!==null){let n=Ce(r.sub[t])+1;e<n&&(e=n)}}return e}var v;(function(n){n.Land="land",n.Mixed="mixed",n.Sea="sea"})(v||(v={}));function we(r){if(!D)return v.Mixed;let e=te({},r),t=!1;if(D<=r.z){t=!0;let n=r.z-D;e={x:r.x>>n,y:r.y>>n,z:D}}return Te(K,e,t)}function Te(r,e,t){if(r===null)return v.Land;if(t&&e.z===0)return v.Mixed;if(r.sub===null)return v.Sea;if(e.z===0)return v.Mixed;e.z--;let n=e.x>>e.z&1,o=(e.y>>e.z&1)<<1|n;return Te(r.sub[o],e,t)}function Ke(r,e){if(!e)return r;let t=.9999999/Math.pow(2,e.z),n=e.x*256*t,s=e.y*256*t,o={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:i}=o;for(let l=-1,u=0;l<=256;l++){let f=s+l*t,b=Math.floor(f),c=f-b;for(let a=-1;a<=256;a++,u++){let d=n+a*t,h=Math.floor(d),m=d-h,p=h+1+(b+1)*258,g=r.raw[p],y=r.raw[p+1],S=r.raw[p+258],C=r.raw[p+258+1];switch((g?1:0)|(y?2:0)|(S?4:0)|(C?8:0)){case 0:i[u]=0;continue;case 1:i[u]=g;continue;case 2:i[u]=y;continue;case 3:S=g,C=y;break;case 4:i[u]=S;continue;case 5:y=g,C=S;break;case 6:C=y+S>>1,g=C;break;case 7:C=y+S>>1;break;case 8:i[u]=C;continue;case 9:y=g+C>>1,S=y;break;case 10:g=y,S=C;break;case 11:S=g+C>>1;break;case 12:g=S,y=C;break;case 13:y=g+C>>1;break;case 14:g=y+S>>1;break}g=r.dmin+r.dmul*g,y=r.dmin+r.dmul*y,S=r.dmin+r.dmul*S,C=r.dmin+r.dmul*C;let P=V(g,y,m),M=V(S,C,m);i[u]=(V(P,M,c)-r.dmin)/r.dmul,i[u]===0&&(i[u]=1)}}return o}function V(r,e,t){let n=((e-r)%360+540)%360-180;return(r+n*t+360)%360}function Ve(r,e){if(!e)return r;let t=.9999999/Math.pow(2,e.z),n=e.x*256*t,s=e.y*256*t,o={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:i}=o;for(let l=-1,u=0;l<=256;l++){let f=s+l*t,b=Math.floor(f),c=f-b;for(let a=-1;a<=256;a++,u++){let d=n+a*t,h=Math.floor(d),m=d-h,p=h+1+(b+1)*258,g=r.raw[p],y=r.raw[p+1],S=r.raw[p+258],C=r.raw[p+258+1];switch((g?1:0)|(y?2:0)|(S?4:0)|(C?8:0)){case 7:i[u]=m+c<1?m*(y-g)+c*(S-g)+g:0;continue;case 14:i[u]=m+c<1?0:m*(C-S)+c*(C-y)+y+S-C;continue;case 11:i[u]=c<m?(1-m)*(g-y)+c*(C-y)+y:0;continue;case 13:i[u]=c<m?0:(1-m)*(S-C)+c*(S-g)+g+C-S;continue;case 15:i[u]=m+c<1?m*(y-g)+c*(S-g)+g:m*(C-S)+c*(C-y)+y+S-C;continue;default:i[u]=0}}}return o}function Xe(r,e,t){let n=t==="land"?1:0;for(let s=3,o=0;o<256;o++)for(let i=0;i<256;i++,s+=4){let l=e.data[s]?1:0;n^l&&(r.raw[(o+1)*258+(i+1)]=0)}return r}function $e(r){let[e,t]=pe(r.x,r.y),[n,s]=q(e,t,r.z),[o,i]=q(e+256,t+256,r.z);return{west:n,north:s,east:o,south:i}}function ve({layer:r,coords:e,done:t}){let n=L("div","leaflet-tile s-tile");return n.wxtile=new Le({layer:r,coords:e,tileEl:n}),n.wxtile.load().then(s=>{s.draw(),t()}),n}var Le=class{constructor({layer:e,coords:t,tileEl:n}){this.data=[];this.sLines=[];this.coords=t,this.layer=e,this.canvasFill=L("canvas","s-tile canvas-fill",n),this.canvasSlines=L("canvas","s-tile canvas-slines",n),this.canvasVector=this.canvasFill,this.canvasFill.width=this.canvasFill.height=this.canvasSlines.width=this.canvasSlines.height=256;function s(o){let i=o.getContext("2d");if(!i)throw"error";return i}this.canvasFillCtx=s(this.canvasFill),this.imData=this.canvasFillCtx.createImageData(256,256),this.canvasSlinesCtx=s(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasSlinesCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVector(),this._drawDegree(),this._drawStaticSlines())}clearSLinesCanvas(){this.canvasSlinesCtx.clearRect(0,0,256,256)}drawSLines(e){if(this.sLines.length===0)return;let t=this.canvasSlinesCtx;if(t.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.sLines=[];return}let n=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let s=0;s<this.sLines.length;++s){let o=this.sLines[s],i=o.length-1,l=(e+(1+o[0].x)*(1+o[0].y))%30;for(let u=0;u<i;++u){let f=o[u],b=o[u+1],c=1-(l-u)/i;(c<0||c>1)&&(c=0);let a=(~~(c*255)).toString(16);t.strokeStyle=n+(a.length<2?"0"+a:a);let d=1+~~((1.2-c)*5);t.lineWidth=d,t.beginPath(),t.moveTo(f.x,f.y),t.lineTo(b.x,b.y),t.stroke()}}}getData({x:e,y:t}){if(!this.data.length)return;let n=this.data[0].raw[(t+1)*258+(e+1)];return{raw:n,data:this.data[0].dmin+this.data[0].dmul*n}}async load(){var c;let{coords:e,layer:t}=this,{boundaries:n}=t.state.meta,s=this.layer.style.mask;var o;if((s==="land"||s==="sea")&&(o=we(e),s===o))return this.data=[],this.sLines=[],this;if(n==null?void 0:n.boundaries180){let a=$e(e),d=h=>!(a.west>h.east||h.west>a.east||a.south>h.north||h.south>a.north);if(!n.boundaries180.some(d))return this.data=[],this.sLines=[],this}let{upCoords:i,subCoords:l}=this._splitCoords(e),u=this._coordsToURLs(i),f;try{f=await Promise.all(u.map(t.loadData))}catch(a){return this}let b=((c=t.state)==null?void 0:c.units)==="degree"?Ke:Ve;if(this.data=f.map(a=>b(de(a,this.layer.style.blurRadius),l)),this.layer.vector&&this._vectorPrepare(),s&&o===v.Mixed){let a=t.state.maskServerURI.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));try{let d=await t.loadMask(a);Xe(this.data[0],d,s)}catch(d){this.layer.style.mask=void 0,x("Can't load Mask. Turned off")}}return this.layer.vector&&this._createSLines(),this}_splitCoords(e){let t=e.z-this.layer.state.meta.maxZoom;if(t<=0)return{upCoords:e};let n={x:e.x>>>t,y:e.y>>>t,z:this.layer.state.meta.maxZoom},s={x:e.x&(1<<t)-1,y:e.y&(1<<t)-1,z:t};return{upCoords:n,subCoords:s}}_coordsToURLs(e){let t=this.layer.state.baseURL.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));return this.layer.dataSource.variables.map(n=>t.replace("{var}",n))}_vectorPrepare(){if(this.data.length!==2)throw"this.data !== 2";this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[e,t,n]=this.data;e.dmax=1.42*Math.max(-t.dmin,t.dmax,-n.dmin,n.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let s=0;s<258*258;++s){if(!t.raw[s]||!n.raw[s]){e.raw[s]=0;continue}let o=t.dmin+t.dmul*t.raw[s],i=n.dmin+n.dmul*n.raw[s];e.raw[s]=Math.sqrt(i*i+o*o)/e.dmul}}_drawFillAndIsolines(){let{imData:e}=this,{canvasFillCtx:t}=this,n=new Uint32Array(e.data.buffer),{raw:s}=this.data[0],{clut:o,style:i}=this.layer,{levelIndex:l,colorsI:u}=o;if(i.fill!=="none"){let b=u;for(let c=0,a=0,d=259;c<256;++c,d+=2)for(let h=0;h<256;++h,++a,++d)n[a]=b[s[d]]}else n.fill(0);let f=[];if(i.isolineColor!=="none"){let b=i.isolineColor[0]==="#"?T(i.isolineColor):0;for(let c=0,a=0;c<256;c+=1)for(let d=0;d<256;d+=1){let h=(c+1)*258+(d+1),m=s[h],p=s[h+1],g=s[h+258];if(!m||!p||!g)continue;let y=l[m],S=l[p],C=l[g];if(y!==S||y!==C){let B=Math.max(y,S,C),P=Math.max(m,p,g),M=c*256+d;switch(i.isolineColor){case"inverted":n[M]=~u[P]|4278190080;break;case"fill":n[M]=u[P]|4278190080;break;default:n[M]=b;break}i.isolineText&&!(++a%255)&&d>20&&d<235&&c>20&&c<235&&f.push({x:d,y:c,d:m,dr:p,db:g,mli:B})}}}if(t.putImageData(e,0,0),!f.length){t.font="1.1em Sans-serif",t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";for(let{x:b,y:c,d:a,dr:d,db:h,mli:m}of f){let p=this.layer.clut.ticks[m].dataString,g=Math.atan2(a-d,h-a);t.save(),t.translate(b,c),t.rotate(g<-1.57||g>1.57?g+3.14:g),t.strokeText(p,0,0),t.fillText(p,0,0),t.restore()}}}_drawStaticSlines(){if(!this.sLines.length||!this.layer.style.streamLineStatic)return;let{canvasSlinesCtx:e}=this;if(this.layer.style.streamLineColor==="none"){this.sLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let t=this.sLines.length;t--;){let n=this.sLines[t];for(let s=0;s<n.length-1;++s){let o=n[s],i=n[s+1];e.moveTo(o.x,o.y),e.lineTo(i.x,i.y)}}e.stroke()}_drawVector(){if(!this.layer.vector||!this.layer.clut.DataToKnots||!this.layer.style.vectorColor||this.layer.style.vectorColor==="none"||!this.layer.style.vectorType||this.layer.style.vectorType==="none")return;if(this.data.length!==3)throw"this.data.length !== 3";let[e,t,n]=this.data,{canvasVectorCtx:s}=this;switch(this.layer.style.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=this.layer.style.vectorType}s.textAlign="center",s.textBaseline="middle";let o=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0,i=32;for(let l=i/2;l<256;l+=i)for(let u=i/2;u<256;u+=i){let f=u+1+(l+1)*258;if(!e.raw[f])continue;let b=Math.atan2(t.dmin+t.raw[f]*t.dmul,n.dmin+n.raw[f]*n.dmul),c=e.dmin+e.raw[f]*e.dmul,a=this.layer.dataSource.variables[0].includes("current")?5:.2,d=Math.min(this.layer.clut.DataToKnots(c)*a,25)+65,h=String.fromCharCode(d);switch(this.layer.style.vectorColor){case"inverted":s.fillStyle=w(~this.layer.clut.colorsI[e.raw[f]]);break;case"fill":s.fillStyle=w(this.layer.clut.colorsI[e.raw[f]]);break;default:s.fillStyle=this.layer.style.vectorColor;break}s.save(),s.translate(u,l),s.rotate(b+o),s.fillText(h,0,0),s.restore()}}_drawDegree(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:e}=this,t=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle";let n=this.data[0],s="L",o=32;for(let i=o/2;i<256;i+=o)for(let l=o/2;l<256;l+=o){let u=l+1+(i+1)*258;if(!n.raw[u])continue;let b=(n.dmin+n.raw[u]*n.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=w(~this.layer.clut.colorsI[n.raw[u]]);break;case"fill":e.fillStyle=w(this.layer.clut.colorsI[n.raw[u]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(l,i),e.rotate(b+t),e.fillText(s,0,0),e.restore()}}_createSLines(){if(this.data.length!==3)throw"this.data.length !== 3";if(!this.layer.style.streamLineColor||this.layer.style.streamLineColor==="none")return;let e=this.layer.style.streamLineSpeedFactor||1;this.sLines=[];let[t,n,s]=this.data,o=Math.max(this.coords.z-this.layer.state.meta.maxZoom,0),i=Math.min(2**(o+5),128),l=~~(120+o*60);for(let u=0;u<=256;u+=i)for(let f=0;f<=256;f+=i){if(!t.raw[1+f+(1+u)*258])continue;let b=[],c=f,a=u;for(let d=0;d<=l&&c>=0&&c<=256&&a>=0&&a<=256;d++){!(d%(l/6))&&b.push({x:~~c,y:~~a});let h=~~c+1+(~~a+1)*258;if(!t.raw[h])break;c+=e*(n.dmin+n.raw[h]*n.dmul)/t.dmax,a-=e*(s.dmin+s.raw[h]*s.dmul)/t.dmax}c=f,a=u;for(let d=1;d<=l&&c>=0&&c<=256&&a>=0&&a<=256;d++){!(d%(l/6))&&b.unshift({x:~~c,y:~~a});let h=~~c+1+(~~a+1)*258;if(!t.raw[h])break;c-=e*(n.dmin+n.raw[h]*n.dmul)/t.dmax,a+=e*(s.dmin+s.raw[h]*s.dmul)/t.dmax}b.length>2&&this.sLines.push(b)}}};var Me="setup not complete",Je=fe(new AbortController),_=class extends De.default.GridLayer{constructor({dataSource:e,options:t,lazy:n}){super(t);this.styles=R();this.style=Object.assign({},this.styles.base);this.loadData=z();this.loadMask=Je;this.error=Me;this.vector=!1;this.clut=new E(this.style,"",[0,2],!1);this.animation=!1;this.animationRedrawID=0;this.animFrame=0;this.oldMaxZoom=0;if(x("Creating a WxTilex layer:",e.name,". Params:",JSON.stringify({dataSource:e,options:t})),!e||!e.ext||!e.dataset||!e.name||!e.serverURI||!e.styleName||!Array.isArray(e.variables))throw x("dataSource is wrong!"),"dataSource is wrong!";this.dataSource=e,this.state={maskServerURI:e.maskServerURI||e.serverURI.replace(/\/data\/?/i,"/mask/{z}/{x}/{y}"),units:"undefined",baseURL:"undefined",meta:{maxZoom:0,times:["undefined"],variables:["undefined"],variablesMeta:{}},instance:"undefined",minmax:[[0,1]],originURI:"undefined",time:"undefined"},this.setupCompletePromise=new Promise(s=>{let o=()=>{x("Setup:",e.name),this.on("remove",this._onRemoveLayer,this),this.on("add",this._onAddLayer,this),this._setUpDataSet(e).then(i=>{x("Setup complete:",this.dataSource.name,". Result:",i),this._map&&n&&this._onAddLayer(),this.fire("setupcomplete",{layer:this}),s(i)})};n?this.once("add",o):o()})}createTile(e,t){return this.error&&this.error!==Me?(setTimeout(t),Object.assign(L("div","error-tile"),{innerHTML:this.error})):this.state.baseURL==="undefined"?(setTimeout(t),L("div","error-tile")):ve({layer:this,coords:e,done:t})}getSetupCompletePromise(){return this.setupCompletePromise}getTile(e){if(!this._map||this.error)return;let t=this._map.getZoom(),{x:n,y:s}=this._map.project(e,t),o={x:~~(n/256),y:~~(s/256)},i=this._getCachedTile(o.x,o.y,t);if(!i)return;let l={x:~~(n-o.x*256),y:~~(s-o.y*256)},u=i.getData(l);if(!u)return;let{raw:f,data:b}=u,c=this.clut.colorsI[f],a=w(c),d=this.clut.DataToStyle(b);return{tile:i,data:b,raw:f,rgba:c,hexColor:a,inStyleUnits:d,tilePoint:l,units:this.style.units}}setStyle(e){if(x("setStyle(",e,") for ",this.dataSource.name),this.error){x("setStyle: failed: "+this.error);return}if(!(this.dataSource.styleName===e&&e!=="custom")){if(e&&(this.dataSource.styleName=e),e==="custom"&&this.styles.custom){(!this.styles.custom.parent||!(this.styles.custom.parent in this.styles))&&(this.styles.custom.parent="base");let t=this.styles[this.styles.custom.parent];this.styles.custom=Object.assign(Object.assign({},t),this.styles.custom)}this.dataSource.styleName in this.styles?Array.isArray(this.styles[this.dataSource.styleName])&&(this.dataSource.styleName+="[0]"):(x(`cant find the style (${this.dataSource.styleName})`),this.dataSource.styleName+="[0]",this.dataSource.styleName in this.styles||(x(`cant find the style (${this.dataSource.styleName}), default is used`),this.dataSource.styleName="base"));try{let t=this.styles[this.dataSource.styleName];this.style=Object.assign({},t);let n=this.style.streamLineColor;n!=="none"&&n.length<7&&(this.style.streamLineColor="#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]);let s=this.state.minmax[0];this.clut=new E(this.style,this.state.units,s,this.vector)}catch(t){let n="setStyle: impossible error in RawCLUT: "+t;throw x(n),n}e&&(this._checkAndStartSlinesAnimation(),this._reloadTiles()),x("setStyle(",e,'): "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete."),this.fire("setstyle",{layer:this})}}getStyle(){return this.dataSource.styleName}getStyleName(){return this.style.name}setTime(e){if(x("setTime: "+e+" for "+this.dataSource.name+" start"),this.error)return x("setTime: failed: "+this.error),Promise.resolve([]);let t=be(this.state.meta.times,e);if(this.state.time===t)return x("setTime: the same time - skipped"),Promise.resolve([]);if(this.state.time=t,this.state.baseURL=this.state.originURI+this.state.instance+`{var}/${this.state.time}/{z}/{x}/{y}.${this.dataSource.ext}`,this.fire("settime",{layer:this,layerTime:t}),x("setTime: "+t+" for "+this.dataSource.name+" complete"),!this._tiles)return Promise.resolve([]);let n=this._reloadTiles(!1);return n.then(()=>{var o;let s=Object.values(this._tiles);for(let i of s){let l=(o=i.el)==null?void 0:o.wxtile;if(l==null?void 0:l.data.length){let[u,f]=this.state.minmax[0],{dmin:b,dmax:c}=l.data[0];(Math.abs(b-u)>.01||Math.abs(c-f)>.01)&&(this.state.minmax=l.data.map(a=>[a.dmin,a.dmax]),this.setStyle(void 0));break}}this._redrawTiles()}),n}getTime(){return this.error?(x("getTime: failed: "+this.error),this.error):this.state.time}getTimes(){return x("getTimes"),this.error?(x("getTimes: failed: "+this.error),[]):this.state.meta.times}async checkDataChanged(){if(x("checkDataChanged"),this.error)return x("checkDataChanged: failed: "+this.error),!1;let e=await A(this.state.originURI+"instances.json"),t=e[e.length-1]+"/";if(this.state.instance!==t)return!0;let n=await A(this.state.originURI+t+"meta.json");return this.state.meta.times.toString()!==n.times.toString()}reloadData(){return x("reloadData"),this._setUpDataSet(void 0)}getLegendData(e){return x("getLegendData"),(this.error||!this.clut)&&x("getLegendData: failed. "+this.dataSource.name+" : "+this.error),G(e,this.style)}setTimeAnimationMode(e=2){x("setTimeAnimationMode"),this.oldMaxZoom=this.state.meta.maxZoom;let t=this._map.getZoom(),s=(t<this.oldMaxZoom?t:this.oldMaxZoom)-e;this.state.meta.maxZoom=s<0?0:s}unsetTimeAnimationMode(){return x("unsetTimeAnimationMode"),this.oldMaxZoom&&(this.state.meta.maxZoom=this.oldMaxZoom),this._reloadTiles()}getMinMax(){let[e,t]=this.state.minmax[0];return{min:e,max:t}}setAnimation(e){return x("setAnimation"),this.animation=e,this._checkAndStartSlinesAnimation(),this.animation}_getCachedTile(e,t,n){var s,o;return(o=(s=this._tiles[`${e}:${t}:${n}`])==null?void 0:s.el)==null?void 0:o.wxtile}_ForEachTile(e){var n;let t=[];for(let s in this._tiles){let o=(n=this._tiles[s].el)==null?void 0:n.wxtile,i=o&&e(o);i&&t.push(i)}return t}async _setUpDataSet(e){e&&(this.dataSource=e),this._stopLoadingResetLoadDataFunc(),this.state.originURI=this.dataSource.serverURI+"/"+this.dataSource.dataset+"/";try{let t=await A(this.state.originURI+"instances.json");this.state.instance=t[t.length-1]+"/"}catch(t){return this.error=this.dataSource.name+": load instances.json error: "+t,x(this.error),!1}try{let t=this.state.originURI+this.state.instance+"meta.json";this.state.meta=await A(t)}catch(t){return this.error=this.dataSource.name+": load meta.json error: "+t,x(this.error),!1}if(this.vector=this.dataSource.variables.length===2,this.animation=this.vector,this.state.units=this.state.meta.variablesMeta[this.dataSource.variables[0]].units,this.state.minmax=this.dataSource.variables.map(t=>[this.state.meta.variablesMeta[t].min,this.state.meta.variablesMeta[t].max]),this.vector){let[[t,n],[s,o]]=this.state.minmax;this.state.minmax.unshift([0,1.42*Math.max(-t,n,-s,o)])}return this.error=null,e&&(this.setStyle(void 0),await this.setTime(new Date)),!0}_checkZoom(){var e;((e=this._map)==null?void 0:e.getZoom())>this.state.meta.maxZoom||this._stopLoadingResetLoadDataFunc()}_onAddLayer(){var e;x("onadd:",this.dataSource.name),(e=this._map)==null||e.on("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this.redraw(),this._checkAndStartSlinesAnimation()})}_onRemoveLayer(){var e;x("onremove:",this.dataSource.name),(e=this._map)==null||e.off("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this._stopLoadingResetLoadDataFunc(),this._stopSlinesAnimation()})}_stopLoadingResetLoadDataFunc(){this.loadData.controllerHolder.controller.abort(),this.loadData=z()}_checkAndStartSlinesAnimation(){if(this.animFrame||!this.animation||!this.vector||!this.style.streamLineColor||this.style.streamLineColor==="none")return;let e=t=>{if(!this.animation||this.style.streamLineStatic){this._stopSlinesAnimation();return}this._ForEachTile(n=>n.drawSLines(t)),this.animFrame=requestAnimationFrame(e)};e(0)}_stopSlinesAnimation(){cancelAnimationFrame(this.animFrame),this._ForEachTile(e=>e.clearSLinesCanvas()),this.animFrame=0}_redrawTiles(){this.animationRedrawID===0&&(this.animationRedrawID=requestAnimationFrame(()=>{x("_redrawTiles: requestAnimationFrame: "+this.dataSource.name),this._ForEachTile(e=>e.draw()),this.animationRedrawID=0}))}_reloadTiles(e=!0){x("_reloadTiles: start - "+this.dataSource.name),this.loadData.controllerHolder.controller.abort(),this.loadData.controllerHolder.controller=new AbortController;let t=this._ForEachTile(o=>o.load()),n=Promise.all(t),{controller:s}=this.loadData.controllerHolder;return e&&n.then(()=>s.signal.aborted||this._redrawTiles()),x("_reloadTiles: finished - "+this.dataSource.name),n}};function ke(r){return new _(r)}var X=class extends N.default.Control{constructor(e){super(e);this.URI=e.URI}onAdd(){let e=document.createElement("img");return e.src=this.URI,e.className="wxtiles-logo",e}};function Ye(r){return x("Add watermark:",JSON.stringify(r)),new X(r)}var $=class extends N.default.GridLayer{createTile(e){let t=document.createElement("div");return t.innerHTML=[e.x,e.y,e.z].join(", "),t.style.outline="1px solid red",t}};function et(){return x("Add WxDebugCoordsLayer:"),new $().setZIndex(1e3)}function tt(r,e){return N.default.layerGroup(r.map(ke),e)}return rt;})();
|
|
1
|
+
var wxtilesjs=(()=>{var Ae=Object.create;var k=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames,J=Object.getOwnPropertySymbols,Pe=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty,Ue=Object.prototype.propertyIsEnumerable;var ee=(r,e,t)=>e in r?k(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,te=(r,e)=>{for(var t in e||(e={}))Y.call(e,t)&&ee(r,t,e[t]);if(J)for(var t of J(e))Ue.call(e,t)&&ee(r,t,e[t]);return r};var re=r=>k(r,"__esModule",{value:!0});var nt=typeof require!="undefined"?require:r=>{throw new Error('Dynamic require of "'+r+'" is not supported')};var Re=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),We=(r,e)=>{re(r);for(var t in e)k(r,t,{get:e[t],enumerable:!0})},Fe=(r,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of _e(e))!Y.call(r,n)&&n!=="default"&&k(r,n,{get:()=>e[n],enumerable:!(t=Ie(e,n))||t.enumerable});return r},ne=r=>Fe(re(k(r!=null?Ae(Pe(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var Z=Re((at,se)=>{se.exports=window.L});var rt={};We(rt,{CreateWxDebugCoordsLayer:()=>et,CreateWxTilesGroupLayer:()=>tt,CreateWxTilesLayer:()=>ke,CreateWxTilesWatermark:()=>Ye,LoadQTree:()=>Se,WxDebugLayer:()=>$,WxGetColorSchemes:()=>W,WxGetColorStyles:()=>R,WxTilesLayer:()=>_,WxTilesLibSetup:()=>ce,WxTilesLogging:()=>xe,WxWatermark:()=>X});var N=ne(Z());var oe={comment1:["'degC': ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["'hPa': ['Pa', 1000]' -> hPa = Pa * 1000 + 0 (0 - could be ommited)",0],K:["K",1],kelvin:["K",1],F:["K",.5555555555,255.372222222],C:["K",1,273.15],degC:["K",1,273.15],"kg/m^2/s":["kg/m^2/s",1],"Kg/m^2/s":["kg/m^2/s",1],"Kg m**-2 s**-1":["kg/m^2/s",1],"Kg m^-2 s^-1":["kg/m^2/s",1],"Kg m^{-2} s^-1":["kg/m^2/s",1],"mm/h":["kg/m^2/s",.00027777777],"mm/hr":["kg/m^2/s",.00027777777],"W/m^2":["W/m^2",1],"W m^-2":["W/m^2",1],"W m^{-2}":["W/m^2",1],"W/m**2":["W/m^2",1],"W m**-2":["W/m^2",1],"m/s":["m/s",1],"m s**-1":["m/s",1],"m s^-1":["m/s",1],"m.s^{-1}":["m/s",1],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["m/s",.27777777777],"km h^-1":["m/s",.27777777777],"km h**-1":["m/s",.27777777777],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],inch:["m",.0254],Pa:["Pa",1],hPa:["Pa",100],degree:["degree",1],radian:["degree",57.3],"mg/m^3":["mg/m^3",1],"mg m^-3":["mg/m^3",1],"mg.m^-3":["mg/m^3",1],"%":["%",1],"(0 - 1)":["%",100]};var ie={none:["#00000000","#00000000"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbowzerro:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow2:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebirdzerro:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bw:["#000000ff","#ffffffff"],wb:["#ffffffff","#000000ff"],redish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]};var U={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"}};var j,ae,le;function ce({colorStyles:r={},units:e={},colorSchemes:t={}}={}){x("WxTile lib setup: start"),j=Object.assign({},oe,e),ae=Object.assign({},t,ie);let n=Object.assign({},r,U);le=Ee(n),x("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),x("WxTile lib setup is done.")}function R(){return le}function W(){return ae}function F(r,e,t){let n=t?Object.assign({},j,t):j;if(!n||!r||!e||r===e||!n[r]||!n[e]||n[r][0]!==n[e][0]){x(r===e?"Trivial converter:":"Inconvertible units. Default converter is used:",r," -> ",e);let i=l=>l;return i.trivial=!0,i}x("Converter: From:",r," To:",e);let s=n[r][1]/n[e][1],o=(n[r][2]||0)/n[e][1]-(n[e][2]||0)/n[e][1];return o?i=>s*i+o:i=>s*i}function Ee(r){let e=Object.assign({},U);for(let s in r){let o=r[s];if(Array.isArray(o))for(let i=0;i<o.length;++i)e[s+"["+i+"]"]=Object.assign({},o[i]);else e[s]=Object.assign({},o)}let t=(s,o)=>{if(o==="base")return U.base;let i=s[o];(!i.parent||!(i.parent in s))&&(i.parent="base");let l=t(s,i.parent);return Object.assign(i,Object.assign({},l,i,{parent:"base"}))},n={};for(let s in e)n[s]=t(e,s);return n}function me(r){let e=new Map;return t=>{let n=e.get(t);if(n===void 0){let s=r(t);return s instanceof Promise?s.then(()=>e.set(t,s)).catch(o=>{o instanceof DOMException||e.set(t,s)}):e.set(t,s),s}return n}}async function He(r,e){let t=new Image;return t.src=URL.createObjectURL(await(await fetch(r,e.controller)).blob()),await t.decode(),URL.revokeObjectURL(t.src),t}function Ne(r){let{width:e,height:t}=r,n=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d");if(!n)throw"catastrophe";return n.drawImage(r,0,0),n.getImageData(0,0,e,t)}async function ue(r,e){return Ne(await He(r,e))}function Be(r,e){let t=n=>{let s=new Uint16Array(n.data.buffer),o=new Uint16Array(s.length/2);for(let a=0;a<o.length;a++)o[a]=s[a*2];let i=new Uint8Array(n.data.buffer);for(let a=0;a<8;++a)i[a]=i[a*4+2];let l=new DataView(n.data.buffer),u=l.getFloat32(0,!0),f=l.getFloat32(4,!0),b=(f-u)/65535,c=Ze(o);return{raw:o,dmin:u,dmax:f,dmul:b,integral:c,radius:0}};return ue(r,e).then(t)}function z(){let r={controller:new AbortController},e=me(t=>Be(t,r));return e.controllerHolder=r,e}function fe(r){let e={controller:r},t=me(n=>ue(n,e));return t.controllerHolder=e,t}function Ze(r){let e=new Uint32Array(258*258),t=new Uint32Array(258*258);e[0]=r[0],t[0]=r[0]===0?0:1;for(let n=1;n<258;++n)e[n]=r[n]+e[n-1],e[258*n]=r[258*n]+e[258*n-258],t[n]=(r[n]===0?0:1)+t[n-1],t[258*n]=(r[258*n]===0?0:1)+t[258*n-258];for(let n=1,s=259;n<258;++n,++s)for(let o=1;o<258;++o,++s)e[s]=r[s]+e[s-258]+e[s-1]-e[s-258-1],t[s]=(r[s]===0?0:1)+t[s-258]+t[s-1]-t[s-258-1];return{integral:e,integralNZ:t}}function de(r,e){if(e<0||e===r.radius)return r;r.radius=e;let t=258,{integral:n,integralNZ:s}=r.integral;for(let o=1;o<t;o++)for(let i=1;i<t;i++){if(!r.raw[t*o+i])continue;let l=Math.min(e,i-1,t-1-i),u=Math.min(e,o-1,t-1-o),f=t*(o-u-1)+i,b=t*(o+u)+i,c=s[f-l-1],a=s[f+l],d=s[b-l-1],h=s[b+l],m=c+h-a-d,p=n[f-l-1],g=n[f+l],y=n[b-l-1],S=n[b+l],C=p+S-g-y;r.raw[o*t+i]=C/m}return r}function w(r){let e=r>>0&255,t=r>>8&255,n=r>>16&255,s=e.toString(16),o=t.toString(16),i=n.toString(16);return s=s.length===2?s:"0"+s,o=o.length===2?o:"0"+o,i=i.length===2?i:"0"+i,"#"+s+o+i}function T(r){if(r[0]==="#"){if(r.length===4)return+("0xff"+r[3]+r[3]+r[2]+r[2]+r[1]+r[1]);if(r.length===7)return+("0xff"+r[5]+r[6]+r[3]+r[4]+r[1]+r[2]);if(r.length===9)return+("0x"+r[7]+r[8]+r[5]+r[6]+r[3]+r[4]+r[1]+r[2])}return x("wrong color format",r),0}async function A(r,e){return(await fetch(r,e)).json()}function L(r,e="",t){var s;let n=document.createElement(r);return n.className=e,t&&((s=t.appendChild)==null||s.call(t,n)),n}function O(r,e,t){let n=r>>0&255,s=r>>8&255,o=r>>16&255,i=r>>>24,l=e>>0&255,u=e>>8&255,f=e>>16&255,b=e>>>24,c=n+t*(l-n),a=s+t*(u-s),d=o+t*(f-o),h=i+t*(b-i);return c|a<<8|d<<16|h<<24}function he(r,e,t){let n=[];for(let s=0;s<t;++s)n.push(s*(e-r)/(t-1)+r);return n}function be(r,e){let t=typeof e=="number"?e:typeof e=="string"?new Date(e).getTime():e.getTime();return r.find(n=>new Date(n).getTime()>=t)||r[r.length-1]}var ge=!1;function xe(r){console.log(r?"Logging on":"Logging off"),ge=r}function x(...r){ge&&console.trace(...r)}var De=ne(Z());function je(r,e,t){return r>t?t:r<e?e:r}var E=class{constructor(e,t,[n,s],o){let i=s-n;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let l=[];this.DataToStyle=F(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),o&&(this.DataToKnots=F(t,"knot"));let u=F(e.units,t,e.extraUnits),f=m=>~~(65535*je((u(m)-n)/(s-n),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((m,p)=>m[0]<p[0]?-1:m[0]>p[0]?1:0);for(let[m]of e.colorMap)l.push(f(m))}else{if(e.levels||(e.levels=he(this.DataToStyle(n),this.DataToStyle(s),10)),e.levels.sort((m,p)=>m<p?-1:m>p?1:0),!e.colors){let m=W();e.colorScheme&&e.colorScheme in m?e.colors=m[e.colorScheme]:e.colors=m.wb}for(let m of e.levels)l.push(f(m))}let b=65536,c=G(b,e);this.ticks=c.ticks;let a=c.ticks[0].data,h=c.ticks[c.ticks.length-1].data-a;for(let m=0;m<65536;++m){let p=i*m/65535+n,g=this.DataToStyle(p),y=Math.round((b-1)*(g-a)/h);y<=0?this.colorsI[m]=e.showBelowMin?c.colors[0]:0:y>=b?this.colorsI[m]=e.showAboveMax?c.colors[b-1]:0:this.colorsI[m]=c.colors[y]}this.colorsI[0]=0;for(let m=0;m<l[0];++m)this.levelIndex[m]=0;for(let m=0;m<l.length-1;m++)for(let p=l[m];p<l[m+1]+1;++p)this.levelIndex[p]=m;for(let m=l[l.length-1];m<65536;++m)this.levelIndex[m]=l.length-1}};function ye(r){var t;if(r!==0&&-.1<r&&r<.1)return r.toExponential(2);let e=r.toString();return((t=e.split(".")[1])==null?void 0:t.length)>2?r.toFixed(2):e}function G(r,e){let t={size:r,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(r),ticks:[]},{colorMap:n,levels:s,colors:o}=e,i=e.fill!=="solid";if(n){let a=n[0][0],d=n[n.length-1][0]-a;for(let[h,m]of n){let p=~~((h-a)/d*(r-1)),g={data:h,dataString:ye(h),color:m,pos:p};t.ticks.push(g)}for(let h=0;h<n.length-1;h++){let m=t.ticks[h].pos,p=t.ticks[h+1].pos,g=T(n[h][1]),y=i?T(n[h+1][1]):0;for(let S=m;S<p;++S)t.colors[S]=i?O(g,y,(S-m)/(p-m)):g}return t.colors[r-1]=T(n[n.length-1][1]),t}if(!o||!s)return t;let l=0,u=0,f=-1;for(let a=0;a<r;++a){let d=a*(o.length-1)/r;f!==~~d&&(f=~~d,l=T(o[f]),u=o.length>f+1?T(o[f+1]):l),t.colors[a]=i?O(l,u,d-f):l}t.colors[r-1]=T(o[o.length-1]);let b=s[0],c=(r-1)/(s[s.length-1]-b);for(let a of s){let d=~~((a-b)*c),h={data:a,dataString:ye(a),color:w(t.colors[d]),pos:d};t.ticks.push(h)}return t}var Q=256,ze=2*Math.PI*6378137/Q,H=2*Math.PI*6378137/2;function Oe(r,e){let t=r/H*180,n=e/H*180;return n=180/Math.PI*(2*Math.atan(Math.exp(n*Math.PI/180))-Math.PI/2),[n,t]}function Ge(r,e,t){let n=Qe(t),s=r*n-H,o=e*n-H;return[s,o]}function Qe(r){return ze/Math.pow(2,r)}function q(r,e,t){let[n,s]=Oe(...Ge(r,e,t));return[s,-n]}function pe(r,e){return[r*Q,e*Q]}var qe="A".charCodeAt(0),K,D=0;async function Se(r,e){let t;try{t=await(await fetch(r,e)).json()}catch(n){console.log("Can't load QTree:",n);return}K=I(t,{pos:0}),D=Ce(K),console.log("Loaded QTree, depth:",D)}function I(r,e){let t=r.charCodeAt(e.pos)-qe;e.pos++;let n=t&1?I(r,e):null,s=t&2?I(r,e):null,o=t&4?I(r,e):null,i=t&8?I(r,e):null;return{sub:n||s||o||i?[n,s,o,i]:null}}function Ce(r){let e=0;if(r==null?void 0:r.sub){for(let t=0;t<4;t++)if(r.sub[t]!==null){let n=Ce(r.sub[t])+1;e<n&&(e=n)}}return e}var v;(function(n){n.Land="land",n.Mixed="mixed",n.Sea="sea"})(v||(v={}));function we(r){if(!D)return v.Mixed;let e=te({},r),t=!1;if(D<=r.z){t=!0;let n=r.z-D;e={x:r.x>>n,y:r.y>>n,z:D}}return Te(K,e,t)}function Te(r,e,t){if(r===null)return v.Land;if(t&&e.z===0)return v.Mixed;if(r.sub===null)return v.Sea;if(e.z===0)return v.Mixed;e.z--;let n=e.x>>e.z&1,o=(e.y>>e.z&1)<<1|n;return Te(r.sub[o],e,t)}function Ke(r,e){if(!e)return r;let t=.9999999/Math.pow(2,e.z),n=e.x*256*t,s=e.y*256*t,o={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:i}=o;for(let l=-1,u=0;l<=256;l++){let f=s+l*t,b=Math.floor(f),c=f-b;for(let a=-1;a<=256;a++,u++){let d=n+a*t,h=Math.floor(d),m=d-h,p=h+1+(b+1)*258,g=r.raw[p],y=r.raw[p+1],S=r.raw[p+258],C=r.raw[p+258+1];switch((g?1:0)|(y?2:0)|(S?4:0)|(C?8:0)){case 0:i[u]=0;continue;case 1:i[u]=g;continue;case 2:i[u]=y;continue;case 3:S=g,C=y;break;case 4:i[u]=S;continue;case 5:y=g,C=S;break;case 6:C=y+S>>1,g=C;break;case 7:C=y+S>>1;break;case 8:i[u]=C;continue;case 9:y=g+C>>1,S=y;break;case 10:g=y,S=C;break;case 11:S=g+C>>1;break;case 12:g=S,y=C;break;case 13:y=g+C>>1;break;case 14:g=y+S>>1;break}g=r.dmin+r.dmul*g,y=r.dmin+r.dmul*y,S=r.dmin+r.dmul*S,C=r.dmin+r.dmul*C;let P=V(g,y,m),M=V(S,C,m);i[u]=(V(P,M,c)-r.dmin)/r.dmul,i[u]===0&&(i[u]=1)}}return o}function V(r,e,t){let n=((e-r)%360+540)%360-180;return(r+n*t+360)%360}function Ve(r,e){if(!e)return r;let t=.9999999/Math.pow(2,e.z),n=e.x*256*t,s=e.y*256*t,o={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:i}=o;for(let l=-1,u=0;l<=256;l++){let f=s+l*t,b=Math.floor(f),c=f-b;for(let a=-1;a<=256;a++,u++){let d=n+a*t,h=Math.floor(d),m=d-h,p=h+1+(b+1)*258,g=r.raw[p],y=r.raw[p+1],S=r.raw[p+258],C=r.raw[p+258+1];switch((g?1:0)|(y?2:0)|(S?4:0)|(C?8:0)){case 7:i[u]=m+c<1?m*(y-g)+c*(S-g)+g:0;continue;case 14:i[u]=m+c<1?0:m*(C-S)+c*(C-y)+y+S-C;continue;case 11:i[u]=c<m?(1-m)*(g-y)+c*(C-y)+y:0;continue;case 13:i[u]=c<m?0:(1-m)*(S-C)+c*(S-g)+g+C-S;continue;case 15:i[u]=m+c<1?m*(y-g)+c*(S-g)+g:m*(C-S)+c*(C-y)+y+S-C;continue;default:i[u]=0}}}return o}function Xe(r,e,t){let n=t==="land"?1:0;for(let s=3,o=0;o<256;o++)for(let i=0;i<256;i++,s+=4){let l=e.data[s]?1:0;n^l&&(r.raw[(o+1)*258+(i+1)]=0)}return r}function $e(r){let[e,t]=pe(r.x,r.y),[n,s]=q(e,t,r.z),[o,i]=q(e+256,t+256,r.z);return{west:n,north:s,east:o,south:i}}function ve({layer:r,coords:e,done:t}){let n=L("div","leaflet-tile s-tile");return n.wxtile=new Le({layer:r,coords:e,tileEl:n}),n.wxtile.load().then(s=>{s.draw(),t()}),n}var Le=class{constructor({layer:e,coords:t,tileEl:n}){this.data=[];this.sLines=[];this.coords=t,this.layer=e,this.canvasFill=L("canvas","s-tile canvas-fill",n),this.canvasSlines=L("canvas","s-tile canvas-slines",n),this.canvasVector=this.canvasFill,this.canvasFill.width=this.canvasFill.height=this.canvasSlines.width=this.canvasSlines.height=256;function s(o){let i=o.getContext("2d");if(!i)throw"error";return i}this.canvasFillCtx=s(this.canvasFill),this.imData=this.canvasFillCtx.createImageData(256,256),this.canvasSlinesCtx=s(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasSlinesCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVector(),this._drawDegree(),this._drawStaticSlines())}clearSLinesCanvas(){this.canvasSlinesCtx.clearRect(0,0,256,256)}drawSLines(e){if(this.sLines.length===0)return;let t=this.canvasSlinesCtx;if(t.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.sLines=[];return}let n=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let s=0;s<this.sLines.length;++s){let o=this.sLines[s],i=o.length-1,l=(e+(1+o[0].x)*(1+o[0].y))%30;for(let u=0;u<i;++u){let f=o[u],b=o[u+1],c=1-(l-u)/i;(c<0||c>1)&&(c=0);let a=(~~(c*255)).toString(16);t.strokeStyle=n+(a.length<2?"0"+a:a);let d=1+~~((1.2-c)*5);t.lineWidth=d,t.beginPath(),t.moveTo(f.x,f.y),t.lineTo(b.x,b.y),t.stroke()}}}getData({x:e,y:t}){if(!this.data.length)return;let n=this.data[0].raw[(t+1)*258+(e+1)];return{raw:n,data:this.data[0].dmin+this.data[0].dmul*n}}async load(){var c;let{coords:e,layer:t}=this,{boundaries:n}=t.state.meta,s=this.layer.style.mask;var o;if((s==="land"||s==="sea")&&(o=we(e),s===o))return this.data=[],this.sLines=[],this;if(n==null?void 0:n.boundaries180){let a=$e(e),d=h=>!(a.west>h.east||h.west>a.east||a.south>h.north||h.south>a.north);if(!n.boundaries180.some(d))return this.data=[],this.sLines=[],this}let{upCoords:i,subCoords:l}=this._splitCoords(e),u=this._coordsToURLs(i),f;try{f=await Promise.all(u.map(t.loadData))}catch(a){return this}let b=((c=t.state)==null?void 0:c.units)==="degree"?Ke:Ve;if(this.data=f.map(a=>b(de(a,this.layer.style.blurRadius),l)),this.layer.vector&&this._vectorPrepare(),s&&o===v.Mixed){let a=t.state.maskServerURI.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));try{let d=await t.loadMask(a);Xe(this.data[0],d,s)}catch(d){this.layer.style.mask=void 0,x("Can't load Mask. Turned off")}}return this.layer.vector&&this._createSLines(),this}_splitCoords(e){let t=e.z-this.layer.state.meta.maxZoom;if(t<=0)return{upCoords:e};let n={x:e.x>>>t,y:e.y>>>t,z:this.layer.state.meta.maxZoom},s={x:e.x&(1<<t)-1,y:e.y&(1<<t)-1,z:t};return{upCoords:n,subCoords:s}}_coordsToURLs(e){let t=this.layer.state.baseURL.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));return this.layer.dataSource.variables.map(n=>t.replace("{var}",n))}_vectorPrepare(){if(this.data.length!==2)throw"this.data !== 2";this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[e,t,n]=this.data;e.dmax=1.42*Math.max(-t.dmin,t.dmax,-n.dmin,n.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let s=0;s<258*258;++s){if(!t.raw[s]||!n.raw[s]){e.raw[s]=0;continue}let o=t.dmin+t.dmul*t.raw[s],i=n.dmin+n.dmul*n.raw[s];e.raw[s]=Math.sqrt(i*i+o*o)/e.dmul}}_drawFillAndIsolines(){let{imData:e}=this,{canvasFillCtx:t}=this,n=new Uint32Array(e.data.buffer),{raw:s}=this.data[0],{clut:o,style:i}=this.layer,{levelIndex:l,colorsI:u}=o;if(i.fill!=="none"){let b=u;for(let c=0,a=0,d=259;c<256;++c,d+=2)for(let h=0;h<256;++h,++a,++d)n[a]=b[s[d]]}else n.fill(0);let f=[];if(i.isolineColor!=="none"){let b=i.isolineColor[0]==="#"?T(i.isolineColor):0;for(let c=0,a=0;c<256;c+=1)for(let d=0;d<256;d+=1){let h=(c+1)*258+(d+1),m=s[h],p=s[h+1],g=s[h+258];if(!m||!p||!g)continue;let y=l[m],S=l[p],C=l[g];if(y!==S||y!==C){let B=Math.max(y,S,C),P=Math.max(m,p,g),M=c*256+d;switch(i.isolineColor){case"inverted":n[M]=~u[P]|4278190080;break;case"fill":n[M]=u[P]|4278190080;break;default:n[M]=b;break}i.isolineText&&!(++a%255)&&d>20&&d<235&&c>20&&c<235&&f.push({x:d,y:c,d:m,dr:p,db:g,mli:B})}}}if(t.putImageData(e,0,0),f.length){t.font="1.1em Sans-serif",t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";for(let{x:b,y:c,d:a,dr:d,db:h,mli:m}of f){let p=this.layer.clut.ticks[m].dataString,g=Math.atan2(a-d,h-a);t.save(),t.translate(b,c),t.rotate(g<-1.57||g>1.57?g+3.14:g),t.strokeText(p,0,0),t.fillText(p,0,0),t.restore()}}}_drawStaticSlines(){if(!this.sLines.length||!this.layer.style.streamLineStatic)return;let{canvasSlinesCtx:e}=this;if(this.layer.style.streamLineColor==="none"){this.sLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let t=this.sLines.length;t--;){let n=this.sLines[t];for(let s=0;s<n.length-1;++s){let o=n[s],i=n[s+1];e.moveTo(o.x,o.y),e.lineTo(i.x,i.y)}}e.stroke()}_drawVector(){if(!this.layer.vector||!this.layer.clut.DataToKnots||!this.layer.style.vectorColor||this.layer.style.vectorColor==="none"||!this.layer.style.vectorType||this.layer.style.vectorType==="none")return;if(this.data.length!==3)throw"this.data.length !== 3";let[e,t,n]=this.data,{canvasVectorCtx:s}=this;switch(this.layer.style.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=this.layer.style.vectorType}s.textAlign="center",s.textBaseline="middle";let o=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0,i=32;for(let l=i/2;l<256;l+=i)for(let u=i/2;u<256;u+=i){let f=u+1+(l+1)*258;if(!e.raw[f])continue;let b=Math.atan2(t.dmin+t.raw[f]*t.dmul,n.dmin+n.raw[f]*n.dmul),c=e.dmin+e.raw[f]*e.dmul,a=this.layer.dataSource.variables[0].includes("current")?5:.2,d=Math.min(this.layer.clut.DataToKnots(c)*a,25)+65,h=String.fromCharCode(d);switch(this.layer.style.vectorColor){case"inverted":s.fillStyle=w(~this.layer.clut.colorsI[e.raw[f]]);break;case"fill":s.fillStyle=w(this.layer.clut.colorsI[e.raw[f]]);break;default:s.fillStyle=this.layer.style.vectorColor;break}s.save(),s.translate(u,l),s.rotate(b+o),s.fillText(h,0,0),s.restore()}}_drawDegree(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:e}=this,t=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle";let n=this.data[0],s="L",o=32;for(let i=o/2;i<256;i+=o)for(let l=o/2;l<256;l+=o){let u=l+1+(i+1)*258;if(!n.raw[u])continue;let b=(n.dmin+n.raw[u]*n.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=w(~this.layer.clut.colorsI[n.raw[u]]);break;case"fill":e.fillStyle=w(this.layer.clut.colorsI[n.raw[u]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(l,i),e.rotate(b+t),e.fillText(s,0,0),e.restore()}}_createSLines(){if(this.data.length!==3)throw"this.data.length !== 3";if(!this.layer.style.streamLineColor||this.layer.style.streamLineColor==="none")return;let e=this.layer.style.streamLineSpeedFactor||1;this.sLines=[];let[t,n,s]=this.data,o=Math.max(this.coords.z-this.layer.state.meta.maxZoom,0),i=Math.min(2**(o+5),128),l=~~(120+o*60);for(let u=0;u<=256;u+=i)for(let f=0;f<=256;f+=i){if(!t.raw[1+f+(1+u)*258])continue;let b=[],c=f,a=u;for(let d=0;d<=l&&c>=0&&c<=256&&a>=0&&a<=256;d++){!(d%(l/6))&&b.push({x:~~c,y:~~a});let h=~~c+1+(~~a+1)*258;if(!t.raw[h])break;c+=e*(n.dmin+n.raw[h]*n.dmul)/t.dmax,a-=e*(s.dmin+s.raw[h]*s.dmul)/t.dmax}c=f,a=u;for(let d=1;d<=l&&c>=0&&c<=256&&a>=0&&a<=256;d++){!(d%(l/6))&&b.unshift({x:~~c,y:~~a});let h=~~c+1+(~~a+1)*258;if(!t.raw[h])break;c-=e*(n.dmin+n.raw[h]*n.dmul)/t.dmax,a+=e*(s.dmin+s.raw[h]*s.dmul)/t.dmax}b.length>2&&this.sLines.push(b)}}};var Me="setup not complete",Je=fe(new AbortController),_=class extends De.default.GridLayer{constructor({dataSource:e,options:t,lazy:n}){super(t);this.styles=R();this.style=Object.assign({},this.styles.base);this.loadData=z();this.loadMask=Je;this.error=Me;this.vector=!1;this.clut=new E(this.style,"",[0,2],!1);this.animation=!1;this.animationRedrawID=0;this.animFrame=0;this.oldMaxZoom=0;if(x("Creating a WxTilex layer:",e.name,". Params:",JSON.stringify({dataSource:e,options:t})),!e||!e.ext||!e.dataset||!e.name||!e.serverURI||!e.styleName||!Array.isArray(e.variables))throw x("dataSource is wrong!"),"dataSource is wrong!";this.dataSource=e,this.state={maskServerURI:e.maskServerURI||e.serverURI.replace(/\/data\/?/i,"/mask/{z}/{x}/{y}"),units:"undefined",baseURL:"undefined",meta:{maxZoom:0,times:["undefined"],variables:["undefined"],variablesMeta:{}},instance:"undefined",minmax:[[0,1]],originURI:"undefined",time:"undefined"},this.setupCompletePromise=new Promise(s=>{let o=()=>{x("Setup:",e.name),this.on("remove",this._onRemoveLayer,this),this.on("add",this._onAddLayer,this),this._setUpDataSet(e).then(i=>{x("Setup complete:",this.dataSource.name,". Result:",i),this._map&&n&&this._onAddLayer(),this.fire("setupcomplete",{layer:this}),s(i)})};n?this.once("add",o):o()})}createTile(e,t){return this.error&&this.error!==Me?(setTimeout(t),Object.assign(L("div","error-tile"),{innerHTML:this.error})):this.state.baseURL==="undefined"?(setTimeout(t),L("div","error-tile")):ve({layer:this,coords:e,done:t})}getSetupCompletePromise(){return this.setupCompletePromise}getTile(e){if(!this._map||this.error)return;let t=this._map.getZoom(),{x:n,y:s}=this._map.project(e,t),o={x:~~(n/256),y:~~(s/256)},i=this._getCachedTile(o.x,o.y,t);if(!i)return;let l={x:~~(n-o.x*256),y:~~(s-o.y*256)},u=i.getData(l);if(!u)return;let{raw:f,data:b}=u,c=this.clut.colorsI[f],a=w(c),d=this.clut.DataToStyle(b);return{tile:i,data:b,raw:f,rgba:c,hexColor:a,inStyleUnits:d,tilePoint:l,units:this.style.units}}setStyle(e){if(x("setStyle(",e,") for ",this.dataSource.name),this.error){x("setStyle: failed: "+this.error);return}if(!(this.dataSource.styleName===e&&e!=="custom")){if(e&&(this.dataSource.styleName=e),e==="custom"&&this.styles.custom){(!this.styles.custom.parent||!(this.styles.custom.parent in this.styles))&&(this.styles.custom.parent="base");let t=this.styles[this.styles.custom.parent];this.styles.custom=Object.assign(Object.assign({},t),this.styles.custom)}this.dataSource.styleName in this.styles?Array.isArray(this.styles[this.dataSource.styleName])&&(this.dataSource.styleName+="[0]"):(x(`cant find the style (${this.dataSource.styleName})`),this.dataSource.styleName+="[0]",this.dataSource.styleName in this.styles||(x(`cant find the style (${this.dataSource.styleName}), default is used`),this.dataSource.styleName="base"));try{let t=this.styles[this.dataSource.styleName];this.style=Object.assign({},t);let n=this.style.streamLineColor;n!=="none"&&n.length<7&&(this.style.streamLineColor="#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]);let s=this.state.minmax[0];this.clut=new E(this.style,this.state.units,s,this.vector)}catch(t){let n="setStyle: impossible error in RawCLUT: "+t;throw x(n),n}e&&(this._checkAndStartSlinesAnimation(),this._reloadTiles()),x("setStyle(",e,'): "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete."),this.fire("setstyle",{layer:this})}}getStyle(){return this.dataSource.styleName}getStyleName(){return this.style.name}setTime(e){if(x("setTime: "+e+" for "+this.dataSource.name+" start"),this.error)return x("setTime: failed: "+this.error),Promise.resolve([]);let t=be(this.state.meta.times,e);if(this.state.time===t)return x("setTime: the same time - skipped"),Promise.resolve([]);if(this.state.time=t,this.state.baseURL=this.state.originURI+this.state.instance+`{var}/${this.state.time}/{z}/{x}/{y}.${this.dataSource.ext}`,this.fire("settime",{layer:this,layerTime:t}),x("setTime: "+t+" for "+this.dataSource.name+" complete"),!this._tiles)return Promise.resolve([]);let n=this._reloadTiles(!1);return n.then(()=>{var o;let s=Object.values(this._tiles);for(let i of s){let l=(o=i.el)==null?void 0:o.wxtile;if(l==null?void 0:l.data.length){let[u,f]=this.state.minmax[0],{dmin:b,dmax:c}=l.data[0];(Math.abs(b-u)>.01||Math.abs(c-f)>.01)&&(this.state.minmax=l.data.map(a=>[a.dmin,a.dmax]),this.setStyle(void 0));break}}this._redrawTiles()}),n}getTime(){return this.error?(x("getTime: failed: "+this.error),this.error):this.state.time}getTimes(){return x("getTimes"),this.error?(x("getTimes: failed: "+this.error),[]):this.state.meta.times}async checkDataChanged(){if(x("checkDataChanged"),this.error)return x("checkDataChanged: failed: "+this.error),!1;let e=await A(this.state.originURI+"instances.json"),t=e[e.length-1]+"/";if(this.state.instance!==t)return!0;let n=await A(this.state.originURI+t+"meta.json");return this.state.meta.times.toString()!==n.times.toString()}reloadData(){return x("reloadData"),this._setUpDataSet(void 0)}getLegendData(e){return x("getLegendData"),(this.error||!this.clut)&&x("getLegendData: failed. "+this.dataSource.name+" : "+this.error),G(e,this.style)}setTimeAnimationMode(e=2){x("setTimeAnimationMode"),this.oldMaxZoom=this.state.meta.maxZoom;let t=this._map.getZoom(),s=(t<this.oldMaxZoom?t:this.oldMaxZoom)-e;this.state.meta.maxZoom=s<0?0:s}unsetTimeAnimationMode(){return x("unsetTimeAnimationMode"),this.oldMaxZoom&&(this.state.meta.maxZoom=this.oldMaxZoom),this._reloadTiles()}getMinMax(){let[e,t]=this.state.minmax[0];return{min:e,max:t}}setAnimation(e){return x("setAnimation"),this.animation=e,this._checkAndStartSlinesAnimation(),this.animation}_getCachedTile(e,t,n){var s,o;return(o=(s=this._tiles[`${e}:${t}:${n}`])==null?void 0:s.el)==null?void 0:o.wxtile}_ForEachTile(e){var n;let t=[];for(let s in this._tiles){let o=(n=this._tiles[s].el)==null?void 0:n.wxtile,i=o&&e(o);i&&t.push(i)}return t}async _setUpDataSet(e){e&&(this.dataSource=e),this._stopLoadingResetLoadDataFunc(),this.state.originURI=this.dataSource.serverURI+"/"+this.dataSource.dataset+"/";try{let t=await A(this.state.originURI+"instances.json");this.state.instance=t[t.length-1]+"/"}catch(t){return this.error=this.dataSource.name+": load instances.json error: "+t,x(this.error),!1}try{let t=this.state.originURI+this.state.instance+"meta.json";this.state.meta=await A(t)}catch(t){return this.error=this.dataSource.name+": load meta.json error: "+t,x(this.error),!1}if(this.vector=this.dataSource.variables.length===2,this.animation=this.vector,this.state.units=this.state.meta.variablesMeta[this.dataSource.variables[0]].units,this.state.minmax=this.dataSource.variables.map(t=>[this.state.meta.variablesMeta[t].min,this.state.meta.variablesMeta[t].max]),this.vector){let[[t,n],[s,o]]=this.state.minmax;this.state.minmax.unshift([0,1.42*Math.max(-t,n,-s,o)])}return this.error=null,e&&(this.setStyle(void 0),await this.setTime(new Date)),!0}_checkZoom(){var e;((e=this._map)==null?void 0:e.getZoom())>this.state.meta.maxZoom||this._stopLoadingResetLoadDataFunc()}_onAddLayer(){var e;x("onadd:",this.dataSource.name),(e=this._map)==null||e.on("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this.redraw(),this._checkAndStartSlinesAnimation()})}_onRemoveLayer(){var e;x("onremove:",this.dataSource.name),(e=this._map)==null||e.off("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this._stopLoadingResetLoadDataFunc(),this._stopSlinesAnimation()})}_stopLoadingResetLoadDataFunc(){this.loadData.controllerHolder.controller.abort(),this.loadData=z()}_checkAndStartSlinesAnimation(){if(this.animFrame||!this.animation||!this.vector||!this.style.streamLineColor||this.style.streamLineColor==="none")return;let e=t=>{if(!this.animation||this.style.streamLineStatic){this._stopSlinesAnimation();return}this._ForEachTile(n=>n.drawSLines(t)),this.animFrame=requestAnimationFrame(e)};e(0)}_stopSlinesAnimation(){cancelAnimationFrame(this.animFrame),this._ForEachTile(e=>e.clearSLinesCanvas()),this.animFrame=0}_redrawTiles(){this.animationRedrawID===0&&(this.animationRedrawID=requestAnimationFrame(()=>{x("_redrawTiles: requestAnimationFrame: "+this.dataSource.name),this._ForEachTile(e=>e.draw()),this.animationRedrawID=0}))}_reloadTiles(e=!0){x("_reloadTiles: start - "+this.dataSource.name),this.loadData.controllerHolder.controller.abort(),this.loadData.controllerHolder.controller=new AbortController;let t=this._ForEachTile(o=>o.load()),n=Promise.all(t),{controller:s}=this.loadData.controllerHolder;return e&&n.then(()=>s.signal.aborted||this._redrawTiles()),x("_reloadTiles: finished - "+this.dataSource.name),n}};function ke(r){return new _(r)}var X=class extends N.default.Control{constructor(e){super(e);this.URI=e.URI}onAdd(){let e=document.createElement("img");return e.src=this.URI,e.className="wxtiles-logo",e}};function Ye(r){return x("Add watermark:",JSON.stringify(r)),new X(r)}var $=class extends N.default.GridLayer{createTile(e){let t=document.createElement("div");return t.innerHTML=[e.x,e.y,e.z].join(", "),t.style.outline="1px solid red",t}};function et(){return x("Add WxDebugCoordsLayer:"),new $().setZIndex(1e3)}function tt(r,e){return N.default.layerGroup(r.map(ke),e)}return rt;})();
|