@metoceanapi/wxtiles-leaflet 1.0.6 → 1.0.10

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/dist/es/bundle.js DELETED
@@ -1 +0,0 @@
1
- var B=Math.pow;var p=(t,e,n)=>new Promise((r,o)=>{var i=l=>{try{c(n.next(l))}catch(h){o(h)}},s=l=>{try{c(n.throw(l))}catch(h){o(h)}},c=l=>l.done?r(l.value):Promise.resolve(l.value).then(i,s);c((n=n.apply(t,e)).next())});var Y={comment1:["degC: ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["hPa: ['Pa', 100]' -> hPa = Pa * 100 + 0 (0 - could be ommited)",0],K:["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**-1":["kg/m^2/s",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],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["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]},tt={none:["#00000000","#00000000"],rainbow:["#f00","#ff0","#0f0","#0ff","#00f","#f0f"],rainbow2:["#f00","#ff0","#0f0","#0ff","#00f","#f0f","#f00"],rainbowzerro:["#ff000000","#f00","#ff0","#0f0","#0ff","#00f","#f0f"],bluebird:["#00f","#f0f","#0ff","#80f","#88f"],bluebirdzerro:["#0000ff00","#00f","#f0f","#0ff","#80f","#88f"],bw:["#000","#fff"],wb:["#fff","#000"],redish:["#f0f","#f00","#ff0"],greenish:["#ff0","#0f0","#0ff"],blueish:["#f0f","#00f","#0ff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]},Z={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},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}},I,O,N;function et({colorStyles:t={},units:e={},colorSchemes:n={}}={}){window.wxlogging&&console.log("WxTile lib setup: start"),I=Object.assign({},Y,e),O=Object.assign({},n,tt),N=nt(t),window.wxlogging&&console.log("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),window.wxlogging&&console.log("WxTile lib setup is done"+JSON.stringify({colorStyles:t,units:e,colorSchemes:n}))}function F(){return N}function H(){return O}function A(t,e,n){let r=n?Object.assign({},I,n):I;if(!r||!t||!e||t===e||!r[t]||!r[e]||r[t][0]!==r[e][0]){window.wxlogging&&console.log(t===e?"Trivial converter:":"Inconvertible units. Default converter is used:",t," -> ",e);let s=c=>c;return s.trivial=!0,s}window.wxlogging&&console.log("Converter: From:",t," To:",e);let o=r[t][1]/r[e][1],i=(r[t][2]||0)/r[e][1]-(r[e][2]||0)/r[e][1];return i?s=>o*s+i:s=>o*s}function nt(t){let e=Object.assign({},Z);for(let o in t){let i=t[o];if(Array.isArray(i))for(let s=0;s<i.length;++s)e[o+"["+s+"]"]=Object.assign({},i[s]);else e[o]=Object.assign({},i)}let n=(o,i)=>{if(i==="base")return Z.base;let s=o[i];(!s.parent||!(s.parent in o))&&(s.parent="base");let c=n(o,s.parent);return Object.assign(s,Object.assign({},c,s,{parent:"base"}))},r={};for(let o in e)r[o]=n(e,o);return r}function rt(t){let e=new Map;return n=>{let r=e.get(n);return r===void 0&&(r=t(n),e.set(n,r)),r}}function ot(t,e){return p(this,null,function*(){let n=new Image;n.crossOrigin="anonymous";let r=()=>{n.src=""};return e.addEventListener("abort",r),n.src=t,yield n.decode(),e.removeEventListener("abort",r),n})}function st(t,e){return p(this,null,function*(){let n=i=>{let s=i.height*i.width,c=new Uint16Array(i.data.buffer),l=new Uint16Array(s);for(let a=0;a<s;a++)l[a]=c[a*2];let h=new Uint8Array(i.data.buffer);for(let a=0;a<8;++a)h[a]=h[a*4+2];let d=new DataView(i.data.buffer),u=d.getFloat32(0,!0),m=d.getFloat32(4,!0),f=(m-u)/65535,g=it(l);return{raw:l,dmin:u,dmax:m,dmul:f,integral:g,radius:0}},r=Object.assign(document.createElement("canvas"),{width:258,height:258,imageSmoothingEnabled:!1}).getContext("2d");if(!r)return Promise.reject();let o=yield ot(t,e);return r.drawImage(o,0,0),n(r.getImageData(0,0,258,258))})}function G(){let t=new AbortController,e=rt(n=>st(n,t.signal));return e.abort=()=>t.abort(),e}function it(t){let e=new Uint32Array(258*258),n=new Uint32Array(258*258);e[0]=t[0],n[0]=t[0]===0?0:1;for(let r=1;r<258;++r)e[r]=t[r]+e[r-1],e[258*r]=t[258*r]+e[258*r-258],n[r]=(t[r]===0?0:1)+n[r-1],n[258*r]=(t[258*r]===0?0:1)+n[258*r-258];for(let r=1,o=259;r<258;++r,++o)for(let i=1;i<258;++i,++o)e[o]=t[o]+e[o-258]+e[o-1]-e[o-258-1],n[o]=(t[o]===0?0:1)+n[o-258]+n[o-1]-n[o-258-1];return{integral:e,integralNZ:n}}function V(t,e){if(e<0||e===t.radius)return t;t.radius=e;let n=258,{integral:r,integralNZ:o}=t.integral;for(let i=1;i<n;i++)for(let s=1;s<n;s++){if(!t.raw[n*i+s])continue;let c=Math.min(e,s-1,n-1-s),l=Math.min(e,i-1,n-1-i),h=n*(i-l-1)+s,d=n*(i+l)+s,u=o[h-c-1],m=o[h+c],f=o[d-c-1],g=o[d+c],a=u+g-m-f,y=r[h-c-1],x=r[h+c],b=r[d-c-1],w=r[d+c],S=y+w-x-b;t.raw[i*n+s]=S/a}return t}function C(t){let e=t>>0&255,n=t>>8&255,r=t>>16&255,o=e.toString(16),i=n.toString(16),s=r.toString(16);return o=o.length===2?o:"0"+o,i=i.length===2?i:"0"+i,s=s.length===2?s:"0"+s,"#"+o+i+s}function v(t){if(t[0]==="#"){if(t.length===4)return+("0xff"+t[3]+t[3]+t[2]+t[2]+t[1]+t[1]);if(t.length===7)return+("0xff"+t[5]+t[6]+t[3]+t[4]+t[1]+t[2]);if(t.length===9)return+("0x"+t[7]+t[8]+t[5]+t[6]+t[3]+t[4]+t[1]+t[2])}return window.wxlogging&&console.log("wrong color format",t),0}function M(t){return p(this,null,function*(){return(yield fetch(t)).json()})}function L(t,e="",n){var o;let r=document.createElement(t);return r.className=e,n&&((o=n.appendChild)==null||o.call(n,r)),r}function U(t,e,n){let r=t>>0&255,o=t>>8&255,i=t>>16&255,s=t>>>24,c=e>>0&255,l=e>>8&255,h=e>>16&255,d=e>>>24,u=r+n*(c-r),m=o+n*(l-o),f=i+n*(h-i),g=s+n*(d-s);return u|m<<8|f<<16|g<<24}function K(t,e,n){let r=[];for(let o=0;o<n;++o)r.push(o*(e-t)/(n-1)+t);return r}function at(t,e,n){return t>n?n:t<e?e:t}var R=class{constructor(e,n,[r,o],i){let s=o-r;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let c=[];this.DataToStyle=A(n,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=n),i&&(this.DataToKnots=A(n,"knot"));let l=A(e.units,n,e.extraUnits),h=a=>~~(65535*at((l(a)-r)/(o-r),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((a,y)=>a[0]<y[0]?-1:a[0]>y[0]?1:0);for(let[a]of e.colorMap)c.push(h(a))}else{if(e.levels||(e.levels=K(this.DataToStyle(r),this.DataToStyle(o),10)),e.levels.sort((a,y)=>a<y?-1:a>y?1:0),!e.colors){let a=H();e.colorScheme&&e.colorScheme in a?e.colors=a[e.colorScheme]:e.colors=a.wb}for(let a of e.levels)c.push(h(a))}let d=65536,u=E(d,e);this.ticks=u.ticks;let m=u.ticks[0].data,g=u.ticks[u.ticks.length-1].data-m;for(let a=0;a<65536;++a){let y=s*a/65535+r,x=this.DataToStyle(y),b=Math.round((d-1)*(x-m)/g);b<=0?this.colorsI[a]=e.showBelowMin?u.colors[0]:0:b>=d?this.colorsI[a]=e.showAboveMax?u.colors[d-1]:0:this.colorsI[a]=u.colors[b]}this.colorsI[0]=0;for(let a=0;a<c[0];++a)this.levelIndex[a]=0;for(let a=0;a<c.length-1;a++)for(let y=c[a];y<c[a+1]+1;++y)this.levelIndex[y]=a;for(let a=c[c.length-1];a<65536;++a)this.levelIndex[a]=c.length-1}};function $(t){var n;if(t!==0&&-.1<t&&t<.1)return t.toExponential(2);let e=t.toString();return((n=e.split(".")[1])==null?void 0:n.length)>2?t.toFixed(2):e}function E(t,e){let n={size:t,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(t),ticks:[]},{colorMap:r,levels:o,colors:i}=e,s=e.fill!=="solid";if(r){let m=r[0][0],f=r[r.length-1][0]-m;for(let[g,a]of r){let y=~~((g-m)/f*(t-1)),x={data:g,dataString:$(g),color:a,pos:y};n.ticks.push(x)}for(let g=0;g<r.length-1;g++){let a=n.ticks[g].pos,y=n.ticks[g+1].pos,x=v(r[g][1]),b=s?v(r[g+1][1]):0;for(let w=a;w<y;++w)n.colors[w]=s?U(x,b,(w-a)/(y-a)):x}return n.colors[t-1]=v(r[r.length-1][1]),n}if(!i||!o)return n;let c=0,l=0,h=-1;for(let m=0;m<t;++m){let f=m*(i.length-1)/t;h!==~~f&&(h=~~f,c=v(i[h]),l=i.length>h+1?v(i[h+1]):c),n.colors[m]=s?U(c,l,f-h):c}n.colors[t-1]=v(i[i.length-1]);let d=o[0],u=(t-1)/(o[o.length-1]-d);for(let m of o){let f=~~((m-d)*u),g={data:m,dataString:$(m),color:C(n.colors[f]),pos:f};n.ticks.push(g)}return n}var W=256,lt=2*Math.PI*6378137/W,k=2*Math.PI*6378137/2;function ct(t,e){let n=t/k*180,r=e/k*180;return r=180/Math.PI*(2*Math.atan(Math.exp(r*Math.PI/180))-Math.PI/2),[r,n]}function ut(t,e,n){let r=mt(n),o=t*r-k,i=e*r-k;return[o,i]}function mt(t){return lt/Math.pow(2,t)}function z(t,e,n){let[r,o]=ct(...ut(t,e,n));return[o,-r]}function q(t,e){return[t*W,e*W]}function ht(t,e){if(!e)return t;let n=.9999999/Math.pow(2,e.z),r=e.x*256*n,o=e.y*256*n,i={raw:new Uint16Array(258*258),dmin:t.dmin,dmax:t.dmax,dmul:t.dmul},{raw:s}=i;for(let c=-1,l=0;c<=256;c++){let h=o+c*n,d=Math.floor(h),u=h-d;for(let m=-1;m<=256;m++,l++){let f=r+m*n,g=Math.floor(f),a=f-g,y=g+1+(d+1)*258,x=t.raw[y],b=t.raw[y+1],w=t.raw[y+258],S=t.raw[y+258+1];switch((x?1:0)|(b?2:0)|(w?4:0)|(S?8:0)){case 0:s[l]=0;continue;case 1:s[l]=x;continue;case 2:s[l]=b;continue;case 3:w=x,S=b;break;case 4:s[l]=w;continue;case 5:b=x,S=w;break;case 6:S=b+w>>1,x=S;break;case 7:S=b+w>>1;break;case 8:s[l]=S;continue;case 9:b=x+S>>1,w=b;break;case 10:x=b,w=S;break;case 11:w=x+S>>1;break;case 12:x=w,b=S;break;case 13:b=x+S>>1;break;case 14:x=b+w>>1;break}x=t.dmin+t.dmul*x,b=t.dmin+t.dmul*b,w=t.dmin+t.dmul*w,S=t.dmin+t.dmul*S;let D=j(x,b,a),T=j(w,S,a);s[l]=(j(D,T,u)-t.dmin)/t.dmul,s[l]===0&&(s[l]=1)}}return i}function j(t,e,n){let r=((e-t)%360+540)%360-180;return(t+r*n+360)%360}function dt(t,e){if(!e)return t;let n=.9999999/Math.pow(2,e.z),r=e.x*256*n,o=e.y*256*n,i={raw:new Uint16Array(258*258),dmin:t.dmin,dmax:t.dmax,dmul:t.dmul},{raw:s}=i;for(let c=-1,l=0;c<=256;c++){let h=o+c*n,d=Math.floor(h),u=h-d;for(let m=-1;m<=256;m++,l++){let f=r+m*n,g=Math.floor(f),a=f-g,y=g+1+(d+1)*258,x=t.raw[y],b=t.raw[y+1],w=t.raw[y+258],S=t.raw[y+258+1];switch((x?1:0)|(b?2:0)|(w?4:0)|(S?8:0)){case 7:s[l]=a+u<1?a*(b-x)+u*(w-x)+x:0;continue;case 14:s[l]=a+u<1?0:a*(S-w)+u*(S-b)+b+w-S;continue;case 11:s[l]=u<a?(1-a)*(x-b)+u*(S-b)+b:0;continue;case 13:s[l]=u<a?0:(1-a)*(w-S)+u*(w-x)+x+S-w;continue;case 15:s[l]=a+u<1?a*(b-x)+u*(w-x)+x:a*(S-w)+u*(S-b)+b+w-S;continue;default:s[l]=0}}}return i}function ft(t){let[e,n]=q(t.x,t.y),[r,o]=z(e,n,t.z),[i,s]=z(e+256,n+256,t.z);return{west:r,north:o,east:i,south:s}}function X({layer:t,coords:e,done:n}){let r=L("div","leaflet-tile s-tile");return t.dataSource?(r.wxtile=new J({layer:t,coords:e,tileEl:r}),r.wxtile._load().then(o=>{o.draw(),n()})):setTimeout(n),r}var J=class{constructor({layer:e,coords:n,tileEl:r}){this.data=[];this.sLines=[];this.imData=null;this.coords=n,this.layer=e,this.canvasFill=L("canvas","s-tile canvas-fill",r),this.canvasSlines=L("canvas","s-tile canvas-slines",r),this.canvasVector=this.canvasFill,this.canvasFill.width=this.canvasFill.height=this.canvasSlines.width=this.canvasSlines.height=256;function o(i){let s=i.getContext("2d");if(!s)throw"error";return s}this.canvasFillCtx=o(this.canvasFill),this.canvasSlinesCtx=o(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}draw(){if(!this.data.length){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasSlinesCtx.clearRect(0,0,256,256);return}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 n=this.canvasSlinesCtx;if(n.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.sLines=[];return}let r=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let o=0;o<this.sLines.length;++o){let i=this.sLines[o],s=i.length-1,c=(e+(1+i[0].x)*(1+i[0].y))%30;for(let l=0;l<s;++l){let h=i[l],d=i[l+1],u=1-(c-l)/s;(u<0||u>1)&&(u=0);let m=(~~(u*255)).toString(16);n.strokeStyle=r+(m.length<2?"0"+m:m);let f=1+~~((1.2-u)*5);n.lineWidth=f,n.beginPath(),n.moveTo(h.x,h.y),n.lineTo(d.x,d.y),n.stroke()}}}getData({x:e,y:n}){if(!this.data.length)return;let r=this.data[0].raw[(n+1)*258+(e+1)];return{raw:r,data:this.data[0].dmin+this.data[0].dmul*r}}_load(){return p(this,null,function*(){let{coords:e,layer:n}=this,{boundaries:r}=n.dataSource.meta;if(r==null?void 0:r.boundaries180){let d=ft(e),u=m=>!(d.west>m.east||m.west>d.east||d.south>m.north||m.south>d.north);if(!r.boundaries180.some(u))return this.data=[],this.imData=null,this}let{upCoords:o,subCoords:i}=this._splitCoords(e),s=this._coordsToURLs(o),c=[];try{c=yield Promise.all(s.map(n.loadData))}catch(d){return this.data=[],this.imData=null,this}let l=n.dataSource.units==="degree"?ht:dt,h=d=>l(V(d,this.layer.style.blurRadius),i);return this.data=c.map(h),this.imData=this.canvasFillCtx.createImageData(256,256),this.layer.vector&&(this._vectorPrepare(),this._createSLines()),this})}_splitCoords(e){let n=e.z-this.layer.dataSource.meta.maxZoom;if(n<=0)return{upCoords:e};let r={x:e.x>>>n,y:e.y>>>n,z:this.layer.dataSource.meta.maxZoom},o={x:e.x&(1<<n)-1,y:e.y&(1<<n)-1,z:n};return{upCoords:r,subCoords:o}}_coordsToURLs(e){let n=this.layer.dataSource.baseURL.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));return this.layer.dataSource.variables.map(r=>n.replace("{var}",r))}_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,n,r]=this.data;e.dmax=1.42*Math.max(-n.dmin,n.dmax,-r.dmin,r.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let o=0;o<258*258;++o){if(!n.raw[o]||!r.raw[o]){e.raw[o]=0;continue}let i=n.dmin+n.dmul*n.raw[o],s=r.dmin+r.dmul*r.raw[o];e.raw[o]=Math.sqrt(s*s+i*i)/e.dmul}}_drawFillAndIsolines(){let{imData:e}=this;if(!e)throw"_drawFillAndIsolines: !imData";let{canvasFillCtx:n}=this;n.clearRect(0,0,256,256);let r=new Uint32Array(e.data.buffer),{raw:o}=this.data[0],{clut:i,style:s}=this.layer,{levelIndex:c,colorsI:l}=i;if(s.fill!=="none"){let d=l;for(let u=0,m=0,f=259;u<256;++u,f+=2)for(let g=0;g<256;++g,++m,++f)r[m]=d[o[f]]}else r.fill(0);let h=[];if(s.isolineColor!=="none"){let d=s.isolineColor[0]==="#"?v(s.isolineColor):0;for(let u=0,m=0;u<256;u+=1)for(let f=0;f<256;f+=1){let g=(u+1)*258+(f+1),a=o[g],y=o[g+1],x=o[g+258];if(!a||!y||!x)continue;let b=c[a],w=c[y],S=c[x];if(b!==w||b!==S){let _=Math.max(b,w,S),D=Math.max(a,y,x),T=u*256+f;switch(s.isolineColor){case"inverted":r[T]=~l[D]|4278190080;break;case"fill":r[T]=l[D]|4278190080;break;default:r[T]=d;break}s.isolineText&&!(++m%255)&&f>20&&f<235&&u>20&&u<235&&h.push({x:f,y:u,d:a,dr:y,db:x,mli:_})}}}if(n.putImageData(e,0,0),!h.length){n.font="1.1em Sans-serif",n.lineWidth=2,n.strokeStyle="white",n.fillStyle="black",n.textAlign="center",n.textBaseline="middle";for(let{x:d,y:u,d:m,dr:f,db:g,mli:a}of h){let y=this.layer.clut.ticks[a].dataString,x=Math.atan2(m-f,g-m);n.save(),n.translate(d,u),n.rotate(x<-1.57||x>1.57?x+3.14:x),n.strokeText(y,0,0),n.fillText(y,0,0),n.restore()}}}_drawStaticSlines(){if(!this.sLines.length||!this.layer.style.streamLineStatic)return;let{canvasSlinesCtx:e}=this;if(e.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.sLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let n=this.sLines.length;n--;){let r=this.sLines[n];for(let o=0;o<r.length-1;++o){let i=r[o],s=r[o+1];e.moveTo(i.x,i.y),e.lineTo(s.x,s.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,n,r]=this.data,{canvasVectorCtx:o}=this;switch(this.layer.style.vectorType){case"barbs":o.font="40px barbs";break;case"arrows":o.font="50px arrows";break;default:o.font=this.layer.style.vectorType}o.textAlign="center",o.textBaseline="middle";let i=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0,s=32;for(let c=s/2;c<256;c+=s)for(let l=s/2;l<256;l+=s){let h=l+1+(c+1)*258;if(!e.raw[h])continue;let d=Math.atan2(n.dmin+n.raw[h]*n.dmul,r.dmin+r.raw[h]*r.dmul),u=e.dmin+e.raw[h]*e.dmul,m=this.layer.dataSource.variables[0].includes("current")?5:.2,f=Math.min(this.layer.clut.DataToKnots(u)*m,25)+65,g=String.fromCharCode(f);switch(this.layer.style.vectorColor){case"inverted":o.fillStyle=C(~this.layer.clut.colorsI[e.raw[h]]);break;case"fill":o.fillStyle=C(this.layer.clut.colorsI[e.raw[h]]);break;default:o.fillStyle=this.layer.style.vectorColor;break}o.save(),o.translate(l,c),o.rotate(d+i),o.fillText(g,0,0),o.restore()}}_drawDegree(){if(this.layer.dataSource.units!=="degree")return;let{canvasVectorCtx:e}=this,n=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0;e.font="50px arrows",e.textAlign="start",e.textBaseline="alphabetic";let r=this.data[0],o="L",i=32;for(let s=i/2;s<256;s+=i)for(let c=i/2;c<256;c+=i){let l=c+1+(s+1)*258;if(!r.raw[l])continue;let d=(r.dmin+r.raw[l]*r.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=C(~this.layer.clut.colorsI[r.raw[l]]);break;case"fill":e.fillStyle=C(this.layer.clut.colorsI[r.raw[l]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(c,s),e.rotate(d+n),e.fillText(o,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[n,r,o]=this.data,i=Math.max(this.coords.z-this.layer.dataSource.meta.maxZoom,0),s=Math.min(B(2,i+5),128),c=~~(120+i*60);for(let l=0;l<=256;l+=s)for(let h=0;h<=256;h+=s){if(!n.raw[h+l*258])continue;let d=[],u=h,m=l;for(let f=0;f<=c&&u>=0&&u<=256&&m>=0&&m<=256;f++){!(f%(c/6))&&d.push({x:~~u,y:~~m});let g=~~u+1+(~~m+1)*258;if(!n.raw[g])break;u+=e*(r.dmin+r.raw[g]*r.dmul)/n.dmax,m-=e*(o.dmin+o.raw[g]*o.dmul)/n.dmax}u=h,m=l;for(let f=1;f<=c&&u>=0&&u<=256&&m>=0&&m<=256;f++){!(f%(c/6))&&d.unshift({x:~~u,y:~~m});let g=~~u+1+(~~m+1)*258;if(!n.raw[g])break;u-=e*(r.dmin+r.raw[g]*r.dmul)/n.dmax,m+=e*(o.dmin+o.raw[g]*o.dmul)/n.dmax}d.length>2&&this.sLines.push(d)}}};var Q={initializeLayer({dataSource:t,options:e={},lazy:n=!0}){if(window.wxlogging&&console.log("Creating a WxTile layer:"+JSON.stringify({dataSource:t,options:e})),!t){window.wxlogging&&console.log("dataSource is empty!");return}Object.assign(this.options,e),this.styles=F(),t.ext||(t.ext="webp"),this.wxtiles=new Map;let r=()=>{window.wxlogging&&console.log("Setup:",t.name),this.setupCompletePromise=this._setUpDataSet(t),this.setupCompletePromise.then(()=>{window.wxlogging&&console.log("Setup complete:",this.dataSource.name,this.error&&". error:"+this.error||""),this._initializeEvents(),this._map&&this._onAddL(),this.fire("setupcomplete",{layer:this})})};n?this.once("add",r):r(),this.on("remove",this._onRemoveL,this)},createTile(t,e){return this.error?(setTimeout(e),Object.assign(L("div","error-tile"),{innerHTML:this.error})):X({layer:this,coords:t,done:e})},getSetupCompletePromise(){return this.setupCompletePromise},getTile(t){if(!this._map||this.error)return;let e=this._map.getZoom(),{x:n,y:r}=this._map.project(t,e),o={x:~~(n/256),y:~~(r/256)},i=this.wxtiles.get(`${o.x}:${o.y}:${e}`);if(!i||!i.data)return;let s={x:~~(n-o.x*256),y:~~(r-o.y*256)},c=i.getData(s);if(!c)return;let{raw:l,data:h}=c,d=this.clut.colorsI[l],u=C(d),m=this.clut.DataToStyle(h);return{tile:i,data:h,raw:l,rgba:d,hexColor:u,inStyleUnits:m,tilePoint:s,units:this.style.units}},setStyle(t){if(!this.dataSource){window.wxlogging&&console.log("setStyle: failed. Lazy setup not finished yet.");return}if(!(this.dataSource.styleName===t&&t!=="custom")){if(t&&(this.dataSource.styleName=t),t==="custom"&&this.styles.custom){(!this.styles.custom.parent||!(this.styles.custom.parent in this.styles))&&(this.styles.custom.parent="base");let e=this.styles[this.styles.custom.parent];this.styles.custom=Object.assign(Object.assign({},e),this.styles.custom)}this.dataSource.styleName in this.styles?Array.isArray(this.styles[this.dataSource.styleName])&&(this.dataSource.styleName+="[0]"):(this.dataSource.styleName=this.dataSource.name+"[0]",this.dataSource.styleName in this.styles||(this.dataSource.styleName="base",window.wxlogging&&console.log(`cant find the style (${t}), default is used`)));try{let e=this.styles[this.dataSource.styleName];this.style=Object.assign({},e);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 r=this.dataSource.minmax[0];this.clut=new R(this.style,this.dataSource.units,r,this.vector)}catch(e){this.error="setStyle: impossible error in RawCLUT",window.wxlogging&&console.log(this.error,e);return}t&&(this._checkAndStartSlinesAnimation(),this._reloadTiles()),window.wxlogging&&console.log('setStyle: "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete."),this.fire("setstyle",{layer:this})}},getStyle(){if(!this.dataSource){window.wxlogging&&console.log("getStyle: failed. Lazy setup not finished yet.");return}return this.dataSource&&this.dataSource.styleName||""},getStyleName(){if(!this.dataSource){window.wxlogging&&console.log("getStyleName: failed. Lazy setup not finished yet.");return}return this.dataSource&&this.style&&this.style.name||"no style"},setTime(t){if(!this.dataSource){window.wxlogging&&console.log("setTime: failed. Lazy setup not finished yet.");return}let e=this._getClosestTimeString(t);if(this.dataSource.time!==e){this.dataSource.time=e,this.dataSource.baseURL=this.dataSource.originURI+this.dataSource.instance+`{var}/${this.dataSource.time}/{z}/{x}/{y}.${this.dataSource.ext}`,this.fire("settime",{layer:this,layerTime:e}),window.wxlogging&&console.log("setTime: "+e+" for "+this.dataSource.name+" complete.");let n=this._reloadTiles();return n.then(()=>{let r=this.wxtiles.values().next().value;if(!(r==null?void 0:r.data.length))return;let[o,i]=this.dataSource.minmax[0],{dmin:s,dmax:c}=r.data[0];(Math.abs(s-o)>.01||Math.abs(c-i)>.01)&&(this.dataSource.minmax=r.data.map(l=>[l.dmin,l.dmax]),this._updateMinMax(),this.setStyle())}),n}return Promise.resolve()},getTime(){if(!this.dataSource){window.wxlogging&&console.log("getTime: failed. Lazy setup not finished yet.");return}return this.dataSource.time},getTimes(){if(!this.dataSource){window.wxlogging&&console.log("getTimes: failed. Lazy setup not finished yet.");return}return this.dataSource.meta.times},checkDataChanged(){return p(this,null,function*(){if(!this.dataSource)return window.wxlogging&&console.log("getTimes: failed. Lazy setup not finished yet."),Promise.resolve(!1);let t=yield M(this.dataSource.originURI+"instances.json"),e=t[t.length-1]+"/";if(this.dataSource.instance!==e)return!0;let n=yield M(this.dataSource.originURI+e+"meta.json");return this.dataSource.meta.times.toString()!==n.times.toString()})},reloadData(){return this._setUpDataSet()},getLegendData(t){if(!this.error){if(!this.clut){window.wxlogging&&console.log("getLegendData: failed. Lazy setup not finished yet:"+this.dataSource.name);return}return E(t,this.style)}},setTimeAnimationMode(t=2){this.oldMaxZoom=this.dataSource.meta.maxZoom;let e=this._map.getZoom(),r=(e<this.oldMaxZoom?e:this.oldMaxZoom)-t;this.dataSource.meta.maxZoom=r<0?0:r},unsetTimeAnimationMode(){var t,e;!this.oldMaxZoom||!((e=(t=this.dataSource)==null?void 0:t.meta)==null?void 0:e.maxZoom)||(this.dataSource.meta.maxZoom=this.oldMaxZoom,this._reloadTiles())},getMinMax(){let[t,e]=this.dataSource.minmax[0];return{min:t,max:e}},_setUpDataSet(t){return p(this,null,function*(){if(t&&!(t.dataset&&t.variables&&Array.isArray(t.variables)&&t.variables.length>0&&t.variables.length<3)){this.error=t.name+": dataSource error",window.wxlogging&&console.log(this.error);return}t&&(this.dataSource=t),this._stopLoadingResetLoadDataFunc(),this.dataSource.originURI=this.dataSource.serverURI+"/"+this.dataSource.dataset+"/";try{let e=yield M(this.dataSource.originURI+"instances.json");this.dataSource.instance=e[e.length-1]+"/"}catch(e){this.error=this.dataSource.name+": load instances.json error",window.wxlogging&&console.log(this.error);return}try{let e=this.dataSource.originURI+this.dataSource.instance+"meta.json";this.dataSource.meta=yield M(e)}catch(e){this.error=this.dataSource.name+": load meta.json error",window.wxlogging&&console.log(this.error);return}this.vector=this.dataSource.variables.length===2,this.animation=this.vector,this.dataSource.units=this.dataSource.meta.variablesMeta[this.dataSource.variables[0]].units,this.dataSource.minmax=this.dataSource.variables.map(e=>[this.dataSource.meta.variablesMeta[e].min,this.dataSource.meta.variablesMeta[e].max]),this._updateMinMax(),t&&(this.setTime(Date.now()),this.setStyle())})},_updateMinMax(){if(!this.vector)return;let[[t,e],[n,r]]=this.dataSource.minmax;this.dataSource.minmax.unshift([0,1.42*Math.max(-t,e,-n,r)])},_initializeEvents(){this.error||(this.on("tileload",t=>{this.wxtiles.set(`${t.coords.x}:${t.coords.y}:${t.coords.z}`,t.tile.wxtile)}),this.on("tileunload",t=>{this.wxtiles.delete(`${t.coords.x}:${t.coords.y}:${t.coords.z}`)}),this.on("add",this._onAddL,this))},_checkZoom(){(!this._map||this._map.getZoom()<this.dataSource.meta.maxZoom)&&this._stopLoadingResetLoadDataFunc()},_onAddL(){window.wxlogging&&console.log("onadd:",this.dataSource.name),this.error||this._map.on("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this.redraw(),this._checkAndStartSlinesAnimation()})},_onRemoveL(){window.wxlogging&&console.log("onremove:",this.dataSource.name),this._map.off("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this._stopLoadingResetLoadDataFunc(),this._stopSlinesAnimation()})},_stopLoadingResetLoadDataFunc(){var t;(t=this.loadData)==null||t.abort(),this.loadData=G()},_checkAndStartSlinesAnimation(){if(this.animFrame||!this.animation||!this.vector||!this.style.streamLineColor||this.style.streamLineColor==="none")return;let t=e=>{if(!this.animation||this.style.streamLineStatic){this._stopSlinesAnimation();return}this.wxtiles.forEach(n=>n.drawSLines(e)),this.animFrame=requestAnimationFrame(t)};t()},_stopSlinesAnimation(){cancelAnimationFrame(this.animFrame),this.wxtiles.forEach(t=>t.clearSLinesCanvas()),this.animFrame=0},_getClosestTimeString(t){return this.dataSource.meta.times.find(e=>new Date(e).getTime()>=t)||this.dataSource.meta.times[this.dataSource.meta.times.length-1]},_redrawTiles(){!this.wxtiles||this.animationRedrawID||(this.animationRedrawID=requestAnimationFrame(()=>{this.wxtiles.forEach(t=>t.draw()),this.animationRedrawID=null}))},_reloadTiles(){let t=[];this.wxtiles.forEach(n=>t.push(n._load()));let e=Promise.all(t);return e.then(()=>this._redrawTiles()),e}};var P=window.L,gt=P.GridLayer.extend(Q);function xt(t){let e=new gt;return e.initializeLayer(t),e}var bt={options:{URI:""},onAdd(){let t=document.createElement("img");return t.src=this.options.URI,t.className="wxtiles-logo",t}},yt=P.Control.extend(bt);function Rt(t){return window.wxlogging&&console.log("Add watermark:",JSON.stringify(t)),new yt(t)}var wt=P.GridLayer.extend({createTile(t){let e=document.createElement("div");return e.innerHTML=[t.x,t.y,t.z].join(", "),e.style.outline="1px solid red",e}});function Et(){window.wxlogging&&console.log("Add WxDebugCoordsLayer:");let t=new wt;return t.setZIndex(1e3),t}function Wt(t){return P.layerGroup(t.map(xt))}function zt(t){console.log(t?"Logging on":"Logging off"),window.wxlogging=t}export{Et as WxDebugCoordsLayer,F as WxGetColorStyles,Wt as WxTileGroupLayer,xt as WxTileLayer,et as WxTileLibSetup,zt as WxTileLogging,Rt as WxTileWatermark};
@@ -1,2 +0,0 @@
1
- import './styles.css';
2
- export * from './wxtile-js';
@@ -1,96 +0,0 @@
1
- export namespace WxGridLayerProto {
2
- function initializeLayer({ dataSource, options, lazy }: {
3
- dataSource: any;
4
- options?: {} | undefined;
5
- lazy?: boolean | undefined;
6
- }): void;
7
- function initializeLayer({ dataSource, options, lazy }: {
8
- dataSource: any;
9
- options?: {} | undefined;
10
- lazy?: boolean | undefined;
11
- }): void;
12
- function createTile(coords: any, done: any): any;
13
- function createTile(coords: any, done: any): any;
14
- function getSetupCompletePromise(): any;
15
- function getSetupCompletePromise(): any;
16
- function getTile(latlng: any): {
17
- tile: any;
18
- data: any;
19
- raw: any;
20
- rgba: any;
21
- hexColor: string;
22
- inStyleUnits: any;
23
- tilePoint: {
24
- x: number;
25
- y: number;
26
- };
27
- units: any;
28
- } | undefined;
29
- function getTile(latlng: any): {
30
- tile: any;
31
- data: any;
32
- raw: any;
33
- rgba: any;
34
- hexColor: string;
35
- inStyleUnits: any;
36
- tilePoint: {
37
- x: number;
38
- y: number;
39
- };
40
- units: any;
41
- } | undefined;
42
- function setStyle(name: any): void;
43
- function setStyle(name: any): void;
44
- function getStyle(): any;
45
- function getStyle(): any;
46
- function getStyleName(): any;
47
- function getStyleName(): any;
48
- function setTime(unixTime: any): Promise<void> | Promise<any[]> | undefined;
49
- function setTime(unixTime: any): Promise<void> | Promise<any[]> | undefined;
50
- function getTime(): any;
51
- function getTime(): any;
52
- function getTimes(): any;
53
- function getTimes(): any;
54
- function checkDataChanged(): Promise<boolean>;
55
- function checkDataChanged(): Promise<boolean>;
56
- function reloadData(): Promise<void>;
57
- function reloadData(): Promise<void>;
58
- function getLegendData(legendSize: any): import("./RawCLUT").Legend | undefined;
59
- function getLegendData(legendSize: any): import("./RawCLUT").Legend | undefined;
60
- function setTimeAnimationMode(l?: number): void;
61
- function setTimeAnimationMode(l?: number): void;
62
- function unsetTimeAnimationMode(): void;
63
- function unsetTimeAnimationMode(): void;
64
- function getMinMax(): {
65
- min: any;
66
- max: any;
67
- };
68
- function getMinMax(): {
69
- min: any;
70
- max: any;
71
- };
72
- function _setUpDataSet(dataSource: any): Promise<void>;
73
- function _setUpDataSet(dataSource: any): Promise<void>;
74
- function _updateMinMax(): void;
75
- function _updateMinMax(): void;
76
- function _initializeEvents(): void;
77
- function _initializeEvents(): void;
78
- function _checkZoom(): void;
79
- function _checkZoom(): void;
80
- function _onAddL(): void;
81
- function _onAddL(): void;
82
- function _onRemoveL(): void;
83
- function _onRemoveL(): void;
84
- function _stopLoadingResetLoadDataFunc(): void;
85
- function _stopLoadingResetLoadDataFunc(): void;
86
- function _checkAndStartSlinesAnimation(): void;
87
- function _checkAndStartSlinesAnimation(): void;
88
- function _stopSlinesAnimation(): void;
89
- function _stopSlinesAnimation(): void;
90
- function _getClosestTimeString(unixTime: any): any;
91
- function _getClosestTimeString(unixTime: any): any;
92
- function _redrawTiles(): void;
93
- function _redrawTiles(): void;
94
- function _reloadTiles(): Promise<any[]>;
95
- function _reloadTiles(): Promise<any[]>;
96
- }
@@ -1,11 +0,0 @@
1
- export { WxTileLibSetup, WxGetColorStyles, ColorStylesWeakMixed, Units, ColorSchemes, LibSetupObject } from './wxtools';
2
- export declare function WxTileLayer(settings: any): any;
3
- export declare function WxTileWatermark(options: any): {
4
- options: {
5
- URI: string;
6
- };
7
- onAdd(): HTMLImageElement;
8
- } & import("leaflet").Control;
9
- export declare function WxDebugCoordsLayer(): any;
10
- export declare function WxTileGroupLayer(group: any): import("leaflet").LayerGroup<any>;
11
- export declare function WxTileLogging(on: any): void;
@@ -1 +0,0 @@
1
- var wxtilejs=(()=>{var et=Object.defineProperty;var B=Math.pow;var nt=(t,e)=>{for(var n in e)et(t,n,{get:e[n],enumerable:!0})};var p=(t,e,n)=>new Promise((r,o)=>{var i=l=>{try{c(n.next(l))}catch(h){o(h)}},s=l=>{try{c(n.throw(l))}catch(h){o(h)}},c=l=>l.done?r(l.value):Promise.resolve(l.value).then(i,s);c((n=n.apply(t,e)).next())});var Mt={};nt(Mt,{WxDebugCoordsLayer:()=>vt,WxGetColorStyles:()=>A,WxTileGroupLayer:()=>Lt,WxTileLayer:()=>tt,WxTileLibSetup:()=>H,WxTileLogging:()=>Tt,WxTileWatermark:()=>pt});var rt={comment1:["degC: ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["hPa: ['Pa', 100]' -> hPa = Pa * 100 + 0 (0 - could be ommited)",0],K:["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**-1":["kg/m^2/s",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],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["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]},ot={none:["#00000000","#00000000"],rainbow:["#f00","#ff0","#0f0","#0ff","#00f","#f0f"],rainbow2:["#f00","#ff0","#0f0","#0ff","#00f","#f0f","#f00"],rainbowzerro:["#ff000000","#f00","#ff0","#0f0","#0ff","#00f","#f0f"],bluebird:["#00f","#f0f","#0ff","#80f","#88f"],bluebirdzerro:["#0000ff00","#00f","#f0f","#0ff","#80f","#88f"],bw:["#000","#fff"],wb:["#fff","#000"],redish:["#f0f","#f00","#ff0"],greenish:["#ff0","#0f0","#0ff"],blueish:["#f0f","#00f","#0ff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]},Z={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},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}},F,O,N;function H({colorStyles:t={},units:e={},colorSchemes:n={}}={}){window.wxlogging&&console.log("WxTile lib setup: start"),F=Object.assign({},rt,e),O=Object.assign({},n,ot),N=st(t),window.wxlogging&&console.log("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),window.wxlogging&&console.log("WxTile lib setup is done"+JSON.stringify({colorStyles:t,units:e,colorSchemes:n}))}function A(){return N}function G(){return O}function k(t,e,n){let r=n?Object.assign({},F,n):F;if(!r||!t||!e||t===e||!r[t]||!r[e]||r[t][0]!==r[e][0]){window.wxlogging&&console.log(t===e?"Trivial converter:":"Inconvertible units. Default converter is used:",t," -> ",e);let s=c=>c;return s.trivial=!0,s}window.wxlogging&&console.log("Converter: From:",t," To:",e);let o=r[t][1]/r[e][1],i=(r[t][2]||0)/r[e][1]-(r[e][2]||0)/r[e][1];return i?s=>o*s+i:s=>o*s}function st(t){let e=Object.assign({},Z);for(let o in t){let i=t[o];if(Array.isArray(i))for(let s=0;s<i.length;++s)e[o+"["+s+"]"]=Object.assign({},i[s]);else e[o]=Object.assign({},i)}let n=(o,i)=>{if(i==="base")return Z.base;let s=o[i];(!s.parent||!(s.parent in o))&&(s.parent="base");let c=n(o,s.parent);return Object.assign(s,Object.assign({},c,s,{parent:"base"}))},r={};for(let o in e)r[o]=n(e,o);return r}function it(t){let e=new Map;return n=>{let r=e.get(n);return r===void 0&&(r=t(n),e.set(n,r)),r}}function at(t,e){return p(this,null,function*(){let n=new Image;n.crossOrigin="anonymous";let r=()=>{n.src=""};return e.addEventListener("abort",r),n.src=t,yield n.decode(),e.removeEventListener("abort",r),n})}function lt(t,e){return p(this,null,function*(){let n=i=>{let s=i.height*i.width,c=new Uint16Array(i.data.buffer),l=new Uint16Array(s);for(let a=0;a<s;a++)l[a]=c[a*2];let h=new Uint8Array(i.data.buffer);for(let a=0;a<8;++a)h[a]=h[a*4+2];let d=new DataView(i.data.buffer),u=d.getFloat32(0,!0),m=d.getFloat32(4,!0),f=(m-u)/65535,g=ct(l);return{raw:l,dmin:u,dmax:m,dmul:f,integral:g,radius:0}},r=Object.assign(document.createElement("canvas"),{width:258,height:258,imageSmoothingEnabled:!1}).getContext("2d");if(!r)return Promise.reject();let o=yield at(t,e);return r.drawImage(o,0,0),n(r.getImageData(0,0,258,258))})}function V(){let t=new AbortController,e=it(n=>lt(n,t.signal));return e.abort=()=>t.abort(),e}function ct(t){let e=new Uint32Array(258*258),n=new Uint32Array(258*258);e[0]=t[0],n[0]=t[0]===0?0:1;for(let r=1;r<258;++r)e[r]=t[r]+e[r-1],e[258*r]=t[258*r]+e[258*r-258],n[r]=(t[r]===0?0:1)+n[r-1],n[258*r]=(t[258*r]===0?0:1)+n[258*r-258];for(let r=1,o=259;r<258;++r,++o)for(let i=1;i<258;++i,++o)e[o]=t[o]+e[o-258]+e[o-1]-e[o-258-1],n[o]=(t[o]===0?0:1)+n[o-258]+n[o-1]-n[o-258-1];return{integral:e,integralNZ:n}}function K(t,e){if(e<0||e===t.radius)return t;t.radius=e;let n=258,{integral:r,integralNZ:o}=t.integral;for(let i=1;i<n;i++)for(let s=1;s<n;s++){if(!t.raw[n*i+s])continue;let c=Math.min(e,s-1,n-1-s),l=Math.min(e,i-1,n-1-i),h=n*(i-l-1)+s,d=n*(i+l)+s,u=o[h-c-1],m=o[h+c],f=o[d-c-1],g=o[d+c],a=u+g-m-f,y=r[h-c-1],x=r[h+c],b=r[d-c-1],w=r[d+c],S=y+w-x-b;t.raw[i*n+s]=S/a}return t}function C(t){let e=t>>0&255,n=t>>8&255,r=t>>16&255,o=e.toString(16),i=n.toString(16),s=r.toString(16);return o=o.length===2?o:"0"+o,i=i.length===2?i:"0"+i,s=s.length===2?s:"0"+s,"#"+o+i+s}function v(t){if(t[0]==="#"){if(t.length===4)return+("0xff"+t[3]+t[3]+t[2]+t[2]+t[1]+t[1]);if(t.length===7)return+("0xff"+t[5]+t[6]+t[3]+t[4]+t[1]+t[2]);if(t.length===9)return+("0x"+t[7]+t[8]+t[5]+t[6]+t[3]+t[4]+t[1]+t[2])}return window.wxlogging&&console.log("wrong color format",t),0}function M(t){return p(this,null,function*(){return(yield fetch(t)).json()})}function L(t,e="",n){var o;let r=document.createElement(t);return r.className=e,n&&((o=n.appendChild)==null||o.call(n,r)),r}function U(t,e,n){let r=t>>0&255,o=t>>8&255,i=t>>16&255,s=t>>>24,c=e>>0&255,l=e>>8&255,h=e>>16&255,d=e>>>24,u=r+n*(c-r),m=o+n*(l-o),f=i+n*(h-i),g=s+n*(d-s);return u|m<<8|f<<16|g<<24}function $(t,e,n){let r=[];for(let o=0;o<n;++o)r.push(o*(e-t)/(n-1)+t);return r}function ut(t,e,n){return t>n?n:t<e?e:t}var R=class{constructor(e,n,[r,o],i){let s=o-r;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let c=[];this.DataToStyle=k(n,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=n),i&&(this.DataToKnots=k(n,"knot"));let l=k(e.units,n,e.extraUnits),h=a=>~~(65535*ut((l(a)-r)/(o-r),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((a,y)=>a[0]<y[0]?-1:a[0]>y[0]?1:0);for(let[a]of e.colorMap)c.push(h(a))}else{if(e.levels||(e.levels=$(this.DataToStyle(r),this.DataToStyle(o),10)),e.levels.sort((a,y)=>a<y?-1:a>y?1:0),!e.colors){let a=G();e.colorScheme&&e.colorScheme in a?e.colors=a[e.colorScheme]:e.colors=a.wb}for(let a of e.levels)c.push(h(a))}let d=65536,u=E(d,e);this.ticks=u.ticks;let m=u.ticks[0].data,g=u.ticks[u.ticks.length-1].data-m;for(let a=0;a<65536;++a){let y=s*a/65535+r,x=this.DataToStyle(y),b=Math.round((d-1)*(x-m)/g);b<=0?this.colorsI[a]=e.showBelowMin?u.colors[0]:0:b>=d?this.colorsI[a]=e.showAboveMax?u.colors[d-1]:0:this.colorsI[a]=u.colors[b]}this.colorsI[0]=0;for(let a=0;a<c[0];++a)this.levelIndex[a]=0;for(let a=0;a<c.length-1;a++)for(let y=c[a];y<c[a+1]+1;++y)this.levelIndex[y]=a;for(let a=c[c.length-1];a<65536;++a)this.levelIndex[a]=c.length-1}};function q(t){var n;if(t!==0&&-.1<t&&t<.1)return t.toExponential(2);let e=t.toString();return((n=e.split(".")[1])==null?void 0:n.length)>2?t.toFixed(2):e}function E(t,e){let n={size:t,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(t),ticks:[]},{colorMap:r,levels:o,colors:i}=e,s=e.fill!=="solid";if(r){let m=r[0][0],f=r[r.length-1][0]-m;for(let[g,a]of r){let y=~~((g-m)/f*(t-1)),x={data:g,dataString:q(g),color:a,pos:y};n.ticks.push(x)}for(let g=0;g<r.length-1;g++){let a=n.ticks[g].pos,y=n.ticks[g+1].pos,x=v(r[g][1]),b=s?v(r[g+1][1]):0;for(let w=a;w<y;++w)n.colors[w]=s?U(x,b,(w-a)/(y-a)):x}return n.colors[t-1]=v(r[r.length-1][1]),n}if(!i||!o)return n;let c=0,l=0,h=-1;for(let m=0;m<t;++m){let f=m*(i.length-1)/t;h!==~~f&&(h=~~f,c=v(i[h]),l=i.length>h+1?v(i[h+1]):c),n.colors[m]=s?U(c,l,f-h):c}n.colors[t-1]=v(i[i.length-1]);let d=o[0],u=(t-1)/(o[o.length-1]-d);for(let m of o){let f=~~((m-d)*u),g={data:m,dataString:q(m),color:C(n.colors[f]),pos:f};n.ticks.push(g)}return n}var W=256,mt=2*Math.PI*6378137/W,P=2*Math.PI*6378137/2;function ht(t,e){let n=t/P*180,r=e/P*180;return r=180/Math.PI*(2*Math.atan(Math.exp(r*Math.PI/180))-Math.PI/2),[r,n]}function dt(t,e,n){let r=ft(n),o=t*r-P,i=e*r-P;return[o,i]}function ft(t){return mt/Math.pow(2,t)}function z(t,e,n){let[r,o]=ht(...dt(t,e,n));return[o,-r]}function X(t,e){return[t*W,e*W]}function gt(t,e){if(!e)return t;let n=.9999999/Math.pow(2,e.z),r=e.x*256*n,o=e.y*256*n,i={raw:new Uint16Array(258*258),dmin:t.dmin,dmax:t.dmax,dmul:t.dmul},{raw:s}=i;for(let c=-1,l=0;c<=256;c++){let h=o+c*n,d=Math.floor(h),u=h-d;for(let m=-1;m<=256;m++,l++){let f=r+m*n,g=Math.floor(f),a=f-g,y=g+1+(d+1)*258,x=t.raw[y],b=t.raw[y+1],w=t.raw[y+258],S=t.raw[y+258+1];switch((x?1:0)|(b?2:0)|(w?4:0)|(S?8:0)){case 0:s[l]=0;continue;case 1:s[l]=x;continue;case 2:s[l]=b;continue;case 3:w=x,S=b;break;case 4:s[l]=w;continue;case 5:b=x,S=w;break;case 6:S=b+w>>1,x=S;break;case 7:S=b+w>>1;break;case 8:s[l]=S;continue;case 9:b=x+S>>1,w=b;break;case 10:x=b,w=S;break;case 11:w=x+S>>1;break;case 12:x=w,b=S;break;case 13:b=x+S>>1;break;case 14:x=b+w>>1;break}x=t.dmin+t.dmul*x,b=t.dmin+t.dmul*b,w=t.dmin+t.dmul*w,S=t.dmin+t.dmul*S;let D=j(x,b,a),T=j(w,S,a);s[l]=(j(D,T,u)-t.dmin)/t.dmul,s[l]===0&&(s[l]=1)}}return i}function j(t,e,n){let r=((e-t)%360+540)%360-180;return(t+r*n+360)%360}function xt(t,e){if(!e)return t;let n=.9999999/Math.pow(2,e.z),r=e.x*256*n,o=e.y*256*n,i={raw:new Uint16Array(258*258),dmin:t.dmin,dmax:t.dmax,dmul:t.dmul},{raw:s}=i;for(let c=-1,l=0;c<=256;c++){let h=o+c*n,d=Math.floor(h),u=h-d;for(let m=-1;m<=256;m++,l++){let f=r+m*n,g=Math.floor(f),a=f-g,y=g+1+(d+1)*258,x=t.raw[y],b=t.raw[y+1],w=t.raw[y+258],S=t.raw[y+258+1];switch((x?1:0)|(b?2:0)|(w?4:0)|(S?8:0)){case 7:s[l]=a+u<1?a*(b-x)+u*(w-x)+x:0;continue;case 14:s[l]=a+u<1?0:a*(S-w)+u*(S-b)+b+w-S;continue;case 11:s[l]=u<a?(1-a)*(x-b)+u*(S-b)+b:0;continue;case 13:s[l]=u<a?0:(1-a)*(w-S)+u*(w-x)+x+S-w;continue;case 15:s[l]=a+u<1?a*(b-x)+u*(w-x)+x:a*(S-w)+u*(S-b)+b+w-S;continue;default:s[l]=0}}}return i}function bt(t){let[e,n]=X(t.x,t.y),[r,o]=z(e,n,t.z),[i,s]=z(e+256,n+256,t.z);return{west:r,north:o,east:i,south:s}}function J({layer:t,coords:e,done:n}){let r=L("div","leaflet-tile s-tile");return t.dataSource?(r.wxtile=new Q({layer:t,coords:e,tileEl:r}),r.wxtile._load().then(o=>{o.draw(),n()})):setTimeout(n),r}var Q=class{constructor({layer:e,coords:n,tileEl:r}){this.data=[];this.sLines=[];this.imData=null;this.coords=n,this.layer=e,this.canvasFill=L("canvas","s-tile canvas-fill",r),this.canvasSlines=L("canvas","s-tile canvas-slines",r),this.canvasVector=this.canvasFill,this.canvasFill.width=this.canvasFill.height=this.canvasSlines.width=this.canvasSlines.height=256;function o(i){let s=i.getContext("2d");if(!s)throw"error";return s}this.canvasFillCtx=o(this.canvasFill),this.canvasSlinesCtx=o(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}draw(){if(!this.data.length){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasSlinesCtx.clearRect(0,0,256,256);return}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 n=this.canvasSlinesCtx;if(n.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.sLines=[];return}let r=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let o=0;o<this.sLines.length;++o){let i=this.sLines[o],s=i.length-1,c=(e+(1+i[0].x)*(1+i[0].y))%30;for(let l=0;l<s;++l){let h=i[l],d=i[l+1],u=1-(c-l)/s;(u<0||u>1)&&(u=0);let m=(~~(u*255)).toString(16);n.strokeStyle=r+(m.length<2?"0"+m:m);let f=1+~~((1.2-u)*5);n.lineWidth=f,n.beginPath(),n.moveTo(h.x,h.y),n.lineTo(d.x,d.y),n.stroke()}}}getData({x:e,y:n}){if(!this.data.length)return;let r=this.data[0].raw[(n+1)*258+(e+1)];return{raw:r,data:this.data[0].dmin+this.data[0].dmul*r}}_load(){return p(this,null,function*(){let{coords:e,layer:n}=this,{boundaries:r}=n.dataSource.meta;if(r==null?void 0:r.boundaries180){let d=bt(e),u=m=>!(d.west>m.east||m.west>d.east||d.south>m.north||m.south>d.north);if(!r.boundaries180.some(u))return this.data=[],this.imData=null,this}let{upCoords:o,subCoords:i}=this._splitCoords(e),s=this._coordsToURLs(o),c=[];try{c=yield Promise.all(s.map(n.loadData))}catch(d){return this.data=[],this.imData=null,this}let l=n.dataSource.units==="degree"?gt:xt,h=d=>l(K(d,this.layer.style.blurRadius),i);return this.data=c.map(h),this.imData=this.canvasFillCtx.createImageData(256,256),this.layer.vector&&(this._vectorPrepare(),this._createSLines()),this})}_splitCoords(e){let n=e.z-this.layer.dataSource.meta.maxZoom;if(n<=0)return{upCoords:e};let r={x:e.x>>>n,y:e.y>>>n,z:this.layer.dataSource.meta.maxZoom},o={x:e.x&(1<<n)-1,y:e.y&(1<<n)-1,z:n};return{upCoords:r,subCoords:o}}_coordsToURLs(e){let n=this.layer.dataSource.baseURL.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));return this.layer.dataSource.variables.map(r=>n.replace("{var}",r))}_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,n,r]=this.data;e.dmax=1.42*Math.max(-n.dmin,n.dmax,-r.dmin,r.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let o=0;o<258*258;++o){if(!n.raw[o]||!r.raw[o]){e.raw[o]=0;continue}let i=n.dmin+n.dmul*n.raw[o],s=r.dmin+r.dmul*r.raw[o];e.raw[o]=Math.sqrt(s*s+i*i)/e.dmul}}_drawFillAndIsolines(){let{imData:e}=this;if(!e)throw"_drawFillAndIsolines: !imData";let{canvasFillCtx:n}=this;n.clearRect(0,0,256,256);let r=new Uint32Array(e.data.buffer),{raw:o}=this.data[0],{clut:i,style:s}=this.layer,{levelIndex:c,colorsI:l}=i;if(s.fill!=="none"){let d=l;for(let u=0,m=0,f=259;u<256;++u,f+=2)for(let g=0;g<256;++g,++m,++f)r[m]=d[o[f]]}else r.fill(0);let h=[];if(s.isolineColor!=="none"){let d=s.isolineColor[0]==="#"?v(s.isolineColor):0;for(let u=0,m=0;u<256;u+=1)for(let f=0;f<256;f+=1){let g=(u+1)*258+(f+1),a=o[g],y=o[g+1],x=o[g+258];if(!a||!y||!x)continue;let b=c[a],w=c[y],S=c[x];if(b!==w||b!==S){let I=Math.max(b,w,S),D=Math.max(a,y,x),T=u*256+f;switch(s.isolineColor){case"inverted":r[T]=~l[D]|4278190080;break;case"fill":r[T]=l[D]|4278190080;break;default:r[T]=d;break}s.isolineText&&!(++m%255)&&f>20&&f<235&&u>20&&u<235&&h.push({x:f,y:u,d:a,dr:y,db:x,mli:I})}}}if(n.putImageData(e,0,0),!h.length){n.font="1.1em Sans-serif",n.lineWidth=2,n.strokeStyle="white",n.fillStyle="black",n.textAlign="center",n.textBaseline="middle";for(let{x:d,y:u,d:m,dr:f,db:g,mli:a}of h){let y=this.layer.clut.ticks[a].dataString,x=Math.atan2(m-f,g-m);n.save(),n.translate(d,u),n.rotate(x<-1.57||x>1.57?x+3.14:x),n.strokeText(y,0,0),n.fillText(y,0,0),n.restore()}}}_drawStaticSlines(){if(!this.sLines.length||!this.layer.style.streamLineStatic)return;let{canvasSlinesCtx:e}=this;if(e.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.sLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let n=this.sLines.length;n--;){let r=this.sLines[n];for(let o=0;o<r.length-1;++o){let i=r[o],s=r[o+1];e.moveTo(i.x,i.y),e.lineTo(s.x,s.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,n,r]=this.data,{canvasVectorCtx:o}=this;switch(this.layer.style.vectorType){case"barbs":o.font="40px barbs";break;case"arrows":o.font="50px arrows";break;default:o.font=this.layer.style.vectorType}o.textAlign="center",o.textBaseline="middle";let i=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0,s=32;for(let c=s/2;c<256;c+=s)for(let l=s/2;l<256;l+=s){let h=l+1+(c+1)*258;if(!e.raw[h])continue;let d=Math.atan2(n.dmin+n.raw[h]*n.dmul,r.dmin+r.raw[h]*r.dmul),u=e.dmin+e.raw[h]*e.dmul,m=this.layer.dataSource.variables[0].includes("current")?5:.2,f=Math.min(this.layer.clut.DataToKnots(u)*m,25)+65,g=String.fromCharCode(f);switch(this.layer.style.vectorColor){case"inverted":o.fillStyle=C(~this.layer.clut.colorsI[e.raw[h]]);break;case"fill":o.fillStyle=C(this.layer.clut.colorsI[e.raw[h]]);break;default:o.fillStyle=this.layer.style.vectorColor;break}o.save(),o.translate(l,c),o.rotate(d+i),o.fillText(g,0,0),o.restore()}}_drawDegree(){if(this.layer.dataSource.units!=="degree")return;let{canvasVectorCtx:e}=this,n=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0;e.font="50px arrows",e.textAlign="start",e.textBaseline="alphabetic";let r=this.data[0],o="L",i=32;for(let s=i/2;s<256;s+=i)for(let c=i/2;c<256;c+=i){let l=c+1+(s+1)*258;if(!r.raw[l])continue;let d=(r.dmin+r.raw[l]*r.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=C(~this.layer.clut.colorsI[r.raw[l]]);break;case"fill":e.fillStyle=C(this.layer.clut.colorsI[r.raw[l]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(c,s),e.rotate(d+n),e.fillText(o,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[n,r,o]=this.data,i=Math.max(this.coords.z-this.layer.dataSource.meta.maxZoom,0),s=Math.min(B(2,i+5),128),c=~~(120+i*60);for(let l=0;l<=256;l+=s)for(let h=0;h<=256;h+=s){if(!n.raw[h+l*258])continue;let d=[],u=h,m=l;for(let f=0;f<=c&&u>=0&&u<=256&&m>=0&&m<=256;f++){!(f%(c/6))&&d.push({x:~~u,y:~~m});let g=~~u+1+(~~m+1)*258;if(!n.raw[g])break;u+=e*(r.dmin+r.raw[g]*r.dmul)/n.dmax,m-=e*(o.dmin+o.raw[g]*o.dmul)/n.dmax}u=h,m=l;for(let f=1;f<=c&&u>=0&&u<=256&&m>=0&&m<=256;f++){!(f%(c/6))&&d.unshift({x:~~u,y:~~m});let g=~~u+1+(~~m+1)*258;if(!n.raw[g])break;u-=e*(r.dmin+r.raw[g]*r.dmul)/n.dmax,m+=e*(o.dmin+o.raw[g]*o.dmul)/n.dmax}d.length>2&&this.sLines.push(d)}}};var Y={initializeLayer({dataSource:t,options:e={},lazy:n=!0}){if(window.wxlogging&&console.log("Creating a WxTile layer:"+JSON.stringify({dataSource:t,options:e})),!t){window.wxlogging&&console.log("dataSource is empty!");return}Object.assign(this.options,e),this.styles=A(),t.ext||(t.ext="webp"),this.wxtiles=new Map;let r=()=>{window.wxlogging&&console.log("Setup:",t.name),this.setupCompletePromise=this._setUpDataSet(t),this.setupCompletePromise.then(()=>{window.wxlogging&&console.log("Setup complete:",this.dataSource.name,this.error&&". error:"+this.error||""),this._initializeEvents(),this._map&&this._onAddL(),this.fire("setupcomplete",{layer:this})})};n?this.once("add",r):r(),this.on("remove",this._onRemoveL,this)},createTile(t,e){return this.error?(setTimeout(e),Object.assign(L("div","error-tile"),{innerHTML:this.error})):J({layer:this,coords:t,done:e})},getSetupCompletePromise(){return this.setupCompletePromise},getTile(t){if(!this._map||this.error)return;let e=this._map.getZoom(),{x:n,y:r}=this._map.project(t,e),o={x:~~(n/256),y:~~(r/256)},i=this.wxtiles.get(`${o.x}:${o.y}:${e}`);if(!i||!i.data)return;let s={x:~~(n-o.x*256),y:~~(r-o.y*256)},c=i.getData(s);if(!c)return;let{raw:l,data:h}=c,d=this.clut.colorsI[l],u=C(d),m=this.clut.DataToStyle(h);return{tile:i,data:h,raw:l,rgba:d,hexColor:u,inStyleUnits:m,tilePoint:s,units:this.style.units}},setStyle(t){if(!this.dataSource){window.wxlogging&&console.log("setStyle: failed. Lazy setup not finished yet.");return}if(!(this.dataSource.styleName===t&&t!=="custom")){if(t&&(this.dataSource.styleName=t),t==="custom"&&this.styles.custom){(!this.styles.custom.parent||!(this.styles.custom.parent in this.styles))&&(this.styles.custom.parent="base");let e=this.styles[this.styles.custom.parent];this.styles.custom=Object.assign(Object.assign({},e),this.styles.custom)}this.dataSource.styleName in this.styles?Array.isArray(this.styles[this.dataSource.styleName])&&(this.dataSource.styleName+="[0]"):(this.dataSource.styleName=this.dataSource.name+"[0]",this.dataSource.styleName in this.styles||(this.dataSource.styleName="base",window.wxlogging&&console.log(`cant find the style (${t}), default is used`)));try{let e=this.styles[this.dataSource.styleName];this.style=Object.assign({},e);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 r=this.dataSource.minmax[0];this.clut=new R(this.style,this.dataSource.units,r,this.vector)}catch(e){this.error="setStyle: impossible error in RawCLUT",window.wxlogging&&console.log(this.error,e);return}t&&(this._checkAndStartSlinesAnimation(),this._reloadTiles()),window.wxlogging&&console.log('setStyle: "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete."),this.fire("setstyle",{layer:this})}},getStyle(){if(!this.dataSource){window.wxlogging&&console.log("getStyle: failed. Lazy setup not finished yet.");return}return this.dataSource&&this.dataSource.styleName||""},getStyleName(){if(!this.dataSource){window.wxlogging&&console.log("getStyleName: failed. Lazy setup not finished yet.");return}return this.dataSource&&this.style&&this.style.name||"no style"},setTime(t){if(!this.dataSource){window.wxlogging&&console.log("setTime: failed. Lazy setup not finished yet.");return}let e=this._getClosestTimeString(t);if(this.dataSource.time!==e){this.dataSource.time=e,this.dataSource.baseURL=this.dataSource.originURI+this.dataSource.instance+`{var}/${this.dataSource.time}/{z}/{x}/{y}.${this.dataSource.ext}`,this.fire("settime",{layer:this,layerTime:e}),window.wxlogging&&console.log("setTime: "+e+" for "+this.dataSource.name+" complete.");let n=this._reloadTiles();return n.then(()=>{let r=this.wxtiles.values().next().value;if(!(r==null?void 0:r.data.length))return;let[o,i]=this.dataSource.minmax[0],{dmin:s,dmax:c}=r.data[0];(Math.abs(s-o)>.01||Math.abs(c-i)>.01)&&(this.dataSource.minmax=r.data.map(l=>[l.dmin,l.dmax]),this._updateMinMax(),this.setStyle())}),n}return Promise.resolve()},getTime(){if(!this.dataSource){window.wxlogging&&console.log("getTime: failed. Lazy setup not finished yet.");return}return this.dataSource.time},getTimes(){if(!this.dataSource){window.wxlogging&&console.log("getTimes: failed. Lazy setup not finished yet.");return}return this.dataSource.meta.times},checkDataChanged(){return p(this,null,function*(){if(!this.dataSource)return window.wxlogging&&console.log("getTimes: failed. Lazy setup not finished yet."),Promise.resolve(!1);let t=yield M(this.dataSource.originURI+"instances.json"),e=t[t.length-1]+"/";if(this.dataSource.instance!==e)return!0;let n=yield M(this.dataSource.originURI+e+"meta.json");return this.dataSource.meta.times.toString()!==n.times.toString()})},reloadData(){return this._setUpDataSet()},getLegendData(t){if(!this.error){if(!this.clut){window.wxlogging&&console.log("getLegendData: failed. Lazy setup not finished yet:"+this.dataSource.name);return}return E(t,this.style)}},setTimeAnimationMode(t=2){this.oldMaxZoom=this.dataSource.meta.maxZoom;let e=this._map.getZoom(),r=(e<this.oldMaxZoom?e:this.oldMaxZoom)-t;this.dataSource.meta.maxZoom=r<0?0:r},unsetTimeAnimationMode(){var t,e;!this.oldMaxZoom||!((e=(t=this.dataSource)==null?void 0:t.meta)==null?void 0:e.maxZoom)||(this.dataSource.meta.maxZoom=this.oldMaxZoom,this._reloadTiles())},getMinMax(){let[t,e]=this.dataSource.minmax[0];return{min:t,max:e}},_setUpDataSet(t){return p(this,null,function*(){if(t&&!(t.dataset&&t.variables&&Array.isArray(t.variables)&&t.variables.length>0&&t.variables.length<3)){this.error=t.name+": dataSource error",window.wxlogging&&console.log(this.error);return}t&&(this.dataSource=t),this._stopLoadingResetLoadDataFunc(),this.dataSource.originURI=this.dataSource.serverURI+"/"+this.dataSource.dataset+"/";try{let e=yield M(this.dataSource.originURI+"instances.json");this.dataSource.instance=e[e.length-1]+"/"}catch(e){this.error=this.dataSource.name+": load instances.json error",window.wxlogging&&console.log(this.error);return}try{let e=this.dataSource.originURI+this.dataSource.instance+"meta.json";this.dataSource.meta=yield M(e)}catch(e){this.error=this.dataSource.name+": load meta.json error",window.wxlogging&&console.log(this.error);return}this.vector=this.dataSource.variables.length===2,this.animation=this.vector,this.dataSource.units=this.dataSource.meta.variablesMeta[this.dataSource.variables[0]].units,this.dataSource.minmax=this.dataSource.variables.map(e=>[this.dataSource.meta.variablesMeta[e].min,this.dataSource.meta.variablesMeta[e].max]),this._updateMinMax(),t&&(this.setTime(Date.now()),this.setStyle())})},_updateMinMax(){if(!this.vector)return;let[[t,e],[n,r]]=this.dataSource.minmax;this.dataSource.minmax.unshift([0,1.42*Math.max(-t,e,-n,r)])},_initializeEvents(){this.error||(this.on("tileload",t=>{this.wxtiles.set(`${t.coords.x}:${t.coords.y}:${t.coords.z}`,t.tile.wxtile)}),this.on("tileunload",t=>{this.wxtiles.delete(`${t.coords.x}:${t.coords.y}:${t.coords.z}`)}),this.on("add",this._onAddL,this))},_checkZoom(){(!this._map||this._map.getZoom()<this.dataSource.meta.maxZoom)&&this._stopLoadingResetLoadDataFunc()},_onAddL(){window.wxlogging&&console.log("onadd:",this.dataSource.name),this.error||this._map.on("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this.redraw(),this._checkAndStartSlinesAnimation()})},_onRemoveL(){window.wxlogging&&console.log("onremove:",this.dataSource.name),this._map.off("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this._stopLoadingResetLoadDataFunc(),this._stopSlinesAnimation()})},_stopLoadingResetLoadDataFunc(){var t;(t=this.loadData)==null||t.abort(),this.loadData=V()},_checkAndStartSlinesAnimation(){if(this.animFrame||!this.animation||!this.vector||!this.style.streamLineColor||this.style.streamLineColor==="none")return;let t=e=>{if(!this.animation||this.style.streamLineStatic){this._stopSlinesAnimation();return}this.wxtiles.forEach(n=>n.drawSLines(e)),this.animFrame=requestAnimationFrame(t)};t()},_stopSlinesAnimation(){cancelAnimationFrame(this.animFrame),this.wxtiles.forEach(t=>t.clearSLinesCanvas()),this.animFrame=0},_getClosestTimeString(t){return this.dataSource.meta.times.find(e=>new Date(e).getTime()>=t)||this.dataSource.meta.times[this.dataSource.meta.times.length-1]},_redrawTiles(){!this.wxtiles||this.animationRedrawID||(this.animationRedrawID=requestAnimationFrame(()=>{this.wxtiles.forEach(t=>t.draw()),this.animationRedrawID=null}))},_reloadTiles(){let t=[];this.wxtiles.forEach(n=>t.push(n._load()));let e=Promise.all(t);return e.then(()=>this._redrawTiles()),e}};var _=window.L,yt=_.GridLayer.extend(Y);function tt(t){let e=new yt;return e.initializeLayer(t),e}var wt={options:{URI:""},onAdd(){let t=document.createElement("img");return t.src=this.options.URI,t.className="wxtiles-logo",t}},St=_.Control.extend(wt);function pt(t){return window.wxlogging&&console.log("Add watermark:",JSON.stringify(t)),new St(t)}var Ct=_.GridLayer.extend({createTile(t){let e=document.createElement("div");return e.innerHTML=[t.x,t.y,t.z].join(", "),e.style.outline="1px solid red",e}});function vt(){window.wxlogging&&console.log("Add WxDebugCoordsLayer:");let t=new Ct;return t.setZIndex(1e3),t}function Lt(t){return _.layerGroup(t.map(tt))}function Tt(t){console.log(t?"Logging on":"Logging off"),window.wxlogging=t}return Mt;})();
@@ -1,16 +0,0 @@
1
- This folder contains examples of how to use different bit of functionality in tiles JS libary.
2
- Everu example is a standalone HTML file
3
- NOTE: build before run examples.
4
- ```
5
- npm run build
6
- ```
7
-
8
- * getTile.html - How to pick data values from the mouse position.
9
- * group.html - how to show and hide multiple layers same canvas.
10
- * scalar.html - an example of how render a scalar value tempature.
11
- * vector.html - an example of how render a vector value (u,v) wind.
12
- * setStyle.html - how change the style of a layer dynamically.
13
- * setTime.html - how select the timestamp of a layer.
14
- * setupcomplete(promise).html - how to hook a callback to the setupcomplete event.
15
- This event is triggered when all the metadata from tiles.metoceanapi.com is loaded and the layer is about to be render.
16
- After this event you are allow to read or set the library properties time, style.
@@ -1,109 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>WxTiles v2.0</title>
5
- <meta charset="utf-8" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <link rel="shortcut icon" href="res/icon.png" type="image/x-icon" />
8
-
9
- <!-- LEAFLET lib goes first -->
10
- <link
11
- rel="stylesheet"
12
- href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
13
- integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
14
- crossorigin=""
15
- />
16
-
17
- <script
18
- src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
19
- integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
20
- crossorigin=""
21
- ></script>
22
-
23
- <!-- WxTile lib goes here -->
24
- <script src="../dist/web/wxtile.js"></script>
25
- <link rel="stylesheet" href="../dist/web/wxtile.css" />
26
- </head>
27
-
28
- <body style="margin: 0">
29
- <div id="map" style="height: 100vh; width: 100vw"></div>
30
-
31
- <script>
32
- ('use strict');
33
- const { WxTileLogging, WxTileLibSetup, WxTileWatermark, WxTileLayer, WxGetColorStyles } = window.wxtilejs;
34
-
35
- // Leaflet basic setup // set the main Leaflet's map object, compose and add base layers
36
- const map = L.map('map', { center: [-37.803113, 174.878166], zoom: 5, zoomControl: false });
37
-
38
- WxTileLogging(true); // use wxtiles logging -> console.log
39
- WxTileWatermark({ URI: 'res/wxtiles-logo.png', position: 'topleft' }).addTo(map); // set the correct URI
40
- // ESSENTIAL step to get lib ready.
41
- WxTileLibSetup({}); // if empty defaults are used
42
-
43
- // SCALAR field setup
44
- const layerS = WxTileLayer({
45
- dataSource: {
46
- serverURI: 'https://tiles.metoceanapi.com/data/', // server to fetch data from
47
- ext: 'png', // png / webp (default) - wxtilesplitter output format
48
- dataset: 'ecwmf.global', // dataset of the dataset
49
- variables: ['air.temperature.at-2m'], // variable(s) to be used for the layer rendering
50
- name: 'air.temperature.at-2m', // attribute of the dataSource to be used externally
51
- styleName: 'base', // The name of the style (from styles.json) to apply for the layer
52
- },
53
- // Lazy setup
54
- // 'true': perform setup and data loading on 'addTo(map)'.
55
- // 'false': start loading immediately, but loading is not finished when layer is created.
56
- // the signal 'setupcomplete' is fired when loading is finished.
57
- // useful when a big bunch of layers is used, so layers are not wasting memory and bandwidth.
58
- lazy: false,
59
- options: {
60
- opacity: 0.99,
61
- },
62
- });
63
- layerS.addTo(map);
64
-
65
- // VECTOR field setup
66
- const layerV = WxTileLayer({
67
- dataSource: {
68
- serverURI: 'https://tiles.metoceanapi.com/data/', // server to fetch data from
69
- ext: 'png', // png / webp (default) - wxtilesplitter output format
70
- dataset: 'ecwmf.global', // dataset of the dataset
71
- variables: ['wind.speed.eastward.at-10m', 'wind.speed.northward.at-10m'], // variabls to be used for the layer rendering
72
- name: 'wind speed at 10m', // attribute of the dataSource to be used externally
73
- styleName: 'base', // The name of the style (from styles.json) to apply for the layer
74
- },
75
- // Lazy setup
76
- // 'true': perform setup and data loading on 'addTo(map)'.
77
- // 'false': start loading immediately, but loading is not finished when layer is created.
78
- // the signal 'setupcomplete' is fired when loading is finished.
79
- // useful when a big bunch of layers is used, so layers are not wasting memory and bandwidth.
80
- lazy: false,
81
- options: { opacity: 0.4 },
82
- });
83
- layerV.addTo(map);
84
-
85
- // ONCLICK
86
- map.on('click', (e) => {
87
- let content = '';
88
- map.eachLayer((layer) => {
89
- if (layer.getTile) {
90
- // check if layer is a wxLayer
91
- const tile = layer.getTile(e.latlng);
92
- const time = layer.getTime();
93
- content += tile
94
- ? `<p>
95
- <div style="width: 18px;height: 18px;float: left;margin-right: 5px;background:${tile.hexColor}"></div>
96
- ${tile.tile.layer.dataSource.name} ${tile.inStyleUnits} (${time})
97
- </p>`
98
- : '';
99
- }
100
- });
101
-
102
- L.popup()
103
- .setLatLng(e.latlng)
104
- .setContent(content + `${e.latlng}`)
105
- .openOn(map);
106
- });
107
- </script>
108
- </body>
109
- </html>
@@ -1,93 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>WxTiles v2.0</title>
5
- <meta charset="utf-8" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <link rel="shortcut icon" href="res/icon.png" type="image/x-icon" />
8
-
9
- <!-- LEAFLET lib goes first -->
10
- <link
11
- rel="stylesheet"
12
- href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
13
- integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
14
- crossorigin=""
15
- />
16
-
17
- <script
18
- src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
19
- integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
20
- crossorigin=""
21
- ></script>
22
- `
23
-
24
- <!-- WxTile lib goes here -->
25
- <script src="../dist/web/wxtile.js"></script>
26
- <link rel="stylesheet" href="../dist/web/wxtile.css" />
27
- </head>
28
-
29
- <body style="margin: 0">
30
- <div id="map" style="height: 100vh; width: 100vw"></div>
31
-
32
- <script>
33
- ('use strict');
34
- const { WxTileLogging, WxTileLibSetup, WxTileWatermark, WxTileLayer, WxGetColorStyles, WxTileGroupLayer } = window.wxtilejs;
35
-
36
- // Leaflet basic setup // set the main Leaflet's map object, compose and add base layers
37
- const map = L.map('map', { center: [-37.803113, 174.878166], zoom: 5, zoomControl: false });
38
-
39
- WxTileLogging(true); // use wxtiles logging -> console.log
40
- WxTileWatermark({ URI: 'res/wxtiles-logo.png', position: 'topleft' }).addTo(map); // set the correct URI
41
- // ESSENTIAL step to get lib ready.
42
- WxTileLibSetup(); // if empty defaults are used
43
-
44
- // group setup
45
- const layersGroupSettings = [
46
- {
47
- dataSource: {
48
- serverURI: 'https://tiles.metoceanapi.com/data', // server to fetch data from
49
- ext: 'png', // png / webp (default) - wxtilesplitter output format
50
- dataset: 'ecwmf.global', // dataset of the dataset
51
- variables: ['air.temperature.at-2m'], // variable(s) to be used for the layer rendering
52
- name: 'air.temperature.at-2m', // attribute of the dataSource to be used externally
53
- styleName: 'base', // The name of the style (from styles.json) to apply for the layer
54
- },
55
- // Lazy setup
56
- // 'true': perform setup and data loading on 'addTo(map)'.
57
- // 'false': start loading immediately, but loading is not finished when layer is created.
58
- // the signal 'setupcomplete' is fired when loading is finished.
59
- // useful when a big bunch of layers is used, so layers are not wasting memory and bandwidth.
60
- lazy: true,
61
- options: {
62
- opacity: 0.99,
63
- },
64
- },
65
- {
66
- dataSource: {
67
- serverURI: 'https://tiles.metoceanapi.com/data', // server to fetch data from
68
- ext: 'png', // png / webp (default) - wxtilesplitter output format
69
- dataset: 'ecwmf.global', // dataset of the dataset
70
- variables: ['wind.speed.eastward.at-10m', 'wind.speed.northward.at-10m'], // variabls to be used for the layer rendering
71
- name: 'wind speed at 10m', // attribute of the dataSource to be used externally
72
- styleName: 'base', // The name of the style (from styles.json) to apply for the layer
73
- },
74
- // Lazy setup
75
- // 'true': perform setup and data loading on 'addTo(map)'.
76
- // 'false': start loading immediately, but loading is not finished when layer is created.
77
- // the signal 'setupcomplete' is fired when loading is finished.
78
- // useful when a big bunch of layers is used, so layers are not wasting memory and bandwidth.
79
- lazy: true,
80
- options: { opacity: 0.99 },
81
- },
82
- ];
83
- // create group of layers using layersGroupSettings
84
- const wxgroup = WxTileGroupLayer(layersGroupSettings);
85
- // add to map
86
- wxgroup.addTo(map);
87
- // get all setupCompletePromises
88
- const completePromises = wxgroup.getLayers().map((l) => l.setupCompletePromise);
89
- // wait all and log setup complete
90
- Promise.all(completePromises).then(() => alert('group setup complete. So, tiles are being loaded and rendered now.'));
91
- </script>
92
- </body>
93
- </html>
Binary file
Binary file
@@ -1,66 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>WxTiles v2.0</title>
5
- <meta charset="utf-8" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <link rel="shortcut icon" href="res/icon.png" type="image/x-icon" />
8
-
9
- <!-- LEAFLET lib goes first -->
10
- <link
11
- rel="stylesheet"
12
- href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
13
- integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
14
- crossorigin=""
15
- />
16
-
17
- <script
18
- src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
19
- integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
20
- crossorigin=""
21
- ></script>
22
-
23
- <!-- WxTile lib goes here -->
24
- <script src="../dist/web/wxtile.js"></script>
25
- <link rel="stylesheet" href="../dist/web/wxtile.css" />
26
- </head>
27
-
28
- <body style="margin: 0">
29
- <div id="map" style="height: 100vh; width: 100vw"></div>
30
-
31
- <script>
32
- ('use strict');
33
- const { WxTileLogging, WxTileLibSetup, WxTileWatermark, WxTileLayer, WxGetColorStyles } = window.wxtilejs;
34
-
35
- // Leaflet basic setup // set the main Leaflet's map object, compose and add base layers
36
- const map = L.map('map', { center: [-37.803113, 174.878166], zoom: 5, zoomControl: false });
37
-
38
- WxTileLogging(true); // use wxtiles logging -> console.log
39
- WxTileWatermark({ URI: 'res/wxtiles-logo.png', position: 'topleft' }).addTo(map); // set the correct URI
40
- // ESSENTIAL step to get lib ready.
41
- WxTileLibSetup({}); // if empty defaults are used
42
-
43
- // SCALAR field setup
44
- const layerS = WxTileLayer({
45
- dataSource: {
46
- serverURI: 'https://tiles.metoceanapi.com/data/', // server to fetch data from
47
- ext: 'png', // png / webp (default) - wxtilesplitter output format
48
- dataset: 'ecwmf.global', // dataset of the dataset
49
- variables: ['air.temperature.at-2m'], // variable(s) to be used for the layer rendering
50
- name: 'air.temperature.at-2m', // attribute of the dataSource to be used externally
51
- styleName: 'base', // The name of the style (from styles.json) to apply for the layer
52
- },
53
- // Lazy setup
54
- // 'true': perform setup and data loading on 'addTo(map)'.
55
- // 'false': start loading immediately, but loading is not finished when layer is created.
56
- // the signal 'setupcomplete' is fired when loading is finished.
57
- // useful when a big bunch of layers is used, so layers are not wasting memory and bandwidth.
58
- lazy: true,
59
- options: {
60
- opacity: 0.99,
61
- },
62
- });
63
- layerS.addTo(map);
64
- </script>
65
- </body>
66
- </html>