@metoceanapi/wxtiles-leaflet 1.0.9 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/es/tile.d.ts +4 -4
- package/dist/es/tilesLayer.d.ts +52 -24
- package/dist/es/wxtiles.d.ts +5 -2
- package/dist/es/wxtiles.js +1 -1
- package/dist/es/wxtools.d.ts +7 -5
- package/dist/web/wxtiles.js +1 -1
- package/package.json +1 -1
- package/src_example/index.ts +513 -0
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,16 @@ Write your changes below this section. `npm version [major|minor|patch]` will au
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
## [1.0.10] - 2021-11-25
|
|
13
|
+
|
|
14
|
+
### FIXED
|
|
15
|
+
|
|
16
|
+
- setTime and cacheIt - remastering
|
|
17
|
+
|
|
18
|
+
### ADDED
|
|
19
|
+
|
|
20
|
+
- proper comments for some exported functions
|
|
21
|
+
|
|
12
22
|
## [1.0.9] - 2021-11-15
|
|
13
23
|
|
|
14
24
|
### FIXED
|
package/dist/es/tile.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface Coords {
|
|
|
6
6
|
y: number;
|
|
7
7
|
}
|
|
8
8
|
export interface TileEl extends HTMLElement {
|
|
9
|
-
wxtile
|
|
9
|
+
wxtile: WxTile;
|
|
10
10
|
}
|
|
11
11
|
export interface TileCreateParams {
|
|
12
12
|
layer: WxTilesLayer;
|
|
@@ -21,6 +21,7 @@ interface SLinePoint {
|
|
|
21
21
|
declare type SLine = SLinePoint[];
|
|
22
22
|
export declare class WxTile {
|
|
23
23
|
coords: Coords;
|
|
24
|
+
data: DataPicture[];
|
|
24
25
|
protected layer: WxTilesLayer;
|
|
25
26
|
protected canvasFill: HTMLCanvasElement;
|
|
26
27
|
protected canvasSlines: HTMLCanvasElement;
|
|
@@ -28,13 +29,12 @@ export declare class WxTile {
|
|
|
28
29
|
protected canvasFillCtx: CanvasRenderingContext2D;
|
|
29
30
|
protected canvasSlinesCtx: CanvasRenderingContext2D;
|
|
30
31
|
protected canvasVectorCtx: CanvasRenderingContext2D;
|
|
31
|
-
protected data: DataPicture[];
|
|
32
32
|
protected sLines: SLine[];
|
|
33
|
-
protected imData: ImageData
|
|
33
|
+
protected imData: ImageData;
|
|
34
34
|
constructor({ layer, coords, tileEl }: {
|
|
35
35
|
layer: WxTilesLayer;
|
|
36
36
|
coords: Coords;
|
|
37
|
-
tileEl:
|
|
37
|
+
tileEl: HTMLElement;
|
|
38
38
|
});
|
|
39
39
|
draw(): void;
|
|
40
40
|
clearSLinesCanvas(): void;
|
package/dist/es/tilesLayer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import L from 'leaflet';
|
|
2
|
-
import { RawCLUT } from './RawCLUT';
|
|
2
|
+
import { RawCLUT, Legend } from './RawCLUT';
|
|
3
3
|
import { WxTile } from './tile';
|
|
4
4
|
import { ColorStylesStrict, ColorStyleStrict, AbortableCacheableFunc, DataIntegral } from './wxtools';
|
|
5
5
|
export interface VariableMeta {
|
|
@@ -47,13 +47,25 @@ export interface WxLayerState {
|
|
|
47
47
|
baseURL: string;
|
|
48
48
|
}
|
|
49
49
|
export interface WxTilesLayerSettings {
|
|
50
|
-
lazy
|
|
50
|
+
lazy?: boolean;
|
|
51
51
|
dataSource: DataSource;
|
|
52
52
|
options: L.GridLayerOptions;
|
|
53
53
|
}
|
|
54
|
+
export interface WxTileInfo {
|
|
55
|
+
tile: WxTile;
|
|
56
|
+
data: number;
|
|
57
|
+
raw: number;
|
|
58
|
+
rgba: number;
|
|
59
|
+
hexColor: string;
|
|
60
|
+
inStyleUnits: number;
|
|
61
|
+
tilePoint: {
|
|
62
|
+
x: number;
|
|
63
|
+
y: number;
|
|
64
|
+
};
|
|
65
|
+
units: string;
|
|
66
|
+
}
|
|
54
67
|
export declare class WxTilesLayer extends L.GridLayer {
|
|
55
|
-
setupCompletePromise: Promise<boolean
|
|
56
|
-
protected wxtiles: Map<string, WxTile>;
|
|
68
|
+
setupCompletePromise: Promise<boolean>;
|
|
57
69
|
protected styles: ColorStylesStrict;
|
|
58
70
|
dataSource: DataSource;
|
|
59
71
|
style: ColorStyleStrict;
|
|
@@ -64,43 +76,59 @@ export declare class WxTilesLayer extends L.GridLayer {
|
|
|
64
76
|
clut: RawCLUT;
|
|
65
77
|
state: WxLayerState;
|
|
66
78
|
animation: boolean;
|
|
79
|
+
protected lastBaseURL: string;
|
|
67
80
|
protected animationRedrawID: number;
|
|
68
81
|
protected animFrame: number;
|
|
69
82
|
protected oldMaxZoom: number;
|
|
70
83
|
constructor({ dataSource, options, lazy }: WxTilesLayerSettings);
|
|
84
|
+
/** Leaflet's calling this, don't use it directly! */
|
|
71
85
|
protected createTile(coords: L.Coords, done: L.DoneCallback): HTMLElement;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
raw: number;
|
|
77
|
-
rgba: number;
|
|
78
|
-
hexColor: string;
|
|
79
|
-
inStyleUnits: number;
|
|
80
|
-
tilePoint: {
|
|
81
|
-
x: number;
|
|
82
|
-
y: number;
|
|
83
|
-
};
|
|
84
|
-
units: string;
|
|
85
|
-
} | undefined;
|
|
86
|
+
/** NOTE: if lazy setup and layer was not added to a map - this is never fulfilled */
|
|
87
|
+
getSetupCompletePromise(): Promise<boolean>;
|
|
88
|
+
/** get all the information about tile and point it represents */
|
|
89
|
+
getTile(latlng: L.LatLngExpression): WxTileInfo | undefined;
|
|
86
90
|
setStyle(name: string | undefined): void;
|
|
91
|
+
/** string - style from dataSource. Useful to get layer's style: style = WxGetColorStyles()[wxlayer.getStyle()] */
|
|
87
92
|
getStyle(): string;
|
|
93
|
+
/** string - style's name used for the layer. Useful for exposing the layer style's name.*/
|
|
88
94
|
getStyleName(): string;
|
|
89
|
-
|
|
95
|
+
/** time as Date or unix time (ms since 00:00:00 UTC on 1 January 1970) */
|
|
96
|
+
setTime(time: Date | string | number): Promise<WxTile[]>;
|
|
97
|
+
/** string - current time as it is in meta */
|
|
90
98
|
getTime(): string;
|
|
99
|
+
/** Array of strings (times) */
|
|
91
100
|
getTimes(): string[];
|
|
101
|
+
/** check if data has been changed since last init */
|
|
92
102
|
checkDataChanged(): Promise<boolean>;
|
|
103
|
+
/** usefull if data is changed on server (checkable with 'checkDataChanged') */
|
|
93
104
|
reloadData(): Promise<boolean>;
|
|
94
|
-
|
|
105
|
+
/**
|
|
106
|
+
* getLegendData - data to render a proper legend
|
|
107
|
+
* pixSize - width of a canvas to render this legend
|
|
108
|
+
* output:
|
|
109
|
+
* legend - object
|
|
110
|
+
* legend.units - (string) units
|
|
111
|
+
* legend.colors - Uint32Array(pixSize) - legend colors RGBA.
|
|
112
|
+
* legend.ticks - ([tick])aray of ticks
|
|
113
|
+
* tick.data - (float) data in legend units
|
|
114
|
+
* tick.color - (string) representation of a color at this tick
|
|
115
|
+
* tick.pos - (int) position in pixels of this tick on the legend. If style uses values out of data's range it clamps pos to (0, pixSize)
|
|
116
|
+
*/
|
|
117
|
+
getLegendData(legendSize: number): Legend;
|
|
118
|
+
/** set coarse maximum zoom level to make tiles load faster during animation */
|
|
95
119
|
setTimeAnimationMode(l?: number): void;
|
|
96
|
-
|
|
120
|
+
/** restore maximum zoom level */
|
|
121
|
+
unsetTimeAnimationMode(): Promise<WxTile[]>;
|
|
122
|
+
/** min, max values of the loaded data */
|
|
97
123
|
getMinMax(): {
|
|
98
124
|
min: number;
|
|
99
125
|
max: number;
|
|
100
126
|
};
|
|
101
|
-
|
|
127
|
+
/** true/false - if vector data and true, animation starts */
|
|
128
|
+
setAnimation(a: boolean): boolean;
|
|
129
|
+
protected _getCachedTile(x: number, y: number, zoom: number): WxTile | undefined;
|
|
130
|
+
protected _ForEachTile<T>(func: (wxtile: WxTile) => T): T[];
|
|
102
131
|
protected _setUpDataSet(dataSource: DataSource | undefined): Promise<boolean>;
|
|
103
|
-
protected _updateMinMax(): void;
|
|
104
132
|
protected _checkZoom(): void;
|
|
105
133
|
protected _onAddLayer(): void;
|
|
106
134
|
protected _onRemoveLayer(): void;
|
|
@@ -108,5 +136,5 @@ export declare class WxTilesLayer extends L.GridLayer {
|
|
|
108
136
|
protected _checkAndStartSlinesAnimation(): void;
|
|
109
137
|
protected _stopSlinesAnimation(): void;
|
|
110
138
|
protected _redrawTiles(): void;
|
|
111
|
-
protected _reloadTiles(): Promise<WxTile[]>;
|
|
139
|
+
protected _reloadTiles(redraw?: boolean): Promise<WxTile[]>;
|
|
112
140
|
}
|
package/dist/es/wxtiles.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import './wxtiles.css';
|
|
2
2
|
import L from 'leaflet';
|
|
3
3
|
import { WxTilesLayer, WxTilesLayerSettings } from './tilesLayer';
|
|
4
|
-
export { WxTilesLogging, WxTilesLibSetup, WxGetColorStyles
|
|
5
|
-
export {
|
|
4
|
+
export { WxTilesLogging, WxTilesLibSetup, WxGetColorStyles } from './wxtools';
|
|
5
|
+
export type { ColorStylesWeakMixed, ColorStyleStrict, ColorStylesStrict, Units, ColorSchemes, LibSetupObject } from './wxtools';
|
|
6
|
+
export type { WxTilesLayerSettings, DataSource, Meta, WxTileInfo } from './tilesLayer';
|
|
7
|
+
export { WxTilesLayer } from './tilesLayer';
|
|
8
|
+
export type { Legend } from './RawCLUT';
|
|
6
9
|
export { LoadQTree } from './qtree';
|
|
7
10
|
export declare function CreateWxTilesLayer(settings: WxTilesLayerSettings): WxTilesLayer;
|
|
8
11
|
export declare class WxWatermark extends L.Control {
|
package/dist/es/wxtiles.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Lt=Object.create;var _=Object.defineProperty;var Tt=Object.getOwnPropertyDescriptor;var Mt=Object.getOwnPropertyNames,V=Object.getOwnPropertySymbols,Dt=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty,kt=Object.prototype.propertyIsEnumerable;var X=(r,t,e)=>t in r?_(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,J=(r,t)=>{for(var e in t||(t={}))$.call(t,e)&&X(r,e,t[e]);if(V)for(var e of V(t))kt.call(t,e)&&X(r,e,t[e]);return r};var At=r=>_(r,"__esModule",{value:!0});var Xt=typeof require!="undefined"?require:r=>{throw new Error('Dynamic require of "'+r+'" is not supported')};var It=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports);var _t=(r,t,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Mt(t))!$.call(r,n)&&n!=="default"&&_(r,n,{get:()=>t[n],enumerable:!(e=Tt(t,n))||e.enumerable});return r},Y=r=>_t(At(_(r!=null?Lt(Dt(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var N=It((ee,tt)=>{tt.exports=window.L});var E=Y(N());var et={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 rt={none:["#00000000","#00000000"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbowzerro:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow2:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebirdzerro:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bw:["#000000ff","#ffffffff"],wb:["#ffffffff","#000000ff"],redish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]};var P={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"}};var Z,nt,st;function Pt({colorStyles:r={},units:t={},colorSchemes:e={}}={}){C("WxTile lib setup: start"),Z=Object.assign({},et,t),nt=Object.assign({},e,rt);let n=Object.assign({},r,P);st=Ut(n),C("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),C("WxTile lib setup is done.")}function B(){return st}function ot(){return nt}function U(r,t,e){let n=e?Object.assign({},Z,e):Z;if(!n||!r||!t||r===t||!n[r]||!n[t]||n[r][0]!==n[t][0]){C(r===t?"Trivial converter:":"Inconvertible units. Default converter is used:",r," -> ",t);let o=a=>a;return o.trivial=!0,o}C("Converter: From:",r," To:",t);let s=n[r][1]/n[t][1],i=(n[r][2]||0)/n[t][1]-(n[t][2]||0)/n[t][1];return i?o=>s*o+i:o=>s*o}function Ut(r){let t=Object.assign({},P);for(let s in r){let i=r[s];if(Array.isArray(i))for(let o=0;o<i.length;++o)t[s+"["+o+"]"]=Object.assign({},i[o]);else t[s]=Object.assign({},i)}let e=(s,i)=>{if(i==="base")return P.base;let o=s[i];(!o.parent||!(o.parent in s))&&(o.parent="base");let a=e(s,o.parent);return Object.assign(o,Object.assign({},a,o,{parent:"base"}))},n={};for(let s in t)n[s]=e(t,s);return n}function it(r){let t=new Map;return e=>{let n=t.get(e);return n===void 0&&(n=r(e),t.set(e,n)),n}}async function Rt(r,t){let e=await(await fetch(r,{signal:t})).blob(),n=new Image;if(!t.aborted){let s=URL.createObjectURL(e);n.src=s,await n.decode(),URL.revokeObjectURL(s)}return n}function Ft(r){let{width:t,height:e}=r,n=Object.assign(document.createElement("canvas"),{width:t,height:e,imageSmoothingEnabled:!1}).getContext("2d");if(!n)throw"catastrophe";return n.drawImage(r,0,0),n.getImageData(0,0,t,e)}async function at(r,t){return Ft(await Rt(r,t))}async function Wt(r,t){return(n=>{let s=n.height*n.width,i=new Uint16Array(n.data.buffer),o=new Uint16Array(s);for(let f=0;f<s;f++)o[f]=i[f*2];let a=new Uint8Array(n.data.buffer);for(let f=0;f<8;++f)a[f]=a[f*4+2];let u=new DataView(n.data.buffer),h=u.getFloat32(0,!0),b=u.getFloat32(4,!0),l=(b-h)/65535,c=Et(o);return{raw:o,dmin:h,dmax:b,dmul:l,integral:c,radius:0}})(await at(r,t))}function j(){let r=new AbortController,t=it(e=>Wt(e,r.signal));return t.abort=()=>r.abort(),t.controller=r,t}function lt(r){let t=it(e=>at(e,r.signal));return t.abort=()=>r.abort(),t.controller=r,t}function Et(r){let t=new Uint32Array(258*258),e=new Uint32Array(258*258);t[0]=r[0],e[0]=r[0]===0?0:1;for(let n=1;n<258;++n)t[n]=r[n]+t[n-1],t[258*n]=r[258*n]+t[258*n-258],e[n]=(r[n]===0?0:1)+e[n-1],e[258*n]=(r[258*n]===0?0:1)+e[258*n-258];for(let n=1,s=259;n<258;++n,++s)for(let i=1;i<258;++i,++s)t[s]=r[s]+t[s-258]+t[s-1]-t[s-258-1],e[s]=(r[s]===0?0:1)+e[s-258]+e[s-1]-e[s-258-1];return{integral:t,integralNZ:e}}function ct(r,t){if(t<0||t===r.radius)return r;r.radius=t;let e=258,{integral:n,integralNZ:s}=r.integral;for(let i=1;i<e;i++)for(let o=1;o<e;o++){if(!r.raw[e*i+o])continue;let a=Math.min(t,o-1,e-1-o),u=Math.min(t,i-1,e-1-i),h=e*(i-u-1)+o,b=e*(i+u)+o,l=s[h-a-1],c=s[h+a],f=s[b-a-1],d=s[b+a],m=l+d-c-f,y=n[h-a-1],g=n[h+a],x=n[b-a-1],p=n[b+a],S=y+p-g-x;r.raw[i*e+o]=S/m}return r}function w(r){let t=r>>0&255,e=r>>8&255,n=r>>16&255,s=t.toString(16),i=e.toString(16),o=n.toString(16);return s=s.length===2?s:"0"+s,i=i.length===2?i:"0"+i,o=o.length===2?o:"0"+o,"#"+s+i+o}function v(r){if(r[0]==="#"){if(r.length===4)return+("0xff"+r[3]+r[3]+r[2]+r[2]+r[1]+r[1]);if(r.length===7)return+("0xff"+r[5]+r[6]+r[3]+r[4]+r[1]+r[2]);if(r.length===9)return+("0x"+r[7]+r[8]+r[5]+r[6]+r[3]+r[4]+r[1]+r[2])}return C("wrong color format",r),0}async function k(r,t){return(await fetch(r,t)).json()}function T(r,t="",e){var s;let n=document.createElement(r);return n.className=t,e&&((s=e.appendChild)==null||s.call(e,n)),n}function O(r,t,e){let n=r>>0&255,s=r>>8&255,i=r>>16&255,o=r>>>24,a=t>>0&255,u=t>>8&255,h=t>>16&255,b=t>>>24,l=n+e*(a-n),c=s+e*(u-s),f=i+e*(h-i),d=o+e*(b-o);return l|c<<8|f<<16|d<<24}function mt(r,t,e){let n=[];for(let s=0;s<e;++s)n.push(s*(t-r)/(e-1)+r);return n}function ut(r,t){return r.find(e=>new Date(e).getTime()>=t)||r[r.length-1]}var ft=!1;function zt(r){console.log(r?"Logging on":"Logging off"),ft=r}function C(...r){ft&&console.log(...r)}var St=Y(N());function Nt(r,t,e){return r>e?e:r<t?t:r}var R=class{constructor(t,e,[n,s],i){let o=s-n;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let a=[];this.DataToStyle=U(e,t.units,t.extraUnits),this.DataToStyle.trivial&&(t.units=e),i&&(this.DataToKnots=U(e,"knot"));let u=U(t.units,e,t.extraUnits),h=m=>~~(65535*Nt((u(m)-n)/(s-n),0,1));if(Array.isArray(t.colorMap)){t.colorMap.sort((m,y)=>m[0]<y[0]?-1:m[0]>y[0]?1:0);for(let[m]of t.colorMap)a.push(h(m))}else{if(t.levels||(t.levels=mt(this.DataToStyle(n),this.DataToStyle(s),10)),t.levels.sort((m,y)=>m<y?-1:m>y?1:0),!t.colors){let m=ot();t.colorScheme&&t.colorScheme in m?t.colors=m[t.colorScheme]:t.colors=m.wb}for(let m of t.levels)a.push(h(m))}let b=65536,l=H(b,t);this.ticks=l.ticks;let c=l.ticks[0].data,d=l.ticks[l.ticks.length-1].data-c;for(let m=0;m<65536;++m){let y=o*m/65535+n,g=this.DataToStyle(y),x=Math.round((b-1)*(g-c)/d);x<=0?this.colorsI[m]=t.showBelowMin?l.colors[0]:0:x>=b?this.colorsI[m]=t.showAboveMax?l.colors[b-1]:0:this.colorsI[m]=l.colors[x]}this.colorsI[0]=0;for(let m=0;m<a[0];++m)this.levelIndex[m]=0;for(let m=0;m<a.length-1;m++)for(let y=a[m];y<a[m+1]+1;++y)this.levelIndex[y]=m;for(let m=a[a.length-1];m<65536;++m)this.levelIndex[m]=a.length-1}};function ht(r){var e;if(r!==0&&-.1<r&&r<.1)return r.toExponential(2);let t=r.toString();return((e=t.split(".")[1])==null?void 0:e.length)>2?r.toFixed(2):t}function H(r,t){let e={size:r,showBelowMin:t.showBelowMin,showAboveMax:t.showAboveMax,units:t.units,colors:new Uint32Array(r),ticks:[]},{colorMap:n,levels:s,colors:i}=t,o=t.fill!=="solid";if(n){let c=n[0][0],f=n[n.length-1][0]-c;for(let[d,m]of n){let y=~~((d-c)/f*(r-1)),g={data:d,dataString:ht(d),color:m,pos:y};e.ticks.push(g)}for(let d=0;d<n.length-1;d++){let m=e.ticks[d].pos,y=e.ticks[d+1].pos,g=v(n[d][1]),x=o?v(n[d+1][1]):0;for(let p=m;p<y;++p)e.colors[p]=o?O(g,x,(p-m)/(y-m)):g}return e.colors[r-1]=v(n[n.length-1][1]),e}if(!i||!s)return e;let a=0,u=0,h=-1;for(let c=0;c<r;++c){let f=c*(i.length-1)/r;h!==~~f&&(h=~~f,a=v(i[h]),u=i.length>h+1?v(i[h+1]):a),e.colors[c]=o?O(a,u,f-h):a}e.colors[r-1]=v(i[i.length-1]);let b=s[0],l=(r-1)/(s[s.length-1]-b);for(let c of s){let f=~~((c-b)*l),d={data:c,dataString:ht(c),color:w(e.colors[f]),pos:f};e.ticks.push(d)}return e}var Q=256,Zt=2*Math.PI*6378137/Q,F=2*Math.PI*6378137/2;function Bt(r,t){let e=r/F*180,n=t/F*180;return n=180/Math.PI*(2*Math.atan(Math.exp(n*Math.PI/180))-Math.PI/2),[n,e]}function jt(r,t,e){let n=Ot(e),s=r*n-F,i=t*n-F;return[s,i]}function Ot(r){return Zt/Math.pow(2,r)}function G(r,t,e){let[n,s]=Bt(...jt(r,t,e));return[s,-n]}function dt(r,t){return[r*Q,t*Q]}var Ht="A".charCodeAt(0),K,M=0;async function Qt(r,t){let e;try{e=await(await fetch(r,t)).json()}catch(n){console.log("Can't load QTree:",n);return}K=A(e,{pos:0}),M=bt(K),console.log("Loaded QTree, depth:",M)}function A(r,t){let e=r.charCodeAt(t.pos)-Ht;t.pos++;let n=e&1?A(r,t):null,s=e&2?A(r,t):null,i=e&4?A(r,t):null,o=e&8?A(r,t):null;return{sub:n||s||i||o?[n,s,i,o]:null}}function bt(r){let t=0;if(r==null?void 0:r.sub){for(let e=0;e<4;e++)if(r.sub[e]!==null){let n=bt(r.sub[e])+1;t<n&&(t=n)}}return t}var L;(function(n){n.Land="land",n.Mixed="mixed",n.Sea="sea"})(L||(L={}));function gt(r){if(!M)return L.Mixed;let t=J({},r),e=!1;if(M<=r.z){e=!0;let n=r.z-M;t={x:r.x>>n,y:r.y>>n,z:M}}return xt(K,t,e)}function xt(r,t,e){if(r===null)return L.Land;if(e&&t.z===0)return L.Mixed;if(r.sub===null)return L.Sea;if(t.z===0)return L.Mixed;t.z--;let n=t.x>>t.z&1,i=(t.y>>t.z&1)<<1|n;return xt(r.sub[i],t,e)}function Gt(r,t){if(!t)return r;let e=.9999999/Math.pow(2,t.z),n=t.x*256*e,s=t.y*256*e,i={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:o}=i;for(let a=-1,u=0;a<=256;a++){let h=s+a*e,b=Math.floor(h),l=h-b;for(let c=-1;c<=256;c++,u++){let f=n+c*e,d=Math.floor(f),m=f-d,y=d+1+(b+1)*258,g=r.raw[y],x=r.raw[y+1],p=r.raw[y+258],S=r.raw[y+258+1];switch((g?1:0)|(x?2:0)|(p?4:0)|(S?8:0)){case 0:o[u]=0;continue;case 1:o[u]=g;continue;case 2:o[u]=x;continue;case 3:p=g,S=x;break;case 4:o[u]=p;continue;case 5:x=g,S=p;break;case 6:S=x+p>>1,g=S;break;case 7:S=x+p>>1;break;case 8:o[u]=S;continue;case 9:x=g+S>>1,p=x;break;case 10:g=x,p=S;break;case 11:p=g+S>>1;break;case 12:g=p,x=S;break;case 13:x=g+S>>1;break;case 14:g=x+p>>1;break}g=r.dmin+r.dmul*g,x=r.dmin+r.dmul*x,p=r.dmin+r.dmul*p,S=r.dmin+r.dmul*S;let I=q(g,x,m),D=q(p,S,m);o[u]=(q(I,D,l)-r.dmin)/r.dmul,o[u]===0&&(o[u]=1)}}return i}function q(r,t,e){let n=((t-r)%360+540)%360-180;return(r+n*e+360)%360}function Kt(r,t){if(!t)return r;let e=.9999999/Math.pow(2,t.z),n=t.x*256*e,s=t.y*256*e,i={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:o}=i;for(let a=-1,u=0;a<=256;a++){let h=s+a*e,b=Math.floor(h),l=h-b;for(let c=-1;c<=256;c++,u++){let f=n+c*e,d=Math.floor(f),m=f-d,y=d+1+(b+1)*258,g=r.raw[y],x=r.raw[y+1],p=r.raw[y+258],S=r.raw[y+258+1];switch((g?1:0)|(x?2:0)|(p?4:0)|(S?8:0)){case 7:o[u]=m+l<1?m*(x-g)+l*(p-g)+g:0;continue;case 14:o[u]=m+l<1?0:m*(S-p)+l*(S-x)+x+p-S;continue;case 11:o[u]=l<m?(1-m)*(g-x)+l*(S-x)+x:0;continue;case 13:o[u]=l<m?0:(1-m)*(p-S)+l*(p-g)+g+S-p;continue;case 15:o[u]=m+l<1?m*(x-g)+l*(p-g)+g:m*(S-p)+l*(S-x)+x+p-S;continue;default:o[u]=0}}}return i}function qt(r,t,e){let n=e==="land"?1:0;for(let s=3,i=0;i<256;i++)for(let o=0;o<256;o++,s+=4){let a=t.data[s]?1:0;n^a&&(r.raw[(i+1)*258+(o+1)]=0)}return r}function Vt(r){let[t,e]=dt(r.x,r.y),[n,s]=G(t,e,r.z),[i,o]=G(t+256,e+256,r.z);return{west:n,north:s,east:i,south:o}}function yt({layer:r,coords:t,done:e}){let n=T("div","leaflet-tile s-tile");return r.error?setTimeout(e):(n.wxtile=new pt({layer:r,coords:t,tileEl:n}),n.wxtile.load().then(s=>{s.draw(),e()})),n}var pt=class{constructor({layer:t,coords:e,tileEl:n}){this.data=[];this.sLines=[];this.imData=null;this.coords=e,this.layer=t,this.canvasFill=T("canvas","s-tile canvas-fill",n),this.canvasSlines=T("canvas","s-tile canvas-slines",n),this.canvasVector=this.canvasFill,this.canvasFill.width=this.canvasFill.height=this.canvasSlines.width=this.canvasSlines.height=256;function s(i){let o=i.getContext("2d");if(!o)throw"error";return o}this.canvasFillCtx=s(this.canvasFill),this.canvasSlinesCtx=s(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasSlinesCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVector(),this._drawDegree(),this._drawStaticSlines())}clearSLinesCanvas(){this.canvasSlinesCtx.clearRect(0,0,256,256)}drawSLines(t){if(this.sLines.length===0)return;let e=this.canvasSlinesCtx;if(e.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.sLines=[];return}let n=this.layer.style.streamLineColor.substr(0,7);t=t>>7;for(let s=0;s<this.sLines.length;++s){let i=this.sLines[s],o=i.length-1,a=(t+(1+i[0].x)*(1+i[0].y))%30;for(let u=0;u<o;++u){let h=i[u],b=i[u+1],l=1-(a-u)/o;(l<0||l>1)&&(l=0);let c=(~~(l*255)).toString(16);e.strokeStyle=n+(c.length<2?"0"+c:c);let f=1+~~((1.2-l)*5);e.lineWidth=f,e.beginPath(),e.moveTo(h.x,h.y),e.lineTo(b.x,b.y),e.stroke()}}}getData({x:t,y:e}){if(!this.data.length)return;let n=this.data[0].raw[(e+1)*258+(t+1)];return{raw:n,data:this.data[0].dmin+this.data[0].dmul*n}}async load(){var l;this.data=[],this.imData=null,this.sLines=[];let{coords:t,layer:e}=this,{boundaries:n}=e.state.meta,s=this.layer.style.mask;var i;if((s==="land"||s==="sea")&&(i=gt(t),s===i))return this;if(n==null?void 0:n.boundaries180){let c=Vt(t),f=d=>!(c.west>d.east||d.west>c.east||c.south>d.north||d.south>c.north);if(!n.boundaries180.some(f))return this}let{upCoords:o,subCoords:a}=this._splitCoords(t),u=this._coordsToURLs(o),h;try{h=await Promise.all(u.map(e.loadData))}catch(c){return this}let b=((l=e.state)==null?void 0:l.units)==="degree"?Gt:Kt;if(this.data=h.map(c=>b(ct(c,this.layer.style.blurRadius),a)),this.imData=this.canvasFillCtx.createImageData(256,256),this.layer.vector&&this._vectorPrepare(),s&&i===L.Mixed){let c=e.state.maskServerURI.replace("{z}",String(t.z)).replace("{x}",String(t.x)).replace("{y}",String(t.y));try{let f=await e.loadMask(c);qt(this.data[0],f,s)}catch(f){this.layer.style.mask=void 0,C("Can't load Mask. Turned off")}}return this.layer.vector&&this._createSLines(),this}_splitCoords(t){let e=t.z-this.layer.state.meta.maxZoom;if(e<=0)return{upCoords:t};let n={x:t.x>>>e,y:t.y>>>e,z:this.layer.state.meta.maxZoom},s={x:t.x&(1<<e)-1,y:t.y&(1<<e)-1,z:e};return{upCoords:n,subCoords:s}}_coordsToURLs(t){let e=this.layer.state.baseURL.replace("{z}",String(t.z)).replace("{x}",String(t.x)).replace("{y}",String(t.y));return this.layer.dataSource.variables.map(n=>e.replace("{var}",n))}_vectorPrepare(){if(this.data.length!==2)throw"this.data !== 2";this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[t,e,n]=this.data;t.dmax=1.42*Math.max(-e.dmin,e.dmax,-n.dmin,n.dmax),t.dmul=(t.dmax-t.dmin)/65535;for(let s=0;s<258*258;++s){if(!e.raw[s]||!n.raw[s]){t.raw[s]=0;continue}let i=e.dmin+e.dmul*e.raw[s],o=n.dmin+n.dmul*n.raw[s];t.raw[s]=Math.sqrt(o*o+i*i)/t.dmul}}_drawFillAndIsolines(){let{imData:t}=this;if(!t)throw"_drawFillAndIsolines: !imData";let{canvasFillCtx:e}=this,n=new Uint32Array(t.data.buffer),{raw:s}=this.data[0],{clut:i,style:o}=this.layer,{levelIndex:a,colorsI:u}=i;if(o.fill!=="none"){let b=u;for(let l=0,c=0,f=259;l<256;++l,f+=2)for(let d=0;d<256;++d,++c,++f)n[c]=b[s[f]]}else n.fill(0);let h=[];if(o.isolineColor!=="none"){let b=o.isolineColor[0]==="#"?v(o.isolineColor):0;for(let l=0,c=0;l<256;l+=1)for(let f=0;f<256;f+=1){let d=(l+1)*258+(f+1),m=s[d],y=s[d+1],g=s[d+258];if(!m||!y||!g)continue;let x=a[m],p=a[y],S=a[g];if(x!==p||x!==S){let z=Math.max(x,p,S),I=Math.max(m,y,g),D=l*256+f;switch(o.isolineColor){case"inverted":n[D]=~u[I]|4278190080;break;case"fill":n[D]=u[I]|4278190080;break;default:n[D]=b;break}o.isolineText&&!(++c%255)&&f>20&&f<235&&l>20&&l<235&&h.push({x:f,y:l,d:m,dr:y,db:g,mli:z})}}}if(e.putImageData(t,0,0),!h.length){e.font="1.1em Sans-serif",e.lineWidth=2,e.strokeStyle="white",e.fillStyle="black",e.textAlign="center",e.textBaseline="middle";for(let{x:b,y:l,d:c,dr:f,db:d,mli:m}of h){let y=this.layer.clut.ticks[m].dataString,g=Math.atan2(c-f,d-c);e.save(),e.translate(b,l),e.rotate(g<-1.57||g>1.57?g+3.14:g),e.strokeText(y,0,0),e.fillText(y,0,0),e.restore()}}}_drawStaticSlines(){if(!this.sLines.length||!this.layer.style.streamLineStatic)return;let{canvasSlinesCtx:t}=this;if(this.layer.style.streamLineColor==="none"){this.sLines=[];return}t.lineWidth=2,t.strokeStyle=this.layer.style.streamLineColor,t.beginPath();for(let e=this.sLines.length;e--;){let n=this.sLines[e];for(let s=0;s<n.length-1;++s){let i=n[s],o=n[s+1];t.moveTo(i.x,i.y),t.lineTo(o.x,o.y)}}t.stroke()}_drawVector(){if(!this.layer.vector||!this.layer.clut.DataToKnots||!this.layer.style.vectorColor||this.layer.style.vectorColor==="none"||!this.layer.style.vectorType||this.layer.style.vectorType==="none")return;if(this.data.length!==3)throw"this.data.length !== 3";let[t,e,n]=this.data,{canvasVectorCtx:s}=this;switch(this.layer.style.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=this.layer.style.vectorType}s.textAlign="center",s.textBaseline="middle";let i=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0,o=32;for(let a=o/2;a<256;a+=o)for(let u=o/2;u<256;u+=o){let h=u+1+(a+1)*258;if(!t.raw[h])continue;let b=Math.atan2(e.dmin+e.raw[h]*e.dmul,n.dmin+n.raw[h]*n.dmul),l=t.dmin+t.raw[h]*t.dmul,c=this.layer.dataSource.variables[0].includes("current")?5:.2,f=Math.min(this.layer.clut.DataToKnots(l)*c,25)+65,d=String.fromCharCode(f);switch(this.layer.style.vectorColor){case"inverted":s.fillStyle=w(~this.layer.clut.colorsI[t.raw[h]]);break;case"fill":s.fillStyle=w(this.layer.clut.colorsI[t.raw[h]]);break;default:s.fillStyle=this.layer.style.vectorColor;break}s.save(),s.translate(u,a),s.rotate(b+i),s.fillText(d,0,0),s.restore()}}_drawDegree(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:t}=this,e=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0;t.font="50px arrows",t.textAlign="center",t.textBaseline="middle";let n=this.data[0],s="L",i=32;for(let o=i/2;o<256;o+=i)for(let a=i/2;a<256;a+=i){let u=a+1+(o+1)*258;if(!n.raw[u])continue;let b=(n.dmin+n.raw[u]*n.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":t.fillStyle=w(~this.layer.clut.colorsI[n.raw[u]]);break;case"fill":t.fillStyle=w(this.layer.clut.colorsI[n.raw[u]]);break;default:t.fillStyle=this.layer.style.vectorColor;break}t.save(),t.translate(a,o),t.rotate(b+e),t.fillText(s,0,0),t.restore()}}_createSLines(){if(this.data.length!==3)throw"this.data.length !== 3";if(!this.layer.style.streamLineColor||this.layer.style.streamLineColor==="none")return;let t=this.layer.style.streamLineSpeedFactor||1;this.sLines=[];let[e,n,s]=this.data,i=Math.max(this.coords.z-this.layer.state.meta.maxZoom,0),o=Math.min(2**(i+5),128),a=~~(120+i*60);for(let u=0;u<=256;u+=o)for(let h=0;h<=256;h+=o){if(!e.raw[1+h+(1+u)*258])continue;let b=[],l=h,c=u;for(let f=0;f<=a&&l>=0&&l<=256&&c>=0&&c<=256;f++){!(f%(a/6))&&b.push({x:~~l,y:~~c});let d=~~l+1+(~~c+1)*258;if(!e.raw[d])break;l+=t*(n.dmin+n.raw[d]*n.dmul)/e.dmax,c-=t*(s.dmin+s.raw[d]*s.dmul)/e.dmax}l=h,c=u;for(let f=1;f<=a&&l>=0&&l<=256&&c>=0&&c<=256;f++){!(f%(a/6))&&b.unshift({x:~~l,y:~~c});let d=~~l+1+(~~c+1)*258;if(!e.raw[d])break;l-=t*(n.dmin+n.raw[d]*n.dmul)/e.dmax,c+=t*(s.dmin+s.raw[d]*s.dmul)/e.dmax}b.length>2&&this.sLines.push(b)}}};var Ct="setup not complete",W=class extends St.default.GridLayer{constructor({dataSource:t,options:e={},lazy:n=!0}){super(e);this.wxtiles=new Map;this.styles=B();this.style=Object.assign({},this.styles.base);this.loadData=j();this.loadMask=lt(new AbortController);this.error=Ct;this.vector=!1;this.clut=new R(this.style,"",[0,2],!1);this.animation=!1;this.animationRedrawID=0;this.animFrame=0;this.oldMaxZoom=0;if(C("Creating a WxTilex layer:"+JSON.stringify({dataSource:t,options:e})),!t||!t.ext||!t.dataset||!t.name||!t.serverURI||!t.styleName||!Array.isArray(t.variables))throw C("dataSource is wrong!"),"dataSource is wrong!";this.dataSource=t,this.state={maskServerURI:t.maskServerURI||t.serverURI.replace(/\/data\/?/i,"/mask/{z}/{x}/{y}"),units:"undefined",baseURL:"undefined",meta:{maxZoom:0,times:["undefined"],variables:["undefined"],variablesMeta:{}},instance:"undefined",minmax:[[0,1]],originURI:"undefined",time:"undefined"};let s=()=>{C("Setup:",t.name),this.setupCompletePromise=this._setUpDataSet(t),this.setupCompletePromise.then(()=>{C("Setup complete:",this.dataSource.name);let i=a=>{this.wxtiles.set(`${a.coords.x}:${a.coords.y}:${a.coords.z}`,a.tile.wxtile)};this.on("tileload",i);let o=a=>{this.wxtiles.delete(`${a.coords.x}:${a.coords.y}:${a.coords.z}`)};this.on("tileunload",o),this.on("add",this._onAddLayer,this),this._map&&this._onAddLayer(),this.fire("setupcomplete",{layer:this})})};n?this.once("add",s):s(),this.on("remove",this._onRemoveLayer,this)}createTile(t,e){return this.error&&this.error!==Ct?(setTimeout(e),Object.assign(T("div","error-tile"),{innerHTML:this.error})):yt({layer:this,coords:t,done:e})}getSetupCompletePromise(){return this.setupCompletePromise}getTile(t){if(!this._map||this.error)return;let e=this._map.getZoom(),{x:n,y:s}=this._map.project(t,e),i={x:~~(n/256),y:~~(s/256)},o=this.wxtiles.get(`${i.x}:${i.y}:${e}`);if(!o)return;let a={x:~~(n-i.x*256),y:~~(s-i.y*256)},u=o.getData(a);if(!u)return;let{raw:h,data:b}=u,l=this.clut.colorsI[h],c=w(l),f=this.clut.DataToStyle(b);return{tile:o,data:b,raw:h,rgba:l,hexColor:c,inStyleUnits:f,tilePoint:a,units:this.style.units}}setStyle(t){if(this.error){C("setStyle: failed: "+this.error);return}if(!(this.dataSource.styleName===t&&t!=="custom")){if(t&&(this.dataSource.styleName=t),t==="custom"&&this.styles.custom){(!this.styles.custom.parent||!(this.styles.custom.parent in this.styles))&&(this.styles.custom.parent="base");let e=this.styles[this.styles.custom.parent];this.styles.custom=Object.assign(Object.assign({},e),this.styles.custom)}this.dataSource.styleName in this.styles?Array.isArray(this.styles[this.dataSource.styleName])&&(this.dataSource.styleName+="[0]"):(C(`cant find the style (${this.dataSource.styleName})`),this.dataSource.styleName+="[0]",this.dataSource.styleName in this.styles||(C(`cant find the style (${this.dataSource.styleName}), default is used`),this.dataSource.styleName="base"));try{let e=this.styles[this.dataSource.styleName];this.style=Object.assign({},e);let n=this.style.streamLineColor;n!=="none"&&n.length<7&&(this.style.streamLineColor="#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]);let s=this.state.minmax[0];this.clut=new R(this.style,this.state.units,s,this.vector)}catch(e){let n="setStyle: impossible error in RawCLUT: "+e;throw C(n),n}t&&(this._checkAndStartSlinesAnimation(),this._reloadTiles()),C('setStyle: "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete."),this.fire("setstyle",{layer:this})}}getStyle(){return this.dataSource.styleName}getStyleName(){return this.style.name}setTime(t){if(this.error)return C("setTime: failed: "+this.error),Promise.resolve([]);let e=ut(this.state.meta.times,t);if(this.state.time!==e){this.state.time=e,this.state.baseURL=this.state.originURI+this.state.instance+`{var}/${this.state.time}/{z}/{x}/{y}.${this.dataSource.ext}`,this.fire("settime",{layer:this,layerTime:e}),C("setTime: "+e+" for "+this.dataSource.name+" complete.");let n=this._reloadTiles();return n.then(()=>{let s=this.wxtiles.values().next().value;if(!(s==null?void 0:s.data.length))return;let[i,o]=this.state.minmax[0],{dmin:a,dmax:u}=s.data[0];(Math.abs(a-i)>.01||Math.abs(u-o)>.01)&&(this.state.minmax=s.data.map(h=>[h.dmin,h.dmax]),this._updateMinMax(),this.setStyle(void 0))}),n}return Promise.resolve([])}getTime(){return this.error?(C("getTime: failed: "+this.error),this.error):this.state.time}getTimes(){return this.error?(C("getTimes: failed: "+this.error),[]):this.state.meta.times}async checkDataChanged(){if(this.error)return C("checkDataChanged: failed: "+this.error),!1;let t=await k(this.state.originURI+"instances.json"),e=t[t.length-1]+"/";if(this.state.instance!==e)return!0;let n=await k(this.state.originURI+e+"meta.json");return this.state.meta.times.toString()!==n.times.toString()}reloadData(){return this._setUpDataSet(void 0)}getLegendData(t){if(!this.error){if(!this.clut){C("getLegendData: failed. Lazy setup not finished yet:"+this.dataSource.name);return}return H(t,this.style)}}setTimeAnimationMode(t=2){this.oldMaxZoom=this.state.meta.maxZoom;let e=this._map.getZoom(),s=(e<this.oldMaxZoom?e:this.oldMaxZoom)-t;this.state.meta.maxZoom=s<0?0:s}unsetTimeAnimationMode(){!this.oldMaxZoom||!this.state.meta.maxZoom||(this.state.meta.maxZoom=this.oldMaxZoom,this._reloadTiles())}getMinMax(){let[t,e]=this.state.minmax[0];return{min:t,max:e}}setAnimation(t){return t&&(this.animation=t,this._checkAndStartSlinesAnimation()),this.animation}async _setUpDataSet(t){t&&(this.dataSource=t),this._stopLoadingResetLoadDataFunc(),this.state.originURI=this.dataSource.serverURI+"/"+this.dataSource.dataset+"/";try{let e=await k(this.state.originURI+"instances.json");this.state.instance=e[e.length-1]+"/"}catch(e){return this.error=this.dataSource.name+": load instances.json error: "+e,C(this.error),!1}try{let e=this.state.originURI+this.state.instance+"meta.json";this.state.meta=await k(e)}catch(e){return this.error=this.dataSource.name+": load meta.json error: "+e,C(this.error),!1}return this.vector=this.dataSource.variables.length===2,this.animation=this.vector,this.state.units=this.state.meta.variablesMeta[this.dataSource.variables[0]].units,this.state.minmax=this.dataSource.variables.map(e=>[this.state.meta.variablesMeta[e].min,this.state.meta.variablesMeta[e].max]),this._updateMinMax(),this.error=null,t&&(this.setTime(Date.now()),this.setStyle(void 0)),!0}_updateMinMax(){if(!this.vector)return;let[[t,e],[n,s]]=this.state.minmax;this.state.minmax.unshift([0,1.42*Math.max(-t,e,-n,s)])}_checkZoom(){var t;((t=this._map)==null?void 0:t.getZoom())>this.state.meta.maxZoom||this._stopLoadingResetLoadDataFunc()}_onAddLayer(){var t,e;C("onadd:",this.dataSource.name),(t=this._map)==null||t.on("zoomstart",this._checkZoom,this),(e=this.setupCompletePromise)==null||e.then(()=>{this.redraw(),this._checkAndStartSlinesAnimation()})}_onRemoveLayer(){var t,e;C("onremove:",this.dataSource.name),(t=this._map)==null||t.off("zoomstart",this._checkZoom,this),(e=this.setupCompletePromise)==null||e.then(()=>{this._stopLoadingResetLoadDataFunc(),this._stopSlinesAnimation()})}_stopLoadingResetLoadDataFunc(){var t;(t=this.loadData)==null||t.abort(),this.loadData=j()}_checkAndStartSlinesAnimation(){if(this.animFrame||!this.animation||!this.vector||!this.style.streamLineColor||this.style.streamLineColor==="none")return;let t=e=>{if(!this.animation||this.style.streamLineStatic){this._stopSlinesAnimation();return}this.wxtiles.forEach(n=>n.drawSLines(e)),this.animFrame=requestAnimationFrame(t)};t(0)}_stopSlinesAnimation(){cancelAnimationFrame(this.animFrame),this.wxtiles.forEach(t=>t.clearSLinesCanvas()),this.animFrame=0}_redrawTiles(){!this.wxtiles||this.animationRedrawID!==0||(this.animationRedrawID=requestAnimationFrame(()=>{this.wxtiles.forEach(t=>t.draw()),this.animationRedrawID=0}))}_reloadTiles(){let t=Array.from(this.wxtiles.values()).map(n=>n.load()),e=Promise.all(t);return e.then(()=>this._redrawTiles()),e}};function $t(r){return new W(r)}var wt=class extends E.default.Control{constructor(t){super(t);this.URI=t.URI}onAdd(){let t=document.createElement("img");return t.src=this.URI,t.className="wxtiles-logo",t}};function _e(r){return C("Add watermark:",JSON.stringify(r)),new wt(r)}var vt=class extends E.default.GridLayer{createTile(t){let e=document.createElement("div");return e.innerHTML=[t.x,t.y,t.z].join(", "),e.style.outline="1px solid red",e}};function Pe(){return C("Add WxDebugCoordsLayer:"),new vt().setZIndex(1e3)}function Ue(r,t){return E.default.layerGroup(r.map($t),t)}export{Pe as CreateWxDebugCoordsLayer,Ue as CreateWxTilesGroupLayer,$t as CreateWxTilesLayer,_e as CreateWxTilesWatermark,Qt as LoadQTree,vt as WxDebugLayer,B as WxGetColorStyles,W as WxTilesLayer,Pt as WxTilesLibSetup,zt as WxTilesLogging,wt as WxWatermark};
|
|
1
|
+
var ve=Object.create;var _=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames,V=Object.getOwnPropertySymbols,Me=Object.getPrototypeOf,X=Object.prototype.hasOwnProperty,ke=Object.prototype.propertyIsEnumerable;var $=(r,e,t)=>e in r?_(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,J=(r,e)=>{for(var t in e||(e={}))X.call(e,t)&&$(r,t,e[t]);if(V)for(var t of V(e))ke.call(e,t)&&$(r,t,e[t]);return r};var Ae=r=>_(r,"__esModule",{value:!0});var Je=typeof require!="undefined"?require:r=>{throw new Error('Dynamic require of "'+r+'" is not supported')};var Ie=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var _e=(r,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of De(e))!X.call(r,n)&&n!=="default"&&_(r,n,{get:()=>e[n],enumerable:!(t=Le(e,n))||t.enumerable});return r},Y=r=>_e(Ae(_(r!=null?ve(Me(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var B=Ie((rt,ee)=>{ee.exports=window.L});var E=Y(B());var te={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 re={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 R={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"}};var N,ne,se;function Re({colorStyles:r={},units:e={},colorSchemes:t={}}={}){g("WxTile lib setup: start"),N=Object.assign({},te,e),ne=Object.assign({},t,re);let n=Object.assign({},r,R);se=Ue(n),g("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),g("WxTile lib setup is done.")}function Z(){return se}function oe(){return ne}function U(r,e,t){let n=t?Object.assign({},N,t):N;if(!n||!r||!e||r===e||!n[r]||!n[e]||n[r][0]!==n[e][0]){g(r===e?"Trivial converter:":"Inconvertible units. Default converter is used:",r," -> ",e);let o=l=>l;return o.trivial=!0,o}g("Converter: From:",r," To:",e);let s=n[r][1]/n[e][1],i=(n[r][2]||0)/n[e][1]-(n[e][2]||0)/n[e][1];return i?o=>s*o+i:o=>s*o}function Ue(r){let e=Object.assign({},R);for(let s in r){let i=r[s];if(Array.isArray(i))for(let o=0;o<i.length;++o)e[s+"["+o+"]"]=Object.assign({},i[o]);else e[s]=Object.assign({},i)}let t=(s,i)=>{if(i==="base")return R.base;let o=s[i];(!o.parent||!(o.parent in s))&&(o.parent="base");let l=t(s,o.parent);return Object.assign(o,Object.assign({},l,o,{parent:"base"}))},n={};for(let s in e)n[s]=t(e,s);return n}function ie(r){let e=new Map;return t=>{let n=e.get(t);return n===void 0&&(n=r(t),e.set(t,n),n instanceof Promise&&n.catch(s=>{s instanceof DOMException&&e.delete(t)})),n}}async function Pe(r,e){let{signal:t}=e.controller;var n;let s=await(await fetch(r,{signal:t})).blob(),i=new Image;if(!t.aborted){let o=URL.createObjectURL(s);i.src=o,await i.decode(),URL.revokeObjectURL(o)}return i}function We(r){let{width:e,height:t}=r,n=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d");if(!n)throw"catastrophe";return n.drawImage(r,0,0),n.getImageData(0,0,e,t)}async function ae(r,e){return We(await Pe(r,e))}function Fe(r,e){let t=n=>{let s=new Uint16Array(n.data.buffer),i=new Uint16Array(s.length/2);for(let a=0;a<i.length;a++)i[a]=s[a*2];let o=new Uint8Array(n.data.buffer);for(let a=0;a<8;++a)o[a]=o[a*4+2];let l=new DataView(n.data.buffer),u=l.getFloat32(0,!0),f=l.getFloat32(4,!0),b=(f-u)/65535,c=Ee(i);return{raw:i,dmin:u,dmax:f,dmul:b,integral:c,radius:0}};return ae(r,e).then(t)}function j(){let r={controller:new AbortController},e=ie(t=>Fe(t,r));return e.controllerHolder=r,e}function le(r){let e={controller:r},t=ie(n=>ae(n,e));return t.controllerHolder=e,t}function Ee(r){let e=new Uint32Array(258*258),t=new Uint32Array(258*258);e[0]=r[0],t[0]=r[0]===0?0:1;for(let n=1;n<258;++n)e[n]=r[n]+e[n-1],e[258*n]=r[258*n]+e[258*n-258],t[n]=(r[n]===0?0:1)+t[n-1],t[258*n]=(r[258*n]===0?0:1)+t[258*n-258];for(let n=1,s=259;n<258;++n,++s)for(let i=1;i<258;++i,++s)e[s]=r[s]+e[s-258]+e[s-1]-e[s-258-1],t[s]=(r[s]===0?0:1)+t[s-258]+t[s-1]-t[s-258-1];return{integral:e,integralNZ:t}}function ce(r,e){if(e<0||e===r.radius)return r;r.radius=e;let t=258,{integral:n,integralNZ:s}=r.integral;for(let i=1;i<t;i++)for(let o=1;o<t;o++){if(!r.raw[t*i+o])continue;let l=Math.min(e,o-1,t-1-o),u=Math.min(e,i-1,t-1-i),f=t*(i-u-1)+o,b=t*(i+u)+o,c=s[f-l-1],a=s[f+l],d=s[b-l-1],h=s[b+l],m=c+h-a-d,p=n[f-l-1],x=n[f+l],y=n[b-l-1],S=n[b+l],C=p+S-x-y;r.raw[i*t+o]=C/m}return r}function w(r){let e=r>>0&255,t=r>>8&255,n=r>>16&255,s=e.toString(16),i=t.toString(16),o=n.toString(16);return s=s.length===2?s:"0"+s,i=i.length===2?i:"0"+i,o=o.length===2?o:"0"+o,"#"+s+i+o}function T(r){if(r[0]==="#"){if(r.length===4)return+("0xff"+r[3]+r[3]+r[2]+r[2]+r[1]+r[1]);if(r.length===7)return+("0xff"+r[5]+r[6]+r[3]+r[4]+r[1]+r[2]);if(r.length===9)return+("0x"+r[7]+r[8]+r[5]+r[6]+r[3]+r[4]+r[1]+r[2])}return g("wrong color format",r),0}async function k(r,e){return(await fetch(r,e)).json()}function L(r,e="",t){var s;let n=document.createElement(r);return n.className=e,t&&((s=t.appendChild)==null||s.call(t,n)),n}function O(r,e,t){let n=r>>0&255,s=r>>8&255,i=r>>16&255,o=r>>>24,l=e>>0&255,u=e>>8&255,f=e>>16&255,b=e>>>24,c=n+t*(l-n),a=s+t*(u-s),d=i+t*(f-i),h=o+t*(b-o);return c|a<<8|d<<16|h<<24}function me(r,e,t){let n=[];for(let s=0;s<t;++s)n.push(s*(e-r)/(t-1)+r);return n}function ue(r,e){let t=typeof e=="number"?e:typeof e=="string"?new Date(e).getTime():e.getTime();return r.find(n=>new Date(n).getTime()>=t)||r[r.length-1]}var fe=!1;function He(r){console.log(r?"Logging on":"Logging off"),fe=r}function g(...r){fe&&console.trace(...r)}var Se=Y(B());function Be(r,e,t){return r>t?t:r<e?e:r}var P=class{constructor(e,t,[n,s],i){let o=s-n;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let l=[];this.DataToStyle=U(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),i&&(this.DataToKnots=U(t,"knot"));let u=U(e.units,t,e.extraUnits),f=m=>~~(65535*Be((u(m)-n)/(s-n),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((m,p)=>m[0]<p[0]?-1:m[0]>p[0]?1:0);for(let[m]of e.colorMap)l.push(f(m))}else{if(e.levels||(e.levels=me(this.DataToStyle(n),this.DataToStyle(s),10)),e.levels.sort((m,p)=>m<p?-1:m>p?1:0),!e.colors){let m=oe();e.colorScheme&&e.colorScheme in m?e.colors=m[e.colorScheme]:e.colors=m.wb}for(let m of e.levels)l.push(f(m))}let b=65536,c=z(b,e);this.ticks=c.ticks;let a=c.ticks[0].data,h=c.ticks[c.ticks.length-1].data-a;for(let m=0;m<65536;++m){let p=o*m/65535+n,x=this.DataToStyle(p),y=Math.round((b-1)*(x-a)/h);y<=0?this.colorsI[m]=e.showBelowMin?c.colors[0]:0:y>=b?this.colorsI[m]=e.showAboveMax?c.colors[b-1]:0:this.colorsI[m]=c.colors[y]}this.colorsI[0]=0;for(let m=0;m<l[0];++m)this.levelIndex[m]=0;for(let m=0;m<l.length-1;m++)for(let p=l[m];p<l[m+1]+1;++p)this.levelIndex[p]=m;for(let m=l[l.length-1];m<65536;++m)this.levelIndex[m]=l.length-1}};function de(r){var t;if(r!==0&&-.1<r&&r<.1)return r.toExponential(2);let e=r.toString();return((t=e.split(".")[1])==null?void 0:t.length)>2?r.toFixed(2):e}function z(r,e){let t={size:r,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(r),ticks:[]},{colorMap:n,levels:s,colors:i}=e,o=e.fill!=="solid";if(n){let a=n[0][0],d=n[n.length-1][0]-a;for(let[h,m]of n){let p=~~((h-a)/d*(r-1)),x={data:h,dataString:de(h),color:m,pos:p};t.ticks.push(x)}for(let h=0;h<n.length-1;h++){let m=t.ticks[h].pos,p=t.ticks[h+1].pos,x=T(n[h][1]),y=o?T(n[h+1][1]):0;for(let S=m;S<p;++S)t.colors[S]=o?O(x,y,(S-m)/(p-m)):x}return t.colors[r-1]=T(n[n.length-1][1]),t}if(!i||!s)return t;let l=0,u=0,f=-1;for(let a=0;a<r;++a){let d=a*(i.length-1)/r;f!==~~d&&(f=~~d,l=T(i[f]),u=i.length>f+1?T(i[f+1]):l),t.colors[a]=o?O(l,u,d-f):l}t.colors[r-1]=T(i[i.length-1]);let b=s[0],c=(r-1)/(s[s.length-1]-b);for(let a of s){let d=~~((a-b)*c),h={data:a,dataString:de(a),color:w(t.colors[d]),pos:d};t.ticks.push(h)}return t}var Q=256,Ne=2*Math.PI*6378137/Q,W=2*Math.PI*6378137/2;function Ze(r,e){let t=r/W*180,n=e/W*180;return n=180/Math.PI*(2*Math.atan(Math.exp(n*Math.PI/180))-Math.PI/2),[n,t]}function je(r,e,t){let n=Oe(t),s=r*n-W,i=e*n-W;return[s,i]}function Oe(r){return Ne/Math.pow(2,r)}function G(r,e,t){let[n,s]=Ze(...je(r,e,t));return[s,-n]}function he(r,e){return[r*Q,e*Q]}var ze="A".charCodeAt(0),q,D=0;async function Qe(r,e){let t;try{t=await(await fetch(r,e)).json()}catch(n){console.log("Can't load QTree:",n);return}q=A(t,{pos:0}),D=be(q),console.log("Loaded QTree, depth:",D)}function A(r,e){let t=r.charCodeAt(e.pos)-ze;e.pos++;let n=t&1?A(r,e):null,s=t&2?A(r,e):null,i=t&4?A(r,e):null,o=t&8?A(r,e):null;return{sub:n||s||i||o?[n,s,i,o]:null}}function be(r){let e=0;if(r==null?void 0:r.sub){for(let t=0;t<4;t++)if(r.sub[t]!==null){let n=be(r.sub[t])+1;e<n&&(e=n)}}return e}var v;(function(n){n.Land="land",n.Mixed="mixed",n.Sea="sea"})(v||(v={}));function ge(r){if(!D)return v.Mixed;let e=J({},r),t=!1;if(D<=r.z){t=!0;let n=r.z-D;e={x:r.x>>n,y:r.y>>n,z:D}}return xe(q,e,t)}function xe(r,e,t){if(r===null)return v.Land;if(t&&e.z===0)return v.Mixed;if(r.sub===null)return v.Sea;if(e.z===0)return v.Mixed;e.z--;let n=e.x>>e.z&1,i=(e.y>>e.z&1)<<1|n;return xe(r.sub[i],e,t)}function Ge(r,e){if(!e)return r;let t=.9999999/Math.pow(2,e.z),n=e.x*256*t,s=e.y*256*t,i={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:o}=i;for(let l=-1,u=0;l<=256;l++){let f=s+l*t,b=Math.floor(f),c=f-b;for(let a=-1;a<=256;a++,u++){let d=n+a*t,h=Math.floor(d),m=d-h,p=h+1+(b+1)*258,x=r.raw[p],y=r.raw[p+1],S=r.raw[p+258],C=r.raw[p+258+1];switch((x?1:0)|(y?2:0)|(S?4:0)|(C?8:0)){case 0:o[u]=0;continue;case 1:o[u]=x;continue;case 2:o[u]=y;continue;case 3:S=x,C=y;break;case 4:o[u]=S;continue;case 5:y=x,C=S;break;case 6:C=y+S>>1,x=C;break;case 7:C=y+S>>1;break;case 8:o[u]=C;continue;case 9:y=x+C>>1,S=y;break;case 10:x=y,S=C;break;case 11:S=x+C>>1;break;case 12:x=S,y=C;break;case 13:y=x+C>>1;break;case 14:x=y+S>>1;break}x=r.dmin+r.dmul*x,y=r.dmin+r.dmul*y,S=r.dmin+r.dmul*S,C=r.dmin+r.dmul*C;let I=K(x,y,m),M=K(S,C,m);o[u]=(K(I,M,c)-r.dmin)/r.dmul,o[u]===0&&(o[u]=1)}}return i}function K(r,e,t){let n=((e-r)%360+540)%360-180;return(r+n*t+360)%360}function qe(r,e){if(!e)return r;let t=.9999999/Math.pow(2,e.z),n=e.x*256*t,s=e.y*256*t,i={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:o}=i;for(let l=-1,u=0;l<=256;l++){let f=s+l*t,b=Math.floor(f),c=f-b;for(let a=-1;a<=256;a++,u++){let d=n+a*t,h=Math.floor(d),m=d-h,p=h+1+(b+1)*258,x=r.raw[p],y=r.raw[p+1],S=r.raw[p+258],C=r.raw[p+258+1];switch((x?1:0)|(y?2:0)|(S?4:0)|(C?8:0)){case 7:o[u]=m+c<1?m*(y-x)+c*(S-x)+x:0;continue;case 14:o[u]=m+c<1?0:m*(C-S)+c*(C-y)+y+S-C;continue;case 11:o[u]=c<m?(1-m)*(x-y)+c*(C-y)+y:0;continue;case 13:o[u]=c<m?0:(1-m)*(S-C)+c*(S-x)+x+C-S;continue;case 15:o[u]=m+c<1?m*(y-x)+c*(S-x)+x:m*(C-S)+c*(C-y)+y+S-C;continue;default:o[u]=0}}}return i}function Ke(r,e,t){let n=t==="land"?1:0;for(let s=3,i=0;i<256;i++)for(let o=0;o<256;o++,s+=4){let l=e.data[s]?1:0;n^l&&(r.raw[(i+1)*258+(o+1)]=0)}return r}function Ve(r){let[e,t]=he(r.x,r.y),[n,s]=G(e,t,r.z),[i,o]=G(e+256,t+256,r.z);return{west:n,north:s,east:i,south:o}}function ye({layer:r,coords:e,done:t}){let n=L("div","leaflet-tile s-tile");return n.wxtile=new pe({layer:r,coords:e,tileEl:n}),n.wxtile.load().then(s=>{s.draw(),t()}),n}var pe=class{constructor({layer:e,coords:t,tileEl:n}){this.data=[];this.sLines=[];this.coords=t,this.layer=e,this.canvasFill=L("canvas","s-tile canvas-fill",n),this.canvasSlines=L("canvas","s-tile canvas-slines",n),this.canvasVector=this.canvasFill,this.canvasFill.width=this.canvasFill.height=this.canvasSlines.width=this.canvasSlines.height=256;function s(i){let o=i.getContext("2d");if(!o)throw"error";return o}this.canvasFillCtx=s(this.canvasFill),this.imData=this.canvasFillCtx.createImageData(256,256),this.canvasSlinesCtx=s(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasSlinesCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVector(),this._drawDegree(),this._drawStaticSlines())}clearSLinesCanvas(){this.canvasSlinesCtx.clearRect(0,0,256,256)}drawSLines(e){if(this.sLines.length===0)return;let t=this.canvasSlinesCtx;if(t.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.sLines=[];return}let n=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let s=0;s<this.sLines.length;++s){let i=this.sLines[s],o=i.length-1,l=(e+(1+i[0].x)*(1+i[0].y))%30;for(let u=0;u<o;++u){let f=i[u],b=i[u+1],c=1-(l-u)/o;(c<0||c>1)&&(c=0);let a=(~~(c*255)).toString(16);t.strokeStyle=n+(a.length<2?"0"+a:a);let d=1+~~((1.2-c)*5);t.lineWidth=d,t.beginPath(),t.moveTo(f.x,f.y),t.lineTo(b.x,b.y),t.stroke()}}}getData({x:e,y:t}){if(!this.data.length)return;let n=this.data[0].raw[(t+1)*258+(e+1)];return{raw:n,data:this.data[0].dmin+this.data[0].dmul*n}}async load(){var c;let{coords:e,layer:t}=this,{boundaries:n}=t.state.meta,s=this.layer.style.mask;var i;if((s==="land"||s==="sea")&&(i=ge(e),s===i))return this.data=[],this.sLines=[],this;if(n==null?void 0:n.boundaries180){let a=Ve(e),d=h=>!(a.west>h.east||h.west>a.east||a.south>h.north||h.south>a.north);if(!n.boundaries180.some(d))return this.data=[],this.sLines=[],this}let{upCoords:o,subCoords:l}=this._splitCoords(e),u=this._coordsToURLs(o),f;try{f=await Promise.all(u.map(t.loadData))}catch(a){return this}let b=((c=t.state)==null?void 0:c.units)==="degree"?Ge:qe;if(this.data=f.map(a=>b(ce(a,this.layer.style.blurRadius),l)),this.layer.vector&&this._vectorPrepare(),s&&i===v.Mixed){let a=t.state.maskServerURI.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));try{let d=await t.loadMask(a);Ke(this.data[0],d,s)}catch(d){this.layer.style.mask=void 0,g("Can't load Mask. Turned off")}}return this.layer.vector&&this._createSLines(),this}_splitCoords(e){let t=e.z-this.layer.state.meta.maxZoom;if(t<=0)return{upCoords:e};let n={x:e.x>>>t,y:e.y>>>t,z:this.layer.state.meta.maxZoom},s={x:e.x&(1<<t)-1,y:e.y&(1<<t)-1,z:t};return{upCoords:n,subCoords:s}}_coordsToURLs(e){let t=this.layer.state.baseURL.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));return this.layer.dataSource.variables.map(n=>t.replace("{var}",n))}_vectorPrepare(){if(this.data.length!==2)throw"this.data !== 2";this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[e,t,n]=this.data;e.dmax=1.42*Math.max(-t.dmin,t.dmax,-n.dmin,n.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let s=0;s<258*258;++s){if(!t.raw[s]||!n.raw[s]){e.raw[s]=0;continue}let i=t.dmin+t.dmul*t.raw[s],o=n.dmin+n.dmul*n.raw[s];e.raw[s]=Math.sqrt(o*o+i*i)/e.dmul}}_drawFillAndIsolines(){let{imData:e}=this,{canvasFillCtx:t}=this,n=new Uint32Array(e.data.buffer),{raw:s}=this.data[0],{clut:i,style:o}=this.layer,{levelIndex:l,colorsI:u}=i;if(o.fill!=="none"){let b=u;for(let c=0,a=0,d=259;c<256;++c,d+=2)for(let h=0;h<256;++h,++a,++d)n[a]=b[s[d]]}else n.fill(0);let f=[];if(o.isolineColor!=="none"){let b=o.isolineColor[0]==="#"?T(o.isolineColor):0;for(let c=0,a=0;c<256;c+=1)for(let d=0;d<256;d+=1){let h=(c+1)*258+(d+1),m=s[h],p=s[h+1],x=s[h+258];if(!m||!p||!x)continue;let y=l[m],S=l[p],C=l[x];if(y!==S||y!==C){let H=Math.max(y,S,C),I=Math.max(m,p,x),M=c*256+d;switch(o.isolineColor){case"inverted":n[M]=~u[I]|4278190080;break;case"fill":n[M]=u[I]|4278190080;break;default:n[M]=b;break}o.isolineText&&!(++a%255)&&d>20&&d<235&&c>20&&c<235&&f.push({x:d,y:c,d:m,dr:p,db:x,mli:H})}}}if(t.putImageData(e,0,0),!f.length){t.font="1.1em Sans-serif",t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";for(let{x:b,y:c,d:a,dr:d,db:h,mli:m}of f){let p=this.layer.clut.ticks[m].dataString,x=Math.atan2(a-d,h-a);t.save(),t.translate(b,c),t.rotate(x<-1.57||x>1.57?x+3.14:x),t.strokeText(p,0,0),t.fillText(p,0,0),t.restore()}}}_drawStaticSlines(){if(!this.sLines.length||!this.layer.style.streamLineStatic)return;let{canvasSlinesCtx:e}=this;if(this.layer.style.streamLineColor==="none"){this.sLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let t=this.sLines.length;t--;){let n=this.sLines[t];for(let s=0;s<n.length-1;++s){let i=n[s],o=n[s+1];e.moveTo(i.x,i.y),e.lineTo(o.x,o.y)}}e.stroke()}_drawVector(){if(!this.layer.vector||!this.layer.clut.DataToKnots||!this.layer.style.vectorColor||this.layer.style.vectorColor==="none"||!this.layer.style.vectorType||this.layer.style.vectorType==="none")return;if(this.data.length!==3)throw"this.data.length !== 3";let[e,t,n]=this.data,{canvasVectorCtx:s}=this;switch(this.layer.style.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=this.layer.style.vectorType}s.textAlign="center",s.textBaseline="middle";let i=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0,o=32;for(let l=o/2;l<256;l+=o)for(let u=o/2;u<256;u+=o){let f=u+1+(l+1)*258;if(!e.raw[f])continue;let b=Math.atan2(t.dmin+t.raw[f]*t.dmul,n.dmin+n.raw[f]*n.dmul),c=e.dmin+e.raw[f]*e.dmul,a=this.layer.dataSource.variables[0].includes("current")?5:.2,d=Math.min(this.layer.clut.DataToKnots(c)*a,25)+65,h=String.fromCharCode(d);switch(this.layer.style.vectorColor){case"inverted":s.fillStyle=w(~this.layer.clut.colorsI[e.raw[f]]);break;case"fill":s.fillStyle=w(this.layer.clut.colorsI[e.raw[f]]);break;default:s.fillStyle=this.layer.style.vectorColor;break}s.save(),s.translate(u,l),s.rotate(b+i),s.fillText(h,0,0),s.restore()}}_drawDegree(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:e}=this,t=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle";let n=this.data[0],s="L",i=32;for(let o=i/2;o<256;o+=i)for(let l=i/2;l<256;l+=i){let u=l+1+(o+1)*258;if(!n.raw[u])continue;let b=(n.dmin+n.raw[u]*n.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=w(~this.layer.clut.colorsI[n.raw[u]]);break;case"fill":e.fillStyle=w(this.layer.clut.colorsI[n.raw[u]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(l,o),e.rotate(b+t),e.fillText(s,0,0),e.restore()}}_createSLines(){if(this.data.length!==3)throw"this.data.length !== 3";if(!this.layer.style.streamLineColor||this.layer.style.streamLineColor==="none")return;let e=this.layer.style.streamLineSpeedFactor||1;this.sLines=[];let[t,n,s]=this.data,i=Math.max(this.coords.z-this.layer.state.meta.maxZoom,0),o=Math.min(2**(i+5),128),l=~~(120+i*60);for(let u=0;u<=256;u+=o)for(let f=0;f<=256;f+=o){if(!t.raw[1+f+(1+u)*258])continue;let b=[],c=f,a=u;for(let d=0;d<=l&&c>=0&&c<=256&&a>=0&&a<=256;d++){!(d%(l/6))&&b.push({x:~~c,y:~~a});let h=~~c+1+(~~a+1)*258;if(!t.raw[h])break;c+=e*(n.dmin+n.raw[h]*n.dmul)/t.dmax,a-=e*(s.dmin+s.raw[h]*s.dmul)/t.dmax}c=f,a=u;for(let d=1;d<=l&&c>=0&&c<=256&&a>=0&&a<=256;d++){!(d%(l/6))&&b.unshift({x:~~c,y:~~a});let h=~~c+1+(~~a+1)*258;if(!t.raw[h])break;c-=e*(n.dmin+n.raw[h]*n.dmul)/t.dmax,a+=e*(s.dmin+s.raw[h]*s.dmul)/t.dmax}b.length>2&&this.sLines.push(b)}}};var Ce="setup not complete",Xe=le(new AbortController),F=class extends Se.default.GridLayer{constructor({dataSource:e,options:t,lazy:n}){super(t);this.styles=Z();this.style=Object.assign({},this.styles.base);this.loadData=j();this.loadMask=Xe;this.error=Ce;this.vector=!1;this.clut=new P(this.style,"",[0,2],!1);this.animation=!1;this.lastBaseURL="";this.animationRedrawID=0;this.animFrame=0;this.oldMaxZoom=0;if(g("Creating a WxTilex layer:",e.name,". Params:",JSON.stringify({dataSource:e,options:t})),!e||!e.ext||!e.dataset||!e.name||!e.serverURI||!e.styleName||!Array.isArray(e.variables))throw g("dataSource is wrong!"),"dataSource is wrong!";this.dataSource=e,this.state={maskServerURI:e.maskServerURI||e.serverURI.replace(/\/data\/?/i,"/mask/{z}/{x}/{y}"),units:"undefined",baseURL:"undefined",meta:{maxZoom:0,times:["undefined"],variables:["undefined"],variablesMeta:{}},instance:"undefined",minmax:[[0,1]],originURI:"undefined",time:"undefined"},this.setupCompletePromise=new Promise(s=>{let i=()=>{g("Setup:",e.name),this.on("remove",this._onRemoveLayer,this),this.on("add",this._onAddLayer,this),this._setUpDataSet(e).then(o=>{g("Setup complete:",this.dataSource.name,". Result:",o),this._map&&n&&this._onAddLayer(),this.fire("setupcomplete",{layer:this}),s(o)})};n?this.once("add",i):i()})}createTile(e,t){return this.error&&this.error!==Ce?(setTimeout(t),Object.assign(L("div","error-tile"),{innerHTML:this.error})):this.state.baseURL==="undefined"?(setTimeout(t),L("div","error-tile")):ye({layer:this,coords:e,done:t})}getSetupCompletePromise(){return this.setupCompletePromise}getTile(e){if(!this._map||this.error)return;let t=this._map.getZoom(),{x:n,y:s}=this._map.project(e,t),i={x:~~(n/256),y:~~(s/256)},o=this._getCachedTile(i.x,i.y,t);if(!o)return;let l={x:~~(n-i.x*256),y:~~(s-i.y*256)},u=o.getData(l);if(!u)return;let{raw:f,data:b}=u,c=this.clut.colorsI[f],a=w(c),d=this.clut.DataToStyle(b);return{tile:o,data:b,raw:f,rgba:c,hexColor:a,inStyleUnits:d,tilePoint:l,units:this.style.units}}setStyle(e){if(g("setStyle(",e,") for ",this.dataSource.name),this.error){g("setStyle: failed: "+this.error);return}if(!(this.dataSource.styleName===e&&e!=="custom")){if(e&&(this.dataSource.styleName=e),e==="custom"&&this.styles.custom){(!this.styles.custom.parent||!(this.styles.custom.parent in this.styles))&&(this.styles.custom.parent="base");let t=this.styles[this.styles.custom.parent];this.styles.custom=Object.assign(Object.assign({},t),this.styles.custom)}this.dataSource.styleName in this.styles?Array.isArray(this.styles[this.dataSource.styleName])&&(this.dataSource.styleName+="[0]"):(g(`cant find the style (${this.dataSource.styleName})`),this.dataSource.styleName+="[0]",this.dataSource.styleName in this.styles||(g(`cant find the style (${this.dataSource.styleName}), default is used`),this.dataSource.styleName="base"));try{let t=this.styles[this.dataSource.styleName];this.style=Object.assign({},t);let n=this.style.streamLineColor;n!=="none"&&n.length<7&&(this.style.streamLineColor="#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]);let s=this.state.minmax[0];this.clut=new P(this.style,this.state.units,s,this.vector)}catch(t){let n="setStyle: impossible error in RawCLUT: "+t;throw g(n),n}e&&(this._checkAndStartSlinesAnimation(),this._reloadTiles()),g("setStyle(",e,'): "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete."),this.fire("setstyle",{layer:this})}}getStyle(){return this.dataSource.styleName}getStyleName(){return this.style.name}setTime(e){if(g("setTime: "+e+" for "+this.dataSource.name+" start"),this.error)return g("setTime: failed: "+this.error),Promise.resolve([]);let t=ue(this.state.meta.times,e);if(this.state.time===t)return g("setTime: the same time - skipped"),Promise.resolve([]);if(this.state.time=t,this.state.baseURL=this.state.originURI+this.state.instance+`{var}/${this.state.time}/{z}/{x}/{y}.${this.dataSource.ext}`,this.fire("settime",{layer:this,layerTime:t}),g("setTime: "+t+" for "+this.dataSource.name+" complete"),!this._tiles)return Promise.resolve([]);let n=this._reloadTiles(!1);return n.then(()=>{let s=Object.values(this._tiles);for(let i of s){let o=(i==null?void 0:i.el).wxtile;if(o==null?void 0:o.data.length){let[l,u]=this.state.minmax[0],{dmin:f,dmax:b}=o.data[0];(Math.abs(f-l)>.01||Math.abs(b-u)>.01)&&(this.state.minmax=o.data.map(c=>[c.dmin,c.dmax]),this.setStyle(void 0));break}}this._redrawTiles()}),n}getTime(){return this.error?(g("getTime: failed: "+this.error),this.error):this.state.time}getTimes(){return g("getTimes"),this.error?(g("getTimes: failed: "+this.error),[]):this.state.meta.times}async checkDataChanged(){if(g("checkDataChanged"),this.error)return g("checkDataChanged: failed: "+this.error),!1;let e=await k(this.state.originURI+"instances.json"),t=e[e.length-1]+"/";if(this.state.instance!==t)return!0;let n=await k(this.state.originURI+t+"meta.json");return this.state.meta.times.toString()!==n.times.toString()}reloadData(){return g("reloadData"),this._setUpDataSet(void 0)}getLegendData(e){return g("getLegendData"),(this.error||!this.clut)&&g("getLegendData: failed. "+this.dataSource.name+" : "+this.error),z(e,this.style)}setTimeAnimationMode(e=2){g("setTimeAnimationMode"),this.oldMaxZoom=this.state.meta.maxZoom;let t=this._map.getZoom(),s=(t<this.oldMaxZoom?t:this.oldMaxZoom)-e;this.state.meta.maxZoom=s<0?0:s}unsetTimeAnimationMode(){return g("unsetTimeAnimationMode"),this.oldMaxZoom&&(this.state.meta.maxZoom=this.oldMaxZoom,this.lastBaseURL=""),this._reloadTiles()}getMinMax(){let[e,t]=this.state.minmax[0];return{min:e,max:t}}setAnimation(e){return g("setAnimation"),this.animation=e,this._checkAndStartSlinesAnimation(),this.animation}_getCachedTile(e,t,n){var s,i;return(i=(s=this._tiles[`${e}:${t}:${n}`])==null?void 0:s.el)==null?void 0:i.wxtile}_ForEachTile(e){var n;let t=[];for(let s in this._tiles){let i=(n=this._tiles[s].el)==null?void 0:n.wxtile,o=i&&e(i);o&&t.push(o)}return t}async _setUpDataSet(e){e&&(this.dataSource=e),this._stopLoadingResetLoadDataFunc(),this.state.originURI=this.dataSource.serverURI+"/"+this.dataSource.dataset+"/";try{let t=await k(this.state.originURI+"instances.json");this.state.instance=t[t.length-1]+"/"}catch(t){return this.error=this.dataSource.name+": load instances.json error: "+t,g(this.error),!1}try{let t=this.state.originURI+this.state.instance+"meta.json";this.state.meta=await k(t)}catch(t){return this.error=this.dataSource.name+": load meta.json error: "+t,g(this.error),!1}if(this.vector=this.dataSource.variables.length===2,this.animation=this.vector,this.state.units=this.state.meta.variablesMeta[this.dataSource.variables[0]].units,this.state.minmax=this.dataSource.variables.map(t=>[this.state.meta.variablesMeta[t].min,this.state.meta.variablesMeta[t].max]),this.vector){let[[t,n],[s,i]]=this.state.minmax;this.state.minmax.unshift([0,1.42*Math.max(-t,n,-s,i)])}return this.error=null,e&&(this.setStyle(void 0),await this.setTime(new Date)),!0}_checkZoom(){var e;((e=this._map)==null?void 0:e.getZoom())>this.state.meta.maxZoom||this._stopLoadingResetLoadDataFunc()}_onAddLayer(){var e;g("onadd:",this.dataSource.name),(e=this._map)==null||e.on("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this.redraw(),this._checkAndStartSlinesAnimation()})}_onRemoveLayer(){var e;g("onremove:",this.dataSource.name),(e=this._map)==null||e.off("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this._stopLoadingResetLoadDataFunc(),this._stopSlinesAnimation()})}_stopLoadingResetLoadDataFunc(){this.loadData.controllerHolder.controller.abort(),this.loadData=j()}_checkAndStartSlinesAnimation(){if(this.animFrame||!this.animation||!this.vector||!this.style.streamLineColor||this.style.streamLineColor==="none")return;let e=t=>{if(!this.animation||this.style.streamLineStatic){this._stopSlinesAnimation();return}this._ForEachTile(n=>n.drawSLines(t)),this.animFrame=requestAnimationFrame(e)};e(0)}_stopSlinesAnimation(){cancelAnimationFrame(this.animFrame),this._ForEachTile(e=>e.clearSLinesCanvas()),this.animFrame=0}_redrawTiles(){this.animationRedrawID===0&&(this.animationRedrawID=requestAnimationFrame(()=>{g("_redrawTiles: requestAnimationFrame: "+this.dataSource.name),this._ForEachTile(e=>e.draw()),this.animationRedrawID=0}))}_reloadTiles(e=!0){if(g("_reloadTiles: start - "+this.dataSource.name),this.lastBaseURL===this.state.baseURL)return g("_reloadTiles: same URL. Nothing to reload"),Promise.resolve([]);this.loadData.controllerHolder.controller.abort(),this.loadData.controllerHolder.controller=new AbortController,this.lastBaseURL=this.state.baseURL;let t=this._ForEachTile(i=>i.load()),n=Promise.all(t),{controller:s}=this.loadData.controllerHolder;return e&&n.then(()=>s.signal.aborted||this._redrawTiles()),g("_reloadTiles: finished - "+this.dataSource.name),n}};function $e(r){return new F(r)}var we=class extends E.default.Control{constructor(e){super(e);this.URI=e.URI}onAdd(){let e=document.createElement("img");return e.src=this.URI,e.className="wxtiles-logo",e}};function Ut(r){return g("Add watermark:",JSON.stringify(r)),new we(r)}var Te=class extends E.default.GridLayer{createTile(e){let t=document.createElement("div");return t.innerHTML=[e.x,e.y,e.z].join(", "),t.style.outline="1px solid red",t}};function Pt(){return g("Add WxDebugCoordsLayer:"),new Te().setZIndex(1e3)}function Wt(r,e){return E.default.layerGroup(r.map($e),e)}export{Pt as CreateWxDebugCoordsLayer,Wt as CreateWxTilesGroupLayer,$e as CreateWxTilesLayer,Ut as CreateWxTilesWatermark,Qe as LoadQTree,Te as WxDebugLayer,Z as WxGetColorStyles,F as WxTilesLayer,Re as WxTilesLibSetup,He as WxTilesLogging,we as WxWatermark};
|
package/dist/es/wxtools.d.ts
CHANGED
|
@@ -89,13 +89,15 @@ export interface DataIntegral extends DataPicture {
|
|
|
89
89
|
integral: IntegralPare;
|
|
90
90
|
radius: number;
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
export interface AbortableCacheableFunc<T> extends CacheableFunc<T> {
|
|
94
|
-
abort(): void;
|
|
92
|
+
interface AbortControllerHolder {
|
|
95
93
|
controller: AbortController;
|
|
96
94
|
}
|
|
95
|
+
export declare function loadImageData(url: string, controllerHolder: AbortControllerHolder): Promise<ImageData>;
|
|
96
|
+
export interface AbortableCacheableFunc<T> extends CacheableFunc<T> {
|
|
97
|
+
controllerHolder: AbortControllerHolder;
|
|
98
|
+
}
|
|
97
99
|
export declare function loadDataPictureCachedAbortable(): AbortableCacheableFunc<Promise<DataIntegral>>;
|
|
98
|
-
export declare function
|
|
100
|
+
export declare function loadImageDataCachedAbortable(controller: AbortController): AbortableCacheableFunc<Promise<ImageData>>;
|
|
99
101
|
export declare function blurData(im: DataIntegral, radius: number): DataIntegral;
|
|
100
102
|
export declare function RGBtoHEX(rgb: number): string;
|
|
101
103
|
export declare function RGBAtoHEX(rgba: number): string;
|
|
@@ -104,7 +106,7 @@ export declare function fetchJson(url: RequestInfo, init?: RequestInit): Promise
|
|
|
104
106
|
export declare function createEl(tagName: string, className?: string, container?: HTMLElement): HTMLElement;
|
|
105
107
|
export declare function mixColor(c1: number, c2: number, t: number): number;
|
|
106
108
|
export declare function createLevels(min: number, max: number, n: number): number[];
|
|
107
|
-
export declare function getClosestTimeString(times: string[],
|
|
109
|
+
export declare function getClosestTimeString(times: string[], time: Date | string | number): string;
|
|
108
110
|
export declare function WxTilesLogging(on: boolean): void;
|
|
109
111
|
export declare function WXLOG(...str: any): void;
|
|
110
112
|
export {};
|
package/dist/web/wxtiles.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var wxtilesjs=(()=>{var At=Object.create;var k=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var _t=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols,Pt=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty,Ut=Object.prototype.propertyIsEnumerable;var Y=(r,t,e)=>t in r?k(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,tt=(r,t)=>{for(var e in t||(t={}))J.call(t,e)&&Y(r,e,t[e]);if(X)for(var e of X(t))Ut.call(t,e)&&Y(r,e,t[e]);return r};var et=r=>k(r,"__esModule",{value:!0});var re=typeof require!="undefined"?require:r=>{throw new Error('Dynamic require of "'+r+'" is not supported')};var Rt=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),Ft=(r,t)=>{et(r);for(var e in t)k(r,e,{get:t[e],enumerable:!0})},Wt=(r,t,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of _t(t))!J.call(r,n)&&n!=="default"&&k(r,n,{get:()=>t[n],enumerable:!(e=It(t,n))||e.enumerable});return r},rt=r=>Wt(et(k(r!=null?At(Pt(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var Z=Rt((ie,nt)=>{nt.exports=window.L});var ee={};Ft(ee,{CreateWxDebugCoordsLayer:()=>Yt,CreateWxTilesGroupLayer:()=>te,CreateWxTilesLayer:()=>kt,CreateWxTilesWatermark:()=>Jt,LoadQTree:()=>St,WxDebugLayer:()=>$,WxGetColorStyles:()=>R,WxTilesLayer:()=>_,WxTilesLibSetup:()=>lt,WxTilesLogging:()=>xt,WxWatermark:()=>V});var z=rt(Z());var st={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 ot={none:["#00000000","#00000000"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbowzerro:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow2:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebirdzerro:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bw:["#000000ff","#ffffffff"],wb:["#ffffffff","#000000ff"],redish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]};var U={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"}};var B,it,at;function lt({colorStyles:r={},units:t={},colorSchemes:e={}}={}){C("WxTile lib setup: start"),B=Object.assign({},st,t),it=Object.assign({},e,ot);let n=Object.assign({},r,U);at=Et(n),C("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),C("WxTile lib setup is done.")}function R(){return at}function ct(){return it}function F(r,t,e){let n=e?Object.assign({},B,e):B;if(!n||!r||!t||r===t||!n[r]||!n[t]||n[r][0]!==n[t][0]){C(r===t?"Trivial converter:":"Inconvertible units. Default converter is used:",r," -> ",t);let o=a=>a;return o.trivial=!0,o}C("Converter: From:",r," To:",t);let s=n[r][1]/n[t][1],i=(n[r][2]||0)/n[t][1]-(n[t][2]||0)/n[t][1];return i?o=>s*o+i:o=>s*o}function Et(r){let t=Object.assign({},U);for(let s in r){let i=r[s];if(Array.isArray(i))for(let o=0;o<i.length;++o)t[s+"["+o+"]"]=Object.assign({},i[o]);else t[s]=Object.assign({},i)}let e=(s,i)=>{if(i==="base")return U.base;let o=s[i];(!o.parent||!(o.parent in s))&&(o.parent="base");let a=e(s,o.parent);return Object.assign(o,Object.assign({},a,o,{parent:"base"}))},n={};for(let s in t)n[s]=e(t,s);return n}function mt(r){let t=new Map;return e=>{let n=t.get(e);return n===void 0&&(n=r(e),t.set(e,n)),n}}async function zt(r,t){let e=await(await fetch(r,{signal:t})).blob(),n=new Image;if(!t.aborted){let s=URL.createObjectURL(e);n.src=s,await n.decode(),URL.revokeObjectURL(s)}return n}function Nt(r){let{width:t,height:e}=r,n=Object.assign(document.createElement("canvas"),{width:t,height:e,imageSmoothingEnabled:!1}).getContext("2d");if(!n)throw"catastrophe";return n.drawImage(r,0,0),n.getImageData(0,0,t,e)}async function ut(r,t){return Nt(await zt(r,t))}async function Zt(r,t){return(n=>{let s=n.height*n.width,i=new Uint16Array(n.data.buffer),o=new Uint16Array(s);for(let f=0;f<s;f++)o[f]=i[f*2];let a=new Uint8Array(n.data.buffer);for(let f=0;f<8;++f)a[f]=a[f*4+2];let u=new DataView(n.data.buffer),h=u.getFloat32(0,!0),b=u.getFloat32(4,!0),l=(b-h)/65535,c=Bt(o);return{raw:o,dmin:h,dmax:b,dmul:l,integral:c,radius:0}})(await ut(r,t))}function j(){let r=new AbortController,t=mt(e=>Zt(e,r.signal));return t.abort=()=>r.abort(),t.controller=r,t}function ft(r){let t=mt(e=>ut(e,r.signal));return t.abort=()=>r.abort(),t.controller=r,t}function Bt(r){let t=new Uint32Array(258*258),e=new Uint32Array(258*258);t[0]=r[0],e[0]=r[0]===0?0:1;for(let n=1;n<258;++n)t[n]=r[n]+t[n-1],t[258*n]=r[258*n]+t[258*n-258],e[n]=(r[n]===0?0:1)+e[n-1],e[258*n]=(r[258*n]===0?0:1)+e[258*n-258];for(let n=1,s=259;n<258;++n,++s)for(let i=1;i<258;++i,++s)t[s]=r[s]+t[s-258]+t[s-1]-t[s-258-1],e[s]=(r[s]===0?0:1)+e[s-258]+e[s-1]-e[s-258-1];return{integral:t,integralNZ:e}}function ht(r,t){if(t<0||t===r.radius)return r;r.radius=t;let e=258,{integral:n,integralNZ:s}=r.integral;for(let i=1;i<e;i++)for(let o=1;o<e;o++){if(!r.raw[e*i+o])continue;let a=Math.min(t,o-1,e-1-o),u=Math.min(t,i-1,e-1-i),h=e*(i-u-1)+o,b=e*(i+u)+o,l=s[h-a-1],c=s[h+a],f=s[b-a-1],d=s[b+a],m=l+d-c-f,y=n[h-a-1],g=n[h+a],x=n[b-a-1],p=n[b+a],S=y+p-g-x;r.raw[i*e+o]=S/m}return r}function w(r){let t=r>>0&255,e=r>>8&255,n=r>>16&255,s=t.toString(16),i=e.toString(16),o=n.toString(16);return s=s.length===2?s:"0"+s,i=i.length===2?i:"0"+i,o=o.length===2?o:"0"+o,"#"+s+i+o}function v(r){if(r[0]==="#"){if(r.length===4)return+("0xff"+r[3]+r[3]+r[2]+r[2]+r[1]+r[1]);if(r.length===7)return+("0xff"+r[5]+r[6]+r[3]+r[4]+r[1]+r[2]);if(r.length===9)return+("0x"+r[7]+r[8]+r[5]+r[6]+r[3]+r[4]+r[1]+r[2])}return C("wrong color format",r),0}async function A(r,t){return(await fetch(r,t)).json()}function T(r,t="",e){var s;let n=document.createElement(r);return n.className=t,e&&((s=e.appendChild)==null||s.call(e,n)),n}function O(r,t,e){let n=r>>0&255,s=r>>8&255,i=r>>16&255,o=r>>>24,a=t>>0&255,u=t>>8&255,h=t>>16&255,b=t>>>24,l=n+e*(a-n),c=s+e*(u-s),f=i+e*(h-i),d=o+e*(b-o);return l|c<<8|f<<16|d<<24}function dt(r,t,e){let n=[];for(let s=0;s<e;++s)n.push(s*(t-r)/(e-1)+r);return n}function bt(r,t){return r.find(e=>new Date(e).getTime()>=t)||r[r.length-1]}var gt=!1;function xt(r){console.log(r?"Logging on":"Logging off"),gt=r}function C(...r){gt&&console.log(...r)}var Mt=rt(Z());function jt(r,t,e){return r>e?e:r<t?t:r}var W=class{constructor(t,e,[n,s],i){let o=s-n;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let a=[];this.DataToStyle=F(e,t.units,t.extraUnits),this.DataToStyle.trivial&&(t.units=e),i&&(this.DataToKnots=F(e,"knot"));let u=F(t.units,e,t.extraUnits),h=m=>~~(65535*jt((u(m)-n)/(s-n),0,1));if(Array.isArray(t.colorMap)){t.colorMap.sort((m,y)=>m[0]<y[0]?-1:m[0]>y[0]?1:0);for(let[m]of t.colorMap)a.push(h(m))}else{if(t.levels||(t.levels=dt(this.DataToStyle(n),this.DataToStyle(s),10)),t.levels.sort((m,y)=>m<y?-1:m>y?1:0),!t.colors){let m=ct();t.colorScheme&&t.colorScheme in m?t.colors=m[t.colorScheme]:t.colors=m.wb}for(let m of t.levels)a.push(h(m))}let b=65536,l=H(b,t);this.ticks=l.ticks;let c=l.ticks[0].data,d=l.ticks[l.ticks.length-1].data-c;for(let m=0;m<65536;++m){let y=o*m/65535+n,g=this.DataToStyle(y),x=Math.round((b-1)*(g-c)/d);x<=0?this.colorsI[m]=t.showBelowMin?l.colors[0]:0:x>=b?this.colorsI[m]=t.showAboveMax?l.colors[b-1]:0:this.colorsI[m]=l.colors[x]}this.colorsI[0]=0;for(let m=0;m<a[0];++m)this.levelIndex[m]=0;for(let m=0;m<a.length-1;m++)for(let y=a[m];y<a[m+1]+1;++y)this.levelIndex[y]=m;for(let m=a[a.length-1];m<65536;++m)this.levelIndex[m]=a.length-1}};function yt(r){var e;if(r!==0&&-.1<r&&r<.1)return r.toExponential(2);let t=r.toString();return((e=t.split(".")[1])==null?void 0:e.length)>2?r.toFixed(2):t}function H(r,t){let e={size:r,showBelowMin:t.showBelowMin,showAboveMax:t.showAboveMax,units:t.units,colors:new Uint32Array(r),ticks:[]},{colorMap:n,levels:s,colors:i}=t,o=t.fill!=="solid";if(n){let c=n[0][0],f=n[n.length-1][0]-c;for(let[d,m]of n){let y=~~((d-c)/f*(r-1)),g={data:d,dataString:yt(d),color:m,pos:y};e.ticks.push(g)}for(let d=0;d<n.length-1;d++){let m=e.ticks[d].pos,y=e.ticks[d+1].pos,g=v(n[d][1]),x=o?v(n[d+1][1]):0;for(let p=m;p<y;++p)e.colors[p]=o?O(g,x,(p-m)/(y-m)):g}return e.colors[r-1]=v(n[n.length-1][1]),e}if(!i||!s)return e;let a=0,u=0,h=-1;for(let c=0;c<r;++c){let f=c*(i.length-1)/r;h!==~~f&&(h=~~f,a=v(i[h]),u=i.length>h+1?v(i[h+1]):a),e.colors[c]=o?O(a,u,f-h):a}e.colors[r-1]=v(i[i.length-1]);let b=s[0],l=(r-1)/(s[s.length-1]-b);for(let c of s){let f=~~((c-b)*l),d={data:c,dataString:yt(c),color:w(e.colors[f]),pos:f};e.ticks.push(d)}return e}var Q=256,Ot=2*Math.PI*6378137/Q,E=2*Math.PI*6378137/2;function Ht(r,t){let e=r/E*180,n=t/E*180;return n=180/Math.PI*(2*Math.atan(Math.exp(n*Math.PI/180))-Math.PI/2),[n,e]}function Qt(r,t,e){let n=Gt(e),s=r*n-E,i=t*n-E;return[s,i]}function Gt(r){return Ot/Math.pow(2,r)}function G(r,t,e){let[n,s]=Ht(...Qt(r,t,e));return[s,-n]}function pt(r,t){return[r*Q,t*Q]}var Kt="A".charCodeAt(0),K,M=0;async function St(r,t){let e;try{e=await(await fetch(r,t)).json()}catch(n){console.log("Can't load QTree:",n);return}K=I(e,{pos:0}),M=Ct(K),console.log("Loaded QTree, depth:",M)}function I(r,t){let e=r.charCodeAt(t.pos)-Kt;t.pos++;let n=e&1?I(r,t):null,s=e&2?I(r,t):null,i=e&4?I(r,t):null,o=e&8?I(r,t):null;return{sub:n||s||i||o?[n,s,i,o]:null}}function Ct(r){let t=0;if(r==null?void 0:r.sub){for(let e=0;e<4;e++)if(r.sub[e]!==null){let n=Ct(r.sub[e])+1;t<n&&(t=n)}}return t}var L;(function(n){n.Land="land",n.Mixed="mixed",n.Sea="sea"})(L||(L={}));function wt(r){if(!M)return L.Mixed;let t=tt({},r),e=!1;if(M<=r.z){e=!0;let n=r.z-M;t={x:r.x>>n,y:r.y>>n,z:M}}return vt(K,t,e)}function vt(r,t,e){if(r===null)return L.Land;if(e&&t.z===0)return L.Mixed;if(r.sub===null)return L.Sea;if(t.z===0)return L.Mixed;t.z--;let n=t.x>>t.z&1,i=(t.y>>t.z&1)<<1|n;return vt(r.sub[i],t,e)}function qt(r,t){if(!t)return r;let e=.9999999/Math.pow(2,t.z),n=t.x*256*e,s=t.y*256*e,i={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:o}=i;for(let a=-1,u=0;a<=256;a++){let h=s+a*e,b=Math.floor(h),l=h-b;for(let c=-1;c<=256;c++,u++){let f=n+c*e,d=Math.floor(f),m=f-d,y=d+1+(b+1)*258,g=r.raw[y],x=r.raw[y+1],p=r.raw[y+258],S=r.raw[y+258+1];switch((g?1:0)|(x?2:0)|(p?4:0)|(S?8:0)){case 0:o[u]=0;continue;case 1:o[u]=g;continue;case 2:o[u]=x;continue;case 3:p=g,S=x;break;case 4:o[u]=p;continue;case 5:x=g,S=p;break;case 6:S=x+p>>1,g=S;break;case 7:S=x+p>>1;break;case 8:o[u]=S;continue;case 9:x=g+S>>1,p=x;break;case 10:g=x,p=S;break;case 11:p=g+S>>1;break;case 12:g=p,x=S;break;case 13:x=g+S>>1;break;case 14:g=x+p>>1;break}g=r.dmin+r.dmul*g,x=r.dmin+r.dmul*x,p=r.dmin+r.dmul*p,S=r.dmin+r.dmul*S;let P=q(g,x,m),D=q(p,S,m);o[u]=(q(P,D,l)-r.dmin)/r.dmul,o[u]===0&&(o[u]=1)}}return i}function q(r,t,e){let n=((t-r)%360+540)%360-180;return(r+n*e+360)%360}function Vt(r,t){if(!t)return r;let e=.9999999/Math.pow(2,t.z),n=t.x*256*e,s=t.y*256*e,i={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:o}=i;for(let a=-1,u=0;a<=256;a++){let h=s+a*e,b=Math.floor(h),l=h-b;for(let c=-1;c<=256;c++,u++){let f=n+c*e,d=Math.floor(f),m=f-d,y=d+1+(b+1)*258,g=r.raw[y],x=r.raw[y+1],p=r.raw[y+258],S=r.raw[y+258+1];switch((g?1:0)|(x?2:0)|(p?4:0)|(S?8:0)){case 7:o[u]=m+l<1?m*(x-g)+l*(p-g)+g:0;continue;case 14:o[u]=m+l<1?0:m*(S-p)+l*(S-x)+x+p-S;continue;case 11:o[u]=l<m?(1-m)*(g-x)+l*(S-x)+x:0;continue;case 13:o[u]=l<m?0:(1-m)*(p-S)+l*(p-g)+g+S-p;continue;case 15:o[u]=m+l<1?m*(x-g)+l*(p-g)+g:m*(S-p)+l*(S-x)+x+p-S;continue;default:o[u]=0}}}return i}function $t(r,t,e){let n=e==="land"?1:0;for(let s=3,i=0;i<256;i++)for(let o=0;o<256;o++,s+=4){let a=t.data[s]?1:0;n^a&&(r.raw[(i+1)*258+(o+1)]=0)}return r}function Xt(r){let[t,e]=pt(r.x,r.y),[n,s]=G(t,e,r.z),[i,o]=G(t+256,e+256,r.z);return{west:n,north:s,east:i,south:o}}function Lt({layer:r,coords:t,done:e}){let n=T("div","leaflet-tile s-tile");return r.error?setTimeout(e):(n.wxtile=new Tt({layer:r,coords:t,tileEl:n}),n.wxtile.load().then(s=>{s.draw(),e()})),n}var Tt=class{constructor({layer:t,coords:e,tileEl:n}){this.data=[];this.sLines=[];this.imData=null;this.coords=e,this.layer=t,this.canvasFill=T("canvas","s-tile canvas-fill",n),this.canvasSlines=T("canvas","s-tile canvas-slines",n),this.canvasVector=this.canvasFill,this.canvasFill.width=this.canvasFill.height=this.canvasSlines.width=this.canvasSlines.height=256;function s(i){let o=i.getContext("2d");if(!o)throw"error";return o}this.canvasFillCtx=s(this.canvasFill),this.canvasSlinesCtx=s(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasSlinesCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVector(),this._drawDegree(),this._drawStaticSlines())}clearSLinesCanvas(){this.canvasSlinesCtx.clearRect(0,0,256,256)}drawSLines(t){if(this.sLines.length===0)return;let e=this.canvasSlinesCtx;if(e.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.sLines=[];return}let n=this.layer.style.streamLineColor.substr(0,7);t=t>>7;for(let s=0;s<this.sLines.length;++s){let i=this.sLines[s],o=i.length-1,a=(t+(1+i[0].x)*(1+i[0].y))%30;for(let u=0;u<o;++u){let h=i[u],b=i[u+1],l=1-(a-u)/o;(l<0||l>1)&&(l=0);let c=(~~(l*255)).toString(16);e.strokeStyle=n+(c.length<2?"0"+c:c);let f=1+~~((1.2-l)*5);e.lineWidth=f,e.beginPath(),e.moveTo(h.x,h.y),e.lineTo(b.x,b.y),e.stroke()}}}getData({x:t,y:e}){if(!this.data.length)return;let n=this.data[0].raw[(e+1)*258+(t+1)];return{raw:n,data:this.data[0].dmin+this.data[0].dmul*n}}async load(){var l;this.data=[],this.imData=null,this.sLines=[];let{coords:t,layer:e}=this,{boundaries:n}=e.state.meta,s=this.layer.style.mask;var i;if((s==="land"||s==="sea")&&(i=wt(t),s===i))return this;if(n==null?void 0:n.boundaries180){let c=Xt(t),f=d=>!(c.west>d.east||d.west>c.east||c.south>d.north||d.south>c.north);if(!n.boundaries180.some(f))return this}let{upCoords:o,subCoords:a}=this._splitCoords(t),u=this._coordsToURLs(o),h;try{h=await Promise.all(u.map(e.loadData))}catch(c){return this}let b=((l=e.state)==null?void 0:l.units)==="degree"?qt:Vt;if(this.data=h.map(c=>b(ht(c,this.layer.style.blurRadius),a)),this.imData=this.canvasFillCtx.createImageData(256,256),this.layer.vector&&this._vectorPrepare(),s&&i===L.Mixed){let c=e.state.maskServerURI.replace("{z}",String(t.z)).replace("{x}",String(t.x)).replace("{y}",String(t.y));try{let f=await e.loadMask(c);$t(this.data[0],f,s)}catch(f){this.layer.style.mask=void 0,C("Can't load Mask. Turned off")}}return this.layer.vector&&this._createSLines(),this}_splitCoords(t){let e=t.z-this.layer.state.meta.maxZoom;if(e<=0)return{upCoords:t};let n={x:t.x>>>e,y:t.y>>>e,z:this.layer.state.meta.maxZoom},s={x:t.x&(1<<e)-1,y:t.y&(1<<e)-1,z:e};return{upCoords:n,subCoords:s}}_coordsToURLs(t){let e=this.layer.state.baseURL.replace("{z}",String(t.z)).replace("{x}",String(t.x)).replace("{y}",String(t.y));return this.layer.dataSource.variables.map(n=>e.replace("{var}",n))}_vectorPrepare(){if(this.data.length!==2)throw"this.data !== 2";this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[t,e,n]=this.data;t.dmax=1.42*Math.max(-e.dmin,e.dmax,-n.dmin,n.dmax),t.dmul=(t.dmax-t.dmin)/65535;for(let s=0;s<258*258;++s){if(!e.raw[s]||!n.raw[s]){t.raw[s]=0;continue}let i=e.dmin+e.dmul*e.raw[s],o=n.dmin+n.dmul*n.raw[s];t.raw[s]=Math.sqrt(o*o+i*i)/t.dmul}}_drawFillAndIsolines(){let{imData:t}=this;if(!t)throw"_drawFillAndIsolines: !imData";let{canvasFillCtx:e}=this,n=new Uint32Array(t.data.buffer),{raw:s}=this.data[0],{clut:i,style:o}=this.layer,{levelIndex:a,colorsI:u}=i;if(o.fill!=="none"){let b=u;for(let l=0,c=0,f=259;l<256;++l,f+=2)for(let d=0;d<256;++d,++c,++f)n[c]=b[s[f]]}else n.fill(0);let h=[];if(o.isolineColor!=="none"){let b=o.isolineColor[0]==="#"?v(o.isolineColor):0;for(let l=0,c=0;l<256;l+=1)for(let f=0;f<256;f+=1){let d=(l+1)*258+(f+1),m=s[d],y=s[d+1],g=s[d+258];if(!m||!y||!g)continue;let x=a[m],p=a[y],S=a[g];if(x!==p||x!==S){let N=Math.max(x,p,S),P=Math.max(m,y,g),D=l*256+f;switch(o.isolineColor){case"inverted":n[D]=~u[P]|4278190080;break;case"fill":n[D]=u[P]|4278190080;break;default:n[D]=b;break}o.isolineText&&!(++c%255)&&f>20&&f<235&&l>20&&l<235&&h.push({x:f,y:l,d:m,dr:y,db:g,mli:N})}}}if(e.putImageData(t,0,0),!h.length){e.font="1.1em Sans-serif",e.lineWidth=2,e.strokeStyle="white",e.fillStyle="black",e.textAlign="center",e.textBaseline="middle";for(let{x:b,y:l,d:c,dr:f,db:d,mli:m}of h){let y=this.layer.clut.ticks[m].dataString,g=Math.atan2(c-f,d-c);e.save(),e.translate(b,l),e.rotate(g<-1.57||g>1.57?g+3.14:g),e.strokeText(y,0,0),e.fillText(y,0,0),e.restore()}}}_drawStaticSlines(){if(!this.sLines.length||!this.layer.style.streamLineStatic)return;let{canvasSlinesCtx:t}=this;if(this.layer.style.streamLineColor==="none"){this.sLines=[];return}t.lineWidth=2,t.strokeStyle=this.layer.style.streamLineColor,t.beginPath();for(let e=this.sLines.length;e--;){let n=this.sLines[e];for(let s=0;s<n.length-1;++s){let i=n[s],o=n[s+1];t.moveTo(i.x,i.y),t.lineTo(o.x,o.y)}}t.stroke()}_drawVector(){if(!this.layer.vector||!this.layer.clut.DataToKnots||!this.layer.style.vectorColor||this.layer.style.vectorColor==="none"||!this.layer.style.vectorType||this.layer.style.vectorType==="none")return;if(this.data.length!==3)throw"this.data.length !== 3";let[t,e,n]=this.data,{canvasVectorCtx:s}=this;switch(this.layer.style.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=this.layer.style.vectorType}s.textAlign="center",s.textBaseline="middle";let i=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0,o=32;for(let a=o/2;a<256;a+=o)for(let u=o/2;u<256;u+=o){let h=u+1+(a+1)*258;if(!t.raw[h])continue;let b=Math.atan2(e.dmin+e.raw[h]*e.dmul,n.dmin+n.raw[h]*n.dmul),l=t.dmin+t.raw[h]*t.dmul,c=this.layer.dataSource.variables[0].includes("current")?5:.2,f=Math.min(this.layer.clut.DataToKnots(l)*c,25)+65,d=String.fromCharCode(f);switch(this.layer.style.vectorColor){case"inverted":s.fillStyle=w(~this.layer.clut.colorsI[t.raw[h]]);break;case"fill":s.fillStyle=w(this.layer.clut.colorsI[t.raw[h]]);break;default:s.fillStyle=this.layer.style.vectorColor;break}s.save(),s.translate(u,a),s.rotate(b+i),s.fillText(d,0,0),s.restore()}}_drawDegree(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:t}=this,e=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0;t.font="50px arrows",t.textAlign="center",t.textBaseline="middle";let n=this.data[0],s="L",i=32;for(let o=i/2;o<256;o+=i)for(let a=i/2;a<256;a+=i){let u=a+1+(o+1)*258;if(!n.raw[u])continue;let b=(n.dmin+n.raw[u]*n.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":t.fillStyle=w(~this.layer.clut.colorsI[n.raw[u]]);break;case"fill":t.fillStyle=w(this.layer.clut.colorsI[n.raw[u]]);break;default:t.fillStyle=this.layer.style.vectorColor;break}t.save(),t.translate(a,o),t.rotate(b+e),t.fillText(s,0,0),t.restore()}}_createSLines(){if(this.data.length!==3)throw"this.data.length !== 3";if(!this.layer.style.streamLineColor||this.layer.style.streamLineColor==="none")return;let t=this.layer.style.streamLineSpeedFactor||1;this.sLines=[];let[e,n,s]=this.data,i=Math.max(this.coords.z-this.layer.state.meta.maxZoom,0),o=Math.min(2**(i+5),128),a=~~(120+i*60);for(let u=0;u<=256;u+=o)for(let h=0;h<=256;h+=o){if(!e.raw[1+h+(1+u)*258])continue;let b=[],l=h,c=u;for(let f=0;f<=a&&l>=0&&l<=256&&c>=0&&c<=256;f++){!(f%(a/6))&&b.push({x:~~l,y:~~c});let d=~~l+1+(~~c+1)*258;if(!e.raw[d])break;l+=t*(n.dmin+n.raw[d]*n.dmul)/e.dmax,c-=t*(s.dmin+s.raw[d]*s.dmul)/e.dmax}l=h,c=u;for(let f=1;f<=a&&l>=0&&l<=256&&c>=0&&c<=256;f++){!(f%(a/6))&&b.unshift({x:~~l,y:~~c});let d=~~l+1+(~~c+1)*258;if(!e.raw[d])break;l-=t*(n.dmin+n.raw[d]*n.dmul)/e.dmax,c+=t*(s.dmin+s.raw[d]*s.dmul)/e.dmax}b.length>2&&this.sLines.push(b)}}};var Dt="setup not complete",_=class extends Mt.default.GridLayer{constructor({dataSource:t,options:e={},lazy:n=!0}){super(e);this.wxtiles=new Map;this.styles=R();this.style=Object.assign({},this.styles.base);this.loadData=j();this.loadMask=ft(new AbortController);this.error=Dt;this.vector=!1;this.clut=new W(this.style,"",[0,2],!1);this.animation=!1;this.animationRedrawID=0;this.animFrame=0;this.oldMaxZoom=0;if(C("Creating a WxTilex layer:"+JSON.stringify({dataSource:t,options:e})),!t||!t.ext||!t.dataset||!t.name||!t.serverURI||!t.styleName||!Array.isArray(t.variables))throw C("dataSource is wrong!"),"dataSource is wrong!";this.dataSource=t,this.state={maskServerURI:t.maskServerURI||t.serverURI.replace(/\/data\/?/i,"/mask/{z}/{x}/{y}"),units:"undefined",baseURL:"undefined",meta:{maxZoom:0,times:["undefined"],variables:["undefined"],variablesMeta:{}},instance:"undefined",minmax:[[0,1]],originURI:"undefined",time:"undefined"};let s=()=>{C("Setup:",t.name),this.setupCompletePromise=this._setUpDataSet(t),this.setupCompletePromise.then(()=>{C("Setup complete:",this.dataSource.name);let i=a=>{this.wxtiles.set(`${a.coords.x}:${a.coords.y}:${a.coords.z}`,a.tile.wxtile)};this.on("tileload",i);let o=a=>{this.wxtiles.delete(`${a.coords.x}:${a.coords.y}:${a.coords.z}`)};this.on("tileunload",o),this.on("add",this._onAddLayer,this),this._map&&this._onAddLayer(),this.fire("setupcomplete",{layer:this})})};n?this.once("add",s):s(),this.on("remove",this._onRemoveLayer,this)}createTile(t,e){return this.error&&this.error!==Dt?(setTimeout(e),Object.assign(T("div","error-tile"),{innerHTML:this.error})):Lt({layer:this,coords:t,done:e})}getSetupCompletePromise(){return this.setupCompletePromise}getTile(t){if(!this._map||this.error)return;let e=this._map.getZoom(),{x:n,y:s}=this._map.project(t,e),i={x:~~(n/256),y:~~(s/256)},o=this.wxtiles.get(`${i.x}:${i.y}:${e}`);if(!o)return;let a={x:~~(n-i.x*256),y:~~(s-i.y*256)},u=o.getData(a);if(!u)return;let{raw:h,data:b}=u,l=this.clut.colorsI[h],c=w(l),f=this.clut.DataToStyle(b);return{tile:o,data:b,raw:h,rgba:l,hexColor:c,inStyleUnits:f,tilePoint:a,units:this.style.units}}setStyle(t){if(this.error){C("setStyle: failed: "+this.error);return}if(!(this.dataSource.styleName===t&&t!=="custom")){if(t&&(this.dataSource.styleName=t),t==="custom"&&this.styles.custom){(!this.styles.custom.parent||!(this.styles.custom.parent in this.styles))&&(this.styles.custom.parent="base");let e=this.styles[this.styles.custom.parent];this.styles.custom=Object.assign(Object.assign({},e),this.styles.custom)}this.dataSource.styleName in this.styles?Array.isArray(this.styles[this.dataSource.styleName])&&(this.dataSource.styleName+="[0]"):(C(`cant find the style (${this.dataSource.styleName})`),this.dataSource.styleName+="[0]",this.dataSource.styleName in this.styles||(C(`cant find the style (${this.dataSource.styleName}), default is used`),this.dataSource.styleName="base"));try{let e=this.styles[this.dataSource.styleName];this.style=Object.assign({},e);let n=this.style.streamLineColor;n!=="none"&&n.length<7&&(this.style.streamLineColor="#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]);let s=this.state.minmax[0];this.clut=new W(this.style,this.state.units,s,this.vector)}catch(e){let n="setStyle: impossible error in RawCLUT: "+e;throw C(n),n}t&&(this._checkAndStartSlinesAnimation(),this._reloadTiles()),C('setStyle: "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete."),this.fire("setstyle",{layer:this})}}getStyle(){return this.dataSource.styleName}getStyleName(){return this.style.name}setTime(t){if(this.error)return C("setTime: failed: "+this.error),Promise.resolve([]);let e=bt(this.state.meta.times,t);if(this.state.time!==e){this.state.time=e,this.state.baseURL=this.state.originURI+this.state.instance+`{var}/${this.state.time}/{z}/{x}/{y}.${this.dataSource.ext}`,this.fire("settime",{layer:this,layerTime:e}),C("setTime: "+e+" for "+this.dataSource.name+" complete.");let n=this._reloadTiles();return n.then(()=>{let s=this.wxtiles.values().next().value;if(!(s==null?void 0:s.data.length))return;let[i,o]=this.state.minmax[0],{dmin:a,dmax:u}=s.data[0];(Math.abs(a-i)>.01||Math.abs(u-o)>.01)&&(this.state.minmax=s.data.map(h=>[h.dmin,h.dmax]),this._updateMinMax(),this.setStyle(void 0))}),n}return Promise.resolve([])}getTime(){return this.error?(C("getTime: failed: "+this.error),this.error):this.state.time}getTimes(){return this.error?(C("getTimes: failed: "+this.error),[]):this.state.meta.times}async checkDataChanged(){if(this.error)return C("checkDataChanged: failed: "+this.error),!1;let t=await A(this.state.originURI+"instances.json"),e=t[t.length-1]+"/";if(this.state.instance!==e)return!0;let n=await A(this.state.originURI+e+"meta.json");return this.state.meta.times.toString()!==n.times.toString()}reloadData(){return this._setUpDataSet(void 0)}getLegendData(t){if(!this.error){if(!this.clut){C("getLegendData: failed. Lazy setup not finished yet:"+this.dataSource.name);return}return H(t,this.style)}}setTimeAnimationMode(t=2){this.oldMaxZoom=this.state.meta.maxZoom;let e=this._map.getZoom(),s=(e<this.oldMaxZoom?e:this.oldMaxZoom)-t;this.state.meta.maxZoom=s<0?0:s}unsetTimeAnimationMode(){!this.oldMaxZoom||!this.state.meta.maxZoom||(this.state.meta.maxZoom=this.oldMaxZoom,this._reloadTiles())}getMinMax(){let[t,e]=this.state.minmax[0];return{min:t,max:e}}setAnimation(t){return t&&(this.animation=t,this._checkAndStartSlinesAnimation()),this.animation}async _setUpDataSet(t){t&&(this.dataSource=t),this._stopLoadingResetLoadDataFunc(),this.state.originURI=this.dataSource.serverURI+"/"+this.dataSource.dataset+"/";try{let e=await A(this.state.originURI+"instances.json");this.state.instance=e[e.length-1]+"/"}catch(e){return this.error=this.dataSource.name+": load instances.json error: "+e,C(this.error),!1}try{let e=this.state.originURI+this.state.instance+"meta.json";this.state.meta=await A(e)}catch(e){return this.error=this.dataSource.name+": load meta.json error: "+e,C(this.error),!1}return this.vector=this.dataSource.variables.length===2,this.animation=this.vector,this.state.units=this.state.meta.variablesMeta[this.dataSource.variables[0]].units,this.state.minmax=this.dataSource.variables.map(e=>[this.state.meta.variablesMeta[e].min,this.state.meta.variablesMeta[e].max]),this._updateMinMax(),this.error=null,t&&(this.setTime(Date.now()),this.setStyle(void 0)),!0}_updateMinMax(){if(!this.vector)return;let[[t,e],[n,s]]=this.state.minmax;this.state.minmax.unshift([0,1.42*Math.max(-t,e,-n,s)])}_checkZoom(){var t;((t=this._map)==null?void 0:t.getZoom())>this.state.meta.maxZoom||this._stopLoadingResetLoadDataFunc()}_onAddLayer(){var t,e;C("onadd:",this.dataSource.name),(t=this._map)==null||t.on("zoomstart",this._checkZoom,this),(e=this.setupCompletePromise)==null||e.then(()=>{this.redraw(),this._checkAndStartSlinesAnimation()})}_onRemoveLayer(){var t,e;C("onremove:",this.dataSource.name),(t=this._map)==null||t.off("zoomstart",this._checkZoom,this),(e=this.setupCompletePromise)==null||e.then(()=>{this._stopLoadingResetLoadDataFunc(),this._stopSlinesAnimation()})}_stopLoadingResetLoadDataFunc(){var t;(t=this.loadData)==null||t.abort(),this.loadData=j()}_checkAndStartSlinesAnimation(){if(this.animFrame||!this.animation||!this.vector||!this.style.streamLineColor||this.style.streamLineColor==="none")return;let t=e=>{if(!this.animation||this.style.streamLineStatic){this._stopSlinesAnimation();return}this.wxtiles.forEach(n=>n.drawSLines(e)),this.animFrame=requestAnimationFrame(t)};t(0)}_stopSlinesAnimation(){cancelAnimationFrame(this.animFrame),this.wxtiles.forEach(t=>t.clearSLinesCanvas()),this.animFrame=0}_redrawTiles(){!this.wxtiles||this.animationRedrawID!==0||(this.animationRedrawID=requestAnimationFrame(()=>{this.wxtiles.forEach(t=>t.draw()),this.animationRedrawID=0}))}_reloadTiles(){let t=Array.from(this.wxtiles.values()).map(n=>n.load()),e=Promise.all(t);return e.then(()=>this._redrawTiles()),e}};function kt(r){return new _(r)}var V=class extends z.default.Control{constructor(t){super(t);this.URI=t.URI}onAdd(){let t=document.createElement("img");return t.src=this.URI,t.className="wxtiles-logo",t}};function Jt(r){return C("Add watermark:",JSON.stringify(r)),new V(r)}var $=class extends z.default.GridLayer{createTile(t){let e=document.createElement("div");return e.innerHTML=[t.x,t.y,t.z].join(", "),e.style.outline="1px solid red",e}};function Yt(){return C("Add WxDebugCoordsLayer:"),new $().setZIndex(1e3)}function te(r,t){return z.default.layerGroup(r.map(kt),t)}return ee;})();
|
|
1
|
+
var wxtilesjs=(()=>{var Ae=Object.create;var k=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames,$=Object.getOwnPropertySymbols,Re=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty,Ue=Object.prototype.propertyIsEnumerable;var Y=(r,e,t)=>e in r?k(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,ee=(r,e)=>{for(var t in e||(e={}))J.call(e,t)&&Y(r,t,e[t]);if($)for(var t of $(e))Ue.call(e,t)&&Y(r,t,e[t]);return r};var te=r=>k(r,"__esModule",{value:!0});var nt=typeof require!="undefined"?require:r=>{throw new Error('Dynamic require of "'+r+'" is not supported')};var Pe=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),We=(r,e)=>{te(r);for(var t in e)k(r,t,{get:e[t],enumerable:!0})},Fe=(r,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of _e(e))!J.call(r,n)&&n!=="default"&&k(r,n,{get:()=>e[n],enumerable:!(t=Ie(e,n))||t.enumerable});return r},re=r=>Fe(te(k(r!=null?Ae(Re(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var N=Pe((at,ne)=>{ne.exports=window.L});var rt={};We(rt,{CreateWxDebugCoordsLayer:()=>et,CreateWxTilesGroupLayer:()=>tt,CreateWxTilesLayer:()=>ke,CreateWxTilesWatermark:()=>Ye,LoadQTree:()=>Se,WxDebugLayer:()=>X,WxGetColorStyles:()=>P,WxTilesLayer:()=>_,WxTilesLibSetup:()=>le,WxTilesLogging:()=>xe,WxWatermark:()=>V});var H=re(N());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 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",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"}};var Z,ie,ae;function le({colorStyles:r={},units:e={},colorSchemes:t={}}={}){g("WxTile lib setup: start"),Z=Object.assign({},se,e),ie=Object.assign({},t,oe);let n=Object.assign({},r,U);ae=Ee(n),g("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),g("WxTile lib setup is done.")}function P(){return ae}function ce(){return ie}function W(r,e,t){let n=t?Object.assign({},Z,t):Z;if(!n||!r||!e||r===e||!n[r]||!n[e]||n[r][0]!==n[e][0]){g(r===e?"Trivial converter:":"Inconvertible units. Default converter is used:",r," -> ",e);let o=l=>l;return o.trivial=!0,o}g("Converter: From:",r," To:",e);let s=n[r][1]/n[e][1],i=(n[r][2]||0)/n[e][1]-(n[e][2]||0)/n[e][1];return i?o=>s*o+i:o=>s*o}function Ee(r){let e=Object.assign({},U);for(let s in r){let i=r[s];if(Array.isArray(i))for(let o=0;o<i.length;++o)e[s+"["+o+"]"]=Object.assign({},i[o]);else e[s]=Object.assign({},i)}let t=(s,i)=>{if(i==="base")return U.base;let o=s[i];(!o.parent||!(o.parent in s))&&(o.parent="base");let l=t(s,o.parent);return Object.assign(o,Object.assign({},l,o,{parent:"base"}))},n={};for(let s in e)n[s]=t(e,s);return n}function me(r){let e=new Map;return t=>{let n=e.get(t);return n===void 0&&(n=r(t),e.set(t,n),n instanceof Promise&&n.catch(s=>{s instanceof DOMException&&e.delete(t)})),n}}async function He(r,e){let{signal:t}=e.controller;var n;let s=await(await fetch(r,{signal:t})).blob(),i=new Image;if(!t.aborted){let o=URL.createObjectURL(s);i.src=o,await i.decode(),URL.revokeObjectURL(o)}return i}function Be(r){let{width:e,height:t}=r,n=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d");if(!n)throw"catastrophe";return n.drawImage(r,0,0),n.getImageData(0,0,e,t)}async function ue(r,e){return Be(await He(r,e))}function Ne(r,e){let t=n=>{let s=new Uint16Array(n.data.buffer),i=new Uint16Array(s.length/2);for(let a=0;a<i.length;a++)i[a]=s[a*2];let o=new Uint8Array(n.data.buffer);for(let a=0;a<8;++a)o[a]=o[a*4+2];let l=new DataView(n.data.buffer),u=l.getFloat32(0,!0),f=l.getFloat32(4,!0),b=(f-u)/65535,c=Ze(i);return{raw:i,dmin:u,dmax:f,dmul:b,integral:c,radius:0}};return ue(r,e).then(t)}function j(){let r={controller:new AbortController},e=me(t=>Ne(t,r));return e.controllerHolder=r,e}function fe(r){let e={controller:r},t=me(n=>ue(n,e));return t.controllerHolder=e,t}function Ze(r){let e=new Uint32Array(258*258),t=new Uint32Array(258*258);e[0]=r[0],t[0]=r[0]===0?0:1;for(let n=1;n<258;++n)e[n]=r[n]+e[n-1],e[258*n]=r[258*n]+e[258*n-258],t[n]=(r[n]===0?0:1)+t[n-1],t[258*n]=(r[258*n]===0?0:1)+t[258*n-258];for(let n=1,s=259;n<258;++n,++s)for(let i=1;i<258;++i,++s)e[s]=r[s]+e[s-258]+e[s-1]-e[s-258-1],t[s]=(r[s]===0?0:1)+t[s-258]+t[s-1]-t[s-258-1];return{integral:e,integralNZ:t}}function de(r,e){if(e<0||e===r.radius)return r;r.radius=e;let t=258,{integral:n,integralNZ:s}=r.integral;for(let i=1;i<t;i++)for(let o=1;o<t;o++){if(!r.raw[t*i+o])continue;let l=Math.min(e,o-1,t-1-o),u=Math.min(e,i-1,t-1-i),f=t*(i-u-1)+o,b=t*(i+u)+o,c=s[f-l-1],a=s[f+l],d=s[b-l-1],h=s[b+l],m=c+h-a-d,p=n[f-l-1],x=n[f+l],y=n[b-l-1],S=n[b+l],C=p+S-x-y;r.raw[i*t+o]=C/m}return r}function w(r){let e=r>>0&255,t=r>>8&255,n=r>>16&255,s=e.toString(16),i=t.toString(16),o=n.toString(16);return s=s.length===2?s:"0"+s,i=i.length===2?i:"0"+i,o=o.length===2?o:"0"+o,"#"+s+i+o}function T(r){if(r[0]==="#"){if(r.length===4)return+("0xff"+r[3]+r[3]+r[2]+r[2]+r[1]+r[1]);if(r.length===7)return+("0xff"+r[5]+r[6]+r[3]+r[4]+r[1]+r[2]);if(r.length===9)return+("0x"+r[7]+r[8]+r[5]+r[6]+r[3]+r[4]+r[1]+r[2])}return g("wrong color format",r),0}async function A(r,e){return(await fetch(r,e)).json()}function L(r,e="",t){var s;let n=document.createElement(r);return n.className=e,t&&((s=t.appendChild)==null||s.call(t,n)),n}function O(r,e,t){let n=r>>0&255,s=r>>8&255,i=r>>16&255,o=r>>>24,l=e>>0&255,u=e>>8&255,f=e>>16&255,b=e>>>24,c=n+t*(l-n),a=s+t*(u-s),d=i+t*(f-i),h=o+t*(b-o);return c|a<<8|d<<16|h<<24}function he(r,e,t){let n=[];for(let s=0;s<t;++s)n.push(s*(e-r)/(t-1)+r);return n}function be(r,e){let t=typeof e=="number"?e:typeof e=="string"?new Date(e).getTime():e.getTime();return r.find(n=>new Date(n).getTime()>=t)||r[r.length-1]}var ge=!1;function xe(r){console.log(r?"Logging on":"Logging off"),ge=r}function g(...r){ge&&console.trace(...r)}var De=re(N());function je(r,e,t){return r>t?t:r<e?e:r}var F=class{constructor(e,t,[n,s],i){let o=s-n;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let l=[];this.DataToStyle=W(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),i&&(this.DataToKnots=W(t,"knot"));let u=W(e.units,t,e.extraUnits),f=m=>~~(65535*je((u(m)-n)/(s-n),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((m,p)=>m[0]<p[0]?-1:m[0]>p[0]?1:0);for(let[m]of e.colorMap)l.push(f(m))}else{if(e.levels||(e.levels=he(this.DataToStyle(n),this.DataToStyle(s),10)),e.levels.sort((m,p)=>m<p?-1:m>p?1:0),!e.colors){let m=ce();e.colorScheme&&e.colorScheme in m?e.colors=m[e.colorScheme]:e.colors=m.wb}for(let m of e.levels)l.push(f(m))}let b=65536,c=z(b,e);this.ticks=c.ticks;let a=c.ticks[0].data,h=c.ticks[c.ticks.length-1].data-a;for(let m=0;m<65536;++m){let p=o*m/65535+n,x=this.DataToStyle(p),y=Math.round((b-1)*(x-a)/h);y<=0?this.colorsI[m]=e.showBelowMin?c.colors[0]:0:y>=b?this.colorsI[m]=e.showAboveMax?c.colors[b-1]:0:this.colorsI[m]=c.colors[y]}this.colorsI[0]=0;for(let m=0;m<l[0];++m)this.levelIndex[m]=0;for(let m=0;m<l.length-1;m++)for(let p=l[m];p<l[m+1]+1;++p)this.levelIndex[p]=m;for(let m=l[l.length-1];m<65536;++m)this.levelIndex[m]=l.length-1}};function ye(r){var t;if(r!==0&&-.1<r&&r<.1)return r.toExponential(2);let e=r.toString();return((t=e.split(".")[1])==null?void 0:t.length)>2?r.toFixed(2):e}function z(r,e){let t={size:r,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(r),ticks:[]},{colorMap:n,levels:s,colors:i}=e,o=e.fill!=="solid";if(n){let a=n[0][0],d=n[n.length-1][0]-a;for(let[h,m]of n){let p=~~((h-a)/d*(r-1)),x={data:h,dataString:ye(h),color:m,pos:p};t.ticks.push(x)}for(let h=0;h<n.length-1;h++){let m=t.ticks[h].pos,p=t.ticks[h+1].pos,x=T(n[h][1]),y=o?T(n[h+1][1]):0;for(let S=m;S<p;++S)t.colors[S]=o?O(x,y,(S-m)/(p-m)):x}return t.colors[r-1]=T(n[n.length-1][1]),t}if(!i||!s)return t;let l=0,u=0,f=-1;for(let a=0;a<r;++a){let d=a*(i.length-1)/r;f!==~~d&&(f=~~d,l=T(i[f]),u=i.length>f+1?T(i[f+1]):l),t.colors[a]=o?O(l,u,d-f):l}t.colors[r-1]=T(i[i.length-1]);let b=s[0],c=(r-1)/(s[s.length-1]-b);for(let a of s){let d=~~((a-b)*c),h={data:a,dataString:ye(a),color:w(t.colors[d]),pos:d};t.ticks.push(h)}return t}var Q=256,Oe=2*Math.PI*6378137/Q,E=2*Math.PI*6378137/2;function ze(r,e){let t=r/E*180,n=e/E*180;return n=180/Math.PI*(2*Math.atan(Math.exp(n*Math.PI/180))-Math.PI/2),[n,t]}function Qe(r,e,t){let n=Ge(t),s=r*n-E,i=e*n-E;return[s,i]}function Ge(r){return Oe/Math.pow(2,r)}function G(r,e,t){let[n,s]=ze(...Qe(r,e,t));return[s,-n]}function pe(r,e){return[r*Q,e*Q]}var qe="A".charCodeAt(0),q,D=0;async function Se(r,e){let t;try{t=await(await fetch(r,e)).json()}catch(n){console.log("Can't load QTree:",n);return}q=I(t,{pos:0}),D=Ce(q),console.log("Loaded QTree, depth:",D)}function I(r,e){let t=r.charCodeAt(e.pos)-qe;e.pos++;let n=t&1?I(r,e):null,s=t&2?I(r,e):null,i=t&4?I(r,e):null,o=t&8?I(r,e):null;return{sub:n||s||i||o?[n,s,i,o]:null}}function Ce(r){let e=0;if(r==null?void 0:r.sub){for(let t=0;t<4;t++)if(r.sub[t]!==null){let n=Ce(r.sub[t])+1;e<n&&(e=n)}}return e}var v;(function(n){n.Land="land",n.Mixed="mixed",n.Sea="sea"})(v||(v={}));function we(r){if(!D)return v.Mixed;let e=ee({},r),t=!1;if(D<=r.z){t=!0;let n=r.z-D;e={x:r.x>>n,y:r.y>>n,z:D}}return Te(q,e,t)}function Te(r,e,t){if(r===null)return v.Land;if(t&&e.z===0)return v.Mixed;if(r.sub===null)return v.Sea;if(e.z===0)return v.Mixed;e.z--;let n=e.x>>e.z&1,i=(e.y>>e.z&1)<<1|n;return Te(r.sub[i],e,t)}function Ke(r,e){if(!e)return r;let t=.9999999/Math.pow(2,e.z),n=e.x*256*t,s=e.y*256*t,i={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:o}=i;for(let l=-1,u=0;l<=256;l++){let f=s+l*t,b=Math.floor(f),c=f-b;for(let a=-1;a<=256;a++,u++){let d=n+a*t,h=Math.floor(d),m=d-h,p=h+1+(b+1)*258,x=r.raw[p],y=r.raw[p+1],S=r.raw[p+258],C=r.raw[p+258+1];switch((x?1:0)|(y?2:0)|(S?4:0)|(C?8:0)){case 0:o[u]=0;continue;case 1:o[u]=x;continue;case 2:o[u]=y;continue;case 3:S=x,C=y;break;case 4:o[u]=S;continue;case 5:y=x,C=S;break;case 6:C=y+S>>1,x=C;break;case 7:C=y+S>>1;break;case 8:o[u]=C;continue;case 9:y=x+C>>1,S=y;break;case 10:x=y,S=C;break;case 11:S=x+C>>1;break;case 12:x=S,y=C;break;case 13:y=x+C>>1;break;case 14:x=y+S>>1;break}x=r.dmin+r.dmul*x,y=r.dmin+r.dmul*y,S=r.dmin+r.dmul*S,C=r.dmin+r.dmul*C;let R=K(x,y,m),M=K(S,C,m);o[u]=(K(R,M,c)-r.dmin)/r.dmul,o[u]===0&&(o[u]=1)}}return i}function K(r,e,t){let n=((e-r)%360+540)%360-180;return(r+n*t+360)%360}function Ve(r,e){if(!e)return r;let t=.9999999/Math.pow(2,e.z),n=e.x*256*t,s=e.y*256*t,i={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:o}=i;for(let l=-1,u=0;l<=256;l++){let f=s+l*t,b=Math.floor(f),c=f-b;for(let a=-1;a<=256;a++,u++){let d=n+a*t,h=Math.floor(d),m=d-h,p=h+1+(b+1)*258,x=r.raw[p],y=r.raw[p+1],S=r.raw[p+258],C=r.raw[p+258+1];switch((x?1:0)|(y?2:0)|(S?4:0)|(C?8:0)){case 7:o[u]=m+c<1?m*(y-x)+c*(S-x)+x:0;continue;case 14:o[u]=m+c<1?0:m*(C-S)+c*(C-y)+y+S-C;continue;case 11:o[u]=c<m?(1-m)*(x-y)+c*(C-y)+y:0;continue;case 13:o[u]=c<m?0:(1-m)*(S-C)+c*(S-x)+x+C-S;continue;case 15:o[u]=m+c<1?m*(y-x)+c*(S-x)+x:m*(C-S)+c*(C-y)+y+S-C;continue;default:o[u]=0}}}return i}function Xe(r,e,t){let n=t==="land"?1:0;for(let s=3,i=0;i<256;i++)for(let o=0;o<256;o++,s+=4){let l=e.data[s]?1:0;n^l&&(r.raw[(i+1)*258+(o+1)]=0)}return r}function $e(r){let[e,t]=pe(r.x,r.y),[n,s]=G(e,t,r.z),[i,o]=G(e+256,t+256,r.z);return{west:n,north:s,east:i,south:o}}function ve({layer:r,coords:e,done:t}){let n=L("div","leaflet-tile s-tile");return n.wxtile=new Le({layer:r,coords:e,tileEl:n}),n.wxtile.load().then(s=>{s.draw(),t()}),n}var Le=class{constructor({layer:e,coords:t,tileEl:n}){this.data=[];this.sLines=[];this.coords=t,this.layer=e,this.canvasFill=L("canvas","s-tile canvas-fill",n),this.canvasSlines=L("canvas","s-tile canvas-slines",n),this.canvasVector=this.canvasFill,this.canvasFill.width=this.canvasFill.height=this.canvasSlines.width=this.canvasSlines.height=256;function s(i){let o=i.getContext("2d");if(!o)throw"error";return o}this.canvasFillCtx=s(this.canvasFill),this.imData=this.canvasFillCtx.createImageData(256,256),this.canvasSlinesCtx=s(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasSlinesCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVector(),this._drawDegree(),this._drawStaticSlines())}clearSLinesCanvas(){this.canvasSlinesCtx.clearRect(0,0,256,256)}drawSLines(e){if(this.sLines.length===0)return;let t=this.canvasSlinesCtx;if(t.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.sLines=[];return}let n=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let s=0;s<this.sLines.length;++s){let i=this.sLines[s],o=i.length-1,l=(e+(1+i[0].x)*(1+i[0].y))%30;for(let u=0;u<o;++u){let f=i[u],b=i[u+1],c=1-(l-u)/o;(c<0||c>1)&&(c=0);let a=(~~(c*255)).toString(16);t.strokeStyle=n+(a.length<2?"0"+a:a);let d=1+~~((1.2-c)*5);t.lineWidth=d,t.beginPath(),t.moveTo(f.x,f.y),t.lineTo(b.x,b.y),t.stroke()}}}getData({x:e,y:t}){if(!this.data.length)return;let n=this.data[0].raw[(t+1)*258+(e+1)];return{raw:n,data:this.data[0].dmin+this.data[0].dmul*n}}async load(){var c;let{coords:e,layer:t}=this,{boundaries:n}=t.state.meta,s=this.layer.style.mask;var i;if((s==="land"||s==="sea")&&(i=we(e),s===i))return this.data=[],this.sLines=[],this;if(n==null?void 0:n.boundaries180){let a=$e(e),d=h=>!(a.west>h.east||h.west>a.east||a.south>h.north||h.south>a.north);if(!n.boundaries180.some(d))return this.data=[],this.sLines=[],this}let{upCoords:o,subCoords:l}=this._splitCoords(e),u=this._coordsToURLs(o),f;try{f=await Promise.all(u.map(t.loadData))}catch(a){return this}let b=((c=t.state)==null?void 0:c.units)==="degree"?Ke:Ve;if(this.data=f.map(a=>b(de(a,this.layer.style.blurRadius),l)),this.layer.vector&&this._vectorPrepare(),s&&i===v.Mixed){let a=t.state.maskServerURI.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));try{let d=await t.loadMask(a);Xe(this.data[0],d,s)}catch(d){this.layer.style.mask=void 0,g("Can't load Mask. Turned off")}}return this.layer.vector&&this._createSLines(),this}_splitCoords(e){let t=e.z-this.layer.state.meta.maxZoom;if(t<=0)return{upCoords:e};let n={x:e.x>>>t,y:e.y>>>t,z:this.layer.state.meta.maxZoom},s={x:e.x&(1<<t)-1,y:e.y&(1<<t)-1,z:t};return{upCoords:n,subCoords:s}}_coordsToURLs(e){let t=this.layer.state.baseURL.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));return this.layer.dataSource.variables.map(n=>t.replace("{var}",n))}_vectorPrepare(){if(this.data.length!==2)throw"this.data !== 2";this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[e,t,n]=this.data;e.dmax=1.42*Math.max(-t.dmin,t.dmax,-n.dmin,n.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let s=0;s<258*258;++s){if(!t.raw[s]||!n.raw[s]){e.raw[s]=0;continue}let i=t.dmin+t.dmul*t.raw[s],o=n.dmin+n.dmul*n.raw[s];e.raw[s]=Math.sqrt(o*o+i*i)/e.dmul}}_drawFillAndIsolines(){let{imData:e}=this,{canvasFillCtx:t}=this,n=new Uint32Array(e.data.buffer),{raw:s}=this.data[0],{clut:i,style:o}=this.layer,{levelIndex:l,colorsI:u}=i;if(o.fill!=="none"){let b=u;for(let c=0,a=0,d=259;c<256;++c,d+=2)for(let h=0;h<256;++h,++a,++d)n[a]=b[s[d]]}else n.fill(0);let f=[];if(o.isolineColor!=="none"){let b=o.isolineColor[0]==="#"?T(o.isolineColor):0;for(let c=0,a=0;c<256;c+=1)for(let d=0;d<256;d+=1){let h=(c+1)*258+(d+1),m=s[h],p=s[h+1],x=s[h+258];if(!m||!p||!x)continue;let y=l[m],S=l[p],C=l[x];if(y!==S||y!==C){let B=Math.max(y,S,C),R=Math.max(m,p,x),M=c*256+d;switch(o.isolineColor){case"inverted":n[M]=~u[R]|4278190080;break;case"fill":n[M]=u[R]|4278190080;break;default:n[M]=b;break}o.isolineText&&!(++a%255)&&d>20&&d<235&&c>20&&c<235&&f.push({x:d,y:c,d:m,dr:p,db:x,mli:B})}}}if(t.putImageData(e,0,0),!f.length){t.font="1.1em Sans-serif",t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";for(let{x:b,y:c,d:a,dr:d,db:h,mli:m}of f){let p=this.layer.clut.ticks[m].dataString,x=Math.atan2(a-d,h-a);t.save(),t.translate(b,c),t.rotate(x<-1.57||x>1.57?x+3.14:x),t.strokeText(p,0,0),t.fillText(p,0,0),t.restore()}}}_drawStaticSlines(){if(!this.sLines.length||!this.layer.style.streamLineStatic)return;let{canvasSlinesCtx:e}=this;if(this.layer.style.streamLineColor==="none"){this.sLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let t=this.sLines.length;t--;){let n=this.sLines[t];for(let s=0;s<n.length-1;++s){let i=n[s],o=n[s+1];e.moveTo(i.x,i.y),e.lineTo(o.x,o.y)}}e.stroke()}_drawVector(){if(!this.layer.vector||!this.layer.clut.DataToKnots||!this.layer.style.vectorColor||this.layer.style.vectorColor==="none"||!this.layer.style.vectorType||this.layer.style.vectorType==="none")return;if(this.data.length!==3)throw"this.data.length !== 3";let[e,t,n]=this.data,{canvasVectorCtx:s}=this;switch(this.layer.style.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=this.layer.style.vectorType}s.textAlign="center",s.textBaseline="middle";let i=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0,o=32;for(let l=o/2;l<256;l+=o)for(let u=o/2;u<256;u+=o){let f=u+1+(l+1)*258;if(!e.raw[f])continue;let b=Math.atan2(t.dmin+t.raw[f]*t.dmul,n.dmin+n.raw[f]*n.dmul),c=e.dmin+e.raw[f]*e.dmul,a=this.layer.dataSource.variables[0].includes("current")?5:.2,d=Math.min(this.layer.clut.DataToKnots(c)*a,25)+65,h=String.fromCharCode(d);switch(this.layer.style.vectorColor){case"inverted":s.fillStyle=w(~this.layer.clut.colorsI[e.raw[f]]);break;case"fill":s.fillStyle=w(this.layer.clut.colorsI[e.raw[f]]);break;default:s.fillStyle=this.layer.style.vectorColor;break}s.save(),s.translate(u,l),s.rotate(b+i),s.fillText(h,0,0),s.restore()}}_drawDegree(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:e}=this,t=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle";let n=this.data[0],s="L",i=32;for(let o=i/2;o<256;o+=i)for(let l=i/2;l<256;l+=i){let u=l+1+(o+1)*258;if(!n.raw[u])continue;let b=(n.dmin+n.raw[u]*n.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=w(~this.layer.clut.colorsI[n.raw[u]]);break;case"fill":e.fillStyle=w(this.layer.clut.colorsI[n.raw[u]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(l,o),e.rotate(b+t),e.fillText(s,0,0),e.restore()}}_createSLines(){if(this.data.length!==3)throw"this.data.length !== 3";if(!this.layer.style.streamLineColor||this.layer.style.streamLineColor==="none")return;let e=this.layer.style.streamLineSpeedFactor||1;this.sLines=[];let[t,n,s]=this.data,i=Math.max(this.coords.z-this.layer.state.meta.maxZoom,0),o=Math.min(2**(i+5),128),l=~~(120+i*60);for(let u=0;u<=256;u+=o)for(let f=0;f<=256;f+=o){if(!t.raw[1+f+(1+u)*258])continue;let b=[],c=f,a=u;for(let d=0;d<=l&&c>=0&&c<=256&&a>=0&&a<=256;d++){!(d%(l/6))&&b.push({x:~~c,y:~~a});let h=~~c+1+(~~a+1)*258;if(!t.raw[h])break;c+=e*(n.dmin+n.raw[h]*n.dmul)/t.dmax,a-=e*(s.dmin+s.raw[h]*s.dmul)/t.dmax}c=f,a=u;for(let d=1;d<=l&&c>=0&&c<=256&&a>=0&&a<=256;d++){!(d%(l/6))&&b.unshift({x:~~c,y:~~a});let h=~~c+1+(~~a+1)*258;if(!t.raw[h])break;c-=e*(n.dmin+n.raw[h]*n.dmul)/t.dmax,a+=e*(s.dmin+s.raw[h]*s.dmul)/t.dmax}b.length>2&&this.sLines.push(b)}}};var Me="setup not complete",Je=fe(new AbortController),_=class extends De.default.GridLayer{constructor({dataSource:e,options:t,lazy:n}){super(t);this.styles=P();this.style=Object.assign({},this.styles.base);this.loadData=j();this.loadMask=Je;this.error=Me;this.vector=!1;this.clut=new F(this.style,"",[0,2],!1);this.animation=!1;this.lastBaseURL="";this.animationRedrawID=0;this.animFrame=0;this.oldMaxZoom=0;if(g("Creating a WxTilex layer:",e.name,". Params:",JSON.stringify({dataSource:e,options:t})),!e||!e.ext||!e.dataset||!e.name||!e.serverURI||!e.styleName||!Array.isArray(e.variables))throw g("dataSource is wrong!"),"dataSource is wrong!";this.dataSource=e,this.state={maskServerURI:e.maskServerURI||e.serverURI.replace(/\/data\/?/i,"/mask/{z}/{x}/{y}"),units:"undefined",baseURL:"undefined",meta:{maxZoom:0,times:["undefined"],variables:["undefined"],variablesMeta:{}},instance:"undefined",minmax:[[0,1]],originURI:"undefined",time:"undefined"},this.setupCompletePromise=new Promise(s=>{let i=()=>{g("Setup:",e.name),this.on("remove",this._onRemoveLayer,this),this.on("add",this._onAddLayer,this),this._setUpDataSet(e).then(o=>{g("Setup complete:",this.dataSource.name,". Result:",o),this._map&&n&&this._onAddLayer(),this.fire("setupcomplete",{layer:this}),s(o)})};n?this.once("add",i):i()})}createTile(e,t){return this.error&&this.error!==Me?(setTimeout(t),Object.assign(L("div","error-tile"),{innerHTML:this.error})):this.state.baseURL==="undefined"?(setTimeout(t),L("div","error-tile")):ve({layer:this,coords:e,done:t})}getSetupCompletePromise(){return this.setupCompletePromise}getTile(e){if(!this._map||this.error)return;let t=this._map.getZoom(),{x:n,y:s}=this._map.project(e,t),i={x:~~(n/256),y:~~(s/256)},o=this._getCachedTile(i.x,i.y,t);if(!o)return;let l={x:~~(n-i.x*256),y:~~(s-i.y*256)},u=o.getData(l);if(!u)return;let{raw:f,data:b}=u,c=this.clut.colorsI[f],a=w(c),d=this.clut.DataToStyle(b);return{tile:o,data:b,raw:f,rgba:c,hexColor:a,inStyleUnits:d,tilePoint:l,units:this.style.units}}setStyle(e){if(g("setStyle(",e,") for ",this.dataSource.name),this.error){g("setStyle: failed: "+this.error);return}if(!(this.dataSource.styleName===e&&e!=="custom")){if(e&&(this.dataSource.styleName=e),e==="custom"&&this.styles.custom){(!this.styles.custom.parent||!(this.styles.custom.parent in this.styles))&&(this.styles.custom.parent="base");let t=this.styles[this.styles.custom.parent];this.styles.custom=Object.assign(Object.assign({},t),this.styles.custom)}this.dataSource.styleName in this.styles?Array.isArray(this.styles[this.dataSource.styleName])&&(this.dataSource.styleName+="[0]"):(g(`cant find the style (${this.dataSource.styleName})`),this.dataSource.styleName+="[0]",this.dataSource.styleName in this.styles||(g(`cant find the style (${this.dataSource.styleName}), default is used`),this.dataSource.styleName="base"));try{let t=this.styles[this.dataSource.styleName];this.style=Object.assign({},t);let n=this.style.streamLineColor;n!=="none"&&n.length<7&&(this.style.streamLineColor="#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]);let s=this.state.minmax[0];this.clut=new F(this.style,this.state.units,s,this.vector)}catch(t){let n="setStyle: impossible error in RawCLUT: "+t;throw g(n),n}e&&(this._checkAndStartSlinesAnimation(),this._reloadTiles()),g("setStyle(",e,'): "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete."),this.fire("setstyle",{layer:this})}}getStyle(){return this.dataSource.styleName}getStyleName(){return this.style.name}setTime(e){if(g("setTime: "+e+" for "+this.dataSource.name+" start"),this.error)return g("setTime: failed: "+this.error),Promise.resolve([]);let t=be(this.state.meta.times,e);if(this.state.time===t)return g("setTime: the same time - skipped"),Promise.resolve([]);if(this.state.time=t,this.state.baseURL=this.state.originURI+this.state.instance+`{var}/${this.state.time}/{z}/{x}/{y}.${this.dataSource.ext}`,this.fire("settime",{layer:this,layerTime:t}),g("setTime: "+t+" for "+this.dataSource.name+" complete"),!this._tiles)return Promise.resolve([]);let n=this._reloadTiles(!1);return n.then(()=>{let s=Object.values(this._tiles);for(let i of s){let o=(i==null?void 0:i.el).wxtile;if(o==null?void 0:o.data.length){let[l,u]=this.state.minmax[0],{dmin:f,dmax:b}=o.data[0];(Math.abs(f-l)>.01||Math.abs(b-u)>.01)&&(this.state.minmax=o.data.map(c=>[c.dmin,c.dmax]),this.setStyle(void 0));break}}this._redrawTiles()}),n}getTime(){return this.error?(g("getTime: failed: "+this.error),this.error):this.state.time}getTimes(){return g("getTimes"),this.error?(g("getTimes: failed: "+this.error),[]):this.state.meta.times}async checkDataChanged(){if(g("checkDataChanged"),this.error)return g("checkDataChanged: failed: "+this.error),!1;let e=await A(this.state.originURI+"instances.json"),t=e[e.length-1]+"/";if(this.state.instance!==t)return!0;let n=await A(this.state.originURI+t+"meta.json");return this.state.meta.times.toString()!==n.times.toString()}reloadData(){return g("reloadData"),this._setUpDataSet(void 0)}getLegendData(e){return g("getLegendData"),(this.error||!this.clut)&&g("getLegendData: failed. "+this.dataSource.name+" : "+this.error),z(e,this.style)}setTimeAnimationMode(e=2){g("setTimeAnimationMode"),this.oldMaxZoom=this.state.meta.maxZoom;let t=this._map.getZoom(),s=(t<this.oldMaxZoom?t:this.oldMaxZoom)-e;this.state.meta.maxZoom=s<0?0:s}unsetTimeAnimationMode(){return g("unsetTimeAnimationMode"),this.oldMaxZoom&&(this.state.meta.maxZoom=this.oldMaxZoom,this.lastBaseURL=""),this._reloadTiles()}getMinMax(){let[e,t]=this.state.minmax[0];return{min:e,max:t}}setAnimation(e){return g("setAnimation"),this.animation=e,this._checkAndStartSlinesAnimation(),this.animation}_getCachedTile(e,t,n){var s,i;return(i=(s=this._tiles[`${e}:${t}:${n}`])==null?void 0:s.el)==null?void 0:i.wxtile}_ForEachTile(e){var n;let t=[];for(let s in this._tiles){let i=(n=this._tiles[s].el)==null?void 0:n.wxtile,o=i&&e(i);o&&t.push(o)}return t}async _setUpDataSet(e){e&&(this.dataSource=e),this._stopLoadingResetLoadDataFunc(),this.state.originURI=this.dataSource.serverURI+"/"+this.dataSource.dataset+"/";try{let t=await A(this.state.originURI+"instances.json");this.state.instance=t[t.length-1]+"/"}catch(t){return this.error=this.dataSource.name+": load instances.json error: "+t,g(this.error),!1}try{let t=this.state.originURI+this.state.instance+"meta.json";this.state.meta=await A(t)}catch(t){return this.error=this.dataSource.name+": load meta.json error: "+t,g(this.error),!1}if(this.vector=this.dataSource.variables.length===2,this.animation=this.vector,this.state.units=this.state.meta.variablesMeta[this.dataSource.variables[0]].units,this.state.minmax=this.dataSource.variables.map(t=>[this.state.meta.variablesMeta[t].min,this.state.meta.variablesMeta[t].max]),this.vector){let[[t,n],[s,i]]=this.state.minmax;this.state.minmax.unshift([0,1.42*Math.max(-t,n,-s,i)])}return this.error=null,e&&(this.setStyle(void 0),await this.setTime(new Date)),!0}_checkZoom(){var e;((e=this._map)==null?void 0:e.getZoom())>this.state.meta.maxZoom||this._stopLoadingResetLoadDataFunc()}_onAddLayer(){var e;g("onadd:",this.dataSource.name),(e=this._map)==null||e.on("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this.redraw(),this._checkAndStartSlinesAnimation()})}_onRemoveLayer(){var e;g("onremove:",this.dataSource.name),(e=this._map)==null||e.off("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this._stopLoadingResetLoadDataFunc(),this._stopSlinesAnimation()})}_stopLoadingResetLoadDataFunc(){this.loadData.controllerHolder.controller.abort(),this.loadData=j()}_checkAndStartSlinesAnimation(){if(this.animFrame||!this.animation||!this.vector||!this.style.streamLineColor||this.style.streamLineColor==="none")return;let e=t=>{if(!this.animation||this.style.streamLineStatic){this._stopSlinesAnimation();return}this._ForEachTile(n=>n.drawSLines(t)),this.animFrame=requestAnimationFrame(e)};e(0)}_stopSlinesAnimation(){cancelAnimationFrame(this.animFrame),this._ForEachTile(e=>e.clearSLinesCanvas()),this.animFrame=0}_redrawTiles(){this.animationRedrawID===0&&(this.animationRedrawID=requestAnimationFrame(()=>{g("_redrawTiles: requestAnimationFrame: "+this.dataSource.name),this._ForEachTile(e=>e.draw()),this.animationRedrawID=0}))}_reloadTiles(e=!0){if(g("_reloadTiles: start - "+this.dataSource.name),this.lastBaseURL===this.state.baseURL)return g("_reloadTiles: same URL. Nothing to reload"),Promise.resolve([]);this.loadData.controllerHolder.controller.abort(),this.loadData.controllerHolder.controller=new AbortController,this.lastBaseURL=this.state.baseURL;let t=this._ForEachTile(i=>i.load()),n=Promise.all(t),{controller:s}=this.loadData.controllerHolder;return e&&n.then(()=>s.signal.aborted||this._redrawTiles()),g("_reloadTiles: finished - "+this.dataSource.name),n}};function ke(r){return new _(r)}var V=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 Ye(r){return g("Add watermark:",JSON.stringify(r)),new V(r)}var X=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 et(){return g("Add WxDebugCoordsLayer:"),new X().setZIndex(1e3)}function tt(r,e){return H.default.layerGroup(r.map(ke),e)}return rt;})();
|
package/package.json
CHANGED
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import 'leaflet/dist/leaflet.css';
|
|
2
|
+
import L from 'leaflet'; // goes first always!
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
WxTilesLogging,
|
|
6
|
+
WxTilesLibSetup,
|
|
7
|
+
CreateWxTilesWatermark,
|
|
8
|
+
CreateWxTilesLayer,
|
|
9
|
+
CreateWxDebugCoordsLayer,
|
|
10
|
+
WxGetColorStyles,
|
|
11
|
+
WxTilesLayer,
|
|
12
|
+
LoadQTree,
|
|
13
|
+
Meta,
|
|
14
|
+
Legend,
|
|
15
|
+
ColorStylesStrict,
|
|
16
|
+
} from '../src/wxtiles';
|
|
17
|
+
import '../src/wxtiles.css';
|
|
18
|
+
|
|
19
|
+
let map: L.Map;
|
|
20
|
+
let layerControl: L.Control.Layers;
|
|
21
|
+
let config: Config; // application config
|
|
22
|
+
let styles: ColorStylesStrict; // all available styles. Not every style is sutable for every layer.
|
|
23
|
+
let globalLayer: WxTilesLayer | undefined; // current layer
|
|
24
|
+
|
|
25
|
+
// json loader helper
|
|
26
|
+
async function fetchJson(url: string) {
|
|
27
|
+
return (await fetch(url)).json();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function fillDataSets() {
|
|
31
|
+
let datasetsNames: string[];
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
datasetsNames = await fetchJson(config.dataServer + '/datasets.json');
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.log(e);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
datasetsNames.sort();
|
|
41
|
+
for (const datasetName of datasetsNames) {
|
|
42
|
+
const opt = document.createElement('option');
|
|
43
|
+
opt.appendChild(document.createTextNode(datasetName));
|
|
44
|
+
opt.value = datasetName;
|
|
45
|
+
selectDataSetEl.appendChild(opt);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
await fillVariables_selectDataSetEl_onchange();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function fillVariables_selectDataSetEl_onchange() {
|
|
52
|
+
const oldVariable = selectVariableEl.value;
|
|
53
|
+
selectVariableEl.innerHTML = '';
|
|
54
|
+
let meta: Meta;
|
|
55
|
+
try {
|
|
56
|
+
const instances = await fetchJson(config.dataServer + '/' + selectDataSetEl.value + '/instances.json');
|
|
57
|
+
const instance = instances[instances.length - 1];
|
|
58
|
+
meta = await fetchJson(config.dataServer + '/' + selectDataSetEl.value + '/' + instance + '/meta.json');
|
|
59
|
+
} catch (e) {
|
|
60
|
+
console.log(e);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
meta.variables.sort();
|
|
65
|
+
for (const variable of meta.variables) {
|
|
66
|
+
if (variable.includes('northward')) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const opt = document.createElement('option');
|
|
70
|
+
opt.appendChild(document.createTextNode(variable.replace('eastward', 'vector')));
|
|
71
|
+
opt.value = variable;
|
|
72
|
+
selectVariableEl.appendChild(opt);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (meta.variables.includes(oldVariable)) {
|
|
76
|
+
selectVariableEl.value = oldVariable;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
loadVariable_selectVariableEl_onchange();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function loadVariable_selectVariableEl_onchange() {
|
|
83
|
+
stopPlay();
|
|
84
|
+
|
|
85
|
+
const variable = selectVariableEl.value;
|
|
86
|
+
const variables = [variable];
|
|
87
|
+
if (variable.includes('eastward')) {
|
|
88
|
+
variables.push(variable.replace('eastward', 'northward'));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const layerSettings = {
|
|
92
|
+
dataSource: {
|
|
93
|
+
serverURI: config.dataServer, // server to fetch data from
|
|
94
|
+
maskServerURI: config.dataServer.replace(/\/data\/?/i, '/mask/{z}/{x}/{y}'),
|
|
95
|
+
ext: config.ext, // png / webp (default) - wxtilesplitter output format
|
|
96
|
+
dataset: selectDataSetEl.value, // dataset of the dataset
|
|
97
|
+
variables, // variable(s) to be used for the layer rendering
|
|
98
|
+
name: selectDataSetEl.value + '/' + selectVariableEl.selectedOptions[0].label, // attribute of the dataSource to be used externally
|
|
99
|
+
styleName: variable, // The name of the style (from styles.json) to apply for the layer
|
|
100
|
+
},
|
|
101
|
+
// Lazy setup
|
|
102
|
+
// 'true': perform setup and data loading on 'addTo(map)'.
|
|
103
|
+
// 'false': start loading immediately, but loading is not finished when layer is created.
|
|
104
|
+
// the signal 'setupcomplete' is fired when loading is finished.
|
|
105
|
+
// useful when a big bunch of layers is used, so layers are not wasting memory and bandwidth.
|
|
106
|
+
// lazy: true,
|
|
107
|
+
options: {
|
|
108
|
+
opacity: 1,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// save in order to delete old layer
|
|
113
|
+
const oldLayer = globalLayer; // this is to store oldLayer in order a user change layers too fast.
|
|
114
|
+
globalLayer = CreateWxTilesLayer(layerSettings);
|
|
115
|
+
await globalLayer.getSetupCompletePromise(); // wait for meta info to be loaded. doesn't mean 'tiles are loaded' !!!
|
|
116
|
+
globalLayer.addTo(map);
|
|
117
|
+
|
|
118
|
+
layerControl.addOverlay(globalLayer, layerSettings.dataSource.name);
|
|
119
|
+
if (oldLayer)
|
|
120
|
+
globalLayer.once('load', () => {
|
|
121
|
+
oldLayer.removeFrom(map);
|
|
122
|
+
layerControl.removeLayer(oldLayer);
|
|
123
|
+
}); // delete old layer
|
|
124
|
+
globalLayer.setTime(selectTimeEl.value !== '' ? selectTimeEl.value : new Date()); // try to preserve 'time' from current time of selectTimeEl
|
|
125
|
+
fillTimes(globalLayer);
|
|
126
|
+
fillStyles(globalLayer);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function fillTimes(layer: WxTilesLayer) {
|
|
130
|
+
// once layer setup finished, times are available.
|
|
131
|
+
// let's fill up 'selectTimeEl'
|
|
132
|
+
selectTimeEl.innerHTML = '';
|
|
133
|
+
layer.getTimes().forEach((val) => {
|
|
134
|
+
const opt = document.createElement('option');
|
|
135
|
+
opt.appendChild(document.createTextNode(val));
|
|
136
|
+
opt.value = val;
|
|
137
|
+
selectTimeEl.appendChild(opt);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
selectTimeEl.value = layer.getTime();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function startPlay() {
|
|
144
|
+
if (!globalLayer) return;
|
|
145
|
+
buttonPlayStopEl.textContent = 'stop';
|
|
146
|
+
globalLayer.setTimeAnimationMode(+inputCoarseLevelEl.value);
|
|
147
|
+
setTimeout(async function nextTimeStep() {
|
|
148
|
+
if (!globalLayer) return;
|
|
149
|
+
if (buttonPlayStopEl.textContent === 'stop') {
|
|
150
|
+
const start = Date.now();
|
|
151
|
+
await globalLayer.setTime(selectTimeEl.value);
|
|
152
|
+
selectTimeEl.selectedIndex++;
|
|
153
|
+
selectTimeEl.selectedIndex %= selectTimeEl.length;
|
|
154
|
+
const dt = +inputAnimDelayEl.value - (Date.now() - start);
|
|
155
|
+
setTimeout(nextTimeStep, dt < 0 ? 0 : dt);
|
|
156
|
+
oldE && updateInfoPanel(oldE);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function stopPlay() {
|
|
162
|
+
buttonPlayStopEl.textContent = 'play';
|
|
163
|
+
globalLayer?.unsetTimeAnimationMode();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function addOption(baseStyle: string, value = baseStyle) {
|
|
167
|
+
const opt = document.createElement('option');
|
|
168
|
+
opt.appendChild(document.createTextNode(baseStyle));
|
|
169
|
+
opt.value = value;
|
|
170
|
+
selectStyleEl.appendChild(opt);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function fillStyles(layer: WxTilesLayer) {
|
|
174
|
+
selectStyleEl.innerHTML = '';
|
|
175
|
+
if (config.varToStyleMap) {
|
|
176
|
+
for (const [regexp, styleName] of config.varToStyleMap) {
|
|
177
|
+
const regExp = new RegExp(regexp, 'i');
|
|
178
|
+
if (styleName in styles && regExp.test(layer.dataSource.variables[0])) {
|
|
179
|
+
addOption(styles[styleName].name, styleName);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
addOption('base');
|
|
185
|
+
addOption('custom');
|
|
186
|
+
onStyleChange_selectStyleEl_onchange();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function JSONsort(o: any) {
|
|
190
|
+
if (Array.isArray(o)) {
|
|
191
|
+
return o.map(JSONsort);
|
|
192
|
+
} else if (typeof o === 'object' && o !== null) {
|
|
193
|
+
const keys = Object.keys(o)
|
|
194
|
+
// .map((a) => a.toUpperCase())
|
|
195
|
+
.sort((a, b) => {
|
|
196
|
+
const aa = a.toUpperCase();
|
|
197
|
+
const bb = b.toUpperCase();
|
|
198
|
+
return aa == bb ? 0 : aa > bb ? 1 : -1;
|
|
199
|
+
});
|
|
200
|
+
return keys.reduce((a, k) => {
|
|
201
|
+
a[k] = JSONsort(o[k]);
|
|
202
|
+
return a;
|
|
203
|
+
}, {});
|
|
204
|
+
}
|
|
205
|
+
return o;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function onStyleChange_selectStyleEl_onchange() {
|
|
209
|
+
if (!globalLayer) return;
|
|
210
|
+
if (selectStyleEl.value === 'custom') {
|
|
211
|
+
try {
|
|
212
|
+
styles.custom = JSON.parse(customStyleEl.value);
|
|
213
|
+
} catch {
|
|
214
|
+
console.log('Wrong custom style');
|
|
215
|
+
const ctx = legendCanvasEl.getContext('2d');
|
|
216
|
+
if (!ctx) return;
|
|
217
|
+
ctx.clearRect(0, 0, legendCanvasEl.width, legendCanvasEl.height);
|
|
218
|
+
ctx.beginPath();
|
|
219
|
+
ctx.font = legendCanvasEl.height / 2 + 'px sans-serif';
|
|
220
|
+
ctx.fillText('Wrong custom style', 10, legendCanvasEl.height / 2);
|
|
221
|
+
ctx.stroke();
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
globalLayer.setStyle(selectStyleEl.value);
|
|
226
|
+
const curStyleName = globalLayer.getStyle();
|
|
227
|
+
const curStyle = styles[curStyleName];
|
|
228
|
+
customStyleEl.value = JSON.stringify(JSONsort(curStyle), null, ' ');
|
|
229
|
+
const legend = globalLayer.getLegendData(legendCanvasEl.width - 50);
|
|
230
|
+
if (!legend) return;
|
|
231
|
+
drawLegend({ legend, canvas: legendCanvasEl });
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function drawLegend({ legend, canvas }: { legend: Legend; canvas: HTMLCanvasElement }) {
|
|
235
|
+
if (!globalLayer || !canvas || !legend) return;
|
|
236
|
+
|
|
237
|
+
const { width, height } = canvas;
|
|
238
|
+
const halfHeight = (16 + height) >> 2;
|
|
239
|
+
|
|
240
|
+
// draw legend
|
|
241
|
+
const ctx = canvas.getContext('2d')!;
|
|
242
|
+
const imData = ctx.createImageData(width, height);
|
|
243
|
+
const im = new Uint32Array(imData.data.buffer);
|
|
244
|
+
im.fill(-1);
|
|
245
|
+
|
|
246
|
+
const startX = 2;
|
|
247
|
+
const startY = 2;
|
|
248
|
+
const startXY = startX + width * startY;
|
|
249
|
+
|
|
250
|
+
const trSize = halfHeight >> 1;
|
|
251
|
+
// left triangle
|
|
252
|
+
if (legend.showBelowMin) {
|
|
253
|
+
const c = legend.colors[0];
|
|
254
|
+
if (c) {
|
|
255
|
+
for (let x = 0; x < trSize; ++x) {
|
|
256
|
+
for (let y = trSize; y < trSize + x; ++y) {
|
|
257
|
+
im[startXY + x + y * width] = c;
|
|
258
|
+
im[startXY + x + (trSize * 2 - y) * width] = c;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
for (let x = 0; x < legend.size; ++x) {
|
|
265
|
+
for (let y = 0; y < halfHeight; ++y) {
|
|
266
|
+
if (legend.colors[0]) {
|
|
267
|
+
im[startX + x + trSize + (y + startY + 1) * width] = legend.colors[x];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// right triangle
|
|
273
|
+
if (legend.showAboveMax) {
|
|
274
|
+
const c = legend.colors[legend.colors.length - 1];
|
|
275
|
+
if (c) {
|
|
276
|
+
for (let x = 0; x <= trSize; ++x) {
|
|
277
|
+
for (let y = trSize; y < trSize + x; ++y) {
|
|
278
|
+
im[startXY + trSize * 2 + legend.size - x + y * width] = c;
|
|
279
|
+
im[startXY + trSize * 2 + legend.size - x + (trSize * 2 - y) * width] = c;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
ctx.putImageData(imData, 0, 0);
|
|
286
|
+
|
|
287
|
+
// draw ticks
|
|
288
|
+
ctx.font = '8px sans-serif';
|
|
289
|
+
ctx.beginPath();
|
|
290
|
+
for (const tick of legend.ticks) {
|
|
291
|
+
ctx.strokeStyle = '#000';
|
|
292
|
+
ctx.moveTo(tick.pos + trSize + startX + 1, startY + 3);
|
|
293
|
+
ctx.lineTo(tick.pos + trSize + startX + 1, halfHeight);
|
|
294
|
+
ctx.fillText(tick.dataString, tick.pos + trSize + startX + 1, halfHeight + 11);
|
|
295
|
+
}
|
|
296
|
+
ctx.font = '12px sans-serif';
|
|
297
|
+
const txt = globalLayer.getStyleName() + ' (' + legend.units + ')';
|
|
298
|
+
ctx.fillText(txt, 13, height - 5);
|
|
299
|
+
ctx.stroke();
|
|
300
|
+
|
|
301
|
+
ctx.strokeStyle = '#888';
|
|
302
|
+
ctx.strokeRect(1, 1, width - 3, height - 2); //for white background
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
let oldE: L.LeafletMouseEvent | undefined;
|
|
306
|
+
function updateInfoPanel(e: L.LeafletMouseEvent) {
|
|
307
|
+
oldE = e; // save 'e'
|
|
308
|
+
let content = '' + `${e.latlng}<br>`;
|
|
309
|
+
map.eachLayer((layer) => {
|
|
310
|
+
if (layer instanceof WxTilesLayer) {
|
|
311
|
+
const tile = layer.getTile(e!.latlng);
|
|
312
|
+
const { min, max } = layer.getMinMax();
|
|
313
|
+
|
|
314
|
+
content += tile
|
|
315
|
+
? `<div>
|
|
316
|
+
<div style="width:1em;height:1em;float:left;margin-right:2px;background:${tile.hexColor}"></div>
|
|
317
|
+
${layer.dataSource.name}=${tile.inStyleUnits.toFixed(2)} ${tile.units} (${min.toFixed(2)}, ${max.toFixed(2)})
|
|
318
|
+
</div>`
|
|
319
|
+
: '';
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
infoPanelEl.innerHTML = content;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function popupInfo(e: L.LeafletMouseEvent) {
|
|
327
|
+
let content = '';
|
|
328
|
+
map.eachLayer((layer) => {
|
|
329
|
+
if (layer instanceof WxTilesLayer) {
|
|
330
|
+
const tile = layer.getTile(e.latlng);
|
|
331
|
+
const time = layer.getTime();
|
|
332
|
+
content += tile
|
|
333
|
+
? `<div>
|
|
334
|
+
<div style="width:1em;height:1em;float:left;margin-right:2px;background:${tile.hexColor}"></div>
|
|
335
|
+
${layer.dataSource.name}<br>
|
|
336
|
+
(in style Units = ${tile.inStyleUnits} ${tile.units})<br>
|
|
337
|
+
(in data Units = ${tile.data} ${layer.state.units})<br>
|
|
338
|
+
(time:${time})<br>
|
|
339
|
+
(instance:${layer.state.instance})<br>
|
|
340
|
+
(tilePoint:${tile.tilePoint.x},${tile.tilePoint.y})<br>
|
|
341
|
+
</div>`
|
|
342
|
+
: '';
|
|
343
|
+
// (tileCoords:${tile.tile.coords.x},${tile.tile.coords.y},zoom:${tile.tile.coords.z})<br>
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
L.popup()
|
|
348
|
+
.setLatLng(e.latlng)
|
|
349
|
+
.setContent(content + `${e.latlng}`)
|
|
350
|
+
.openOn(map);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function createControl(opt: L.ControlOptions & { htmlID: string }): L.Control {
|
|
354
|
+
return new (L.Control.extend({
|
|
355
|
+
onAdd() {
|
|
356
|
+
return document.getElementById(opt.htmlID);
|
|
357
|
+
},
|
|
358
|
+
}))(opt);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
interface BaseLayerOptions {
|
|
362
|
+
name: string;
|
|
363
|
+
URL: string;
|
|
364
|
+
options?: L.TileLayerOptions;
|
|
365
|
+
add?: boolean;
|
|
366
|
+
}
|
|
367
|
+
interface Config {
|
|
368
|
+
dataServer: string;
|
|
369
|
+
ext: 'webp' | 'png';
|
|
370
|
+
map?: L.MapOptions;
|
|
371
|
+
baseLayers?: BaseLayerOptions[];
|
|
372
|
+
varToStyleMap?: [string, string][];
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
async function start() {
|
|
376
|
+
// read config
|
|
377
|
+
try {
|
|
378
|
+
config = await fetchJson('props/config.json'); // set the correct URI
|
|
379
|
+
} catch (e) {
|
|
380
|
+
console.log(e);
|
|
381
|
+
alert('No props/config.json');
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// Leaflet basic setup // set the main Leaflet's map object, compose and add base layers
|
|
386
|
+
map = L.map('map', config.map);
|
|
387
|
+
|
|
388
|
+
// Setup WxTiles lib
|
|
389
|
+
WxTilesLogging(true); // use wxtiles logging -> console.log
|
|
390
|
+
CreateWxTilesWatermark({ URI: 'res/wxtiles-logo.png', position: 'topright' }).addTo(map);
|
|
391
|
+
layerControl = L.control.layers(undefined, undefined, { position: 'topright', autoZIndex: false, collapsed: false }).addTo(map);
|
|
392
|
+
config.baseLayers?.map((baseLayer) => {
|
|
393
|
+
if (!baseLayer.add) return;
|
|
394
|
+
const layer = L.tileLayer(baseLayer.URL, baseLayer.options);
|
|
395
|
+
baseLayer.options?.zIndex === 0 ? layerControl.addBaseLayer(layer, baseLayer.name) : layerControl.addOverlay(layer, baseLayer.name);
|
|
396
|
+
});
|
|
397
|
+
layerControl.addOverlay(CreateWxDebugCoordsLayer(), 'tile boundaries');
|
|
398
|
+
layerControl.addBaseLayer(L.tileLayer('').addTo(map), 'base-empty');
|
|
399
|
+
|
|
400
|
+
createControl({ position: 'topleft', htmlID: 'legend' }).addTo(map);
|
|
401
|
+
createControl({ position: 'topleft', htmlID: 'layerPanel' }).addTo(map);
|
|
402
|
+
createControl({ position: 'topleft', htmlID: 'styleEditor' }).addTo(map);
|
|
403
|
+
createControl({ position: 'bottomleft', htmlID: 'infoPanel' }).addTo(map);
|
|
404
|
+
|
|
405
|
+
const wxlibCustomSettings: any = {};
|
|
406
|
+
try {
|
|
407
|
+
// these URIs are for the demo purpose. set the correct URI
|
|
408
|
+
wxlibCustomSettings.colorStyles = await fetchJson('props/styles.json'); // set the correct URI
|
|
409
|
+
} catch (e) {
|
|
410
|
+
console.log(e);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
try {
|
|
414
|
+
wxlibCustomSettings.units = await fetchJson('props/uconv.json'); // set the correct URI
|
|
415
|
+
} catch (e) {
|
|
416
|
+
console.log(e);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
try {
|
|
420
|
+
wxlibCustomSettings.colorSchemes = await fetchJson('props/colorschemes.json'); // set the correct URI
|
|
421
|
+
} catch (e) {
|
|
422
|
+
console.log(e);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// ESSENTIAL step to get lib ready.
|
|
426
|
+
WxTilesLibSetup(wxlibCustomSettings); // load fonts and styles, units, colorschemas - empty => defaults
|
|
427
|
+
await document.fonts.ready; // !!! IMPORTANT: make sure fonts (barbs, arrows, etc) are loaded
|
|
428
|
+
await LoadQTree(config.dataServer + 'seamask.qtree');
|
|
429
|
+
|
|
430
|
+
styles = WxGetColorStyles(); // all available styles. Not every style is sutable for this layer.
|
|
431
|
+
|
|
432
|
+
fillDataSets();
|
|
433
|
+
|
|
434
|
+
map.on('zoom', stopPlay); // stop time animation on zoom
|
|
435
|
+
map.on('mousemove', updateInfoPanel);
|
|
436
|
+
map.on('click', popupInfo);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const selectDataSetEl = document.getElementById('selectDataSet') as HTMLSelectElement;
|
|
440
|
+
selectDataSetEl.addEventListener('change', () => {
|
|
441
|
+
fillVariables_selectDataSetEl_onchange();
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
const selectVariableEl = document.getElementById('selectVariable') as HTMLSelectElement;
|
|
445
|
+
selectVariableEl.addEventListener('change', loadVariable_selectVariableEl_onchange);
|
|
446
|
+
|
|
447
|
+
const selectStyleEl = document.getElementById('selectStyle') as HTMLSelectElement;
|
|
448
|
+
selectStyleEl.addEventListener('change', onStyleChange_selectStyleEl_onchange);
|
|
449
|
+
|
|
450
|
+
const legendCanvasEl = document.getElementById('legend') as HTMLCanvasElement;
|
|
451
|
+
|
|
452
|
+
const customStyleEl = document.getElementById('customStyle') as HTMLTextAreaElement;
|
|
453
|
+
customStyleEl.addEventListener('change', () => {
|
|
454
|
+
selectStyleEl.value = 'custom';
|
|
455
|
+
onStyleChange_selectStyleEl_onchange();
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
const customStyleButtonEl = document.getElementById('customStyleButton')! as HTMLButtonElement;
|
|
459
|
+
customStyleButtonEl.addEventListener('click', () => {
|
|
460
|
+
if (customStyleEl.style.display != 'none') {
|
|
461
|
+
customStyleEl.style.display = 'none';
|
|
462
|
+
customStyleButtonEl.innerHTML = 'show Custom Style Editor';
|
|
463
|
+
} else {
|
|
464
|
+
customStyleEl.style.display = 'block';
|
|
465
|
+
customStyleButtonEl.innerHTML = 'update Custom Style & Hide';
|
|
466
|
+
selectStyleEl.value = 'custom';
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
const selectTimeEl = document.getElementById('selectTime') as HTMLSelectElement;
|
|
471
|
+
selectTimeEl.addEventListener('change', () => {
|
|
472
|
+
if (!globalLayer) return;
|
|
473
|
+
if (buttonPlayStopEl.textContent === 'stop') stopPlay();
|
|
474
|
+
globalLayer.setTime(selectTimeEl.value);
|
|
475
|
+
selectTimeEl.value = globalLayer.getTime();
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
const buttonHoldEl = document.getElementById('buttonHold') as HTMLButtonElement;
|
|
479
|
+
buttonHoldEl.addEventListener('click', () => {
|
|
480
|
+
L.popup()
|
|
481
|
+
.setLatLng(map.getCenter())
|
|
482
|
+
.setContent(
|
|
483
|
+
`
|
|
484
|
+
This layer was "held".
|
|
485
|
+
You can hold as many layers as you want, but you can't control them after holding.
|
|
486
|
+
New layers will appear OVER the held layers.
|
|
487
|
+
Use the "clear" button to clear the ALL VISIBLE layers.
|
|
488
|
+
`
|
|
489
|
+
)
|
|
490
|
+
.openOn(map);
|
|
491
|
+
stopPlay();
|
|
492
|
+
globalLayer = undefined;
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
const infoPanelEl = document.getElementById('infoPanel') as HTMLDivElement;
|
|
496
|
+
const inputAnimDelayEl = document.getElementById('animDelay') as HTMLInputElement;
|
|
497
|
+
const inputCoarseLevelEl = document.getElementById('coarseLevel') as HTMLInputElement;
|
|
498
|
+
const buttonPlayStopEl = document.getElementById('buttonPlayStop') as HTMLButtonElement;
|
|
499
|
+
buttonPlayStopEl.addEventListener('click', () => {
|
|
500
|
+
buttonPlayStopEl.textContent === 'play' ? startPlay() : stopPlay();
|
|
501
|
+
});
|
|
502
|
+
const clearEl = document.getElementById('buttonClear')!;
|
|
503
|
+
clearEl.addEventListener('click', () => {
|
|
504
|
+
map.eachLayer((l) => {
|
|
505
|
+
if ('getTile' in l) {
|
|
506
|
+
l.removeFrom(map);
|
|
507
|
+
layerControl.removeLayer(l);
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
loadVariable_selectVariableEl_onchange();
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
start();
|