@metoceanapi/wxtiles-leaflet 1.0.14 → 1.1.1

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 CHANGED
@@ -9,6 +9,42 @@ Write your changes below this section. `npm version [major|minor|patch]` will au
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [1.1.1] - 2022-04-26
13
+
14
+ ### fix
15
+
16
+ - refineColor
17
+
18
+ ### add
19
+
20
+ - style.gridStep and steps to stream lines
21
+
22
+ ## [1.1.0] - 2022-04-21
23
+
24
+ ### Added
25
+
26
+ - A new visual 'custom' style editor
27
+ - coloring streamlines
28
+ ### REVERT
29
+
30
+ - checkDataChanged
31
+
32
+ ### Fixed
33
+
34
+ - addDegree in \_createStreamLines
35
+ - error handling in makeConverter
36
+
37
+ ## [1.0.15] - 2022-04-12
38
+
39
+ ### add
40
+
41
+ - style.vectorFactor
42
+
43
+ ### FIX
44
+
45
+ - remastered async functions
46
+ - masking spoiled original (cached) data
47
+
12
48
  ## [1.0.14] - 2021-12-15
13
49
 
14
50
  ### FIX
@@ -1,2 +1,2 @@
1
- import { ColorSchemes } from '../wxtools';
1
+ import { ColorSchemes } from '../utils/wxtools';
2
2
  export declare const __colorSchemes_default_preset: ColorSchemes;
@@ -1,2 +1,2 @@
1
- import { ColorStylesStrict } from '../wxtools';
1
+ import { ColorStylesStrict } from '../utils/wxtools';
2
2
  export declare const __colorStyles_default_preset: ColorStylesStrict;
@@ -1,2 +1,2 @@
1
- import { Units } from '../wxtools';
1
+ import { Units } from '../utils/wxtools';
2
2
  export declare const __units_default_preset: Units;
package/dist/es/tile.d.ts CHANGED
@@ -1,19 +1,20 @@
1
- import { DataPicture } from './wxtools';
1
+ import { DataPicture } from './utils/wxtools';
2
2
  import { WxTilesLayer } from './tilesLayer';
3
+ import { TileType } from './utils/qtree';
3
4
  export interface Coords {
4
5
  z: number;
5
6
  x: number;
6
7
  y: number;
7
8
  }
8
9
  export interface TileEl extends HTMLElement {
9
- wxtile?: WxTile;
10
+ wxtile: WxTile;
10
11
  }
11
12
  export interface TileCreateParams {
12
13
  layer: WxTilesLayer;
13
14
  coords: Coords;
14
- done: () => void;
15
+ done: L.DoneCallback;
15
16
  }
