@metoceanapi/wxtiles-leaflet 1.0.12 → 1.0.15
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 +22 -0
- package/dist/es/defaults/colorschemes.d.ts +1 -1
- package/dist/es/defaults/styles.d.ts +1 -1
- package/dist/es/defaults/uconv.d.ts +1 -1
- package/dist/es/tile.d.ts +26 -28
- package/dist/es/tilesLayer.d.ts +59 -53
- package/dist/es/{RawCLUT.d.ts → utils/RawCLUT.d.ts} +0 -0
- package/dist/es/{mercator.d.ts → utils/mercator.d.ts} +0 -0
- package/dist/es/{qtree.d.ts → utils/qtree.d.ts} +5 -1
- package/dist/es/{wxtools.d.ts → utils/wxtools.d.ts} +15 -7
- package/dist/es/wxtiles.d.ts +4 -4
- package/dist/es/wxtiles.js +1 -1
- package/dist/web/wxtiles.js +1 -1
- package/package.json +1 -1
- package/src_example/index.ts +54 -43
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,28 @@ Write your changes below this section. `npm version [major|minor|patch]` will au
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
## [1.0.15] - 2022-04-12
|
|
13
|
+
|
|
14
|
+
### add
|
|
15
|
+
|
|
16
|
+
- style.vectorFactor
|
|
17
|
+
|
|
18
|
+
### FIX
|
|
19
|
+
- remastered async functions
|
|
20
|
+
- masking spoiled original (cached) data
|
|
21
|
+
|
|
22
|
+
## [1.0.14] - 2021-12-15
|
|
23
|
+
|
|
24
|
+
### FIX
|
|
25
|
+
|
|
26
|
+
- text on isolines
|
|
27
|
+
|
|
28
|
+
## [1.0.13] - 2021-12-15
|
|
29
|
+
|
|
30
|
+
### ADD
|
|
31
|
+
|
|
32
|
+
- export WxGetColorSchemes
|
|
33
|
+
|
|
12
34
|
## [1.0.12] - 2021-12-01
|
|
13
35
|
|
|
14
36
|
### REVERT
|
|
@@ -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
|
|
10
|
+
wxtile: WxTile;
|
|
10
11
|
}
|
|
11
12
|
export interface TileCreateParams {
|
|
12
13
|
layer: WxTilesLayer;
|
|
13
14
|
coords: Coords;
|
|
14
|
-
done:
|
|
15
|
+
done: L.DoneCallback;
|
|
15
16
|
}
|
|
16
|
-
export declare function
|
|
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
|
|
31
|
+
protected canvasVectorAnimationCtx: CanvasRenderingContext2D;
|
|
31
32
|
protected canvasVectorCtx: CanvasRenderingContext2D;
|
|
32
|
-
protected
|
|
33
|
-
protected
|
|
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
|
|
55
|
-
|
|
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
|
|
58
|
-
protected
|
|
59
|
-
protected
|
|
60
|
-
protected
|
|
55
|
+
protected _drawStreamLinesStatic(): void;
|
|
56
|
+
protected _drawVectorsStatic(): void;
|
|
57
|
+
protected _drawDegreesStatic(): void;
|
|
58
|
+
protected _createStreamLines(): void;
|
|
61
59
|
}
|
|
62
60
|
export {};
|
package/dist/es/tilesLayer.d.ts
CHANGED
|
@@ -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,
|
|
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,74 @@ export interface Meta {
|
|
|
29
44
|
}
|
|
30
45
|
export interface DataSource {
|
|
31
46
|
serverURI: string;
|
|
32
|
-
maskServerURI
|
|
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
|
-
|
|
41
|
-
|
|
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
|
-
|
|
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
|
-
|
|
80
|
-
protected
|
|
81
|
-
protected
|
|
82
|
-
|
|
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<
|
|
92
|
+
getSetupCompletePromise(): Promise<void>;
|
|
87
93
|
/** get all the information about tile and point it represents */
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
/** time
|
|
95
|
-
|
|
94
|
+
getLayerInfoAtLatLon(latlng: L.LatLngExpression): WxTileInfo | undefined;
|
|
95
|
+
/** Layer's current style.*/
|
|
96
|
+
getStyle(): ColorStyleStrict;
|
|
97
|
+
/** get first non-empty wxtile */
|
|
98
|
+
protected _getFirstNonEmptyTile(): WxTile | undefined;
|
|
99
|
+
protected _setTimeUrl(time: Date | string | number): boolean;
|
|
100
|
+
/** set time to the closest time in the list of times
|
|
101
|
+
* params:
|
|
102
|
+
* time - Date, String or number (unix time ms since 00:00:00 UTC on 1 January 1970)
|
|
103
|
+
* return:
|
|
104
|
+
* Promise resolved as true - if time was changed and tiles were redrawn
|
|
105
|
+
* NOTE:
|
|
106
|
+
* User should await for setTime promise to be fulfilled, otherwise the data might be loaded but not
|
|
107
|
+
* displayed. Some visual issues can come from vector animation.
|
|
108
|
+
* */
|
|
109
|
+
setTime(time: Date | string | number): Promise<boolean>;
|
|
96
110
|
/** string - current time as it is in meta */
|
|
97
111
|
getTime(): string;
|
|
98
112
|
/** Array of strings (times) */
|
|
99
113
|
getTimes(): string[];
|
|
100
|
-
/**
|
|
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
|
|
114
|
+
/** getLegendData - data to render a proper legend
|
|
106
115
|
* pixSize - width of a canvas to render this legend
|
|
107
116
|
* output:
|
|
108
117
|
* legend - object
|
|
@@ -117,7 +126,7 @@ export declare class WxTilesLayer extends L.GridLayer {
|
|
|
117
126
|
/** set coarse maximum zoom level to make tiles load faster during animation */
|
|
118
127
|
setTimeAnimationMode(l?: number): void;
|
|
119
128
|
/** restore maximum zoom level */
|
|
120
|
-
unsetTimeAnimationMode(): Promise<
|
|
129
|
+
unsetTimeAnimationMode(): Promise<boolean>;
|
|
121
130
|
/** min, max values of the loaded data */
|
|
122
131
|
getMinMax(): {
|
|
123
132
|
min: number;
|
|
@@ -125,15 +134,12 @@ export declare class WxTilesLayer extends L.GridLayer {
|
|
|
125
134
|
};
|
|
126
135
|
/** true/false - if vector data and true, animation starts */
|
|
127
136
|
setAnimation(a: boolean): boolean;
|
|
128
|
-
protected _getCachedTile(x
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
protected
|
|
133
|
-
protected _onRemoveLayer(): void;
|
|
137
|
+
protected _getCachedTile({ x, y }: {
|
|
138
|
+
x: number;
|
|
139
|
+
y: number;
|
|
140
|
+
}, zoom: number): WxTile | undefined;
|
|
141
|
+
protected _ForEachWxTile<T>(func: (wxtile: WxTile) => T): T[];
|
|
134
142
|
protected _stopLoadingResetLoadDataFunc(): void;
|
|
135
|
-
protected
|
|
136
|
-
protected _stopSlinesAnimation(): void;
|
|
143
|
+
protected _checkAndStartVectorAnimation(): void;
|
|
137
144
|
protected _redrawTiles(): void;
|
|
138
|
-
protected _reloadTiles(redraw?: boolean): Promise<WxTile[]>;
|
|
139
145
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -14,6 +14,7 @@ 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;
|
|
19
20
|
streamLineStatic?: boolean;
|
|
@@ -43,6 +44,7 @@ export interface ColorStyleStrict {
|
|
|
43
44
|
isolineText: boolean;
|
|
44
45
|
vectorType: string;
|
|
45
46
|
vectorColor: string;
|
|
47
|
+
vectorFactor: number;
|
|
46
48
|
streamLineColor: string;
|
|
47
49
|
streamLineSpeedFactor: number;
|
|
48
50
|
streamLineStatic: boolean;
|
|
@@ -68,13 +70,13 @@ export interface LibSetupObject {
|
|
|
68
70
|
}
|
|
69
71
|
export declare function WxTilesLibSetup({ colorStyles, units, colorSchemes }?: LibSetupObject): void;
|
|
70
72
|
export declare function WxGetColorStyles(): ColorStylesStrict;
|
|
71
|
-
export declare function
|
|
73
|
+
export declare function WxGetColorSchemes(): ColorSchemes;
|
|
72
74
|
export interface Converter {
|
|
73
75
|
(x: number): number;
|
|
74
76
|
trivial?: boolean;
|
|
75
77
|
}
|
|
76
78
|
export declare function makeConverter(from: string, to: string, customUnits?: Units): Converter;
|
|
77
|
-
declare type
|
|
79
|
+
declare type CacheableURILoaderPromiseFunc<T> = (url: string) => Promise<T>;
|
|
78
80
|
interface IntegralPare {
|
|
79
81
|
integral: Uint32Array;
|
|
80
82
|
integralNZ: Uint32Array;
|
|
@@ -89,24 +91,30 @@ export interface DataIntegral extends DataPicture {
|
|
|
89
91
|
integral: IntegralPare;
|
|
90
92
|
radius: number;
|
|
91
93
|
}
|
|
94
|
+
export declare function loadImageData(url: string, requestInit?: RequestInit): Promise<ImageData>;
|
|
92
95
|
interface AbortControllerHolder {
|
|
93
96
|
controller: AbortController;
|
|
97
|
+
debug: string;
|
|
94
98
|
}
|
|
95
|
-
export
|
|
96
|
-
export interface AbortableCacheableFunc<T> extends CacheableFunc<T> {
|
|
99
|
+
export interface AbortableCacheableURILoaderPromiseFunc<T> extends CacheableURILoaderPromiseFunc<T> {
|
|
97
100
|
controllerHolder: AbortControllerHolder;
|
|
101
|
+
abort: () => void;
|
|
98
102
|
}
|
|
99
|
-
export declare function
|
|
100
|
-
export declare function
|
|
103
|
+
export declare function loadingFunctionCachedAbortable<T>(F: (url: string, requestInit?: RequestInit) => Promise<T>, requestInit?: RequestInit): AbortableCacheableURILoaderPromiseFunc<T>;
|
|
104
|
+
export declare function loadDataIntegralCachedAbortable(requestInit?: RequestInit): AbortableCacheableURILoaderPromiseFunc<DataIntegral>;
|
|
105
|
+
export declare function loadImageDataCachedAbortable(requestInit?: RequestInit): AbortableCacheableURILoaderPromiseFunc<ImageData>;
|
|
106
|
+
export declare function loadDataIntegralCachedAbortable_old(requestInit?: RequestInit): AbortableCacheableURILoaderPromiseFunc<DataIntegral>;
|
|
107
|
+
export declare function loadImageDataCachedAbortable_old(requestInit?: RequestInit): AbortableCacheableURILoaderPromiseFunc<ImageData>;
|
|
101
108
|
export declare function blurData(im: DataIntegral, radius: number): DataIntegral;
|
|
102
109
|
export declare function RGBtoHEX(rgb: number): string;
|
|
103
110
|
export declare function RGBAtoHEX(rgba: number): string;
|
|
104
111
|
export declare function HEXtoRGBA(c: string): number;
|
|
105
|
-
export declare function fetchJson(url: RequestInfo,
|
|
112
|
+
export declare function fetchJson(url: RequestInfo, requestInit?: RequestInit): Promise<any>;
|
|
106
113
|
export declare function createEl(tagName: string, className?: string, container?: HTMLElement): HTMLElement;
|
|
107
114
|
export declare function mixColor(c1: number, c2: number, t: number): number;
|
|
108
115
|
export declare function createLevels(min: number, max: number, n: number): number[];
|
|
109
116
|
export declare function getClosestTimeString(times: string[], time: Date | string | number): string;
|
|
110
117
|
export declare function WxTilesLogging(on: boolean): void;
|
|
111
118
|
export declare function WXLOG(...str: any): void;
|
|
119
|
+
export declare function refineColor(c: string): string;
|
|
112
120
|
export {};
|
package/dist/es/wxtiles.d.ts
CHANGED
|
@@ -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 } 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;
|
package/dist/es/wxtiles.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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 N=Ie((rt,ee)=>{ee.exports=window.L});var E=Y(N());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 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,ne,se;function Pe({colorStyles:r={},units:e={},colorSchemes:t={}}={}){x("WxTile lib setup: start"),B=Object.assign({},te,e),ne=Object.assign({},t,re);let n=Object.assign({},r,P);se=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 se}function oe(){return ne}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 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 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 z(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=Y(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=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=O(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 O(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?z(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?z(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 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 Oe="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)-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=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,o=(e.y>>e.z&1)<<1|n;return xe(r.sub[o],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,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=K(g,y,m),M=K(S,C,m);i[u]=(K(I,M,c)-r.dmin)/r.dmul,i[u]===0&&(i[u]=1)}}return o}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,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]=G(e,t,r.z),[o,i]=G(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"?Ge: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=j();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),O(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=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(()=>{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,Qe as LoadQTree,Te as WxDebugLayer,Z as WxGetColorStyles,F as WxTilesLayer,Pe as WxTilesLibSetup,He as WxTilesLogging,we as WxWatermark};
|
|
1
|
+
var Ae=Object.create;var R=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols,ke=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable;var Y=(n,e,t)=>e in n?R(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,ee=(n,e)=>{for(var t in e||(e={}))J.call(e,t)&&Y(n,t,e[t]);if(X)for(var t of X(e))_e.call(e,t)&&Y(n,t,e[t]);return n};var Pe=n=>R(n,"__esModule",{value:!0});var at=typeof require!="undefined"?require:n=>{throw new Error('Dynamic require of "'+n+'" is not supported')};var Fe=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var Ue=(n,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Re(e))!J.call(n,r)&&r!=="default"&&R(n,r,{get:()=>e[r],enumerable:!(t=Me(e,r))||t.enumerable});return n},te=n=>Ue(Pe(R(n!=null?Ae(ke(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var B=Fe((ct,re)=>{re.exports=window.L});var q=te(B());var ne={comment1:["'degC': ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["'hPa': ['Pa', 1000]' -> hPa = Pa * 1000 + 0 (0 - could be ommited)",0],K:["K",1],kelvin:["K",1],F:["K",.5555555555,255.372222222],C:["K",1,273.15],degC:["K",1,273.15],"kg/m^2/s":["kg/m^2/s",1],"Kg/m^2/s":["kg/m^2/s",1],"Kg m**-2 s**-1":["kg/m^2/s",1],"Kg m^-2 s^-1":["kg/m^2/s",1],"Kg m^{-2} s^-1":["kg/m^2/s",1],"mm/h":["kg/m^2/s",.00027777777],"mm/hr":["kg/m^2/s",.00027777777],"W/m^2":["W/m^2",1],"W m^-2":["W/m^2",1],"W m^{-2}":["W/m^2",1],"W/m**2":["W/m^2",1],"W m**-2":["W/m^2",1],"m/s":["m/s",1],"m s**-1":["m/s",1],"m s^-1":["m/s",1],"m.s^{-1}":["m/s",1],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["m/s",.27777777777],"km h^-1":["m/s",.27777777777],"km h**-1":["m/s",.27777777777],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],inch:["m",.0254],Pa:["Pa",1],hPa:["Pa",100],degree:["degree",1],radian:["degree",57.3],"mg/m^3":["mg/m^3",1],"mg m^-3":["mg/m^3",1],"mg.m^-3":["mg/m^3",1],"%":["%",1],"(0 - 1)":["%",100]};var oe={none:["#00000000","#00000000"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbowzerro:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow2:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebirdzerro:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bw:["#000000ff","#ffffffff"],wb:["#ffffffff","#000000ff"],redish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]};var k={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",vectorFactor:1,streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",vectorFactor:1,streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"}};var O,ae,se;function We({colorStyles:n={},units:e={},colorSchemes:t={}}={}){b("WxTile lib setup: start"),O=Object.assign({},ne,e),ae=Object.assign({},t,oe);let r=Object.assign({},n,k);se=Ee(r),b("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),b("WxTile lib setup is done.")}function H(){return se}function z(){return ae}function _(n,e,t){let r=t?Object.assign({},O,t):O;if(!r||!n||!e||n===e||!r[n]||!r[e]||r[n][0]!==r[e][0]){b(n===e?"Trivial converter:":"Inconvertible units. Default converter is used:",n," -> ",e);let s=i=>i;return s.trivial=!0,s}b("Converter: From:",n," To:",e);let o=r[n][1]/r[e][1],a=(r[n][2]||0)/r[e][1]-(r[e][2]||0)/r[e][1];return a?s=>o*s+a:s=>o*s}function Ee(n){let e=Object.assign({},k);for(let o in n){let a=n[o];if(Array.isArray(a))for(let s=0;s<a.length;++s)e[o+"["+s+"]"]=Object.assign({},a[s]);else e[o]=Object.assign({},a)}let t=(o,a)=>{if(a==="base")return k.base;let s=o[a];(!s.parent||!(s.parent in o))&&(s.parent="base");let i=t(o,s.parent);return Object.assign(s,Object.assign({},i,s,{parent:"base"}))},r={};for(let o in e)r[o]=t(e,o);return r}function qe(n){let e=new Map;return t=>{let r=e.get(t);if(r)return r;let o=n(t);return e.set(t,o),o.catch(a=>{a.code===DOMException.ABORT_ERR&&e.delete(t)}),o}}async function Be(n,e){let t=new Image;return t.src=URL.createObjectURL(await(await fetch(n,e)).blob()),await t.decode(),URL.revokeObjectURL(t.src),t}function Oe(n){let{width:e,height:t}=n,r=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d");if(!r)throw new Error("Error: can not create context. Catastrophe");return r.drawImage(n,0,0),r.getImageData(0,0,e,t)}async function ie(n,e){return Oe(await Be(n,e))}function He(n){n.data[34]<1&&b("Warning: image is in too old format. Check the version of the Splitter.");let e=new Uint16Array(n.data.buffer),t=new Uint16Array(e.length/2);for(let u=0;u<t.length;u++)t[u]=e[u*2];let r=new Uint8Array(8);for(let u=0;u<8;++u)r[u]=n.data[u*4+2];let o=new DataView(r.buffer),a=o.getFloat32(0,!0),s=o.getFloat32(4,!0),i=(s-a)/65535,c=Ze(t);return{raw:t,dmin:a,dmax:s,dmul:i,integral:c,radius:0}}async function ze(n,e){return He(await ie(n,e))}function le(n,e){let t={controller:new AbortController,debug:Date.now().toString()},r=Object.assign({},e,{signal:t.controller.signal}),o=qe(a=>n(a,r));return o.controllerHolder=t,o.abort=()=>{t.controller.abort(),t.controller=new AbortController,t.debug=Date.now().toString(),r.signal=t.controller.signal},o}function Z(n){return le(ze,n)}function ce(n){return le(ie,n)}function Ze(n){let e=new Uint32Array(258*258),t=new Uint32Array(258*258);e[0]=n[0],t[0]=n[0]===0?0:1;for(let r=1;r<258;++r)e[r]=n[r]+e[r-1],e[258*r]=n[258*r]+e[258*r-258],t[r]=(n[r]===0?0:1)+t[r-1],t[258*r]=(n[258*r]===0?0:1)+t[258*r-258];for(let r=1,o=259;r<258;++r,++o)for(let a=1;a<258;++a,++o)e[o]=n[o]+e[o-258]+e[o-1]-e[o-258-1],t[o]=(n[o]===0?0:1)+t[o-258]+t[o-1]-t[o-258-1];return{integral:e,integralNZ:t}}function ue(n,e){if(e<0||e===n.radius)return n;n.radius=e;let t=258,{integral:r,integralNZ:o}=n.integral;for(let a=1;a<t;a++)for(let s=1;s<t;s++){if(!n.raw[t*a+s])continue;let i=Math.min(e,s-1,t-1-s),c=Math.min(e,a-1,t-1-a),u=t*(a-c-1)+s,f=t*(a+c)+s,l=o[u-i-1],d=o[u+i],h=o[f-i-1],g=o[f+i],m=l+g-d-h,x=r[u-i-1],p=r[u+i],y=r[f-i-1],C=r[f+i],v=x+C-p-y;n.raw[a*t+s]=v/m}return n}function w(n){let e=n>>0&255,t=n>>8&255,r=n>>16&255,o=e.toString(16),a=t.toString(16),s=r.toString(16);return o=o.length===2?o:"0"+o,a=a.length===2?a:"0"+a,s=s.length===2?s:"0"+s,"#"+o+a+s}function T(n){if(n[0]==="#"){if(n.length===4)return+("0xff"+n[3]+n[3]+n[2]+n[2]+n[1]+n[1]);if(n.length===7)return+("0xff"+n[5]+n[6]+n[3]+n[4]+n[1]+n[2]);if(n.length===9)return+("0x"+n[7]+n[8]+n[5]+n[6]+n[3]+n[4]+n[1]+n[2])}return b("wrong color format",n),0}async function P(n,e){return(await fetch(n,e)).json()}function F(n,e="",t){var o;let r=document.createElement(n);return r.className=e,t&&((o=t.appendChild)==null||o.call(t,r)),r}function j(n,e,t){let r=n>>0&255,o=n>>8&255,a=n>>16&255,s=n>>>24,i=e>>0&255,c=e>>8&255,u=e>>16&255,f=e>>>24,l=r+t*(i-r),d=o+t*(c-o),h=a+t*(u-a),g=s+t*(f-s);return l|d<<8|h<<16|g<<24}function me(n,e,t){let r=[];for(let o=0;o<t;++o)r.push(o*(e-n)/(t-1)+n);return r}function fe(n,e){let t=typeof e=="number"?e:typeof e=="string"?new Date(e).getTime():e.getTime();return n.find(r=>new Date(r).getTime()>=t)||n[n.length-1]}var de=!1;function je(n){console.log(n?"Logging on":"Logging off"),de=n}function b(...n){de&&console.trace(...n)}function he(n){return n!=="none"&&n.length<7?"#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]:n}var Te=te(B());function Ve(n,e,t){return n>t?t:n<e?e:n}var U=class{constructor(e,t,[r,o],a){let s=o-r;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let i=[];this.DataToStyle=_(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),a&&(this.DataToKnots=_(t,"knot"));let c=_(e.units,t,e.extraUnits),u=m=>~~(65535*Ve((c(m)-r)/(o-r),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((m,x)=>m[0]<x[0]?-1:m[0]>x[0]?1:0);for(let[m]of e.colorMap)i.push(u(m))}else{if(e.levels||(e.levels=me(this.DataToStyle(r),this.DataToStyle(o),10)),e.levels.sort((m,x)=>m<x?-1:m>x?1:0),!e.colors){let m=z();e.colorScheme&&e.colorScheme in m?e.colors=m[e.colorScheme]:e.colors=m.wb}for(let m of e.levels)i.push(u(m))}let f=65536,l=V(f,e);this.ticks=l.ticks;let d=l.ticks[0].data,g=l.ticks[l.ticks.length-1].data-d;for(let m=0;m<65536;++m){let x=s*m/65535+r,p=this.DataToStyle(x),y=Math.round((f-1)*(p-d)/g);y<=0?this.colorsI[m]=e.showBelowMin?l.colors[0]:0:y>=f?this.colorsI[m]=e.showAboveMax?l.colors[f-1]:0:this.colorsI[m]=l.colors[y]}this.colorsI[0]=0;for(let m=0;m<i[0];++m)this.levelIndex[m]=0;for(let m=0;m<i.length-1;m++)for(let x=i[m];x<i[m+1]+1;++x)this.levelIndex[x]=m;for(let m=i[i.length-1];m<65536;++m)this.levelIndex[m]=i.length-1}};function be(n){var t;if(n!==0&&-.1<n&&n<.1)return n.toExponential(2);let e=n.toString();return((t=e.split(".")[1])==null?void 0:t.length)>2?n.toFixed(2):e}function V(n,e){let t={size:n,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(n),ticks:[]},{colorMap:r,levels:o,colors:a}=e,s=e.fill!=="solid";if(r){let d=r[0][0],h=r[r.length-1][0]-d;for(let[g,m]of r){let x=~~((g-d)/h*(n-1)),p={data:g,dataString:be(g),color:m,pos:x};t.ticks.push(p)}for(let g=0;g<r.length-1;g++){let m=t.ticks[g].pos,x=t.ticks[g+1].pos,p=T(r[g][1]),y=s?T(r[g+1][1]):0;for(let C=m;C<x;++C)t.colors[C]=s?j(p,y,(C-m)/(x-m)):p}return t.colors[n-1]=T(r[r.length-1][1]),t}if(!a||!o)return t;let i=0,c=0,u=-1;for(let d=0;d<n;++d){let h=d*(a.length-1)/n;u!==~~h&&(u=~~h,i=T(a[u]),c=a.length>u+1?T(a[u+1]):i),t.colors[d]=s?j(i,c,h-u):i}t.colors[n-1]=T(a[a.length-1]);let f=o[0],l=(n-1)/(o[o.length-1]-f);for(let d of o){let h=~~((d-f)*l),g={data:d,dataString:be(d),color:w(t.colors[h]),pos:h};t.ticks.push(g)}return t}var G=256,Ge=2*Math.PI*6378137/G,W=2*Math.PI*6378137/2;function Qe(n,e){let t=n/W*180,r=e/W*180;return r=180/Math.PI*(2*Math.atan(Math.exp(r*Math.PI/180))-Math.PI/2),[r,t]}function Ne(n,e,t){let r=Ke(t),o=n*r-W,a=e*r-W;return[o,a]}function Ke(n){return Ge/Math.pow(2,n)}function Q(n,e,t){let[r,o]=Qe(...Ne(n,e,t));return[o,-r]}function ge(n,e){return[n*G,e*G]}var $e="A".charCodeAt(0),N,I=0;async function Xe(n,e){let t;try{t=await(await fetch(n,e)).json()}catch(r){console.log("Can't load QTree:",r);return}N=A(t,{pos:0}),I=xe(N),console.log("Loaded QTree, depth:",I)}function A(n,e){let t=n.charCodeAt(e.pos)-$e;e.pos++;let r=t&1?A(n,e):null,o=t&2?A(n,e):null,a=t&4?A(n,e):null,s=t&8?A(n,e):null;return{sub:r||o||a||s?[r,o,a,s]:null}}function xe(n){let e=0;if(n==null?void 0:n.sub){for(let t=0;t<4;t++)if(n.sub[t]!==null){let r=xe(n.sub[t])+1;e<r&&(e=r)}}return e}var S;(function(r){r.Land="land",r.Mixed="mixed",r.Sea="sea"})(S||(S={}));function pe(n){if(!I)return S.Mixed;let e=ee({},n),t=!1;if(I<=n.z){t=!0;let r=n.z-I;e={x:n.x>>r,y:n.y>>r,z:I}}return ye(N,e,t)}function ye(n,e,t){if(n===null)return S.Land;if(t&&e.z===0)return S.Mixed;if(n.sub===null)return S.Sea;if(e.z===0)return S.Mixed;e.z--;let r=e.x>>e.z&1,a=(e.y>>e.z&1)<<1|r;return ye(n.sub[a],e,t)}function K(n,e,t){let r=((e-n)%360+540)%360-180;return(n+r*t+360)%360}function Je(n,e,t,r,o,a,s,i){switch((n?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 0:return 0;case 1:return n;case 2:return e;case 3:t=n,r=e;break;case 4:return t;case 5:e=n,r=t;break;case 6:r=e+t>>1,n=r;break;case 7:r=e+t>>1;break;case 8:return r;case 9:e=n+r>>1,t=e;break;case 10:n=e,t=r;break;case 11:t=n+r>>1;break;case 12:n=t,e=r;break;case 13:e=n+r>>1;break;case 14:n=e+t>>1;break}n=s+i*n,e=s+i*e,t=s+i*t,r=s+i*r;let u=K(n,e,o),f=K(t,r,o);return(K(u,f,a)-s)/i||1}function Ye(n,e,t,r,o,a,s,i){switch((n?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 7:return o+a<1?o*(e-n)+a*(t-n)+n:0;case 14:return o+a<1?0:o*(r-t)+a*(r-e)+e+t-r;case 11:return a<o?(1-o)*(n-e)+a*(r-e)+e:0;case 13:return a<o?0:(1-o)*(t-r)+a*(t-n)+n+r-t;case 15:return o+a<1?o*(e-n)+a*(t-n)+n:o*(r-t)+a*(r-e)+e+t-r;default:return 0}}function Ce(n,e,t){if(!t)return e;let r=.9999999/Math.pow(2,t.z),o=t.x*256*r,a=t.y*256*r,{raw:s,dmin:i,dmax:c,dmul:u}=e,f={raw:new Uint16Array(258*258),dmin:i,dmax:c,dmul:u},{raw:l}=f;for(let d=-1,h=0;d<=256;d++){let g=a+d*r,m=Math.floor(g),x=g-m;for(let p=-1;p<=256;p++,h++){let y=o+p*r,C=Math.floor(y),v=y-C,L=C+1+(m+1)*258,M=s[L],D=s[L+1],Ie=s[L+258],De=s[L+258+1];l[h]=n(M,D,Ie,De,v,x,i,u)}}return f}function et(n,e){return Ce(Ye,n,e)}function tt(n,e){return Ce(Je,n,e)}function rt(n,e,t){let r=t==="land"?1:0;for(let o=3,a=0;a<256;a++)for(let s=0;s<256;s++,o+=4){let i=e.data[o]?1:0;r^i&&(n.raw[(a+1)*258+(s+1)]=0)}return n}function nt(n){let[e,t]=ge(n.x,n.y),[r,o]=Q(e,t,n.z),[a,s]=Q(e+256,t+256,n.z);return{west:r,north:o,east:a,south:s}}function Se(n){let e=F("div","leaflet-tile s-tile");return e.wxtile=new we(n,e),(async()=>{let{wxtile:t}=e;try{await t.load(),t.draw()}catch(r){let{x:o,y:a,z:s}=t.coords;b(`tile(${o},${a},${s}) loading error: ${r}`)}n.done()})(),e}var we=class{constructor({layer:e,coords:t},r){this.data=[];this.streamLines=[];this.coords=t,this.layer=e,this.canvasFill=F("canvas","s-tile canvas-fill",r),this.canvasSlines=F("canvas","s-tile canvas-slines",r),this.canvasVector=this.canvasFill,this.canvasFill.width=this.canvasFill.height=this.canvasSlines.width=this.canvasSlines.height=256;function o(a){let s=a.getContext("2d");if(!s)throw new Error("getCtx error");return s}this.canvasFillCtx=o(this.canvasFill),this.imageDataForFillCtx=this.canvasFillCtx.createImageData(256,256),this.canvasVectorAnimationCtx=o(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}async load(){let{coords:e,layer:t}=this;await t.setupCompletePromise;let r=this._getTileType();if(!r)return this.data=[],this.streamLines=[],this;let{upCoords:o,subCoords:a}=this._splitCoords(e),s=this.layer.state.baseURL.replace("{z}",String(o.z)).replace("{x}",String(o.x)).replace("{y}",String(o.y)),i=this.layer.dataSource.variables.map(l=>s.replace("{var}",l)),c;try{c=await Promise.all(i.map(t.loadDataIntegralFunc))}catch(l){return l.code!==DOMException.ABORT_ERR&&(this.data=[],this.streamLines=[]),this}let u=t.state.units==="degree"?tt:et,f=l=>u(ue(l,t.style.blurRadius),a);return this.data=c.map(f),t.state.vector&&this._vectorMagnitudesPrepare(),await this._applyMask(r,a===void 0),t.state.vector&&this._createStreamLines(),this}async _applyMask(e,t){let{coords:r,layer:o}=this;if((o.style.mask==="land"||o.style.mask==="sea")&&e===S.Mixed){let a=o.dataSource.maskServerURI.replace("{z}",String(r.z)).replace("{x}",String(r.x)).replace("{y}",String(r.y));try{let s=await o.loadMaskFunc(a);if(!o.state.vector&&t){let{raw:i,dmin:c,dmax:u,dmul:f}=this.data[0];this.data[0]={raw:new Uint16Array(i),dmin:c,dmax:u,dmul:f}}rt(this.data[0],s,o.style.mask)}catch(s){o.style.mask=void 0,b("Can't load Mask. Masking is Turned OFF")}}}_splitCoords(e){let t=e.z-this.layer.state.meta.maxZoom;if(t<=0)return{upCoords:e};let r={x:e.x>>>t,y:e.y>>>t,z:this.layer.state.meta.maxZoom},o={x:e.x&(1<<t)-1,y:e.y&(1<<t)-1,z:t};return{upCoords:r,subCoords:o}}_getTileType(){let{coords:e,layer:t}=this,{mask:r}=t.style;var o=S.Mixed;if((r==="land"||r==="sea")&&(o=pe(e),r===o))return;let{boundaries:a}=t.state.meta;if(a==null?void 0:a.boundaries180){let s=nt(e),i=c=>!(s.west>c.east||c.west>s.east||s.south>c.north||c.south>s.north);if(!a.boundaries180.some(i))return}return o}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasVectorAnimationCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVectorsStatic(),this._drawDegreesStatic(),this._drawStreamLinesStatic())}clearVectorAnimationCanvas(){this.canvasVectorAnimationCtx.clearRect(0,0,256,256)}drawVectorAnimationLinesStep(e){if(this.streamLines.length===0)return;let t=this.canvasVectorAnimationCtx;if(t.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.streamLines=[];return}let r=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let o=0;o<this.streamLines.length;++o){let a=this.streamLines[o],s=a.length-1,i=(e+(1+a[0].x)*(1+a[0].y))%30;for(let c=0;c<s;++c){let u=a[c],f=a[c+1],l=1-(i-c)/s;(l<0||l>1)&&(l=0);let d=(~~(l*255)).toString(16);t.strokeStyle=r+(d.length<2?"0"+d:d);let h=1+~~((1.2-l)*5);t.lineWidth=h,t.beginPath(),t.moveTo(u.x,u.y),t.lineTo(f.x,f.y),t.stroke()}}}getPixelInfo({x:e,y:t}){var o;let r=(t+1)*258+(e+1);if(!!((o=this.data[0])==null?void 0:o.raw[r]))return{raw:this.data.map(a=>a.raw[r]),data:this.data.map(a=>a.raw[r]*a.dmul+a.dmin)}}_vectorMagnitudesPrepare(){if(this.data.length!==2)throw new Error("this.data !== 2");this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[e,t,r]=this.data;e.dmax=1.42*Math.max(-t.dmin,t.dmax,-r.dmin,r.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let o=0;o<258*258;++o){if(!t.raw[o]||!r.raw[o]){e.raw[o]=0;continue}let a=t.dmin+t.dmul*t.raw[o],s=r.dmin+r.dmul*r.raw[o];e.raw[o]=Math.sqrt(s*s+a*a)/e.dmul}}_drawFillAndIsolines(){let{imageDataForFillCtx:e}=this,{canvasFillCtx:t}=this,r=new Uint32Array(e.data.buffer),{raw:o}=this.data[0],{clut:a,style:s}=this.layer,{levelIndex:i,colorsI:c}=a;if(s.fill!=="none")for(let f=0,l=0,d=259;f<256;++f,d+=2)for(let h=0;h<256;++h,++l,++d)r[l]=c[o[d]];else r.fill(0);let u=[];if(s.isolineColor!=="none"){let f=s.isolineColor[0]==="#"?T(s.isolineColor):0;for(let l=0,d=0;l<256;l+=1)for(let h=0;h<256;h+=1){let g=(l+1)*258+(h+1),m=o[g],x=o[g+1],p=o[g+258];if(!m||!x||!p)continue;let y=i[m],C=i[x],v=i[p];if(y!==C||y!==v){let L=Math.max(y,C,v),M=Math.max(m,x,p),D=l*256+h;switch(s.isolineColor){case"inverted":r[D]=~c[M]|4278190080;break;case"fill":r[D]=c[M]|4278190080;break;default:r[D]=f;break}s.isolineText&&!(++d%255)&&h>20&&h<235&&l>20&&l<235&&u.push({x:h,y:l,d:m,dr:x,db:p,mli:L})}}}if(t.putImageData(e,0,0),u.length){t.font="1.1em Sans-serif",t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";for(let{x:f,y:l,d,dr:h,db:g,mli:m}of u){let x=this.layer.clut.ticks[m].dataString,p=Math.atan2(d-h,g-d);t.save(),t.translate(f,l),t.rotate(p<-1.57||p>1.57?p+3.14:p),t.strokeText(x,0,0),t.fillText(x,0,0),t.restore()}}}_drawStreamLinesStatic(){if(!this.streamLines.length||!this.layer.style.streamLineStatic)return;let{canvasVectorAnimationCtx:e}=this;if(this.layer.style.streamLineColor==="none"){this.streamLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let t=this.streamLines.length;t--;){let r=this.streamLines[t];for(let o=0;o<r.length-1;++o){let a=r[o],s=r[o+1];e.moveTo(a.x,a.y),e.lineTo(s.x,s.y)}}e.stroke()}_drawVectorsStatic(){let{clut:e,style:t}=this.layer;if(!this.layer.state.vector||!e.DataToKnots||t.vectorColor==="none"||t.vectorType==="none")return;if(this.data.length!==3)throw new Error("this.data.length !== 3");let[r,o,a]=this.data,{canvasVectorCtx:s}=this;switch(t.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=t.vectorType}s.textAlign="center",s.textBaseline="middle";let i=t.addDegrees?.017453292519943*t.addDegrees:0,c=32;for(let u=c/2;u<256;u+=c)for(let f=c/2;f<256;f+=c){let l=f+1+(u+1)*258;if(!r.raw[l])continue;let d=Math.atan2(o.dmin+o.raw[l]*o.dmul,a.dmin+a.raw[l]*a.dmul),h=r.dmin+r.raw[l]*r.dmul,g=t.vectorType!=="barbs"?t.vectorFactor*.2:.2,m=Math.min(e.DataToKnots(h)*g,25)+65,x=String.fromCharCode(m);switch(t.vectorColor){case"inverted":s.fillStyle=w(~e.colorsI[r.raw[l]]);break;case"fill":s.fillStyle=w(e.colorsI[r.raw[l]]);break;default:s.fillStyle=t.vectorColor;break}s.save(),s.translate(f,u),s.rotate(d+i),s.fillText(x,0,0),s.restore()}}_drawDegreesStatic(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:e}=this,t=.017453292519943*this.layer.style.addDegrees;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle";let r=this.data[0],o="L",a=32;for(let s=a/2;s<256;s+=a)for(let i=a/2;i<256;i+=a){let c=i+1+(s+1)*258;if(!r.raw[c])continue;let f=(r.dmin+r.raw[c]*r.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=w(~this.layer.clut.colorsI[r.raw[c]]);break;case"fill":e.fillStyle=w(this.layer.clut.colorsI[r.raw[c]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(i,s),e.rotate(f+t),e.fillText(o,0,0),e.restore()}}_createStreamLines(){if(this.data.length!==3)throw new Error("this.data.length !== 3");if(this.layer.style.streamLineColor==="none")return;let e=this.layer.style.streamLineSpeedFactor||1;this.streamLines=[];let[t,r,o]=this.data,a=Math.max(this.coords.z-this.layer.state.meta.maxZoom,0),s=Math.min(2**(a+5),128),i=~~(120+a*60);for(let c=0;c<=256;c+=s)for(let u=0;u<=256;u+=s){if(!t.raw[1+u+(1+c)*258])continue;let f=[],l=u,d=c;for(let h=0;h<=i&&l>=0&&l<=256&&d>=0&&d<=256;h++){!(h%(i/6))&&f.push({x:~~l,y:~~d});let g=~~l+1+(~~d+1)*258;if(!t.raw[g])break;l+=e*(r.dmin+r.raw[g]*r.dmul)/t.dmax,d-=e*(o.dmin+o.raw[g]*o.dmul)/t.dmax}l=u,d=c;for(let h=1;h<=i&&l>=0&&l<=256&&d>=0&&d<=256;h++){!(h%(i/6))&&f.unshift({x:~~l,y:~~d});let g=~~l+1+(~~d+1)*258;if(!t.raw[g])break;l-=e*(r.dmin+r.raw[g]*r.dmul)/t.dmax,d+=e*(o.dmin+o.raw[g]*o.dmul)/t.dmax}f.length>2&&this.streamLines.push(f)}}};var $;var E=class extends Te.default.GridLayer{constructor(e){super(e.options);this.styles=H();this.redrawRequestID=0;this.vectorAnimationRequestID=0;this.oldMaxZoom=0;this.style=Object.assign({},this.styles.base);this.clut=new U(this.style,"",[0,2],!1);this.animation=!0;let{dataSource:t,lazy:r}=e;if(b("Creating a WxTiles layer:",t.name,". Params:",JSON.stringify(e)),!(t==null?void 0:t.ext)||!t.dataset||!t.name||!t.serverURI||!t.styleName||!Array.isArray(t.variables)||t.variables.length<1||t.variables.length>2){let i="WxTilesLayer: dataSource is wrong!";throw b(i),new Error(i)}this.dataSource=t,this.state={originURI:t.serverURI+"/"+t.dataset+"/",units:"",baseURL:"",meta:{maxZoom:0,times:[],variables:[],variablesMeta:{}},instance:"",minmax:[[0,1]],currentTime:"",vector:t.variables.length>1},this.loadDataIntegralFunc=Z(t.requestInit),$||($=ce(t.requestInit)),this.loadMaskFunc=$;let o=()=>{var i;((i=this._map)==null?void 0:i.getZoom())<this.state.meta.maxZoom&&this._stopLoadingResetLoadDataFunc()},a=()=>{if(b("onadd:",this.dataSource.name),!this._map)throw new Error("_map is not set!");this._map.on("zoomstart",o),this._checkAndStartVectorAnimation()},s=()=>{if(b("onremove:",this.dataSource.name),!this._map)throw new Error("_map is not set!");this._map.off("zoomstart",o),this._stopLoadingResetLoadDataFunc()};this.on("remove",s),this.on("add",a),this.setupCompletePromise=new Promise(i=>{let c=async()=>{b("Setup:",t.name),await this._setUpDataSet(),b("Setup complete: ",this.dataSource.name),i()};r?this.once("add",c):c()})}async _setUpDataSet(){let{state:e,dataSource:t}=this;try{e.instance=(await P(e.originURI+"instances.json")).pop()+"/"}catch(o){let a=t.name+": load instances.json error: "+o;throw b(a),new Error(a)}try{let o=e.originURI+e.instance+"meta.json";e.meta=await P(o)}catch(o){let a=t.name+": load meta.json error: "+o;throw b(a),new Error(a)}e.vector=t.variables.length===2;let{variablesMeta:r}=e.meta;if(e.units=r[t.variables[0]].units,e.minmax=t.variables.map(o=>[r[o].min,r[o].max]),e.vector){let[[o,a],[s,i]]=e.minmax;e.minmax.unshift([0,1.42*Math.max(-o,a,-s,i)])}this._setStyleAndCLUT(t.styleName),this._setTimeUrl(new Date)}async _requestReloadTilesAndRedraw(){let e=await this._requestReloadTiles();return e&&this._redrawTiles(),e}async _requestReloadTiles(){b(`_requestReloadTiles: start - ${this.dataSource.name}`);let{controller:e}=this.loadDataIntegralFunc.controllerHolder;return await Promise.allSettled(this._ForEachWxTile(t=>t.load())),b(`_requestReloadTiles: end - ${this.dataSource.name}, aborted: ${e.signal.aborted}`),!e.signal.aborted}async setStyle(e){b("setStyle(",e,") for ",this.dataSource.name),(e==="custom"||e!==this.dataSource.styleName)&&(this._setStyleAndCLUT(e),this._checkAndStartVectorAnimation(),await this._requestReloadTilesAndRedraw()),b("setStyle(",e,'): "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete.")}_setStyleAndCLUT(e){let{dataSource:t,styles:r,state:o}=this;t.styleName=e,e==="custom"&&(r.custom.parent&&r.custom.parent in r||(b(`cant find the parent style (${r.custom.parent}), 'base' is used`),r.custom.parent="base"),r.custom=Object.assign(Object.assign({},r[r.custom.parent]),r.custom)),e in r||(b(`cant find the style (${e}), 'base' is used`),e=t.styleName="base");try{this.style=Object.assign({},r[e]),this.style.streamLineColor=he(this.style.streamLineColor),this.clut=new U(this.style,o.units,o.minmax[0],o.vector)}catch(a){let s="setStyle: impossible error in RawCLUT: "+a;throw b(s),new Error(s)}}createTile(e,t){return Se({layer:this,coords:e,done:t})}getSetupCompletePromise(){return this.setupCompletePromise}getLayerInfoAtLatLon(e){if(!this._map)return;let t=this._map.getZoom(),r=this._map.project(e,t),o=r.divideBy(256).floor(),a=this._getCachedTile(o,t);if(!a)return;let s=r.subtract(o.multiplyBy(256)).floor(),i=a.getPixelInfo(s);if(!i)return;let{raw:c,data:u}=i,f=c.map(h=>this.clut.colorsI[h]),l=f.map(w),d=u.map(h=>this.clut.DataToStyle(h));return{wxtile:a,data:u,raw:c,rgba:f,hexColor:l,inStyleUnits:d,tilePoint:s,styleUnits:this.style.units,dataUnits:this.state.units}}getStyle(){return this.style}_getFirstNonEmptyTile(){for(let e in this._tiles){let{wxtile:t}=this._tiles[e].el;if(t==null?void 0:t.data.length)return t}}_setTimeUrl(e){let{dataSource:t,state:r}=this,o=fe(r.meta.times,e);return r.currentTime===o?(b("_setTimeUrl: the same time - skipped"),!1):(r.currentTime=o,r.baseURL=r.originURI+r.instance+`{var}/${r.currentTime}/{z}/{x}/{y}.${t.ext}`,b(`_setTimeUrl: ${o} for ${t.name} complete`),!0)}setTime(e){if(b("setTime: "+e+" for "+this.dataSource.name+" start"),!this._tiles)return b("setTime: no tiles - skipped"),Promise.resolve(!1);let{currentTime:t}=this.state;if(!this._setTimeUrl(e))return Promise.resolve(!1);this.loadDataIntegralFunc.abort();let r=this._requestReloadTiles();return r.then(o=>{if(!o){this.state.currentTime=t;return}let a=this._getFirstNonEmptyTile();if(a==null?void 0:a.data.length){let[s,i]=this.state.minmax[0],{dmin:c,dmax:u}=a.data[0];(Math.abs(c-s)>.01||Math.abs(u-i)>.01)&&(this.state.minmax=a.data.map(f=>[f.dmin,f.dmax]),this._setStyleAndCLUT(this.dataSource.styleName))}this._redrawTiles()}),r}getTime(){return this.state.currentTime}getTimes(){return b("getTimes"),this.state.meta.times}getLegendData(e){return b("getLegendData"),V(e,this.style)}setTimeAnimationMode(e=2){b("setTimeAnimationMode"),this.oldMaxZoom=this.state.meta.maxZoom;let t=this._map.getZoom(),o=(t<this.oldMaxZoom?t:this.oldMaxZoom)-e;this.state.meta.maxZoom=o<0?0:o}async unsetTimeAnimationMode(){return b("unsetTimeAnimationMode"),this.oldMaxZoom&&(this.state.meta.maxZoom=this.oldMaxZoom),this._requestReloadTilesAndRedraw()}getMinMax(){let[e,t]=this.state.minmax[0];return{min:e,max:t}}setAnimation(e){return b("setAnimation"),this.animation=e,this._checkAndStartVectorAnimation(),this.animation}_getCachedTile({x:e,y:t},r){var o,a;return(a=(o=this._tiles[`${e}:${t}:${r}`])==null?void 0:o.el)==null?void 0:a.wxtile}_ForEachWxTile(e){var r;let t=[];for(let o in this._tiles){let a=(r=this._tiles[o].el)==null?void 0:r.wxtile;a&&t.push(e(a))}return t}_stopLoadingResetLoadDataFunc(){this.loadDataIntegralFunc.abort(),this.loadDataIntegralFunc=Z()}_checkAndStartVectorAnimation(){if(this.vectorAnimationRequestID)return;let e=t=>{if(!this._map||!this.animation||!this.state.vector||this.style.streamLineStatic||this.style.streamLineColor==="none"){this._ForEachWxTile(r=>r.clearVectorAnimationCanvas()),this.vectorAnimationRequestID=0;return}this._ForEachWxTile(r=>r.drawVectorAnimationLinesStep(t)),this.vectorAnimationRequestID=requestAnimationFrame(e)};this.vectorAnimationRequestID=requestAnimationFrame(e)}_redrawTiles(){this.redrawRequestID||(b("_redrawTiles: start: "+this.dataSource.name),this.redrawRequestID=requestAnimationFrame(()=>{this._ForEachWxTile(e=>e.draw()),this.redrawRequestID=0,b("_redrawTiles: requestAnimationFrame: end: "+this.dataSource.name)}))}};function ot(n){return new E(n)}var ve=class extends q.default.Control{constructor(e){super(e);this.URI=e.URI}onAdd(){let e=document.createElement("img");return e.src=this.URI,e.className="wxtiles-logo",e}};function Ot(n){return b("Add watermark:",JSON.stringify(n)),new ve(n)}var Le=class extends q.default.GridLayer{createTile(e){let t=document.createElement("div");return t.innerHTML=[e.x,e.y,e.z].join(", "),t.style.outline="1px solid red",t}};function Ht(){return b("Add WxDebugCoordsLayer:"),new Le().setZIndex(1e3)}function zt(n,e){return q.default.layerGroup(n.map(ot),e)}export{Ht as CreateWxDebugCoordsLayer,zt as CreateWxTilesGroupLayer,ot as CreateWxTilesLayer,Ot as CreateWxTilesWatermark,Xe as LoadQTree,Le as WxDebugLayer,z as WxGetColorSchemes,H as WxGetColorStyles,E as WxTilesLayer,We as WxTilesLibSetup,je as WxTilesLogging,ve as WxWatermark,P as fetchJson};
|
package/dist/web/wxtiles.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var wxtilesjs=(()=>{var Ae=Object.create;var k=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames,$=Object.getOwnPropertySymbols,Pe=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 Re=(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(Pe(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var B=Re((at,ne)=>{ne.exports=window.L});var rt={};We(rt,{CreateWxDebugCoordsLayer:()=>et,CreateWxTilesGroupLayer:()=>tt,CreateWxTilesLayer:()=>ke,CreateWxTilesWatermark:()=>Ye,LoadQTree:()=>Se,WxDebugLayer:()=>X,WxGetColorStyles:()=>R,WxTilesLayer:()=>_,WxTilesLibSetup:()=>le,WxTilesLogging:()=>xe,WxWatermark:()=>V});var H=re(B());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={}}={}){x("WxTile lib setup: start"),Z=Object.assign({},se,e),ie=Object.assign({},t,oe);let n=Object.assign({},r,U);ae=Ee(n),x("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),x("WxTile lib setup is done.")}function R(){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]){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 Ee(r){let e=Object.assign({},U);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 U.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 me(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 He(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 Ne(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 Ne(await He(r,e))}function Be(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=Ze(o);return{raw:o,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=>Be(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 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 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 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 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 z(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 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 x(...r){ge&&console.trace(...r)}var De=re(B());function je(r,e,t){return r>t?t:r<e?e:r}var F=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=W(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),o&&(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=O(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 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 O(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:ye(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?z(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?z(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:ye(a),color:w(t.colors[d]),pos:d};t.ticks.push(h)}return t}var Q=256,ze=2*Math.PI*6378137/Q,E=2*Math.PI*6378137/2;function Oe(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,o=e*n-E;return[s,o]}function Ge(r){return ze/Math.pow(2,r)}function G(r,e,t){let[n,s]=Oe(...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,o=t&4?I(r,e):null,i=t&8?I(r,e):null;return{sub:n||s||o||i?[n,s,o,i]: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,o=(e.y>>e.z&1)<<1|n;return Te(r.sub[o],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,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 P=K(g,y,m),M=K(S,C,m);i[u]=(K(P,M,c)-r.dmin)/r.dmul,i[u]===0&&(i[u]=1)}}return o}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,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 Xe(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 $e(r){let[e,t]=pe(r.x,r.y),[n,s]=G(e,t,r.z),[o,i]=G(e+256,t+256,r.z);return{west:n,north:s,east:o,south:i}}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(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=we(e),s===o))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: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"?Ke:Ve;if(this.data=f.map(a=>b(de(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);Xe(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 N=Math.max(y,S,C),P=Math.max(m,p,g),M=c*256+d;switch(i.isolineColor){case"inverted":n[M]=~u[P]|4278190080;break;case"fill":n[M]=u[P]|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:N})}}}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 Me="setup not complete",Je=fe(new AbortController),_=class extends De.default.GridLayer{constructor({dataSource:e,options:t,lazy:n}){super(t);this.styles=R();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.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!==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),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 F(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=be(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 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 x("reloadData"),this._setUpDataSet(void 0)}getLegendData(e){return x("getLegendData"),(this.error||!this.clut)&&x("getLegendData: failed. "+this.dataSource.name+" : "+this.error),O(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 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,x(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,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=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(()=>{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 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 x("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 x("Add WxDebugCoordsLayer:"),new X().setZIndex(1e3)}function tt(r,e){return H.default.layerGroup(r.map(ke),e)}return rt;})();
|
|
1
|
+
var wxtilesjs=(()=>{var Pe=Object.create;var A=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames,Y=Object.getOwnPropertySymbols,We=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var te=(n,e,t)=>e in n?A(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,re=(n,e)=>{for(var t in e||(e={}))ee.call(e,t)&&te(n,t,e[t]);if(Y)for(var t of Y(e))Ee.call(e,t)&&te(n,t,e[t]);return n};var ne=n=>A(n,"__esModule",{value:!0});var ut=typeof require!="undefined"?require:n=>{throw new Error('Dynamic require of "'+n+'" is not supported')};var qe=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Be=(n,e)=>{ne(n);for(var t in e)A(n,t,{get:e[t],enumerable:!0})},Oe=(n,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ue(e))!ee.call(n,r)&&r!=="default"&&A(n,r,{get:()=>e[r],enumerable:!(t=Fe(e,r))||t.enumerable});return n},oe=n=>Oe(ne(A(n!=null?Pe(We(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var H=qe((ht,ae)=>{ae.exports=window.L});var ct={};Be(ct,{CreateWxDebugCoordsLayer:()=>it,CreateWxTilesGroupLayer:()=>lt,CreateWxTilesLayer:()=>Re,CreateWxTilesWatermark:()=>st,LoadQTree:()=>we,WxDebugLayer:()=>J,WxGetColorSchemes:()=>U,WxGetColorStyles:()=>F,WxTilesLayer:()=>k,WxTilesLibSetup:()=>ue,WxTilesLogging:()=>pe,WxWatermark:()=>X,fetchJson:()=>M});var O=oe(H());var se={comment1:["'degC': ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["'hPa': ['Pa', 1000]' -> hPa = Pa * 1000 + 0 (0 - could be ommited)",0],K:["K",1],kelvin:["K",1],F:["K",.5555555555,255.372222222],C:["K",1,273.15],degC:["K",1,273.15],"kg/m^2/s":["kg/m^2/s",1],"Kg/m^2/s":["kg/m^2/s",1],"Kg m**-2 s**-1":["kg/m^2/s",1],"Kg m^-2 s^-1":["kg/m^2/s",1],"Kg m^{-2} s^-1":["kg/m^2/s",1],"mm/h":["kg/m^2/s",.00027777777],"mm/hr":["kg/m^2/s",.00027777777],"W/m^2":["W/m^2",1],"W m^-2":["W/m^2",1],"W m^{-2}":["W/m^2",1],"W/m**2":["W/m^2",1],"W m**-2":["W/m^2",1],"m/s":["m/s",1],"m s**-1":["m/s",1],"m s^-1":["m/s",1],"m.s^{-1}":["m/s",1],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["m/s",.27777777777],"km h^-1":["m/s",.27777777777],"km h**-1":["m/s",.27777777777],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],inch:["m",.0254],Pa:["Pa",1],hPa:["Pa",100],degree:["degree",1],radian:["degree",57.3],"mg/m^3":["mg/m^3",1],"mg m^-3":["mg/m^3",1],"mg.m^-3":["mg/m^3",1],"%":["%",1],"(0 - 1)":["%",100]};var ie={none:["#00000000","#00000000"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbowzerro:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow2:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebirdzerro:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bw:["#000000ff","#ffffffff"],wb:["#ffffffff","#000000ff"],redish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"]};var P={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",vectorFactor:1,streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",vectorFactor:1,streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"}};var z,le,ce;function ue({colorStyles:n={},units:e={},colorSchemes:t={}}={}){b("WxTile lib setup: start"),z=Object.assign({},se,e),le=Object.assign({},t,ie);let r=Object.assign({},n,P);ce=He(r),b("WxTile lib setup: styles unrolled"),document.fonts.load("32px barbs"),document.fonts.load("32px arrows"),b("WxTile lib setup is done.")}function F(){return ce}function U(){return le}function W(n,e,t){let r=t?Object.assign({},z,t):z;if(!r||!n||!e||n===e||!r[n]||!r[e]||r[n][0]!==r[e][0]){b(n===e?"Trivial converter:":"Inconvertible units. Default converter is used:",n," -> ",e);let s=i=>i;return s.trivial=!0,s}b("Converter: From:",n," To:",e);let o=r[n][1]/r[e][1],a=(r[n][2]||0)/r[e][1]-(r[e][2]||0)/r[e][1];return a?s=>o*s+a:s=>o*s}function He(n){let e=Object.assign({},P);for(let o in n){let a=n[o];if(Array.isArray(a))for(let s=0;s<a.length;++s)e[o+"["+s+"]"]=Object.assign({},a[s]);else e[o]=Object.assign({},a)}let t=(o,a)=>{if(a==="base")return P.base;let s=o[a];(!s.parent||!(s.parent in o))&&(s.parent="base");let i=t(o,s.parent);return Object.assign(s,Object.assign({},i,s,{parent:"base"}))},r={};for(let o in e)r[o]=t(e,o);return r}function ze(n){let e=new Map;return t=>{let r=e.get(t);if(r)return r;let o=n(t);return e.set(t,o),o.catch(a=>{a.code===DOMException.ABORT_ERR&&e.delete(t)}),o}}async function Ze(n,e){let t=new Image;return t.src=URL.createObjectURL(await(await fetch(n,e)).blob()),await t.decode(),URL.revokeObjectURL(t.src),t}function je(n){let{width:e,height:t}=n,r=Object.assign(document.createElement("canvas"),{width:e,height:t,imageSmoothingEnabled:!1}).getContext("2d");if(!r)throw new Error("Error: can not create context. Catastrophe");return r.drawImage(n,0,0),r.getImageData(0,0,e,t)}async function me(n,e){return je(await Ze(n,e))}function Ve(n){n.data[34]<1&&b("Warning: image is in too old format. Check the version of the Splitter.");let e=new Uint16Array(n.data.buffer),t=new Uint16Array(e.length/2);for(let u=0;u<t.length;u++)t[u]=e[u*2];let r=new Uint8Array(8);for(let u=0;u<8;++u)r[u]=n.data[u*4+2];let o=new DataView(r.buffer),a=o.getFloat32(0,!0),s=o.getFloat32(4,!0),i=(s-a)/65535,c=Qe(t);return{raw:t,dmin:a,dmax:s,dmul:i,integral:c,radius:0}}async function Ge(n,e){return Ve(await me(n,e))}function fe(n,e){let t={controller:new AbortController,debug:Date.now().toString()},r=Object.assign({},e,{signal:t.controller.signal}),o=ze(a=>n(a,r));return o.controllerHolder=t,o.abort=()=>{t.controller.abort(),t.controller=new AbortController,t.debug=Date.now().toString(),r.signal=t.controller.signal},o}function Z(n){return fe(Ge,n)}function de(n){return fe(me,n)}function Qe(n){let e=new Uint32Array(258*258),t=new Uint32Array(258*258);e[0]=n[0],t[0]=n[0]===0?0:1;for(let r=1;r<258;++r)e[r]=n[r]+e[r-1],e[258*r]=n[258*r]+e[258*r-258],t[r]=(n[r]===0?0:1)+t[r-1],t[258*r]=(n[258*r]===0?0:1)+t[258*r-258];for(let r=1,o=259;r<258;++r,++o)for(let a=1;a<258;++a,++o)e[o]=n[o]+e[o-258]+e[o-1]-e[o-258-1],t[o]=(n[o]===0?0:1)+t[o-258]+t[o-1]-t[o-258-1];return{integral:e,integralNZ:t}}function he(n,e){if(e<0||e===n.radius)return n;n.radius=e;let t=258,{integral:r,integralNZ:o}=n.integral;for(let a=1;a<t;a++)for(let s=1;s<t;s++){if(!n.raw[t*a+s])continue;let i=Math.min(e,s-1,t-1-s),c=Math.min(e,a-1,t-1-a),u=t*(a-c-1)+s,f=t*(a+c)+s,l=o[u-i-1],d=o[u+i],h=o[f-i-1],g=o[f+i],m=l+g-d-h,x=r[u-i-1],p=r[u+i],y=r[f-i-1],C=r[f+i],v=x+C-p-y;n.raw[a*t+s]=v/m}return n}function w(n){let e=n>>0&255,t=n>>8&255,r=n>>16&255,o=e.toString(16),a=t.toString(16),s=r.toString(16);return o=o.length===2?o:"0"+o,a=a.length===2?a:"0"+a,s=s.length===2?s:"0"+s,"#"+o+a+s}function T(n){if(n[0]==="#"){if(n.length===4)return+("0xff"+n[3]+n[3]+n[2]+n[2]+n[1]+n[1]);if(n.length===7)return+("0xff"+n[5]+n[6]+n[3]+n[4]+n[1]+n[2]);if(n.length===9)return+("0x"+n[7]+n[8]+n[5]+n[6]+n[3]+n[4]+n[1]+n[2])}return b("wrong color format",n),0}async function M(n,e){return(await fetch(n,e)).json()}function E(n,e="",t){var o;let r=document.createElement(n);return r.className=e,t&&((o=t.appendChild)==null||o.call(t,r)),r}function j(n,e,t){let r=n>>0&255,o=n>>8&255,a=n>>16&255,s=n>>>24,i=e>>0&255,c=e>>8&255,u=e>>16&255,f=e>>>24,l=r+t*(i-r),d=o+t*(c-o),h=a+t*(u-a),g=s+t*(f-s);return l|d<<8|h<<16|g<<24}function be(n,e,t){let r=[];for(let o=0;o<t;++o)r.push(o*(e-n)/(t-1)+n);return r}function ge(n,e){let t=typeof e=="number"?e:typeof e=="string"?new Date(e).getTime():e.getTime();return n.find(r=>new Date(r).getTime()>=t)||n[n.length-1]}var xe=!1;function pe(n){console.log(n?"Logging on":"Logging off"),xe=n}function b(...n){xe&&console.trace(...n)}function ye(n){return n!=="none"&&n.length<7?"#"+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]:n}var Me=oe(H());function Ne(n,e,t){return n>t?t:n<e?e:n}var q=class{constructor(e,t,[r,o],a){let s=o-r;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let i=[];this.DataToStyle=W(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),a&&(this.DataToKnots=W(t,"knot"));let c=W(e.units,t,e.extraUnits),u=m=>~~(65535*Ne((c(m)-r)/(o-r),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((m,x)=>m[0]<x[0]?-1:m[0]>x[0]?1:0);for(let[m]of e.colorMap)i.push(u(m))}else{if(e.levels||(e.levels=be(this.DataToStyle(r),this.DataToStyle(o),10)),e.levels.sort((m,x)=>m<x?-1:m>x?1:0),!e.colors){let m=U();e.colorScheme&&e.colorScheme in m?e.colors=m[e.colorScheme]:e.colors=m.wb}for(let m of e.levels)i.push(u(m))}let f=65536,l=V(f,e);this.ticks=l.ticks;let d=l.ticks[0].data,g=l.ticks[l.ticks.length-1].data-d;for(let m=0;m<65536;++m){let x=s*m/65535+r,p=this.DataToStyle(x),y=Math.round((f-1)*(p-d)/g);y<=0?this.colorsI[m]=e.showBelowMin?l.colors[0]:0:y>=f?this.colorsI[m]=e.showAboveMax?l.colors[f-1]:0:this.colorsI[m]=l.colors[y]}this.colorsI[0]=0;for(let m=0;m<i[0];++m)this.levelIndex[m]=0;for(let m=0;m<i.length-1;m++)for(let x=i[m];x<i[m+1]+1;++x)this.levelIndex[x]=m;for(let m=i[i.length-1];m<65536;++m)this.levelIndex[m]=i.length-1}};function Ce(n){var t;if(n!==0&&-.1<n&&n<.1)return n.toExponential(2);let e=n.toString();return((t=e.split(".")[1])==null?void 0:t.length)>2?n.toFixed(2):e}function V(n,e){let t={size:n,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(n),ticks:[]},{colorMap:r,levels:o,colors:a}=e,s=e.fill!=="solid";if(r){let d=r[0][0],h=r[r.length-1][0]-d;for(let[g,m]of r){let x=~~((g-d)/h*(n-1)),p={data:g,dataString:Ce(g),color:m,pos:x};t.ticks.push(p)}for(let g=0;g<r.length-1;g++){let m=t.ticks[g].pos,x=t.ticks[g+1].pos,p=T(r[g][1]),y=s?T(r[g+1][1]):0;for(let C=m;C<x;++C)t.colors[C]=s?j(p,y,(C-m)/(x-m)):p}return t.colors[n-1]=T(r[r.length-1][1]),t}if(!a||!o)return t;let i=0,c=0,u=-1;for(let d=0;d<n;++d){let h=d*(a.length-1)/n;u!==~~h&&(u=~~h,i=T(a[u]),c=a.length>u+1?T(a[u+1]):i),t.colors[d]=s?j(i,c,h-u):i}t.colors[n-1]=T(a[a.length-1]);let f=o[0],l=(n-1)/(o[o.length-1]-f);for(let d of o){let h=~~((d-f)*l),g={data:d,dataString:Ce(d),color:w(t.colors[h]),pos:h};t.ticks.push(g)}return t}var G=256,Ke=2*Math.PI*6378137/G,B=2*Math.PI*6378137/2;function $e(n,e){let t=n/B*180,r=e/B*180;return r=180/Math.PI*(2*Math.atan(Math.exp(r*Math.PI/180))-Math.PI/2),[r,t]}function Xe(n,e,t){let r=Je(t),o=n*r-B,a=e*r-B;return[o,a]}function Je(n){return Ke/Math.pow(2,n)}function Q(n,e,t){let[r,o]=$e(...Xe(n,e,t));return[o,-r]}function Se(n,e){return[n*G,e*G]}var Ye="A".charCodeAt(0),N,I=0;async function we(n,e){let t;try{t=await(await fetch(n,e)).json()}catch(r){console.log("Can't load QTree:",r);return}N=R(t,{pos:0}),I=Te(N),console.log("Loaded QTree, depth:",I)}function R(n,e){let t=n.charCodeAt(e.pos)-Ye;e.pos++;let r=t&1?R(n,e):null,o=t&2?R(n,e):null,a=t&4?R(n,e):null,s=t&8?R(n,e):null;return{sub:r||o||a||s?[r,o,a,s]:null}}function Te(n){let e=0;if(n==null?void 0:n.sub){for(let t=0;t<4;t++)if(n.sub[t]!==null){let r=Te(n.sub[t])+1;e<r&&(e=r)}}return e}var S;(function(r){r.Land="land",r.Mixed="mixed",r.Sea="sea"})(S||(S={}));function ve(n){if(!I)return S.Mixed;let e=re({},n),t=!1;if(I<=n.z){t=!0;let r=n.z-I;e={x:n.x>>r,y:n.y>>r,z:I}}return Le(N,e,t)}function Le(n,e,t){if(n===null)return S.Land;if(t&&e.z===0)return S.Mixed;if(n.sub===null)return S.Sea;if(e.z===0)return S.Mixed;e.z--;let r=e.x>>e.z&1,a=(e.y>>e.z&1)<<1|r;return Le(n.sub[a],e,t)}function K(n,e,t){let r=((e-n)%360+540)%360-180;return(n+r*t+360)%360}function et(n,e,t,r,o,a,s,i){switch((n?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 0:return 0;case 1:return n;case 2:return e;case 3:t=n,r=e;break;case 4:return t;case 5:e=n,r=t;break;case 6:r=e+t>>1,n=r;break;case 7:r=e+t>>1;break;case 8:return r;case 9:e=n+r>>1,t=e;break;case 10:n=e,t=r;break;case 11:t=n+r>>1;break;case 12:n=t,e=r;break;case 13:e=n+r>>1;break;case 14:n=e+t>>1;break}n=s+i*n,e=s+i*e,t=s+i*t,r=s+i*r;let u=K(n,e,o),f=K(t,r,o);return(K(u,f,a)-s)/i||1}function tt(n,e,t,r,o,a,s,i){switch((n?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 7:return o+a<1?o*(e-n)+a*(t-n)+n:0;case 14:return o+a<1?0:o*(r-t)+a*(r-e)+e+t-r;case 11:return a<o?(1-o)*(n-e)+a*(r-e)+e:0;case 13:return a<o?0:(1-o)*(t-r)+a*(t-n)+n+r-t;case 15:return o+a<1?o*(e-n)+a*(t-n)+n:o*(r-t)+a*(r-e)+e+t-r;default:return 0}}function Ie(n,e,t){if(!t)return e;let r=.9999999/Math.pow(2,t.z),o=t.x*256*r,a=t.y*256*r,{raw:s,dmin:i,dmax:c,dmul:u}=e,f={raw:new Uint16Array(258*258),dmin:i,dmax:c,dmul:u},{raw:l}=f;for(let d=-1,h=0;d<=256;d++){let g=a+d*r,m=Math.floor(g),x=g-m;for(let p=-1;p<=256;p++,h++){let y=o+p*r,C=Math.floor(y),v=y-C,L=C+1+(m+1)*258,_=s[L],D=s[L+1],ke=s[L+258],_e=s[L+258+1];l[h]=n(_,D,ke,_e,v,x,i,u)}}return f}function rt(n,e){return Ie(tt,n,e)}function nt(n,e){return Ie(et,n,e)}function ot(n,e,t){let r=t==="land"?1:0;for(let o=3,a=0;a<256;a++)for(let s=0;s<256;s++,o+=4){let i=e.data[o]?1:0;r^i&&(n.raw[(a+1)*258+(s+1)]=0)}return n}function at(n){let[e,t]=Se(n.x,n.y),[r,o]=Q(e,t,n.z),[a,s]=Q(e+256,t+256,n.z);return{west:r,north:o,east:a,south:s}}function De(n){let e=E("div","leaflet-tile s-tile");return e.wxtile=new Ae(n,e),(async()=>{let{wxtile:t}=e;try{await t.load(),t.draw()}catch(r){let{x:o,y:a,z:s}=t.coords;b(`tile(${o},${a},${s}) loading error: ${r}`)}n.done()})(),e}var Ae=class{constructor({layer:e,coords:t},r){this.data=[];this.streamLines=[];this.coords=t,this.layer=e,this.canvasFill=E("canvas","s-tile canvas-fill",r),this.canvasSlines=E("canvas","s-tile canvas-slines",r),this.canvasVector=this.canvasFill,this.canvasFill.width=this.canvasFill.height=this.canvasSlines.width=this.canvasSlines.height=256;function o(a){let s=a.getContext("2d");if(!s)throw new Error("getCtx error");return s}this.canvasFillCtx=o(this.canvasFill),this.imageDataForFillCtx=this.canvasFillCtx.createImageData(256,256),this.canvasVectorAnimationCtx=o(this.canvasSlines),this.canvasVectorCtx=this.canvasFillCtx}async load(){let{coords:e,layer:t}=this;await t.setupCompletePromise;let r=this._getTileType();if(!r)return this.data=[],this.streamLines=[],this;let{upCoords:o,subCoords:a}=this._splitCoords(e),s=this.layer.state.baseURL.replace("{z}",String(o.z)).replace("{x}",String(o.x)).replace("{y}",String(o.y)),i=this.layer.dataSource.variables.map(l=>s.replace("{var}",l)),c;try{c=await Promise.all(i.map(t.loadDataIntegralFunc))}catch(l){return l.code!==DOMException.ABORT_ERR&&(this.data=[],this.streamLines=[]),this}let u=t.state.units==="degree"?nt:rt,f=l=>u(he(l,t.style.blurRadius),a);return this.data=c.map(f),t.state.vector&&this._vectorMagnitudesPrepare(),await this._applyMask(r,a===void 0),t.state.vector&&this._createStreamLines(),this}async _applyMask(e,t){let{coords:r,layer:o}=this;if((o.style.mask==="land"||o.style.mask==="sea")&&e===S.Mixed){let a=o.dataSource.maskServerURI.replace("{z}",String(r.z)).replace("{x}",String(r.x)).replace("{y}",String(r.y));try{let s=await o.loadMaskFunc(a);if(!o.state.vector&&t){let{raw:i,dmin:c,dmax:u,dmul:f}=this.data[0];this.data[0]={raw:new Uint16Array(i),dmin:c,dmax:u,dmul:f}}ot(this.data[0],s,o.style.mask)}catch(s){o.style.mask=void 0,b("Can't load Mask. Masking is Turned OFF")}}}_splitCoords(e){let t=e.z-this.layer.state.meta.maxZoom;if(t<=0)return{upCoords:e};let r={x:e.x>>>t,y:e.y>>>t,z:this.layer.state.meta.maxZoom},o={x:e.x&(1<<t)-1,y:e.y&(1<<t)-1,z:t};return{upCoords:r,subCoords:o}}_getTileType(){let{coords:e,layer:t}=this,{mask:r}=t.style;var o=S.Mixed;if((r==="land"||r==="sea")&&(o=ve(e),r===o))return;let{boundaries:a}=t.state.meta;if(a==null?void 0:a.boundaries180){let s=at(e),i=c=>!(s.west>c.east||c.west>s.east||s.south>c.north||c.south>s.north);if(!a.boundaries180.some(i))return}return o}draw(){this.canvasFillCtx.clearRect(0,0,256,256),this.canvasVectorAnimationCtx.clearRect(0,0,256,256),!!this.data.length&&(this._drawFillAndIsolines(),this._drawVectorsStatic(),this._drawDegreesStatic(),this._drawStreamLinesStatic())}clearVectorAnimationCanvas(){this.canvasVectorAnimationCtx.clearRect(0,0,256,256)}drawVectorAnimationLinesStep(e){if(this.streamLines.length===0)return;let t=this.canvasVectorAnimationCtx;if(t.clearRect(0,0,256,256),this.layer.style.streamLineColor==="none"){this.streamLines=[];return}let r=this.layer.style.streamLineColor.substr(0,7);e=e>>7;for(let o=0;o<this.streamLines.length;++o){let a=this.streamLines[o],s=a.length-1,i=(e+(1+a[0].x)*(1+a[0].y))%30;for(let c=0;c<s;++c){let u=a[c],f=a[c+1],l=1-(i-c)/s;(l<0||l>1)&&(l=0);let d=(~~(l*255)).toString(16);t.strokeStyle=r+(d.length<2?"0"+d:d);let h=1+~~((1.2-l)*5);t.lineWidth=h,t.beginPath(),t.moveTo(u.x,u.y),t.lineTo(f.x,f.y),t.stroke()}}}getPixelInfo({x:e,y:t}){var o;let r=(t+1)*258+(e+1);if(!!((o=this.data[0])==null?void 0:o.raw[r]))return{raw:this.data.map(a=>a.raw[r]),data:this.data.map(a=>a.raw[r]*a.dmul+a.dmin)}}_vectorMagnitudesPrepare(){if(this.data.length!==2)throw new Error("this.data !== 2");this.data.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[e,t,r]=this.data;e.dmax=1.42*Math.max(-t.dmin,t.dmax,-r.dmin,r.dmax),e.dmul=(e.dmax-e.dmin)/65535;for(let o=0;o<258*258;++o){if(!t.raw[o]||!r.raw[o]){e.raw[o]=0;continue}let a=t.dmin+t.dmul*t.raw[o],s=r.dmin+r.dmul*r.raw[o];e.raw[o]=Math.sqrt(s*s+a*a)/e.dmul}}_drawFillAndIsolines(){let{imageDataForFillCtx:e}=this,{canvasFillCtx:t}=this,r=new Uint32Array(e.data.buffer),{raw:o}=this.data[0],{clut:a,style:s}=this.layer,{levelIndex:i,colorsI:c}=a;if(s.fill!=="none")for(let f=0,l=0,d=259;f<256;++f,d+=2)for(let h=0;h<256;++h,++l,++d)r[l]=c[o[d]];else r.fill(0);let u=[];if(s.isolineColor!=="none"){let f=s.isolineColor[0]==="#"?T(s.isolineColor):0;for(let l=0,d=0;l<256;l+=1)for(let h=0;h<256;h+=1){let g=(l+1)*258+(h+1),m=o[g],x=o[g+1],p=o[g+258];if(!m||!x||!p)continue;let y=i[m],C=i[x],v=i[p];if(y!==C||y!==v){let L=Math.max(y,C,v),_=Math.max(m,x,p),D=l*256+h;switch(s.isolineColor){case"inverted":r[D]=~c[_]|4278190080;break;case"fill":r[D]=c[_]|4278190080;break;default:r[D]=f;break}s.isolineText&&!(++d%255)&&h>20&&h<235&&l>20&&l<235&&u.push({x:h,y:l,d:m,dr:x,db:p,mli:L})}}}if(t.putImageData(e,0,0),u.length){t.font="1.1em Sans-serif",t.lineWidth=2,t.strokeStyle="white",t.fillStyle="black",t.textAlign="center",t.textBaseline="middle";for(let{x:f,y:l,d,dr:h,db:g,mli:m}of u){let x=this.layer.clut.ticks[m].dataString,p=Math.atan2(d-h,g-d);t.save(),t.translate(f,l),t.rotate(p<-1.57||p>1.57?p+3.14:p),t.strokeText(x,0,0),t.fillText(x,0,0),t.restore()}}}_drawStreamLinesStatic(){if(!this.streamLines.length||!this.layer.style.streamLineStatic)return;let{canvasVectorAnimationCtx:e}=this;if(this.layer.style.streamLineColor==="none"){this.streamLines=[];return}e.lineWidth=2,e.strokeStyle=this.layer.style.streamLineColor,e.beginPath();for(let t=this.streamLines.length;t--;){let r=this.streamLines[t];for(let o=0;o<r.length-1;++o){let a=r[o],s=r[o+1];e.moveTo(a.x,a.y),e.lineTo(s.x,s.y)}}e.stroke()}_drawVectorsStatic(){let{clut:e,style:t}=this.layer;if(!this.layer.state.vector||!e.DataToKnots||t.vectorColor==="none"||t.vectorType==="none")return;if(this.data.length!==3)throw new Error("this.data.length !== 3");let[r,o,a]=this.data,{canvasVectorCtx:s}=this;switch(t.vectorType){case"barbs":s.font="40px barbs";break;case"arrows":s.font="50px arrows";break;default:s.font=t.vectorType}s.textAlign="center",s.textBaseline="middle";let i=t.addDegrees?.017453292519943*t.addDegrees:0,c=32;for(let u=c/2;u<256;u+=c)for(let f=c/2;f<256;f+=c){let l=f+1+(u+1)*258;if(!r.raw[l])continue;let d=Math.atan2(o.dmin+o.raw[l]*o.dmul,a.dmin+a.raw[l]*a.dmul),h=r.dmin+r.raw[l]*r.dmul,g=t.vectorType!=="barbs"?t.vectorFactor*.2:.2,m=Math.min(e.DataToKnots(h)*g,25)+65,x=String.fromCharCode(m);switch(t.vectorColor){case"inverted":s.fillStyle=w(~e.colorsI[r.raw[l]]);break;case"fill":s.fillStyle=w(e.colorsI[r.raw[l]]);break;default:s.fillStyle=t.vectorColor;break}s.save(),s.translate(f,u),s.rotate(d+i),s.fillText(x,0,0),s.restore()}}_drawDegreesStatic(){if(this.layer.state.units!=="degree")return;let{canvasVectorCtx:e}=this,t=.017453292519943*this.layer.style.addDegrees;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle";let r=this.data[0],o="L",a=32;for(let s=a/2;s<256;s+=a)for(let i=a/2;i<256;i+=a){let c=i+1+(s+1)*258;if(!r.raw[c])continue;let f=(r.dmin+r.raw[c]*r.dmul+180)*.01745329251;switch(this.layer.style.vectorColor){case"inverted":e.fillStyle=w(~this.layer.clut.colorsI[r.raw[c]]);break;case"fill":e.fillStyle=w(this.layer.clut.colorsI[r.raw[c]]);break;default:e.fillStyle=this.layer.style.vectorColor;break}e.save(),e.translate(i,s),e.rotate(f+t),e.fillText(o,0,0),e.restore()}}_createStreamLines(){if(this.data.length!==3)throw new Error("this.data.length !== 3");if(this.layer.style.streamLineColor==="none")return;let e=this.layer.style.streamLineSpeedFactor||1;this.streamLines=[];let[t,r,o]=this.data,a=Math.max(this.coords.z-this.layer.state.meta.maxZoom,0),s=Math.min(2**(a+5),128),i=~~(120+a*60);for(let c=0;c<=256;c+=s)for(let u=0;u<=256;u+=s){if(!t.raw[1+u+(1+c)*258])continue;let f=[],l=u,d=c;for(let h=0;h<=i&&l>=0&&l<=256&&d>=0&&d<=256;h++){!(h%(i/6))&&f.push({x:~~l,y:~~d});let g=~~l+1+(~~d+1)*258;if(!t.raw[g])break;l+=e*(r.dmin+r.raw[g]*r.dmul)/t.dmax,d-=e*(o.dmin+o.raw[g]*o.dmul)/t.dmax}l=u,d=c;for(let h=1;h<=i&&l>=0&&l<=256&&d>=0&&d<=256;h++){!(h%(i/6))&&f.unshift({x:~~l,y:~~d});let g=~~l+1+(~~d+1)*258;if(!t.raw[g])break;l-=e*(r.dmin+r.raw[g]*r.dmul)/t.dmax,d+=e*(o.dmin+o.raw[g]*o.dmul)/t.dmax}f.length>2&&this.streamLines.push(f)}}};var $;var k=class extends Me.default.GridLayer{constructor(e){super(e.options);this.styles=F();this.redrawRequestID=0;this.vectorAnimationRequestID=0;this.oldMaxZoom=0;this.style=Object.assign({},this.styles.base);this.clut=new q(this.style,"",[0,2],!1);this.animation=!0;let{dataSource:t,lazy:r}=e;if(b("Creating a WxTiles layer:",t.name,". Params:",JSON.stringify(e)),!(t==null?void 0:t.ext)||!t.dataset||!t.name||!t.serverURI||!t.styleName||!Array.isArray(t.variables)||t.variables.length<1||t.variables.length>2){let i="WxTilesLayer: dataSource is wrong!";throw b(i),new Error(i)}this.dataSource=t,this.state={originURI:t.serverURI+"/"+t.dataset+"/",units:"",baseURL:"",meta:{maxZoom:0,times:[],variables:[],variablesMeta:{}},instance:"",minmax:[[0,1]],currentTime:"",vector:t.variables.length>1},this.loadDataIntegralFunc=Z(t.requestInit),$||($=de(t.requestInit)),this.loadMaskFunc=$;let o=()=>{var i;((i=this._map)==null?void 0:i.getZoom())<this.state.meta.maxZoom&&this._stopLoadingResetLoadDataFunc()},a=()=>{if(b("onadd:",this.dataSource.name),!this._map)throw new Error("_map is not set!");this._map.on("zoomstart",o),this._checkAndStartVectorAnimation()},s=()=>{if(b("onremove:",this.dataSource.name),!this._map)throw new Error("_map is not set!");this._map.off("zoomstart",o),this._stopLoadingResetLoadDataFunc()};this.on("remove",s),this.on("add",a),this.setupCompletePromise=new Promise(i=>{let c=async()=>{b("Setup:",t.name),await this._setUpDataSet(),b("Setup complete: ",this.dataSource.name),i()};r?this.once("add",c):c()})}async _setUpDataSet(){let{state:e,dataSource:t}=this;try{e.instance=(await M(e.originURI+"instances.json")).pop()+"/"}catch(o){let a=t.name+": load instances.json error: "+o;throw b(a),new Error(a)}try{let o=e.originURI+e.instance+"meta.json";e.meta=await M(o)}catch(o){let a=t.name+": load meta.json error: "+o;throw b(a),new Error(a)}e.vector=t.variables.length===2;let{variablesMeta:r}=e.meta;if(e.units=r[t.variables[0]].units,e.minmax=t.variables.map(o=>[r[o].min,r[o].max]),e.vector){let[[o,a],[s,i]]=e.minmax;e.minmax.unshift([0,1.42*Math.max(-o,a,-s,i)])}this._setStyleAndCLUT(t.styleName),this._setTimeUrl(new Date)}async _requestReloadTilesAndRedraw(){let e=await this._requestReloadTiles();return e&&this._redrawTiles(),e}async _requestReloadTiles(){b(`_requestReloadTiles: start - ${this.dataSource.name}`);let{controller:e}=this.loadDataIntegralFunc.controllerHolder;return await Promise.allSettled(this._ForEachWxTile(t=>t.load())),b(`_requestReloadTiles: end - ${this.dataSource.name}, aborted: ${e.signal.aborted}`),!e.signal.aborted}async setStyle(e){b("setStyle(",e,") for ",this.dataSource.name),(e==="custom"||e!==this.dataSource.styleName)&&(this._setStyleAndCLUT(e),this._checkAndStartVectorAnimation(),await this._requestReloadTilesAndRedraw()),b("setStyle(",e,'): "'+this.dataSource.styleName+'" for '+this.dataSource.name+" complete.")}_setStyleAndCLUT(e){let{dataSource:t,styles:r,state:o}=this;t.styleName=e,e==="custom"&&(r.custom.parent&&r.custom.parent in r||(b(`cant find the parent style (${r.custom.parent}), 'base' is used`),r.custom.parent="base"),r.custom=Object.assign(Object.assign({},r[r.custom.parent]),r.custom)),e in r||(b(`cant find the style (${e}), 'base' is used`),e=t.styleName="base");try{this.style=Object.assign({},r[e]),this.style.streamLineColor=ye(this.style.streamLineColor),this.clut=new q(this.style,o.units,o.minmax[0],o.vector)}catch(a){let s="setStyle: impossible error in RawCLUT: "+a;throw b(s),new Error(s)}}createTile(e,t){return De({layer:this,coords:e,done:t})}getSetupCompletePromise(){return this.setupCompletePromise}getLayerInfoAtLatLon(e){if(!this._map)return;let t=this._map.getZoom(),r=this._map.project(e,t),o=r.divideBy(256).floor(),a=this._getCachedTile(o,t);if(!a)return;let s=r.subtract(o.multiplyBy(256)).floor(),i=a.getPixelInfo(s);if(!i)return;let{raw:c,data:u}=i,f=c.map(h=>this.clut.colorsI[h]),l=f.map(w),d=u.map(h=>this.clut.DataToStyle(h));return{wxtile:a,data:u,raw:c,rgba:f,hexColor:l,inStyleUnits:d,tilePoint:s,styleUnits:this.style.units,dataUnits:this.state.units}}getStyle(){return this.style}_getFirstNonEmptyTile(){for(let e in this._tiles){let{wxtile:t}=this._tiles[e].el;if(t==null?void 0:t.data.length)return t}}_setTimeUrl(e){let{dataSource:t,state:r}=this,o=ge(r.meta.times,e);return r.currentTime===o?(b("_setTimeUrl: the same time - skipped"),!1):(r.currentTime=o,r.baseURL=r.originURI+r.instance+`{var}/${r.currentTime}/{z}/{x}/{y}.${t.ext}`,b(`_setTimeUrl: ${o} for ${t.name} complete`),!0)}setTime(e){if(b("setTime: "+e+" for "+this.dataSource.name+" start"),!this._tiles)return b("setTime: no tiles - skipped"),Promise.resolve(!1);let{currentTime:t}=this.state;if(!this._setTimeUrl(e))return Promise.resolve(!1);this.loadDataIntegralFunc.abort();let r=this._requestReloadTiles();return r.then(o=>{if(!o){this.state.currentTime=t;return}let a=this._getFirstNonEmptyTile();if(a==null?void 0:a.data.length){let[s,i]=this.state.minmax[0],{dmin:c,dmax:u}=a.data[0];(Math.abs(c-s)>.01||Math.abs(u-i)>.01)&&(this.state.minmax=a.data.map(f=>[f.dmin,f.dmax]),this._setStyleAndCLUT(this.dataSource.styleName))}this._redrawTiles()}),r}getTime(){return this.state.currentTime}getTimes(){return b("getTimes"),this.state.meta.times}getLegendData(e){return b("getLegendData"),V(e,this.style)}setTimeAnimationMode(e=2){b("setTimeAnimationMode"),this.oldMaxZoom=this.state.meta.maxZoom;let t=this._map.getZoom(),o=(t<this.oldMaxZoom?t:this.oldMaxZoom)-e;this.state.meta.maxZoom=o<0?0:o}async unsetTimeAnimationMode(){return b("unsetTimeAnimationMode"),this.oldMaxZoom&&(this.state.meta.maxZoom=this.oldMaxZoom),this._requestReloadTilesAndRedraw()}getMinMax(){let[e,t]=this.state.minmax[0];return{min:e,max:t}}setAnimation(e){return b("setAnimation"),this.animation=e,this._checkAndStartVectorAnimation(),this.animation}_getCachedTile({x:e,y:t},r){var o,a;return(a=(o=this._tiles[`${e}:${t}:${r}`])==null?void 0:o.el)==null?void 0:a.wxtile}_ForEachWxTile(e){var r;let t=[];for(let o in this._tiles){let a=(r=this._tiles[o].el)==null?void 0:r.wxtile;a&&t.push(e(a))}return t}_stopLoadingResetLoadDataFunc(){this.loadDataIntegralFunc.abort(),this.loadDataIntegralFunc=Z()}_checkAndStartVectorAnimation(){if(this.vectorAnimationRequestID)return;let e=t=>{if(!this._map||!this.animation||!this.state.vector||this.style.streamLineStatic||this.style.streamLineColor==="none"){this._ForEachWxTile(r=>r.clearVectorAnimationCanvas()),this.vectorAnimationRequestID=0;return}this._ForEachWxTile(r=>r.drawVectorAnimationLinesStep(t)),this.vectorAnimationRequestID=requestAnimationFrame(e)};this.vectorAnimationRequestID=requestAnimationFrame(e)}_redrawTiles(){this.redrawRequestID||(b("_redrawTiles: start: "+this.dataSource.name),this.redrawRequestID=requestAnimationFrame(()=>{this._ForEachWxTile(e=>e.draw()),this.redrawRequestID=0,b("_redrawTiles: requestAnimationFrame: end: "+this.dataSource.name)}))}};function Re(n){return new k(n)}var X=class extends O.default.Control{constructor(e){super(e);this.URI=e.URI}onAdd(){let e=document.createElement("img");return e.src=this.URI,e.className="wxtiles-logo",e}};function st(n){return b("Add watermark:",JSON.stringify(n)),new X(n)}var J=class extends O.default.GridLayer{createTile(e){let t=document.createElement("div");return t.innerHTML=[e.x,e.y,e.z].join(", "),t.style.outline="1px solid red",t}};function it(){return b("Add WxDebugCoordsLayer:"),new J().setZIndex(1e3)}function lt(n,e){return O.default.layerGroup(n.map(Re),e)}return ct;})();
|
package/package.json
CHANGED
package/src_example/index.ts
CHANGED
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
Meta,
|
|
14
14
|
Legend,
|
|
15
15
|
ColorStylesStrict,
|
|
16
|
+
fetchJson,
|
|
17
|
+
WxTilesLayerSettings,
|
|
16
18
|
} from '../src/wxtiles';
|
|
17
19
|
import '../src/wxtiles.css';
|
|
18
20
|
|
|
@@ -22,12 +24,7 @@ let config: Config; // application config
|
|
|
22
24
|
let styles: ColorStylesStrict; // all available styles. Not every style is sutable for every layer.
|
|
23
25
|
let globalLayer: WxTilesLayer | undefined; // current layer
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
async function fetchJson(url: string) {
|
|
27
|
-
return (await fetch(url)).json();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function fillDataSets() {
|
|
27
|
+
async function fillDataSets(defaultDataset?: string, deafaultVariable?: string) {
|
|
31
28
|
let datasetsNames: string[];
|
|
32
29
|
|
|
33
30
|
try {
|
|
@@ -45,10 +42,12 @@ async function fillDataSets() {
|
|
|
45
42
|
selectDataSetEl.appendChild(opt);
|
|
46
43
|
}
|
|
47
44
|
|
|
48
|
-
|
|
45
|
+
defaultDataset && datasetsNames.find((n) => n === defaultDataset) && (selectDataSetEl.value = defaultDataset);
|
|
46
|
+
|
|
47
|
+
await fillVariables_selectDataSetEl_onchange(deafaultVariable);
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
async function fillVariables_selectDataSetEl_onchange() {
|
|
50
|
+
async function fillVariables_selectDataSetEl_onchange(defaultVariable?: string): Promise<void> {
|
|
52
51
|
const oldVariable = selectVariableEl.value;
|
|
53
52
|
selectVariableEl.innerHTML = '';
|
|
54
53
|
let meta: Meta;
|
|
@@ -76,11 +75,13 @@ async function fillVariables_selectDataSetEl_onchange() {
|
|
|
76
75
|
selectVariableEl.value = oldVariable;
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
|
|
78
|
+
defaultVariable && meta.variables.find((n) => n === defaultVariable) && (selectVariableEl.value = defaultVariable);
|
|
79
|
+
|
|
80
|
+
await loadVariable_selectVariableEl_onchange();
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
async function loadVariable_selectVariableEl_onchange() {
|
|
83
|
-
stopPlay();
|
|
83
|
+
async function loadVariable_selectVariableEl_onchange(): Promise<void> {
|
|
84
|
+
await stopPlay();
|
|
84
85
|
|
|
85
86
|
const variable = selectVariableEl.value;
|
|
86
87
|
const variables = [variable];
|
|
@@ -88,7 +89,7 @@ async function loadVariable_selectVariableEl_onchange() {
|
|
|
88
89
|
variables.push(variable.replace('eastward', 'northward'));
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
const layerSettings = {
|
|
92
|
+
const layerSettings: WxTilesLayerSettings = {
|
|
92
93
|
dataSource: {
|
|
93
94
|
serverURI: config.dataServer, // server to fetch data from
|
|
94
95
|
maskServerURI: config.dataServer.replace(/\/data\/?/i, '/mask/{z}/{x}/{y}'),
|
|
@@ -104,6 +105,7 @@ async function loadVariable_selectVariableEl_onchange() {
|
|
|
104
105
|
// the signal 'setupcomplete' is fired when loading is finished.
|
|
105
106
|
// useful when a big bunch of layers is used, so layers are not wasting memory and bandwidth.
|
|
106
107
|
// lazy: true,
|
|
108
|
+
// L.GridLayerOptions leaflet's options for the layer
|
|
107
109
|
options: {
|
|
108
110
|
opacity: 1,
|
|
109
111
|
},
|
|
@@ -112,18 +114,18 @@ async function loadVariable_selectVariableEl_onchange() {
|
|
|
112
114
|
// save in order to delete old layer
|
|
113
115
|
const oldLayer = globalLayer; // this is to store oldLayer in order a user change layers too fast.
|
|
114
116
|
globalLayer = CreateWxTilesLayer(layerSettings);
|
|
115
|
-
await globalLayer.getSetupCompletePromise(); // wait for meta info to be loaded. doesn't mean 'tiles are loaded' !!!
|
|
116
117
|
globalLayer.addTo(map);
|
|
117
|
-
|
|
118
|
+
oldLayer && globalLayer.once('load', () => layerControl.removeLayer(oldLayer.removeFrom(map))); // delete old layer
|
|
118
119
|
layerControl.addOverlay(globalLayer, layerSettings.dataSource.name);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
|
|
121
|
+
// IMPORTANT: wait for meta info to be loaded (doesn't mean 'tiles are loaded' !!!)
|
|
122
|
+
// 1. must be befor any other operation on the layer
|
|
123
|
+
// 2. must be after layer is added to the map
|
|
124
|
+
await globalLayer.getSetupCompletePromise();
|
|
125
|
+
|
|
125
126
|
fillTimes(globalLayer);
|
|
126
127
|
fillStyles(globalLayer);
|
|
128
|
+
await globalLayer.setTime(selectTimeEl.value !== '' ? selectTimeEl.value : new Date()); // try to preserve 'time' from current time of selectTimeEl
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
function fillTimes(layer: WxTilesLayer) {
|
|
@@ -140,27 +142,31 @@ function fillTimes(layer: WxTilesLayer) {
|
|
|
140
142
|
selectTimeEl.value = layer.getTime();
|
|
141
143
|
}
|
|
142
144
|
|
|
143
|
-
function startPlay() {
|
|
145
|
+
function startPlay(): void {
|
|
144
146
|
if (!globalLayer) return;
|
|
145
147
|
buttonPlayStopEl.textContent = 'stop';
|
|
146
148
|
globalLayer.setTimeAnimationMode(+inputCoarseLevelEl.value);
|
|
147
|
-
|
|
149
|
+
|
|
150
|
+
// function to be called every timestep
|
|
151
|
+
(async function nextTimeStep() {
|
|
148
152
|
if (!globalLayer) return;
|
|
149
153
|
if (buttonPlayStopEl.textContent === 'stop') {
|
|
150
154
|
const start = Date.now();
|
|
151
155
|
await globalLayer.setTime(selectTimeEl.value);
|
|
156
|
+
updateInfoPanel(undefined);
|
|
152
157
|
selectTimeEl.selectedIndex++;
|
|
153
158
|
selectTimeEl.selectedIndex %= selectTimeEl.length;
|
|
154
159
|
const dt = +inputAnimDelayEl.value - (Date.now() - start);
|
|
155
160
|
setTimeout(nextTimeStep, dt < 0 ? 0 : dt);
|
|
156
|
-
oldE && updateInfoPanel(oldE);
|
|
157
161
|
}
|
|
158
|
-
});
|
|
162
|
+
})();
|
|
159
163
|
}
|
|
160
164
|
|
|
161
|
-
function stopPlay() {
|
|
162
|
-
buttonPlayStopEl.textContent
|
|
163
|
-
|
|
165
|
+
async function stopPlay() {
|
|
166
|
+
if (buttonPlayStopEl.textContent !== 'play') {
|
|
167
|
+
buttonPlayStopEl.textContent = 'play';
|
|
168
|
+
return globalLayer?.unsetTimeAnimationMode();
|
|
169
|
+
}
|
|
164
170
|
}
|
|
165
171
|
|
|
166
172
|
function addOption(baseStyle: string, value = baseStyle) {
|
|
@@ -223,8 +229,7 @@ function onStyleChange_selectStyleEl_onchange() {
|
|
|
223
229
|
}
|
|
224
230
|
}
|
|
225
231
|
globalLayer.setStyle(selectStyleEl.value);
|
|
226
|
-
const
|
|
227
|
-
const curStyle = styles[curStyleName];
|
|
232
|
+
const curStyle = globalLayer.getStyle();
|
|
228
233
|
customStyleEl.value = JSON.stringify(JSONsort(curStyle), null, ' ');
|
|
229
234
|
const legend = globalLayer.getLegendData(legendCanvasEl.width - 50);
|
|
230
235
|
if (!legend) return;
|
|
@@ -293,8 +298,9 @@ function drawLegend({ legend, canvas }: { legend: Legend; canvas: HTMLCanvasElem
|
|
|
293
298
|
ctx.lineTo(tick.pos + trSize + startX + 1, halfHeight);
|
|
294
299
|
ctx.fillText(tick.dataString, tick.pos + trSize + startX + 1, halfHeight + 11);
|
|
295
300
|
}
|
|
301
|
+
|
|
296
302
|
ctx.font = '12px sans-serif';
|
|
297
|
-
const txt = globalLayer.
|
|
303
|
+
const txt = `${globalLayer.getStyle().name} (${legend.units})`;
|
|
298
304
|
ctx.fillText(txt, 13, height - 5);
|
|
299
305
|
ctx.stroke();
|
|
300
306
|
|
|
@@ -302,19 +308,21 @@ function drawLegend({ legend, canvas }: { legend: Legend; canvas: HTMLCanvasElem
|
|
|
302
308
|
ctx.strokeRect(1, 1, width - 3, height - 2); //for white background
|
|
303
309
|
}
|
|
304
310
|
|
|
305
|
-
let oldE: L.LeafletMouseEvent
|
|
306
|
-
function updateInfoPanel(e: L.LeafletMouseEvent) {
|
|
307
|
-
|
|
308
|
-
|
|
311
|
+
let oldE: L.LeafletMouseEvent;
|
|
312
|
+
function updateInfoPanel(e: L.LeafletMouseEvent | undefined) {
|
|
313
|
+
// save 'e'
|
|
314
|
+
if (e) oldE = e;
|
|
315
|
+
else e = oldE; // restore 'e'
|
|
316
|
+
let content = `${e.latlng}<br>`;
|
|
309
317
|
map.eachLayer((layer) => {
|
|
310
318
|
if (layer instanceof WxTilesLayer) {
|
|
311
|
-
const tile = layer.
|
|
319
|
+
const tile = layer.getLayerInfoAtLatLon(e!.latlng);
|
|
312
320
|
const { min, max } = layer.getMinMax();
|
|
313
|
-
|
|
321
|
+
const ltime = layer.getTime();
|
|
314
322
|
content += tile
|
|
315
323
|
? `<div>
|
|
316
324
|
<div style="width:1em;height:1em;float:left;margin-right:2px;background:${tile.hexColor}"></div>
|
|
317
|
-
${layer.dataSource.name}=${tile.inStyleUnits.toFixed(2)} ${tile.
|
|
325
|
+
${layer.dataSource.name}=${tile.inStyleUnits.map((d) => d.toFixed(2)).join(',')} ${tile.styleUnits} (${min.toFixed(2)}, ${max.toFixed(2)}), time: ${ltime}<br>
|
|
318
326
|
</div>`
|
|
319
327
|
: '';
|
|
320
328
|
}
|
|
@@ -327,13 +335,13 @@ function popupInfo(e: L.LeafletMouseEvent) {
|
|
|
327
335
|
let content = '';
|
|
328
336
|
map.eachLayer((layer) => {
|
|
329
337
|
if (layer instanceof WxTilesLayer) {
|
|
330
|
-
const tile = layer.
|
|
338
|
+
const tile = layer.getLayerInfoAtLatLon(e.latlng);
|
|
331
339
|
const time = layer.getTime();
|
|
332
340
|
content += tile
|
|
333
341
|
? `<div>
|
|
334
342
|
<div style="width:1em;height:1em;float:left;margin-right:2px;background:${tile.hexColor}"></div>
|
|
335
343
|
${layer.dataSource.name}<br>
|
|
336
|
-
(in style Units = ${tile.inStyleUnits} ${tile.
|
|
344
|
+
(in style Units = ${tile.inStyleUnits} ${tile.styleUnits})<br>
|
|
337
345
|
(in data Units = ${tile.data} ${layer.state.units})<br>
|
|
338
346
|
(time:${time})<br>
|
|
339
347
|
(instance:${layer.state.instance})<br>
|
|
@@ -429,7 +437,7 @@ async function start() {
|
|
|
429
437
|
|
|
430
438
|
styles = WxGetColorStyles(); // all available styles. Not every style is sutable for this layer.
|
|
431
439
|
|
|
432
|
-
fillDataSets();
|
|
440
|
+
fillDataSets('gfs.global', 'wind.speed.eastward.at-10m');
|
|
433
441
|
|
|
434
442
|
map.on('zoom', stopPlay); // stop time animation on zoom
|
|
435
443
|
map.on('mousemove', updateInfoPanel);
|
|
@@ -468,11 +476,14 @@ customStyleButtonEl.addEventListener('click', () => {
|
|
|
468
476
|
});
|
|
469
477
|
|
|
470
478
|
const selectTimeEl = document.getElementById('selectTime') as HTMLSelectElement;
|
|
471
|
-
selectTimeEl.addEventListener('change', () => {
|
|
479
|
+
selectTimeEl.addEventListener('change', async () => {
|
|
472
480
|
if (!globalLayer) return;
|
|
473
|
-
if (buttonPlayStopEl.textContent === 'stop') stopPlay();
|
|
474
|
-
|
|
481
|
+
if (buttonPlayStopEl.textContent === 'stop') await stopPlay();
|
|
482
|
+
selectTimeEl.style.backgroundColor = '#fa0';
|
|
483
|
+
await globalLayer.setTime(selectTimeEl.value);
|
|
484
|
+
selectTimeEl.style.backgroundColor = '#fff';
|
|
475
485
|
selectTimeEl.value = globalLayer.getTime();
|
|
486
|
+
updateInfoPanel(undefined);
|
|
476
487
|
});
|
|
477
488
|
|
|
478
489
|
const buttonHoldEl = document.getElementById('buttonHold') as HTMLButtonElement;
|