@metoceanapi/wxtiles-leaflet 1.0.15 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/es/tilesLayer.d.ts +2 -0
- package/dist/es/wxtiles.js +1 -1
- package/dist/web/wxtiles.js +1 -1
- package/package.json +1 -1
- package/src_example/index.ts +49 -41
- package/src_example/visualStyleEditor.ts +324 -0
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,21 @@ Write your changes below this section. `npm version [major|minor|patch]` will au
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
## [1.1.0] - 2022-04-21
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- A new visual 'custom' style editor
|
|
17
|
+
|
|
18
|
+
### REVERT
|
|
19
|
+
|
|
20
|
+
- checkDataChanged
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- addDegree in \_createStreamLines
|
|
25
|
+
- error handling in makeConverter
|
|
26
|
+
|
|
12
27
|
## [1.0.15] - 2022-04-12
|
|
13
28
|
|
|
14
29
|
### add
|
|
@@ -16,6 +31,7 @@ Write your changes below this section. `npm version [major|minor|patch]` will au
|
|
|
16
31
|
- style.vectorFactor
|
|
17
32
|
|
|
18
33
|
### FIX
|
|
34
|
+
|
|
19
35
|
- remastered async functions
|
|
20
36
|
- masking spoiled original (cached) data
|
|
21
37
|
|
package/dist/es/tilesLayer.d.ts
CHANGED
|
@@ -90,6 +90,8 @@ export declare class WxTilesLayer extends L.GridLayer {
|
|
|
90
90
|
protected createTile(coords: L.Coords, done: L.DoneCallback): HTMLElement;
|
|
91
91
|
/** NOTE: if lazy setup and layer was not added to a map - this is never fulfilled */
|
|
92
92
|
getSetupCompletePromise(): Promise<void>;
|
|
93
|
+
/** check if data has been changed since last init */
|
|
94
|
+
checkDataChanged(): Promise<boolean>;
|
|
93
95
|
/** get all the information about tile and point it represents */
|
|
94
96
|
getLayerInfoAtLatLon(latlng: L.LatLngExpression): WxTileInfo | undefined;
|
|
95
97
|
/** Layer's current style.*/
|
package/dist/es/wxtiles.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Ae=Object.create;var R=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols,ke=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable;var Y=(n,e,t)=>e in n?R(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,ee=(n,e)=>{for(var t in e||(e={}))J.call(e,t)&&Y(n,t,e[t]);if(X)for(var t of X(e))_e.call(e,t)&&Y(n,t,e[t]);return n};var Pe=n=>R(n,"__esModule",{value:!0});var at=typeof require!="undefined"?require:n=>{throw new Error('Dynamic require of "'+n+'" is not supported')};var Fe=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var Ue=(n,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Re(e))!J.call(n,r)&&r!=="default"&&R(n,r,{get:()=>e[r],enumerable:!(t=Me(e,r))||t.enumerable});return n},te=n=>Ue(Pe(R(n!=null?Ae(ke(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var B=Fe((ct,re)=>{re.exports=window.L});var q=te(B());var ne={comment1:["'degC': ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["'hPa': ['Pa', 1000]' -> hPa = Pa * 1000 + 0 (0 - could be ommited)",0],K:["K",1],kelvin:["K",1],F:["K",.5555555555,255.372222222],C:["K",1,273.15],degC:["K",1,273.15],"kg/m^2/s":["kg/m^2/s",1],"Kg/m^2/s":["kg/m^2/s",1],"Kg m**-2 s**-1":["kg/m^2/s",1],"Kg m^-2 s^-1":["kg/m^2/s",1],"Kg m^{-2} s^-1":["kg/m^2/s",1],"mm/h":["kg/m^2/s",.00027777777],"mm/hr":["kg/m^2/s",.00027777777],"W/m^2":["W/m^2",1],"W m^-2":["W/m^2",1],"W m^{-2}":["W/m^2",1],"W/m**2":["W/m^2",1],"W m**-2":["W/m^2",1],"m/s":["m/s",1],"m s**-1":["m/s",1],"m s^-1":["m/s",1],"m.s^{-1}":["m/s",1],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["m/s",.27777777777],"km h^-1":["m/s",.27777777777],"km h**-1":["m/s",.27777777777],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],inch:["m",.0254],Pa:["Pa",1],hPa:["Pa",100],degree:["degree",1],radian:["degree",57.3],"mg/m^3":["mg/m^3",1],"mg m^-3":["mg/m^3",1],"mg.m^-3":["mg/m^3",1],"%":["%",1],"(0 - 1)":["%",100]};var oe={none:["#00000000","#00000000"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbowzerro:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow2:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebirdzerro:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bw:["#000000ff","#ffffffff"],wb:["#ffffffff","#000000ff"],redish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]};var k={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,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"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,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"}};var O,ae,se;function We({colorStyles:n={},units:e={},colorSchemes:t={}}={}){b("WxTile lib setup: start"),O=Object.assign({},ne,e),ae=Object.assign({},t,oe);let r=Object.assign({},n,k);se=Ee(r),b("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),b("WxTile lib setup is done.")}function H(){return se}function z(){return ae}function _(n,e,t){let r=t?Object.assign({},O,t):O;if(!r||!n||!e||n===e||!r[n]||!r[e]||r[n][0]!==r[e][0]){b(n===e?"Trivial converter:":"Inconvertible units. Default converter is used:",n," -> ",e);let s=i=>i;return s.trivial=!0,s}b("Converter: From:",n," To:",e);let o=r[n][1]/r[e][1],a=(r[n][2]||0)/r[e][1]-(r[e][2]||0)/r[e][1];return a?s=>o*s+a:s=>o*s}function Ee(n){let e=Object.assign({},k);for(let o in n){let a=n[o];if(Array.isArray(a))for(let s=0;s<a.length;++s)e[o+"["+s+"]"]=Object.assign({},a[s]);else e[o]=Object.assign({},a)}let t=(o,a)=>{if(a==="base")return k.base;let s=o[a];(!s.parent||!(s.parent in o))&&(s.parent="base");let i=t(o,s.parent);return Object.assign(s,Object.assign({},i,s,{parent:"base"}))},r={};for(let o in e)r[o]=t(e,o);return r}function qe(n){let e=new Map;return t=>{let r=e.get(t);if(r)return r;let o=n(t);return e.set(t,o),o.catch(a=>{a.code===DOMException.ABORT_ERR&&e.delete(t)}),o}}async function Be(n,e){let t=new Image;return t.src=URL.createObjectURL(await(await fetch(n,e)).blob()),await t.decode(),URL.revokeObjectURL(t.src),t}function Oe(n){let{width:e,height:t}=n,r=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d");if(!r)throw new Error("Error: can not create context. Catastrophe");return r.drawImage(n,0,0),r.getImageData(0,0,e,t)}async function ie(n,e){return Oe(await Be(n,e))}function He(n){n.data[34]<1&&b("Warning: image is in too old format. Check the version of the Splitter.");let e=new Uint16Array(n.data.buffer),t=new Uint16Array(e.length/2);for(let u=0;u<t.length;u++)t[u]=e[u*2];let r=new Uint8Array(8);for(let u=0;u<8;++u)r[u]=n.data[u*4+2];let o=new DataView(r.buffer),a=o.getFloat32(0,!0),s=o.getFloat32(4,!0),i=(s-a)/65535,c=Ze(t);return{raw:t,dmin:a,dmax:s,dmul:i,integral:c,radius:0}}async function ze(n,e){return He(await ie(n,e))}function le(n,e){let t={controller:new AbortController,debug:Date.now().toString()},r=Object.assign({},e,{signal:t.controller.signal}),o=qe(a=>n(a,r));return o.controllerHolder=t,o.abort=()=>{t.controller.abort(),t.controller=new AbortController,t.debug=Date.now().toString(),r.signal=t.controller.signal},o}function Z(n){return le(ze,n)}function ce(n){return le(ie,n)}function Ze(n){let e=new Uint32Array(258*258),t=new Uint32Array(258*258);e[0]=n[0],t[0]=n[0]===0?0:1;for(let r=1;r<258;++r)e[r]=n[r]+e[r-1],e[258*r]=n[258*r]+e[258*r-258],t[r]=(n[r]===0?0:1)+t[r-1],t[258*r]=(n[258*r]===0?0:1)+t[258*r-258];for(let r=1,o=259;r<258;++r,++o)for(let a=1;a<258;++a,++o)e[o]=n[o]+e[o-258]+e[o-1]-e[o-258-1],t[o]=(n[o]===0?0:1)+t[o-258]+t[o-1]-t[o-258-1];return{integral:e,integralNZ:t}}function ue(n,e){if(e<0||e===n.radius)return n;n.radius=e;let t=258,{integral:r,integralNZ:o}=n.integral;for(let a=1;a<t;a++)for(let s=1;s<t;s++){if(!n.raw[t*a+s])continue;let i=Math.min(e,s-1,t-1-s),c=Math.min(e,a-1,t-1-a),u=t*(a-c-1)+s,f=t*(a+c)+s,l=o[u-i-1],d=o[u+i],h=o[f-i-1],g=o[f+i],m=l+g-d-h,x=r[u-i-1],p=r[u+i],y=r[f-i-1],C=r[f+i],v=x+C-p-y;n.raw[a*t+s]=v/m}return n}function w(n){let e=n>>0&255,t=n>>8&255,r=n>>16&255,o=e.toString(16),a=t.toString(16),s=r.toString(16);return o=o.length===2?o:"0"+o,a=a.length===2?a:"0"+a,s=s.length===2?s:"0"+s,"#"+o+a+s}function T(n){if(n[0]==="#"){if(n.length===4)return+("0xff"+n[3]+n[3]+n[2]+n[2]+n[1]+n[1]);if(n.length===7)return+("0xff"+n[5]+n[6]+n[3]+n[4]+n[1]+n[2]);if(n.length===9)return+("0x"+n[7]+n[8]+n[5]+n[6]+n[3]+n[4]+n[1]+n[2])}return b("wrong color format",n),0}async function P(n,e){return(await fetch(n,e)).json()}function F(n,e="",t){var o;let r=document.createElement(n);return r.className=e,t&&((o=t.appendChild)==null||o.call(t,r)),r}function j(n,e,t){let r=n>>0&255,o=n>>8&255,a=n>>16&255,s=n>>>24,i=e>>0&255,c=e>>8&255,u=e>>16&255,f=e>>>24,l=r+t*(i-r),d=o+t*(c-o),h=a+t*(u-a),g=s+t*(f-s);return l|d<<8|h<<16|g<<24}function me(n,e,t){let r=[];for(let o=0;o<t;++o)r.push(o*(e-n)/(t-1)+n);return r}function fe(n,e){let t=typeof e=="number"?e:typeof e=="string"?new Date(e).getTime():e.getTime();return n.find(r=>new Date(r).getTime()>=t)||n[n.length-1]}var de=!1;function je(n){console.log(n?"Logging on":"Logging off"),de=n}function b(...n){de&&console.trace(...n)}function he(n){return n!=="none"&&n.length<7?"#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]:n}var Te=te(B());function Ve(n,e,t){return n>t?t:n<e?e:n}var U=class{constructor(e,t,[r,o],a){let s=o-r;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let i=[];this.DataToStyle=_(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),a&&(this.DataToKnots=_(t,"knot"));let c=_(e.units,t,e.extraUnits),u=m=>~~(65535*Ve((c(m)-r)/(o-r),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((m,x)=>m[0]<x[0]?-1:m[0]>x[0]?1:0);for(let[m]of e.colorMap)i.push(u(m))}else{if(e.levels||(e.levels=me(this.DataToStyle(r),this.DataToStyle(o),10)),e.levels.sort((m,x)=>m<x?-1:m>x?1:0),!e.colors){let m=z();e.colorScheme&&e.colorScheme in m?e.colors=m[e.colorScheme]:e.colors=m.wb}for(let m of e.levels)i.push(u(m))}let f=65536,l=V(f,e);this.ticks=l.ticks;let d=l.ticks[0].data,g=l.ticks[l.ticks.length-1].data-d;for(let m=0;m<65536;++m){let x=s*m/65535+r,p=this.DataToStyle(x),y=Math.round((f-1)*(p-d)/g);y<=0?this.colorsI[m]=e.showBelowMin?l.colors[0]:0:y>=f?this.colorsI[m]=e.showAboveMax?l.colors[f-1]:0:this.colorsI[m]=l.colors[y]}this.colorsI[0]=0;for(let m=0;m<i[0];++m)this.levelIndex[m]=0;for(let m=0;m<i.length-1;m++)for(let x=i[m];x<i[m+1]+1;++x)this.levelIndex[x]=m;for(let m=i[i.length-1];m<65536;++m)this.levelIndex[m]=i.length-1}};function be(n){var t;if(n!==0&&-.1<n&&n<.1)return n.toExponential(2);let e=n.toString();return((t=e.split(".")[1])==null?void 0:t.length)>2?n.toFixed(2):e}function V(n,e){let t={size:n,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(n),ticks:[]},{colorMap:r,levels:o,colors:a}=e,s=e.fill!=="solid";if(r){let d=r[0][0],h=r[r.length-1][0]-d;for(let[g,m]of r){let x=~~((g-d)/h*(n-1)),p={data:g,dataString:be(g),color:m,pos:x};t.ticks.push(p)}for(let g=0;g<r.length-1;g++){let m=t.ticks[g].pos,x=t.ticks[g+1].pos,p=T(r[g][1]),y=s?T(r[g+1][1]):0;for(let C=m;C<x;++C)t.colors[C]=s?j(p,y,(C-m)/(x-m)):p}return t.colors[n-1]=T(r[r.length-1][1]),t}if(!a||!o)return t;let i=0,c=0,u=-1;for(let d=0;d<n;++d){let h=d*(a.length-1)/n;u!==~~h&&(u=~~h,i=T(a[u]),c=a.length>u+1?T(a[u+1]):i),t.colors[d]=s?j(i,c,h-u):i}t.colors[n-1]=T(a[a.length-1]);let f=o[0],l=(n-1)/(o[o.length-1]-f);for(let d of o){let h=~~((d-f)*l),g={data:d,dataString:be(d),color:w(t.colors[h]),pos:h};t.ticks.push(g)}return t}var G=256,Ge=2*Math.PI*6378137/G,W=2*Math.PI*6378137/2;function Qe(n,e){let t=n/W*180,r=e/W*180;return r=180/Math.PI*(2*Math.atan(Math.exp(r*Math.PI/180))-Math.PI/2),[r,t]}function Ne(n,e,t){let r=Ke(t),o=n*r-W,a=e*r-W;return[o,a]}function Ke(n){return Ge/Math.pow(2,n)}function Q(n,e,t){let[r,o]=Qe(...Ne(n,e,t));return[o,-r]}function ge(n,e){return[n*G,e*G]}var $e="A".charCodeAt(0),N,I=0;async function Xe(n,e){let t;try{t=await(await fetch(n,e)).json()}catch(r){console.log("Can't load QTree:",r);return}N=A(t,{pos:0}),I=xe(N),console.log("Loaded QTree, depth:",I)}function A(n,e){let t=n.charCodeAt(e.pos)-$e;e.pos++;let r=t&1?A(n,e):null,o=t&2?A(n,e):null,a=t&4?A(n,e):null,s=t&8?A(n,e):null;return{sub:r||o||a||s?[r,o,a,s]:null}}function xe(n){let e=0;if(n==null?void 0:n.sub){for(let t=0;t<4;t++)if(n.sub[t]!==null){let r=xe(n.sub[t])+1;e<r&&(e=r)}}return e}var S;(function(r){r.Land="land",r.Mixed="mixed",r.Sea="sea"})(S||(S={}));function pe(n){if(!I)return S.Mixed;let e=ee({},n),t=!1;if(I<=n.z){t=!0;let r=n.z-I;e={x:n.x>>r,y:n.y>>r,z:I}}return ye(N,e,t)}function ye(n,e,t){if(n===null)return S.Land;if(t&&e.z===0)return S.Mixed;if(n.sub===null)return S.Sea;if(e.z===0)return S.Mixed;e.z--;let r=e.x>>e.z&1,a=(e.y>>e.z&1)<<1|r;return ye(n.sub[a],e,t)}function K(n,e,t){let r=((e-n)%360+540)%360-180;return(n+r*t+360)%360}function Je(n,e,t,r,o,a,s,i){switch((n?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 0:return 0;case 1:return n;case 2:return e;case 3:t=n,r=e;break;case 4:return t;case 5:e=n,r=t;break;case 6:r=e+t>>1,n=r;break;case 7:r=e+t>>1;break;case 8:return r;case 9:e=n+r>>1,t=e;break;case 10:n=e,t=r;break;case 11:t=n+r>>1;break;case 12:n=t,e=r;break;case 13:e=n+r>>1;break;case 14:n=e+t>>1;break}n=s+i*n,e=s+i*e,t=s+i*t,r=s+i*r;let u=K(n,e,o),f=K(t,r,o);return(K(u,f,a)-s)/i||1}function Ye(n,e,t,r,o,a,s,i){switch((n?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 7:return o+a<1?o*(e-n)+a*(t-n)+n:0;case 14:return o+a<1?0:o*(r-t)+a*(r-e)+e+t-r;case 11:return a<o?(1-o)*(n-e)+a*(r-e)+e:0;case 13:return a<o?0:(1-o)*(t-r)+a*(t-n)+n+r-t;case 15:return o+a<1?o*(e-n)+a*(t-n)+n:o*(r-t)+a*(r-e)+e+t-r;default:return 0}}function Ce(n,e,t){if(!t)return e;let r=.9999999/Math.pow(2,t.z),o=t.x*256*r,a=t.y*256*r,{raw:s,dmin:i,dmax:c,dmul:u}=e,f={raw:new Uint16Array(258*258),dmin:i,dmax:c,dmul:u},{raw:l}=f;for(let d=-1,h=0;d<=256;d++){let g=a+d*r,m=Math.floor(g),x=g-m;for(let p=-1;p<=256;p++,h++){let y=o+p*r,C=Math.floor(y),v=y-C,L=C+1+(m+1)*258,M=s[L],D=s[L+1],Ie=s[L+258],De=s[L+258+1];l[h]=n(M,D,Ie,De,v,x,i,u)}}return f}function et(n,e){return Ce(Ye,n,e)}function tt(n,e){return Ce(Je,n,e)}function rt(n,e,t){let r=t==="land"?1:0;for(let o=3,a=0;a<256;a++)for(let s=0;s<256;s++,o+=4){let i=e.data[o]?1:0;r^i&&(n.raw[(a+1)*258+(s+1)]=0)}return n}function nt(n){let[e,t]=ge(n.x,n.y),[r,o]=Q(e,t,n.z),[a,s]=Q(e+256,t+256,n.z);return{west:r,north:o,east:a,south:s}}function Se(n){let e=F("div","leaflet-tile s-tile");return e.wxtile=new we(n,e),(async()=>{let{wxtile:t}=e;try{await t.load(),t.draw()}catch(r){let{x:o,y:a,z:s}=t.coords;b(`tile(${o},${a},${s}) loading error: ${r}`)}n.done()})(),e}var we=class{constructor({layer:e,coords:t},r){this.data=[];this.streamLines=[];this.coords=t,this.layer=e,this.canvasFill=F("canvas","s-tile canvas-fill",r),this.canvasSlines=F("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(a){let s=a.getContext("2d");if(!s)throw new Error("getCtx error");return s}this.canvasFillCtx=o(this.canvasFill),this.imageDataForFillCtx=this.canvasFillCtx.createImageData(256,256),this.canvasVectorAnimationCtx=o(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}async load(){let{coords:e,layer:t}=this;await t.setupCompletePromise;let r=this._getTileType();if(!r)return this.data=[],this.streamLines=[],this;let{upCoords:o,subCoords:a}=this._splitCoords(e),s=this.layer.state.baseURL.replace("{z}",String(o.z)).replace("{x}",String(o.x)).replace("{y}",String(o.y)),i=this.layer.dataSource.variables.map(l=>s.replace("{var}",l)),c;try{c=await Promise.all(i.map(t.loadDataIntegralFunc))}catch(l){return l.code!==DOMException.ABORT_ERR&&(this.data=[],this.streamLines=[]),this}let u=t.state.units==="degree"?tt:et,f=l=>u(ue(l,t.style.blurRadius),a);return this.data=c.map(f),t.state.vector&&this._vectorMagnitudesPrepare(),await this._applyMask(r,a===void 0),t.state.vector&&this._createStreamLines(),this}async _applyMask(e,t){let{coords:r,layer:o}=this;if((o.style.mask==="land"||o.style.mask==="sea")&&e===S.Mixed){let a=o.dataSource.maskServerURI.replace("{z}",String(r.z)).replace("{x}",String(r.x)).replace("{y}",String(r.y));try{let s=await o.loadMaskFunc(a);if(!o.state.vector&&t){let{raw:i,dmin:c,dmax:u,dmul:f}=this.data[0];this.data[0]={raw:new Uint16Array(i),dmin:c,dmax:u,dmul:f}}rt(this.data[0],s,o.style.mask)}catch(s){o.style.mask=void 0,b("Can't load Mask. Masking is Turned OFF")}}}_splitCoords(e){let t=e.z-this.layer.state.meta.maxZoom;if(t<=0)return{upCoords:e};let r={x:e.x>>>t,y:e.y>>>t,z:this.layer.state.meta.maxZoom},o={x:e.x&(1<<t)-1,y:e.y&(1<<t)-1,z:t};return{upCoords:r,subCoords:o}}_getTileType(){let{coords:e,layer:t}=this,{mask:r}=t.style;var o=S.Mixed;if((r==="land"||r==="sea")&&(o=pe(e),r===o))return;let{boundaries:a}=t.state.meta;if(a==null?void 0:a.boundaries180){let s=nt(e),i=c=>!(s.west>c.east||c.west>s.east||s.south>c.north||c.south>s.north);if(!a.boundaries180.some(i))return}return o}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasVectorAnimationCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVectorsStatic(),this._drawDegreesStatic(),this._drawStreamLinesStatic())}clearVectorAnimationCanvas(){this.canvasVectorAnimationCtx.clearRect(0,0,256,256)}drawVectorAnimationLinesStep(e){if(this.streamLines.length===0)return;let t=this.canvasVectorAnimationCtx;if(t.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.streamLines=[];return}let r=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let o=0;o<this.streamLines.length;++o){let a=this.streamLines[o],s=a.length-1,i=(e+(1+a[0].x)*(1+a[0].y))%30;for(let c=0;c<s;++c){let u=a[c],f=a[c+1],l=1-(i-c)/s;(l<0||l>1)&&(l=0);let d=(~~(l*255)).toString(16);t.strokeStyle=r+(d.length<2?"0"+d:d);let h=1+~~((1.2-l)*5);t.lineWidth=h,t.beginPath(),t.moveTo(u.x,u.y),t.lineTo(f.x,f.y),t.stroke()}}}getPixelInfo({x:e,y:t}){var o;let r=(t+1)*258+(e+1);if(!!((o=this.data[0])==null?void 0:o.raw[r]))return{raw:this.data.map(a=>a.raw[r]),data:this.data.map(a=>a.raw[r]*a.dmul+a.dmin)}}_vectorMagnitudesPrepare(){if(this.data.length!==2)throw new Error("this.data !== 2");this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[e,t,r]=this.data;e.dmax=1.42*Math.max(-t.dmin,t.dmax,-r.dmin,r.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let o=0;o<258*258;++o){if(!t.raw[o]||!r.raw[o]){e.raw[o]=0;continue}let a=t.dmin+t.dmul*t.raw[o],s=r.dmin+r.dmul*r.raw[o];e.raw[o]=Math.sqrt(s*s+a*a)/e.dmul}}_drawFillAndIsolines(){let{imageDataForFillCtx:e}=this,{canvasFillCtx:t}=this,r=new Uint32Array(e.data.buffer),{raw:o}=this.data[0],{clut:a,style:s}=this.layer,{levelIndex:i,colorsI:c}=a;if(s.fill!=="none")for(let f=0,l=0,d=259;f<256;++f,d+=2)for(let h=0;h<256;++h,++l,++d)r[l]=c[o[d]];else r.fill(0);let u=[];if(s.isolineColor!=="none"){let f=s.isolineColor[0]==="#"?T(s.isolineColor):0;for(let l=0,d=0;l<256;l+=1)for(let h=0;h<256;h+=1){let g=(l+1)*258+(h+1),m=o[g],x=o[g+1],p=o[g+258];if(!m||!x||!p)continue;let y=i[m],C=i[x],v=i[p];if(y!==C||y!==v){let L=Math.max(y,C,v),M=Math.max(m,x,p),D=l*256+h;switch(s.isolineColor){case"inverted":r[D]=~c[M]|4278190080;break;case"fill":r[D]=c[M]|4278190080;break;default:r[D]=f;break}s.isolineText&&!(++d%255)&&h>20&&h<235&&l>20&&l<235&&u.push({x:h,y:l,d:m,dr:x,db:p,mli:L})}}}if(t.putImageData(e,0,0),u.length){t.font="1.1em Sans-serif",t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";for(let{x:f,y:l,d,dr:h,db:g,mli:m}of u){let x=this.layer.clut.ticks[m].dataString,p=Math.atan2(d-h,g-d);t.save(),t.translate(f,l),t.rotate(p<-1.57||p>1.57?p+3.14:p),t.strokeText(x,0,0),t.fillText(x,0,0),t.restore()}}}_drawStreamLinesStatic(){if(!this.streamLines.length||!this.layer.style.streamLineStatic)return;let{canvasVectorAnimationCtx:e}=this;if(this.layer.style.streamLineColor==="none"){this.streamLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let t=this.streamLines.length;t--;){let r=this.streamLines[t];for(let o=0;o<r.length-1;++o){let a=r[o],s=r[o+1];e.moveTo(a.x,a.y),e.lineTo(s.x,s.y)}}e.stroke()}_drawVectorsStatic(){let{clut:e,style:t}=this.layer;if(!this.layer.state.vector||!e.DataToKnots||t.vectorColor==="none"||t.vectorType==="none")return;if(this.data.length!==3)throw new Error("this.data.length !== 3");let[r,o,a]=this.data,{canvasVectorCtx:s}=this;switch(t.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=t.vectorType}s.textAlign="center",s.textBaseline="middle";let i=t.addDegrees?.017453292519943*t.addDegrees:0,c=32;for(let u=c/2;u<256;u+=c)for(let f=c/2;f<256;f+=c){let l=f+1+(u+1)*258;if(!r.raw[l])continue;let d=Math.atan2(o.dmin+o.raw[l]*o.dmul,a.dmin+a.raw[l]*a.dmul),h=r.dmin+r.raw[l]*r.dmul,g=t.vectorType!=="barbs"?t.vectorFactor*.2:.2,m=Math.min(e.DataToKnots(h)*g,25)+65,x=String.fromCharCode(m);switch(t.vectorColor){case"inverted":s.fillStyle=w(~e.colorsI[r.raw[l]]);break;case"fill":s.fillStyle=w(e.colorsI[r.raw[l]]);break;default:s.fillStyle=t.vectorColor;break}s.save(),s.translate(f,u),s.rotate(d+i),s.fillText(x,0,0),s.restore()}}_drawDegreesStatic(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:e}=this,t=.017453292519943*this.layer.style.addDegrees;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle";let r=this.data[0],o="L",a=32;for(let s=a/2;s<256;s+=a)for(let i=a/2;i<256;i+=a){let c=i+1+(s+1)*258;if(!r.raw[c])continue;let f=(r.dmin+r.raw[c]*r.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=w(~this.layer.clut.colorsI[r.raw[c]]);break;case"fill":e.fillStyle=w(this.layer.clut.colorsI[r.raw[c]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(i,s),e.rotate(f+t),e.fillText(o,0,0),e.restore()}}_createStreamLines(){if(this.data.length!==3)throw new Error("this.data.length !== 3");if(this.layer.style.streamLineColor==="none")return;let e=this.layer.style.streamLineSpeedFactor||1;this.streamLines=[];let[t,r,o]=this.data,a=Math.max(this.coords.z-this.layer.state.meta.maxZoom,0),s=Math.min(2**(a+5),128),i=~~(120+a*60);for(let c=0;c<=256;c+=s)for(let u=0;u<=256;u+=s){if(!t.raw[1+u+(1+c)*258])continue;let f=[],l=u,d=c;for(let h=0;h<=i&&l>=0&&l<=256&&d>=0&&d<=256;h++){!(h%(i/6))&&f.push({x:~~l,y:~~d});let g=~~l+1+(~~d+1)*258;if(!t.raw[g])break;l+=e*(r.dmin+r.raw[g]*r.dmul)/t.dmax,d-=e*(o.dmin+o.raw[g]*o.dmul)/t.dmax}l=u,d=c;for(let h=1;h<=i&&l>=0&&l<=256&&d>=0&&d<=256;h++){!(h%(i/6))&&f.unshift({x:~~l,y:~~d});let g=~~l+1+(~~d+1)*258;if(!t.raw[g])break;l-=e*(r.dmin+r.raw[g]*r.dmul)/t.dmax,d+=e*(o.dmin+o.raw[g]*o.dmul)/t.dmax}f.length>2&&this.streamLines.push(f)}}};var $;var E=class extends Te.default.GridLayer{constructor(e){super(e.options);this.styles=H();this.redrawRequestID=0;this.vectorAnimationRequestID=0;this.oldMaxZoom=0;this.style=Object.assign({},this.styles.base);this.clut=new U(this.style,"",[0,2],!1);this.animation=!0;let{dataSource:t,lazy:r}=e;if(b("Creating a WxTiles layer:",t.name,". Params:",JSON.stringify(e)),!(t==null?void 0:t.ext)||!t.dataset||!t.name||!t.serverURI||!t.styleName||!Array.isArray(t.variables)||t.variables.length<1||t.variables.length>2){let i="WxTilesLayer: dataSource is wrong!";throw b(i),new Error(i)}this.dataSource=t,this.state={originURI:t.serverURI+"/"+t.dataset+"/",units:"",baseURL:"",meta:{maxZoom:0,times:[],variables:[],variablesMeta:{}},instance:"",minmax:[[0,1]],currentTime:"",vector:t.variables.length>1},this.loadDataIntegralFunc=Z(t.requestInit),$||($=ce(t.requestInit)),this.loadMaskFunc=$;let o=()=>{var i;((i=this._map)==null?void 0:i.getZoom())<this.state.meta.maxZoom&&this._stopLoadingResetLoadDataFunc()},a=()=>{if(b("onadd:",this.dataSource.name),!this._map)throw new Error("_map is not set!");this._map.on("zoomstart",o),this._checkAndStartVectorAnimation()},s=()=>{if(b("onremove:",this.dataSource.name),!this._map)throw new Error("_map is not set!");this._map.off("zoomstart",o),this._stopLoadingResetLoadDataFunc()};this.on("remove",s),this.on("add",a),this.setupCompletePromise=new Promise(i=>{let c=async()=>{b("Setup:",t.name),await this._setUpDataSet(),b("Setup complete: ",this.dataSource.name),i()};r?this.once("add",c):c()})}async _setUpDataSet(){let{state:e,dataSource:t}=this;try{e.instance=(await P(e.originURI+"instances.json")).pop()+"/"}catch(o){let a=t.name+": load instances.json error: "+o;throw b(a),new Error(a)}try{let o=e.originURI+e.instance+"meta.json";e.meta=await P(o)}catch(o){let a=t.name+": load meta.json error: "+o;throw b(a),new Error(a)}e.vector=t.variables.length===2;let{variablesMeta:r}=e.meta;if(e.units=r[t.variables[0]].units,e.minmax=t.variables.map(o=>[r[o].min,r[o].max]),e.vector){let[[o,a],[s,i]]=e.minmax;e.minmax.unshift([0,1.42*Math.max(-o,a,-s,i)])}this._setStyleAndCLUT(t.styleName),this._setTimeUrl(new Date)}async _requestReloadTilesAndRedraw(){let e=await this._requestReloadTiles();return e&&this._redrawTiles(),e}async _requestReloadTiles(){b(`_requestReloadTiles: start - ${this.dataSource.name}`);let{controller:e}=this.loadDataIntegralFunc.controllerHolder;return await Promise.allSettled(this._ForEachWxTile(t=>t.load())),b(`_requestReloadTiles: end - ${this.dataSource.name}, aborted: ${e.signal.aborted}`),!e.signal.aborted}async setStyle(e){b("setStyle(",e,") for ",this.dataSource.name),(e==="custom"||e!==this.dataSource.styleName)&&(this._setStyleAndCLUT(e),this._checkAndStartVectorAnimation(),await this._requestReloadTilesAndRedraw()),b("setStyle(",e,'): "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete.")}_setStyleAndCLUT(e){let{dataSource:t,styles:r,state:o}=this;t.styleName=e,e==="custom"&&(r.custom.parent&&r.custom.parent in r||(b(`cant find the parent style (${r.custom.parent}), 'base' is used`),r.custom.parent="base"),r.custom=Object.assign(Object.assign({},r[r.custom.parent]),r.custom)),e in r||(b(`cant find the style (${e}), 'base' is used`),e=t.styleName="base");try{this.style=Object.assign({},r[e]),this.style.streamLineColor=he(this.style.streamLineColor),this.clut=new U(this.style,o.units,o.minmax[0],o.vector)}catch(a){let s="setStyle: impossible error in RawCLUT: "+a;throw b(s),new Error(s)}}createTile(e,t){return Se({layer:this,coords:e,done:t})}getSetupCompletePromise(){return this.setupCompletePromise}getLayerInfoAtLatLon(e){if(!this._map)return;let t=this._map.getZoom(),r=this._map.project(e,t),o=r.divideBy(256).floor(),a=this._getCachedTile(o,t);if(!a)return;let s=r.subtract(o.multiplyBy(256)).floor(),i=a.getPixelInfo(s);if(!i)return;let{raw:c,data:u}=i,f=c.map(h=>this.clut.colorsI[h]),l=f.map(w),d=u.map(h=>this.clut.DataToStyle(h));return{wxtile:a,data:u,raw:c,rgba:f,hexColor:l,inStyleUnits:d,tilePoint:s,styleUnits:this.style.units,dataUnits:this.state.units}}getStyle(){return this.style}_getFirstNonEmptyTile(){for(let e in this._tiles){let{wxtile:t}=this._tiles[e].el;if(t==null?void 0:t.data.length)return t}}_setTimeUrl(e){let{dataSource:t,state:r}=this,o=fe(r.meta.times,e);return r.currentTime===o?(b("_setTimeUrl: the same time - skipped"),!1):(r.currentTime=o,r.baseURL=r.originURI+r.instance+`{var}/${r.currentTime}/{z}/{x}/{y}.${t.ext}`,b(`_setTimeUrl: ${o} for ${t.name} complete`),!0)}setTime(e){if(b("setTime: "+e+" for "+this.dataSource.name+" start"),!this._tiles)return b("setTime: no tiles - skipped"),Promise.resolve(!1);let{currentTime:t}=this.state;if(!this._setTimeUrl(e))return Promise.resolve(!1);this.loadDataIntegralFunc.abort();let r=this._requestReloadTiles();return r.then(o=>{if(!o){this.state.currentTime=t;return}let a=this._getFirstNonEmptyTile();if(a==null?void 0:a.data.length){let[s,i]=this.state.minmax[0],{dmin:c,dmax:u}=a.data[0];(Math.abs(c-s)>.01||Math.abs(u-i)>.01)&&(this.state.minmax=a.data.map(f=>[f.dmin,f.dmax]),this._setStyleAndCLUT(this.dataSource.styleName))}this._redrawTiles()}),r}getTime(){return this.state.currentTime}getTimes(){return b("getTimes"),this.state.meta.times}getLegendData(e){return b("getLegendData"),V(e,this.style)}setTimeAnimationMode(e=2){b("setTimeAnimationMode"),this.oldMaxZoom=this.state.meta.maxZoom;let t=this._map.getZoom(),o=(t<this.oldMaxZoom?t:this.oldMaxZoom)-e;this.state.meta.maxZoom=o<0?0:o}async unsetTimeAnimationMode(){return b("unsetTimeAnimationMode"),this.oldMaxZoom&&(this.state.meta.maxZoom=this.oldMaxZoom),this._requestReloadTilesAndRedraw()}getMinMax(){let[e,t]=this.state.minmax[0];return{min:e,max:t}}setAnimation(e){return b("setAnimation"),this.animation=e,this._checkAndStartVectorAnimation(),this.animation}_getCachedTile({x:e,y:t},r){var o,a;return(a=(o=this._tiles[`${e}:${t}:${r}`])==null?void 0:o.el)==null?void 0:a.wxtile}_ForEachWxTile(e){var r;let t=[];for(let o in this._tiles){let a=(r=this._tiles[o].el)==null?void 0:r.wxtile;a&&t.push(e(a))}return t}_stopLoadingResetLoadDataFunc(){this.loadDataIntegralFunc.abort(),this.loadDataIntegralFunc=Z()}_checkAndStartVectorAnimation(){if(this.vectorAnimationRequestID)return;let e=t=>{if(!this._map||!this.animation||!this.state.vector||this.style.streamLineStatic||this.style.streamLineColor==="none"){this._ForEachWxTile(r=>r.clearVectorAnimationCanvas()),this.vectorAnimationRequestID=0;return}this._ForEachWxTile(r=>r.drawVectorAnimationLinesStep(t)),this.vectorAnimationRequestID=requestAnimationFrame(e)};this.vectorAnimationRequestID=requestAnimationFrame(e)}_redrawTiles(){this.redrawRequestID||(b("_redrawTiles: start: "+this.dataSource.name),this.redrawRequestID=requestAnimationFrame(()=>{this._ForEachWxTile(e=>e.draw()),this.redrawRequestID=0,b("_redrawTiles: requestAnimationFrame: end: "+this.dataSource.name)}))}};function ot(n){return new E(n)}var ve=class extends q.default.Control{constructor(e){super(e);this.URI=e.URI}onAdd(){let e=document.createElement("img");return e.src=this.URI,e.className="wxtiles-logo",e}};function Ot(n){return b("Add watermark:",JSON.stringify(n)),new ve(n)}var Le=class extends q.default.GridLayer{createTile(e){let t=document.createElement("div");return t.innerHTML=[e.x,e.y,e.z].join(", "),t.style.outline="1px solid red",t}};function Ht(){return b("Add WxDebugCoordsLayer:"),new Le().setZIndex(1e3)}function zt(n,e){return q.default.layerGroup(n.map(ot),e)}export{Ht as CreateWxDebugCoordsLayer,zt as CreateWxTilesGroupLayer,ot as CreateWxTilesLayer,Ot as CreateWxTilesWatermark,Xe as LoadQTree,Le as WxDebugLayer,z as WxGetColorSchemes,H as WxGetColorStyles,E as WxTilesLayer,We as WxTilesLibSetup,je as WxTilesLogging,ve as WxWatermark,P as fetchJson};
|
|
1
|
+
var Me=Object.create;var _=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var ke=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols,Re=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable;var Y=(n,e,t)=>e in n?_(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,ee=(n,e)=>{for(var t in e||(e={}))J.call(e,t)&&Y(n,t,e[t]);if(X)for(var t of X(e))_e.call(e,t)&&Y(n,t,e[t]);return n};var Ue=n=>_(n,"__esModule",{value:!0});var at=typeof require!="undefined"?require:n=>{throw new Error('Dynamic require of "'+n+'" is not supported')};var Pe=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var Fe=(n,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ke(e))!J.call(n,r)&&r!=="default"&&_(n,r,{get:()=>e[r],enumerable:!(t=Ae(e,r))||t.enumerable});return n},te=n=>Fe(Ue(_(n!=null?Me(Re(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var O=Pe((ct,re)=>{re.exports=window.L});var B=te(O());var ne={comment1:["'degC': ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["'hPa': ['Pa', 1000]' -> hPa = Pa * 1000 + 0 (0 - could be ommited)",0],K:["K",1],kelvin:["K",1],F:["K",.5555555555,255.372222222],C:["K",1,273.15],degC:["K",1,273.15],"kg/m^2/s":["kg/m^2/s",1],"Kg/m^2/s":["kg/m^2/s",1],"Kg m**-2 s**-1":["kg/m^2/s",1],"Kg m^-2 s^-1":["kg/m^2/s",1],"Kg m^{-2} s^-1":["kg/m^2/s",1],"mm/h":["kg/m^2/s",.00027777777],"mm/hr":["kg/m^2/s",.00027777777],"W/m^2":["W/m^2",1],"W m^-2":["W/m^2",1],"W m^{-2}":["W/m^2",1],"W/m**2":["W/m^2",1],"W m**-2":["W/m^2",1],"m/s":["m/s",1],"m s**-1":["m/s",1],"m s^-1":["m/s",1],"m.s^{-1}":["m/s",1],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["m/s",.27777777777],"km h^-1":["m/s",.27777777777],"km h**-1":["m/s",.27777777777],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],inch:["m",.0254],Pa:["Pa",1],hPa:["Pa",100],degree:["degree",1],radian:["degree",57.3],"mg/m^3":["mg/m^3",1],"mg m^-3":["mg/m^3",1],"mg.m^-3":["mg/m^3",1],"%":["%",1],"(0 - 1)":["%",100]};var oe={none:["#00000000","#00000000"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbowzerro:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow2:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebirdzerro:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bw:["#000000ff","#ffffffff"],wb:["#ffffffff","#000000ff"],redish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]};var U={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",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"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,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"}};var ae,se,ie;function We({colorStyles:n={},units:e={},colorSchemes:t={}}={}){b("WxTile lib setup: start"),ae=Object.assign({},ne,e),se=Object.assign({},t,oe);let r=Object.assign({},n,U);ie=Ee(r),b("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),b("WxTile lib setup is done.")}function H(){return ie}function j(){return se}function P(n,e,t){b("makeConverter: From=",n," To=",e);let r=d=>d;if(r.trivial=!0,n===e)return b("Trivial converter"),r;let o=Object.assign({},ae,t);if(!o[n]||!o[e])return b("Inconvertible units. Trivial converter"),r;let[a,s,i]=o[n],[u,l,f]=o[e];if(a!==u||!s||!l)return b("Inconvertible units. Trivial converter"),r;let m=s/l,h=((i||0)-(f||0))/l;return h?d=>m*d+h:d=>m*d}function Ee(n){let e=Object.assign({},U);for(let o in n){let a=n[o];if(Array.isArray(a))for(let s=0;s<a.length;++s)e[o+"["+s+"]"]=Object.assign({},a[s]);else e[o]=Object.assign({},a)}let t=(o,a)=>{if(a==="base")return U.base;let s=o[a];(!s.parent||!(s.parent in o))&&(s.parent="base");let i=t(o,s.parent);return Object.assign(s,Object.assign({},i,s,{parent:"base"}))},r={};for(let o in e)r[o]=t(e,o);return r}function qe(n){let e=new Map;return t=>{let r=e.get(t);if(r)return r;let o=n(t);return e.set(t,o),o.catch(a=>{a.code===DOMException.ABORT_ERR&&e.delete(t)}),o}}async function Be(n,e){let t=new Image;return t.src=URL.createObjectURL(await(await fetch(n,e)).blob()),await t.decode(),URL.revokeObjectURL(t.src),t}function Oe(n){let{width:e,height:t}=n,r=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d");if(!r)throw new Error("Error: can not create context. Catastrophe");return r.drawImage(n,0,0),r.getImageData(0,0,e,t)}async function le(n,e){return Oe(await Be(n,e))}function He(n){n.data[34]<1&&b("Warning: image is in too old format. Check the version of the Splitter.");let e=new Uint16Array(n.data.buffer),t=new Uint16Array(e.length/2);for(let l=0;l<t.length;l++)t[l]=e[l*2];let r=new Uint8Array(8);for(let l=0;l<8;++l)r[l]=n.data[l*4+2];let o=new DataView(r.buffer),a=o.getFloat32(0,!0),s=o.getFloat32(4,!0),i=(s-a)/65535,u=ze(t);return{raw:t,dmin:a,dmax:s,dmul:i,integral:u,radius:0}}async function je(n,e){return He(await le(n,e))}function ce(n,e){let t={controller:new AbortController,debug:Date.now().toString()},r=Object.assign({},e,{signal:t.controller.signal}),o=qe(a=>n(a,r));return o.controllerHolder=t,o.abort=()=>{t.controller.abort(),t.controller=new AbortController,t.debug=Date.now().toString(),r.signal=t.controller.signal},o}function z(n){return ce(je,n)}function ue(n){return ce(le,n)}function ze(n){let e=new Uint32Array(258*258),t=new Uint32Array(258*258);e[0]=n[0],t[0]=n[0]===0?0:1;for(let r=1;r<258;++r)e[r]=n[r]+e[r-1],e[258*r]=n[258*r]+e[258*r-258],t[r]=(n[r]===0?0:1)+t[r-1],t[258*r]=(n[258*r]===0?0:1)+t[258*r-258];for(let r=1,o=259;r<258;++r,++o)for(let a=1;a<258;++a,++o)e[o]=n[o]+e[o-258]+e[o-1]-e[o-258-1],t[o]=(n[o]===0?0:1)+t[o-258]+t[o-1]-t[o-258-1];return{integral:e,integralNZ:t}}function me(n,e){if(e<0||e===n.radius)return n;n.radius=e;let t=258,{integral:r,integralNZ:o}=n.integral;for(let a=1;a<t;a++)for(let s=1;s<t;s++){if(!n.raw[t*a+s])continue;let i=Math.min(e,s-1,t-1-s),u=Math.min(e,a-1,t-1-a),l=t*(a-u-1)+s,f=t*(a+u)+s,m=o[l-i-1],h=o[l+i],d=o[f-i-1],g=o[f+i],c=m+g-h-d,x=r[l-i-1],p=r[l+i],y=r[f-i-1],C=r[f+i],S=x+C-p-y;n.raw[a*t+s]=S/c}return n}function L(n){let e=n>>0&255,t=n>>8&255,r=n>>16&255,o=e.toString(16),a=t.toString(16),s=r.toString(16);return o=o.length===2?o:"0"+o,a=a.length===2?a:"0"+a,s=s.length===2?s:"0"+s,"#"+o+a+s}function I(n){if(n[0]==="#"){if(n.length===4)return+("0xff"+n[3]+n[3]+n[2]+n[2]+n[1]+n[1]);if(n.length===7)return+("0xff"+n[5]+n[6]+n[3]+n[4]+n[1]+n[2]);if(n.length===9)return+("0x"+n[7]+n[8]+n[5]+n[6]+n[3]+n[4]+n[1]+n[2])}return b("wrong color format",n),0}async function A(n,e){return(await fetch(n,e)).json()}function F(n,e="",t){var o;let r=document.createElement(n);return r.className=e,t&&((o=t.appendChild)==null||o.call(t,r)),r}function Z(n,e,t){let r=n>>0&255,o=n>>8&255,a=n>>16&255,s=n>>>24,i=e>>0&255,u=e>>8&255,l=e>>16&255,f=e>>>24,m=r+t*(i-r),h=o+t*(u-o),d=a+t*(l-a),g=s+t*(f-s);return m|h<<8|d<<16|g<<24}function fe(n,e,t){let r=[];for(let o=0;o<t;++o)r.push(o*(e-n)/(t-1)+n);return r}function de(n,e){let t=typeof e=="number"?e:typeof e=="string"?new Date(e).getTime():e.getTime();return n.find(r=>new Date(r).getTime()>=t)||n[n.length-1]}var he=!1;function Ze(n){console.log(n?"Logging on":"Logging off"),he=n}function b(...n){he&&console.trace(...n)}function be(n){return n!=="none"&&n.length<7?"#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]:n}var ve=te(O());function Ve(n,e,t){return n>t?t:n<e?e:n}var W=class{constructor(e,t,[r,o],a){let s=o-r;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let i=[];this.DataToStyle=P(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),a&&(this.DataToKnots=P(t,"knot"));let u=P(e.units,t,e.extraUnits),l=c=>~~(65535*Ve((u(c)-r)/(o-r),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((c,x)=>c[0]<x[0]?-1:c[0]>x[0]?1:0);for(let[c]of e.colorMap)i.push(l(c))}else{if(e.levels||(e.levels=fe(this.DataToStyle(r),this.DataToStyle(o),10)),e.levels.sort((c,x)=>c<x?-1:c>x?1:0),!e.colors){let c=j();e.colorScheme&&e.colorScheme in c?e.colors=c[e.colorScheme]:e.colors=c.wb}for(let c of e.levels)i.push(l(c))}let f=65536,m=V(f,e);this.ticks=m.ticks;let h=m.ticks[0].data,g=m.ticks[m.ticks.length-1].data-h;for(let c=0;c<65536;++c){let x=s*c/65535+r,p=this.DataToStyle(x),y=Math.round((f-1)*(p-h)/g);y<=0?this.colorsI[c]=e.showBelowMin?m.colors[0]:0:y>=f?this.colorsI[c]=e.showAboveMax?m.colors[f-1]:0:this.colorsI[c]=m.colors[y]}this.colorsI[0]=0;for(let c=0;c<i[0];++c)this.levelIndex[c]=0;for(let c=0;c<i.length-1;c++)for(let x=i[c];x<i[c+1]+1;++x)this.levelIndex[x]=c;for(let c=i[i.length-1];c<65536;++c)this.levelIndex[c]=i.length-1}};function ge(n){var t;if(n!==0&&-.1<n&&n<.1)return n.toExponential(2);let e=n.toString();return((t=e.split(".")[1])==null?void 0:t.length)>2?n.toFixed(2):e}function V(n,e){let t={size:n,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(n),ticks:[]},{colorMap:r,levels:o,colors:a}=e,s=e.fill!=="solid";if(r){let h=r[0][0],d=r[r.length-1][0]-h;for(let[g,c]of r){let x=~~((g-h)/d*(n-1)),p={data:g,dataString:ge(g),color:c,pos:x};t.ticks.push(p)}for(let g=0;g<r.length-1;g++){let c=t.ticks[g].pos,x=t.ticks[g+1].pos,p=I(r[g][1]),y=s?I(r[g+1][1]):0;for(let C=c;C<x;++C)t.colors[C]=s?Z(p,y,(C-c)/(x-c)):p}return t.colors[n-1]=I(r[r.length-1][1]),t}if(!a||!o)return t;let i=0,u=0,l=-1;for(let h=0;h<n;++h){let d=h*(a.length-1)/n;l!==~~d&&(l=~~d,i=I(a[l]),u=a.length>l+1?I(a[l+1]):i),t.colors[h]=s?Z(i,u,d-l):i}t.colors[n-1]=I(a[a.length-1]);let f=o[0],m=(n-1)/(o[o.length-1]-f);for(let h of o){let d=~~((h-f)*m),g={data:h,dataString:ge(h),color:L(t.colors[d]),pos:d};t.ticks.push(g)}return t}var G=256,Ge=2*Math.PI*6378137/G,E=2*Math.PI*6378137/2;function Qe(n,e){let t=n/E*180,r=e/E*180;return r=180/Math.PI*(2*Math.atan(Math.exp(r*Math.PI/180))-Math.PI/2),[r,t]}function Ne(n,e,t){let r=Ke(t),o=n*r-E,a=e*r-E;return[o,a]}function Ke(n){return Ge/Math.pow(2,n)}function Q(n,e,t){let[r,o]=Qe(...Ne(n,e,t));return[o,-r]}function xe(n,e){return[n*G,e*G]}var $e="A".charCodeAt(0),N,k=0;async function Xe(n,e){let t;try{t=await(await fetch(n,e)).json()}catch(r){console.log("Can't load QTree:",r);return}N=R(t,{pos:0}),k=pe(N),console.log("Loaded QTree, depth:",k)}function R(n,e){let t=n.charCodeAt(e.pos)-$e;e.pos++;let r=t&1?R(n,e):null,o=t&2?R(n,e):null,a=t&4?R(n,e):null,s=t&8?R(n,e):null;return{sub:r||o||a||s?[r,o,a,s]:null}}function pe(n){let e=0;if(n==null?void 0:n.sub){for(let t=0;t<4;t++)if(n.sub[t]!==null){let r=pe(n.sub[t])+1;e<r&&(e=r)}}return e}var T;(function(r){r.Land="land",r.Mixed="mixed",r.Sea="sea"})(T||(T={}));function ye(n){if(!k)return T.Mixed;let e=ee({},n),t=!1;if(k<=n.z){t=!0;let r=n.z-k;e={x:n.x>>r,y:n.y>>r,z:k}}return Ce(N,e,t)}function Ce(n,e,t){if(n===null)return T.Land;if(t&&e.z===0)return T.Mixed;if(n.sub===null)return T.Sea;if(e.z===0)return T.Mixed;e.z--;let r=e.x>>e.z&1,a=(e.y>>e.z&1)<<1|r;return Ce(n.sub[a],e,t)}function K(n,e,t){let r=((e-n)%360+540)%360-180;return(n+r*t+360)%360}function Je(n,e,t,r,o,a,s,i){switch((n?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 0:return 0;case 1:return n;case 2:return e;case 3:t=n,r=e;break;case 4:return t;case 5:e=n,r=t;break;case 6:r=e+t>>1,n=r;break;case 7:r=e+t>>1;break;case 8:return r;case 9:e=n+r>>1,t=e;break;case 10:n=e,t=r;break;case 11:t=n+r>>1;break;case 12:n=t,e=r;break;case 13:e=n+r>>1;break;case 14:n=e+t>>1;break}n=s+i*n,e=s+i*e,t=s+i*t,r=s+i*r;let l=K(n,e,o),f=K(t,r,o);return(K(l,f,a)-s)/i||1}function Ye(n,e,t,r,o,a,s,i){switch((n?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 7:return o+a<1?o*(e-n)+a*(t-n)+n:0;case 14:return o+a<1?0:o*(r-t)+a*(r-e)+e+t-r;case 11:return a<o?(1-o)*(n-e)+a*(r-e)+e:0;case 13:return a<o?0:(1-o)*(t-r)+a*(t-n)+n+r-t;case 15:return o+a<1?o*(e-n)+a*(t-n)+n:o*(r-t)+a*(r-e)+e+t-r;default:return 0}}function Se(n,e,t){if(!t)return e;let r=.9999999/Math.pow(2,t.z),o=t.x*256*r,a=t.y*256*r,{raw:s,dmin:i,dmax:u,dmul:l}=e,f={raw:new Uint16Array(258*258),dmin:i,dmax:u,dmul:l},{raw:m}=f;for(let h=-1,d=0;h<=256;h++){let g=a+h*r,c=Math.floor(g),x=g-c;for(let p=-1;p<=256;p++,d++){let y=o+p*r,C=Math.floor(y),S=y-C,w=C+1+(c+1)*258,D=s[w],v=s[w+1],M=s[w+258],De=s[w+258+1];m[d]=n(D,v,M,De,S,x,i,l)}}return f}function et(n,e){return Se(Ye,n,e)}function tt(n,e){return Se(Je,n,e)}function rt(n,e,t){let r=t==="land"?1:0;for(let o=3,a=0;a<256;a++)for(let s=0;s<256;s++,o+=4){let i=e.data[o]?1:0;r^i&&(n.raw[(a+1)*258+(s+1)]=0)}return n}function nt(n){let[e,t]=xe(n.x,n.y),[r,o]=Q(e,t,n.z),[a,s]=Q(e+256,t+256,n.z);return{west:r,north:o,east:a,south:s}}function we(n){let e=F("div","leaflet-tile s-tile");return e.wxtile=new Te(n,e),(async()=>{let{wxtile:t}=e;try{await t.load(),t.draw()}catch(r){let{x:o,y:a,z:s}=t.coords;b(`tile(${o},${a},${s}) loading error: ${r}`)}n.done()})(),e}var Te=class{constructor({layer:e,coords:t},r){this.data=[];this.streamLines=[];this.coords=t,this.layer=e,this.canvasFill=F("canvas","s-tile canvas-fill",r),this.canvasSlines=F("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(a){let s=a.getContext("2d");if(!s)throw new Error("getCtx error");return s}this.canvasFillCtx=o(this.canvasFill),this.imageDataForFillCtx=this.canvasFillCtx.createImageData(256,256),this.canvasVectorAnimationCtx=o(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}async load(){let{coords:e,layer:t}=this;await t.setupCompletePromise;let r=this._getTileType();if(!r)return this.data=[],this.streamLines=[],this;let{upCoords:o,subCoords:a}=this._splitCoords(e),s=this.layer.state.baseURL.replace("{z}",String(o.z)).replace("{x}",String(o.x)).replace("{y}",String(o.y)),i=this.layer.dataSource.variables.map(m=>s.replace("{var}",m)),u;try{u=await Promise.all(i.map(t.loadDataIntegralFunc))}catch(m){return m.code!==DOMException.ABORT_ERR&&(this.data=[],this.streamLines=[]),this}let l=t.state.units==="degree"?tt:et,f=m=>l(me(m,t.style.blurRadius),a);return this.data=u.map(f),t.state.vector&&this._vectorMagnitudesPrepare(),await this._applyMask(r,a===void 0),t.state.vector&&this._createStreamLines(),this}async _applyMask(e,t){let{coords:r,layer:o}=this;if((o.style.mask==="land"||o.style.mask==="sea")&&e===T.Mixed){let a=o.dataSource.maskServerURI.replace("{z}",String(r.z)).replace("{x}",String(r.x)).replace("{y}",String(r.y));try{let s=await o.loadMaskFunc(a);if(!o.state.vector&&t){let{raw:i,dmin:u,dmax:l,dmul:f}=this.data[0];this.data[0]={raw:new Uint16Array(i),dmin:u,dmax:l,dmul:f}}rt(this.data[0],s,o.style.mask)}catch(s){o.style.mask=void 0,b("Can't load Mask. Masking is Turned OFF")}}}_splitCoords(e){let t=e.z-this.layer.state.meta.maxZoom;if(t<=0)return{upCoords:e};let r={x:e.x>>>t,y:e.y>>>t,z:this.layer.state.meta.maxZoom},o={x:e.x&(1<<t)-1,y:e.y&(1<<t)-1,z:t};return{upCoords:r,subCoords:o}}_getTileType(){let{coords:e,layer:t}=this,{mask:r}=t.style;var o=T.Mixed;if((r==="land"||r==="sea")&&(o=ye(e),r===o))return;let{boundaries:a}=t.state.meta;if(a==null?void 0:a.boundaries180){let s=nt(e),i=u=>!(s.west>u.east||u.west>s.east||s.south>u.north||u.south>s.north);if(!a.boundaries180.some(i))return}return o}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasVectorAnimationCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVectorsStatic(),this._drawDegreesStatic(),this._drawStreamLinesStatic())}clearVectorAnimationCanvas(){this.canvasVectorAnimationCtx.clearRect(0,0,256,256)}drawVectorAnimationLinesStep(e){if(this.streamLines.length===0)return;let t=this.canvasVectorAnimationCtx;if(t.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.streamLines=[];return}let r=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let o=0;o<this.streamLines.length;++o){let a=this.streamLines[o],s=a.length-1,i=(e+(1+a[0].x)*(1+a[0].y))%30;for(let u=0;u<s;++u){let l=a[u],f=a[u+1],m=1-(i-u)/s;(m<0||m>1)&&(m=0);let h=(~~(m*255)).toString(16);t.strokeStyle=r+(h.length<2?"0"+h:h);let d=1+~~((1.2-m)*5);t.lineWidth=d,t.beginPath(),t.moveTo(l.x,l.y),t.lineTo(f.x,f.y),t.stroke()}}}getPixelInfo({x:e,y:t}){var o;let r=(t+1)*258+(e+1);if(!!((o=this.data[0])==null?void 0:o.raw[r]))return{raw:this.data.map(a=>a.raw[r]),data:this.data.map(a=>a.raw[r]*a.dmul+a.dmin)}}_vectorMagnitudesPrepare(){if(this.data.length!==2)throw new Error("this.data !== 2");this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[e,t,r]=this.data;e.dmax=1.42*Math.max(-t.dmin,t.dmax,-r.dmin,r.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let o=0;o<258*258;++o){if(!t.raw[o]||!r.raw[o]){e.raw[o]=0;continue}let a=t.dmin+t.dmul*t.raw[o],s=r.dmin+r.dmul*r.raw[o];e.raw[o]=Math.sqrt(s*s+a*a)/e.dmul}}_drawFillAndIsolines(){let{imageDataForFillCtx:e}=this,{canvasFillCtx:t}=this,r=new Uint32Array(e.data.buffer),{raw:o}=this.data[0],{clut:a,style:s}=this.layer,{levelIndex:i,colorsI:u}=a;if(s.fill!=="none")for(let f=0,m=0,h=259;f<256;++f,h+=2)for(let d=0;d<256;++d,++m,++h)r[m]=u[o[h]];else r.fill(0);let l=[];if(s.isolineColor!=="none"){let f=s.isolineColor[0]==="#"?I(s.isolineColor):0;for(let m=0,h=0;m<256;m+=1)for(let d=0;d<256;d+=1){let g=(m+1)*258+(d+1),c=o[g],x=o[g+1],p=o[g+258];if(!c||!x||!p)continue;let y=i[c],C=i[x],S=i[p];if(y!==C||y!==S){let w=Math.max(y,C,S),D=Math.max(c,x,p),v=m*256+d;switch(s.isolineColor){case"inverted":r[v]=~u[D]|4278190080;break;case"fill":r[v]=u[D]|4278190080;break;default:r[v]=f;break}s.isolineText&&!(++h%255)&&d>20&&d<235&&m>20&&m<235&&l.push({x:d,y:m,d:c,dr:x,db:p,mli:w})}}}if(t.putImageData(e,0,0),l.length){t.font="1.1em Sans-serif",t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";for(let{x:f,y:m,d:h,dr:d,db:g,mli:c}of l){let x=this.layer.clut.ticks[c].dataString,p=Math.atan2(h-d,g-h);t.save(),t.translate(f,m),t.rotate(p<-1.57||p>1.57?p+3.14:p),t.strokeText(x,0,0),t.fillText(x,0,0),t.restore()}}}_drawStreamLinesStatic(){if(!this.streamLines.length||!this.layer.style.streamLineStatic)return;let{canvasVectorAnimationCtx:e}=this;if(this.layer.style.streamLineColor==="none"){this.streamLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let t=this.streamLines.length;t--;){let r=this.streamLines[t];for(let o=0;o<r.length-1;++o){let a=r[o],s=r[o+1];e.moveTo(a.x,a.y),e.lineTo(s.x,s.y)}}e.stroke()}_drawVectorsStatic(){let{clut:e,style:t}=this.layer;if(!this.layer.state.vector||!e.DataToKnots||t.vectorColor==="none"||t.vectorType==="none")return;if(this.data.length!==3)throw new Error("this.data.length !== 3");let[r,o,a]=this.data,{canvasVectorCtx:s}=this;switch(t.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=t.vectorType}s.textAlign="center",s.textBaseline="middle";let i=t.addDegrees?.017453292519943*t.addDegrees:0,u=32;for(let l=u/2;l<256;l+=u)for(let f=u/2;f<256;f+=u){let m=f+1+(l+1)*258;if(!r.raw[m])continue;let h=Math.atan2(o.dmin+o.raw[m]*o.dmul,a.dmin+a.raw[m]*a.dmul),d=r.dmin+r.raw[m]*r.dmul,g=t.vectorType!=="barbs"?t.vectorFactor*.2:.2,c=Math.min(e.DataToKnots(d)*g,25)+65,x=String.fromCharCode(c);switch(t.vectorColor){case"inverted":s.fillStyle=L(~e.colorsI[r.raw[m]]);break;case"fill":s.fillStyle=L(e.colorsI[r.raw[m]]);break;default:s.fillStyle=t.vectorColor;break}s.save(),s.translate(f,l),s.rotate(h+i),s.fillText(x,0,0),s.restore()}}_drawDegreesStatic(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:e}=this,t=.017453292519943*this.layer.style.addDegrees;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle";let r=this.data[0],o="L",a=32;for(let s=a/2;s<256;s+=a)for(let i=a/2;i<256;i+=a){let u=i+1+(s+1)*258;if(!r.raw[u])continue;let f=(r.dmin+r.raw[u]*r.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=L(~this.layer.clut.colorsI[r.raw[u]]);break;case"fill":e.fillStyle=L(this.layer.clut.colorsI[r.raw[u]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(i,s),e.rotate(f+t),e.fillText(o,0,0),e.restore()}}_createStreamLines(){if(this.data.length!==3)throw new Error("this.data.length !== 3");let{style:e}=this.layer;if(e.streamLineColor==="none")return;this.streamLines=[];let[t,r,o]=this.data,a=(e.streamLineSpeedFactor||1)/t.dmax,s=e.addDegrees?.017453292519943*e.addDegrees:0,i=64,u=300;for(let l=0;l<=256;l+=i)for(let f=0;f<=256;f+=i){if(!t.raw[1+f+(1+l)*258])continue;let m=[],h=f,d=l,g=-1,c=0,x=0;for(let C=0;C<=u&&h>=0&&h<=256&&d>=0&&d<=256;C++){C%(u/10)||m.push({x:~~h,y:~~d});let S=~~h+1+(~~d+1)*258;if(S!==g){if(!t.raw[S])break;g=S;let w=t.dmin+t.raw[S]*t.dmul,D=r.dmin+r.raw[S]*r.dmul,v=o.dmin+o.raw[S]*o.dmul,M=Math.atan2(D,v)+s;c=a*w*Math.sin(M),x=a*w*Math.cos(M)}h+=c,d-=x}let p=f,y=l;g=-1;for(let C=1;C<=u&&p>=0&&p<=256&&y>=0&&y<=256;C++){C%(u/10)||m.unshift({x:~~p,y:~~y});let S=~~p+1+(~~y+1)*258;if(S!==g){if(!t.raw[S])break;g=S;let w=t.dmin+t.raw[S]*t.dmul,D=r.dmin+r.raw[S]*r.dmul,v=o.dmin+o.raw[S]*o.dmul,M=Math.atan2(D,v)+s;c=a*w*Math.sin(M),x=a*w*Math.cos(M)}p-=c,y+=x}m.length>2&&this.streamLines.push(m)}}};var $;var q=class extends ve.default.GridLayer{constructor(e){super(e.options);this.styles=H();this.redrawRequestID=0;this.vectorAnimationRequestID=0;this.oldMaxZoom=0;this.style=Object.assign({},this.styles.base);this.clut=new W(this.style,"",[0,2],!1);this.animation=!0;let{dataSource:t,lazy:r}=e;if(b("Creating a WxTiles layer:",t.name,". Params:",JSON.stringify(e)),!(t==null?void 0:t.ext)||!t.dataset||!t.name||!t.serverURI||!t.styleName||!Array.isArray(t.variables)||t.variables.length<1||t.variables.length>2){let i="WxTilesLayer: dataSource is wrong!";throw b(i),new Error(i)}this.dataSource=t,this.state={originURI:t.serverURI+"/"+t.dataset+"/",units:"",baseURL:"",meta:{maxZoom:0,times:[],variables:[],variablesMeta:{}},instance:"",minmax:[[0,1]],currentTime:"",vector:t.variables.length>1},this.loadDataIntegralFunc=z(t.requestInit),$||($=ue(t.requestInit)),this.loadMaskFunc=$;let o=()=>{var i;((i=this._map)==null?void 0:i.getZoom())<this.state.meta.maxZoom&&this._stopLoadingResetLoadDataFunc()},a=()=>{if(b("onadd:",this.dataSource.name),!this._map)throw new Error("_map is not set!");this._map.on("zoomstart",o),this._checkAndStartVectorAnimation()},s=()=>{if(b("onremove:",this.dataSource.name),!this._map)throw new Error("_map is not set!");this._map.off("zoomstart",o),this._stopLoadingResetLoadDataFunc()};this.on("remove",s),this.on("add",a),this.setupCompletePromise=new Promise(i=>{let u=async()=>{b("Setup:",t.name),await this._setUpDataSet(),b("Setup complete: ",this.dataSource.name),i()};r?this.once("add",u):u()})}async _setUpDataSet(){let{state:e,dataSource:t}=this;try{e.instance=(await A(e.originURI+"instances.json")).pop()+"/"}catch(o){let a=t.name+": load instances.json error: "+o;throw b(a),new Error(a)}try{let o=e.originURI+e.instance+"meta.json";e.meta=await A(o)}catch(o){let a=t.name+": load meta.json error: "+o;throw b(a),new Error(a)}e.vector=t.variables.length===2;let{variablesMeta:r}=e.meta;if(e.units=r[t.variables[0]].units,e.minmax=t.variables.map(o=>[r[o].min,r[o].max]),e.vector){let[[o,a],[s,i]]=e.minmax;e.minmax.unshift([0,1.42*Math.max(-o,a,-s,i)])}this._setStyleAndCLUT(t.styleName),this._setTimeUrl(new Date)}async _requestReloadTilesAndRedraw(){let e=await this._requestReloadTiles();return e&&this._redrawTiles(),e}async _requestReloadTiles(){b(`_requestReloadTiles: start - ${this.dataSource.name}`);let{controller:e}=this.loadDataIntegralFunc.controllerHolder;return await Promise.allSettled(this._ForEachWxTile(t=>t.load())),b(`_requestReloadTiles: end - ${this.dataSource.name}, aborted: ${e.signal.aborted}`),!e.signal.aborted}async setStyle(e){b("setStyle(",e,") for ",this.dataSource.name),(e==="custom"||e!==this.dataSource.styleName)&&(this._setStyleAndCLUT(e),this._checkAndStartVectorAnimation(),await this._requestReloadTilesAndRedraw()),b("setStyle(",e,'): "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete.")}_setStyleAndCLUT(e){let{dataSource:t,styles:r,state:o}=this;t.styleName=e,e==="custom"&&(r.custom.parent&&r.custom.parent in r||(b(`cant find the parent style (${r.custom.parent}), 'base' is used`),r.custom.parent="base"),r.custom=Object.assign(Object.assign({},r[r.custom.parent]),r.custom)),e in r||(b(`cant find the style (${e}), 'base' is used`),e=t.styleName="base");try{this.style=Object.assign({},r[e]),this.style.streamLineColor=be(this.style.streamLineColor),this.clut=new W(this.style,o.units,o.minmax[0],o.vector)}catch(a){let s="setStyle: impossible error in RawCLUT: "+a;throw b(s),new Error(s)}}createTile(e,t){return we({layer:this,coords:e,done:t})}getSetupCompletePromise(){return this.setupCompletePromise}async checkDataChanged(){b("checkDataChanged");try{let e=await A(this.state.originURI+"instances.json"),t=e[e.length-1]+"/";if(this.state.instance!==t)return!0;let r=await A(this.state.originURI+t+"meta.json");return this.state.meta.times.toString()!==r.times.toString()}catch(e){return!1}}getLayerInfoAtLatLon(e){if(!this._map)return;let t=this._map.getZoom(),r=this._map.project(e,t),o=r.divideBy(256).floor(),a=this._getCachedTile(o,t);if(!a)return;let s=r.subtract(o.multiplyBy(256)).floor(),i=a.getPixelInfo(s);if(!i)return;let{raw:u,data:l}=i,f=u.map(d=>this.clut.colorsI[d]),m=f.map(L),h=l.map(d=>this.clut.DataToStyle(d));return{wxtile:a,data:l,raw:u,rgba:f,hexColor:m,inStyleUnits:h,tilePoint:s,styleUnits:this.style.units,dataUnits:this.state.units}}getStyle(){return this.style}_getFirstNonEmptyTile(){for(let e in this._tiles){let{wxtile:t}=this._tiles[e].el;if(t==null?void 0:t.data.length)return t}}_setTimeUrl(e){let{dataSource:t,state:r}=this,o=de(r.meta.times,e);return r.currentTime===o?(b("_setTimeUrl: the same time - skipped"),!1):(r.currentTime=o,r.baseURL=r.originURI+r.instance+`{var}/${r.currentTime}/{z}/{x}/{y}.${t.ext}`,b(`_setTimeUrl: ${o} for ${t.name} complete`),!0)}setTime(e){if(b("setTime: "+e+" for "+this.dataSource.name+" start"),!this._tiles)return b("setTime: no tiles - skipped"),Promise.resolve(!1);let{currentTime:t}=this.state;if(!this._setTimeUrl(e))return Promise.resolve(!1);this.loadDataIntegralFunc.abort();let r=this._requestReloadTiles();return r.then(o=>{if(!o){this.state.currentTime=t;return}let a=this._getFirstNonEmptyTile();if(a==null?void 0:a.data.length){let[s,i]=this.state.minmax[0],{dmin:u,dmax:l}=a.data[0];(Math.abs(u-s)>.01||Math.abs(l-i)>.01)&&(this.state.minmax=a.data.map(f=>[f.dmin,f.dmax]),this._setStyleAndCLUT(this.dataSource.styleName))}this._redrawTiles()}),r}getTime(){return this.state.currentTime}getTimes(){return b("getTimes"),this.state.meta.times}getLegendData(e){return b("getLegendData"),V(e,this.style)}setTimeAnimationMode(e=2){b("setTimeAnimationMode"),this.oldMaxZoom=this.state.meta.maxZoom;let t=this._map.getZoom(),o=(t<this.oldMaxZoom?t:this.oldMaxZoom)-e;this.state.meta.maxZoom=o<0?0:o}async unsetTimeAnimationMode(){return b("unsetTimeAnimationMode"),this.oldMaxZoom&&(this.state.meta.maxZoom=this.oldMaxZoom),this._requestReloadTilesAndRedraw()}getMinMax(){let[e,t]=this.state.minmax[0];return{min:e,max:t}}setAnimation(e){return b("setAnimation"),this.animation=e,this._checkAndStartVectorAnimation(),this.animation}_getCachedTile({x:e,y:t},r){var o,a;return(a=(o=this._tiles[`${e}:${t}:${r}`])==null?void 0:o.el)==null?void 0:a.wxtile}_ForEachWxTile(e){var r;let t=[];for(let o in this._tiles){let a=(r=this._tiles[o].el)==null?void 0:r.wxtile;a&&t.push(e(a))}return t}_stopLoadingResetLoadDataFunc(){this.loadDataIntegralFunc.abort(),this.loadDataIntegralFunc=z()}_checkAndStartVectorAnimation(){if(this.vectorAnimationRequestID)return;let e=t=>{if(!this._map||!this.animation||!this.state.vector||this.style.streamLineStatic||this.style.streamLineColor==="none"){this._ForEachWxTile(r=>r.clearVectorAnimationCanvas()),this.vectorAnimationRequestID=0;return}this._ForEachWxTile(r=>r.drawVectorAnimationLinesStep(t)),this.vectorAnimationRequestID=requestAnimationFrame(e)};this.vectorAnimationRequestID=requestAnimationFrame(e)}_redrawTiles(){this.redrawRequestID||(b("_redrawTiles: start: "+this.dataSource.name),this.redrawRequestID=requestAnimationFrame(()=>{this._ForEachWxTile(e=>e.draw()),this.redrawRequestID=0,b("_redrawTiles: requestAnimationFrame: end: "+this.dataSource.name)}))}};function ot(n){return new q(n)}var Le=class extends B.default.Control{constructor(e){super(e);this.URI=e.URI}onAdd(){let e=document.createElement("img");return e.src=this.URI,e.className="wxtiles-logo",e}};function Ot(n){return b("Add watermark:",JSON.stringify(n)),new Le(n)}var Ie=class extends B.default.GridLayer{createTile(e){let t=document.createElement("div");return t.innerHTML=[e.x,e.y,e.z].join(", "),t.style.outline="1px solid red",t}};function Ht(){return b("Add WxDebugCoordsLayer:"),new Ie().setZIndex(1e3)}function jt(n,e){return B.default.layerGroup(n.map(ot),e)}export{Ht as CreateWxDebugCoordsLayer,jt as CreateWxTilesGroupLayer,ot as CreateWxTilesLayer,Ot as CreateWxTilesWatermark,Xe as LoadQTree,Ie as WxDebugLayer,j as WxGetColorSchemes,H as WxGetColorStyles,q as WxTilesLayer,We as WxTilesLibSetup,Ze as WxTilesLogging,Le as WxWatermark,A as fetchJson};
|
package/dist/web/wxtiles.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var wxtilesjs=(()=>{var Pe=Object.create;var A=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames,Y=Object.getOwnPropertySymbols,We=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var te=(n,e,t)=>e in n?A(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,re=(n,e)=>{for(var t in e||(e={}))ee.call(e,t)&&te(n,t,e[t]);if(Y)for(var t of Y(e))Ee.call(e,t)&&te(n,t,e[t]);return n};var ne=n=>A(n,"__esModule",{value:!0});var ut=typeof require!="undefined"?require:n=>{throw new Error('Dynamic require of "'+n+'" is not supported')};var qe=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Be=(n,e)=>{ne(n);for(var t in e)A(n,t,{get:e[t],enumerable:!0})},Oe=(n,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ue(e))!ee.call(n,r)&&r!=="default"&&A(n,r,{get:()=>e[r],enumerable:!(t=Fe(e,r))||t.enumerable});return n},oe=n=>Oe(ne(A(n!=null?Pe(We(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var H=qe((ht,ae)=>{ae.exports=window.L});var ct={};Be(ct,{CreateWxDebugCoordsLayer:()=>it,CreateWxTilesGroupLayer:()=>lt,CreateWxTilesLayer:()=>Re,CreateWxTilesWatermark:()=>st,LoadQTree:()=>we,WxDebugLayer:()=>J,WxGetColorSchemes:()=>U,WxGetColorStyles:()=>F,WxTilesLayer:()=>k,WxTilesLibSetup:()=>ue,WxTilesLogging:()=>pe,WxWatermark:()=>X,fetchJson:()=>M});var O=oe(H());var se={comment1:["'degC': ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["'hPa': ['Pa', 1000]' -> hPa = Pa * 1000 + 0 (0 - could be ommited)",0],K:["K",1],kelvin:["K",1],F:["K",.5555555555,255.372222222],C:["K",1,273.15],degC:["K",1,273.15],"kg/m^2/s":["kg/m^2/s",1],"Kg/m^2/s":["kg/m^2/s",1],"Kg m**-2 s**-1":["kg/m^2/s",1],"Kg m^-2 s^-1":["kg/m^2/s",1],"Kg m^{-2} s^-1":["kg/m^2/s",1],"mm/h":["kg/m^2/s",.00027777777],"mm/hr":["kg/m^2/s",.00027777777],"W/m^2":["W/m^2",1],"W m^-2":["W/m^2",1],"W m^{-2}":["W/m^2",1],"W/m**2":["W/m^2",1],"W m**-2":["W/m^2",1],"m/s":["m/s",1],"m s**-1":["m/s",1],"m s^-1":["m/s",1],"m.s^{-1}":["m/s",1],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["m/s",.27777777777],"km h^-1":["m/s",.27777777777],"km h**-1":["m/s",.27777777777],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],inch:["m",.0254],Pa:["Pa",1],hPa:["Pa",100],degree:["degree",1],radian:["degree",57.3],"mg/m^3":["mg/m^3",1],"mg m^-3":["mg/m^3",1],"mg.m^-3":["mg/m^3",1],"%":["%",1],"(0 - 1)":["%",100]};var ie={none:["#00000000","#00000000"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbowzerro:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow2:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebirdzerro:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bw:["#000000ff","#ffffffff"],wb:["#ffffffff","#000000ff"],redish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]};var P={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,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"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,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"}};var z,le,ce;function ue({colorStyles:n={},units:e={},colorSchemes:t={}}={}){b("WxTile lib setup: start"),z=Object.assign({},se,e),le=Object.assign({},t,ie);let r=Object.assign({},n,P);ce=He(r),b("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),b("WxTile lib setup is done.")}function F(){return ce}function U(){return le}function W(n,e,t){let r=t?Object.assign({},z,t):z;if(!r||!n||!e||n===e||!r[n]||!r[e]||r[n][0]!==r[e][0]){b(n===e?"Trivial converter:":"Inconvertible units. Default converter is used:",n," -> ",e);let s=i=>i;return s.trivial=!0,s}b("Converter: From:",n," To:",e);let o=r[n][1]/r[e][1],a=(r[n][2]||0)/r[e][1]-(r[e][2]||0)/r[e][1];return a?s=>o*s+a:s=>o*s}function He(n){let e=Object.assign({},P);for(let o in n){let a=n[o];if(Array.isArray(a))for(let s=0;s<a.length;++s)e[o+"["+s+"]"]=Object.assign({},a[s]);else e[o]=Object.assign({},a)}let t=(o,a)=>{if(a==="base")return P.base;let s=o[a];(!s.parent||!(s.parent in o))&&(s.parent="base");let i=t(o,s.parent);return Object.assign(s,Object.assign({},i,s,{parent:"base"}))},r={};for(let o in e)r[o]=t(e,o);return r}function ze(n){let e=new Map;return t=>{let r=e.get(t);if(r)return r;let o=n(t);return e.set(t,o),o.catch(a=>{a.code===DOMException.ABORT_ERR&&e.delete(t)}),o}}async function Ze(n,e){let t=new Image;return t.src=URL.createObjectURL(await(await fetch(n,e)).blob()),await t.decode(),URL.revokeObjectURL(t.src),t}function je(n){let{width:e,height:t}=n,r=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d");if(!r)throw new Error("Error: can not create context. Catastrophe");return r.drawImage(n,0,0),r.getImageData(0,0,e,t)}async function me(n,e){return je(await Ze(n,e))}function Ve(n){n.data[34]<1&&b("Warning: image is in too old format. Check the version of the Splitter.");let e=new Uint16Array(n.data.buffer),t=new Uint16Array(e.length/2);for(let u=0;u<t.length;u++)t[u]=e[u*2];let r=new Uint8Array(8);for(let u=0;u<8;++u)r[u]=n.data[u*4+2];let o=new DataView(r.buffer),a=o.getFloat32(0,!0),s=o.getFloat32(4,!0),i=(s-a)/65535,c=Qe(t);return{raw:t,dmin:a,dmax:s,dmul:i,integral:c,radius:0}}async function Ge(n,e){return Ve(await me(n,e))}function fe(n,e){let t={controller:new AbortController,debug:Date.now().toString()},r=Object.assign({},e,{signal:t.controller.signal}),o=ze(a=>n(a,r));return o.controllerHolder=t,o.abort=()=>{t.controller.abort(),t.controller=new AbortController,t.debug=Date.now().toString(),r.signal=t.controller.signal},o}function Z(n){return fe(Ge,n)}function de(n){return fe(me,n)}function Qe(n){let e=new Uint32Array(258*258),t=new Uint32Array(258*258);e[0]=n[0],t[0]=n[0]===0?0:1;for(let r=1;r<258;++r)e[r]=n[r]+e[r-1],e[258*r]=n[258*r]+e[258*r-258],t[r]=(n[r]===0?0:1)+t[r-1],t[258*r]=(n[258*r]===0?0:1)+t[258*r-258];for(let r=1,o=259;r<258;++r,++o)for(let a=1;a<258;++a,++o)e[o]=n[o]+e[o-258]+e[o-1]-e[o-258-1],t[o]=(n[o]===0?0:1)+t[o-258]+t[o-1]-t[o-258-1];return{integral:e,integralNZ:t}}function he(n,e){if(e<0||e===n.radius)return n;n.radius=e;let t=258,{integral:r,integralNZ:o}=n.integral;for(let a=1;a<t;a++)for(let s=1;s<t;s++){if(!n.raw[t*a+s])continue;let i=Math.min(e,s-1,t-1-s),c=Math.min(e,a-1,t-1-a),u=t*(a-c-1)+s,f=t*(a+c)+s,l=o[u-i-1],d=o[u+i],h=o[f-i-1],g=o[f+i],m=l+g-d-h,x=r[u-i-1],p=r[u+i],y=r[f-i-1],C=r[f+i],v=x+C-p-y;n.raw[a*t+s]=v/m}return n}function w(n){let e=n>>0&255,t=n>>8&255,r=n>>16&255,o=e.toString(16),a=t.toString(16),s=r.toString(16);return o=o.length===2?o:"0"+o,a=a.length===2?a:"0"+a,s=s.length===2?s:"0"+s,"#"+o+a+s}function T(n){if(n[0]==="#"){if(n.length===4)return+("0xff"+n[3]+n[3]+n[2]+n[2]+n[1]+n[1]);if(n.length===7)return+("0xff"+n[5]+n[6]+n[3]+n[4]+n[1]+n[2]);if(n.length===9)return+("0x"+n[7]+n[8]+n[5]+n[6]+n[3]+n[4]+n[1]+n[2])}return b("wrong color format",n),0}async function M(n,e){return(await fetch(n,e)).json()}function E(n,e="",t){var o;let r=document.createElement(n);return r.className=e,t&&((o=t.appendChild)==null||o.call(t,r)),r}function j(n,e,t){let r=n>>0&255,o=n>>8&255,a=n>>16&255,s=n>>>24,i=e>>0&255,c=e>>8&255,u=e>>16&255,f=e>>>24,l=r+t*(i-r),d=o+t*(c-o),h=a+t*(u-a),g=s+t*(f-s);return l|d<<8|h<<16|g<<24}function be(n,e,t){let r=[];for(let o=0;o<t;++o)r.push(o*(e-n)/(t-1)+n);return r}function ge(n,e){let t=typeof e=="number"?e:typeof e=="string"?new Date(e).getTime():e.getTime();return n.find(r=>new Date(r).getTime()>=t)||n[n.length-1]}var xe=!1;function pe(n){console.log(n?"Logging on":"Logging off"),xe=n}function b(...n){xe&&console.trace(...n)}function ye(n){return n!=="none"&&n.length<7?"#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]:n}var Me=oe(H());function Ne(n,e,t){return n>t?t:n<e?e:n}var q=class{constructor(e,t,[r,o],a){let s=o-r;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let i=[];this.DataToStyle=W(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),a&&(this.DataToKnots=W(t,"knot"));let c=W(e.units,t,e.extraUnits),u=m=>~~(65535*Ne((c(m)-r)/(o-r),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((m,x)=>m[0]<x[0]?-1:m[0]>x[0]?1:0);for(let[m]of e.colorMap)i.push(u(m))}else{if(e.levels||(e.levels=be(this.DataToStyle(r),this.DataToStyle(o),10)),e.levels.sort((m,x)=>m<x?-1:m>x?1:0),!e.colors){let m=U();e.colorScheme&&e.colorScheme in m?e.colors=m[e.colorScheme]:e.colors=m.wb}for(let m of e.levels)i.push(u(m))}let f=65536,l=V(f,e);this.ticks=l.ticks;let d=l.ticks[0].data,g=l.ticks[l.ticks.length-1].data-d;for(let m=0;m<65536;++m){let x=s*m/65535+r,p=this.DataToStyle(x),y=Math.round((f-1)*(p-d)/g);y<=0?this.colorsI[m]=e.showBelowMin?l.colors[0]:0:y>=f?this.colorsI[m]=e.showAboveMax?l.colors[f-1]:0:this.colorsI[m]=l.colors[y]}this.colorsI[0]=0;for(let m=0;m<i[0];++m)this.levelIndex[m]=0;for(let m=0;m<i.length-1;m++)for(let x=i[m];x<i[m+1]+1;++x)this.levelIndex[x]=m;for(let m=i[i.length-1];m<65536;++m)this.levelIndex[m]=i.length-1}};function Ce(n){var t;if(n!==0&&-.1<n&&n<.1)return n.toExponential(2);let e=n.toString();return((t=e.split(".")[1])==null?void 0:t.length)>2?n.toFixed(2):e}function V(n,e){let t={size:n,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(n),ticks:[]},{colorMap:r,levels:o,colors:a}=e,s=e.fill!=="solid";if(r){let d=r[0][0],h=r[r.length-1][0]-d;for(let[g,m]of r){let x=~~((g-d)/h*(n-1)),p={data:g,dataString:Ce(g),color:m,pos:x};t.ticks.push(p)}for(let g=0;g<r.length-1;g++){let m=t.ticks[g].pos,x=t.ticks[g+1].pos,p=T(r[g][1]),y=s?T(r[g+1][1]):0;for(let C=m;C<x;++C)t.colors[C]=s?j(p,y,(C-m)/(x-m)):p}return t.colors[n-1]=T(r[r.length-1][1]),t}if(!a||!o)return t;let i=0,c=0,u=-1;for(let d=0;d<n;++d){let h=d*(a.length-1)/n;u!==~~h&&(u=~~h,i=T(a[u]),c=a.length>u+1?T(a[u+1]):i),t.colors[d]=s?j(i,c,h-u):i}t.colors[n-1]=T(a[a.length-1]);let f=o[0],l=(n-1)/(o[o.length-1]-f);for(let d of o){let h=~~((d-f)*l),g={data:d,dataString:Ce(d),color:w(t.colors[h]),pos:h};t.ticks.push(g)}return t}var G=256,Ke=2*Math.PI*6378137/G,B=2*Math.PI*6378137/2;function $e(n,e){let t=n/B*180,r=e/B*180;return r=180/Math.PI*(2*Math.atan(Math.exp(r*Math.PI/180))-Math.PI/2),[r,t]}function Xe(n,e,t){let r=Je(t),o=n*r-B,a=e*r-B;return[o,a]}function Je(n){return Ke/Math.pow(2,n)}function Q(n,e,t){let[r,o]=$e(...Xe(n,e,t));return[o,-r]}function Se(n,e){return[n*G,e*G]}var Ye="A".charCodeAt(0),N,I=0;async function we(n,e){let t;try{t=await(await fetch(n,e)).json()}catch(r){console.log("Can't load QTree:",r);return}N=R(t,{pos:0}),I=Te(N),console.log("Loaded QTree, depth:",I)}function R(n,e){let t=n.charCodeAt(e.pos)-Ye;e.pos++;let r=t&1?R(n,e):null,o=t&2?R(n,e):null,a=t&4?R(n,e):null,s=t&8?R(n,e):null;return{sub:r||o||a||s?[r,o,a,s]:null}}function Te(n){let e=0;if(n==null?void 0:n.sub){for(let t=0;t<4;t++)if(n.sub[t]!==null){let r=Te(n.sub[t])+1;e<r&&(e=r)}}return e}var S;(function(r){r.Land="land",r.Mixed="mixed",r.Sea="sea"})(S||(S={}));function ve(n){if(!I)return S.Mixed;let e=re({},n),t=!1;if(I<=n.z){t=!0;let r=n.z-I;e={x:n.x>>r,y:n.y>>r,z:I}}return Le(N,e,t)}function Le(n,e,t){if(n===null)return S.Land;if(t&&e.z===0)return S.Mixed;if(n.sub===null)return S.Sea;if(e.z===0)return S.Mixed;e.z--;let r=e.x>>e.z&1,a=(e.y>>e.z&1)<<1|r;return Le(n.sub[a],e,t)}function K(n,e,t){let r=((e-n)%360+540)%360-180;return(n+r*t+360)%360}function et(n,e,t,r,o,a,s,i){switch((n?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 0:return 0;case 1:return n;case 2:return e;case 3:t=n,r=e;break;case 4:return t;case 5:e=n,r=t;break;case 6:r=e+t>>1,n=r;break;case 7:r=e+t>>1;break;case 8:return r;case 9:e=n+r>>1,t=e;break;case 10:n=e,t=r;break;case 11:t=n+r>>1;break;case 12:n=t,e=r;break;case 13:e=n+r>>1;break;case 14:n=e+t>>1;break}n=s+i*n,e=s+i*e,t=s+i*t,r=s+i*r;let u=K(n,e,o),f=K(t,r,o);return(K(u,f,a)-s)/i||1}function tt(n,e,t,r,o,a,s,i){switch((n?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 7:return o+a<1?o*(e-n)+a*(t-n)+n:0;case 14:return o+a<1?0:o*(r-t)+a*(r-e)+e+t-r;case 11:return a<o?(1-o)*(n-e)+a*(r-e)+e:0;case 13:return a<o?0:(1-o)*(t-r)+a*(t-n)+n+r-t;case 15:return o+a<1?o*(e-n)+a*(t-n)+n:o*(r-t)+a*(r-e)+e+t-r;default:return 0}}function Ie(n,e,t){if(!t)return e;let r=.9999999/Math.pow(2,t.z),o=t.x*256*r,a=t.y*256*r,{raw:s,dmin:i,dmax:c,dmul:u}=e,f={raw:new Uint16Array(258*258),dmin:i,dmax:c,dmul:u},{raw:l}=f;for(let d=-1,h=0;d<=256;d++){let g=a+d*r,m=Math.floor(g),x=g-m;for(let p=-1;p<=256;p++,h++){let y=o+p*r,C=Math.floor(y),v=y-C,L=C+1+(m+1)*258,_=s[L],D=s[L+1],ke=s[L+258],_e=s[L+258+1];l[h]=n(_,D,ke,_e,v,x,i,u)}}return f}function rt(n,e){return Ie(tt,n,e)}function nt(n,e){return Ie(et,n,e)}function ot(n,e,t){let r=t==="land"?1:0;for(let o=3,a=0;a<256;a++)for(let s=0;s<256;s++,o+=4){let i=e.data[o]?1:0;r^i&&(n.raw[(a+1)*258+(s+1)]=0)}return n}function at(n){let[e,t]=Se(n.x,n.y),[r,o]=Q(e,t,n.z),[a,s]=Q(e+256,t+256,n.z);return{west:r,north:o,east:a,south:s}}function De(n){let e=E("div","leaflet-tile s-tile");return e.wxtile=new Ae(n,e),(async()=>{let{wxtile:t}=e;try{await t.load(),t.draw()}catch(r){let{x:o,y:a,z:s}=t.coords;b(`tile(${o},${a},${s}) loading error: ${r}`)}n.done()})(),e}var Ae=class{constructor({layer:e,coords:t},r){this.data=[];this.streamLines=[];this.coords=t,this.layer=e,this.canvasFill=E("canvas","s-tile canvas-fill",r),this.canvasSlines=E("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(a){let s=a.getContext("2d");if(!s)throw new Error("getCtx error");return s}this.canvasFillCtx=o(this.canvasFill),this.imageDataForFillCtx=this.canvasFillCtx.createImageData(256,256),this.canvasVectorAnimationCtx=o(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}async load(){let{coords:e,layer:t}=this;await t.setupCompletePromise;let r=this._getTileType();if(!r)return this.data=[],this.streamLines=[],this;let{upCoords:o,subCoords:a}=this._splitCoords(e),s=this.layer.state.baseURL.replace("{z}",String(o.z)).replace("{x}",String(o.x)).replace("{y}",String(o.y)),i=this.layer.dataSource.variables.map(l=>s.replace("{var}",l)),c;try{c=await Promise.all(i.map(t.loadDataIntegralFunc))}catch(l){return l.code!==DOMException.ABORT_ERR&&(this.data=[],this.streamLines=[]),this}let u=t.state.units==="degree"?nt:rt,f=l=>u(he(l,t.style.blurRadius),a);return this.data=c.map(f),t.state.vector&&this._vectorMagnitudesPrepare(),await this._applyMask(r,a===void 0),t.state.vector&&this._createStreamLines(),this}async _applyMask(e,t){let{coords:r,layer:o}=this;if((o.style.mask==="land"||o.style.mask==="sea")&&e===S.Mixed){let a=o.dataSource.maskServerURI.replace("{z}",String(r.z)).replace("{x}",String(r.x)).replace("{y}",String(r.y));try{let s=await o.loadMaskFunc(a);if(!o.state.vector&&t){let{raw:i,dmin:c,dmax:u,dmul:f}=this.data[0];this.data[0]={raw:new Uint16Array(i),dmin:c,dmax:u,dmul:f}}ot(this.data[0],s,o.style.mask)}catch(s){o.style.mask=void 0,b("Can't load Mask. Masking is Turned OFF")}}}_splitCoords(e){let t=e.z-this.layer.state.meta.maxZoom;if(t<=0)return{upCoords:e};let r={x:e.x>>>t,y:e.y>>>t,z:this.layer.state.meta.maxZoom},o={x:e.x&(1<<t)-1,y:e.y&(1<<t)-1,z:t};return{upCoords:r,subCoords:o}}_getTileType(){let{coords:e,layer:t}=this,{mask:r}=t.style;var o=S.Mixed;if((r==="land"||r==="sea")&&(o=ve(e),r===o))return;let{boundaries:a}=t.state.meta;if(a==null?void 0:a.boundaries180){let s=at(e),i=c=>!(s.west>c.east||c.west>s.east||s.south>c.north||c.south>s.north);if(!a.boundaries180.some(i))return}return o}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasVectorAnimationCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVectorsStatic(),this._drawDegreesStatic(),this._drawStreamLinesStatic())}clearVectorAnimationCanvas(){this.canvasVectorAnimationCtx.clearRect(0,0,256,256)}drawVectorAnimationLinesStep(e){if(this.streamLines.length===0)return;let t=this.canvasVectorAnimationCtx;if(t.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.streamLines=[];return}let r=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let o=0;o<this.streamLines.length;++o){let a=this.streamLines[o],s=a.length-1,i=(e+(1+a[0].x)*(1+a[0].y))%30;for(let c=0;c<s;++c){let u=a[c],f=a[c+1],l=1-(i-c)/s;(l<0||l>1)&&(l=0);let d=(~~(l*255)).toString(16);t.strokeStyle=r+(d.length<2?"0"+d:d);let h=1+~~((1.2-l)*5);t.lineWidth=h,t.beginPath(),t.moveTo(u.x,u.y),t.lineTo(f.x,f.y),t.stroke()}}}getPixelInfo({x:e,y:t}){var o;let r=(t+1)*258+(e+1);if(!!((o=this.data[0])==null?void 0:o.raw[r]))return{raw:this.data.map(a=>a.raw[r]),data:this.data.map(a=>a.raw[r]*a.dmul+a.dmin)}}_vectorMagnitudesPrepare(){if(this.data.length!==2)throw new Error("this.data !== 2");this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[e,t,r]=this.data;e.dmax=1.42*Math.max(-t.dmin,t.dmax,-r.dmin,r.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let o=0;o<258*258;++o){if(!t.raw[o]||!r.raw[o]){e.raw[o]=0;continue}let a=t.dmin+t.dmul*t.raw[o],s=r.dmin+r.dmul*r.raw[o];e.raw[o]=Math.sqrt(s*s+a*a)/e.dmul}}_drawFillAndIsolines(){let{imageDataForFillCtx:e}=this,{canvasFillCtx:t}=this,r=new Uint32Array(e.data.buffer),{raw:o}=this.data[0],{clut:a,style:s}=this.layer,{levelIndex:i,colorsI:c}=a;if(s.fill!=="none")for(let f=0,l=0,d=259;f<256;++f,d+=2)for(let h=0;h<256;++h,++l,++d)r[l]=c[o[d]];else r.fill(0);let u=[];if(s.isolineColor!=="none"){let f=s.isolineColor[0]==="#"?T(s.isolineColor):0;for(let l=0,d=0;l<256;l+=1)for(let h=0;h<256;h+=1){let g=(l+1)*258+(h+1),m=o[g],x=o[g+1],p=o[g+258];if(!m||!x||!p)continue;let y=i[m],C=i[x],v=i[p];if(y!==C||y!==v){let L=Math.max(y,C,v),_=Math.max(m,x,p),D=l*256+h;switch(s.isolineColor){case"inverted":r[D]=~c[_]|4278190080;break;case"fill":r[D]=c[_]|4278190080;break;default:r[D]=f;break}s.isolineText&&!(++d%255)&&h>20&&h<235&&l>20&&l<235&&u.push({x:h,y:l,d:m,dr:x,db:p,mli:L})}}}if(t.putImageData(e,0,0),u.length){t.font="1.1em Sans-serif",t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";for(let{x:f,y:l,d,dr:h,db:g,mli:m}of u){let x=this.layer.clut.ticks[m].dataString,p=Math.atan2(d-h,g-d);t.save(),t.translate(f,l),t.rotate(p<-1.57||p>1.57?p+3.14:p),t.strokeText(x,0,0),t.fillText(x,0,0),t.restore()}}}_drawStreamLinesStatic(){if(!this.streamLines.length||!this.layer.style.streamLineStatic)return;let{canvasVectorAnimationCtx:e}=this;if(this.layer.style.streamLineColor==="none"){this.streamLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let t=this.streamLines.length;t--;){let r=this.streamLines[t];for(let o=0;o<r.length-1;++o){let a=r[o],s=r[o+1];e.moveTo(a.x,a.y),e.lineTo(s.x,s.y)}}e.stroke()}_drawVectorsStatic(){let{clut:e,style:t}=this.layer;if(!this.layer.state.vector||!e.DataToKnots||t.vectorColor==="none"||t.vectorType==="none")return;if(this.data.length!==3)throw new Error("this.data.length !== 3");let[r,o,a]=this.data,{canvasVectorCtx:s}=this;switch(t.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=t.vectorType}s.textAlign="center",s.textBaseline="middle";let i=t.addDegrees?.017453292519943*t.addDegrees:0,c=32;for(let u=c/2;u<256;u+=c)for(let f=c/2;f<256;f+=c){let l=f+1+(u+1)*258;if(!r.raw[l])continue;let d=Math.atan2(o.dmin+o.raw[l]*o.dmul,a.dmin+a.raw[l]*a.dmul),h=r.dmin+r.raw[l]*r.dmul,g=t.vectorType!=="barbs"?t.vectorFactor*.2:.2,m=Math.min(e.DataToKnots(h)*g,25)+65,x=String.fromCharCode(m);switch(t.vectorColor){case"inverted":s.fillStyle=w(~e.colorsI[r.raw[l]]);break;case"fill":s.fillStyle=w(e.colorsI[r.raw[l]]);break;default:s.fillStyle=t.vectorColor;break}s.save(),s.translate(f,u),s.rotate(d+i),s.fillText(x,0,0),s.restore()}}_drawDegreesStatic(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:e}=this,t=.017453292519943*this.layer.style.addDegrees;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle";let r=this.data[0],o="L",a=32;for(let s=a/2;s<256;s+=a)for(let i=a/2;i<256;i+=a){let c=i+1+(s+1)*258;if(!r.raw[c])continue;let f=(r.dmin+r.raw[c]*r.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=w(~this.layer.clut.colorsI[r.raw[c]]);break;case"fill":e.fillStyle=w(this.layer.clut.colorsI[r.raw[c]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(i,s),e.rotate(f+t),e.fillText(o,0,0),e.restore()}}_createStreamLines(){if(this.data.length!==3)throw new Error("this.data.length !== 3");if(this.layer.style.streamLineColor==="none")return;let e=this.layer.style.streamLineSpeedFactor||1;this.streamLines=[];let[t,r,o]=this.data,a=Math.max(this.coords.z-this.layer.state.meta.maxZoom,0),s=Math.min(2**(a+5),128),i=~~(120+a*60);for(let c=0;c<=256;c+=s)for(let u=0;u<=256;u+=s){if(!t.raw[1+u+(1+c)*258])continue;let f=[],l=u,d=c;for(let h=0;h<=i&&l>=0&&l<=256&&d>=0&&d<=256;h++){!(h%(i/6))&&f.push({x:~~l,y:~~d});let g=~~l+1+(~~d+1)*258;if(!t.raw[g])break;l+=e*(r.dmin+r.raw[g]*r.dmul)/t.dmax,d-=e*(o.dmin+o.raw[g]*o.dmul)/t.dmax}l=u,d=c;for(let h=1;h<=i&&l>=0&&l<=256&&d>=0&&d<=256;h++){!(h%(i/6))&&f.unshift({x:~~l,y:~~d});let g=~~l+1+(~~d+1)*258;if(!t.raw[g])break;l-=e*(r.dmin+r.raw[g]*r.dmul)/t.dmax,d+=e*(o.dmin+o.raw[g]*o.dmul)/t.dmax}f.length>2&&this.streamLines.push(f)}}};var $;var k=class extends Me.default.GridLayer{constructor(e){super(e.options);this.styles=F();this.redrawRequestID=0;this.vectorAnimationRequestID=0;this.oldMaxZoom=0;this.style=Object.assign({},this.styles.base);this.clut=new q(this.style,"",[0,2],!1);this.animation=!0;let{dataSource:t,lazy:r}=e;if(b("Creating a WxTiles layer:",t.name,". Params:",JSON.stringify(e)),!(t==null?void 0:t.ext)||!t.dataset||!t.name||!t.serverURI||!t.styleName||!Array.isArray(t.variables)||t.variables.length<1||t.variables.length>2){let i="WxTilesLayer: dataSource is wrong!";throw b(i),new Error(i)}this.dataSource=t,this.state={originURI:t.serverURI+"/"+t.dataset+"/",units:"",baseURL:"",meta:{maxZoom:0,times:[],variables:[],variablesMeta:{}},instance:"",minmax:[[0,1]],currentTime:"",vector:t.variables.length>1},this.loadDataIntegralFunc=Z(t.requestInit),$||($=de(t.requestInit)),this.loadMaskFunc=$;let o=()=>{var i;((i=this._map)==null?void 0:i.getZoom())<this.state.meta.maxZoom&&this._stopLoadingResetLoadDataFunc()},a=()=>{if(b("onadd:",this.dataSource.name),!this._map)throw new Error("_map is not set!");this._map.on("zoomstart",o),this._checkAndStartVectorAnimation()},s=()=>{if(b("onremove:",this.dataSource.name),!this._map)throw new Error("_map is not set!");this._map.off("zoomstart",o),this._stopLoadingResetLoadDataFunc()};this.on("remove",s),this.on("add",a),this.setupCompletePromise=new Promise(i=>{let c=async()=>{b("Setup:",t.name),await this._setUpDataSet(),b("Setup complete: ",this.dataSource.name),i()};r?this.once("add",c):c()})}async _setUpDataSet(){let{state:e,dataSource:t}=this;try{e.instance=(await M(e.originURI+"instances.json")).pop()+"/"}catch(o){let a=t.name+": load instances.json error: "+o;throw b(a),new Error(a)}try{let o=e.originURI+e.instance+"meta.json";e.meta=await M(o)}catch(o){let a=t.name+": load meta.json error: "+o;throw b(a),new Error(a)}e.vector=t.variables.length===2;let{variablesMeta:r}=e.meta;if(e.units=r[t.variables[0]].units,e.minmax=t.variables.map(o=>[r[o].min,r[o].max]),e.vector){let[[o,a],[s,i]]=e.minmax;e.minmax.unshift([0,1.42*Math.max(-o,a,-s,i)])}this._setStyleAndCLUT(t.styleName),this._setTimeUrl(new Date)}async _requestReloadTilesAndRedraw(){let e=await this._requestReloadTiles();return e&&this._redrawTiles(),e}async _requestReloadTiles(){b(`_requestReloadTiles: start - ${this.dataSource.name}`);let{controller:e}=this.loadDataIntegralFunc.controllerHolder;return await Promise.allSettled(this._ForEachWxTile(t=>t.load())),b(`_requestReloadTiles: end - ${this.dataSource.name}, aborted: ${e.signal.aborted}`),!e.signal.aborted}async setStyle(e){b("setStyle(",e,") for ",this.dataSource.name),(e==="custom"||e!==this.dataSource.styleName)&&(this._setStyleAndCLUT(e),this._checkAndStartVectorAnimation(),await this._requestReloadTilesAndRedraw()),b("setStyle(",e,'): "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete.")}_setStyleAndCLUT(e){let{dataSource:t,styles:r,state:o}=this;t.styleName=e,e==="custom"&&(r.custom.parent&&r.custom.parent in r||(b(`cant find the parent style (${r.custom.parent}), 'base' is used`),r.custom.parent="base"),r.custom=Object.assign(Object.assign({},r[r.custom.parent]),r.custom)),e in r||(b(`cant find the style (${e}), 'base' is used`),e=t.styleName="base");try{this.style=Object.assign({},r[e]),this.style.streamLineColor=ye(this.style.streamLineColor),this.clut=new q(this.style,o.units,o.minmax[0],o.vector)}catch(a){let s="setStyle: impossible error in RawCLUT: "+a;throw b(s),new Error(s)}}createTile(e,t){return De({layer:this,coords:e,done:t})}getSetupCompletePromise(){return this.setupCompletePromise}getLayerInfoAtLatLon(e){if(!this._map)return;let t=this._map.getZoom(),r=this._map.project(e,t),o=r.divideBy(256).floor(),a=this._getCachedTile(o,t);if(!a)return;let s=r.subtract(o.multiplyBy(256)).floor(),i=a.getPixelInfo(s);if(!i)return;let{raw:c,data:u}=i,f=c.map(h=>this.clut.colorsI[h]),l=f.map(w),d=u.map(h=>this.clut.DataToStyle(h));return{wxtile:a,data:u,raw:c,rgba:f,hexColor:l,inStyleUnits:d,tilePoint:s,styleUnits:this.style.units,dataUnits:this.state.units}}getStyle(){return this.style}_getFirstNonEmptyTile(){for(let e in this._tiles){let{wxtile:t}=this._tiles[e].el;if(t==null?void 0:t.data.length)return t}}_setTimeUrl(e){let{dataSource:t,state:r}=this,o=ge(r.meta.times,e);return r.currentTime===o?(b("_setTimeUrl: the same time - skipped"),!1):(r.currentTime=o,r.baseURL=r.originURI+r.instance+`{var}/${r.currentTime}/{z}/{x}/{y}.${t.ext}`,b(`_setTimeUrl: ${o} for ${t.name} complete`),!0)}setTime(e){if(b("setTime: "+e+" for "+this.dataSource.name+" start"),!this._tiles)return b("setTime: no tiles - skipped"),Promise.resolve(!1);let{currentTime:t}=this.state;if(!this._setTimeUrl(e))return Promise.resolve(!1);this.loadDataIntegralFunc.abort();let r=this._requestReloadTiles();return r.then(o=>{if(!o){this.state.currentTime=t;return}let a=this._getFirstNonEmptyTile();if(a==null?void 0:a.data.length){let[s,i]=this.state.minmax[0],{dmin:c,dmax:u}=a.data[0];(Math.abs(c-s)>.01||Math.abs(u-i)>.01)&&(this.state.minmax=a.data.map(f=>[f.dmin,f.dmax]),this._setStyleAndCLUT(this.dataSource.styleName))}this._redrawTiles()}),r}getTime(){return this.state.currentTime}getTimes(){return b("getTimes"),this.state.meta.times}getLegendData(e){return b("getLegendData"),V(e,this.style)}setTimeAnimationMode(e=2){b("setTimeAnimationMode"),this.oldMaxZoom=this.state.meta.maxZoom;let t=this._map.getZoom(),o=(t<this.oldMaxZoom?t:this.oldMaxZoom)-e;this.state.meta.maxZoom=o<0?0:o}async unsetTimeAnimationMode(){return b("unsetTimeAnimationMode"),this.oldMaxZoom&&(this.state.meta.maxZoom=this.oldMaxZoom),this._requestReloadTilesAndRedraw()}getMinMax(){let[e,t]=this.state.minmax[0];return{min:e,max:t}}setAnimation(e){return b("setAnimation"),this.animation=e,this._checkAndStartVectorAnimation(),this.animation}_getCachedTile({x:e,y:t},r){var o,a;return(a=(o=this._tiles[`${e}:${t}:${r}`])==null?void 0:o.el)==null?void 0:a.wxtile}_ForEachWxTile(e){var r;let t=[];for(let o in this._tiles){let a=(r=this._tiles[o].el)==null?void 0:r.wxtile;a&&t.push(e(a))}return t}_stopLoadingResetLoadDataFunc(){this.loadDataIntegralFunc.abort(),this.loadDataIntegralFunc=Z()}_checkAndStartVectorAnimation(){if(this.vectorAnimationRequestID)return;let e=t=>{if(!this._map||!this.animation||!this.state.vector||this.style.streamLineStatic||this.style.streamLineColor==="none"){this._ForEachWxTile(r=>r.clearVectorAnimationCanvas()),this.vectorAnimationRequestID=0;return}this._ForEachWxTile(r=>r.drawVectorAnimationLinesStep(t)),this.vectorAnimationRequestID=requestAnimationFrame(e)};this.vectorAnimationRequestID=requestAnimationFrame(e)}_redrawTiles(){this.redrawRequestID||(b("_redrawTiles: start: "+this.dataSource.name),this.redrawRequestID=requestAnimationFrame(()=>{this._ForEachWxTile(e=>e.draw()),this.redrawRequestID=0,b("_redrawTiles: requestAnimationFrame: end: "+this.dataSource.name)}))}};function Re(n){return new k(n)}var X=class extends O.default.Control{constructor(e){super(e);this.URI=e.URI}onAdd(){let e=document.createElement("img");return e.src=this.URI,e.className="wxtiles-logo",e}};function st(n){return b("Add watermark:",JSON.stringify(n)),new X(n)}var J=class extends O.default.GridLayer{createTile(e){let t=document.createElement("div");return t.innerHTML=[e.x,e.y,e.z].join(", "),t.style.outline="1px solid red",t}};function it(){return b("Add WxDebugCoordsLayer:"),new J().setZIndex(1e3)}function lt(n,e){return O.default.layerGroup(n.map(Re),e)}return ct;})();
|
|
1
|
+
var wxtilesjs=(()=>{var Ue=Object.create;var R=Object.defineProperty;var Pe=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames,Y=Object.getOwnPropertySymbols,We=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var te=(n,e,t)=>e in n?R(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,re=(n,e)=>{for(var t in e||(e={}))ee.call(e,t)&&te(n,t,e[t]);if(Y)for(var t of Y(e))Ee.call(e,t)&&te(n,t,e[t]);return n};var ne=n=>R(n,"__esModule",{value:!0});var ut=typeof require!="undefined"?require:n=>{throw new Error('Dynamic require of "'+n+'" is not supported')};var qe=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Be=(n,e)=>{ne(n);for(var t in e)R(n,t,{get:e[t],enumerable:!0})},Oe=(n,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Fe(e))!ee.call(n,r)&&r!=="default"&&R(n,r,{get:()=>e[r],enumerable:!(t=Pe(e,r))||t.enumerable});return n},oe=n=>Oe(ne(R(n!=null?Ue(We(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var j=qe((ht,ae)=>{ae.exports=window.L});var ct={};Be(ct,{CreateWxDebugCoordsLayer:()=>it,CreateWxTilesGroupLayer:()=>lt,CreateWxTilesLayer:()=>Re,CreateWxTilesWatermark:()=>st,LoadQTree:()=>Te,WxDebugLayer:()=>J,WxGetColorSchemes:()=>W,WxGetColorStyles:()=>F,WxTilesLayer:()=>U,WxTilesLibSetup:()=>me,WxTilesLogging:()=>ye,WxWatermark:()=>X,fetchJson:()=>A});var H=oe(j());var se={comment1:["'degC': ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["'hPa': ['Pa', 1000]' -> hPa = Pa * 1000 + 0 (0 - could be ommited)",0],K:["K",1],kelvin:["K",1],F:["K",.5555555555,255.372222222],C:["K",1,273.15],degC:["K",1,273.15],"kg/m^2/s":["kg/m^2/s",1],"Kg/m^2/s":["kg/m^2/s",1],"Kg m**-2 s**-1":["kg/m^2/s",1],"Kg m^-2 s^-1":["kg/m^2/s",1],"Kg m^{-2} s^-1":["kg/m^2/s",1],"mm/h":["kg/m^2/s",.00027777777],"mm/hr":["kg/m^2/s",.00027777777],"W/m^2":["W/m^2",1],"W m^-2":["W/m^2",1],"W m^{-2}":["W/m^2",1],"W/m**2":["W/m^2",1],"W m**-2":["W/m^2",1],"m/s":["m/s",1],"m s**-1":["m/s",1],"m s^-1":["m/s",1],"m.s^{-1}":["m/s",1],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["m/s",.27777777777],"km h^-1":["m/s",.27777777777],"km h**-1":["m/s",.27777777777],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],inch:["m",.0254],Pa:["Pa",1],hPa:["Pa",100],degree:["degree",1],radian:["degree",57.3],"mg/m^3":["mg/m^3",1],"mg m^-3":["mg/m^3",1],"mg.m^-3":["mg/m^3",1],"%":["%",1],"(0 - 1)":["%",100]};var ie={none:["#00000000","#00000000"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbowzerro:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow2:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebirdzerro:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bw:["#000000ff","#ffffffff"],wb:["#ffffffff","#000000ff"],redish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]};var P={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,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"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,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"}};var le,ce,ue;function me({colorStyles:n={},units:e={},colorSchemes:t={}}={}){b("WxTile lib setup: start"),le=Object.assign({},se,e),ce=Object.assign({},t,ie);let r=Object.assign({},n,P);ue=He(r),b("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),b("WxTile lib setup is done.")}function F(){return ue}function W(){return ce}function E(n,e,t){b("makeConverter: From=",n," To=",e);let r=d=>d;if(r.trivial=!0,n===e)return b("Trivial converter"),r;let o=Object.assign({},le,t);if(!o[n]||!o[e])return b("Inconvertible units. Trivial converter"),r;let[a,s,i]=o[n],[u,l,f]=o[e];if(a!==u||!s||!l)return b("Inconvertible units. Trivial converter"),r;let m=s/l,h=((i||0)-(f||0))/l;return h?d=>m*d+h:d=>m*d}function He(n){let e=Object.assign({},P);for(let o in n){let a=n[o];if(Array.isArray(a))for(let s=0;s<a.length;++s)e[o+"["+s+"]"]=Object.assign({},a[s]);else e[o]=Object.assign({},a)}let t=(o,a)=>{if(a==="base")return P.base;let s=o[a];(!s.parent||!(s.parent in o))&&(s.parent="base");let i=t(o,s.parent);return Object.assign(s,Object.assign({},i,s,{parent:"base"}))},r={};for(let o in e)r[o]=t(e,o);return r}function je(n){let e=new Map;return t=>{let r=e.get(t);if(r)return r;let o=n(t);return e.set(t,o),o.catch(a=>{a.code===DOMException.ABORT_ERR&&e.delete(t)}),o}}async function ze(n,e){let t=new Image;return t.src=URL.createObjectURL(await(await fetch(n,e)).blob()),await t.decode(),URL.revokeObjectURL(t.src),t}function Ze(n){let{width:e,height:t}=n,r=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d");if(!r)throw new Error("Error: can not create context. Catastrophe");return r.drawImage(n,0,0),r.getImageData(0,0,e,t)}async function fe(n,e){return Ze(await ze(n,e))}function Ve(n){n.data[34]<1&&b("Warning: image is in too old format. Check the version of the Splitter.");let e=new Uint16Array(n.data.buffer),t=new Uint16Array(e.length/2);for(let l=0;l<t.length;l++)t[l]=e[l*2];let r=new Uint8Array(8);for(let l=0;l<8;++l)r[l]=n.data[l*4+2];let o=new DataView(r.buffer),a=o.getFloat32(0,!0),s=o.getFloat32(4,!0),i=(s-a)/65535,u=Qe(t);return{raw:t,dmin:a,dmax:s,dmul:i,integral:u,radius:0}}async function Ge(n,e){return Ve(await fe(n,e))}function de(n,e){let t={controller:new AbortController,debug:Date.now().toString()},r=Object.assign({},e,{signal:t.controller.signal}),o=je(a=>n(a,r));return o.controllerHolder=t,o.abort=()=>{t.controller.abort(),t.controller=new AbortController,t.debug=Date.now().toString(),r.signal=t.controller.signal},o}function z(n){return de(Ge,n)}function he(n){return de(fe,n)}function Qe(n){let e=new Uint32Array(258*258),t=new Uint32Array(258*258);e[0]=n[0],t[0]=n[0]===0?0:1;for(let r=1;r<258;++r)e[r]=n[r]+e[r-1],e[258*r]=n[258*r]+e[258*r-258],t[r]=(n[r]===0?0:1)+t[r-1],t[258*r]=(n[258*r]===0?0:1)+t[258*r-258];for(let r=1,o=259;r<258;++r,++o)for(let a=1;a<258;++a,++o)e[o]=n[o]+e[o-258]+e[o-1]-e[o-258-1],t[o]=(n[o]===0?0:1)+t[o-258]+t[o-1]-t[o-258-1];return{integral:e,integralNZ:t}}function be(n,e){if(e<0||e===n.radius)return n;n.radius=e;let t=258,{integral:r,integralNZ:o}=n.integral;for(let a=1;a<t;a++)for(let s=1;s<t;s++){if(!n.raw[t*a+s])continue;let i=Math.min(e,s-1,t-1-s),u=Math.min(e,a-1,t-1-a),l=t*(a-u-1)+s,f=t*(a+u)+s,m=o[l-i-1],h=o[l+i],d=o[f-i-1],g=o[f+i],c=m+g-h-d,x=r[l-i-1],p=r[l+i],y=r[f-i-1],C=r[f+i],S=x+C-p-y;n.raw[a*t+s]=S/c}return n}function L(n){let e=n>>0&255,t=n>>8&255,r=n>>16&255,o=e.toString(16),a=t.toString(16),s=r.toString(16);return o=o.length===2?o:"0"+o,a=a.length===2?a:"0"+a,s=s.length===2?s:"0"+s,"#"+o+a+s}function I(n){if(n[0]==="#"){if(n.length===4)return+("0xff"+n[3]+n[3]+n[2]+n[2]+n[1]+n[1]);if(n.length===7)return+("0xff"+n[5]+n[6]+n[3]+n[4]+n[1]+n[2]);if(n.length===9)return+("0x"+n[7]+n[8]+n[5]+n[6]+n[3]+n[4]+n[1]+n[2])}return b("wrong color format",n),0}async function A(n,e){return(await fetch(n,e)).json()}function q(n,e="",t){var o;let r=document.createElement(n);return r.className=e,t&&((o=t.appendChild)==null||o.call(t,r)),r}function Z(n,e,t){let r=n>>0&255,o=n>>8&255,a=n>>16&255,s=n>>>24,i=e>>0&255,u=e>>8&255,l=e>>16&255,f=e>>>24,m=r+t*(i-r),h=o+t*(u-o),d=a+t*(l-a),g=s+t*(f-s);return m|h<<8|d<<16|g<<24}function ge(n,e,t){let r=[];for(let o=0;o<t;++o)r.push(o*(e-n)/(t-1)+n);return r}function xe(n,e){let t=typeof e=="number"?e:typeof e=="string"?new Date(e).getTime():e.getTime();return n.find(r=>new Date(r).getTime()>=t)||n[n.length-1]}var pe=!1;function ye(n){console.log(n?"Logging on":"Logging off"),pe=n}function b(...n){pe&&console.trace(...n)}function Ce(n){return n!=="none"&&n.length<7?"#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]:n}var ke=oe(j());function Ne(n,e,t){return n>t?t:n<e?e:n}var B=class{constructor(e,t,[r,o],a){let s=o-r;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let i=[];this.DataToStyle=E(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),a&&(this.DataToKnots=E(t,"knot"));let u=E(e.units,t,e.extraUnits),l=c=>~~(65535*Ne((u(c)-r)/(o-r),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((c,x)=>c[0]<x[0]?-1:c[0]>x[0]?1:0);for(let[c]of e.colorMap)i.push(l(c))}else{if(e.levels||(e.levels=ge(this.DataToStyle(r),this.DataToStyle(o),10)),e.levels.sort((c,x)=>c<x?-1:c>x?1:0),!e.colors){let c=W();e.colorScheme&&e.colorScheme in c?e.colors=c[e.colorScheme]:e.colors=c.wb}for(let c of e.levels)i.push(l(c))}let f=65536,m=V(f,e);this.ticks=m.ticks;let h=m.ticks[0].data,g=m.ticks[m.ticks.length-1].data-h;for(let c=0;c<65536;++c){let x=s*c/65535+r,p=this.DataToStyle(x),y=Math.round((f-1)*(p-h)/g);y<=0?this.colorsI[c]=e.showBelowMin?m.colors[0]:0:y>=f?this.colorsI[c]=e.showAboveMax?m.colors[f-1]:0:this.colorsI[c]=m.colors[y]}this.colorsI[0]=0;for(let c=0;c<i[0];++c)this.levelIndex[c]=0;for(let c=0;c<i.length-1;c++)for(let x=i[c];x<i[c+1]+1;++x)this.levelIndex[x]=c;for(let c=i[i.length-1];c<65536;++c)this.levelIndex[c]=i.length-1}};function Se(n){var t;if(n!==0&&-.1<n&&n<.1)return n.toExponential(2);let e=n.toString();return((t=e.split(".")[1])==null?void 0:t.length)>2?n.toFixed(2):e}function V(n,e){let t={size:n,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(n),ticks:[]},{colorMap:r,levels:o,colors:a}=e,s=e.fill!=="solid";if(r){let h=r[0][0],d=r[r.length-1][0]-h;for(let[g,c]of r){let x=~~((g-h)/d*(n-1)),p={data:g,dataString:Se(g),color:c,pos:x};t.ticks.push(p)}for(let g=0;g<r.length-1;g++){let c=t.ticks[g].pos,x=t.ticks[g+1].pos,p=I(r[g][1]),y=s?I(r[g+1][1]):0;for(let C=c;C<x;++C)t.colors[C]=s?Z(p,y,(C-c)/(x-c)):p}return t.colors[n-1]=I(r[r.length-1][1]),t}if(!a||!o)return t;let i=0,u=0,l=-1;for(let h=0;h<n;++h){let d=h*(a.length-1)/n;l!==~~d&&(l=~~d,i=I(a[l]),u=a.length>l+1?I(a[l+1]):i),t.colors[h]=s?Z(i,u,d-l):i}t.colors[n-1]=I(a[a.length-1]);let f=o[0],m=(n-1)/(o[o.length-1]-f);for(let h of o){let d=~~((h-f)*m),g={data:h,dataString:Se(h),color:L(t.colors[d]),pos:d};t.ticks.push(g)}return t}var G=256,Ke=2*Math.PI*6378137/G,O=2*Math.PI*6378137/2;function $e(n,e){let t=n/O*180,r=e/O*180;return r=180/Math.PI*(2*Math.atan(Math.exp(r*Math.PI/180))-Math.PI/2),[r,t]}function Xe(n,e,t){let r=Je(t),o=n*r-O,a=e*r-O;return[o,a]}function Je(n){return Ke/Math.pow(2,n)}function Q(n,e,t){let[r,o]=$e(...Xe(n,e,t));return[o,-r]}function we(n,e){return[n*G,e*G]}var Ye="A".charCodeAt(0),N,k=0;async function Te(n,e){let t;try{t=await(await fetch(n,e)).json()}catch(r){console.log("Can't load QTree:",r);return}N=_(t,{pos:0}),k=ve(N),console.log("Loaded QTree, depth:",k)}function _(n,e){let t=n.charCodeAt(e.pos)-Ye;e.pos++;let r=t&1?_(n,e):null,o=t&2?_(n,e):null,a=t&4?_(n,e):null,s=t&8?_(n,e):null;return{sub:r||o||a||s?[r,o,a,s]:null}}function ve(n){let e=0;if(n==null?void 0:n.sub){for(let t=0;t<4;t++)if(n.sub[t]!==null){let r=ve(n.sub[t])+1;e<r&&(e=r)}}return e}var T;(function(r){r.Land="land",r.Mixed="mixed",r.Sea="sea"})(T||(T={}));function Le(n){if(!k)return T.Mixed;let e=re({},n),t=!1;if(k<=n.z){t=!0;let r=n.z-k;e={x:n.x>>r,y:n.y>>r,z:k}}return Ie(N,e,t)}function Ie(n,e,t){if(n===null)return T.Land;if(t&&e.z===0)return T.Mixed;if(n.sub===null)return T.Sea;if(e.z===0)return T.Mixed;e.z--;let r=e.x>>e.z&1,a=(e.y>>e.z&1)<<1|r;return Ie(n.sub[a],e,t)}function K(n,e,t){let r=((e-n)%360+540)%360-180;return(n+r*t+360)%360}function et(n,e,t,r,o,a,s,i){switch((n?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 0:return 0;case 1:return n;case 2:return e;case 3:t=n,r=e;break;case 4:return t;case 5:e=n,r=t;break;case 6:r=e+t>>1,n=r;break;case 7:r=e+t>>1;break;case 8:return r;case 9:e=n+r>>1,t=e;break;case 10:n=e,t=r;break;case 11:t=n+r>>1;break;case 12:n=t,e=r;break;case 13:e=n+r>>1;break;case 14:n=e+t>>1;break}n=s+i*n,e=s+i*e,t=s+i*t,r=s+i*r;let l=K(n,e,o),f=K(t,r,o);return(K(l,f,a)-s)/i||1}function tt(n,e,t,r,o,a,s,i){switch((n?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 7:return o+a<1?o*(e-n)+a*(t-n)+n:0;case 14:return o+a<1?0:o*(r-t)+a*(r-e)+e+t-r;case 11:return a<o?(1-o)*(n-e)+a*(r-e)+e:0;case 13:return a<o?0:(1-o)*(t-r)+a*(t-n)+n+r-t;case 15:return o+a<1?o*(e-n)+a*(t-n)+n:o*(r-t)+a*(r-e)+e+t-r;default:return 0}}function De(n,e,t){if(!t)return e;let r=.9999999/Math.pow(2,t.z),o=t.x*256*r,a=t.y*256*r,{raw:s,dmin:i,dmax:u,dmul:l}=e,f={raw:new Uint16Array(258*258),dmin:i,dmax:u,dmul:l},{raw:m}=f;for(let h=-1,d=0;h<=256;h++){let g=a+h*r,c=Math.floor(g),x=g-c;for(let p=-1;p<=256;p++,d++){let y=o+p*r,C=Math.floor(y),S=y-C,w=C+1+(c+1)*258,D=s[w],v=s[w+1],M=s[w+258],_e=s[w+258+1];m[d]=n(D,v,M,_e,S,x,i,l)}}return f}function rt(n,e){return De(tt,n,e)}function nt(n,e){return De(et,n,e)}function ot(n,e,t){let r=t==="land"?1:0;for(let o=3,a=0;a<256;a++)for(let s=0;s<256;s++,o+=4){let i=e.data[o]?1:0;r^i&&(n.raw[(a+1)*258+(s+1)]=0)}return n}function at(n){let[e,t]=we(n.x,n.y),[r,o]=Q(e,t,n.z),[a,s]=Q(e+256,t+256,n.z);return{west:r,north:o,east:a,south:s}}function Me(n){let e=q("div","leaflet-tile s-tile");return e.wxtile=new Ae(n,e),(async()=>{let{wxtile:t}=e;try{await t.load(),t.draw()}catch(r){let{x:o,y:a,z:s}=t.coords;b(`tile(${o},${a},${s}) loading error: ${r}`)}n.done()})(),e}var Ae=class{constructor({layer:e,coords:t},r){this.data=[];this.streamLines=[];this.coords=t,this.layer=e,this.canvasFill=q("canvas","s-tile canvas-fill",r),this.canvasSlines=q("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(a){let s=a.getContext("2d");if(!s)throw new Error("getCtx error");return s}this.canvasFillCtx=o(this.canvasFill),this.imageDataForFillCtx=this.canvasFillCtx.createImageData(256,256),this.canvasVectorAnimationCtx=o(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}async load(){let{coords:e,layer:t}=this;await t.setupCompletePromise;let r=this._getTileType();if(!r)return this.data=[],this.streamLines=[],this;let{upCoords:o,subCoords:a}=this._splitCoords(e),s=this.layer.state.baseURL.replace("{z}",String(o.z)).replace("{x}",String(o.x)).replace("{y}",String(o.y)),i=this.layer.dataSource.variables.map(m=>s.replace("{var}",m)),u;try{u=await Promise.all(i.map(t.loadDataIntegralFunc))}catch(m){return m.code!==DOMException.ABORT_ERR&&(this.data=[],this.streamLines=[]),this}let l=t.state.units==="degree"?nt:rt,f=m=>l(be(m,t.style.blurRadius),a);return this.data=u.map(f),t.state.vector&&this._vectorMagnitudesPrepare(),await this._applyMask(r,a===void 0),t.state.vector&&this._createStreamLines(),this}async _applyMask(e,t){let{coords:r,layer:o}=this;if((o.style.mask==="land"||o.style.mask==="sea")&&e===T.Mixed){let a=o.dataSource.maskServerURI.replace("{z}",String(r.z)).replace("{x}",String(r.x)).replace("{y}",String(r.y));try{let s=await o.loadMaskFunc(a);if(!o.state.vector&&t){let{raw:i,dmin:u,dmax:l,dmul:f}=this.data[0];this.data[0]={raw:new Uint16Array(i),dmin:u,dmax:l,dmul:f}}ot(this.data[0],s,o.style.mask)}catch(s){o.style.mask=void 0,b("Can't load Mask. Masking is Turned OFF")}}}_splitCoords(e){let t=e.z-this.layer.state.meta.maxZoom;if(t<=0)return{upCoords:e};let r={x:e.x>>>t,y:e.y>>>t,z:this.layer.state.meta.maxZoom},o={x:e.x&(1<<t)-1,y:e.y&(1<<t)-1,z:t};return{upCoords:r,subCoords:o}}_getTileType(){let{coords:e,layer:t}=this,{mask:r}=t.style;var o=T.Mixed;if((r==="land"||r==="sea")&&(o=Le(e),r===o))return;let{boundaries:a}=t.state.meta;if(a==null?void 0:a.boundaries180){let s=at(e),i=u=>!(s.west>u.east||u.west>s.east||s.south>u.north||u.south>s.north);if(!a.boundaries180.some(i))return}return o}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasVectorAnimationCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVectorsStatic(),this._drawDegreesStatic(),this._drawStreamLinesStatic())}clearVectorAnimationCanvas(){this.canvasVectorAnimationCtx.clearRect(0,0,256,256)}drawVectorAnimationLinesStep(e){if(this.streamLines.length===0)return;let t=this.canvasVectorAnimationCtx;if(t.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.streamLines=[];return}let r=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let o=0;o<this.streamLines.length;++o){let a=this.streamLines[o],s=a.length-1,i=(e+(1+a[0].x)*(1+a[0].y))%30;for(let u=0;u<s;++u){let l=a[u],f=a[u+1],m=1-(i-u)/s;(m<0||m>1)&&(m=0);let h=(~~(m*255)).toString(16);t.strokeStyle=r+(h.length<2?"0"+h:h);let d=1+~~((1.2-m)*5);t.lineWidth=d,t.beginPath(),t.moveTo(l.x,l.y),t.lineTo(f.x,f.y),t.stroke()}}}getPixelInfo({x:e,y:t}){var o;let r=(t+1)*258+(e+1);if(!!((o=this.data[0])==null?void 0:o.raw[r]))return{raw:this.data.map(a=>a.raw[r]),data:this.data.map(a=>a.raw[r]*a.dmul+a.dmin)}}_vectorMagnitudesPrepare(){if(this.data.length!==2)throw new Error("this.data !== 2");this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[e,t,r]=this.data;e.dmax=1.42*Math.max(-t.dmin,t.dmax,-r.dmin,r.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let o=0;o<258*258;++o){if(!t.raw[o]||!r.raw[o]){e.raw[o]=0;continue}let a=t.dmin+t.dmul*t.raw[o],s=r.dmin+r.dmul*r.raw[o];e.raw[o]=Math.sqrt(s*s+a*a)/e.dmul}}_drawFillAndIsolines(){let{imageDataForFillCtx:e}=this,{canvasFillCtx:t}=this,r=new Uint32Array(e.data.buffer),{raw:o}=this.data[0],{clut:a,style:s}=this.layer,{levelIndex:i,colorsI:u}=a;if(s.fill!=="none")for(let f=0,m=0,h=259;f<256;++f,h+=2)for(let d=0;d<256;++d,++m,++h)r[m]=u[o[h]];else r.fill(0);let l=[];if(s.isolineColor!=="none"){let f=s.isolineColor[0]==="#"?I(s.isolineColor):0;for(let m=0,h=0;m<256;m+=1)for(let d=0;d<256;d+=1){let g=(m+1)*258+(d+1),c=o[g],x=o[g+1],p=o[g+258];if(!c||!x||!p)continue;let y=i[c],C=i[x],S=i[p];if(y!==C||y!==S){let w=Math.max(y,C,S),D=Math.max(c,x,p),v=m*256+d;switch(s.isolineColor){case"inverted":r[v]=~u[D]|4278190080;break;case"fill":r[v]=u[D]|4278190080;break;default:r[v]=f;break}s.isolineText&&!(++h%255)&&d>20&&d<235&&m>20&&m<235&&l.push({x:d,y:m,d:c,dr:x,db:p,mli:w})}}}if(t.putImageData(e,0,0),l.length){t.font="1.1em Sans-serif",t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";for(let{x:f,y:m,d:h,dr:d,db:g,mli:c}of l){let x=this.layer.clut.ticks[c].dataString,p=Math.atan2(h-d,g-h);t.save(),t.translate(f,m),t.rotate(p<-1.57||p>1.57?p+3.14:p),t.strokeText(x,0,0),t.fillText(x,0,0),t.restore()}}}_drawStreamLinesStatic(){if(!this.streamLines.length||!this.layer.style.streamLineStatic)return;let{canvasVectorAnimationCtx:e}=this;if(this.layer.style.streamLineColor==="none"){this.streamLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let t=this.streamLines.length;t--;){let r=this.streamLines[t];for(let o=0;o<r.length-1;++o){let a=r[o],s=r[o+1];e.moveTo(a.x,a.y),e.lineTo(s.x,s.y)}}e.stroke()}_drawVectorsStatic(){let{clut:e,style:t}=this.layer;if(!this.layer.state.vector||!e.DataToKnots||t.vectorColor==="none"||t.vectorType==="none")return;if(this.data.length!==3)throw new Error("this.data.length !== 3");let[r,o,a]=this.data,{canvasVectorCtx:s}=this;switch(t.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=t.vectorType}s.textAlign="center",s.textBaseline="middle";let i=t.addDegrees?.017453292519943*t.addDegrees:0,u=32;for(let l=u/2;l<256;l+=u)for(let f=u/2;f<256;f+=u){let m=f+1+(l+1)*258;if(!r.raw[m])continue;let h=Math.atan2(o.dmin+o.raw[m]*o.dmul,a.dmin+a.raw[m]*a.dmul),d=r.dmin+r.raw[m]*r.dmul,g=t.vectorType!=="barbs"?t.vectorFactor*.2:.2,c=Math.min(e.DataToKnots(d)*g,25)+65,x=String.fromCharCode(c);switch(t.vectorColor){case"inverted":s.fillStyle=L(~e.colorsI[r.raw[m]]);break;case"fill":s.fillStyle=L(e.colorsI[r.raw[m]]);break;default:s.fillStyle=t.vectorColor;break}s.save(),s.translate(f,l),s.rotate(h+i),s.fillText(x,0,0),s.restore()}}_drawDegreesStatic(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:e}=this,t=.017453292519943*this.layer.style.addDegrees;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle";let r=this.data[0],o="L",a=32;for(let s=a/2;s<256;s+=a)for(let i=a/2;i<256;i+=a){let u=i+1+(s+1)*258;if(!r.raw[u])continue;let f=(r.dmin+r.raw[u]*r.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=L(~this.layer.clut.colorsI[r.raw[u]]);break;case"fill":e.fillStyle=L(this.layer.clut.colorsI[r.raw[u]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(i,s),e.rotate(f+t),e.fillText(o,0,0),e.restore()}}_createStreamLines(){if(this.data.length!==3)throw new Error("this.data.length !== 3");let{style:e}=this.layer;if(e.streamLineColor==="none")return;this.streamLines=[];let[t,r,o]=this.data,a=(e.streamLineSpeedFactor||1)/t.dmax,s=e.addDegrees?.017453292519943*e.addDegrees:0,i=64,u=300;for(let l=0;l<=256;l+=i)for(let f=0;f<=256;f+=i){if(!t.raw[1+f+(1+l)*258])continue;let m=[],h=f,d=l,g=-1,c=0,x=0;for(let C=0;C<=u&&h>=0&&h<=256&&d>=0&&d<=256;C++){C%(u/10)||m.push({x:~~h,y:~~d});let S=~~h+1+(~~d+1)*258;if(S!==g){if(!t.raw[S])break;g=S;let w=t.dmin+t.raw[S]*t.dmul,D=r.dmin+r.raw[S]*r.dmul,v=o.dmin+o.raw[S]*o.dmul,M=Math.atan2(D,v)+s;c=a*w*Math.sin(M),x=a*w*Math.cos(M)}h+=c,d-=x}let p=f,y=l;g=-1;for(let C=1;C<=u&&p>=0&&p<=256&&y>=0&&y<=256;C++){C%(u/10)||m.unshift({x:~~p,y:~~y});let S=~~p+1+(~~y+1)*258;if(S!==g){if(!t.raw[S])break;g=S;let w=t.dmin+t.raw[S]*t.dmul,D=r.dmin+r.raw[S]*r.dmul,v=o.dmin+o.raw[S]*o.dmul,M=Math.atan2(D,v)+s;c=a*w*Math.sin(M),x=a*w*Math.cos(M)}p-=c,y+=x}m.length>2&&this.streamLines.push(m)}}};var $;var U=class extends ke.default.GridLayer{constructor(e){super(e.options);this.styles=F();this.redrawRequestID=0;this.vectorAnimationRequestID=0;this.oldMaxZoom=0;this.style=Object.assign({},this.styles.base);this.clut=new B(this.style,"",[0,2],!1);this.animation=!0;let{dataSource:t,lazy:r}=e;if(b("Creating a WxTiles layer:",t.name,". Params:",JSON.stringify(e)),!(t==null?void 0:t.ext)||!t.dataset||!t.name||!t.serverURI||!t.styleName||!Array.isArray(t.variables)||t.variables.length<1||t.variables.length>2){let i="WxTilesLayer: dataSource is wrong!";throw b(i),new Error(i)}this.dataSource=t,this.state={originURI:t.serverURI+"/"+t.dataset+"/",units:"",baseURL:"",meta:{maxZoom:0,times:[],variables:[],variablesMeta:{}},instance:"",minmax:[[0,1]],currentTime:"",vector:t.variables.length>1},this.loadDataIntegralFunc=z(t.requestInit),$||($=he(t.requestInit)),this.loadMaskFunc=$;let o=()=>{var i;((i=this._map)==null?void 0:i.getZoom())<this.state.meta.maxZoom&&this._stopLoadingResetLoadDataFunc()},a=()=>{if(b("onadd:",this.dataSource.name),!this._map)throw new Error("_map is not set!");this._map.on("zoomstart",o),this._checkAndStartVectorAnimation()},s=()=>{if(b("onremove:",this.dataSource.name),!this._map)throw new Error("_map is not set!");this._map.off("zoomstart",o),this._stopLoadingResetLoadDataFunc()};this.on("remove",s),this.on("add",a),this.setupCompletePromise=new Promise(i=>{let u=async()=>{b("Setup:",t.name),await this._setUpDataSet(),b("Setup complete: ",this.dataSource.name),i()};r?this.once("add",u):u()})}async _setUpDataSet(){let{state:e,dataSource:t}=this;try{e.instance=(await A(e.originURI+"instances.json")).pop()+"/"}catch(o){let a=t.name+": load instances.json error: "+o;throw b(a),new Error(a)}try{let o=e.originURI+e.instance+"meta.json";e.meta=await A(o)}catch(o){let a=t.name+": load meta.json error: "+o;throw b(a),new Error(a)}e.vector=t.variables.length===2;let{variablesMeta:r}=e.meta;if(e.units=r[t.variables[0]].units,e.minmax=t.variables.map(o=>[r[o].min,r[o].max]),e.vector){let[[o,a],[s,i]]=e.minmax;e.minmax.unshift([0,1.42*Math.max(-o,a,-s,i)])}this._setStyleAndCLUT(t.styleName),this._setTimeUrl(new Date)}async _requestReloadTilesAndRedraw(){let e=await this._requestReloadTiles();return e&&this._redrawTiles(),e}async _requestReloadTiles(){b(`_requestReloadTiles: start - ${this.dataSource.name}`);let{controller:e}=this.loadDataIntegralFunc.controllerHolder;return await Promise.allSettled(this._ForEachWxTile(t=>t.load())),b(`_requestReloadTiles: end - ${this.dataSource.name}, aborted: ${e.signal.aborted}`),!e.signal.aborted}async setStyle(e){b("setStyle(",e,") for ",this.dataSource.name),(e==="custom"||e!==this.dataSource.styleName)&&(this._setStyleAndCLUT(e),this._checkAndStartVectorAnimation(),await this._requestReloadTilesAndRedraw()),b("setStyle(",e,'): "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete.")}_setStyleAndCLUT(e){let{dataSource:t,styles:r,state:o}=this;t.styleName=e,e==="custom"&&(r.custom.parent&&r.custom.parent in r||(b(`cant find the parent style (${r.custom.parent}), 'base' is used`),r.custom.parent="base"),r.custom=Object.assign(Object.assign({},r[r.custom.parent]),r.custom)),e in r||(b(`cant find the style (${e}), 'base' is used`),e=t.styleName="base");try{this.style=Object.assign({},r[e]),this.style.streamLineColor=Ce(this.style.streamLineColor),this.clut=new B(this.style,o.units,o.minmax[0],o.vector)}catch(a){let s="setStyle: impossible error in RawCLUT: "+a;throw b(s),new Error(s)}}createTile(e,t){return Me({layer:this,coords:e,done:t})}getSetupCompletePromise(){return this.setupCompletePromise}async checkDataChanged(){b("checkDataChanged");try{let e=await A(this.state.originURI+"instances.json"),t=e[e.length-1]+"/";if(this.state.instance!==t)return!0;let r=await A(this.state.originURI+t+"meta.json");return this.state.meta.times.toString()!==r.times.toString()}catch(e){return!1}}getLayerInfoAtLatLon(e){if(!this._map)return;let t=this._map.getZoom(),r=this._map.project(e,t),o=r.divideBy(256).floor(),a=this._getCachedTile(o,t);if(!a)return;let s=r.subtract(o.multiplyBy(256)).floor(),i=a.getPixelInfo(s);if(!i)return;let{raw:u,data:l}=i,f=u.map(d=>this.clut.colorsI[d]),m=f.map(L),h=l.map(d=>this.clut.DataToStyle(d));return{wxtile:a,data:l,raw:u,rgba:f,hexColor:m,inStyleUnits:h,tilePoint:s,styleUnits:this.style.units,dataUnits:this.state.units}}getStyle(){return this.style}_getFirstNonEmptyTile(){for(let e in this._tiles){let{wxtile:t}=this._tiles[e].el;if(t==null?void 0:t.data.length)return t}}_setTimeUrl(e){let{dataSource:t,state:r}=this,o=xe(r.meta.times,e);return r.currentTime===o?(b("_setTimeUrl: the same time - skipped"),!1):(r.currentTime=o,r.baseURL=r.originURI+r.instance+`{var}/${r.currentTime}/{z}/{x}/{y}.${t.ext}`,b(`_setTimeUrl: ${o} for ${t.name} complete`),!0)}setTime(e){if(b("setTime: "+e+" for "+this.dataSource.name+" start"),!this._tiles)return b("setTime: no tiles - skipped"),Promise.resolve(!1);let{currentTime:t}=this.state;if(!this._setTimeUrl(e))return Promise.resolve(!1);this.loadDataIntegralFunc.abort();let r=this._requestReloadTiles();return r.then(o=>{if(!o){this.state.currentTime=t;return}let a=this._getFirstNonEmptyTile();if(a==null?void 0:a.data.length){let[s,i]=this.state.minmax[0],{dmin:u,dmax:l}=a.data[0];(Math.abs(u-s)>.01||Math.abs(l-i)>.01)&&(this.state.minmax=a.data.map(f=>[f.dmin,f.dmax]),this._setStyleAndCLUT(this.dataSource.styleName))}this._redrawTiles()}),r}getTime(){return this.state.currentTime}getTimes(){return b("getTimes"),this.state.meta.times}getLegendData(e){return b("getLegendData"),V(e,this.style)}setTimeAnimationMode(e=2){b("setTimeAnimationMode"),this.oldMaxZoom=this.state.meta.maxZoom;let t=this._map.getZoom(),o=(t<this.oldMaxZoom?t:this.oldMaxZoom)-e;this.state.meta.maxZoom=o<0?0:o}async unsetTimeAnimationMode(){return b("unsetTimeAnimationMode"),this.oldMaxZoom&&(this.state.meta.maxZoom=this.oldMaxZoom),this._requestReloadTilesAndRedraw()}getMinMax(){let[e,t]=this.state.minmax[0];return{min:e,max:t}}setAnimation(e){return b("setAnimation"),this.animation=e,this._checkAndStartVectorAnimation(),this.animation}_getCachedTile({x:e,y:t},r){var o,a;return(a=(o=this._tiles[`${e}:${t}:${r}`])==null?void 0:o.el)==null?void 0:a.wxtile}_ForEachWxTile(e){var r;let t=[];for(let o in this._tiles){let a=(r=this._tiles[o].el)==null?void 0:r.wxtile;a&&t.push(e(a))}return t}_stopLoadingResetLoadDataFunc(){this.loadDataIntegralFunc.abort(),this.loadDataIntegralFunc=z()}_checkAndStartVectorAnimation(){if(this.vectorAnimationRequestID)return;let e=t=>{if(!this._map||!this.animation||!this.state.vector||this.style.streamLineStatic||this.style.streamLineColor==="none"){this._ForEachWxTile(r=>r.clearVectorAnimationCanvas()),this.vectorAnimationRequestID=0;return}this._ForEachWxTile(r=>r.drawVectorAnimationLinesStep(t)),this.vectorAnimationRequestID=requestAnimationFrame(e)};this.vectorAnimationRequestID=requestAnimationFrame(e)}_redrawTiles(){this.redrawRequestID||(b("_redrawTiles: start: "+this.dataSource.name),this.redrawRequestID=requestAnimationFrame(()=>{this._ForEachWxTile(e=>e.draw()),this.redrawRequestID=0,b("_redrawTiles: requestAnimationFrame: end: "+this.dataSource.name)}))}};function Re(n){return new U(n)}var X=class extends H.default.Control{constructor(e){super(e);this.URI=e.URI}onAdd(){let e=document.createElement("img");return e.src=this.URI,e.className="wxtiles-logo",e}};function st(n){return b("Add watermark:",JSON.stringify(n)),new X(n)}var J=class extends H.default.GridLayer{createTile(e){let t=document.createElement("div");return t.innerHTML=[e.x,e.y,e.z].join(", "),t.style.outline="1px solid red",t}};function it(){return b("Add WxDebugCoordsLayer:"),new J().setZIndex(1e3)}function lt(n,e){return H.default.layerGroup(n.map(Re),e)}return ct;})();
|
package/package.json
CHANGED
package/src_example/index.ts
CHANGED
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
} from '../src/wxtiles';
|
|
19
19
|
import '../src/wxtiles.css';
|
|
20
20
|
|
|
21
|
+
import { Editor } from './visualStyleEditor';
|
|
22
|
+
|
|
21
23
|
let map: L.Map;
|
|
22
24
|
let layerControl: L.Control.Layers;
|
|
23
25
|
let config: Config; // application config
|
|
@@ -167,6 +169,8 @@ async function stopPlay() {
|
|
|
167
169
|
buttonPlayStopEl.textContent = 'play';
|
|
168
170
|
return globalLayer?.unsetTimeAnimationMode();
|
|
169
171
|
}
|
|
172
|
+
|
|
173
|
+
return;
|
|
170
174
|
}
|
|
171
175
|
|
|
172
176
|
function addOption(baseStyle: string, value = baseStyle) {
|
|
@@ -192,31 +196,11 @@ function fillStyles(layer: WxTilesLayer) {
|
|
|
192
196
|
onStyleChange_selectStyleEl_onchange();
|
|
193
197
|
}
|
|
194
198
|
|
|
195
|
-
function JSONsort(o: any) {
|
|
196
|
-
if (Array.isArray(o)) {
|
|
197
|
-
return o.map(JSONsort);
|
|
198
|
-
} else if (typeof o === 'object' && o !== null) {
|
|
199
|
-
const keys = Object.keys(o)
|
|
200
|
-
// .map((a) => a.toUpperCase())
|
|
201
|
-
.sort((a, b) => {
|
|
202
|
-
const aa = a.toUpperCase();
|
|
203
|
-
const bb = b.toUpperCase();
|
|
204
|
-
return aa == bb ? 0 : aa > bb ? 1 : -1;
|
|
205
|
-
});
|
|
206
|
-
return keys.reduce((a, k) => {
|
|
207
|
-
a[k] = JSONsort(o[k]);
|
|
208
|
-
return a;
|
|
209
|
-
}, {});
|
|
210
|
-
}
|
|
211
|
-
return o;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
199
|
function onStyleChange_selectStyleEl_onchange() {
|
|
215
200
|
if (!globalLayer) return;
|
|
216
201
|
if (selectStyleEl.value === 'custom') {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
} catch {
|
|
202
|
+
const style = editor.getStyle();
|
|
203
|
+
if (style instanceof Error) {
|
|
220
204
|
console.log('Wrong custom style');
|
|
221
205
|
const ctx = legendCanvasEl.getContext('2d');
|
|
222
206
|
if (!ctx) return;
|
|
@@ -227,10 +211,13 @@ function onStyleChange_selectStyleEl_onchange() {
|
|
|
227
211
|
ctx.stroke();
|
|
228
212
|
return;
|
|
229
213
|
}
|
|
214
|
+
styles.custom = style; //JSON.parse(customStyleTextAreaEl.value);
|
|
230
215
|
}
|
|
216
|
+
|
|
231
217
|
globalLayer.setStyle(selectStyleEl.value);
|
|
232
218
|
const curStyle = globalLayer.getStyle();
|
|
233
|
-
|
|
219
|
+
// customStyleTextAreaEl.value = JSON.stringify(JSONsort(curStyle), null, ' ');
|
|
220
|
+
editor.setStyle(curStyle);
|
|
234
221
|
const legend = globalLayer.getLegendData(legendCanvasEl.width - 50);
|
|
235
222
|
if (!legend) return;
|
|
236
223
|
drawLegend({ legend, canvas: legendCanvasEl });
|
|
@@ -393,6 +380,11 @@ async function start() {
|
|
|
393
380
|
// Leaflet basic setup // set the main Leaflet's map object, compose and add base layers
|
|
394
381
|
map = L.map('map', config.map);
|
|
395
382
|
|
|
383
|
+
const styleEditorEl = document.getElementById('styleEditor');
|
|
384
|
+
if (!styleEditorEl) {
|
|
385
|
+
throw new Error('styleEditorEl not found');
|
|
386
|
+
}
|
|
387
|
+
|
|
396
388
|
// Setup WxTiles lib
|
|
397
389
|
WxTilesLogging(true); // use wxtiles logging -> console.log
|
|
398
390
|
CreateWxTilesWatermark({ URI: 'res/wxtiles-logo.png', position: 'topright' }).addTo(map);
|
|
@@ -408,7 +400,7 @@ async function start() {
|
|
|
408
400
|
createControl({ position: 'topleft', htmlID: 'legend' }).addTo(map);
|
|
409
401
|
createControl({ position: 'topleft', htmlID: 'layerPanel' }).addTo(map);
|
|
410
402
|
createControl({ position: 'topleft', htmlID: 'styleEditor' }).addTo(map);
|
|
411
|
-
createControl({ position: '
|
|
403
|
+
createControl({ position: 'bottomright', htmlID: 'infoPanel' }).addTo(map);
|
|
412
404
|
|
|
413
405
|
const wxlibCustomSettings: any = {};
|
|
414
406
|
try {
|
|
@@ -438,10 +430,18 @@ async function start() {
|
|
|
438
430
|
styles = WxGetColorStyles(); // all available styles. Not every style is sutable for this layer.
|
|
439
431
|
|
|
440
432
|
fillDataSets('gfs.global', 'wind.speed.eastward.at-10m');
|
|
433
|
+
// fillDataSets('gfs.global', 'air.temperature.at-2m');
|
|
441
434
|
|
|
442
435
|
map.on('zoom', stopPlay); // stop time animation on zoom
|
|
443
436
|
map.on('mousemove', updateInfoPanel);
|
|
444
437
|
map.on('click', popupInfo);
|
|
438
|
+
editor = new Editor(map, styleEditorEl, selectStyleEl, { id: 'visualCustomStyleDivId', className: 'visualCustomStyleDivClass' });
|
|
439
|
+
editor.onchange = (style) => {
|
|
440
|
+
selectStyleEl.value = 'custom';
|
|
441
|
+
styles['custom'] = style;
|
|
442
|
+
// globalLayer?.setStyle('custom');
|
|
443
|
+
onStyleChange_selectStyleEl_onchange();
|
|
444
|
+
};
|
|
445
445
|
}
|
|
446
446
|
|
|
447
447
|
const selectDataSetEl = document.getElementById('selectDataSet') as HTMLSelectElement;
|
|
@@ -457,23 +457,31 @@ selectStyleEl.addEventListener('change', onStyleChange_selectStyleEl_onchange);
|
|
|
457
457
|
|
|
458
458
|
const legendCanvasEl = document.getElementById('legend') as HTMLCanvasElement;
|
|
459
459
|
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
460
|
+
// const customStyleDivEl = document.getElementById('customStyleDiv') as HTMLDivElement;
|
|
461
|
+
// const customStyleTextAreaEl = document.getElementById('customStyleTextArea') as HTMLTextAreaElement;
|
|
462
|
+
// const editor = createEditor(customStyleDivEl, 'visualCustomStyleDivId', 'visualCustomStyleDivClass');
|
|
463
|
+
let editor: Editor; // = new Editor(map, customStyleDivEl, 'visualCustomStyleDivId', 'visualCustomStyleDivClass');
|
|
464
|
+
// editor.onchange = (style) => {
|
|
465
|
+
// selectStyleEl.value = 'custom';
|
|
466
|
+
// customStyleTextAreaEl.value = JSON.stringify(style, null, ' ');
|
|
467
|
+
// onStyleChange_selectStyleEl_onchange();
|
|
468
|
+
// };
|
|
469
|
+
// customStyleTextAreaEl.addEventListener('change', () => {
|
|
470
|
+
// selectStyleEl.value = 'custom';
|
|
471
|
+
// onStyleChange_selectStyleEl_onchange();
|
|
472
|
+
// });
|
|
473
|
+
|
|
474
|
+
// const customStyleButtonEl = document.getElementById('customStyleButton')! as HTMLButtonElement;
|
|
475
|
+
// customStyleButtonEl.addEventListener('click', () => {
|
|
476
|
+
// if (customStyleDivEl.style.display != 'none') {
|
|
477
|
+
// customStyleDivEl.style.display = 'none';
|
|
478
|
+
// customStyleButtonEl.innerHTML = 'show Custom Style Editor';
|
|
479
|
+
// } else {
|
|
480
|
+
// customStyleDivEl.style.display = 'block';
|
|
481
|
+
// customStyleButtonEl.innerHTML = 'update Custom Style & Hide';
|
|
482
|
+
// selectStyleEl.value = 'custom';
|
|
483
|
+
// }
|
|
484
|
+
// });
|
|
477
485
|
|
|
478
486
|
const selectTimeEl = document.getElementById('selectTime') as HTMLSelectElement;
|
|
479
487
|
selectTimeEl.addEventListener('change', async () => {
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { ColorStyleStrict } from '../src/wxtiles';
|
|
2
|
+
import { WxGetColorSchemes, WxGetColorStyles } from '../src/wxtiles';
|
|
3
|
+
import { ColorStyleWeak } from '../src/utils/wxtools';
|
|
4
|
+
import L from 'leaflet';
|
|
5
|
+
|
|
6
|
+
function createEl<K extends keyof HTMLElementTagNameMap>(container: HTMLElement, tag: K, params?: any): HTMLElementTagNameMap[K] {
|
|
7
|
+
const el = document.createElement(tag);
|
|
8
|
+
Object.assign(el, params);
|
|
9
|
+
container?.appendChild(el);
|
|
10
|
+
return el;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function JSONsort(o: any) {
|
|
14
|
+
if (Array.isArray(o)) {
|
|
15
|
+
return o.map(JSONsort);
|
|
16
|
+
} else if (typeof o === 'object' && o !== null) {
|
|
17
|
+
const keys = Object.keys(o)
|
|
18
|
+
// .map((a) => a.toUpperCase())
|
|
19
|
+
.sort((a, b) => {
|
|
20
|
+
const aa = a.toUpperCase();
|
|
21
|
+
const bb = b.toUpperCase();
|
|
22
|
+
return aa == bb ? 0 : aa > bb ? 1 : -1;
|
|
23
|
+
});
|
|
24
|
+
return keys.reduce((a, k) => {
|
|
25
|
+
a[k] = JSONsort(o[k]);
|
|
26
|
+
return a;
|
|
27
|
+
}, {});
|
|
28
|
+
}
|
|
29
|
+
return o;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class Editor {
|
|
33
|
+
onchange?: (style: ColorStyleStrict) => void;
|
|
34
|
+
|
|
35
|
+
editorTextAreaEl: HTMLTextAreaElement;
|
|
36
|
+
editorDivEl: HTMLDivElement;
|
|
37
|
+
|
|
38
|
+
// inputs
|
|
39
|
+
parentInput: HTMLInputElement; // string
|
|
40
|
+
|
|
41
|
+
nameInput: HTMLInputElement; // string
|
|
42
|
+
|
|
43
|
+
fillSelect: HTMLSelectElement; // string
|
|
44
|
+
|
|
45
|
+
isolineColorSelect: HTMLSelectElement; // string
|
|
46
|
+
isolineColorInput: HTMLInputElement;
|
|
47
|
+
|
|
48
|
+
isolineTextInput: HTMLInputElement; // boolean
|
|
49
|
+
|
|
50
|
+
vectorTypeSelect: HTMLSelectElement; // string
|
|
51
|
+
|
|
52
|
+
vectorColorSelect: HTMLSelectElement; // string
|
|
53
|
+
vectorColorInput: HTMLInputElement;
|
|
54
|
+
|
|
55
|
+
vectorFactorInput: HTMLInputElement; // number
|
|
56
|
+
|
|
57
|
+
streamLineColorInput: HTMLInputElement; // string
|
|
58
|
+
streamLineColorVisibleInput: HTMLInputElement; // boolean
|
|
59
|
+
|
|
60
|
+
streamLineSpeedFactorInput: HTMLInputElement; // number
|
|
61
|
+
|
|
62
|
+
streamLineStaticInput: HTMLInputElement; // boolean
|
|
63
|
+
|
|
64
|
+
showBelowMinInput: HTMLInputElement; // boolean
|
|
65
|
+
|
|
66
|
+
showAboveMaxInput: HTMLInputElement; // boolean
|
|
67
|
+
|
|
68
|
+
colorSchemeSelect: HTMLSelectElement; // string
|
|
69
|
+
|
|
70
|
+
colorsInput: HTMLInputElement; // string[];
|
|
71
|
+
|
|
72
|
+
colorMapInput: HTMLInputElement; // [number, string][];
|
|
73
|
+
|
|
74
|
+
levelsInput: HTMLInputElement; // number[];
|
|
75
|
+
|
|
76
|
+
blurRadiusInput: HTMLInputElement; // number
|
|
77
|
+
|
|
78
|
+
addDegreesInput: HTMLInputElement; // number
|
|
79
|
+
|
|
80
|
+
unitsInput: HTMLInputElement; // string
|
|
81
|
+
|
|
82
|
+
extraUnitsInput: HTMLInputElement; // Units as { [name: string]: [string, number, ?number] };
|
|
83
|
+
|
|
84
|
+
maskSelect: HTMLSelectElement; // string
|
|
85
|
+
|
|
86
|
+
styleBase: ColorStyleStrict;
|
|
87
|
+
|
|
88
|
+
constructor(map: L.Map, parent: HTMLElement, selectStyleEl: HTMLSelectElement, opts: { id: string; className: string }) {
|
|
89
|
+
this.styleBase = WxGetColorStyles()['base'];
|
|
90
|
+
|
|
91
|
+
// helpers
|
|
92
|
+
const onwheel = L.DomEvent.stopPropagation;
|
|
93
|
+
const onmousedown = (e: MouseEvent) => map.dragging.disable() && onwheel(e);
|
|
94
|
+
const onmouseup = (e: MouseEvent) => map.dragging.enable() && onwheel(e);
|
|
95
|
+
// Top level container
|
|
96
|
+
const topmostDivEl = createEl(parent, 'div', { onclick: onwheel, ondblclick: onwheel, onwheel, onmousedown, onmouseup });
|
|
97
|
+
// Button to open/close editor
|
|
98
|
+
const customStyleButtonEl = createEl(topmostDivEl, 'button', {
|
|
99
|
+
id: 'customStyleButton',
|
|
100
|
+
style: 'height: 1.5em; background-color: gray',
|
|
101
|
+
innerText: 'Custom Style',
|
|
102
|
+
});
|
|
103
|
+
// Editor container
|
|
104
|
+
const customStyleHiddableDivEl = createEl(topmostDivEl, 'div', {
|
|
105
|
+
id: 'customStyleDiv',
|
|
106
|
+
style: 'display: none; border-color: black; border-style: solid; border-width: 2px; background-color: rgba(135, 206, 250, 0.8)',
|
|
107
|
+
});
|
|
108
|
+
customStyleButtonEl.addEventListener('click', () => {
|
|
109
|
+
if (customStyleHiddableDivEl.style.display !== 'none') {
|
|
110
|
+
customStyleHiddableDivEl.style.display = 'none';
|
|
111
|
+
customStyleButtonEl.innerHTML = 'show Custom Style Editor';
|
|
112
|
+
} else {
|
|
113
|
+
customStyleHiddableDivEl.style.display = 'flex';
|
|
114
|
+
customStyleButtonEl.innerHTML = 'update Custom Style & Hide';
|
|
115
|
+
selectStyleEl.value = 'custom';
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Text area to edit custom style
|
|
120
|
+
this.editorTextAreaEl = createEl(customStyleHiddableDivEl, 'textarea', { id: 'customStyleTextArea', style: 'width: 20vw; height: 70vh' });
|
|
121
|
+
this.editorTextAreaEl.addEventListener('change', () => this._onTextChange());
|
|
122
|
+
// Editor container
|
|
123
|
+
this.editorDivEl = createEl(customStyleHiddableDivEl, 'div', opts);
|
|
124
|
+
// Helpers
|
|
125
|
+
const addLabel = (id: string, br: boolean = true) => {
|
|
126
|
+
createEl(this.editorDivEl, 'label', { htmlFor: id, id: id + 'Label', className: id + 'LabelClass', textContent: id.replace(/Input|Select$/i, '') });
|
|
127
|
+
br && createEl(this.editorDivEl, 'br', {});
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const addInput = ({
|
|
131
|
+
id,
|
|
132
|
+
type,
|
|
133
|
+
min,
|
|
134
|
+
max,
|
|
135
|
+
step,
|
|
136
|
+
onEvent = 'change',
|
|
137
|
+
br = true,
|
|
138
|
+
}: {
|
|
139
|
+
id: string;
|
|
140
|
+
type: string;
|
|
141
|
+
onEvent?: string;
|
|
142
|
+
min?: string;
|
|
143
|
+
max?: string;
|
|
144
|
+
step?: string;
|
|
145
|
+
br?: boolean;
|
|
146
|
+
}): HTMLInputElement => {
|
|
147
|
+
const el = createEl(this.editorDivEl, 'input', { id, className: id + 'Class', type, min, max, step });
|
|
148
|
+
onEvent !== 'none' && el.addEventListener(onEvent, () => this._onDivChange());
|
|
149
|
+
addLabel(id, br);
|
|
150
|
+
return el;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const addSelect = ({ id, opts, onEvent = 'change', br = true }: { id: string; opts: string[]; onEvent?: string; br?: boolean }) => {
|
|
154
|
+
const el = createEl(this.editorDivEl, 'select', { id, className: id + 'Class' });
|
|
155
|
+
onEvent !== 'none' && el.addEventListener(onEvent, () => this._onDivChange());
|
|
156
|
+
opts.forEach((name) => el.options.add(createEl(el, 'option', { value: name, text: name })));
|
|
157
|
+
addLabel(id, br);
|
|
158
|
+
el.selectedIndex = 0;
|
|
159
|
+
return el;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
this.parentInput = addInput({ id: 'parentInput', type: 'text' });
|
|
163
|
+
this.nameInput = addInput({ id: 'nameInput', type: 'text' });
|
|
164
|
+
this.fillSelect = addSelect({ id: 'fillSelect', opts: ['', 'gradient', 'solid', 'none'] });
|
|
165
|
+
|
|
166
|
+
this.isolineColorSelect = addSelect({ id: 'isolineColorSelect', br: false, opts: ['', 'inverted', 'fill', 'none', 'custom'] });
|
|
167
|
+
this.isolineColorInput = addInput({ id: 'isolineColorInput', type: 'color', onEvent: 'none' });
|
|
168
|
+
|
|
169
|
+
// this.isolineColorSelect.addEventListener('change', () => {
|
|
170
|
+
// this.isolineColorInput.disabled = this.isolineColorSelect.value !== 'custom';
|
|
171
|
+
// });
|
|
172
|
+
this.isolineColorInput.addEventListener('change', () => {
|
|
173
|
+
this.isolineColorSelect.value = 'custom';
|
|
174
|
+
this._onDivChange();
|
|
175
|
+
});
|
|
176
|
+
this.isolineTextInput = addInput({ id: 'isolineTextInput', type: 'checkbox' });
|
|
177
|
+
this.vectorTypeSelect = addSelect({ id: 'vectorTypeSelect', opts: ['', 'arrows', 'barbs', 'none'] });
|
|
178
|
+
this.vectorColorSelect = addSelect({ id: 'vectorColorSelect', br: false, opts: ['', 'inverted', 'fill', 'none', 'custom'] });
|
|
179
|
+
this.vectorColorInput = addInput({ id: 'vectorColorInput', type: 'color', onEvent: 'none' });
|
|
180
|
+
this.vectorColorInput.addEventListener('change', () => {
|
|
181
|
+
this.vectorColorSelect.value = 'custom';
|
|
182
|
+
this._onDivChange();
|
|
183
|
+
});
|
|
184
|
+
this.vectorFactorInput = addInput({ id: 'vectorFactorInput', type: 'number', min: '0.1', max: '10', step: '0.1' });
|
|
185
|
+
this.streamLineColorVisibleInput = addInput({ id: 'streamLineColorVisibleInput', br: false, type: 'checkbox' });
|
|
186
|
+
this.streamLineColorVisibleInput.addEventListener('change', () => (this.streamLineColorInput.disabled = !this.streamLineColorVisibleInput.checked));
|
|
187
|
+
this.streamLineColorInput = addInput({ id: 'streamLineColorInput', type: 'color' });
|
|
188
|
+
this.streamLineSpeedFactorInput = addInput({ id: 'streamLineSpeedFactorInput', type: 'number', min: '0.1', max: '10', step: '0.1' });
|
|
189
|
+
this.streamLineStaticInput = addInput({ id: 'streamLineStaticInput', type: 'checkbox' });
|
|
190
|
+
this.showBelowMinInput = addInput({ id: 'showBelowMinInput', type: 'checkbox' });
|
|
191
|
+
this.showAboveMaxInput = addInput({ id: 'showAboveMaxInput', type: 'checkbox' });
|
|
192
|
+
this.colorSchemeSelect = addSelect({ id: 'colorSchemeSelect', opts: Object.keys(WxGetColorSchemes()), onEvent: 'none' });
|
|
193
|
+
this.colorSchemeSelect.addEventListener('change', () => {
|
|
194
|
+
const style = this.getStyle();
|
|
195
|
+
delete style.colors;
|
|
196
|
+
this._setStyleToTextArea(style);
|
|
197
|
+
this.colorsInput.value = '';
|
|
198
|
+
this._onDivChange();
|
|
199
|
+
});
|
|
200
|
+
this.colorsInput = addInput({ id: 'colorsInput', type: 'text' }); // TODO:
|
|
201
|
+
this.colorMapInput = addInput({ id: 'colorMapInput', type: 'text' }); // TODO:
|
|
202
|
+
this.levelsInput = addInput({ id: 'levelsInput', type: 'text' }); // TODO:
|
|
203
|
+
this.blurRadiusInput = addInput({ id: 'blurRadiusInput', type: 'range', onEvent: 'input', min: '0', max: '10', step: '1' });
|
|
204
|
+
this.addDegreesInput = addInput({ id: 'addDegreesInput', type: 'number', min: '0', max: '360', step: '1' });
|
|
205
|
+
this.unitsInput = addInput({ id: 'unitsInput', type: 'text' });
|
|
206
|
+
this.extraUnitsInput = addInput({ id: 'extraUnitsInput', type: 'text' });
|
|
207
|
+
this.maskSelect = addSelect({ id: 'maskSelect', opts: ['', 'none', 'sea', 'land'] });
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
getStyle(): ColorStyleStrict {
|
|
211
|
+
// deep copy from _getStyleFromTextArea, _getStyleFromDiv not needed as affected the textarea already
|
|
212
|
+
return Object.assign({}, this.styleBase, this._getStyleFromTextArea() /*, this._getStyleFromDiv()*/);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
setStyle(style: ColorStyleWeak): void {
|
|
216
|
+
this._setStyleToTextArea(style);
|
|
217
|
+
this._setStyleToDiv(style);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// this.editorTextAreaEl is always modifyed by StyleFromDiv at any changes in the div
|
|
221
|
+
protected _getStyleFromTextArea(): ColorStyleWeak {
|
|
222
|
+
try {
|
|
223
|
+
return JSON.parse(this.editorTextAreaEl.value);
|
|
224
|
+
} catch (e) {
|
|
225
|
+
return e;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
protected _getStyleFromDiv(): ColorStyleWeak {
|
|
230
|
+
const objFromValue = (field: string) => {
|
|
231
|
+
try {
|
|
232
|
+
return this[field].value ? JSON.parse(this[field].value) : undefined;
|
|
233
|
+
} catch (e) {
|
|
234
|
+
console.log(field, ' : parsing error: ', e);
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
const extraUnits = objFromValue('extraUnitsInput');
|
|
239
|
+
const colors = objFromValue('colorsInput');
|
|
240
|
+
const colorMap = objFromValue('colorMapInput');
|
|
241
|
+
const levels = objFromValue('levelsInput');
|
|
242
|
+
// (() => {
|
|
243
|
+
// try {
|
|
244
|
+
// return this.extraUnitsInput.value ? <Units>JSON.parse(this.extraUnitsInput.value) : undefined;
|
|
245
|
+
// } catch (e) {
|
|
246
|
+
// console.log('ExtraUnits: parsing error: ', e);
|
|
247
|
+
// return undefined;
|
|
248
|
+
// }
|
|
249
|
+
// })();
|
|
250
|
+
|
|
251
|
+
const style: ColorStyleWeak = {
|
|
252
|
+
parent: this.parentInput.value || 'base', // string;
|
|
253
|
+
name: this.nameInput.value || undefined, //string;
|
|
254
|
+
fill: this.fillSelect.value || undefined, //string;
|
|
255
|
+
isolineColor: this.isolineColorSelect.value === 'custom' ? this.isolineColorInput.value : this.isolineColorSelect.value || undefined, //string;
|
|
256
|
+
isolineText: this.isolineTextInput.checked, //boolean;
|
|
257
|
+
vectorType: this.vectorTypeSelect.value || undefined, //string;
|
|
258
|
+
vectorColor: this.vectorColorSelect.value === 'custom' ? this.vectorColorInput.value : this.vectorColorSelect.value || undefined, //string;
|
|
259
|
+
vectorFactor: this.vectorFactorInput.value ? +this.vectorFactorInput.value : undefined, //number;
|
|
260
|
+
streamLineColor: this.streamLineColorVisibleInput.checked ? this.streamLineColorInput.value : 'none', //string;
|
|
261
|
+
streamLineSpeedFactor: this.streamLineSpeedFactorInput.value ? +this.streamLineSpeedFactorInput.value : undefined, //number;
|
|
262
|
+
streamLineStatic: this.streamLineStaticInput.checked, //boolean;
|
|
263
|
+
showBelowMin: this.showBelowMinInput.checked, //boolean;
|
|
264
|
+
showAboveMax: this.showAboveMaxInput.checked, //boolean;
|
|
265
|
+
colorScheme: this.colorSchemeSelect.value || undefined, //string;
|
|
266
|
+
colors, // string[];
|
|
267
|
+
colorMap, // [number, string][];
|
|
268
|
+
levels, // number[];
|
|
269
|
+
blurRadius: this.blurRadiusInput.value ? +this.blurRadiusInput.value : undefined, //number;
|
|
270
|
+
addDegrees: this.addDegreesInput.value ? +this.addDegreesInput.value : undefined, //number;
|
|
271
|
+
units: this.unitsInput.value || undefined, //string;
|
|
272
|
+
extraUnits, // Units; //{ [name: string]: [string, number, ?number] };
|
|
273
|
+
mask: this.maskSelect.value || undefined, // string;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
return style;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
protected _setStyleToTextArea(style: ColorStyleWeak): void {
|
|
280
|
+
this.editorTextAreaEl.value = JSON.stringify(JSONsort(style), null, 2);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
protected _setStyleToDiv(style: ColorStyleWeak): void {
|
|
284
|
+
this.parentInput.value = style.parent || ''; // string;
|
|
285
|
+
this.nameInput.value = style.name || ''; //string;
|
|
286
|
+
this.fillSelect.value = style.fill || ''; //string;
|
|
287
|
+
this.isolineColorSelect.value = style.isolineColor?.[0] === '#' ? 'custom' : style.isolineColor || ''; //string;
|
|
288
|
+
this.isolineColorInput.value = style.isolineColor?.[0] === '#' ? style.isolineColor : ''; //string;
|
|
289
|
+
this.isolineTextInput.checked = style.isolineText || false; //boolean;
|
|
290
|
+
this.vectorTypeSelect.value = style.vectorType || ''; //string;
|
|
291
|
+
this.vectorColorSelect.value = style.vectorColor?.[0] === '#' ? 'custom' : style.vectorColor || ''; //string;
|
|
292
|
+
this.vectorColorInput.value = style.vectorColor?.[0] === '#' ? style.vectorColor : ''; //string;
|
|
293
|
+
this.vectorFactorInput.value = style.vectorFactor?.toString() || '1'; //number;
|
|
294
|
+
this.streamLineColorVisibleInput.checked = style.streamLineColor !== 'none'; //boolean;
|
|
295
|
+
this.streamLineColorInput.value = style.streamLineColor || ''; //string;
|
|
296
|
+
this.streamLineSpeedFactorInput.value = style.streamLineSpeedFactor?.toString() || '1'; //number;
|
|
297
|
+
this.streamLineStaticInput.checked = style.streamLineStatic || false; //boolean;
|
|
298
|
+
this.showBelowMinInput.checked = style.showBelowMin || false; //boolean;
|
|
299
|
+
this.showAboveMaxInput.checked = style.showAboveMax || false; //boolean;
|
|
300
|
+
this.colorSchemeSelect.value = style.colorScheme || ''; //string;
|
|
301
|
+
this.colorsInput.value = style.colors?.length ? JSON.stringify(style.colors) : ''; // string[];
|
|
302
|
+
this.colorMapInput.value = style.colorMap?.length ? JSON.stringify(style.colorMap) : ''; // [number, string][];
|
|
303
|
+
this.levelsInput.value = style.levels?.length ? JSON.stringify(style.levels) : ''; // number[];
|
|
304
|
+
this.blurRadiusInput.value = style.blurRadius?.toString() || ''; //number;
|
|
305
|
+
this.addDegreesInput.value = style.addDegrees?.toString() || ''; //number;
|
|
306
|
+
this.unitsInput.value = style.units || ''; //string;
|
|
307
|
+
this.extraUnitsInput.value = style.extraUnits ? JSON.stringify(style.extraUnits) : ''; // Units; //{ [name: string]: [string, number, ?number] };
|
|
308
|
+
this.maskSelect.value = style.mask || ''; // string;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
protected _onDivChange(): void {
|
|
312
|
+
// update text area
|
|
313
|
+
const style = Object.assign(this._getStyleFromTextArea(), this._getStyleFromDiv());
|
|
314
|
+
this.editorTextAreaEl.value = JSON.stringify(style, null, 2);
|
|
315
|
+
this.onchange?.(this.getStyle());
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
protected _onTextChange(): void {
|
|
319
|
+
// update div
|
|
320
|
+
const style = this._getStyleFromTextArea();
|
|
321
|
+
this._setStyleToDiv(style);
|
|
322
|
+
this.onchange?.(this.getStyle());
|
|
323
|
+
}
|
|
324
|
+
}
|