16
- export declare function TileCreate({ layer, coords, done }: TileCreateParams): TileEl;
17
+ export declare function newWxTile(params: TileCreateParams): TileEl;
17
18
  interface SLinePoint {
18
19
  x: number;
19
20
  y: number;
@@ -27,36 +28,33 @@ export declare class WxTile {
27
28
  protected canvasSlines: HTMLCanvasElement;
28
29
  protected canvasVector: HTMLCanvasElement;
29
30
  protected canvasFillCtx: CanvasRenderingContext2D;
30
- protected canvasSlinesCtx: CanvasRenderingContext2D;
31
+ protected canvasVectorAnimationCtx: CanvasRenderingContext2D;
31
32
  protected canvasVectorCtx: CanvasRenderingContext2D;
32
- protected sLines: SLine[];
33
- protected imData: ImageData;
34
- constructor({ layer, coords, tileEl }: {
35
- layer: WxTilesLayer;
36
- coords: Coords;
37
- tileEl: HTMLElement;
38
- });
39
- draw(): void;
40
- clearSLinesCanvas(): void;
41
- drawSLines(timeStemp: number): void;
42
- getData({ x, y }: {
43
- x: number;
44
- y: number;
45
- }): {
46
- raw: number;
47
- data: number;
48
- } | undefined;
33
+ protected streamLines: SLine[];
34
+ protected imageDataForFillCtx: ImageData;
35
+ constructor({ layer, coords }: TileCreateParams, tileEl: TileEl);
49
36
  load(): Promise<WxTile>;
37
+ protected _applyMask(tileType: TileType, needCopy: boolean): Promise<void>;
50
38
  protected _splitCoords(coords: Coords): {
51
39
  upCoords: Coords;
52
40
  subCoords?: Coords;
53
41
  };
54
- protected _coordsToURLs(upCoords: Coords): string[];
55
- protected _vectorPrepare(): void;
42
+ protected _getTileType(): TileType | undefined;
43
+ draw(): void;
44
+ clearVectorAnimationCanvas(): void;
45
+ drawVectorAnimationLinesStep(timeStemp: number): void;
46
+ getPixelInfo({ x, y }: {
47
+ x: number;
48
+ y: number;
49
+ }): {
50
+ raw: number[];
51
+ data: number[];
52
+ } | undefined;
53
+ protected _vectorMagnitudesPrepare(): void;
56
54
  protected _drawFillAndIsolines(): void;
57
- protected _drawStaticSlines(): void;
58
- protected _drawVector(): void;
59
- protected _drawDegree(): void;
60
- protected _createSLines(): void;
55
+ protected _drawStreamLinesStatic(): void;
56
+ protected _drawVectorsStatic(): void;
57
+ protected _drawDegreesStatic(): void;
58
+ protected _createStreamLines(): void;
61
59
  }
62
60
  export {};
@@ -1,7 +1,22 @@
1
1
  import L from 'leaflet';
2
- import { RawCLUT, Legend } from './RawCLUT';
2
+ import { RawCLUT, Legend } from './utils/RawCLUT';
3
3
  import { WxTile } from './tile';
4
- import { ColorStylesStrict, ColorStyleStrict, AbortableCacheableFunc, DataIntegral } from './wxtools';
4
+ import { ColorStylesStrict, ColorStyleStrict, AbortableCacheableURILoaderPromiseFunc, DataIntegral } from './utils/wxtools';
5
+ export declare function WxInitLoadMaskFunc(requestInit?: RequestInit): void;
6
+ export interface WxTileInfo {
7
+ wxtile: WxTile;
8
+ data: number[];
9
+ raw: number[];
10
+ rgba: number[];
11
+ hexColor: string[];
12
+ inStyleUnits: number[];
13
+ tilePoint: {
14
+ x: number;
15
+ y: number;
16
+ };
17
+ styleUnits: string;
18
+ dataUnits: string;
19
+ }
5
20
  export interface VariableMeta {
6
21
  [name: string]: {
7
22
  units: string;
@@ -29,80 +44,76 @@ export interface Meta {
29
44
  }
30
45
  export interface DataSource {
31
46
  serverURI: string;
32
- maskServerURI?: string;
47
+ maskServerURI: string;
33
48
  ext: 'webp' | 'png';
34
49
  dataset: string;
35
50
  variables: string[];
36
51
  name: string;
37
52
  styleName: string;
53
+ requestInit?: RequestInit;
38
54
  }
39
55
  export interface WxLayerState {
40
- maskServerURI: string;
41
- time: string;
56
+ currentTime: string;
57
+ baseURL: string;
42
58
  minmax: [number, number][];
43
59
  instance: string;
44
60
  originURI: string;
45
61
  units: string;
46
62
  meta: Meta;
47
- baseURL: string;
63
+ vector: boolean;
48
64
  }
49
65
  export interface WxTilesLayerSettings {
50
66
  lazy?: boolean;
51
67
  dataSource: DataSource;
52
68
  options: L.GridLayerOptions;
53
69
  }
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
- }
67
70
  export declare class WxTilesLayer extends L.GridLayer {
68
- setupCompletePromise: Promise<boolean>;
69
71
  protected styles: ColorStylesStrict;
72
+ protected redrawRequestID: number;
73
+ protected vectorAnimationRequestID: number;
74
+ protected oldMaxZoom: number;
75
+ setupCompletePromise: Promise<void>;
70
76
  dataSource: DataSource;
71
77
  style: ColorStyleStrict;
72
- loadData: AbortableCacheableFunc<Promise<DataIntegral>>;
73
- loadMask: AbortableCacheableFunc<Promise<ImageData>>;
74
- error: string | null;
75
- vector: boolean;
76
78
  clut: RawCLUT;
79
+ loadDataIntegralFunc: AbortableCacheableURILoaderPromiseFunc<DataIntegral>;
80
+ loadMaskFunc: AbortableCacheableURILoaderPromiseFunc<ImageData>;
77
81
  state: WxLayerState;
78
82
  animation: boolean;
79
- protected animationRedrawID: number;
80
- protected animFrame: number;
81
- protected oldMaxZoom: number;
82
- constructor({ dataSource, options, lazy }: WxTilesLayerSettings);
83
+ constructor(settings: WxTilesLayerSettings);
84
+ protected _setUpDataSet(): Promise<void>;
85
+ protected _requestReloadTilesAndRedraw(): Promise<boolean>;
86
+ protected _requestReloadTiles(): Promise<boolean>;
87
+ setStyle(styleName: string): Promise<void>;
88
+ protected _setStyleAndCLUT(styleName: string): void;
83
89
  /** Leaflet's calling this, don't use it directly! */
84
90
  protected createTile(coords: L.Coords, done: L.DoneCallback): HTMLElement;
85
91
  /** NOTE: if lazy setup and layer was not added to a map - this is never fulfilled */
86
- getSetupCompletePromise(): Promise<boolean>;
92
+ getSetupCompletePromise(): Promise<void>;
93
+ /** check if data has been changed since last init */
94
+ checkDataChanged(): Promise<boolean>;
87
95
  /** get all the information about tile and point it represents */
88
- getTile(latlng: L.LatLngExpression): WxTileInfo | undefined;
89
- setStyle(name: string | undefined): void;
90
- /** string - style from dataSource. Useful to get layer's style: style = WxGetColorStyles()[wxlayer.getStyle()] */
91
- getStyle(): string;
92
- /** string - style's name used for the layer. Useful for exposing the layer style's name.*/
93
- getStyleName(): string;
94
- /** time as Date or unix time (ms since 00:00:00 UTC on 1 January 1970) */
95
- setTime(time: Date | string | number): Promise<WxTile[]>;
96
+ getLayerInfoAtLatLon(latlng: L.LatLngExpression): WxTileInfo | undefined;
97
+ /** Layer's current style.*/
98
+ getStyle(): ColorStyleStrict;
99
+ /** get first non-empty wxtile */
100
+ protected _getFirstNonEmptyTile(): WxTile | undefined;
101
+ protected _setTimeUrl(time: Date | string | number): boolean;
102
+ /** set time to the closest time in the list of times
103
+ * params:
104
+ * time - Date, String or number (unix time ms since 00:00:00 UTC on 1 January 1970)
105
+ * return:
106
+ * Promise resolved as true - if time was changed and tiles were redrawn
107
+ * NOTE:
108
+ * User should await for setTime promise to be fulfilled, otherwise the data might be loaded but not
109
+ * displayed. Some visual issues can come from vector animation.
110
+ * */
111
+ setTime(time: Date | string | number): Promise<boolean>;
96
112
  /** string - current time as it is in meta */
97
113
  getTime(): string;
98
114
  /** Array of strings (times) */
99
115
  getTimes(): string[];
100
- /** check if data has been changed since last init */
101
- checkDataChanged(): Promise<boolean>;
102
- /** usefull if data is changed on server (checkable with 'checkDataChanged') */
103
- reloadData(): Promise<boolean>;
104
- /**
105
- * getLegendData - data to render a proper legend
116
+ /** getLegendData - data to render a proper legend
106
117
  * pixSize - width of a canvas to render this legend
107
118
  * output:
108
119
  * legend - object
@@ -117,7 +128,7 @@ export declare class WxTilesLayer extends L.GridLayer {
117
128
  /** set coarse maximum zoom level to make tiles load faster during animation */
118
129
  setTimeAnimationMode(l?: number): void;
119
130
  /** restore maximum zoom level */
120
- unsetTimeAnimationMode(): Promise<WxTile[]>;
131
+ unsetTimeAnimationMode(): Promise<boolean>;
121
132
  /** min, max values of the loaded data */
122
133
  getMinMax(): {
123
134
  min: number;
@@ -125,15 +136,12 @@ export declare class WxTilesLayer extends L.GridLayer {
125
136
  };
126
137
  /** true/false - if vector data and true, animation starts */
127
138
  setAnimation(a: boolean): boolean;
128
- protected _getCachedTile(x: number, y: number, zoom: number): WxTile | undefined;
129
- protected _ForEachTile<T>(func: (wxtile: WxTile) => T): T[];
130
- protected _setUpDataSet(dataSource: DataSource | undefined): Promise<boolean>;
131
- protected _checkZoom(): void;
132
- protected _onAddLayer(): void;
133
- protected _onRemoveLayer(): void;
139
+ protected _getCachedTile({ x, y }: {
140
+ x: number;
141
+ y: number;
142
+ }, zoom: number): WxTile | undefined;
143
+ protected _ForEachWxTile<T>(func: (wxtile: WxTile) => T): T[];
134
144
  protected _stopLoadingResetLoadDataFunc(): void;
135
- protected _checkAndStartSlinesAnimation(): void;
136
- protected _stopSlinesAnimation(): void;
145
+ protected _checkAndStartVectorAnimation(): void;
137
146
  protected _redrawTiles(): void;
138
- protected _reloadTiles(redraw?: boolean): Promise<WxTile[]>;
139
147
  }
File without changes
File without changes
@@ -1,4 +1,8 @@
1
- import { Coords } from './tile';
1
+ export interface Coords {
2
+ z: number;
3
+ x: number;
4
+ y: number;
5
+ }
2
6
  export declare function LoadQTree(input: RequestInfo, init?: RequestInit | undefined): Promise<void>;
3
7
  export declare enum TileType {
4
8
  Land = "land",
@@ -14,8 +14,11 @@ export interface ColorStyleWeak {
14
14
  isolineText?: boolean;
15
15
  vectorType?: string;
16
16
  vectorColor?: string;
17
+ vectorFactor?: number;
17
18
  streamLineColor?: string;
18
19
  streamLineSpeedFactor?: number;
20
+ streamLineGridStep?: number;
21
+ streamLineSteps?: number;
19
22
  streamLineStatic?: boolean;
20
23
  showBelowMin?: boolean;
21
24
  showAboveMax?: boolean;
@@ -35,7 +38,7 @@ export interface ColorStylesWeakMixed {
35
38
  export interface ColorStylesIncomplete {
36
39
  [name: string]: ColorStyleWeak;
37
40
  }
38
- export interface ColorStyleStrict {
41
+ export interface ColorStyleStrict extends ColorStyleWeak {
39
42
  parent?: string;
40
43
  name: string;
41
44
  fill: string;
@@ -43,8 +46,11 @@ export interface ColorStyleStrict {
43
46
  isolineText: boolean;
44
47
  vectorType: string;
45
48
  vectorColor: string;
49
+ vectorFactor: number;
46
50
  streamLineColor: string;
47
51
  streamLineSpeedFactor: number;
52
+ streamLineGridStep?: number;
53
+ streamLineSteps?: number;
48
54
  streamLineStatic: boolean;
49
55
  showBelowMin: boolean;
50
56
  showAboveMax: boolean;
@@ -74,7 +80,7 @@ export interface Converter {
74
80
  trivial?: boolean;
75
81
  }
76
82
  export declare function makeConverter(from: string, to: string, customUnits?: Units): Converter;
77
- declare type CacheableFunc<T> = (url: string) => T;
83
+ declare type CacheableURILoaderPromiseFunc<T> = (url: string) => Promise<T>;
78
84
  interface IntegralPare {
79
85
  integral: Uint32Array;
80
86
  integralNZ: Uint32Array;
@@ -89,24 +95,30 @@ export interface DataIntegral extends DataPicture {
89
95
  integral: IntegralPare;
90
96
  radius: number;
91
97
  }
98
+ export declare function loadImageData(url: string, requestInit?: RequestInit): Promise<ImageData>;
92
99
  interface AbortControllerHolder {
93
100
  controller: AbortController;
101
+ debug: string;
94
102
  }
95
- export declare function loadImageData(url: string, controllerHolder: AbortControllerHolder): Promise<ImageData>;
96
- export interface AbortableCacheableFunc<T> extends CacheableFunc<T> {
103
+ export interface AbortableCacheableURILoaderPromiseFunc<T> extends CacheableURILoaderPromiseFunc<T> {
97
104
  controllerHolder: AbortControllerHolder;
105
+ abort: () => void;
98
106
  }
99
- export declare function loadDataPictureCachedAbortable(): AbortableCacheableFunc<Promise<DataIntegral>>;
100
- export declare function loadImageDataCachedAbortable(controller: AbortController): AbortableCacheableFunc<Promise<ImageData>>;
107
+ export declare function loadingFunctionCachedAbortable<T>(F: (url: string, requestInit?: RequestInit) => Promise<T>, requestInit?: RequestInit): AbortableCacheableURILoaderPromiseFunc<T>;
108
+ export declare function loadDataIntegralCachedAbortable(requestInit?: RequestInit): AbortableCacheableURILoaderPromiseFunc<DataIntegral>;
109
+ export declare function loadImageDataCachedAbortable(requestInit?: RequestInit): AbortableCacheableURILoaderPromiseFunc<ImageData>;
110
+ export declare function loadDataIntegralCachedAbortable_old(requestInit?: RequestInit): AbortableCacheableURILoaderPromiseFunc<DataIntegral>;
111
+ export declare function loadImageDataCachedAbortable_old(requestInit?: RequestInit): AbortableCacheableURILoaderPromiseFunc<ImageData>;
101
112
  export declare function blurData(im: DataIntegral, radius: number): DataIntegral;
102
113
  export declare function RGBtoHEX(rgb: number): string;
103
114
  export declare function RGBAtoHEX(rgba: number): string;
104
115
  export declare function HEXtoRGBA(c: string): number;
105
- export declare function fetchJson(url: RequestInfo, init?: RequestInit): Promise<any>;
116
+ export declare function fetchJson(url: RequestInfo, requestInit?: RequestInit): Promise<any>;
106
117
  export declare function createEl(tagName: string, className?: string, container?: HTMLElement): HTMLElement;
107
118
  export declare function mixColor(c1: number, c2: number, t: number): number;
108
119
  export declare function createLevels(min: number, max: number, n: number): number[];
109
120
  export declare function getClosestTimeString(times: string[], time: Date | string | number): string;
110
121
  export declare function WxTilesLogging(on: boolean): void;
111
122
  export declare function WXLOG(...str: any): void;
123
+ export declare function refineColor(c: string): string;
112
124
  export {};
@@ -1,12 +1,12 @@
1
1
  import './wxtiles.css';
2
2
  import L from 'leaflet';
3
3
  import { WxTilesLayer, WxTilesLayerSettings } from './tilesLayer';
4
- export { WxTilesLogging, WxTilesLibSetup, WxGetColorStyles, WxGetColorSchemes } from './wxtools';
5
- export type { ColorStylesWeakMixed, ColorStyleStrict, ColorStylesStrict, Units, ColorSchemes, LibSetupObject } from './wxtools';
4
+ export { WxTilesLogging, WxTilesLibSetup, WxGetColorStyles, WxGetColorSchemes, fetchJson } from './utils/wxtools';
5
+ export type { ColorStylesWeakMixed, ColorStyleStrict, ColorStylesStrict, Units, ColorSchemes, LibSetupObject } from './utils/wxtools';
6
6
  export type { WxTilesLayerSettings, DataSource, Meta, WxTileInfo } from './tilesLayer';
7
7
  export { WxTilesLayer } from './tilesLayer';
8
- export type { Legend } from './RawCLUT';
9
- export { LoadQTree } from './qtree';
8
+ export type { Legend } from './utils/RawCLUT';
9
+ export { LoadQTree } from './utils/qtree';
10
10
  export declare function CreateWxTilesLayer(settings: WxTilesLayerSettings): WxTilesLayer;
11
11
  export declare class WxWatermark extends L.Control {
12
12
  URI: string;
@@ -1 +1 @@
1
- var ve=Object.create;var _=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols,Me=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty,ke=Object.prototype.propertyIsEnumerable;var J=(r,e,t)=>e in r?_(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Y=(r,e)=>{for(var t in e||(e={}))$.call(e,t)&&J(r,t,e[t]);if(X)for(var t of X(e))ke.call(e,t)&&J(r,t,e[t]);return r};var Ae=r=>_(r,"__esModule",{value:!0});var Je=typeof require!="undefined"?require:r=>{throw new Error('Dynamic require of "'+r+'" is not supported')};var Ie=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var _e=(r,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of De(e))!$.call(r,n)&&n!=="default"&&_(r,n,{get:()=>e[n],enumerable:!(t=Le(e,n))||t.enumerable});return r},ee=r=>_e(Ae(_(r!=null?ve(Me(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var N=Ie((rt,te)=>{te.exports=window.L});var E=ee(N());var re={comment1:["'degC': ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["'hPa': ['Pa', 1000]' -> hPa = Pa * 1000 + 0 (0 - could be ommited)",0],K:["K",1],kelvin:["K",1],F:["K",.5555555555,255.372222222],C:["K",1,273.15],degC:["K",1,273.15],"kg/m^2/s":["kg/m^2/s",1],"Kg/m^2/s":["kg/m^2/s",1],"Kg m**-2 s**-1":["kg/m^2/s",1],"Kg m^-2 s^-1":["kg/m^2/s",1],"Kg m^{-2} s^-1":["kg/m^2/s",1],"mm/h":["kg/m^2/s",.00027777777],"mm/hr":["kg/m^2/s",.00027777777],"W/m^2":["W/m^2",1],"W m^-2":["W/m^2",1],"W m^{-2}":["W/m^2",1],"W/m**2":["W/m^2",1],"W m**-2":["W/m^2",1],"m/s":["m/s",1],"m s**-1":["m/s",1],"m s^-1":["m/s",1],"m.s^{-1}":["m/s",1],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["m/s",.27777777777],"km h^-1":["m/s",.27777777777],"km h**-1":["m/s",.27777777777],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],inch:["m",.0254],Pa:["Pa",1],hPa:["Pa",100],degree:["degree",1],radian:["degree",57.3],"mg/m^3":["mg/m^3",1],"mg m^-3":["mg/m^3",1],"mg.m^-3":["mg/m^3",1],"%":["%",1],"(0 - 1)":["%",100]};var ne={none:["#00000000","#00000000"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbowzerro:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow2:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebirdzerro:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bw:["#000000ff","#ffffffff"],wb:["#ffffffff","#000000ff"],redish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]};var P={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"}};var B,se,oe;function Pe({colorStyles:r={},units:e={},colorSchemes:t={}}={}){x("WxTile lib setup: start"),B=Object.assign({},re,e),se=Object.assign({},t,ne);let n=Object.assign({},r,P);oe=Ue(n),x("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),x("WxTile lib setup is done.")}function Z(){return oe}function j(){return se}function U(r,e,t){let n=t?Object.assign({},B,t):B;if(!n||!r||!e||r===e||!n[r]||!n[e]||n[r][0]!==n[e][0]){x(r===e?"Trivial converter:":"Inconvertible units. Default converter is used:",r," -> ",e);let i=l=>l;return i.trivial=!0,i}x("Converter: From:",r," To:",e);let s=n[r][1]/n[e][1],o=(n[r][2]||0)/n[e][1]-(n[e][2]||0)/n[e][1];return o?i=>s*i+o:i=>s*i}function Ue(r){let e=Object.assign({},P);for(let s in r){let o=r[s];if(Array.isArray(o))for(let i=0;i<o.length;++i)e[s+"["+i+"]"]=Object.assign({},o[i]);else e[s]=Object.assign({},o)}let t=(s,o)=>{if(o==="base")return P.base;let i=s[o];(!i.parent||!(i.parent in s))&&(i.parent="base");let l=t(s,i.parent);return Object.assign(i,Object.assign({},l,i,{parent:"base"}))},n={};for(let s in e)n[s]=t(e,s);return n}function ie(r){let e=new Map;return t=>{let n=e.get(t);if(n===void 0){let s=r(t);return s instanceof Promise?s.then(()=>e.set(t,s)).catch(o=>{o instanceof DOMException||e.set(t,s)}):e.set(t,s),s}return n}}async function Re(r,e){let t=new Image;return t.src=URL.createObjectURL(await(await fetch(r,e.controller)).blob()),await t.decode(),URL.revokeObjectURL(t.src),t}function We(r){let{width:e,height:t}=r,n=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d");if(!n)throw"catastrophe";return n.drawImage(r,0,0),n.getImageData(0,0,e,t)}async function ae(r,e){return We(await Re(r,e))}function Fe(r,e){let t=n=>{let s=new Uint16Array(n.data.buffer),o=new Uint16Array(s.length/2);for(let a=0;a<o.length;a++)o[a]=s[a*2];let i=new Uint8Array(n.data.buffer);for(let a=0;a<8;++a)i[a]=i[a*4+2];let l=new DataView(n.data.buffer),u=l.getFloat32(0,!0),f=l.getFloat32(4,!0),b=(f-u)/65535,c=Ee(o);return{raw:o,dmin:u,dmax:f,dmul:b,integral:c,radius:0}};return ae(r,e).then(t)}function z(){let r={controller:new AbortController},e=ie(t=>Fe(t,r));return e.controllerHolder=r,e}function le(r){let e={controller:r},t=ie(n=>ae(n,e));return t.controllerHolder=e,t}function Ee(r){let e=new Uint32Array(258*258),t=new Uint32Array(258*258);e[0]=r[0],t[0]=r[0]===0?0:1;for(let n=1;n<258;++n)e[n]=r[n]+e[n-1],e[258*n]=r[258*n]+e[258*n-258],t[n]=(r[n]===0?0:1)+t[n-1],t[258*n]=(r[258*n]===0?0:1)+t[258*n-258];for(let n=1,s=259;n<258;++n,++s)for(let o=1;o<258;++o,++s)e[s]=r[s]+e[s-258]+e[s-1]-e[s-258-1],t[s]=(r[s]===0?0:1)+t[s-258]+t[s-1]-t[s-258-1];return{integral:e,integralNZ:t}}function ce(r,e){if(e<0||e===r.radius)return r;r.radius=e;let t=258,{integral:n,integralNZ:s}=r.integral;for(let o=1;o<t;o++)for(let i=1;i<t;i++){if(!r.raw[t*o+i])continue;let l=Math.min(e,i-1,t-1-i),u=Math.min(e,o-1,t-1-o),f=t*(o-u-1)+i,b=t*(o+u)+i,c=s[f-l-1],a=s[f+l],d=s[b-l-1],h=s[b+l],m=c+h-a-d,p=n[f-l-1],g=n[f+l],y=n[b-l-1],S=n[b+l],C=p+S-g-y;r.raw[o*t+i]=C/m}return r}function w(r){let e=r>>0&255,t=r>>8&255,n=r>>16&255,s=e.toString(16),o=t.toString(16),i=n.toString(16);return s=s.length===2?s:"0"+s,o=o.length===2?o:"0"+o,i=i.length===2?i:"0"+i,"#"+s+o+i}function T(r){if(r[0]==="#"){if(r.length===4)return+("0xff"+r[3]+r[3]+r[2]+r[2]+r[1]+r[1]);if(r.length===7)return+("0xff"+r[5]+r[6]+r[3]+r[4]+r[1]+r[2]);if(r.length===9)return+("0x"+r[7]+r[8]+r[5]+r[6]+r[3]+r[4]+r[1]+r[2])}return x("wrong color format",r),0}async function k(r,e){return(await fetch(r,e)).json()}function L(r,e="",t){var s;let n=document.createElement(r);return n.className=e,t&&((s=t.appendChild)==null||s.call(t,n)),n}function O(r,e,t){let n=r>>0&255,s=r>>8&255,o=r>>16&255,i=r>>>24,l=e>>0&255,u=e>>8&255,f=e>>16&255,b=e>>>24,c=n+t*(l-n),a=s+t*(u-s),d=o+t*(f-o),h=i+t*(b-i);return c|a<<8|d<<16|h<<24}function me(r,e,t){let n=[];for(let s=0;s<t;++s)n.push(s*(e-r)/(t-1)+r);return n}function ue(r,e){let t=typeof e=="number"?e:typeof e=="string"?new Date(e).getTime():e.getTime();return r.find(n=>new Date(n).getTime()>=t)||r[r.length-1]}var fe=!1;function He(r){console.log(r?"Logging on":"Logging off"),fe=r}function x(...r){fe&&console.trace(...r)}var Se=ee(N());function Ne(r,e,t){return r>t?t:r<e?e:r}var R=class{constructor(e,t,[n,s],o){let i=s-n;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let l=[];this.DataToStyle=U(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),o&&(this.DataToKnots=U(t,"knot"));let u=U(e.units,t,e.extraUnits),f=m=>~~(65535*Ne((u(m)-n)/(s-n),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((m,p)=>m[0]<p[0]?-1:m[0]>p[0]?1:0);for(let[m]of e.colorMap)l.push(f(m))}else{if(e.levels||(e.levels=me(this.DataToStyle(n),this.DataToStyle(s),10)),e.levels.sort((m,p)=>m<p?-1:m>p?1:0),!e.colors){let m=j();e.colorScheme&&e.colorScheme in m?e.colors=m[e.colorScheme]:e.colors=m.wb}for(let m of e.levels)l.push(f(m))}let b=65536,c=G(b,e);this.ticks=c.ticks;let a=c.ticks[0].data,h=c.ticks[c.ticks.length-1].data-a;for(let m=0;m<65536;++m){let p=i*m/65535+n,g=this.DataToStyle(p),y=Math.round((b-1)*(g-a)/h);y<=0?this.colorsI[m]=e.showBelowMin?c.colors[0]:0:y>=b?this.colorsI[m]=e.showAboveMax?c.colors[b-1]:0:this.colorsI[m]=c.colors[y]}this.colorsI[0]=0;for(let m=0;m<l[0];++m)this.levelIndex[m]=0;for(let m=0;m<l.length-1;m++)for(let p=l[m];p<l[m+1]+1;++p)this.levelIndex[p]=m;for(let m=l[l.length-1];m<65536;++m)this.levelIndex[m]=l.length-1}};function de(r){var t;if(r!==0&&-.1<r&&r<.1)return r.toExponential(2);let e=r.toString();return((t=e.split(".")[1])==null?void 0:t.length)>2?r.toFixed(2):e}function G(r,e){let t={size:r,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(r),ticks:[]},{colorMap:n,levels:s,colors:o}=e,i=e.fill!=="solid";if(n){let a=n[0][0],d=n[n.length-1][0]-a;for(let[h,m]of n){let p=~~((h-a)/d*(r-1)),g={data:h,dataString:de(h),color:m,pos:p};t.ticks.push(g)}for(let h=0;h<n.length-1;h++){let m=t.ticks[h].pos,p=t.ticks[h+1].pos,g=T(n[h][1]),y=i?T(n[h+1][1]):0;for(let S=m;S<p;++S)t.colors[S]=i?O(g,y,(S-m)/(p-m)):g}return t.colors[r-1]=T(n[n.length-1][1]),t}if(!o||!s)return t;let l=0,u=0,f=-1;for(let a=0;a<r;++a){let d=a*(o.length-1)/r;f!==~~d&&(f=~~d,l=T(o[f]),u=o.length>f+1?T(o[f+1]):l),t.colors[a]=i?O(l,u,d-f):l}t.colors[r-1]=T(o[o.length-1]);let b=s[0],c=(r-1)/(s[s.length-1]-b);for(let a of s){let d=~~((a-b)*c),h={data:a,dataString:de(a),color:w(t.colors[d]),pos:d};t.ticks.push(h)}return t}var Q=256,Be=2*Math.PI*6378137/Q,W=2*Math.PI*6378137/2;function Ze(r,e){let t=r/W*180,n=e/W*180;return n=180/Math.PI*(2*Math.atan(Math.exp(n*Math.PI/180))-Math.PI/2),[n,t]}function je(r,e,t){let n=ze(t),s=r*n-W,o=e*n-W;return[s,o]}function ze(r){return Be/Math.pow(2,r)}function q(r,e,t){let[n,s]=Ze(...je(r,e,t));return[s,-n]}function he(r,e){return[r*Q,e*Q]}var Oe="A".charCodeAt(0),K,D=0;async function Ge(r,e){let t;try{t=await(await fetch(r,e)).json()}catch(n){console.log("Can't load QTree:",n);return}K=A(t,{pos:0}),D=be(K),console.log("Loaded QTree, depth:",D)}function A(r,e){let t=r.charCodeAt(e.pos)-Oe;e.pos++;let n=t&1?A(r,e):null,s=t&2?A(r,e):null,o=t&4?A(r,e):null,i=t&8?A(r,e):null;return{sub:n||s||o||i?[n,s,o,i]:null}}function be(r){let e=0;if(r==null?void 0:r.sub){for(let t=0;t<4;t++)if(r.sub[t]!==null){let n=be(r.sub[t])+1;e<n&&(e=n)}}return e}var v;(function(n){n.Land="land",n.Mixed="mixed",n.Sea="sea"})(v||(v={}));function ge(r){if(!D)return v.Mixed;let e=Y({},r),t=!1;if(D<=r.z){t=!0;let n=r.z-D;e={x:r.x>>n,y:r.y>>n,z:D}}return xe(K,e,t)}function xe(r,e,t){if(r===null)return v.Land;if(t&&e.z===0)return v.Mixed;if(r.sub===null)return v.Sea;if(e.z===0)return v.Mixed;e.z--;let n=e.x>>e.z&1,o=(e.y>>e.z&1)<<1|n;return xe(r.sub[o],e,t)}function Qe(r,e){if(!e)return r;let t=.9999999/Math.pow(2,e.z),n=e.x*256*t,s=e.y*256*t,o={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:i}=o;for(let l=-1,u=0;l<=256;l++){let f=s+l*t,b=Math.floor(f),c=f-b;for(let a=-1;a<=256;a++,u++){let d=n+a*t,h=Math.floor(d),m=d-h,p=h+1+(b+1)*258,g=r.raw[p],y=r.raw[p+1],S=r.raw[p+258],C=r.raw[p+258+1];switch((g?1:0)|(y?2:0)|(S?4:0)|(C?8:0)){case 0:i[u]=0;continue;case 1:i[u]=g;continue;case 2:i[u]=y;continue;case 3:S=g,C=y;break;case 4:i[u]=S;continue;case 5:y=g,C=S;break;case 6:C=y+S>>1,g=C;break;case 7:C=y+S>>1;break;case 8:i[u]=C;continue;case 9:y=g+C>>1,S=y;break;case 10:g=y,S=C;break;case 11:S=g+C>>1;break;case 12:g=S,y=C;break;case 13:y=g+C>>1;break;case 14:g=y+S>>1;break}g=r.dmin+r.dmul*g,y=r.dmin+r.dmul*y,S=r.dmin+r.dmul*S,C=r.dmin+r.dmul*C;let I=V(g,y,m),M=V(S,C,m);i[u]=(V(I,M,c)-r.dmin)/r.dmul,i[u]===0&&(i[u]=1)}}return o}function V(r,e,t){let n=((e-r)%360+540)%360-180;return(r+n*t+360)%360}function qe(r,e){if(!e)return r;let t=.9999999/Math.pow(2,e.z),n=e.x*256*t,s=e.y*256*t,o={raw:new Uint16Array(258*258),dmin:r.dmin,dmax:r.dmax,dmul:r.dmul},{raw:i}=o;for(let l=-1,u=0;l<=256;l++){let f=s+l*t,b=Math.floor(f),c=f-b;for(let a=-1;a<=256;a++,u++){let d=n+a*t,h=Math.floor(d),m=d-h,p=h+1+(b+1)*258,g=r.raw[p],y=r.raw[p+1],S=r.raw[p+258],C=r.raw[p+258+1];switch((g?1:0)|(y?2:0)|(S?4:0)|(C?8:0)){case 7:i[u]=m+c<1?m*(y-g)+c*(S-g)+g:0;continue;case 14:i[u]=m+c<1?0:m*(C-S)+c*(C-y)+y+S-C;continue;case 11:i[u]=c<m?(1-m)*(g-y)+c*(C-y)+y:0;continue;case 13:i[u]=c<m?0:(1-m)*(S-C)+c*(S-g)+g+C-S;continue;case 15:i[u]=m+c<1?m*(y-g)+c*(S-g)+g:m*(C-S)+c*(C-y)+y+S-C;continue;default:i[u]=0}}}return o}function Ke(r,e,t){let n=t==="land"?1:0;for(let s=3,o=0;o<256;o++)for(let i=0;i<256;i++,s+=4){let l=e.data[s]?1:0;n^l&&(r.raw[(o+1)*258+(i+1)]=0)}return r}function Ve(r){let[e,t]=he(r.x,r.y),[n,s]=q(e,t,r.z),[o,i]=q(e+256,t+256,r.z);return{west:n,north:s,east:o,south:i}}function ye({layer:r,coords:e,done:t}){let n=L("div","leaflet-tile s-tile");return n.wxtile=new pe({layer:r,coords:e,tileEl:n}),n.wxtile.load().then(s=>{s.draw(),t()}),n}var pe=class{constructor({layer:e,coords:t,tileEl:n}){this.data=[];this.sLines=[];this.coords=t,this.layer=e,this.canvasFill=L("canvas","s-tile canvas-fill",n),this.canvasSlines=L("canvas","s-tile canvas-slines",n),this.canvasVector=this.canvasFill,this.canvasFill.width=this.canvasFill.height=this.canvasSlines.width=this.canvasSlines.height=256;function s(o){let i=o.getContext("2d");if(!i)throw"error";return i}this.canvasFillCtx=s(this.canvasFill),this.imData=this.canvasFillCtx.createImageData(256,256),this.canvasSlinesCtx=s(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasSlinesCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVector(),this._drawDegree(),this._drawStaticSlines())}clearSLinesCanvas(){this.canvasSlinesCtx.clearRect(0,0,256,256)}drawSLines(e){if(this.sLines.length===0)return;let t=this.canvasSlinesCtx;if(t.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.sLines=[];return}let n=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let s=0;s<this.sLines.length;++s){let o=this.sLines[s],i=o.length-1,l=(e+(1+o[0].x)*(1+o[0].y))%30;for(let u=0;u<i;++u){let f=o[u],b=o[u+1],c=1-(l-u)/i;(c<0||c>1)&&(c=0);let a=(~~(c*255)).toString(16);t.strokeStyle=n+(a.length<2?"0"+a:a);let d=1+~~((1.2-c)*5);t.lineWidth=d,t.beginPath(),t.moveTo(f.x,f.y),t.lineTo(b.x,b.y),t.stroke()}}}getData({x:e,y:t}){if(!this.data.length)return;let n=this.data[0].raw[(t+1)*258+(e+1)];return{raw:n,data:this.data[0].dmin+this.data[0].dmul*n}}async load(){var c;let{coords:e,layer:t}=this,{boundaries:n}=t.state.meta,s=this.layer.style.mask;var o;if((s==="land"||s==="sea")&&(o=ge(e),s===o))return this.data=[],this.sLines=[],this;if(n==null?void 0:n.boundaries180){let a=Ve(e),d=h=>!(a.west>h.east||h.west>a.east||a.south>h.north||h.south>a.north);if(!n.boundaries180.some(d))return this.data=[],this.sLines=[],this}let{upCoords:i,subCoords:l}=this._splitCoords(e),u=this._coordsToURLs(i),f;try{f=await Promise.all(u.map(t.loadData))}catch(a){return this}let b=((c=t.state)==null?void 0:c.units)==="degree"?Qe:qe;if(this.data=f.map(a=>b(ce(a,this.layer.style.blurRadius),l)),this.layer.vector&&this._vectorPrepare(),s&&o===v.Mixed){let a=t.state.maskServerURI.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));try{let d=await t.loadMask(a);Ke(this.data[0],d,s)}catch(d){this.layer.style.mask=void 0,x("Can't load Mask. Turned off")}}return this.layer.vector&&this._createSLines(),this}_splitCoords(e){let t=e.z-this.layer.state.meta.maxZoom;if(t<=0)return{upCoords:e};let n={x:e.x>>>t,y:e.y>>>t,z:this.layer.state.meta.maxZoom},s={x:e.x&(1<<t)-1,y:e.y&(1<<t)-1,z:t};return{upCoords:n,subCoords:s}}_coordsToURLs(e){let t=this.layer.state.baseURL.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y));return this.layer.dataSource.variables.map(n=>t.replace("{var}",n))}_vectorPrepare(){if(this.data.length!==2)throw"this.data !== 2";this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[e,t,n]=this.data;e.dmax=1.42*Math.max(-t.dmin,t.dmax,-n.dmin,n.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let s=0;s<258*258;++s){if(!t.raw[s]||!n.raw[s]){e.raw[s]=0;continue}let o=t.dmin+t.dmul*t.raw[s],i=n.dmin+n.dmul*n.raw[s];e.raw[s]=Math.sqrt(i*i+o*o)/e.dmul}}_drawFillAndIsolines(){let{imData:e}=this,{canvasFillCtx:t}=this,n=new Uint32Array(e.data.buffer),{raw:s}=this.data[0],{clut:o,style:i}=this.layer,{levelIndex:l,colorsI:u}=o;if(i.fill!=="none"){let b=u;for(let c=0,a=0,d=259;c<256;++c,d+=2)for(let h=0;h<256;++h,++a,++d)n[a]=b[s[d]]}else n.fill(0);let f=[];if(i.isolineColor!=="none"){let b=i.isolineColor[0]==="#"?T(i.isolineColor):0;for(let c=0,a=0;c<256;c+=1)for(let d=0;d<256;d+=1){let h=(c+1)*258+(d+1),m=s[h],p=s[h+1],g=s[h+258];if(!m||!p||!g)continue;let y=l[m],S=l[p],C=l[g];if(y!==S||y!==C){let H=Math.max(y,S,C),I=Math.max(m,p,g),M=c*256+d;switch(i.isolineColor){case"inverted":n[M]=~u[I]|4278190080;break;case"fill":n[M]=u[I]|4278190080;break;default:n[M]=b;break}i.isolineText&&!(++a%255)&&d>20&&d<235&&c>20&&c<235&&f.push({x:d,y:c,d:m,dr:p,db:g,mli:H})}}}if(t.putImageData(e,0,0),f.length){t.font="1.1em Sans-serif",t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";for(let{x:b,y:c,d:a,dr:d,db:h,mli:m}of f){let p=this.layer.clut.ticks[m].dataString,g=Math.atan2(a-d,h-a);t.save(),t.translate(b,c),t.rotate(g<-1.57||g>1.57?g+3.14:g),t.strokeText(p,0,0),t.fillText(p,0,0),t.restore()}}}_drawStaticSlines(){if(!this.sLines.length||!this.layer.style.streamLineStatic)return;let{canvasSlinesCtx:e}=this;if(this.layer.style.streamLineColor==="none"){this.sLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let t=this.sLines.length;t--;){let n=this.sLines[t];for(let s=0;s<n.length-1;++s){let o=n[s],i=n[s+1];e.moveTo(o.x,o.y),e.lineTo(i.x,i.y)}}e.stroke()}_drawVector(){if(!this.layer.vector||!this.layer.clut.DataToKnots||!this.layer.style.vectorColor||this.layer.style.vectorColor==="none"||!this.layer.style.vectorType||this.layer.style.vectorType==="none")return;if(this.data.length!==3)throw"this.data.length !== 3";let[e,t,n]=this.data,{canvasVectorCtx:s}=this;switch(this.layer.style.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=this.layer.style.vectorType}s.textAlign="center",s.textBaseline="middle";let o=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0,i=32;for(let l=i/2;l<256;l+=i)for(let u=i/2;u<256;u+=i){let f=u+1+(l+1)*258;if(!e.raw[f])continue;let b=Math.atan2(t.dmin+t.raw[f]*t.dmul,n.dmin+n.raw[f]*n.dmul),c=e.dmin+e.raw[f]*e.dmul,a=this.layer.dataSource.variables[0].includes("current")?5:.2,d=Math.min(this.layer.clut.DataToKnots(c)*a,25)+65,h=String.fromCharCode(d);switch(this.layer.style.vectorColor){case"inverted":s.fillStyle=w(~this.layer.clut.colorsI[e.raw[f]]);break;case"fill":s.fillStyle=w(this.layer.clut.colorsI[e.raw[f]]);break;default:s.fillStyle=this.layer.style.vectorColor;break}s.save(),s.translate(u,l),s.rotate(b+o),s.fillText(h,0,0),s.restore()}}_drawDegree(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:e}=this,t=this.layer.style.addDegrees?.017453292519943*this.layer.style.addDegrees:0;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle";let n=this.data[0],s="L",o=32;for(let i=o/2;i<256;i+=o)for(let l=o/2;l<256;l+=o){let u=l+1+(i+1)*258;if(!n.raw[u])continue;let b=(n.dmin+n.raw[u]*n.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=w(~this.layer.clut.colorsI[n.raw[u]]);break;case"fill":e.fillStyle=w(this.layer.clut.colorsI[n.raw[u]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(l,i),e.rotate(b+t),e.fillText(s,0,0),e.restore()}}_createSLines(){if(this.data.length!==3)throw"this.data.length !== 3";if(!this.layer.style.streamLineColor||this.layer.style.streamLineColor==="none")return;let e=this.layer.style.streamLineSpeedFactor||1;this.sLines=[];let[t,n,s]=this.data,o=Math.max(this.coords.z-this.layer.state.meta.maxZoom,0),i=Math.min(2**(o+5),128),l=~~(120+o*60);for(let u=0;u<=256;u+=i)for(let f=0;f<=256;f+=i){if(!t.raw[1+f+(1+u)*258])continue;let b=[],c=f,a=u;for(let d=0;d<=l&&c>=0&&c<=256&&a>=0&&a<=256;d++){!(d%(l/6))&&b.push({x:~~c,y:~~a});let h=~~c+1+(~~a+1)*258;if(!t.raw[h])break;c+=e*(n.dmin+n.raw[h]*n.dmul)/t.dmax,a-=e*(s.dmin+s.raw[h]*s.dmul)/t.dmax}c=f,a=u;for(let d=1;d<=l&&c>=0&&c<=256&&a>=0&&a<=256;d++){!(d%(l/6))&&b.unshift({x:~~c,y:~~a});let h=~~c+1+(~~a+1)*258;if(!t.raw[h])break;c-=e*(n.dmin+n.raw[h]*n.dmul)/t.dmax,a+=e*(s.dmin+s.raw[h]*s.dmul)/t.dmax}b.length>2&&this.sLines.push(b)}}};var Ce="setup not complete",Xe=le(new AbortController),F=class extends Se.default.GridLayer{constructor({dataSource:e,options:t,lazy:n}){super(t);this.styles=Z();this.style=Object.assign({},this.styles.base);this.loadData=z();this.loadMask=Xe;this.error=Ce;this.vector=!1;this.clut=new R(this.style,"",[0,2],!1);this.animation=!1;this.animationRedrawID=0;this.animFrame=0;this.oldMaxZoom=0;if(x("Creating a WxTilex layer:",e.name,". Params:",JSON.stringify({dataSource:e,options:t})),!e||!e.ext||!e.dataset||!e.name||!e.serverURI||!e.styleName||!Array.isArray(e.variables))throw x("dataSource is wrong!"),"dataSource is wrong!";this.dataSource=e,this.state={maskServerURI:e.maskServerURI||e.serverURI.replace(/\/data\/?/i,"/mask/{z}/{x}/{y}"),units:"undefined",baseURL:"undefined",meta:{maxZoom:0,times:["undefined"],variables:["undefined"],variablesMeta:{}},instance:"undefined",minmax:[[0,1]],originURI:"undefined",time:"undefined"},this.setupCompletePromise=new Promise(s=>{let o=()=>{x("Setup:",e.name),this.on("remove",this._onRemoveLayer,this),this.on("add",this._onAddLayer,this),this._setUpDataSet(e).then(i=>{x("Setup complete:",this.dataSource.name,". Result:",i),this._map&&n&&this._onAddLayer(),this.fire("setupcomplete",{layer:this}),s(i)})};n?this.once("add",o):o()})}createTile(e,t){return this.error&&this.error!==Ce?(setTimeout(t),Object.assign(L("div","error-tile"),{innerHTML:this.error})):this.state.baseURL==="undefined"?(setTimeout(t),L("div","error-tile")):ye({layer:this,coords:e,done:t})}getSetupCompletePromise(){return this.setupCompletePromise}getTile(e){if(!this._map||this.error)return;let t=this._map.getZoom(),{x:n,y:s}=this._map.project(e,t),o={x:~~(n/256),y:~~(s/256)},i=this._getCachedTile(o.x,o.y,t);if(!i)return;let l={x:~~(n-o.x*256),y:~~(s-o.y*256)},u=i.getData(l);if(!u)return;let{raw:f,data:b}=u,c=this.clut.colorsI[f],a=w(c),d=this.clut.DataToStyle(b);return{tile:i,data:b,raw:f,rgba:c,hexColor:a,inStyleUnits:d,tilePoint:l,units:this.style.units}}setStyle(e){if(x("setStyle(",e,") for ",this.dataSource.name),this.error){x("setStyle: failed: "+this.error);return}if(!(this.dataSource.styleName===e&&e!=="custom")){if(e&&(this.dataSource.styleName=e),e==="custom"&&this.styles.custom){(!this.styles.custom.parent||!(this.styles.custom.parent in this.styles))&&(this.styles.custom.parent="base");let t=this.styles[this.styles.custom.parent];this.styles.custom=Object.assign(Object.assign({},t),this.styles.custom)}this.dataSource.styleName in this.styles?Array.isArray(this.styles[this.dataSource.styleName])&&(this.dataSource.styleName+="[0]"):(x(`cant find the style (${this.dataSource.styleName})`),this.dataSource.styleName+="[0]",this.dataSource.styleName in this.styles||(x(`cant find the style (${this.dataSource.styleName}), default is used`),this.dataSource.styleName="base"));try{let t=this.styles[this.dataSource.styleName];this.style=Object.assign({},t);let n=this.style.streamLineColor;n!=="none"&&n.length<7&&(this.style.streamLineColor="#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]);let s=this.state.minmax[0];this.clut=new R(this.style,this.state.units,s,this.vector)}catch(t){let n="setStyle: impossible error in RawCLUT: "+t;throw x(n),n}e&&(this._checkAndStartSlinesAnimation(),this._reloadTiles()),x("setStyle(",e,'): "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete."),this.fire("setstyle",{layer:this})}}getStyle(){return this.dataSource.styleName}getStyleName(){return this.style.name}setTime(e){if(x("setTime: "+e+" for "+this.dataSource.name+" start"),this.error)return x("setTime: failed: "+this.error),Promise.resolve([]);let t=ue(this.state.meta.times,e);if(this.state.time===t)return x("setTime: the same time - skipped"),Promise.resolve([]);if(this.state.time=t,this.state.baseURL=this.state.originURI+this.state.instance+`{var}/${this.state.time}/{z}/{x}/{y}.${this.dataSource.ext}`,this.fire("settime",{layer:this,layerTime:t}),x("setTime: "+t+" for "+this.dataSource.name+" complete"),!this._tiles)return Promise.resolve([]);let n=this._reloadTiles(!1);return n.then(()=>{var o;let s=Object.values(this._tiles);for(let i of s){let l=(o=i.el)==null?void 0:o.wxtile;if(l==null?void 0:l.data.length){let[u,f]=this.state.minmax[0],{dmin:b,dmax:c}=l.data[0];(Math.abs(b-u)>.01||Math.abs(c-f)>.01)&&(this.state.minmax=l.data.map(a=>[a.dmin,a.dmax]),this.setStyle(void 0));break}}this._redrawTiles()}),n}getTime(){return this.error?(x("getTime: failed: "+this.error),this.error):this.state.time}getTimes(){return x("getTimes"),this.error?(x("getTimes: failed: "+this.error),[]):this.state.meta.times}async checkDataChanged(){if(x("checkDataChanged"),this.error)return x("checkDataChanged: failed: "+this.error),!1;let e=await k(this.state.originURI+"instances.json"),t=e[e.length-1]+"/";if(this.state.instance!==t)return!0;let n=await k(this.state.originURI+t+"meta.json");return this.state.meta.times.toString()!==n.times.toString()}reloadData(){return x("reloadData"),this._setUpDataSet(void 0)}getLegendData(e){return x("getLegendData"),(this.error||!this.clut)&&x("getLegendData: failed. "+this.dataSource.name+" : "+this.error),G(e,this.style)}setTimeAnimationMode(e=2){x("setTimeAnimationMode"),this.oldMaxZoom=this.state.meta.maxZoom;let t=this._map.getZoom(),s=(t<this.oldMaxZoom?t:this.oldMaxZoom)-e;this.state.meta.maxZoom=s<0?0:s}unsetTimeAnimationMode(){return x("unsetTimeAnimationMode"),this.oldMaxZoom&&(this.state.meta.maxZoom=this.oldMaxZoom),this._reloadTiles()}getMinMax(){let[e,t]=this.state.minmax[0];return{min:e,max:t}}setAnimation(e){return x("setAnimation"),this.animation=e,this._checkAndStartSlinesAnimation(),this.animation}_getCachedTile(e,t,n){var s,o;return(o=(s=this._tiles[`${e}:${t}:${n}`])==null?void 0:s.el)==null?void 0:o.wxtile}_ForEachTile(e){var n;let t=[];for(let s in this._tiles){let o=(n=this._tiles[s].el)==null?void 0:n.wxtile,i=o&&e(o);i&&t.push(i)}return t}async _setUpDataSet(e){e&&(this.dataSource=e),this._stopLoadingResetLoadDataFunc(),this.state.originURI=this.dataSource.serverURI+"/"+this.dataSource.dataset+"/";try{let t=await k(this.state.originURI+"instances.json");this.state.instance=t[t.length-1]+"/"}catch(t){return this.error=this.dataSource.name+": load instances.json error: "+t,x(this.error),!1}try{let t=this.state.originURI+this.state.instance+"meta.json";this.state.meta=await k(t)}catch(t){return this.error=this.dataSource.name+": load meta.json error: "+t,x(this.error),!1}if(this.vector=this.dataSource.variables.length===2,this.animation=this.vector,this.state.units=this.state.meta.variablesMeta[this.dataSource.variables[0]].units,this.state.minmax=this.dataSource.variables.map(t=>[this.state.meta.variablesMeta[t].min,this.state.meta.variablesMeta[t].max]),this.vector){let[[t,n],[s,o]]=this.state.minmax;this.state.minmax.unshift([0,1.42*Math.max(-t,n,-s,o)])}return this.error=null,e&&(this.setStyle(void 0),await this.setTime(new Date)),!0}_checkZoom(){var e;((e=this._map)==null?void 0:e.getZoom())>this.state.meta.maxZoom||this._stopLoadingResetLoadDataFunc()}_onAddLayer(){var e;x("onadd:",this.dataSource.name),(e=this._map)==null||e.on("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this.redraw(),this._checkAndStartSlinesAnimation()})}_onRemoveLayer(){var e;x("onremove:",this.dataSource.name),(e=this._map)==null||e.off("zoomstart",this._checkZoom,this),this.setupCompletePromise.then(()=>{this._stopLoadingResetLoadDataFunc(),this._stopSlinesAnimation()})}_stopLoadingResetLoadDataFunc(){this.loadData.controllerHolder.controller.abort(),this.loadData=z()}_checkAndStartSlinesAnimation(){if(this.animFrame||!this.animation||!this.vector||!this.style.streamLineColor||this.style.streamLineColor==="none")return;let e=t=>{if(!this.animation||this.style.streamLineStatic){this._stopSlinesAnimation();return}this._ForEachTile(n=>n.drawSLines(t)),this.animFrame=requestAnimationFrame(e)};e(0)}_stopSlinesAnimation(){cancelAnimationFrame(this.animFrame),this._ForEachTile(e=>e.clearSLinesCanvas()),this.animFrame=0}_redrawTiles(){this.animationRedrawID===0&&(this.animationRedrawID=requestAnimationFrame(()=>{x("_redrawTiles: requestAnimationFrame: "+this.dataSource.name),this._ForEachTile(e=>e.draw()),this.animationRedrawID=0}))}_reloadTiles(e=!0){x("_reloadTiles: start - "+this.dataSource.name),this.loadData.controllerHolder.controller.abort(),this.loadData.controllerHolder.controller=new AbortController;let t=this._ForEachTile(o=>o.load()),n=Promise.all(t),{controller:s}=this.loadData.controllerHolder;return e&&n.then(()=>s.signal.aborted||this._redrawTiles()),x("_reloadTiles: finished - "+this.dataSource.name),n}};function $e(r){return new F(r)}var we=class extends E.default.Control{constructor(e){super(e);this.URI=e.URI}onAdd(){let e=document.createElement("img");return e.src=this.URI,e.className="wxtiles-logo",e}};function Ut(r){return x("Add watermark:",JSON.stringify(r)),new we(r)}var Te=class extends E.default.GridLayer{createTile(e){let t=document.createElement("div");return t.innerHTML=[e.x,e.y,e.z].join(", "),t.style.outline="1px solid red",t}};function Rt(){return x("Add WxDebugCoordsLayer:"),new Te().setZIndex(1e3)}function Wt(r,e){return E.default.layerGroup(r.map($e),e)}export{Rt as CreateWxDebugCoordsLayer,Wt as CreateWxTilesGroupLayer,$e as CreateWxTilesLayer,Ut as CreateWxTilesWatermark,Ge as LoadQTree,Te as WxDebugLayer,j as WxGetColorSchemes,Z as WxGetColorStyles,F as WxTilesLayer,Pe as WxTilesLibSetup,He as WxTilesLogging,we as WxWatermark};
1
+ var Me=Object.create;var _=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var Ae=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols,Re=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable;var Y=(n,e,t)=>e in n?_(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,ee=(n,e)=>{for(var t in e||(e={}))J.call(e,t)&&Y(n,t,e[t]);if(X)for(var t of X(e))_e.call(e,t)&&Y(n,t,e[t]);return n};var Ue=n=>_(n,"__esModule",{value:!0});var at=typeof require!="undefined"?require:n=>{throw new Error('Dynamic require of "'+n+'" is not supported')};var Pe=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var Fe=(n,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ae(e))!J.call(n,r)&&r!=="default"&&_(n,r,{get:()=>e[r],enumerable:!(t=ke(e,r))||t.enumerable});return n},te=n=>Fe(Ue(_(n!=null?Me(Re(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var O=Pe((ct,re)=>{re.exports=window.L});var B=te(O());var ne={comment1:["'degC': ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["'hPa': ['Pa', 1000]' -> hPa = Pa * 1000 + 0 (0 - could be ommited)",0],K:["K",1],kelvin:["K",1],F:["K",.5555555555,255.372222222],C:["K",1,273.15],degC:["K",1,273.15],"kg/m^2/s":["kg/m^2/s",1],"Kg/m^2/s":["kg/m^2/s",1],"Kg m**-2 s**-1":["kg/m^2/s",1],"Kg m^-2 s^-1":["kg/m^2/s",1],"Kg m^{-2} s^-1":["kg/m^2/s",1],"mm/h":["kg/m^2/s",.00027777777],"mm/hr":["kg/m^2/s",.00027777777],"W/m^2":["W/m^2",1],"W m^-2":["W/m^2",1],"W m^{-2}":["W/m^2",1],"W/m**2":["W/m^2",1],"W m**-2":["W/m^2",1],"m/s":["m/s",1],"m s**-1":["m/s",1],"m s^-1":["m/s",1],"m.s^{-1}":["m/s",1],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["m/s",.27777777777],"km h^-1":["m/s",.27777777777],"km h**-1":["m/s",.27777777777],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],inch:["m",.0254],Pa:["Pa",1],hPa:["Pa",100],degree:["degree",1],radian:["degree",57.3],"mg/m^3":["mg/m^3",1],"mg m^-3":["mg/m^3",1],"mg.m^-3":["mg/m^3",1],"%":["%",1],"(0 - 1)":["%",100]};var oe={none:["#00000000","#00000000"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbowzerro:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow2:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebirdzerro:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bw:["#000000ff","#ffffffff"],wb:["#ffffffff","#000000ff"],redish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]};var U={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",vectorFactor:1,streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",vectorFactor:1,streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"}};var ae,se,ie;function We({colorStyles:n={},units:e={},colorSchemes:t={}}={}){b("WxTile lib setup: start"),ae=Object.assign({},ne,e),se=Object.assign({},t,oe);let r=Object.assign({},n,U);ie=Ee(r),b("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),b("WxTile lib setup is done.")}function H(){return ie}function j(){return se}function P(n,e,t){b("makeConverter: From=",n," To=",e);let r=d=>d;if(r.trivial=!0,n===e)return b("Trivial converter"),r;let o=Object.assign({},ae,t);if(!o[n]||!o[e])return b("Inconvertible units. Trivial converter"),r;let[a,s,i]=o[n],[u,l,m]=o[e];if(a!==u||!s||!l)return b("Inconvertible units. Trivial converter"),r;let f=s/l,h=((i||0)-(m||0))/l;return h?d=>f*d+h:d=>f*d}function Ee(n){let e=Object.assign({},U);for(let o in n){let a=n[o];if(Array.isArray(a))for(let s=0;s<a.length;++s)e[o+"["+s+"]"]=Object.assign({},a[s]);else e[o]=Object.assign({},a)}let t=(o,a)=>{if(a==="base")return U.base;let s=o[a];(!s.parent||!(s.parent in o))&&(s.parent="base");let i=t(o,s.parent);return Object.assign(s,Object.assign({},i,s,{parent:"base"}))},r={};for(let o in e)r[o]=t(e,o);return r}function qe(n){let e=new Map;return t=>{let r=e.get(t);if(r)return r;let o=n(t);return e.set(t,o),o.catch(a=>{a.code===DOMException.ABORT_ERR&&e.delete(t)}),o}}async function Be(n,e){let t=new Image;return t.src=URL.createObjectURL(await(await fetch(n,e)).blob()),await t.decode(),URL.revokeObjectURL(t.src),t}function Oe(n){let{width:e,height:t}=n,r=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d");if(!r)throw new Error("Error: can not create context. Catastrophe");return r.drawImage(n,0,0),r.getImageData(0,0,e,t)}async function le(n,e){return Oe(await Be(n,e))}function He(n){n.data[34]<1&&b("Warning: image is in too old format. Check the version of the Splitter.");let e=new Uint16Array(n.data.buffer),t=new Uint16Array(e.length/2);for(let l=0;l<t.length;l++)t[l]=e[l*2];let r=new Uint8Array(8);for(let l=0;l<8;++l)r[l]=n.data[l*4+2];let o=new DataView(r.buffer),a=o.getFloat32(0,!0),s=o.getFloat32(4,!0),i=(s-a)/65535,u=ze(t);return{raw:t,dmin:a,dmax:s,dmul:i,integral:u,radius:0}}async function je(n,e){return He(await le(n,e))}function ce(n,e){let t={controller:new AbortController,debug:Date.now().toString()},r=Object.assign({},e,{signal:t.controller.signal}),o=qe(a=>n(a,r));return o.controllerHolder=t,o.abort=()=>{t.controller.abort(),t.controller=new AbortController,t.debug=Date.now().toString(),r.signal=t.controller.signal},o}function z(n){return ce(je,n)}function ue(n){return ce(le,n)}function ze(n){let e=new Uint32Array(258*258),t=new Uint32Array(258*258);e[0]=n[0],t[0]=n[0]===0?0:1;for(let r=1;r<258;++r)e[r]=n[r]+e[r-1],e[258*r]=n[258*r]+e[258*r-258],t[r]=(n[r]===0?0:1)+t[r-1],t[258*r]=(n[258*r]===0?0:1)+t[258*r-258];for(let r=1,o=259;r<258;++r,++o)for(let a=1;a<258;++a,++o)e[o]=n[o]+e[o-258]+e[o-1]-e[o-258-1],t[o]=(n[o]===0?0:1)+t[o-258]+t[o-1]-t[o-258-1];return{integral:e,integralNZ:t}}function me(n,e){if(e<0||e===n.radius)return n;n.radius=e;let t=258,{integral:r,integralNZ:o}=n.integral;for(let a=1;a<t;a++)for(let s=1;s<t;s++){if(!n.raw[t*a+s])continue;let i=Math.min(e,s-1,t-1-s),u=Math.min(e,a-1,t-1-a),l=t*(a-u-1)+s,m=t*(a+u)+s,f=o[l-i-1],h=o[l+i],d=o[m-i-1],g=o[m+i],c=f+g-h-d,x=r[l-i-1],p=r[l+i],S=r[m-i-1],y=r[m+i],C=x+y-p-S;n.raw[a*t+s]=C/c}return n}function w(n){let e=n>>0&255,t=n>>8&255,r=n>>16&255,o=e.toString(16),a=t.toString(16),s=r.toString(16);return o=o.length===2?o:"0"+o,a=a.length===2?a:"0"+a,s=s.length===2?s:"0"+s,"#"+o+a+s}function I(n){if(n[0]==="#"){if(n.length===4)return+("0xff"+n[3]+n[3]+n[2]+n[2]+n[1]+n[1]);if(n.length===7)return+("0xff"+n[5]+n[6]+n[3]+n[4]+n[1]+n[2]);if(n.length===9)return+("0x"+n[7]+n[8]+n[5]+n[6]+n[3]+n[4]+n[1]+n[2])}return b("wrong color format",n),0}async function k(n,e){return(await fetch(n,e)).json()}function F(n,e="",t){var o;let r=document.createElement(n);return r.className=e,t&&((o=t.appendChild)==null||o.call(t,r)),r}function Z(n,e,t){let r=n>>0&255,o=n>>8&255,a=n>>16&255,s=n>>>24,i=e>>0&255,u=e>>8&255,l=e>>16&255,m=e>>>24,f=r+t*(i-r),h=o+t*(u-o),d=a+t*(l-a),g=s+t*(m-s);return f|h<<8|d<<16|g<<24}function fe(n,e,t){let r=[];for(let o=0;o<t;++o)r.push(o*(e-n)/(t-1)+n);return r}function de(n,e){let t=typeof e=="number"?e:typeof e=="string"?new Date(e).getTime():e.getTime();return n.find(r=>new Date(r).getTime()>=t)||n[n.length-1]}var he=!1;function Ze(n){console.log(n?"Logging on":"Logging off"),he=n}function b(...n){he&&console.trace(...n)}function be(n){return n[0]==="#"&&n.length===4?"#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]:n}var ve=te(O());function Ve(n,e,t){return n>t?t:n<e?e:n}var W=class{constructor(e,t,[r,o],a){let s=o-r;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let i=[];this.DataToStyle=P(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),a&&(this.DataToKnots=P(t,"knot"));let u=P(e.units,t,e.extraUnits),l=c=>~~(65535*Ve((u(c)-r)/(o-r),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((c,x)=>c[0]<x[0]?-1:c[0]>x[0]?1:0);for(let[c]of e.colorMap)i.push(l(c))}else{if(e.levels||(e.levels=fe(this.DataToStyle(r),this.DataToStyle(o),10)),e.levels.sort((c,x)=>c<x?-1:c>x?1:0),!e.colors){let c=j();e.colorScheme&&e.colorScheme in c?e.colors=c[e.colorScheme]:e.colors=c.wb}for(let c of e.levels)i.push(l(c))}let m=65536,f=V(m,e);this.ticks=f.ticks;let h=f.ticks[0].data,g=f.ticks[f.ticks.length-1].data-h;for(let c=0;c<65536;++c){let x=s*c/65535+r,p=this.DataToStyle(x),S=Math.round((m-1)*(p-h)/g);S<=0?this.colorsI[c]=e.showBelowMin?f.colors[0]:0:S>=m?this.colorsI[c]=e.showAboveMax?f.colors[m-1]:0:this.colorsI[c]=f.colors[S]}this.colorsI[0]=0;for(let c=0;c<i[0];++c)this.levelIndex[c]=0;for(let c=0;c<i.length-1;c++)for(let x=i[c];x<i[c+1]+1;++x)this.levelIndex[x]=c;for(let c=i[i.length-1];c<65536;++c)this.levelIndex[c]=i.length-1}};function ge(n){var t;if(n!==0&&-.1<n&&n<.1)return n.toExponential(2);let e=n.toString();return((t=e.split(".")[1])==null?void 0:t.length)>2?n.toFixed(2):e}function V(n,e){let t={size:n,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(n),ticks:[]},{colorMap:r,levels:o,colors:a}=e,s=e.fill!=="solid";if(r){let h=r[0][0],d=r[r.length-1][0]-h;for(let[g,c]of r){let x=~~((g-h)/d*(n-1)),p={data:g,dataString:ge(g),color:c,pos:x};t.ticks.push(p)}for(let g=0;g<r.length-1;g++){let c=t.ticks[g].pos,x=t.ticks[g+1].pos,p=I(r[g][1]),S=s?I(r[g+1][1]):0;for(let y=c;y<x;++y)t.colors[y]=s?Z(p,S,(y-c)/(x-c)):p}return t.colors[n-1]=I(r[r.length-1][1]),t}if(!a||!o)return t;let i=0,u=0,l=-1;for(let h=0;h<n;++h){let d=h*(a.length-1)/n;l!==~~d&&(l=~~d,i=I(a[l]),u=a.length>l+1?I(a[l+1]):i),t.colors[h]=s?Z(i,u,d-l):i}t.colors[n-1]=I(a[a.length-1]);let m=o[0],f=(n-1)/(o[o.length-1]-m);for(let h of o){let d=~~((h-m)*f),g={data:h,dataString:ge(h),color:w(t.colors[d]),pos:d};t.ticks.push(g)}return t}var G=256,Ge=2*Math.PI*6378137/G,E=2*Math.PI*6378137/2;function Qe(n,e){let t=n/E*180,r=e/E*180;return r=180/Math.PI*(2*Math.atan(Math.exp(r*Math.PI/180))-Math.PI/2),[r,t]}function Ne(n,e,t){let r=Ke(t),o=n*r-E,a=e*r-E;return[o,a]}function Ke(n){return Ge/Math.pow(2,n)}function Q(n,e,t){let[r,o]=Qe(...Ne(n,e,t));return[o,-r]}function xe(n,e){return[n*G,e*G]}var $e="A".charCodeAt(0),N,A=0;async function Xe(n,e){let t;try{t=await(await fetch(n,e)).json()}catch(r){console.log("Can't load QTree:",r);return}N=R(t,{pos:0}),A=pe(N),console.log("Loaded QTree, depth:",A)}function R(n,e){let t=n.charCodeAt(e.pos)-$e;e.pos++;let r=t&1?R(n,e):null,o=t&2?R(n,e):null,a=t&4?R(n,e):null,s=t&8?R(n,e):null;return{sub:r||o||a||s?[r,o,a,s]:null}}function pe(n){let e=0;if(n==null?void 0:n.sub){for(let t=0;t<4;t++)if(n.sub[t]!==null){let r=pe(n.sub[t])+1;e<r&&(e=r)}}return e}var v;(function(r){r.Land="land",r.Mixed="mixed",r.Sea="sea"})(v||(v={}));function ye(n){if(!A)return v.Mixed;let e=ee({},n),t=!1;if(A<=n.z){t=!0;let r=n.z-A;e={x:n.x>>r,y:n.y>>r,z:A}}return Se(N,e,t)}function Se(n,e,t){if(n===null)return v.Land;if(t&&e.z===0)return v.Mixed;if(n.sub===null)return v.Sea;if(e.z===0)return v.Mixed;e.z--;let r=e.x>>e.z&1,a=(e.y>>e.z&1)<<1|r;return Se(n.sub[a],e,t)}function K(n,e,t){let r=((e-n)%360+540)%360-180;return(n+r*t+360)%360}function Je(n,e,t,r,o,a,s,i){switch((n?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 0:return 0;case 1:return n;case 2:return e;case 3:t=n,r=e;break;case 4:return t;case 5:e=n,r=t;break;case 6:r=e+t>>1,n=r;break;case 7:r=e+t>>1;break;case 8:return r;case 9:e=n+r>>1,t=e;break;case 10:n=e,t=r;break;case 11:t=n+r>>1;break;case 12:n=t,e=r;break;case 13:e=n+r>>1;break;case 14:n=e+t>>1;break}n=s+i*n,e=s+i*e,t=s+i*t,r=s+i*r;let l=K(n,e,o),m=K(t,r,o);return(K(l,m,a)-s)/i||1}function Ye(n,e,t,r,o,a,s,i){switch((n?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 7:return o+a<1?o*(e-n)+a*(t-n)+n:0;case 14:return o+a<1?0:o*(r-t)+a*(r-e)+e+t-r;case 11:return a<o?(1-o)*(n-e)+a*(r-e)+e:0;case 13:return a<o?0:(1-o)*(t-r)+a*(t-n)+n+r-t;case 15:return o+a<1?o*(e-n)+a*(t-n)+n:o*(r-t)+a*(r-e)+e+t-r;default:return 0}}function Ce(n,e,t){if(!t)return e;let r=.9999999/Math.pow(2,t.z),o=t.x*256*r,a=t.y*256*r,{raw:s,dmin:i,dmax:u,dmul:l}=e,m={raw:new Uint16Array(258*258),dmin:i,dmax:u,dmul:l},{raw:f}=m;for(let h=-1,d=0;h<=256;h++){let g=a+h*r,c=Math.floor(g),x=g-c;for(let p=-1;p<=256;p++,d++){let S=o+p*r,y=Math.floor(S),C=S-y,T=y+1+(c+1)*258,D=s[T],L=s[T+1],M=s[T+258],De=s[T+258+1];f[d]=n(D,L,M,De,C,x,i,l)}}return m}function et(n,e){return Ce(Ye,n,e)}function tt(n,e){return Ce(Je,n,e)}function rt(n,e,t){let r=t==="land"?1:0;for(let o=3,a=0;a<256;a++)for(let s=0;s<256;s++,o+=4){let i=e.data[o]?1:0;r^i&&(n.raw[(a+1)*258+(s+1)]=0)}return n}function nt(n){let[e,t]=xe(n.x,n.y),[r,o]=Q(e,t,n.z),[a,s]=Q(e+256,t+256,n.z);return{west:r,north:o,east:a,south:s}}function we(n){let e=F("div","leaflet-tile s-tile");return e.wxtile=new Te(n,e),(async()=>{let{wxtile:t}=e;try{await t.load(),t.draw()}catch(r){let{x:o,y:a,z:s}=t.coords;b(`tile(${o},${a},${s}) loading error: ${r}`)}n.done()})(),e}var Te=class{constructor({layer:e,coords:t},r){this.data=[];this.streamLines=[];this.coords=t,this.layer=e,this.canvasFill=F("canvas","s-tile canvas-fill",r),this.canvasSlines=F("canvas","s-tile canvas-slines",r),this.canvasVector=this.canvasFill,this.canvasFill.width=this.canvasFill.height=this.canvasSlines.width=this.canvasSlines.height=256;function o(a){let s=a.getContext("2d");if(!s)throw new Error("getCtx error");return s}this.canvasFillCtx=o(this.canvasFill),this.imageDataForFillCtx=this.canvasFillCtx.createImageData(256,256),this.canvasVectorAnimationCtx=o(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}async load(){let{coords:e,layer:t}=this;await t.setupCompletePromise;let r=this._getTileType();if(!r)return this.data=[],this.streamLines=[],this;let{upCoords:o,subCoords:a}=this._splitCoords(e),s=this.layer.state.baseURL.replace("{z}",String(o.z)).replace("{x}",String(o.x)).replace("{y}",String(o.y)),i=this.layer.dataSource.variables.map(f=>s.replace("{var}",f)),u;try{u=await Promise.all(i.map(t.loadDataIntegralFunc))}catch(f){return f.code!==DOMException.ABORT_ERR&&(this.data=[],this.streamLines=[]),this}let l=t.state.units==="degree"?tt:et,m=f=>l(me(f,t.style.blurRadius),a);return this.data=u.map(m),t.state.vector&&this._vectorMagnitudesPrepare(),await this._applyMask(r,a===void 0),t.state.vector&&this._createStreamLines(),this}async _applyMask(e,t){let{coords:r,layer:o}=this;if((o.style.mask==="land"||o.style.mask==="sea")&&e===v.Mixed){let a=o.dataSource.maskServerURI.replace("{z}",String(r.z)).replace("{x}",String(r.x)).replace("{y}",String(r.y));try{let s=await o.loadMaskFunc(a);if(!o.state.vector&&t){let{raw:i,dmin:u,dmax:l,dmul:m}=this.data[0];this.data[0]={raw:new Uint16Array(i),dmin:u,dmax:l,dmul:m}}rt(this.data[0],s,o.style.mask)}catch(s){o.style.mask=void 0,b("Can't load Mask. Masking is Turned OFF")}}}_splitCoords(e){let t=e.z-this.layer.state.meta.maxZoom;if(t<=0)return{upCoords:e};let r={x:e.x>>>t,y:e.y>>>t,z:this.layer.state.meta.maxZoom},o={x:e.x&(1<<t)-1,y:e.y&(1<<t)-1,z:t};return{upCoords:r,subCoords:o}}_getTileType(){let{coords:e,layer:t}=this,{mask:r}=t.style;var o=v.Mixed;if((r==="land"||r==="sea")&&(o=ye(e),r===o))return;let{boundaries:a}=t.state.meta;if(a==null?void 0:a.boundaries180){let s=nt(e),i=u=>!(s.west>u.east||u.west>s.east||s.south>u.north||u.south>s.north);if(!a.boundaries180.some(i))return}return o}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasVectorAnimationCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVectorsStatic(),this._drawDegreesStatic(),this._drawStreamLinesStatic())}clearVectorAnimationCanvas(){this.canvasVectorAnimationCtx.clearRect(0,0,256,256)}drawVectorAnimationLinesStep(e){if(this.streamLines.length===0)return;let t=this.canvasVectorAnimationCtx;t.clearRect(0,0,256,256);let{clut:r,style:o}=this.layer,[a,s,i]=this.data;if(o.streamLineColor==="none"){this.streamLines=[];return}e=e>>7;for(let u=0;u<this.streamLines.length;++u){let l=this.streamLines[u],m=l.length-1,f=(e+(1+l[0].x)*(1+l[0].y))%30;for(let h=0;h<m;++h){let d=l[h],g=l[h+1],c=1-(f-h)/m;(c<0||c>1)&&(c=0);let x=(~~(c*255)).toString(16).padStart(2,"0"),p=1+~~((1.2-c)*5);t.lineWidth=p;let S=d.x+1+(d.y+1)*258,y;switch(o.streamLineColor){case"inverted":y=w(~r.colorsI[a.raw[S]]);break;case"fill":y=w(r.colorsI[a.raw[S]]);break;default:y=o.streamLineColor;break}t.strokeStyle=y+x,t.beginPath(),t.moveTo(d.x,d.y),t.lineTo(g.x,g.y),t.stroke()}}}getPixelInfo({x:e,y:t}){var o;let r=(t+1)*258+(e+1);if(!!((o=this.data[0])==null?void 0:o.raw[r]))return{raw:this.data.map(a=>a.raw[r]),data:this.data.map(a=>a.raw[r]*a.dmul+a.dmin)}}_vectorMagnitudesPrepare(){if(this.data.length!==2)throw new Error("this.data !== 2");this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[e,t,r]=this.data;e.dmax=1.42*Math.max(-t.dmin,t.dmax,-r.dmin,r.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let o=0;o<258*258;++o){if(!t.raw[o]||!r.raw[o]){e.raw[o]=0;continue}let a=t.dmin+t.dmul*t.raw[o],s=r.dmin+r.dmul*r.raw[o];e.raw[o]=Math.sqrt(s*s+a*a)/e.dmul}}_drawFillAndIsolines(){let{imageDataForFillCtx:e}=this,{canvasFillCtx:t}=this,r=new Uint32Array(e.data.buffer),{raw:o}=this.data[0],{clut:a,style:s}=this.layer,{levelIndex:i,colorsI:u}=a;if(s.fill!=="none")for(let m=0,f=0,h=259;m<256;++m,h+=2)for(let d=0;d<256;++d,++f,++h)r[f]=u[o[h]];else r.fill(0);let l=[];if(s.isolineColor!=="none"){let m=s.isolineColor[0]==="#"?I(s.isolineColor):0;for(let f=0,h=0;f<256;f+=1)for(let d=0;d<256;d+=1){let g=(f+1)*258+(d+1),c=o[g],x=o[g+1],p=o[g+258];if(!c||!x||!p)continue;let S=i[c],y=i[x],C=i[p];if(S!==y||S!==C){let T=Math.max(S,y,C),D=Math.max(c,x,p),L=f*256+d;switch(s.isolineColor){case"inverted":r[L]=~u[D]|4278190080;break;case"fill":r[L]=u[D]|4278190080;break;default:r[L]=m;break}s.isolineText&&!(++h%255)&&d>20&&d<235&&f>20&&f<235&&l.push({x:d,y:f,d:c,dr:x,db:p,mli:T})}}}if(t.putImageData(e,0,0),l.length){t.font="1.1em Sans-serif",t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";for(let{x:m,y:f,d:h,dr:d,db:g,mli:c}of l){let x=this.layer.clut.ticks[c].dataString,p=Math.atan2(h-d,g-h);t.save(),t.translate(m,f),t.rotate(p<-1.57||p>1.57?p+3.14:p),t.strokeText(x,0,0),t.fillText(x,0,0),t.restore()}}}_drawStreamLinesStatic(){if(!this.streamLines.length||!this.layer.style.streamLineStatic)return;let{canvasVectorAnimationCtx:e}=this,{clut:t,style:r}=this.layer;if(r.streamLineColor==="none"){this.streamLines=[];return}let[o]=this.data;e.lineWidth=2;for(let a=this.streamLines.length;a--;){let s=this.streamLines[a];for(let i=0;i<s.length-1;++i){let u=s[i],l=s[i+1],m=u.x+1+(u.y+1)*258;switch(r.streamLineColor){case"inverted":e.strokeStyle=w(~t.colorsI[o.raw[m]]);break;case"fill":e.strokeStyle=w(t.colorsI[o.raw[m]]);break;default:e.strokeStyle=r.streamLineColor;break}e.beginPath(),e.moveTo(u.x,u.y),e.lineTo(l.x,l.y),e.stroke()}}}_drawVectorsStatic(){let{clut:e,style:t}=this.layer;if(!this.layer.state.vector||!e.DataToKnots||t.vectorColor==="none"||t.vectorType==="none")return;if(this.data.length!==3)throw new Error("this.data.length !== 3");let[r,o,a]=this.data,{canvasVectorCtx:s}=this;switch(t.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=t.vectorType}s.textAlign="center",s.textBaseline="middle";let i=t.addDegrees?.017453292519943*t.addDegrees:0,u=32;for(let l=u/2;l<256;l+=u)for(let m=u/2;m<256;m+=u){let f=m+1+(l+1)*258;if(!r.raw[f])continue;let h=Math.atan2(o.dmin+o.raw[f]*o.dmul,a.dmin+a.raw[f]*a.dmul),d=r.dmin+r.raw[f]*r.dmul,g=t.vectorType!=="barbs"?t.vectorFactor*.2:.2,c=Math.min(e.DataToKnots(d)*g,25)+65,x=String.fromCharCode(c);switch(t.vectorColor){case"inverted":s.fillStyle=w(~e.colorsI[r.raw[f]]);break;case"fill":s.fillStyle=w(e.colorsI[r.raw[f]]);break;default:s.fillStyle=t.vectorColor;break}s.save(),s.translate(m,l),s.rotate(h+i),s.fillText(x,0,0),s.restore()}}_drawDegreesStatic(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:e}=this,t=.017453292519943*this.layer.style.addDegrees;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle";let r=this.data[0],o="L",a=32;for(let s=a/2;s<256;s+=a)for(let i=a/2;i<256;i+=a){let u=i+1+(s+1)*258;if(!r.raw[u])continue;let m=(r.dmin+r.raw[u]*r.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=w(~this.layer.clut.colorsI[r.raw[u]]);break;case"fill":e.fillStyle=w(this.layer.clut.colorsI[r.raw[u]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(i,s),e.rotate(m+t),e.fillText(o,0,0),e.restore()}}_createStreamLines(){if(this.data.length!==3)throw new Error("this.data.length !== 3");let{style:e}=this.layer;if(e.streamLineColor==="none")return;this.streamLines=[];let[t,r,o]=this.data,a=(e.streamLineSpeedFactor||1)/t.dmax,s=e.addDegrees?.017453292519943*e.addDegrees:0,i=e.streamLineGridStep||64,u=e.streamLineSteps||300;for(let l=0;l<=256;l+=i)for(let m=0;m<=256;m+=i){if(!t.raw[1+m+(1+l)*258])continue;let f=[],h=m,d=l,g=-1,c=0,x=0;for(let y=0;y<=u&&h>=0&&h<=256&&d>=0&&d<=256;y++){y%(u/10)||f.push({x:~~h,y:~~d});let C=~~h+1+(~~d+1)*258;if(C!==g){if(!t.raw[C])break;g=C;let T=t.dmin+t.raw[C]*t.dmul,D=r.dmin+r.raw[C]*r.dmul,L=o.dmin+o.raw[C]*o.dmul,M=Math.atan2(D,L)+s;c=a*T*Math.sin(M),x=a*T*Math.cos(M)}h+=c,d-=x}let p=m,S=l;g=-1;for(let y=1;y<=u&&p>=0&&p<=256&&S>=0&&S<=256;y++){y%(u/10)||f.unshift({x:~~p,y:~~S});let C=~~p+1+(~~S+1)*258;if(C!==g){if(!t.raw[C])break;g=C;let T=t.dmin+t.raw[C]*t.dmul,D=r.dmin+r.raw[C]*r.dmul,L=o.dmin+o.raw[C]*o.dmul,M=Math.atan2(D,L)+s;c=a*T*Math.sin(M),x=a*T*Math.cos(M)}p-=c,S+=x}f.length>2&&this.streamLines.push(f)}}};var $;var q=class extends ve.default.GridLayer{constructor(e){super(e.options);this.styles=H();this.redrawRequestID=0;this.vectorAnimationRequestID=0;this.oldMaxZoom=0;this.style=Object.assign({},this.styles.base);this.clut=new W(this.style,"",[0,2],!1);this.animation=!0;let{dataSource:t,lazy:r}=e;if(b("Creating a WxTiles layer:",t.name,". Params:",JSON.stringify(e)),!(t==null?void 0:t.ext)||!t.dataset||!t.name||!t.serverURI||!t.styleName||!Array.isArray(t.variables)||t.variables.length<1||t.variables.length>2){let i="WxTilesLayer: dataSource is wrong!";throw b(i),new Error(i)}this.dataSource=t,this.state={originURI:t.serverURI+"/"+t.dataset+"/",units:"",baseURL:"",meta:{maxZoom:0,times:[],variables:[],variablesMeta:{}},instance:"",minmax:[[0,1]],currentTime:"",vector:t.variables.length>1},this.loadDataIntegralFunc=z(t.requestInit),$||($=ue(t.requestInit)),this.loadMaskFunc=$;let o=()=>{var i;((i=this._map)==null?void 0:i.getZoom())<this.state.meta.maxZoom&&this._stopLoadingResetLoadDataFunc()},a=()=>{if(b("onadd:",this.dataSource.name),!this._map)throw new Error("_map is not set!");this._map.on("zoomstart",o),this._checkAndStartVectorAnimation()},s=()=>{if(b("onremove:",this.dataSource.name),!this._map)throw new Error("_map is not set!");this._map.off("zoomstart",o),this._stopLoadingResetLoadDataFunc()};this.on("remove",s),this.on("add",a),this.setupCompletePromise=new Promise(i=>{let u=async()=>{b("Setup:",t.name),await this._setUpDataSet(),b("Setup complete: ",this.dataSource.name),i()};r?this.once("add",u):u()})}async _setUpDataSet(){let{state:e,dataSource:t}=this;try{e.instance=(await k(e.originURI+"instances.json")).pop()+"/"}catch(o){let a=t.name+": load instances.json error: "+o;throw b(a),new Error(a)}try{let o=e.originURI+e.instance+"meta.json";e.meta=await k(o)}catch(o){let a=t.name+": load meta.json error: "+o;throw b(a),new Error(a)}e.vector=t.variables.length===2;let{variablesMeta:r}=e.meta;if(e.units=r[t.variables[0]].units,e.minmax=t.variables.map(o=>[r[o].min,r[o].max]),e.vector){let[[o,a],[s,i]]=e.minmax;e.minmax.unshift([0,1.42*Math.max(-o,a,-s,i)])}this._setStyleAndCLUT(t.styleName),this._setTimeUrl(new Date)}async _requestReloadTilesAndRedraw(){let e=await this._requestReloadTiles();return e&&this._redrawTiles(),e}async _requestReloadTiles(){b(`_requestReloadTiles: start - ${this.dataSource.name}`);let{controller:e}=this.loadDataIntegralFunc.controllerHolder;return await Promise.allSettled(this._ForEachWxTile(t=>t.load())),b(`_requestReloadTiles: end - ${this.dataSource.name}, aborted: ${e.signal.aborted}`),!e.signal.aborted}async setStyle(e){b("setStyle(",e,") for ",this.dataSource.name),(e==="custom"||e!==this.dataSource.styleName)&&(this._setStyleAndCLUT(e),this._checkAndStartVectorAnimation(),await this._requestReloadTilesAndRedraw()),b("setStyle(",e,'): "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete.")}_setStyleAndCLUT(e){let{dataSource:t,styles:r,state:o}=this;t.styleName=e,e==="custom"&&(r.custom.parent&&r.custom.parent in r||(b(`cant find the parent style (${r.custom.parent}), 'base' is used`),r.custom.parent="base"),r.custom=Object.assign(Object.assign({},r[r.custom.parent]),r.custom)),e in r||(b(`cant find the style (${e}), 'base' is used`),e=t.styleName="base");try{this.style=Object.assign({},r[e]),this.style.streamLineColor=be(this.style.streamLineColor),this.clut=new W(this.style,o.units,o.minmax[0],o.vector)}catch(a){let s="setStyle: impossible error in RawCLUT: "+a;throw b(s),new Error(s)}}createTile(e,t){return we({layer:this,coords:e,done:t})}getSetupCompletePromise(){return this.setupCompletePromise}async checkDataChanged(){b("checkDataChanged");try{let e=await k(this.state.originURI+"instances.json"),t=e[e.length-1]+"/";if(this.state.instance!==t)return!0;let r=await k(this.state.originURI+t+"meta.json");return this.state.meta.times.toString()!==r.times.toString()}catch(e){return!1}}getLayerInfoAtLatLon(e){if(!this._map)return;let t=this._map.getZoom(),r=this._map.project(e,t),o=r.divideBy(256).floor(),a=this._getCachedTile(o,t);if(!a)return;let s=r.subtract(o.multiplyBy(256)).floor(),i=a.getPixelInfo(s);if(!i)return;let{raw:u,data:l}=i,m=u.map(d=>this.clut.colorsI[d]),f=m.map(w),h=l.map(d=>this.clut.DataToStyle(d));return{wxtile:a,data:l,raw:u,rgba:m,hexColor:f,inStyleUnits:h,tilePoint:s,styleUnits:this.style.units,dataUnits:this.state.units}}getStyle(){return this.style}_getFirstNonEmptyTile(){for(let e in this._tiles){let{wxtile:t}=this._tiles[e].el;if(t==null?void 0:t.data.length)return t}}_setTimeUrl(e){let{dataSource:t,state:r}=this,o=de(r.meta.times,e);return r.currentTime===o?(b("_setTimeUrl: the same time - skipped"),!1):(r.currentTime=o,r.baseURL=r.originURI+r.instance+`{var}/${r.currentTime}/{z}/{x}/{y}.${t.ext}`,b(`_setTimeUrl: ${o} for ${t.name} complete`),!0)}setTime(e){if(b("setTime: "+e+" for "+this.dataSource.name+" start"),!this._tiles)return b("setTime: no tiles - skipped"),Promise.resolve(!1);let{currentTime:t}=this.state;if(!this._setTimeUrl(e))return Promise.resolve(!1);this.loadDataIntegralFunc.abort();let r=this._requestReloadTiles();return r.then(o=>{if(!o){this.state.currentTime=t;return}let a=this._getFirstNonEmptyTile();if(a==null?void 0:a.data.length){let[s,i]=this.state.minmax[0],{dmin:u,dmax:l}=a.data[0];(Math.abs(u-s)>.01||Math.abs(l-i)>.01)&&(this.state.minmax=a.data.map(m=>[m.dmin,m.dmax]),this._setStyleAndCLUT(this.dataSource.styleName))}this._redrawTiles()}),r}getTime(){return this.state.currentTime}getTimes(){return b("getTimes"),this.state.meta.times}getLegendData(e){return b("getLegendData"),V(e,this.style)}setTimeAnimationMode(e=2){b("setTimeAnimationMode"),this.oldMaxZoom=this.state.meta.maxZoom;let t=this._map.getZoom(),o=(t<this.oldMaxZoom?t:this.oldMaxZoom)-e;this.state.meta.maxZoom=o<0?0:o}async unsetTimeAnimationMode(){return b("unsetTimeAnimationMode"),this.oldMaxZoom&&(this.state.meta.maxZoom=this.oldMaxZoom),this._requestReloadTilesAndRedraw()}getMinMax(){let[e,t]=this.state.minmax[0];return{min:e,max:t}}setAnimation(e){return b("setAnimation"),this.animation=e,this._checkAndStartVectorAnimation(),this.animation}_getCachedTile({x:e,y:t},r){var o,a;return(a=(o=this._tiles[`${e}:${t}:${r}`])==null?void 0:o.el)==null?void 0:a.wxtile}_ForEachWxTile(e){var r;let t=[];for(let o in this._tiles){let a=(r=this._tiles[o].el)==null?void 0:r.wxtile;a&&t.push(e(a))}return t}_stopLoadingResetLoadDataFunc(){this.loadDataIntegralFunc.abort(),this.loadDataIntegralFunc=z()}_checkAndStartVectorAnimation(){if(this.vectorAnimationRequestID)return;let e=t=>{if(!this._map||!this.animation||!this.state.vector||this.style.streamLineStatic||this.style.streamLineColor==="none"){this._ForEachWxTile(r=>r.clearVectorAnimationCanvas()),this.vectorAnimationRequestID=0;return}this._ForEachWxTile(r=>r.drawVectorAnimationLinesStep(t)),this.vectorAnimationRequestID=requestAnimationFrame(e)};this.vectorAnimationRequestID=requestAnimationFrame(e)}_redrawTiles(){this.redrawRequestID||(b("_redrawTiles: start: "+this.dataSource.name),this.redrawRequestID=requestAnimationFrame(()=>{this._ForEachWxTile(e=>e.draw()),this.redrawRequestID=0,b("_redrawTiles: requestAnimationFrame: end: "+this.dataSource.name)}))}};function ot(n){return new q(n)}var Le=class extends B.default.Control{constructor(e){super(e);this.URI=e.URI}onAdd(){let e=document.createElement("img");return e.src=this.URI,e.className="wxtiles-logo",e}};function Ot(n){return b("Add watermark:",JSON.stringify(n)),new Le(n)}var Ie=class extends B.default.GridLayer{createTile(e){let t=document.createElement("div");return t.innerHTML=[e.x,e.y,e.z].join(", "),t.style.outline="1px solid red",t}};function Ht(){return b("Add WxDebugCoordsLayer:"),new Ie().setZIndex(1e3)}function jt(n,e){return B.default.layerGroup(n.map(ot),e)}export{Ht as CreateWxDebugCoordsLayer,jt as CreateWxTilesGroupLayer,ot as CreateWxTilesLayer,Ot as CreateWxTilesWatermark,Xe as LoadQTree,Ie as WxDebugLayer,j as WxGetColorSchemes,H as WxGetColorStyles,q as WxTilesLayer,We as WxTilesLibSetup,Ze as WxTilesLogging,Le as WxWatermark,k as fetchJson};