/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@metoceanapi/wxtiles-mbox@2.4.0-1/dist/es/bundle.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
var ae={none:["#00000000","#00000000"],diverging_blue_red:["#2166acff","#92c5deff","#f7f7f7ff","#f4a582ff","#b2182bff"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow_zero:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow_wrap:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],rainbow_backwards:["#0000ffff","#00ffffff","#00ff00ff","#ffff00ff","#ff0000ff","#ff00ffff"],rainbow_backwards_zero:["#0000ff00","#0000ffff","#00ffffff","#00ff00ff","#ffff00ff","#ff0000ff","#ff00ffff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebird_zero:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],black_white:["#000000ff","#ffffffff"],white_black:["#ffffffff","#000000ff"],reddish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"],black:["#000000ff","#000000ff"],white:["#ffffffff","#ffffffff"],transparent:["#ffffff00"],peach_red_zero:["#fdd49f00","#fdd49fff","#d7301fff"]},k={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"none",isolineText:!0,isolineTextSizeEm:1.1,isolineTextBackground:!1,vectorType:"arrows",vectorColor:"inverted",vectorFactor:1,streamLineColor:"none",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"diverging_blue_red",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none",gl:{animationIntensity:5,animationSpeed:1,noiseTexturePow:5,vectorFieldFactor:1,wavesCount:4}},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,isolineTextSizeEm:1.1,isolineTextBackground:!1,vectorType:"arrows",vectorColor:"inverted",vectorFactor:1,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"}},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],mph:["m/s",.44704],"miles/h":["m/s",.44704],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],km:["m",1e3],mile:["m",1609.344],miles:["m",1609.344],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]},_={_units:re,_colorSchemes:ae,_colorStylesUnrolled:k,wxlogging:!1};function We({colorStyles:e={},units:t={},colorSchemes:a={}}={}){h("WxTile lib setup: start"),_._units=Object.assign({},re,t),_._colorSchemes=Object.assign({},a,ae);let r=Object.assign({},e,k);_._colorStylesUnrolled=Oe(r),h("WxTile lib setup: styles unrolled"),(async()=>{try{await document.fonts.load("32px barbs"),await document.fonts.load("32px arrows")}catch{h("WxTile lib setup: fonts not loaded")}})(),h("WxTile lib setup is done.")}function A(){return _._colorStylesUnrolled}function U(){return _._colorSchemes}function X(e,t,a){h("makeConverter: From=",e," To=",t);let r=e=>e;if(r.trivial=!0,e===t)return h("Trivial converter"),r;let i=Object.assign({},_._units,a),s=i[e],n=i[t];if(!s||!n)return h("Inconvertible units. Trivial converter"),r;let[o,l,u]=s,[d,c,m]=n;if(o!==d||!l||!c)return h("Inconvertible units. Trivial converter"),r;let f=l/c,g=((u||0)-(m||0))/c;return g?e=>f*e+g:e=>f*e}function Oe(e){let t=Object.assign({},k);for(let a in e){let r=e[a];if(Array.isArray(r))for(let e=0;e<r.length;++e)t[`${a}[${e}]`]=Object.assign({},r[e]);else t[a]=Object.assign({},r)}let a=Object.assign({},k.base),r=(e,t)=>{if("base"===t)return a;let i=e[t];if(!i)return a;(!i.parent||!(i.parent in e))&&(i.parent="base");let s=r(e,i.parent);return Object.assign(i,Object.assign({},s,i,{parent:"base"}))},i={base:a};for(let e in t)i[e]=r(t,e);return i}function O(e){let t=new Map,a=(a,...r)=>{let i=t.get(a);if(i)return i;let s=e(a,...r);return t.set(a,s),s.catch((e=>"AbortError"===e.name&&t.delete(a))),s};return a.clearCache=()=>t.clear(),a}async function Ze(e,t){let a=await fetch(e,t);if(200!==a.status&&304!==a.status)throw{name:"Tile loading failed",reason:a.headers.get("x-reason"),status:a.status};return await createImageBitmap(await a.blob(),{premultiplyAlpha:"none"})}var F=class{constructor(e,t,a,r){this.raw=e,this.dmin=t,this.dmax=a,this.dmul=r,this.radius=0}get integral(){return this.integral_||(this.integral_=qe(this.raw)),this.integral_}};function Z(e,t,a=!0){let r=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d",{willReadFrequently:a});if(!r)throw new Error("Cannot get canvas context");return r}function Ge(e){let{width:t,height:a}=e,r=Z(t,a);return r.drawImage(e,0,0),r.getImageData(0,0,t,a)}async function ne(e,t){return Ge(await Ze(e,t))}function He(e){e.data[34]<1&&h("Warning: image is in too old format. Check the version of the Splitter.");let t=new Uint16Array(e.data.buffer),a=new Uint16Array(t.length/2);for(let e=0;e<a.length;e++)a[e]=t[2*e];let r=new Uint8Array(8);for(let t=0;t<8;++t)r[t]=e.data[4*t+2];let i=new DataView(r.buffer),s=i.getFloat32(0,!0),n=i.getFloat32(4,!0);return new F(a,s,n,(n-s)/65535)}async function Se(e,t){return He(await ne(e,t))}function qe(e){let t=new Uint32Array(66564),a=new Uint32Array(66564);t[0]=e[0],a[0]=e[0]?1:0;for(let r=1;r<258;++r){t[r]=e[r]+t[r-1],a[r]=(e[r]?1:0)+a[r-1];let i=258*r;t[i]=e[i]+t[i-258],a[i]=(e[i]?1:0)+a[i-258]}for(let r=1;r<258;++r)for(let i=1;i<258;++i){let s=258*r+i;t[s]=e[s]+t[s-258]+t[s-1]-t[s-259],a[s]=(e[s]?1:0)+a[s-258]+a[s-1]-a[s-259]}return{integral:t,integralNZ:66564===a[66563]?null:a}}function Ye(e){let{integral:t}=e.integral;e.raw[0]=t[0];for(let a=1;a<258;a++){e.raw[a]=t[a]-t[a-1],e.raw[258*a]=t[258*a]-t[258*(a-1)];for(let r=1;r<258;r++){let i=258*a+r;e.raw[i]=t[i-259]+t[i]-t[i-258]-t[i-1]}}return e}function Me(e,t){let a=t<0?0:t;if(a===e.radius)return e;if(e.radius=a,!a)return Ye(e);let{integral:r,integralNZ:i}=e.integral;for(let t=2;t<256;t++)for(let s=2;s<256;s++){let n=258*t+s;if(!e.raw[n])continue;let o,l=Math.min(a,s-1,256-s),h=Math.min(a,t-1,256-t),u=258*(t-h-1)+s,d=258*(t+h)+s;if(i){let e=i[u-l-1],t=i[u+l],a=i[d-l-1];o=e+i[d+l]-t-a}else o=(2*l+1)*(2*h+1);let c=r[u-l-1],m=r[u+l],f=r[d-l-1],g=c+r[d+l]-m-f;e.raw[n]=g/o}for(let t=2;t<256;t++){let s=258+t;if(e.raw[s]){let n,o=t,l=Math.min(a,o-1,256-o),h=258+o;if(i){let e=i[h-l-1];n=0+i[h+l]-0-e}else n=2*(2*l+1);let u=0,d=0,c=r[h-l-1],m=(u+r[h+l]-d-c)/n;e.raw[s-258]=m,e.raw[s]=m}let n=66048+t;if(e.raw[n]){let s,o=t,l=Math.min(a,o-1,256-o),h=65790+o,u=66306+o,d=r[h-l-1],c=r[h+l],m=r[u-l-1],f=d+r[u+l]-c-m;if(i){let e=i[h-l-1],t=i[h+l],a=i[u-l-1];s=e+i[u+l]-t-a}else s=2*(2*l+1);let g=f/s;e.raw[n]=g,e.raw[n+258]=g}let o=258*t+1;if(e.raw[o]){let s,n=t,l=Math.min(a,n-1,256-n),h=258*(n-l-1)+1,u=258*(n+l)+1;if(i){let e=i[h],t=0;s=0+i[u]-e-t}else s=2*(2*l+1);let d=0,c=r[h],m=0,f=(d+r[u]-c-m)/s;e.raw[o-1]=f,e.raw[o]=f}let l=258*t+256;if(e.raw[l]){let s,n=t,o=Math.min(a,n-1,256-n),h=258*(n-o-1)+256,u=258*(n+o)+256;if(i){let e=i[h-1],t=i[h+1],a=i[u-1];s=e+i[u+1]-t-a}else s=2*(2*o+1);let d=r[h-1],c=r[h+1],m=r[u-1],f=(d+r[u+1]-c-m)/s;e.raw[l]=f,e.raw[l+1]=f}}return e}function C(e){let t=e>>8&255,a=e>>16&255,r=(255&e).toString(16),i=t.toString(16),s=a.toString(16);return r=2===r.length?r:`0${r}`,i=2===i.length?i:`0${i}`,s=2===s.length?s:`0${s}`,`#${r}${i}${s}`}function E(e){if("#"===e[0]){if(4===e.length)return+`0xff${e[3]}${e[3]}${e[2]}${e[2]}${e[1]}${e[1]}`;if(7===e.length)return+`0xff${e[5]}${e[6]}${e[3]}${e[4]}${e[1]}${e[2]}`;if(9===e.length)return+`0x${e[7]}${e[8]}${e[5]}${e[6]}${e[3]}${e[4]}${e[1]}${e[2]}`}return h("wrong color format",e),0}async function P(e,t){let a=await fetch(e,t);if(!a.ok)throw new Error(`error:${e} - ${a.statusText}`);return a.json()}function se(e,t,a){let r=255&e,i=e>>8&255,s=e>>16&255,n=e>>>24;return r+a*((255&t)-r)|i+a*((t>>8&255)-i)<<8|s+a*((t>>16&255)-s)<<16|n+a*((t>>>24)-n)<<24}function De(e,t,a){let r=[];for(let i=0;i<a;++i)r.push(i*(t-e)/(a-1)+e);return r}var h=(...e)=>{};function je(e){_.wxlogging=!!e,console.log("WXLOGing",_.wxlogging),h="function"==typeof e?e:_.wxlogging?console.log:()=>{}}function oe(e){return"#"===e[0]&&4===e.length?`#${e[1]}${e[1]}${e[2]}${e[2]}${e[3]}${e[3]}`:e}function G(e,{x:t,y:a,z:r}){return e.replace("{x}",`${t}`).replace("{y}",`${a}`).replace("{z}",`${r}`)}function R({x:e,y:t,z:a}){return`${a}-${e}-${t}`}var ze="A".charCodeAt(0),$=class{constructor(e,t){this._qtree={},this._qtreedepth=0,h("QTree.constructor"),this._ready=this._load(e,t)}get ready(){return this._ready}async _load(e,t){if("none"!==e){try{let a=await P(e,t);this._qtree=we(a,{pos:0})}catch(e){throw new Error(`Failed to load QTree: ${e.message}`)}this._qtreedepth=Ce(this._qtree),h(`QTree.load: qtreedepth=${this._qtreedepth}`)}}check(e){let t=e.z-this._qtreedepth,a=t>=0,r=a?{x:e.x>>t,y:e.y>>t,z:this._qtreedepth}:{...e};return Ke(this._qtree,r,a)}};function we(e,t){let a=e.charCodeAt(t.pos)-ze;t.pos++;let r=[1,2,4,8].map((r=>a&r?we(e,t):void 0));return r.some((e=>e))?{nodes:r}:{}}function Ce(e){return e?.nodes?1+Math.max(...e.nodes.map(Ce)):0}function Ke(e,t,a){let r=e;for(;r;){if(a&&0===t.z)return"mixed";if(!r.nodes)return"sea";if(0===t.z)return"mixed";t.z--,r=r.nodes[(t.y>>t.z&1)<<1|t.x>>t.z&1]}return"land"}var H=class{constructor(e){this.wxAPI=e,this.allDatasetsShortMetas={},this.ready=this.updateAll()}updateAll(){return this.ready=P(`${this.wxAPI.dataServerURL}meta.json`,this.wxAPI.requestInit),this.ready.then((e=>{this.allDatasetsShortMetas=e})),this.ready}async updateOne(e){try{let t=`${this.wxAPI.dataServerURL+e}/meta.json`,a=await P(t,this.wxAPI.requestInit);return Object.assign(this.allDatasetsShortMetas,a)}catch{return this.updateAll()}}},q=class{constructor({dataServerURL:e,ext:t="webp",maskURL:a="none",maskChannel:r="R",maskDepth:i=11,qtreeURL:s="none",requestInit:n,colorStyles:o,units:l,colorSchemes:u}){if(h("WxAPI.constructor",e),We({colorStyles:o,units:l,colorSchemes:u}),"auto"===s&&(s=`${e}masks/11+1.seamask.qtree`),"auto"===a&&(a=`${e}masks/{z}/{x}/{y}.${t}`),this.dataServerURL=e,this.ext=t,this.requestInit=n,this.maskURL=a,this.maskChannel="R"===r?0:"G"===r?1:"B"===r?2:"A"===r?3:0,this.maskDepth=i,"none"!==this.maskURL){let e=O(ne);this.loadMaskFunc=t=>e(G(this.maskURL,t),n)}else this.loadMaskFunc=()=>Promise.reject(new Error("maskURL not defined"));this._allDatasetsManager=new H(this),this.qtree=new $(s,n),this.initDone=Promise.all([this._allDatasetsManager.ready,this.qtree.ready]).then((()=>h("WxAPI.constructor initDone")))}async createDatasetManagerOptions(e){await this.initDone,await this._allDatasetsManager.updateOne(e),h("WxAPI.createDatasetManager",e);let t=this._allDatasetsManager.allDatasetsShortMetas[e],a=t?.instance;if(!a)throw new Error(`Dataset/instance not found:${e}`);let r,i=t.instanced,s=`${this.dataServerURL+e}/`;try{r=await P(`${s}metafull.json`,this.requestInit)}catch{h("Can't load metafull.json. Trying old infrastructure with NGINX");let e=await P(`${s}instances.json`,this.requestInit);if(!Array.isArray(e)||!e.length)throw new Error("instances.json is not an array or empty");r=await Promise.all(e.reverse().map((async e=>Object.assign(await P(`${s+e}/meta.json`,this.requestInit),{instance:e}))))}return{datasetName:e,datasetCurrentInstance:a,datasetCurrentMeta:r[0],instanced:i,metas:i&&new Map(r.map((e=>[e.instance,e]))),wxAPI:this}}async getDatasetAllVariables(e){return await this.initDone,h("WxAPI.getDatasetVariables",e),this._allDatasetsManager.allDatasetsShortMetas[e]?.variables}async filterDatasetsByVariableName(e){await this.initDone,h("WxAPI.filterDatasetsByVariableName:",e);let{allDatasetsShortMetas:t}=this._allDatasetsManager;return Object.keys(t).filter((a=>t[a]?.variables.includes(e)))}async getAllDatasetsNames(){return await this.initDone,h("WxAPI.getAllDatasetsNames"),Object.keys(this._allDatasetsManager.allDatasetsShortMetas)}};function Ie(e){return class extends e{constructor(){super(...arguments),this._animation=!1,this._animationSeed=0,this._needUpdateDSManager=!1}get wxdatasetManager(){return h(`WxLayerBaseImplementation.wxdatasetManager (${this.id})`),this._layer.wxdatasetManager}getCurrentVariableMeta(){return h(`WxLayerBaseImplementation.getCurrentVariableMeta (${this.id})`),{...this._layer.currentVariableMeta}}getDatasetMeta(){return this._layer.wxdatasetManager.getInstanceMeta(this.getTime())}getMetadata(){return h(`WxLayerBaseImplementation.getMetadata (${this.id})`),{...this._layer.currentVariableMeta}}getVariablesNames(){return h(`WxLayerBaseImplementation.getVariables (${this.id})`),[...this._layer.variables]}clearCache(){h(`WxLayerBaseImplementation.clearCache (${this.id})`),this._layer.clearCache()}getCache(){return this._layer.tilesRasterCache}getCurrentStyleObjectCopy(){return h(`WxLayerBaseImplementation.getCurrentStyleObjectCopy (${this.id})`),this._layer.getCurrentStyleObjectCopy()}getTime(){return h(`WxLayerBaseImplementation.getTime (${this.id})`),this._layer.getTime()}getAllTimes(){return h(`WxLayerBaseImplementation.getTimes (${this.id})`),this._layer.wxdatasetManager.getAllTimes()}async setTime(e,t,a){h(`WxLayerBaseImplementation.setTime (${this.id}) time=${e}`);let r=this.getTime();return this._layer.setURLsAndTime(e),await this._reloadVisible(t,a),t?.signal?.aborted&&this._layer.setURLsAndTime(r),this.getTime()}async preloadTime(e,t){return h(`WxLayerBaseImplementation.preloadTime (${this.id}) time=${e}`),this._layer.preloadTime(e,this.coveringTiles(),t)}startAnimation(){if(this._animation)return void h(`WxLayerBaseImplementation.startAnimation (${this.id}) already started`);if(this._layer.nonanimatable)return void h(`WxLayerBaseImplementation.startAnimation (${this.id}) nonanimatable`);h(`WxLayerBaseImplementation.startAnimation (${this.id})`),this._animation=!0;let e=async t=>{h(`WxLayerBaseImplementation.startAnimation (${this.id}) animationStep`),this._animation&&!this._layer.nonanimatable?(this._animationSeed=t,await this._redrawTiles(),requestAnimationFrame(e)):this._animation=!1};requestAnimationFrame(e)}async stopAnimation(){return h(`WxLayerBaseImplementation.stopAnimation (${this.id})`),this._animation=!1,this._redrawTiles()}async setCoarseLevel(e=2){this._layer.coarseLevel=Math.max(0,Math.min(e,this.wxdatasetManager.getMaxZoom()))}async unsetCoarseLevel(){return this._layer.coarseLevel=0,this._reloadVisible()}async setStyleByName(e,t=!0){return h(`WxLayerBaseImplementation.setStyleByName (${this.id}) wxstyleName=${e} reload=${t}`),this.updateCurrentStyleObject(A()[e],t)}async updateCurrentStyleObject(e,t=!0,a){if(h(`WxLayerBaseImplementation.updateCurrentStyleObject (${this.id}) style=${e} reload=${t}`),this._layer.updateCurrentStyleObject(e),this.startAnimation(),t)return this._reloadVisible(a)}_redrawTiles(){return this._redrawRequested||(this._redrawRequested=new Promise((e=>{requestAnimationFrame((()=>{h(`WxTileSource _redrawTiles (${this.id})`),this.update(),e(),this._redrawRequested=void 0}))}))),this._redrawRequested}async _reloadVisible(e,t){}coveringTiles(){return[]}update(){}async _loadTileHelper(e,t){if(!this._needUpdateDSManager)try{return await this._layer.loadTile(e,t)}catch(e){if("AbortError"===e.name)throw e;"instance-not-found"===e.reason&&!this._needUpdateDSManager&&(this._needUpdateDSManager=!0,h(`WxTileSource.loadTile (${this.id}) instance-not-found. Trying to update wxdatasetManager and load again.`),this.wxdatasetManager.update().then((()=>{this._needUpdateDSManager=!1,this.setTime(this.getTime()).then((()=>this.fire("changed",this)))})).catch((e=>{h(`WxTileSource.loadTile (${this.id}) instance-not-found. wxdatasetManager update failed.`,e)})))}return null}}}function Je(e,t,a){return e>a?a:e<t?t:e}var Y=class{constructor(e,t,[a,r],i){let s;h("RawCLUT.constructor"),this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536),this.DataToStyle=X(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),i&&(this.DataToKnots=X(t,"knot"));let n=X(e.units,t,e.extraUnits),o=e=>~~(65535*Je((n(e)-a)/(r-a),0,1));if(e.colorMap?.length)s=e.colorMap.sort(((e,t)=>e[0]-t[0])).map((([e])=>o(e)));else{e.levels||=De(this.DataToStyle(a),this.DataToStyle(r),10),e.levels.sort(((e,t)=>e-t));let t=U();e.colors||=t[e.colorScheme]||["#ffffffff","#000000ff"],s=e.levels.map(o)}let l=r-a,u=j(65536,e);this.ticks=u.ticks;let d=u.ticks[0].data,c=u.ticks[u.ticks.length-1].data-d,m=e.showBelowMin?u.colors[0]:0,f=e.showAboveMax?u.colors[65535]:0;this.colorsI[0]=0;for(let e=1;e<65536;++e){let t=this.DataToStyle(l*e/65535+a),r=Math.round(65535*(t-d)/c);this.colorsI[e]=r<=0?m:r>65535?f:u.colors[r]}for(let e=0;e<s[0];++e)this.levelIndex[e]=0;for(let e=0;e<s.length-1;e++)for(let t=s[e];t<s[e+1]+1;++t)this.levelIndex[t]=e;for(let e=s[s.length-1];e<65536;++e)this.levelIndex[e]=s.length-1}};function Le(e){if(0!==e&&-.1<e&&e<.1)return e.toExponential(2);let t=e.toString();return t.split(".")[1]?.length>2?e.toFixed(2):t}function j(e,t){let a={size:e,showBelowMin:t.showBelowMin,showAboveMax:t.showAboveMax,units:t.units,colors:new Uint32Array(e),ticks:[]},{colorMap:r,levels:i,colors:s}=t,n="solid"!==t.fill;if(r){let t=r[0][0],i=(e-1)/(r[r.length-1][0]-t);a.ticks=r.map((([e,a])=>({data:e,dataString:Le(e),color:a,pos:~~((e-t)*i)})));for(let e=0;e<r.length-1;e++){let t=a.ticks[e].pos,i=a.ticks[e+1].pos,s=E(r[e][1]),o=n?E(r[e+1][1]):0;for(let e=t;e<i;++e)a.colors[e]=n?se(s,o,(e-t)/(i-t)):s}return a.colors[e-1]=E(r[r.length-1][1]),a}if(!s||!i)return a;let o=0,l=0,h=-1;for(let t=0;t<e;++t){let r=t*(s.length-1)/e;h!==~~r&&(h=~~r,o=E(s[h]),l=s.length>h+1?E(s[h+1]):o),a.colors[t]=n?se(o,l,r-h):o}a.colors[e-1]=E(s[s.length-1]);let u=i[0],d=(e-1)/(i[i.length-1]-u);return a.ticks=i.map((e=>{let t=~~((e-u)*d);return{data:e,dataString:Le(e),pos:t,color:C(a.colors[t])}})),a}var N=class extends Map{clear(){h("TilesCache.clear()");for(let e of this.values()){if(!e.rd)return;e.rd.gl.deleteTexture(e.rd.vectorTextureU),e.rd.gl.deleteTexture(e.rd.vectorTextureV)}super.clear()}},Qe=2*Math.PI*6378137/256,z=2*Math.PI*6378137/2;function et(e,t){let a=e/z*180,r=t/z*180;return r=180/Math.PI*(2*Math.atan(Math.exp(r*Math.PI/180))-Math.PI/2),[r,a]}function tt(e,t,a){let r=at(a);return[e*r-z,t*r-z]}function at(e){return Qe/2**e}function ie(e,t,a){let[r,i]=et(...tt(e,t,a));return[i,-r]}function _e(e,t){return[256*e,256*t]}function le(e,t,a){return(e+(((t-e)%360+540)%360-180)*a+360)%360}function rt(e,t,a,r,i,s,n,o){switch((e?1:0)|(t?2:0)|(a?4:0)|(r?8:0)){case 0:return 0;case 1:return e;case 2:return t;case 3:a=e,r=t;break;case 4:return a;case 5:t=e,r=a;break;case 6:e=r=t+a>>1;break;case 7:r=t+a>>1;break;case 8:return r;case 9:a=t=e+r>>1;break;case 10:e=t,a=r;break;case 11:a=e+r>>1;break;case 12:e=a,t=r;break;case 13:t=e+r>>1;break;case 14:e=t+a>>1}a=n+o*a,r=n+o*r;let l=le(e=n+o*e,t=n+o*t,i),h=le(a,r,i),u=(le(l,h,s)-n)/o;return u<1?1:u}function Ee(e,t,a,r,i,s,n,o){switch((e?1:0)|(t?2:0)|(a?4:0)|(r?8:0)){case 7:return i+s<1?i*(t-e)+s*(a-e)+e:0;case 14:return i+s<1?0:i*(r-a)+s*(r-t)+t+a-r;case 11:return s<i?(1-i)*(e-t)+s*(r-t)+t:0;case 13:return s<i?0:(1-i)*(a-r)+s*(a-e)+e+r-a;case 15:return i+s<1?i*(t-e)+s*(a-e)+e:i*(r-a)+s*(r-t)+t+a-r;default:return 0}}function Pe(e,t,a){let r=1/2**a.z,i=256*a.x*r-.5,s=256*a.y*r-.5,{raw:n,dmin:o,dmax:l,dmul:h}=t,u={raw:new Uint16Array(66564),dmin:o,dmax:l,dmul:h},{raw:d}=u;for(let t=-1,a=0,l=s-r+1;t<=256;t++,l+=r){let t=Math.floor(l),s=l-t,u=258*t;for(let t=-1,l=i-r+1;t<=256;t++,a++,l+=r){let t=Math.floor(l),r=l-t,i=t+u,c=n[i],m=n[i+1],f=n[i+258],g=n[i+258+1];d[a]=e(c,m,f,g,r,s,o,h)}}return u}function Ae(e,t,a){if(!t)return e;let r=e=>e<0?0:e>254?254:e,i=1/2**t.z,s=256*t.x*i-.5,n=256*t.y*i-.5,{data:o}=e,l=new ImageData(256,256),{data:h}=l;for(let e=0,t=a,l=n;e<256;e++,l+=i){let e=~~r(l),n=l-e,u=256*e;for(let e=0,l=s;e<256;e++,t+=4,l+=i){let e=~~r(l),i=l-e,s=4*(e+u)+a,d=Ee(o[s],o[s+4],o[s+1024],o[s+1024+4],i,n,0,0);h[t]=d>127?255:0}}return l}function Re(e,t){return t?Pe(Ee,e,t):e}function ke(e,t){return t?Pe(rt,e,t):e}function Ue(e,{data:t},a,r){let i="sea"===r,{raw:s}=e;for(let e=a,r=259,n=0;n<256;r+=2,n++)for(let a=0;a<256;a++,r++,e+=4)i===!t[e]&&(s[r]=0);return e}function $e(e){let[t,a]=_e(e.x,e.y),[r,i]=ie(t,a,e.z),[s,n]=ie(t+256,a+256,e.z);return{west:r,north:i,east:s,south:n}}function ce(e,t){let a=e.z-t;return a<=0?{upCoords:e}:{upCoords:{x:e.x>>>a,y:e.y>>>a,z:t},subCoords:{x:e.x&(1<<a)-1,y:e.y&(1<<a)-1,z:a}}}var K=class{constructor(e){this._loadDataFunc=O(Se),this._layer=e}async load(e,t){let a=await this.cacheLoad(e,this._layer.tilesURIs,t);if(!a)return null;let{rawdata:r,subCoords:i,tileType:s}=a,{units:n}=this._layer.currentVariableMeta,o="degree"===n?ke:Re,l=r.map((e=>o(Me(e,this._layer.style.blurRadius),i)));return this._vectorMagnitudesPrepare(l),await this._applyMask(l,e,s,!i&&1===r.length),{data:l,slines:this._createStreamLines(l)}}async cacheLoad(e,t,a){if(!this._checkInsideBoundaries(e))return null;let r=this._checkTypeAndMask(e);if(!r)return null;let{upCoords:i,subCoords:s}=ce(e,this._layer.getCoarseMaxZoom()),n=t.map((e=>G(e,i))),o=Object.assign({},this._layer.wxdatasetManager.wxAPI.requestInit,{signal:a?.signal});return{rawdata:await Promise.all(n.map((e=>this._loadDataFunc(e,o)))),subCoords:s,tileType:r}}clearCache(){this._loadDataFunc.clearCache()}async _applyMask(e,t,a,r){let{style:i}=this._layer;if(("land"===i.mask||"sea"===i.mask)&&"mixed"===a){if(r){let{raw:t,dmin:a,dmax:r,dmul:i}=e[0];e[0]={raw:new Uint16Array(t),dmin:a,dmax:r,dmul:i}}let a,{wxAPI:s}=this._layer.wxdatasetManager;try{let{upCoords:e,subCoords:r}=ce(t,s.maskDepth);a=await s.loadMaskFunc(e),a=Ae(a,r,s.maskChannel)}catch{return i.mask=void 0,void h("Can't load Mask. Masking is disabled")}Ue(e[0],a,s.maskChannel,i.mask)}}_vectorMagnitudesPrepare(e){if(1===e.length)return;e.unshift({raw:new Uint16Array(66564),dmin:0,dmax:0,dmul:0});let[t,a,r]=e;t.dmax=1.42*Math.max(-a.dmin,a.dmax,-r.dmin,r.dmax),t.dmul=(t.dmax-t.dmin)/65535;for(let e=0;e<66564;++e){if(!a.raw[e]||!r.raw[e])continue;let i=a.dmin+a.dmul*a.raw[e],s=r.dmin+r.dmul*r.raw[e];t.raw[e]=Math.sqrt(s*s+i*i)/t.dmul}}_checkTypeAndMask(e){let{mask:t}=this._layer.style;if("land"===t||"sea"===t){let a=this._layer.wxdatasetManager.wxAPI.qtree.check(e);return t===a?void 0:a}return"mixed"}_checkInsideBoundaries(e){let t=this._layer.getBoundaries();if(t?.boundaries180){let a=$e(e),r=e=>!(a.west>e.east||e.west>a.east||a.south>e.north||e.south>a.north);if(!t.boundaries180.some(r))return!1}return!0}_createStreamLines(e){if(3!==e.length)return[];let{style:t}=this._layer;if("none"===t.streamLineColor)return[];let a=[],[r,i,s]=e,n=(t.streamLineSpeedFactor||1)/r.dmax,o=t.addDegrees?.017453292519943*t.addDegrees:0,l=t.streamLineGridStep||64,h=t.streamLineSteps||300;for(let e=0;e<=256;e+=l)for(let t=0;t<=256;t+=l){if(!r.raw[1+t+258*(1+e)])continue;let l=[],u=t,d=e,c=-1,m=0,f=0;for(let e=0;e<=h&&u>=0&&u<=256&&d>=0&&d<=256;e++){e%(h/10)||l.push({x:~~u,y:~~d});let t=1+~~u+258*(1+~~d);if(t!==c){if(!r.raw[t])break;c=t;let e=r.dmin+r.raw[t]*r.dmul,a=i.dmin+i.raw[t]*i.dmul,l=s.dmin+s.raw[t]*s.dmul,h=Math.atan2(a,l)+o;m=n*e*Math.sin(h),f=n*e*Math.cos(h)}u+=m,d-=f}let g=t,p=e;c=-1;for(let e=1;e<=h&&g>=0&&g<=256&&p>=0&&p<=256;e++){e%(h/10)||l.unshift({x:~~g,y:~~p});let t=1+~~g+258*(1+~~p);if(t!==c){if(!r.raw[t])break;c=t;let e=r.dmin+r.raw[t]*r.dmul,a=i.dmin+i.raw[t]*i.dmul,l=s.dmin+s.raw[t]*s.dmul,h=Math.atan2(a,l)+o;m=n*e*Math.sin(h),f=n*e*Math.cos(h)}g-=m,p+=f}l.length>2&&a.push(l)}return a}},J=class{constructor(e){this._layer=e}paint({data:e,ctxFill:t,ctxText:a,ctxStreamLines:r}){let{_layer:i}=this,{units:s}=i.currentVariableMeta,n=new ImageData(256,256),o=new Uint32Array(n.data.buffer);t.clearRect(0,0,256,256),a.clearRect(0,0,256,256),r.clearRect(0,0,256,256),nt(e.data[0],o,i);let l=st(o,e.data[0],i);t.putImageData(n,0,0),ot(l,a,i),ct(e.data,a,i),ut(e.data[0],a,s,i),mt(e,a,i)}getPaintedCanvas(e,t,a){return t?(this.imprintVectorAnimationLinesStep(e,a),e.ctxStreamLines.canvas):e.ctxFill.canvas}imprintVectorAnimationLinesStep({data:e,ctxFill:t,ctxStreamLines:a},r){let{_layer:i}=this;a.clearRect(0,0,256,256),a.drawImage(t.canvas,0,0),0!==e.slines.length&&!i.style.streamLineStatic&&"none"!==i.style.streamLineColor&&dt(e,a,i,r)}};function nt(e,t,{CLUT:a,style:r}){let{raw:i}=e,{colorsI:s}=a;if("none"!==r.fill)for(let e=0,a=0,r=259;e<256;++e,r+=2)for(let e=0;e<256;++e,++a,++r)t[a]=s[i[r]];else t.fill(0)}function st(e,t,{CLUT:a,style:r}){let{raw:i}=t,{levelIndex:s,colorsI:n}=a,o=[];if("none"!==r.isolineColor){let t="#"===r.isolineColor[0]?E(r.isolineColor):0;for(let a=0,l=0;a<256;a+=1)for(let h=0;h<256;h+=1){let u=258*(a+1)+(h+1),d=i[u],c=i[u+1],m=i[u+258];if(!d||!c||!m)continue;let f=s[d],g=s[c],p=s[m];if(f!==g||f!==p){let i=Math.max(f,g,p),s=Math.max(d,c,m),u=256*a+h;switch(r.isolineColor){case"inverted":e[u]=4278190080|~n[s];break;case"fill":e[u]=4278190080|n[s];break;default:e[u]=t}r.isolineText&&!(++l%255)&&h>20&&h<235&&a>20&&a<235&&o.push({x:h,y:a,d:d,dr:c,db:m,mli:i})}}}return o}function ot(e,t,{CLUT:a,style:r}){if(e.length){let i=r.isolineTextSizeEm||1.1;t.font=`${i.toString()}em Sans-serif`,t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";let s=t.measureText("-.0123456789"),n=s.actualBoundingBoxAscent+s.actualBoundingBoxDescent,o=1.5*n,l=s.actualBoundingBoxAscent+(o-n)/2,h=1.1,u=2.5*i,d=r.isolineTextBackground?it:lt;for(let{x:r,y:i,d:s,dr:n,db:c,mli:m}of e){let e=Math.atan2(s-n,c-s);t.save(),t.translate(r,i),t.rotate(e<-1.57||e>1.57?e+3.14:e);let f=a.ticks[m].dataString;d(f,t,{height:o,hOffset:l,wScale:h,radii:u}),t.fillText(f,0,0),t.restore()}}}function it(e,t,a){t.strokeText(e,0,0)}function lt(e,t,{height:a,hOffset:r,wScale:i,radii:s}){let n=t.fillStyle;t.fillStyle=t.strokeStyle;let o=i*t.measureText(e).width;t.beginPath(),t.roundRect(-o/2,-r,o,a,s),t.closePath(),t.fill(),t.fillStyle=n}function ct(e,t,{CLUT:a,style:r}){if(!a.DataToKnots||"none"===r.vectorColor||"none"===r.vectorType)return;if(3!==e.length)throw new Error("data.length !== 3");let[i,s,n]=e;switch(r.vectorType){case"barbs":t.font="40px barbs";break;case"arrows":t.font="50px arrows";break;default:t.font=r.vectorType}t.textAlign="center",t.textBaseline="middle",t.fillStyle=r.vectorColor;let o=r.addDegrees?.017453292519943*r.addDegrees:0;for(let e=16;e<256;e+=32)for(let l=16;l<256;l+=32){let h=l+1+258*(e+1);if(!i.raw[h])continue;let u=Math.atan2(s.dmin+s.raw[h]*s.dmul,n.dmin+n.raw[h]*n.dmul),d=i.dmin+i.raw[h]*i.dmul,c="barbs"!==r.vectorType?.5*r.vectorFactor:.2,m=Math.min(~~(a.DataToKnots(d)*c),25)+65,f=String.fromCharCode(m);switch(r.vectorColor){case"inverted":t.fillStyle=C(~a.colorsI[i.raw[h]]);break;case"fill":t.fillStyle=C(a.colorsI[i.raw[h]])}t.save(),t.translate(l,e),t.rotate(u+o),t.fillText(f,0,0),t.restore()}}function ut(e,t,a,{CLUT:r,style:i}){if("degree"!==a)return;let s=.017453292519943*i.addDegrees;t.font="50px arrows",t.textAlign="center",t.textBaseline="middle",t.fillStyle=i.vectorColor;for(let a=16;a<256;a+=32)for(let n=16;n<256;n+=32){let o=n+1+258*(a+1);if(!e.raw[o])continue;let l=.01745329251*(e.dmin+e.raw[o]*e.dmul+180);switch(i.vectorColor){case"inverted":t.fillStyle=C(~r.colorsI[e.raw[o]]);break;case"fill":t.fillStyle=C(r.colorsI[e.raw[o]])}t.save(),t.translate(n,a),t.rotate(l+s),t.fillText("L",0,0),t.restore()}}function mt(e,t,{CLUT:a,style:r}){let{data:i,slines:s}=e;if(!s.length||!r.streamLineStatic||"none"===r.streamLineColor)return;let n=i[0];t.lineWidth=1,"#"===r.streamLineColor[0]&&(t.strokeStyle=oe(r.streamLineColor));for(let e=s.length;e--;){let i=s[e];for(let e=0;e<i.length-1;++e){let s=i[e],o=i[e+1],l=s.x+1+258*(s.y+1);switch(r.streamLineColor){case"inverted":t.strokeStyle=C(~a.colorsI[n.raw[l]]);break;case"fill":t.strokeStyle=C(a.colorsI[n.raw[l]])}t.beginPath(),t.moveTo(s.x,s.y),t.lineTo(o.x,o.y),t.stroke()}}}function dt(e,t,{CLUT:a,style:r},i){let{data:s,slines:n}=e,o=s[0],l="#"===r.streamLineColor[0]?oe(r.streamLineColor).substring(0,7):"#000000";i>>=5;for(let e=0;e<n.length;++e){let s=n[e],h=s.length-1,u=(i+(1+s[0].x)*(1+s[0].y))%30;for(let e=0;e<h;++e){let i=s[e],n=s[e+1],d=1-(u-e)/h;(d<0||d>1)&&(d=0);let c=(~~(255*d)).toString(16).padStart(2,"0"),m=1+~~(5*(1.2-d));t.lineWidth=m;let f=i.x+1+258*(i.y+1);switch(r.streamLineColor){case"inverted":l=C(~a.colorsI[o.raw[f]]);break;case"fill":l=C(a.colorsI[o.raw[f]])}t.strokeStyle=l+c,t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(n.x,n.y),t.stroke()}}}var Q=class{constructor(e){if(this.tilesRasterCache=new N,this.coarseLevel=0,this._painter=new J(this),this._loader=new K(this),h(`WxLayer.constructor:\n\t\tdatasetName: ${e.wxdatasetManager.datasetName},\n\t\tvariables: ${e.variables.join(", ")},\n\t\twxstyleName: ${e.wxstyleName},\n\t\twxstyle: ${JSON.stringify(e.wxstyle)},\n\t\ttime: ${e.time}`),!e.variables?.length||e.variables.length>2)throw new Error(`datasetName: ${e.wxdatasetManager.datasetName}: only 1 or 2 variables are supported but ${e.variables} was given`);for(let t of e.variables)if(!e.wxdatasetManager.isVariableValid(t))throw new Error(`datasetName: ${e.wxdatasetManager.datasetName}: variable ${t} is not valid`);this.variables=e.variables,this.wxdatasetManager=e.wxdatasetManager,[this.tilesURIs,this._time]=this._createURLsAndTime(e.time);let t=A(),a=t.base,r=e.wxstyleName&&t[e.wxstyleName];this.currentVariableMeta=this._getCurrentVariableMeta(),[this.style,this.CLUT]=this._createStyleAndCLUT({...a,...r,...e.wxstyle})}get nonanimatable(){return h("WxLayer.nonanimatabl()"),this.variables.length<2||this.style.streamLineStatic||"none"===this.style.streamLineColor}getMaxZoom(){return h("WxLayer.getMaxZoom"),this.wxdatasetManager.isInstanced()?this.wxdatasetManager.getInstanceMeta(this.getTime()).maxZoom:this.wxdatasetManager.getMaxZoom()}getCoarseMaxZoom(){return h("WxLayer.getCoarseMaxZoom"),this.getMaxZoom()-this.coarseLevel}getBoundaries(){return this.wxdatasetManager.isInstanced()?this.wxdatasetManager.getInstanceMeta(this.getTime()).boundaries:this.wxdatasetManager.getBoundaries()}getTime(){return h("WxLayer.getTime"),this._time}clearCache(){h("WxLayer.clearCache"),this.tilesRasterCache.clear(),this._loader.clearCache()}getCurrentStyleObjectCopy(){return h("WxLayer.getCurrentStyleObjectCopy"),Object.assign({},this.style)}updateCurrentStyleObject(e){h(`WxLayer.updateCurrentStyleObject ${JSON.stringify(e)}`),[this.style,this.CLUT]=this._createStyleAndCLUT(e)}getTileData(e,t){let a=this.tilesRasterCache.get(R(e));if(!a)return;let r=this._getPixelInfo(t,a.data.data);if(!r)return;let{raw:i,data:s}=r,n=i.map((e=>this.CLUT.colorsI[e])),o=n.map(C),l=s.map((e=>this.CLUT.DataToStyle(e)));return{data:s,raw:i,rgba:n,hexColor:o,inStyleUnits:l,tilePoint:t,styleUnits:this.style.units,dataUnits:this.currentVariableMeta.units}}setURLsAndTime(e){h(`WxLayer.setURLsAndTime time=${e}`),[this.tilesURIs,this._time]=this._createURLsAndTime(e),this.wxdatasetManager.isInstanced()&&(this.currentVariableMeta=this._getCurrentVariableMeta(),[this.style,this.CLUT]=this._createStyleAndCLUT())}getPaintedCanvas(e,t,a){return this._painter.getPaintedCanvas(e,t,a)}async loadTile(e,t){return this._loadCacheDrawTile(e,this.tilesRasterCache,t)}async preloadTime(e,t,a){h(`WxLayer.preloadTime time=${e}`);let[r]=this._createURLsAndTime(e);await Promise.allSettled(t.map((e=>this._loader.cacheLoad(e,r,a))))}async reloadTiles(e,t){h("WxLayer.reloadTiles");let a=new N;await Promise.allSettled(e.map((e=>this._loadCacheDrawTile(e,a,t)))),t?.signal?.aborted?a.clear():(this.tilesRasterCache.clear(),this.tilesRasterCache=a)}async _loadCacheDrawTile(e,t,a){let r=t.get(R(e));if(r)return r;let i=await this._loader.load(e,a);if(!i)return null;let s=Z(256,256),n={ctxFill:s,ctxText:s,ctxStreamLines:2===this.variables.length?Z(256,256):s,data:i};return this._painter.paint(n),t.set(R(e),n),n}_getCurrentVariableMeta(){let e=this.variables.map((e=>{let t=this.wxdatasetManager.getInstanceVariableMeta(e,this._time);if(!t)throw new Error(`datasetName ${this.wxdatasetManager.datasetName}: variable ${e} is not valid`);return t})),{min:t,max:a,units:r,vector:i}=e[0];return this.variables.length>1&&(t=0,a=1.42*Math.max(-e[0].min,e[0].max,-e[1].min,e[1].max)),{min:t,max:a,units:r,vector:i}}_getPixelInfo({x:e,y:t},a){h(`WxLayer._getPixelInfo x=${e} y=${t}`);let r=258*(t+1)+(e+1);if(a?.[0]?.raw?.[r])return{raw:a.map((e=>e.raw[r])),data:a.map((e=>e.raw[r]*e.dmul+e.dmin))}}_createStyleAndCLUT(e){let t=Object.assign({},this.style,e);return[t,this._prepareCLUT(t)]}_prepareCLUT(e){let{min:t,max:a,units:r}=this.currentVariableMeta;return new Y(e,r,[t,a],2===this.variables.length)}_createURLsAndTime(e){let t=this.wxdatasetManager.getNearestValidTime(e);return[this.variables.map((e=>this.wxdatasetManager.createURI(e,t))),t]}},ee=class{constructor(e,t){this.type="custom",this.dataType="raster",this.tileSize=256,this._listeners={},h(`FrameworkParentClass.constructor frwOptions: ${JSON.stringify(e)}`),this.id=e.id,this.maxzoom=e.maxzoom,this.bounds=e.bounds,this.attribution=e.attribution,this.opacity=e.opacity,this._layer=new Q(t)}on(e,t){var a;((a=this._listeners)[e]||(a[e]=[])).push(t)}off(e,t){this._listeners[e]=this._listeners[e]?.filter((e=>e!==t))}once(e,t){let a=(...r)=>{t(...r),this.off(e,a)};this.on(e,a)}fire(e,t){this._listeners[e]?.forEach((async e=>e(t)))}},Ne=Ie(ee),B=class extends Ne{constructor(e,t){h(`WxTileSource.constructor (id=${t.id})`),super(t,e)}getLayerInfoAtLatLon(e,t){let a=t.transform.worldSize,r=Math.round(Math.log2(a)-8),i=a/(2<<r-1),s=t.transform.project(e),n=s.div(i);n.x=Math.floor(n.x),n.y=Math.floor(n.y);let o=s.sub(n.mult(i)).mult(255/i).round();return this._layer.getTileData({x:n.x,y:n.y,z:r},o)}async _reloadVisible(e,t=!0){if(h(`WxTileSource _reloadVisible (${this.id})`),await this._layer.reloadTiles(this.coveringTiles(),e),!e?.signal?.aborted)return t?this._redrawTiles():Promise.resolve();h(`WxTileSource _reloadVisible (${this.id}) aborted`)}coveringTiles(){return[]}update(){}async loadTile(e,t){let a=await this._loadTileHelper(e,t);return a?this._layer.getPaintedCanvas(a,this._animation,this._animationSeed):new ImageData(1,1)}onRemove(e){h(`WxTileSource onRemove (${this.id})`),this._animation=!1,this.clearCache()}},te=class{constructor({datasetName:e,datasetCurrentInstance:t,instanced:a,datasetCurrentMeta:r,metas:i,wxAPI:s}){this.datasetName=e,this._instanced=a,this._datasetCurrentInstance=t,this._datasetCurrentMeta=r,this._metas=i,this.wxAPI=s,h(`WxDataSetManager.constructor: ${this.datasetName}`)}getNearestValidTime(e=Date()){h(`WxDataSetManager.getValidTime: ${this.datasetName}, ${e}`);let t=this.getAllTimes();if(""===e)return t[t.length-1];if("string"==typeof e){let a=t.indexOf(e);if(-1!==a)return t[a]}if("number"==typeof e){if(e<=0)return t[0];if(e<t.length)return t[e]}let a=new Date(e).getTime();return Number.isNaN(a)?t[t.length-1]:t.find((e=>new Date(e).getTime()>=a))||t[t.length-1]}getAllTimes(){return h(`WxDataSetManager.getTimes: ${this.datasetName}`),this._instanced||this._datasetCurrentMeta.times}getAllVariables(){return h(`WxDataSetManager.getVariables: ${this.datasetName}`),this._datasetCurrentMeta.variables}getVariableCurrentMeta(e){return h(`WxDataSetManager.getVariableCurrentMeta: ${this.datasetName}, ${e}`),this._datasetCurrentMeta.variablesMeta[e]}getInstanceVariableMeta(e,t){return h(`WxDataSetManager.getInstanceVariableMeta: ${this.datasetName}, ${e}, ${t}`),this.getInstanceMeta(t).variablesMeta[e]}getMaxZoom(){return h(`WxDataSetManager.getMaxZoom: ${this.datasetName}`),this._datasetCurrentMeta.maxZoom}getBoundaries(){return h(`WxDataSetManager.getBoundaries: ${this.datasetName}`),this._datasetCurrentMeta.boundaries}getInstanceMeta(e){return h(`WxDataSetManager.getInstanceMeta: ${this.datasetName}, ${e}`),e&&this._metas?.get(e)||this._datasetCurrentMeta}createURI(e,t,a="webp"){if(h(`WxDataSetManager.createURI: ${this.datasetName}, ${e}, ${t}`),!this.isVariableValid(e))throw new Error(`in dataset ${this.datasetName} variable ${e} not found`);let r=this._instanced?t:this._datasetCurrentInstance;return`${this.wxAPI.dataServerURL+this.datasetName}/${r}/${e}/${t}/{z}/{x}/{y}.${a}`}isVariableValid(e){return h(`WxDataSetManager.checkVariableValid: ${this.datasetName}, ${e}`),void 0!==this._datasetCurrentMeta.variablesMeta[e]}async update(){let e=await this.wxAPI.createDatasetManagerOptions(this.datasetName);this._datasetCurrentInstance=e.datasetCurrentInstance,this._instanced=e.instanced,this._datasetCurrentMeta=e.datasetCurrentMeta,this._metas=e.metas}isInstanced(){return void 0!==this._instanced}_checkCombineVariableIfVector(e){h(`WxDataSetManager.checkCombineVariableIfVector: ${this.datasetName}, ${e}`);let t=this._datasetCurrentMeta.variablesMeta[e];if(!t)throw new Error(`in dataset ${this.datasetName} variable ${e} not found`);return t.vector||[e]}},V=class extends te{createSourceLayer(e,t){h(`WxDataSetManager.createSourceLayer: ${this.datasetName}`);let a={...e,variables:this._checkCombineVariableIfVector(e.variable),wxdatasetManager:this};return new B(a,t)}},ue=class extends q{async createDatasetManager(e){let t=await this.createDatasetManagerOptions(e);return new V(t)}},Be="#version 100\nprecision highp float;\n#define PI 3.1415926538\nuniform sampler2D u_noiseTexture;uniform sampler2D u_tileTexture;uniform float u_opacity;uniform float u_Lmax;uniform sampler2D u_V;uniform float u_Vmul;uniform float u_Vmin;uniform sampler2D u_U;uniform float u_Umul;uniform float u_Umin;uniform float u_vectorFieldFactor;uniform float u_animationTimePosition;uniform float u_animationIntensity;uniform float u_wavesCount;varying vec2 v_pos0;varying vec2 v_posV;vec3 noise(vec2 uv){return texture2D(u_noiseTexture,uv).rgb;}void main(){vec4 color=texture2D(u_tileTexture,v_pos0)*u_opacity;if(u_vectorFieldFactor<0.2){gl_FragColor=color;return;}float U=texture2D(u_U,v_posV).a;float V=texture2D(u_V,v_posV).a;vec2 vectorValueAtPixel=vec2(-(U*u_Umul+u_Umin),V*u_Vmul+u_Vmin)/u_Lmax;float vectorValueAtPixelLength=length(vectorValueAtPixel);if(vectorValueAtPixelLength<0.001){gl_FragColor=color;return;}vec3 wavesCumulativeNoise=vec3(0.0);float d=1.0/u_wavesCount;for(float i=0.0;i<10.0;i++){if(i>=u_wavesCount)break;float phase=fract(i*d+u_animationTimePosition);float intensity=1.-2.*abs(phase-0.5);vec3 noiseValue=noise(v_pos0+vectorValueAtPixel*phase*u_vectorFieldFactor);wavesCumulativeNoise+=(noiseValue-0.5)*intensity;}wavesCumulativeNoise*=vectorValueAtPixelLength*u_animationIntensity/u_wavesCount;color.xyz*=1.0+wavesCumulativeNoise;gl_FragColor=color;}",Ve="#version 100\nuniform mat4 u_matrix;attribute vec2 a_pos;attribute vec2 a_texture_pos;varying vec2 v_pos0;varying vec2 v_posV;void main(){gl_Position=u_matrix*vec4(a_pos,0,1);v_pos0=a_texture_pos/8192.0;v_posV=v_pos0*(256.0/258.0)+vec2(1.0/258.0,1.0/258.0);}",me=class{constructor(){this.boundPaintVertexBuffers=[]}bind(e,t,a,r,i,s,n,o){this.context=e;let l=this.boundPaintVertexBuffers.length!==r.length;for(let e=0;!l&&e<r.length;e++)this.boundPaintVertexBuffers[e]!==r[e]&&(l=!0);let h=!this.vao||this.boundProgram!==t||this.boundLayoutVertexBuffer!==a||l||this.boundIndexBuffer!==i||this.boundVertexOffset!==s||this.boundDynamicVertexBuffer!==n||this.boundDynamicVertexBuffer2!==o;!e.extVertexArrayObject||h?this.freshBind(t,a,r,i,s,n,o):(e.bindVertexArrayOES.set(this.vao),n&&n.bind(),i?.dynamicDraw&&i.bind(),o&&o.bind())}freshBind(e,t,a,r,i,s,n){let o=0,l=e.numAttributes,h=this.context,u=h.gl;if(h.extVertexArrayObject)this.vao&&this.destroy(),this.vao=h.extVertexArrayObject.createVertexArrayOES(),h.bindVertexArrayOES.set(this.vao),this.boundProgram=e,this.boundLayoutVertexBuffer=t,this.boundPaintVertexBuffers=a,this.boundIndexBuffer=r,this.boundVertexOffset=i,this.boundDynamicVertexBuffer=s,this.boundDynamicVertexBuffer2=n;else{o=h.currentNumAttributes||0;for(let e=l;e<o;e++)0!==e&&u.disableVertexAttribArray(e)}t.enableAttributes(u,e);for(let t of a)t.enableAttributes(u,e);t.bind(),t.setVertexAttribPointers(u,e,i);for(let t of a)t.bind(),t.setVertexAttribPointers(u,e,i);r&&r.bind(),h.currentNumAttributes=l}destroy(){this.vao&&(this.context.extVertexArrayObject.deleteVertexArrayOES(this.vao),this.vao=null)}},de=class{fill(e,t){for(let a in this){if(!a.startsWith("u_"))continue;let r=e.getUniformLocation(t,a);r?this[a]=r:console.log(`uniform not found: ${a}`)}}},fe=class extends de{constructor(){super(...arguments),this.u_matrix={},this.u_opacity={},this.u_tileTexture={},this.u_noiseTexture={},this.u_animationTimePosition={},this.u_vectorFieldFactor={},this.u_animationIntensity={},this.u_wavesCount={},this.u_Lmax={},this.u_U={},this.u_Umul={},this.u_Umin={},this.u_V={},this.u_Vmul={},this.u_Vmin={}}},xe=class{constructor(e,t,a=1){this.id=e,this.sourceID=t,this.opacity=a,this.type="custom",this.renderingMode="2d",this.program=null,this.attributes={a_pos:0,a_texture_pos:0},this.uniforms=new fe,this.noiseTexture=null,this.noiseTexturePow=5}onRemove(e,t){e.style?._layers?.[this.id]?.source&&delete e.style._layers[this.id].source,t.deleteTexture(this.noiseTexture),t.deleteProgram(this.program);for(let e of this.map.painter.mercatorBoundsSegments.get())delete e.vaos[this.id]}checkCreateNoiseTexture(e,t){t===this.noiseTexturePow&&this.noiseTexture||(e.deleteTexture(this.noiseTexture),this.noiseTexture=pt(e,t),this.noiseTexturePow=t)}onAdd(e,t){this.map=e,this.program=ht(t),this.attributes={a_pos:t.getAttribLocation(this.program,"a_pos"),a_texture_pos:t.getAttribLocation(this.program,"a_texture_pos")},this.uniforms.fill(t,this.program),e.style._layers[this.id].source=this.sourceID}render(e){if(!this.program)return;let t=this.map.style._otherSourceCaches[this.sourceID],a=t.getSource()._implementation,r=t.getVisibleCoordinates().reverse();if(!r.length)return;e.useProgram(this.program);let i=a.getCurrentStyleObjectCopy(),s=this.id,n=this.map.painter,o=a.getCache(),l=n.context,h=r.length&&r[0].overscaledZ||0,u={test:{func:519,mask:0},ref:0,mask:0,fail:7680,depthFail:7680,pass:7680},d={enable:!1,mode:1029,frontFace:2305},c=a.getCurrentVariableMeta().vector&&i.gl?.animationSpeed&&i.gl.animationSpeed>.2;c&&this.checkCreateNoiseTexture(e,i.gl?.noiseTexturePow||5);for(let a of r){let r=t.getTile(a);r.registerFadeDuration(300);let m=n.depthModeForSublayer(a.overscaledZ-h,!0,e.LESS),f=n.colorModeForRenderPass();l.setDepthMode(m),l.setStencilMode(u),l.setColorMode(f),l.setCullFace(d),e.uniformMatrix4fv(this.uniforms.u_matrix,!1,a.projMatrix),e.uniform1i(this.uniforms.u_tileTexture,0),e.uniform1f(this.uniforms.u_opacity,this.opacity);let g=o.get(R(a.canonical));if(3===g?.data.data.length&&c){if(!g.rd){let t=Fe(e,e.TEXTURE1,g.data.data[1].raw),a=Fe(e,e.TEXTURE2,g.data.data[2].raw);g.rd={vectorTextureU:t,vectorTextureV:a,gl:e}}e.uniform1f(this.uniforms.u_Lmax,g.data.data[0].dmax),l.activeTexture.set(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,g.rd.vectorTextureU),e.uniform1i(this.uniforms.u_U,1),e.uniform1f(this.uniforms.u_Umin,g.data.data[1].dmin),e.uniform1f(this.uniforms.u_Umul,65535*g.data.data[1].dmul),l.activeTexture.set(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,g.rd.vectorTextureV),e.uniform1i(this.uniforms.u_V,2),e.uniform1f(this.uniforms.u_Vmin,g.data.data[2].dmin),e.uniform1f(this.uniforms.u_Vmul,65535*g.data.data[2].dmul);let t=i.gl?.animationSpeed||1,a=Date.now()%1e4/5e3*t;e.uniform1f(this.uniforms.u_animationTimePosition,a),e.uniform1f(this.uniforms.u_vectorFieldFactor,i.gl?.vectorFieldFactor||1),e.uniform1f(this.uniforms.u_animationIntensity,i.gl?.animationIntensity||5),e.uniform1f(this.uniforms.u_wavesCount,i.gl?.wavesCount||4),l.activeTexture.set(e.TEXTURE3),e.bindTexture(e.TEXTURE_2D,this.noiseTexture),e.uniform1i(this.uniforms.u_noiseTexture,3)}else e.uniform1f(this.uniforms.u_vectorFieldFactor,0);l.activeTexture.set(e.TEXTURE0),r.texture.bind(e.LINEAR,e.CLAMP_TO_EDGE,e.LINEAR_MIPMAP_NEAREST);let p=n.mercatorBoundsBuffer,v=n.quadTriangleIndexBuffer,x=n.mercatorBoundsSegments,y=3;for(let t of x.get()){let a,r=t.vaos||{};t.vaos||(t.vaos=r),r[s]?a=r[s]:(a=new me,r[s]=a),a.bind(l,this,p,[],v,t.vertexOffset,[],[]),e.drawElements(e.TRIANGLES,t.primitiveLength*y,e.UNSIGNED_SHORT,t.primitiveLength*y*t.primitiveOffset)}}c&&this.map.triggerRepaint()}};function Fe(e,t,a){let r,i=e.createTexture();if(!i)throw new Error("Unable to create texture");if(e.activeTexture(t),e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.LUMINANCE_ALPHA,258,258,0,e.LUMINANCE_ALPHA,e.UNSIGNED_BYTE,new Uint8Array(a.buffer)),r=e.getError(),r)throw new Error(`GL error: ${r}`);if(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),r=e.getError(),r)throw new Error(`GL error: ${r}`);if(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),r=e.getError(),r)throw new Error(`GL error: ${r}`);if(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),r=e.getError(),r)throw new Error(`GL error: ${r}`);if(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),r=e.getError(),r)throw new Error(`GL error: ${r}`);return i}function Xe(e,t,a){let r,i=e.createShader(a);if(!i)throw new Error(`Could not create shader: GlError=${e.getError()}`);if(e.shaderSource(i,t),r=e.getError(),r)throw new Error(`Could not set shader source: GlError=${r}`);if(e.compileShader(i),r=e.getError(),r)throw new Error(`Could not compile shader: GlError=${r}`);if(console.log("Shader STATUS:",e.getShaderParameter(i,e.COMPILE_STATUS)),!e.getShaderParameter(i,e.COMPILE_STATUS))throw new Error(`Could not compile vertex program: ${e.getShaderInfoLog(i)}`);return console.log("Shader compiled:",e.getShaderInfoLog(i)),i}function ht(e){let t=e.createProgram();if(!t)throw new Error(`Could not create WebGL program: GlError=${e.getError()}`);if(e.attachShader(t,Xe(e,Ve,e.VERTEX_SHADER)),e.attachShader(t,Xe(e,Be,e.FRAGMENT_SHADER)),e.linkProgram(t),e.validateProgram(t),!e.getProgramParameter(t,e.LINK_STATUS))throw new Error(`Could not link WebGL program: ${e.getProgramInfoLog(t)}`);return t}function pt(e,t){let a=2**Math.max(4,Math.min(t,8)),r=Uint8Array.from({length:a*a},(()=>256*Math.random())),i=e.createTexture();if(!i)throw new Error(`Could not create noise texture: GlError=${e.getError()}`);return e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.LUMINANCE,a,a,0,e.LUMINANCE,e.UNSIGNED_BYTE,new Uint8Array(r)),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),i}var he=class{constructor(e=[]){this._sources=new Map;for(let t of e)this.addSource(t)}async setTime(e,t){let a=Array.from(this._sources.values());await Promise.all(a.map((a=>a.setTime(e,t,!1)))),await Promise.all(a.map((e=>e._redrawTiles())))}async preloadTime(e,t){let a=Array.from(this._sources.values());await Promise.all(a.map((a=>a.preloadTime(e,t))))}async preloadTimes(e,t){let a=Array.from(this._sources.values());for(let r of e){if(t?.signal?.aborted)return;await Promise.all(a.map((e=>e.preloadTime(r,t))))}}async preloadTimesRasterize(e,t){let a=Array.from(this._sources.values());for(let r of e){if(t?.signal?.aborted)return;await Promise.all(a.map((e=>e.setTime(r,t,!1))))}}addSource(e){this._sources.set(e.id,e)}removeSource(e){"string"==typeof e?this._sources.delete(e):this._sources.delete(e.id)}clear(){this._sources.clear()}},pe=class{constructor(e,t,a){this.wxapi=e,this._busy=!1;let r=document.createElement("div");r.className="mapboxgl-ctrl leaflet-control",r.style.borderStyle="solid",r.style.borderColor="#000",r.style.backgroundColor="#aaaaaaaa",r.style.padding="5px",r.style.display="flex",r.style.flexDirection="column",this._div=r;let i=document.createElement("label");i.innerText="Dataset",r.appendChild(i),this.datasets=document.createElement("select"),r.appendChild(this.datasets),this.fillDatasets(t,a),this.datasets.addEventListener("change",(async()=>{if(this._busy)return;this.setBusy(!0);let e=this.datasets.value;await this.fillVariables();let t=this.variables.value;await(this.onchange?.(this.datasets.value,this.variables.value)),this.datasets.value=e,this.variables.value=t,this.setBusy(!1)}));let s=document.createElement("label");s.innerText="Variable",r.appendChild(s),this.variables=document.createElement("select"),r.appendChild(this.variables),this.variables.addEventListener("change",(async()=>{if(this._busy)return;this.setBusy(!0);let e=this.variables.value;await(this.onchange?.(this.datasets.value,this.variables.value)),this.variables.value=e,this.setBusy(!1)})),this.datasets.value=t||"",this.variables.value=a||""}setBusy(e){this._busy=e,this._div.style.backgroundColor=e?"yellow":"lightgray"}async fillDatasets(e,t){this.datasets.options.length=0;let a=await this.wxapi.getAllDatasetsNames();for(let e of a){let t=document.createElement("option");t.value=e,t.text=e,this.datasets.appendChild(t)}e&&(this.datasets.value=e),await this.fillVariables(t)}async fillVariables(e){this.variables.options.length=0;let t=this.datasets.value,a=await this.wxapi.getDatasetAllVariables(t);if(a)for(let e of a){let t=document.createElement("option");t.value=e,t.text=e,this.variables.appendChild(t)}e&&this.variables.options.length&&(this.variables.value=e)}onAdd(){return this._div}onRemove(){this._div.parentNode?.removeChild(this._div)}extender(){return{onAdd:()=>this.onAdd(),onRemove:()=>this.onRemove()}}},ge=class{constructor(){this.pos={lng:0,lat:0};let e=document.createElement("div");e.className="mapboxgl-ctrl leaflet-control",e.style.borderStyle="solid",e.style.borderColor="#000",e.style.backgroundColor="#aaaaaaaa",e.style.padding="5px",this.div=e}onAdd(){return this.div}onRemove(){this.div.parentNode?.removeChild(this.div)}update(e,t,a){if(a&&(this.pos=a),!e)return void(this.div.innerHTML="");let{min:r,max:i,units:s}=e.getCurrentVariableMeta(),{datasetName:n}=e.wxdatasetManager,o=e.wxdatasetManager.getInstanceMeta(e.getTime()),{sourceID:l,baseAtmosphericModel:h,model:u}=o;this.div.innerHTML=`lnglat=(${this.pos.lng.toFixed(2)}, ${this.pos.lat.toFixed(2)})<br>`,this.div.innerHTML+=l&&`sourceID=${l}<br>`||"",this.div.innerHTML+=h&&`baseAtmosphericModel=${h}<br>`||"",this.div.innerHTML+=u&&`model=${u}<br>`||"",this.div.innerHTML+=`dataset=${n}<br>\n\t\tvariables=${e.getVariablesNames()}<br>\n\t\ttime=${e.getTime()}<br>\n\t\tmin=${r.toFixed(2)} ${s}, max=${i.toFixed(2)} ${s}<br>`;let d=e.getLayerInfoAtLatLon(this.pos,t);this.div.innerHTML+=d?`style=${d.inStyleUnits.map((e=>e.toFixed(2)))} ${d.styleUnits}<br>\n\t\t\tsource=${d.data.map((e=>e.toFixed(2)))} ${d.dataUnits}<br>`:"style=outside<br>source=outside<br>"}extender(){return{onAdd:()=>this.onAdd(),onRemove:()=>this.onRemove()}}},ye=class{constructor(){let e=document.createElement("div");e.className="mapboxgl-ctrl leaflet-control",e.style.borderStyle="solid",e.style.borderColor="#000",e.style.backgroundColor="#aaaaaaaa",e.style.padding="5px",this._div=e,this._canvas=document.createElement("canvas"),this._canvas.width=600,this._canvas.height=40,e.appendChild(this._canvas)}onAdd(){return this._div}onRemove(){this._div.parentNode?.removeChild(this._div)}drawLegend(e){let{_canvas:t}=this,{width:a,height:r}=t,i=16+r>>2,s=j(a-50,e),n=t.getContext("2d");if(!n)throw new Error("Failed to get 2D context from canvas");let o=n.createImageData(a,r),l=new Uint32Array(o.data.buffer);l.fill(-1);let h=2+2*a,u=i>>1;if(s.showBelowMin){let e=s.colors[0];if(e)for(let t=0;t<u;++t)for(let r=u;r<u+t;++r)l[h+t+r*a]=e,l[h+t+(2*u-r)*a]=e}for(let e=0;e<s.size;++e)for(let t=0;t<i;++t)s.colors[0]&&(l[2+e+u+(t+2+1)*a]=s.colors[e]);if(s.showAboveMax){let e=s.colors[s.colors.length-1];if(e)for(let t=0;t<=u;++t)for(let r=u;r<u+t;++r)l[h+2*u+s.size-t+r*a]=e,l[h+2*u+s.size-t+(2*u-r)*a]=e}n.putImageData(o,0,0),n.font="8px sans-serif",n.beginPath();for(let e of s.ticks)n.strokeStyle="#000",n.moveTo(e.pos+u+2+1,5),n.lineTo(e.pos+u+2+1,i),n.fillText(e.dataString,e.pos+u+2+1,i+11);n.font="12px sans-serif",n.fillText(`(${s.units})`,13,r-5),n.stroke(),n.strokeStyle="#888",n.strokeRect(1,1,a-3,r-2)}clear(){let{_canvas:e}=this,{width:t,height:a}=e,r=e.getContext("2d");if(!r)throw new Error("Failed to get 2D context from canvas");r.clearRect(0,0,t,a)}extender(){return{onAdd:()=>this.onAdd(),onRemove:()=>this.onRemove()}}},be=class{constructor(){this.parent=document.createElement("div"),this.parent.className="mapboxgl-ctrl leaflet-control",this.parent.style.borderStyle="solid",this.parent.style.borderColor="#000",this.parent.style.backgroundColor="#aaaaaaaa",this.parent.style.padding="5px",this.parent.onmousemove=this.parent.ondblclick=this.parent.onclick=e=>e.stopPropagation?.();let{base:e}=A();this.styleBase=e;let t=I(this.parent,"div",{onclick:onwheel,ondblclick:onwheel,onwheel:onwheel,onmousedown:onmousedown,onmouseup:onmouseup}),a=I(t,"button",{id:"customStyleButton",style:"height: 1.5em; background-color: gray",innerText:"Custom Style"}),r=I(t,"div",{id:"customStyleDiv",style:"display: none; border-color: black; border-style: solid; border-width: 2px; background-color: rgba(135, 206, 250, 0.8)"});a.addEventListener("click",(()=>{"none"!==r.style.display?(r.style.display="none",a.innerHTML="show Custom Style Editor"):(r.style.display="flex",a.innerHTML="update Custom Style & Hide")})),this.editorTextAreaEl=I(r,"textarea",{id:"customStyleTextArea",style:"width: 20vw;"}),this.editorTextAreaEl.readOnly=!0,this.editorDivEl=I(r,"div");let i=(e,t=!0)=>{I(this.editorDivEl,"label",{htmlFor:e,id:`${e}Label`,className:`${e}LabelClass`,textContent:e.replace(/Input|Select$/i,"")}),t&&I(this.editorDivEl,"br",{})},s=({id:e,type:t,min:a,max:r,step:s,onEvent:n="change",br:o=!0})=>{let l=I(this.editorDivEl,"input",{id:e,className:`${e}Class`,type:t,min:a,max:r,step:s});return"none"!==n&&l.addEventListener(n,(()=>this._onDivChange())),i(e,o),l},n=({id:e,opts:t,onEvent:a="change",br:r=!0})=>{let s=I(this.editorDivEl,"select",{id:e,className:`${e}Class`});"none"!==a&&s.addEventListener(a,(()=>this._onDivChange()));for(let e of t)s.options.add(I(s,"option",{value:e,text:e}));return i(e,r),s.selectedIndex=0,s},o=e=>{let t=n({id:`${e}Select`,br:!1,opts:["inverted","fill","none","custom"]}),a=s({id:`${e}Input`,type:"color",onEvent:"none"});return a.addEventListener("change",(()=>{t.value="custom",this._onDivChange()})),[t,a]};this.parentInput=s({id:"parentInput",type:"text"}),this.nameInput=s({id:"nameInput",type:"text"}),this.fillSelect=n({id:"fillSelect",opts:["gradient","solid","none"]}),[this.isolineColorSelect,this.isolineColorInput]=o("isolineColor"),this.isolineTextInput=s({id:"isolineTextInput",type:"checkbox"}),this.vectorFactorInput=s({id:"vectorFactorInput",type:"number",min:"0.1",max:"10",step:"0.1"}),this.vectorTypeSelect=n({id:"vectorTypeSelect",opts:["arrows","barbs","none"]}),[this.vectorColorSelect,this.vectorColorInput]=o("vectorColor"),[this.streamLineColorSelect,this.streamLineColorInput]=o("streamLineColor"),this.streamLineSpeedFactorInput=s({id:"streamLineSpeedFactorInput",type:"range",onEvent:"input",min:"0.1",max:"10",step:"0.1"}),this.streamLineStaticInput=s({id:"streamLineStaticInput",type:"checkbox"}),this.showBelowMinInput=s({id:"showBelowMinInput",type:"checkbox"}),this.showAboveMaxInput=s({id:"showAboveMaxInput",type:"checkbox"}),this.colorSchemeSelect=n({id:"colorSchemeSelect",opts:Object.keys(U()),onEvent:"none"}),this.colorSchemeSelect.addEventListener("change",(()=>{let{colors:e,...t}=this.getStyle(),a=t;this._setStyleToTextArea(a),this.colorsInput.value="",this._onDivChange()})),this.colorsInput=s({id:"colorsInput",type:"text"}),this.colorMapInput=s({id:"colorMapInput",type:"text"}),this.levelsInput=s({id:"levelsInput",type:"text"}),this.blurRadiusInput=s({id:"blurRadiusInput",type:"range",onEvent:"input",min:"0",max:"10",step:"1"}),this.addDegreesInput=s({id:"addDegreesInput",type:"number",min:"0",max:"360",step:"1"}),this.unitsInput=s({id:"unitsInput",type:"text"}),this.extraUnitsInput=s({id:"extraUnitsInput",type:"text"}),this.maskSelect=n({id:"maskSelect",opts:["none","sea","land"]}),this.animationSpeed=s({id:"animationSpeed",type:"range",onEvent:"input",min:"0.1",max:"10",step:"0.1"}),this.noiseTexturePow=s({id:"noiseTexturePow",type:"range",onEvent:"input",min:"5",max:"8",step:"1"}),this.vectorFieldFactor=s({id:"vectorFieldFactor",type:"range",onEvent:"input",min:"0.1",max:"3",step:"0.1"}),this.animationIntensity=s({id:"animationIntensity",type:"range",onEvent:"input",min:"0.1",max:"10",step:"0.1"}),this.wavesCount=s({id:"wavesCount",type:"range",onEvent:"input",min:"2",max:"10",step:"1"})}extender(){return{onAdd:()=>this.onAdd(),onRemove:()=>this.onRemove()}}onAdd(){return this.parent}onRemove(){this.parent.parentNode?.removeChild(this.parent)}getStyle(){return this._getStyleFromDiv()}setStyle(e){if(e.colorMap){let{colors:t,levels:a,...r}=e;this._setStyleToDiv(r)}else this._setStyleToDiv(e);this._setStyleToTextArea(this._getStyleFromDiv())}_getStyleFromDiv(){let e=e=>{try{return this[e].value?JSON.parse(this[e].value):void 0}catch(t){return void console.log(e," : parsing error: ",t)}},t=(e,t)=>"custom"===e.value?t.value:e.value||void 0;return{parent:this.parentInput.value||void 0,name:this.nameInput.value||void 0,fill:this.fillSelect.value||void 0,isolineColor:t(this.isolineColorSelect,this.isolineColorInput),isolineText:this.isolineTextInput.checked,vectorType:this.vectorTypeSelect.value||void 0,vectorColor:t(this.vectorColorSelect,this.vectorColorInput),vectorFactor:+this.vectorFactorInput.value,streamLineColor:t(this.streamLineColorSelect,this.streamLineColorInput),streamLineSpeedFactor:+this.streamLineSpeedFactorInput.value,streamLineStatic:this.streamLineStaticInput.checked,showBelowMin:this.showBelowMinInput.checked,showAboveMax:this.showAboveMaxInput.checked,colorScheme:this.colorSchemeSelect.value||void 0,colors:e("colorsInput"),colorMap:e("colorMapInput"),levels:e("levelsInput"),blurRadius:+this.blurRadiusInput.value,addDegrees:+this.addDegreesInput.value,units:this.unitsInput.value||void 0,extraUnits:e("extraUnitsInput"),mask:this.maskSelect.value||void 0,gl:{animationSpeed:+this.animationSpeed.value||void 0,noiseTexturePow:+this.noiseTexturePow.value||void 0,vectorFieldFactor:+this.vectorFieldFactor.value||void 0,animationIntensity:+this.animationIntensity.value||void 0,wavesCount:+this.wavesCount.value||void 0}}}_setStyleToTextArea(e){this.editorTextAreaEl.value=JSON.stringify(ve(e),null,2)}_setStyleToDiv(e){this.parentInput.value=e.parent||"",this.nameInput.value=e.name||"",this.fillSelect.value=e.fill||"",this.isolineColorSelect.value="#"===e.isolineColor?.[0]?"custom":e.isolineColor||"",this.isolineColorInput.value="#"===e.isolineColor?.[0]?e.isolineColor:"#000000",this.isolineTextInput.checked=e.isolineText||!1,this.vectorTypeSelect.value=e.vectorType||"",this.vectorColorSelect.value="#"===e.vectorColor?.[0]?"custom":e.vectorColor||"",this.vectorColorInput.value="#"===e.vectorColor?.[0]?e.vectorColor:"#000000",this.vectorFactorInput.value=e.vectorFactor?.toString()||"1",this.streamLineColorSelect.value="#"===e.streamLineColor?.[0]?"custom":e.streamLineColor||"",this.streamLineColorInput.value="#"===e.streamLineColor?.[0]?e.streamLineColor:"#000000",this.streamLineSpeedFactorInput.value=e.streamLineSpeedFactor?.toString()||"1",this.streamLineStaticInput.checked=e.streamLineStatic||!1,this.showBelowMinInput.checked=e.showBelowMin||!1,this.showAboveMaxInput.checked=e.showAboveMax||!1,this.colorSchemeSelect.value=e.colorScheme||"",this.colorsInput.value=e.colors?.length?JSON.stringify(e.colors):"",this.colorMapInput.value=e.colorMap?.length?JSON.stringify(e.colorMap):"",this.levelsInput.value=e.levels?.length?JSON.stringify(e.levels.map((e=>+e.toFixed(2)))):"",this.blurRadiusInput.value=e.blurRadius?.toString()||"",this.addDegreesInput.value=e.addDegrees?.toString()||"",this.unitsInput.value=e.units||"",this.extraUnitsInput.value=e.extraUnits?JSON.stringify(e.extraUnits):"",this.maskSelect.value=e.mask||"",e.gl?.animationSpeed&&(this.animationSpeed.value=e.gl.animationSpeed.toString()),e.gl?.noiseTexturePow&&(this.noiseTexturePow.value=e.gl.noiseTexturePow.toString()),e.gl?.vectorFieldFactor&&(this.vectorFieldFactor.value=e.gl.vectorFieldFactor.toString()),e.gl?.animationIntensity&&(this.animationIntensity.value=e.gl.animationIntensity.toString()),e.gl?.wavesCount&&(this.wavesCount.value=e.gl.wavesCount.toString())}_onDivChange(){let e=this._getStyleFromDiv();for(let t of Object.keys(e))(void 0===e[t]||""===e[t]||0===e[t].length)&&delete e[t];this._setStyleToTextArea(e),this.onchange?.(this.getStyle())}};function I(e,t,a){let r=document.createElement(t);return Object.assign(r,a),e?.appendChild(r),r}function ve(e){return Array.isArray(e)?e.map(ve):"object"==typeof e&&null!==e?Object.keys(e).sort(((e,t)=>{let a=e.toUpperCase(),r=t.toUpperCase();return a===r?0:a>r?1:-1})).reduce(((t,a)=>(t[a]=ve(e[a]),t)),{}):e}var Te=class{constructor(e,t){this.delay=e,this.wxsource=t,this.onchange=()=>{};let a=document.createElement("div");a.className="mapboxgl-ctrl leaflet-control",a.style.borderStyle="solid",a.style.borderColor="#000",a.style.backgroundColor="#aaaaaaaa",a.style.padding="5px",a.style.display="flex",a.style.flexDirection="column",this._div=a,a.innerText="Time animation",this.buttonPlayStop=document.createElement("button"),a.appendChild(this.buttonPlayStop),this.timesEl=document.createElement("select"),a.appendChild(this.timesEl),this.timesEl.onchange=async()=>{"yellow"!==this.timesEl.style.backgroundColor&&(this.timesEl.style.backgroundColor="yellow",this.timesEl.value=await(this.wxsource?.setTime(this.timesEl.value))||"",this.onchange(this.timesEl.value),this.timesEl.style.backgroundColor="white")},this.wxsource&&this.updateSource(this.wxsource),this.buttonPlayStop.innerHTML="Start";let r=0,i={abortController:new AbortController};this.buttonPlayStop.onclick=async()=>{if("Start"===this.buttonPlayStop.innerHTML){this.buttonPlayStop.innerHTML="Stop";let e=async()=>{if(this.wxsource){if(this.timesEl.style.backgroundColor="yellow","Stop"===this.buttonPlayStop.innerHTML){let t=r++%this.wxsource.getAllTimes().length;await this.wxsource.setTime(t,i.abortController),setTimeout(e,this.delay)}else await this.wxsource.unsetCoarseLevel();this.timesEl.value=this.wxsource.getTime()||"",this.onchange(this.timesEl.value),this.timesEl.style.backgroundColor="white"}};await(this.wxsource?.setCoarseLevel(2)),e()}else i.abortController.abort(),i.abortController=new AbortController,this.buttonPlayStop.innerHTML="Start"}}setTimes(e){this.timesEl.options.length=0;for(let t=0;t<e.length;t++){let a=document.createElement("option");a.value=e[t],a.text=e[t],this.timesEl.appendChild(a)}this.onchange(this.timesEl.value)}updateSource(e){this.buttonPlayStop.innerHTML="Start",this.wxsource=e;let t=this.wxsource?.getAllTimes()||[];this.setTimes(t),this.timesEl.value=this.wxsource?.getTime()||"",this.onchange(this.timesEl.value),e?.on("changed",(()=>this.updateSource(e)))}onAdd(){return this._div}onRemove(){this._div.parentNode?.removeChild(this._div)}extender(){return{onAdd:()=>this.onAdd(),onRemove:()=>this.onRemove()}}};export{xe as CustomWxTilesLayer,F as DataIntegral,$ as QTree,h as WXLOG,ue as WxAPI,pe as WxAPIControl,j as WxCreateLegend,V as WxDataSetManager,U as WxGetColorSchemes,A as WxGetColorStyles,ge as WxInfoControl,Ne as WxLayerBaseImplementation,ye as WxLegendControl,he as WxMultilayerManager,be as WxStyleEditorControl,B as WxTileSource,je as WxTilesLogging,Te as WxTimeControl};
//# sourceMappingURL=/sm/b464a66d59b86e1757e26ea8e056a91b54bde447b1b564e327c797f8b42a7f3d.map