@metoceanapi/wxtiles-leaflet 2.1.3 → 2.3.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/GPLv3.txt +674 -0
- package/LICENSE.txt +12 -9
- package/README.md +10 -32
- package/dist/es/controls/WxAPIControl.d.ts +4 -2
- package/dist/es/controls/WxTimeControl .d.ts +1 -1
- package/dist/es/index.d.ts +13 -17
- package/dist/es/index.js +2 -2
- package/dist/es/utils/RawCLUT.d.ts +9 -8
- package/dist/es/utils/qtree.d.ts +6 -4
- package/dist/es/utils/wxtools.d.ts +16 -5
- package/dist/es/wxAPI/WxAPI.d.ts +63 -0
- package/dist/es/wxAPI/WxAPItypes.d.ts +152 -0
- package/dist/es/wxAPI/WxDataSetManager.d.ts +69 -92
- package/dist/es/wxlayer/WxImplementation.d.ts +36 -11
- package/dist/es/wxlayer/loader.d.ts +3 -3
- package/dist/es/wxlayer/loadertools.d.ts +1 -1
- package/dist/es/wxlayer/painter.d.ts +1 -1
- package/dist/es/wxlayer/wxlayer.d.ts +48 -26
- package/dist/es/wxsource/wxsource.d.ts +3 -1
- package/dist/es/wxsource/wxsourcetypes.d.ts +2 -1
- package/dist/web/index.js +2 -2
- package/docs/docs/assets/highlight.css +4 -4
- package/docs/docs/assets/search.js +1 -1
- package/docs/docs/classes/CustomWxTilesLayer.html +1 -1
- package/docs/docs/classes/DataIntegral.html +13 -13
- package/docs/docs/classes/Loader.html +17 -17
- package/docs/docs/classes/Painter.html +11 -11
- package/docs/docs/classes/QTree.html +63 -34
- package/docs/docs/classes/RawCLUT.html +8 -8
- package/docs/docs/classes/TilesCache.html +108 -0
- package/docs/docs/classes/WxAPI.html +31 -104
- package/docs/docs/classes/WxDataSetManager.html +118 -184
- package/docs/docs/classes/WxLayer.html +78 -60
- package/docs/docs/classes/WxLayerBaseImplementation.html +52 -43
- package/docs/docs/classes/WxTileSource.html +63 -47
- package/docs/docs/enums/TileType.html +4 -4
- package/docs/docs/functions/WXLOG.html +9 -7
- package/docs/docs/functions/WxCreateLegend.html +11 -9
- package/docs/docs/functions/WxGetColorSchemes.html +9 -7
- package/docs/docs/functions/WxGetColorStyles.html +9 -7
- package/docs/docs/functions/WxTilesLogging.html +9 -7
- package/docs/docs/index.html +21 -20
- package/docs/docs/interfaces/CachedUriLoaderPromiseFunc.html +106 -0
- package/docs/docs/interfaces/ColorStylesIncomplete.html +9 -7
- package/docs/docs/interfaces/Converter.html +5 -3
- package/docs/docs/interfaces/DataPicture.html +5 -5
- package/docs/docs/interfaces/FrameworkOptions.html +5 -4
- package/docs/docs/interfaces/IntegralPare.html +3 -3
- package/docs/docs/interfaces/SLinePoint.html +3 -3
- package/docs/docs/interfaces/Tree.html +2 -2
- package/docs/docs/interfaces/WxAPIOptions.html +17 -17
- package/docs/docs/interfaces/WxAllBoundariesMeta.html +4 -4
- package/docs/docs/interfaces/WxAllDatasetsShortMetas.html +120 -0
- package/docs/docs/interfaces/WxBoundaryMeta.html +5 -5
- package/docs/docs/interfaces/WxColorSchemes.html +9 -7
- package/docs/docs/interfaces/WxColorStyleStrict.html +45 -27
- package/docs/docs/interfaces/WxColorStyleWeak.html +47 -27
- package/docs/docs/interfaces/WxColorStylesStrict.html +2 -2
- package/docs/docs/interfaces/WxColorStylesWeakMixed.html +9 -7
- package/docs/docs/interfaces/WxData.html +3 -3
- package/docs/docs/interfaces/WxDataSetManagerOptions.html +12 -12
- package/docs/docs/interfaces/WxDatasetMeta.html +18 -9
- package/docs/docs/interfaces/WxDatasetShortMeta.html +5 -5
- package/docs/docs/interfaces/WxLayerAPI.html +92 -26
- package/docs/docs/interfaces/WxLayerBaseAPI.html +21 -21
- package/docs/docs/interfaces/WxLayerOptions.html +9 -10
- package/docs/docs/interfaces/WxLegend.html +7 -7
- package/docs/docs/interfaces/WxLngLat.html +3 -3
- package/docs/docs/interfaces/WxRasterData.html +6 -6
- package/docs/docs/interfaces/WxRequestInit.html +2 -2
- package/docs/docs/interfaces/WxSourceLayerOptions.html +8 -5
- package/docs/docs/interfaces/WxTick.html +5 -5
- package/docs/docs/interfaces/WxTileInfo.html +9 -9
- package/docs/docs/interfaces/WxUnits.html +9 -7
- package/docs/docs/interfaces/WxVariableMeta.html +6 -6
- package/docs/docs/interfaces/WxVariablesMetas.html +9 -7
- package/docs/docs/interfaces/XYZ.html +4 -4
- package/docs/docs/modules.html +17 -13
- package/docs/docs/types/DataIntegrals.html +9 -7
- package/docs/docs/types/DataPictures.html +9 -7
- package/docs/docs/types/{UriLoaderPromiseFunc.html → ListenerMethod.html} +21 -23
- package/docs/docs/types/SLine.html +9 -7
- package/docs/docs/types/SubTrees.html +9 -7
- package/docs/docs/types/SubTreesN.html +9 -7
- package/docs/docs/types/TreeN.html +9 -7
- package/docs/docs/types/WxDate.html +17 -8
- package/docs/docs/types/WxEventType.html +116 -0
- package/docs/docs/types/{WxVars.html → WxInstances.html} +13 -13
- package/docs/docs/types/WxLayerVarsNames.html +113 -0
- package/docs/docs/types/WxURIs.html +9 -7
- package/docs/docs/types/WxUnitTuple.html +9 -7
- package/docs/examples/interactive.html +84 -0
- package/docs/examples/seaMaskAndAnimatedBlur.html +31 -23
- package/docs/examples/simpleDemo.html +33 -22
- package/docs/script/script.css +1 -1
- package/docs/script/script.js +13 -9
- package/docs/server.py +11 -0
- package/package.json +1 -1
- package/src_example/frwrkdeps.ts +6 -3
- package/src_example/index.ts +31 -54
- package/src_example/start.ts +39 -21
- package/watch-public.mjs +1 -7
- package/dist/es/wxAPI/wxAPI.d.ts +0 -192
- package/docs/docs/classes/FrameworkParentClass.html +0 -98
- package/docs/docs/interfaces/WxDataSetsMetasJSON.html +0 -75
- package/docs/docs/interfaces/WxTilesLibOptions.html +0 -92
package/LICENSE.txt
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
WxTiles Leaflet - Weather Tiles
|
|
2
|
+
Copyright (C) 2022 Meteorological Service of New Zealand Limited
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU General Public License as published by
|
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
(at your option) any later version.
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
This program is distributed in the hope that it will be useful,
|
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
GNU General Public License for more details.
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Contact me if you need a different license.
|
|
14
|
+
You should have received a copy of the GNU General Public License
|
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
package/README.md
CHANGED
|
@@ -20,43 +20,21 @@ Usage and API documentation is mainly equal for both frameworks.
|
|
|
20
20
|
|
|
21
21
|
## Examples
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
import 'mapbox-gl/dist/mapbox-gl.css';
|
|
27
|
-
import mapboxgl from 'mapbox-gl';
|
|
28
|
-
import { WxAPI } from '@metoceanapi/wxtiles-mbox';
|
|
29
|
-
|
|
30
|
-
async func(){
|
|
31
|
-
// Get the API ready - should be ONE per application
|
|
32
|
-
// requestInit is used in every request to the server. Add your keys, credentials, mode, etc.
|
|
33
|
-
const wxapi = new WxAPI({ dataServerURL: 'https://tiles.metoceanapi.com/data/',
|
|
34
|
-
requestInit: { /* headers: new Headers([['x-api-key', 'key']]), */ } });
|
|
35
|
-
|
|
36
|
-
// Create a dataset manager (may be used for many variables-layers from this dataset)
|
|
37
|
-
const wxdatasetManager = await wxapi.createDatasetManager('gfs.global');
|
|
38
|
-
|
|
39
|
-
// Automatically gets a proper set of variable(s) from the dataset and composes northward or eastward components if needed
|
|
40
|
-
const variables = wxdatasetManager.checkCombineVariableIfVector('air.temperature.at-2m'); // 'wind.speed.eastward.at-10m' - Vector example
|
|
41
|
-
|
|
42
|
-
// create a Mapbox layer source
|
|
43
|
-
const mboxSourceOptions = { id: 'wxsource', attribution: 'WxTiles' };
|
|
44
|
-
const wxsource = new WxTileSource({ wxdatasetManager, variables }, mboxSourceOptions);
|
|
45
|
-
|
|
46
|
-
// add the layer to the map
|
|
47
|
-
const map = new mapboxgl.Map({ container: 'map', accessToken:'token', style: { version: 8, name: 'Empty', sources: {}, layers: [] } });
|
|
48
|
-
await map.once('load');
|
|
49
|
-
map.addSource(wxsource.id, wxsource);
|
|
50
|
-
map.addLayer({ id: 'wxlayer', type: 'raster', source: wxsource.id, paint: { 'raster-fade-duration': 0 /*NEDDED for animation*/ } });
|
|
51
|
-
}()
|
|
52
|
-
|
|
53
|
-
```
|
|
23
|
+
1. [SimpleDemo](https://metoceanapi.github.io/wxtiles-mbox/examples/simpleDemo.html).
|
|
24
|
+
2. [Animated blur parameter](https://metoceanapi.github.io/wxtiles-mbox/examples/seaMaskAndAnimatedBlur.html)
|
|
25
|
+
3. [Mouse Interaction](https://metoceanapi.github.io/wxtiles-mbox/examples/interactive.html)
|
|
54
26
|
|
|
55
27
|
### Leaflet
|
|
56
28
|
|
|
57
29
|
```ts
|
|
58
30
|
import 'leaflet/dist/leaflet.css';
|
|
59
|
-
import L from 'leaflet';
|
|
31
|
+
import L from 'leaflet';start();
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
start();
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
|
|
60
38
|
import { WxAPI } from '@metoceanapi/wxtiles-leaflet';
|
|
61
39
|
|
|
62
40
|
async func(){
|
|
@@ -2,10 +2,12 @@ import { WxAPI } from '../index';
|
|
|
2
2
|
export declare class WxAPIControl {
|
|
3
3
|
private readonly wxapi;
|
|
4
4
|
private readonly _div;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
readonly datasets: HTMLSelectElement;
|
|
6
|
+
readonly variables: HTMLSelectElement;
|
|
7
|
+
protected _busy: boolean;
|
|
7
8
|
onchange?: (dataset: string, variable: string, resetStyleAndFlyTo?: boolean) => Promise<void>;
|
|
8
9
|
constructor(wxapi: WxAPI, dataset?: string, variable?: string);
|
|
10
|
+
setBusy(b: boolean): void;
|
|
9
11
|
fillDatasets(dataset?: string, variable?: string): Promise<void>;
|
|
10
12
|
fillVariables(variable?: string): Promise<void>;
|
|
11
13
|
onAdd(): HTMLDivElement;
|
|
@@ -3,7 +3,7 @@ export declare class WxTimeControl {
|
|
|
3
3
|
readonly delay: number;
|
|
4
4
|
private wxsource?;
|
|
5
5
|
private readonly _div;
|
|
6
|
-
private readonly
|
|
6
|
+
private readonly buttonPlayStop;
|
|
7
7
|
private readonly timesEl;
|
|
8
8
|
onchange: (time: string) => void;
|
|
9
9
|
constructor(delay: number, wxsource?: WxTileSource | undefined);
|
package/dist/es/index.d.ts
CHANGED
|
@@ -2,35 +2,31 @@
|
|
|
2
2
|
* Main classes and interfaces to use in your application are:
|
|
3
3
|
* - {@link WxAPIOptions} options to pass to the constructor of {@link WxAPI}.
|
|
4
4
|
* - {@link WxAPI} the main class to use to interact with the *WxTiles* API and to create {@link WxDataSetManager} instances
|
|
5
|
+
* - {@link WxDataSetManagerOptions} options to pass to the constructor of {@link WxDataSetManager}.
|
|
5
6
|
* - {@link WxDataSetManager} class for managing WX datasets and create {@link WxTileSource}.
|
|
6
7
|
* * {@link FrameworkOptions} framework specific options to pass to the constructor of {@link WxTileSource}.
|
|
7
8
|
* - {@link WxLayerOptions} options to pass to the constructor of {@link WxTileSource}.
|
|
8
9
|
* - {@link WxTileSource} class for managing WX tiles sources.
|
|
9
10
|
* - {@link WxColorStyleWeak} interface for color styles.
|
|
10
11
|
* - {@link WxDate} type for dates.
|
|
11
|
-
* - {@link
|
|
12
|
-
* - {@link WxDatasetMeta} interface for dataset's meta data.
|
|
12
|
+
* - {@link WxDatasetMeta} interface for dataset's metadata.
|
|
13
13
|
* - {@link WxVariableMeta} interface for variable's meta data.
|
|
14
14
|
* - {@link WxAllBoundariesMeta} interface for boundaries of a dataset.
|
|
15
15
|
* - {@link WxTileInfo} interface for tile's information.
|
|
16
|
-
*
|
|
17
16
|
* ### Note
|
|
18
17
|
* In case of use **async** member functions, you must use the **await** syntax.
|
|
19
18
|
* @module
|
|
20
19
|
*/
|
|
21
|
-
export {
|
|
22
|
-
export
|
|
23
|
-
export {
|
|
20
|
+
export { Loader, type WxData, type SLine, type SLinePoint, } from './wxlayer/loader';
|
|
21
|
+
export { Painter, type WxRasterData, } from './wxlayer/painter';
|
|
22
|
+
export { QTree, type TileType, type Tree, type TreeN, type SubTrees, type SubTreesN, } from './utils/qtree';
|
|
23
|
+
export { WxAPI } from './wxAPI/WxAPI';
|
|
24
|
+
export { type WxInstances, type WxAPIOptions, type WxDatasetMeta, type WxVariableMeta, type WxVariablesMetas, type WxBoundaryMeta, type WxAllBoundariesMeta, type WxDatasetShortMeta, type WxAllDatasetsShortMetas, type WxSourceLayerOptions, type WxDataSetManagerOptions, } from './wxAPI/WxAPItypes';
|
|
25
|
+
export { WxDataSetManager } from './wxAPI/WxDataSetManager';
|
|
24
26
|
export { WxTileSource } from './wxsource/wxsource';
|
|
25
|
-
export { type FrameworkOptions
|
|
26
|
-
export type
|
|
27
|
-
export {
|
|
28
|
-
export type
|
|
29
|
-
export {
|
|
30
|
-
export { WxGetColorStyles, WxGetColorSchemes, WxTilesLogging, WXLOG } from './utils/wxtools';
|
|
31
|
-
export type { XYZ, WxUnits, WxUnitTuple, WxColorSchemes, WxColorStyleWeak, WxColorStyleStrict, WxColorStylesStrict, WxColorStylesWeakMixed, WxTilesLibOptions, ColorStylesIncomplete, Converter, IntegralPare, DataIntegral, DataIntegrals, DataPicture, DataPictures, UriLoaderPromiseFunc, } from './utils/wxtools';
|
|
32
|
-
export { Painter, type WxRasterData } from './wxlayer/painter';
|
|
33
|
-
export { Loader, type WxData, type SLine, type SLinePoint } from './wxlayer/loader';
|
|
34
|
-
export { QTree } from './utils/qtree';
|
|
35
|
-
export type { TileType, Tree, SubTrees, SubTreesN, TreeN } from './utils/qtree';
|
|
27
|
+
export { type FrameworkOptions } from './wxsource/wxsourcetypes';
|
|
28
|
+
export { WxLayer, type WxLayerOptions, type WxDate, type WxRequestInit, type WxTileInfo, type WxLayerVarsNames, type WxLngLat, type WxURIs, WxRasterDataCache as TilesCache, } from './wxlayer/wxlayer';
|
|
29
|
+
export { WxLayerBaseImplementation, type WxLayerAPI, type WxLayerBaseAPI, type ListenerMethod, type WxEventType, } from './wxlayer/WxImplementation';
|
|
30
|
+
export { WxCreateLegend, type WxLegend, type WxTick, type RawCLUT, } from './utils/RawCLUT';
|
|
31
|
+
export { WxGetColorStyles, WxGetColorSchemes, WxTilesLogging, WXLOG, type XYZ, type DataPicture, type DataPictures, DataIntegral, type DataIntegrals, type CachedUriLoaderPromiseFunc, type IntegralPare, type WxUnits, type WxUnitTuple, type WxColorSchemes, type WxColorStyleWeak, type WxColorStyleStrict, type WxColorStylesStrict, type WxColorStylesWeakMixed, type ColorStylesIncomplete, type Converter, } from './utils/wxtools';
|
|
36
32
|
export { CustomWxTilesLayer } from './customlayer/customlayer';
|
package/dist/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var Re=Object.create;var le=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var Ne=Object.getPrototypeOf,Ue=Object.prototype.hasOwnProperty;var Be=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports);var Ve=(a,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of $e(e))!Ue.call(a,n)&&n!==t&&le(a,n,{get:()=>e[n],enumerable:!(r=_e(e,n))||r.enumerable});return a};var Ze=(a,e,t)=>(t=a!=null?Re(Ne(a)):{},Ve(e||!a||!a.__esModule?le(t,"default",{value:a,enumerable:!0}):t,a));var ke=Be((Vt,Pe)=>{Pe.exports=window.L});var ce={comment1:["'degC': ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["'hPa': ['Pa', 1000]' -> hPa = Pa * 1000 + 0 (0 - could be ommited)",0],K:["K",1],kelvin:["K",1],F:["K",.5555555555,255.372222222],C:["K",1,273.15],degC:["K",1,273.15],"kg/m^2/s":["kg/m^2/s",1],"Kg/m^2/s":["kg/m^2/s",1],"Kg m**-2 s**-1":["kg/m^2/s",1],"Kg m^-2 s^-1":["kg/m^2/s",1],"Kg m^{-2} s^-1":["kg/m^2/s",1],"mm/h":["kg/m^2/s",.00027777777],"mm/hr":["kg/m^2/s",.00027777777],"W/m^2":["W/m^2",1],"W m^-2":["W/m^2",1],"W m^{-2}":["W/m^2",1],"W/m**2":["W/m^2",1],"W m**-2":["W/m^2",1],"m/s":["m/s",1],"m s**-1":["m/s",1],"m s^-1":["m/s",1],"m.s^{-1}":["m/s",1],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["m/s",.27777777777],"km h^-1":["m/s",.27777777777],"km h**-1":["m/s",.27777777777],mph:["m/s",.44704],"miles/h":["m/s",.44704],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],km:["m",1e3],mile:["m",1609.344],miles:["m",1609.344],inch:["m",.0254],Pa:["Pa",1],hPa:["Pa",100],degree:["degree",1],radian:["degree",57.3],"mg/m^3":["mg/m^3",1],"mg m^-3":["mg/m^3",1],"mg.m^-3":["mg/m^3",1],"%":["%",1],"(0 - 1)":["%",100]};var ue={none:["#00000000","#00000000"],divergingbluered:["#2166acff","#92c5deff","#f7f7f7ff","#f4a582ff","#b2182bff"],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 X={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"inverted",isolineText:!0,vectorType:"arrows",vectorColor:"inverted",vectorFactor:1,streamLineColor:"none",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"divergingbluered",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none",gl:{animationSpeed:1,noiseTexturePow:5,vectorFieldFactor:1,animationIntensity:5,wavesCount:4}},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 me,fe,de;function xe({colorStyles:a={},units:e={},colorSchemes:t={}}={}){u("WxTile lib setup: start"),me=Object.assign({},ce,e),fe=Object.assign({},t,ue);let r=Object.assign({},a,X);de=Fe(r),u("WxTile lib setup: styles unrolled");try{(async()=>(await document.fonts.load("32px barbs"),await document.fonts.load("32px arrows")))()}catch{u("WxTile lib setup: fonts not loaded")}u("WxTile lib setup is done.")}function A(){return de}function J(){return fe}function O(a,e,t){u("makeConverter: From=",a," To=",e);let r=d=>d;if(r.trivial=!0,a===e)return u("Trivial converter"),r;let n=Object.assign({},me,t),s=n[a],i=n[e];if(!s||!i)return u("Inconvertible units. Trivial converter"),r;let[o,m,c]=s,[l,f,x]=i;if(o!==l||!m||!f)return u("Inconvertible units. Trivial converter"),r;let h=m/f,g=((c||0)-(x||0))/f;return g?d=>h*d+g:d=>h*d}function Fe(a){let e=Object.assign({},X);for(let s in a){let i=a[s];if(Array.isArray(i))for(let o=0;o<i.length;++o)e[s+"["+o+"]"]=Object.assign({},i[o]);else e[s]=Object.assign({},i)}let t=Object.assign({},X.base),r=(s,i)=>{if(i==="base")return t;let o=s[i];if(!o)return t;(!o.parent||!(o.parent in s))&&(o.parent="base");let m=r(s,o.parent);return Object.assign(o,Object.assign({},m,o,{parent:"base"}))},n={base:t};for(let s in e)n[s]=r(e,s);return n}function R(a){let e=new Map;return(t,...r)=>{let n=e.get(t);if(n)return n;let s=a(t,...r);return e.set(t,s),s.catch(i=>i.name==="AbortError"&&e.delete(t)),s}}async function Xe(a,e){let t=await fetch(a,e),r=await t.blob();if(!t.ok){let n=t.headers.get("x-reason");throw console.log(n),{name:"Tile loading failed",reason:n}}return await createImageBitmap(r,{premultiplyAlpha:"none"})}var H=class{constructor(e,t,r,n){this.raw=e;this.dmin=t;this.dmax=r;this.dmul=n;this.radius=0}get integral(){return this.integral_||(this.integral_=Ee(this.raw))}};function k(a,e,t=!0){let r=Object.assign(document.createElement("canvas"),{width:a,height:e,imageSmoothingEnabled:!1}).getContext("2d",{willReadFrequently:t});if(!r)throw new Error("Cannot get canvas context");return r}function Oe(a){let{width:e,height:t}=a,r=k(e,t);return r.drawImage(a,0,0),r.getImageData(0,0,e,t)}async function Q(a,e){return Oe(await Xe(a,e))}function qe(a){a.data[34]<1&&u("Warning: image is in too old format. Check the version of the Splitter.");let e=new Uint16Array(a.data.buffer),t=new Uint16Array(e.length/2);for(let m=0;m<t.length;m++)t[m]=e[m*2];let r=new Uint8Array(8);for(let m=0;m<8;++m)r[m]=a.data[m*4+2];let n=new DataView(r.buffer),s=n.getFloat32(0,!0),i=n.getFloat32(4,!0),o=(i-s)/65535;return new H(t,s,i,o)}async function ee(a,e){return qe(await Q(a,e))}function Ee(a){let e=new Uint32Array(66564),t=new Uint32Array(258*258);e[0]=a[0],t[0]=a[0]?1:0;for(let r=1;r<258;++r){e[r]=a[r]+e[r-1],t[r]=(a[r]?1:0)+t[r-1];let n=258*r;e[n]=a[n]+e[n-258],t[n]=(a[n]?1:0)+t[n-258]}for(let r=1;r<258;++r)for(let n=1;n<258;++n){let s=258*r+n;e[s]=a[s]+e[s-258]+e[s-1]-e[s-259],t[s]=(a[s]?1:0)+t[s-258]+t[s-1]-t[s-259]}return{integral:e,integralNZ:t[66563]===66564?null:t}}function Ye(a){let{integral:e}=a.integral;a.raw[0]=e[0];for(let t=1;t<258;t++){a.raw[t]=e[t]-e[t-1],a.raw[258*t]=e[258*t]-e[258*(t-1)];for(let r=1;r<258;r++){let n=258*t+r;a.raw[n]=e[n-259]+e[n]-e[n-258]-e[n-1]}}return a}function ge(a,e){if(e<0&&(e=0),e===a.radius)return a;if(a.radius=e,!e)return Ye(a);let{integral:t,integralNZ:r}=a.integral;for(let n=2;n<256;n++)for(let s=2;s<256;s++){let i=258*n+s;if(!a.raw[i])continue;let o=Math.min(e,s-1,256-s),m=Math.min(e,n-1,256-n),c=258*(n-m-1)+s,l=258*(n+m)+s,f;if(r){let W=r[c-o-1],y=r[c+o],b=r[l-o-1],S=r[l+o];f=W+S-y-b}else f=(2*o+1)*(2*m+1);let x=t[c-o-1],h=t[c+o],g=t[l-o-1],d=t[l+o],p=x+d-h-g;a.raw[i]=p/f}for(let n=2;n<256;n++){let s=258+n;if(a.raw[s]){let c=n,l=Math.min(e,c-1,256-c),f=258+c,x;if(r){let M=r[f-l-1];x=0+r[f+l]-0-M}else x=(2*l+1)*2;let h=0,g=0,d=t[f-l-1],p=t[f+l],y=(h+p-g-d)/x;a.raw[s-258]=y,a.raw[s]=y}let i=258*256+n;if(a.raw[i]){let c=n,l=Math.min(e,c-1,256-c),f=258*255+c,x=258*257+c,h=t[f-l-1],g=t[f+l],d=t[x-l-1],p=t[x+l],W=h+p-g-d,y;if(r){let S=r[f-l-1],M=r[f+l],w=r[x-l-1],D=r[x+l];y=S+D-M-w}else y=(2*l+1)*2;let b=W/y;a.raw[i]=b,a.raw[i+258]=b}let o=258*n+1;if(a.raw[o]){let c=n,l=Math.min(e,c-1,256-c),f=258*(c-l-1)+1,x=258*(c+l)+1,h;if(r){let M=r[f],w=0;h=0+r[x]-M-w}else h=(2*l+1)*2;let g=0,d=t[f],p=0,W=t[x],b=(g+W-d-p)/h;a.raw[o-1]=b,a.raw[o]=b}let m=258*n+256;if(a.raw[m]){let c=n,l=Math.min(e,c-1,256-c),f=258*(c-l-1)+256,x=258*(c+l)+256,h;if(r){let S=r[f-1],M=r[f+1],w=r[x-1],D=r[x+1];h=S+D-M-w}else h=2*(2*l+1);let g=t[f-1],d=t[f+1],p=t[x-1],W=t[x+1],b=(g+W-d-p)/h;a.raw[m]=b,a.raw[m+1]=b}}return a}function C(a){let e=a>>0&255,t=a>>8&255,r=a>>16&255,n=e.toString(16),s=t.toString(16),i=r.toString(16);return n=n.length===2?n:"0"+n,s=s.length===2?s:"0"+s,i=i.length===2?i:"0"+i,"#"+n+s+i}function T(a){if(a[0]==="#"){if(a.length===4)return+("0xff"+a[3]+a[3]+a[2]+a[2]+a[1]+a[1]);if(a.length===7)return+("0xff"+a[5]+a[6]+a[3]+a[4]+a[1]+a[2]);if(a.length===9)return+("0x"+a[7]+a[8]+a[5]+a[6]+a[3]+a[4]+a[1]+a[2])}return u("wrong color format",a),0}async function P(a,e){let t=await fetch(a,e);if(!t.ok)throw new Error("error:"+a+" - "+t.statusText);return t.json()}function te(a,e,t){let r=a>>0&255,n=a>>8&255,s=a>>16&255,i=a>>>24,o=e>>0&255,m=e>>8&255,c=e>>16&255,l=e>>>24,f=r+t*(o-r),x=n+t*(m-n),h=s+t*(c-s),g=i+t*(l-i);return f|x<<8|h<<16|g<<24}function he(a,e,t){let r=[];for(let n=0;n<t;++n)r.push(n*(e-a)/(t-1)+a);return r}var K=!1,u=(...a)=>{};function je(a){K=!!a,console.log("WXLOGing",K),u=typeof a=="function"?a:K?console.log:()=>{}}function re(a){return a[0]==="#"&&a.length===4?"#"+a[1]+a[1]+a[2]+a[2]+a[3]+a[3]:a}function q(a,{x:e,y:t,z:r}){return a.replace("{x}",`${e}`).replace("{y}",`${t}`).replace("{z}",`${r}`)}function E({x:a,y:e,z:t}){return`${t}-${a}-${e}`}var Ge="A".charCodeAt(0);var _=class{constructor(){this.qtree={nodes:null};this.qtreedepth=0;u("QTree.constructor")}async load(e,t){try{let r=await P(e,t);this.qtree=pe(r,{pos:0})}catch(r){throw new Error(`Failed to load QTree: ${r.message}`)}this.qtreedepth=be(this.qtree),u(`QTree.load: qtreedepth=${this.qtreedepth}`)}check(e){let t=e.z-this.qtreedepth,r=t>=0,n=r?{x:e.x>>t,y:e.y>>t,z:this.qtreedepth}:{...e};return ye(this.qtree,n,r)}};function pe(a,e){let t=a.charCodeAt(e.pos)-Ge;e.pos++;let r=[1,2,4,8].map(n=>t&n?pe(a,e):null);return{nodes:r.some(n=>n)?r:null}}function be(a){return a?.nodes?1+Math.max(...a.nodes.map(be)):0}function ye(a,e,t){return a===null?"land":t&&!e.z?"mixed":a.nodes===null?"sea":e.z?(e.z--,ye(a.nodes[(e.y>>e.z&1)<<1|e.x>>e.z&1],e,t)):"mixed"}function ze(a,e,t){return a>t?t:a<e?e:a}var $=class{constructor(e,t,[r,n],s){u("RawCLUT.constructor");let i=n-r;this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let o=[];this.DataToStyle=O(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),s&&(this.DataToKnots=O(t,"knot"));let m=O(e.units,t,e.extraUnits),c=d=>~~(65535*ze((m(d)-r)/(n-r),0,1));if(Array.isArray(e.colorMap)){e.colorMap.sort((d,p)=>d[0]<p[0]?-1:d[0]>p[0]?1:0);for(let[d]of e.colorMap)o.push(c(d))}else{if(e.levels||(e.levels=he(this.DataToStyle(r),this.DataToStyle(n),10)),e.levels.sort((d,p)=>d<p?-1:d>p?1:0),!e.colors){let d=J();e.colorScheme&&e.colorScheme in d?e.colors=d[e.colorScheme]:e.colors=d.wb}for(let d of e.levels)o.push(c(d))}let l=65536,f=we(l,e);this.ticks=f.ticks;let x=f.ticks[0].data,g=f.ticks[f.ticks.length-1].data-x;for(let d=0;d<65536;++d){let p=i*d/65535+r,W=this.DataToStyle(p),y=Math.round((l-1)*(W-x)/g);y<=0?this.colorsI[d]=e.showBelowMin?f.colors[0]:0:y>=l?this.colorsI[d]=e.showAboveMax?f.colors[l-1]:0:this.colorsI[d]=f.colors[y]}this.colorsI[0]=0;for(let d=0;d<o[0];++d)this.levelIndex[d]=0;for(let d=0;d<o.length-1;d++)for(let p=o[d];p<o[d+1]+1;++p)this.levelIndex[p]=d;for(let d=o[o.length-1];d<65536;++d)this.levelIndex[d]=o.length-1}};function We(a){if(a!==0&&-.1<a&&a<.1)return a.toExponential(2);let e=a.toString();return e.split(".")[1]?.length>2?a.toFixed(2):e}function we(a,e){let t={size:a,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(a),ticks:[]},{colorMap:r,levels:n,colors:s}=e,i=e.fill!=="solid";if(r){let x=r[0][0],h=r[r.length-1][0]-x;for(let[g,d]of r){let p=~~((g-x)/h*(a-1)),W={data:g,dataString:We(g),color:d,pos:p};t.ticks.push(W)}for(let g=0;g<r.length-1;g++){let d=t.ticks[g].pos,p=t.ticks[g+1].pos,W=T(r[g][1]),y=i?T(r[g+1][1]):0;for(let b=d;b<p;++b)t.colors[b]=i?te(W,y,(b-d)/(p-d)):W}return t.colors[a-1]=T(r[r.length-1][1]),t}if(!s||!n)return t;let o=0,m=0,c=-1;for(let x=0;x<a;++x){let h=x*(s.length-1)/a;c!==~~h&&(c=~~h,o=T(s[c]),m=s.length>c+1?T(s[c+1]):o),t.colors[x]=i?te(o,m,h-c):o}t.colors[a-1]=T(s[s.length-1]);let l=n[0],f=(a-1)/(n[n.length-1]-l);for(let x of n){let h=~~((x-l)*f),g={data:x,dataString:We(x),color:C(t.colors[h]),pos:h};t.ticks.push(g)}return t}var Ke=2*Math.PI*6378137/256,Y=2*Math.PI*6378137/2;function He(a,e){let t=a/Y*180,r=e/Y*180;return r=180/Math.PI*(2*Math.atan(Math.exp(r*Math.PI/180))-Math.PI/2),[r,t]}function Je(a,e,t){let r=Qe(t),n=a*r-Y,s=e*r-Y;return[n,s]}function Qe(a){return Ke/2**a}function ae(a,e,t){let[r,n]=He(...Je(a,e,t));return[n,-r]}function Se(a,e){return[a*256,e*256]}function ne(a,e,t){let r=((e-a)%360+540)%360-180;return(a+r*t+360)%360}function et(a,e,t,r,n,s,i,o){switch((a?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 0:return 0;case 1:return a;case 2:return e;case 3:t=a,r=e;break;case 4:return t;case 5:e=a,r=t;break;case 6:r=e+t>>1,a=r;break;case 7:r=e+t>>1;break;case 8:return r;case 9:e=a+r>>1,t=e;break;case 10:a=e,t=r;break;case 11:t=a+r>>1;break;case 12:a=t,e=r;break;case 13:e=a+r>>1;break;case 14:a=e+t>>1;break}a=i+o*a,e=i+o*e,t=i+o*t,r=i+o*r;let c=ne(a,e,n),l=ne(t,r,n),f=(ne(c,l,s)-i)/o;return f<1?1:f}function Me(a,e,t,r,n,s,i,o){switch((a?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 7:return n+s<1?n*(e-a)+s*(t-a)+a:0;case 14:return n+s<1?0:n*(r-t)+s*(r-e)+e+t-r;case 11:return s<n?(1-n)*(a-e)+s*(r-e)+e:0;case 13:return s<n?0:(1-n)*(t-r)+s*(t-a)+a+r-t;case 15:return n+s<1?n*(e-a)+s*(t-a)+a:n*(r-t)+s*(r-e)+e+t-r;default:return 0}}function De(a,e,t){let r=1/2**t.z,n=t.x*256*r-.5,s=t.y*256*r-.5,{raw:i,dmin:o,dmax:m,dmul:c}=e,l={raw:new Uint16Array(258*258),dmin:o,dmax:m,dmul:c},{raw:f}=l;for(let x=-1,h=0,g=s-r+1;x<=256;x++,g+=r){let d=Math.floor(g),p=g-d,W=d*258;for(let y=-1,b=n-r+1;y<=256;y++,h++,b+=r){let S=Math.floor(b),M=b-S,w=S+W,D=i[w],I=i[w+1],L=i[w+258],v=i[w+258+1];f[h]=a(D,I,L,v,M,p,o,c)}}return l}function Ce(a,e,t){if(!e)return a;let r=l=>l<0?0:l>254?254:l,n=1/2**e.z,s=e.x*256*n-.5,i=e.y*256*n-.5,{data:o}=a,m=new ImageData(256,256),{data:c}=m;for(let l=0,f=t,x=i;l<256;l++,x+=n){let h=~~r(x),g=x-h,d=h*256;for(let p=0,W=s;p<256;p++,f+=4,W+=n){let y=~~r(W),b=W-y,S=(y+d)*4+t,M=o[S],w=o[S+4],D=o[S+4*256],I=o[S+4*256+4],L=Me(M,w,D,I,b,g,0,0);c[f]=L>127?255:0}}return m}function Te(a,e){return e?De(Me,a,e):a}function Ie(a,e){return e?De(et,a,e):a}function Le(a,{data:e},t,r){let n=r==="sea",{raw:s}=a;for(let i=t,o=259,m=0;m<256;o+=2,m++)for(let c=0;c<256;c++,o++,i+=4)n===!e[i]&&(s[o]=0);return a}function ve(a){let[e,t]=Se(a.x,a.y),[r,n]=ae(e,t,a.z),[s,i]=ae(e+256,t+256,a.z);return{west:r,north:n,east:s,south:i}}function se(a,e){let t=a.z-e;if(t<=0)return{upCoords:a};let r={x:a.x>>>t,y:a.y>>>t,z:e},n={x:a.x&(1<<t)-1,y:a.y&(1<<t)-1,z:t};return{upCoords:r,subCoords:n}}var N=class{constructor(e){this.loadDataFunc=R(ee);this.layer=e}async load(e,t){let r=await this.cacheLoad(e,this.layer.tilesURIs,t);if(!r)return null;let{rawdata:n,subCoords:s,tileType:i}=r,{units:o}=this.layer.currentVariableMeta,m=o==="degree"?Ie:Te,c=f=>m(ge(f,this.layer.style.blurRadius),s),l=n.map(c);return this._vectorMagnitudesPrepare(l),await this._applyMask(l,e,i,!s&&n.length===1),{data:l,slines:this._createStreamLines(l)}}async cacheLoad(e,t,r){if(!this._checkInsideBoundaries(e))return null;let n=this._checkTypeAndMask(e);if(!n)return null;let{upCoords:s,subCoords:i}=se(e,this.layer.getCoarseMaxZoom()),o=t.map(l=>q(l,s)),m=Object.assign({},this.layer.wxdatasetManager.wxAPI.requestInit,{signal:r?.signal});return{rawdata:await Promise.all(o.map(l=>this.loadDataFunc(l,m))),subCoords:i,tileType:n}}clearCache(){this.loadDataFunc=R(ee)}async _applyMask(e,t,r,n){let{style:s}=this.layer;if((s.mask==="land"||s.mask==="sea")&&r==="mixed"){if(n){let{raw:m,dmin:c,dmax:l,dmul:f}=e[0];e[0]={raw:new Uint16Array(m),dmin:c,dmax:l,dmul:f}}let i,{wxAPI:o}=this.layer.wxdatasetManager;try{let{upCoords:m,subCoords:c}=se(t,o.maskDepth);i=await o.loadMaskFunc(m),i=Ce(i,c,o.maskChannel)}catch{s.mask=void 0,u("Can't load Mask. Masking is disabled");return}Le(e[0],i,o.maskChannel,s.mask)}}_vectorMagnitudesPrepare(e){if(e.length===1)return;e.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[t,r,n]=e;t.dmax=1.42*Math.max(-r.dmin,r.dmax,-n.dmin,n.dmax),t.dmul=(t.dmax-t.dmin)/65535;for(let s=0;s<258*258;++s){if(!r.raw[s]||!n.raw[s])continue;let i=r.dmin+r.dmul*r.raw[s],o=n.dmin+n.dmul*n.raw[s];t.raw[s]=Math.sqrt(o*o+i*i)/t.dmul}}_checkTypeAndMask(e){let{mask:t}=this.layer.style;if(t==="land"||t==="sea"){let r=this.layer.wxdatasetManager.wxAPI.qtree.check(e);return t===r?void 0:r}return"mixed"}_checkInsideBoundaries(e){let t=this.layer.getBoundaries();if(t?.boundaries180){let r=ve(e),n=s=>!(r.west>s.east||s.west>r.east||r.south>s.north||s.south>r.north);if(!t.boundaries180.some(n))return!1}return!0}_createStreamLines(e){if(e.length!==3)return[];let{style:t}=this.layer;if(t.streamLineColor==="none")return[];let r=[],[n,s,i]=e,o=(t.streamLineSpeedFactor||1)/n.dmax,m=t.addDegrees?.017453292519943*t.addDegrees:0,c=t.streamLineGridStep||64,l=t.streamLineSteps||300;for(let f=0;f<=256;f+=c)for(let x=0;x<=256;x+=c){if(!n.raw[1+x+(1+f)*258])continue;let h=[],g=x,d=f,p=-1,W=0,y=0;for(let M=0;M<=l&&g>=0&&g<=256&&d>=0&&d<=256;M++){M%(l/10)||h.push({x:~~g,y:~~d});let w=~~g+1+(~~d+1)*258;if(w!==p){if(!n.raw[w])break;p=w;let D=n.dmin+n.raw[w]*n.dmul,I=s.dmin+s.raw[w]*s.dmul,L=i.dmin+i.raw[w]*i.dmul,v=Math.atan2(I,L)+m;W=o*D*Math.sin(v),y=o*D*Math.cos(v)}g+=W,d-=y}let b=x,S=f;p=-1;for(let M=1;M<=l&&b>=0&&b<=256&&S>=0&&S<=256;M++){M%(l/10)||h.unshift({x:~~b,y:~~S});let w=~~b+1+(~~S+1)*258;if(w!==p){if(!n.raw[w])break;p=w;let D=n.dmin+n.raw[w]*n.dmul,I=s.dmin+s.raw[w]*s.dmul,L=i.dmin+i.raw[w]*i.dmul,v=Math.atan2(I,L)+m;W=o*D*Math.sin(v),y=o*D*Math.cos(v)}b-=W,S+=y}h.length>2&&r.push(h)}return r}};var U=class{constructor(e){this.layer=e}paint({data:e,ctxFill:t,ctxText:r,ctxStreamLines:n}){let{layer:s}=this,{units:i}=s.currentVariableMeta,o=new ImageData(256,256),m=new Uint32Array(o.data.buffer);t.clearRect(0,0,256,256),r.clearRect(0,0,256,256),n.clearRect(0,0,256,256),tt(e.data[0],m,s);let c=rt(m,e.data[0],s);t.putImageData(o,0,0),at(c,r,s),nt(e.data,r,s),st(e.data[0],r,i,s),ot(e,r,s)}getPaintedCanvas(e,t,r){return t?(this.imprintVectorAnimationLinesStep(e,r),e.ctxStreamLines.canvas):e.ctxFill.canvas}imprintVectorAnimationLinesStep({data:e,ctxFill:t,ctxStreamLines:r},n){let{layer:s}=this;r.clearRect(0,0,256,256),r.drawImage(t.canvas,0,0),!(e.slines.length===0||s.style.streamLineStatic||s.style.streamLineColor==="none")&&it(e,r,s,n)}};function tt(a,e,{CLUT:t,style:r}){let{raw:n}=a,{colorsI:s}=t;if(r.fill!=="none")for(let i=0,o=0,m=259;i<256;++i,m+=2)for(let c=0;c<256;++c,++o,++m)e[o]=s[n[m]];else e.fill(0)}function rt(a,e,{CLUT:t,style:r}){let{raw:n}=e,{levelIndex:s,colorsI:i}=t,o=[];if(r.isolineColor!=="none"){let m=r.isolineColor[0]==="#"?T(r.isolineColor):0;for(let c=0,l=0;c<256;c+=1)for(let f=0;f<256;f+=1){let x=(c+1)*258+(f+1),h=n[x],g=n[x+1],d=n[x+258];if(!h||!g||!d)continue;let p=s[h],W=s[g],y=s[d];if(p!==W||p!==y){let b=Math.max(p,W,y),S=Math.max(h,g,d),M=c*256+f;switch(r.isolineColor){case"inverted":a[M]=~i[S]|4278190080;break;case"fill":a[M]=i[S]|4278190080;break;default:a[M]=m;break}r.isolineText&&!(++l%255)&&f>20&&f<235&&c>20&&c<235&&o.push({x:f,y:c,d:h,dr:g,db:d,mli:b})}}}return o}function at(a,e,{CLUT:t}){if(a.length){e.font="1.1em Sans-serif",e.lineWidth=2,e.strokeStyle="white",e.fillStyle="black",e.textAlign="center",e.textBaseline="middle";for(let{x:r,y:n,d:s,dr:i,db:o,mli:m}of a){let c=t.ticks[m].dataString,l=Math.atan2(s-i,o-s);e.save(),e.translate(r,n),e.rotate(l<-1.57||l>1.57?l+3.14:l),e.strokeText(c,0,0),e.fillText(c,0,0),e.restore()}}}function nt(a,e,{CLUT:t,style:r}){if(!t.DataToKnots||r.vectorColor==="none"||r.vectorType==="none")return;if(a.length!==3)throw new Error("data.length !== 3");let[n,s,i]=a;switch(r.vectorType){case"barbs":e.font="40px barbs";break;case"arrows":e.font="50px arrows";break;default:e.font=r.vectorType}e.textAlign="center",e.textBaseline="middle",e.fillStyle=r.vectorColor;let o=r.addDegrees?.017453292519943*r.addDegrees:0,m=32;for(let c=m/2;c<256;c+=m)for(let l=m/2;l<256;l+=m){let f=l+1+(c+1)*258;if(!n.raw[f])continue;let x=Math.atan2(s.dmin+s.raw[f]*s.dmul,i.dmin+i.raw[f]*i.dmul),h=n.dmin+n.raw[f]*n.dmul,g=r.vectorType!=="barbs"?r.vectorFactor*.5:.2,d=Math.min(~~(t.DataToKnots(h)*g),25)+65,p=String.fromCharCode(d);switch(r.vectorColor){case"inverted":e.fillStyle=C(~t.colorsI[n.raw[f]]);break;case"fill":e.fillStyle=C(t.colorsI[n.raw[f]]);break}e.save(),e.translate(l,c),e.rotate(x+o),e.fillText(p,0,0),e.restore()}}function st(a,e,t,{CLUT:r,style:n}){if(t!=="degree")return;let s=.017453292519943*n.addDegrees;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle",e.fillStyle=n.vectorColor;let i="L",o=32;for(let m=o/2;m<256;m+=o)for(let c=o/2;c<256;c+=o){let l=c+1+(m+1)*258;if(!a.raw[l])continue;let x=(a.dmin+a.raw[l]*a.dmul+180)*.01745329251;switch(n.vectorColor){case"inverted":e.fillStyle=C(~r.colorsI[a.raw[l]]);break;case"fill":e.fillStyle=C(r.colorsI[a.raw[l]]);break}e.save(),e.translate(c,m),e.rotate(x+s),e.fillText(i,0,0),e.restore()}}function ot(a,e,{CLUT:t,style:r}){let{data:n,slines:s}=a;if(!s.length||!r.streamLineStatic||r.streamLineColor==="none")return;let i=n[0];e.lineWidth=1,r.streamLineColor[0]==="#"&&(e.strokeStyle=re(r.streamLineColor));for(let o=s.length;o--;){let m=s[o];for(let c=0;c<m.length-1;++c){let l=m[c],f=m[c+1],x=l.x+1+(l.y+1)*258;switch(r.streamLineColor){case"inverted":e.strokeStyle=C(~t.colorsI[i.raw[x]]);break;case"fill":e.strokeStyle=C(t.colorsI[i.raw[x]]);break}e.beginPath(),e.moveTo(l.x,l.y),e.lineTo(f.x,f.y),e.stroke()}}}function it(a,e,{CLUT:t,style:r},n){let{data:s,slines:i}=a,o=s[0],m=r.streamLineColor[0]==="#"?re(r.streamLineColor).substring(0,7):"#000000";n=n>>5;for(let c=0;c<i.length;++c){let l=i[c],f=l.length-1,x=(n+(1+l[0].x)*(1+l[0].y))%30;for(let h=0;h<f;++h){let g=l[h],d=l[h+1],p=1-(x-h)/f;(p<0||p>1)&&(p=0);let W=(~~(p*255)).toString(16).padStart(2,"0"),y=1+~~((1.2-p)*5);e.lineWidth=y;let b=g.x+1+(g.y+1)*258;switch(r.streamLineColor){case"inverted":m=C(~t.colorsI[o.raw[b]]);break;case"fill":m=C(t.colorsI[o.raw[b]]);break}e.strokeStyle=m+W,e.beginPath(),e.moveTo(g.x,g.y),e.lineTo(d.x,d.y),e.stroke()}}}var j=class extends Map{clear(){u("TilesCache.clear()"),this.forEach(e=>{e.rd&&(e.rd.gl.deleteTexture(e.rd.vectorTextureU),e.rd.gl.deleteTexture(e.rd.vectorTextureV))}),super.clear()}},B=class{constructor(e){this.tilesCache=new j;this.coarseLevel=0;this.painter=new U(this);this.loader=new N(this);if(u(`WxLayer.constructor:
|
|
1
|
+
var Re=Object.create;var le=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var Be=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty;var Ze=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports);var Ve=(a,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ne(e))!$e.call(a,n)&&n!==t&&le(a,n,{get:()=>e[n],enumerable:!(r=Ue(e,n))||r.enumerable});return a};var Fe=(a,e,t)=>(t=a!=null?Re(Be(a)):{},Ve(e||!a||!a.__esModule?le(t,"default",{value:a,enumerable:!0}):t,a));var ke=Ze((Xt,Pe)=>{Pe.exports=window.L});var ce={comment1:["'degC': ['K', 1, 273.15] -> degC = K * 1 + 273.15",0],comment2:["'hPa': ['Pa', 1000]' -> hPa = Pa * 1000 + 0 (0 - could be ommited)",0],K:["K",1],kelvin:["K",1],F:["K",.5555555555,255.372222222],C:["K",1,273.15],degC:["K",1,273.15],"kg/m^2/s":["kg/m^2/s",1],"Kg/m^2/s":["kg/m^2/s",1],"Kg m**-2 s**-1":["kg/m^2/s",1],"Kg m^-2 s^-1":["kg/m^2/s",1],"Kg m^{-2} s^-1":["kg/m^2/s",1],"mm/h":["kg/m^2/s",.00027777777],"mm/hr":["kg/m^2/s",.00027777777],"W/m^2":["W/m^2",1],"W m^-2":["W/m^2",1],"W m^{-2}":["W/m^2",1],"W/m**2":["W/m^2",1],"W m**-2":["W/m^2",1],"m/s":["m/s",1],"m s**-1":["m/s",1],"m s^-1":["m/s",1],"m.s^{-1}":["m/s",1],knot:["m/s",.514444],knots:["m/s",.514444],"km/h":["m/s",.27777777777],"km h^-1":["m/s",.27777777777],"km h**-1":["m/s",.27777777777],mph:["m/s",.44704],"miles/h":["m/s",.44704],s:["s",1],sec:["s",1],h:["s",3600],min:["s",60],m:["m",1],cm:["m",.01],km:["m",1e3],mile:["m",1609.344],miles:["m",1609.344],inch:["m",.0254],Pa:["Pa",1],hPa:["Pa",100],degree:["degree",1],radian:["degree",57.3],"mg/m^3":["mg/m^3",1],"mg m^-3":["mg/m^3",1],"mg.m^-3":["mg/m^3",1],"%":["%",1],"(0 - 1)":["%",100]};var ue={none:["#00000000","#00000000"],diverging_blue_red:["#2166acff","#92c5deff","#f7f7f7ff","#f4a582ff","#b2182bff"],rainbow:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow_zero:["#ff000000","#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff"],rainbow_wrap:["#ff0000ff","#ffff00ff","#00ff00ff","#00ffffff","#0000ffff","#ff00ffff","#ff0000ff"],rainbow_backwards:["#0000ffff","#00ffffff","#00ff00ff","#ffff00ff","#ff0000ff","#ff00ffff"],rainbow_backwards_zero:["#0000ff00","#0000ffff","#00ffffff","#00ff00ff","#ffff00ff","#ff0000ff","#ff00ffff"],bluebird:["#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],bluebird_zero:["#0000ff00","#0000ffff","#ff00ffff","#00ffffff","#9000ffff","#9090ffff"],black_white:["#000000ff","#ffffffff"],white_black:["#ffffffff","#000000ff"],reddish:["#ff00ffff","#ff0000ff","#ffff00ff"],greenish:["#ffff00ff","#00ff00ff","#00ffffff"],blueish:["#ff00ffff","#0000ffff","#00ffffff"],hspastel:["#AC6EA4FF","#8E92BDFF","#ACD4DEFF","#E9DC8EFF","#E7A97DFF","#E59074FF","#BE7E68FF","#A88F86FF"],black:["#000000ff","#000000ff"],white:["#ffffffff","#ffffffff"],transparent:["#ffffff00"],peach_red_zero:["#fdd49f00","#fdd49fff","#d7301fff"]};var F={base:{parent:void 0,name:"base",fill:"gradient",isolineColor:"none",isolineText:!0,isolineTextSizeEm:1.1,isolineTextBackground:!1,vectorType:"arrows",vectorColor:"inverted",vectorFactor:1,streamLineColor:"none",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"diverging_blue_red",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none",gl:{animationIntensity:5,animationSpeed:1,noiseTexturePow:5,vectorFieldFactor:1,wavesCount:4}},custom:{parent:void 0,name:"custom",fill:"gradient",isolineColor:"inverted",isolineText:!0,isolineTextSizeEm:1.1,isolineTextBackground:!1,vectorType:"arrows",vectorColor:"inverted",vectorFactor:1,streamLineColor:"#777",streamLineSpeedFactor:1,streamLineStatic:!1,showBelowMin:!0,showAboveMax:!0,colorScheme:"rainbow",colors:void 0,colorMap:void 0,levels:void 0,blurRadius:0,addDegrees:0,units:"",extraUnits:void 0,mask:"none"}};var me,fe,de;function xe({colorStyles:a={},units:e={},colorSchemes:t={}}={}){m("WxTile lib setup: start"),me=Object.assign({},ce,e),fe=Object.assign({},t,ue);let r=Object.assign({},a,F);de=Xe(r),m("WxTile lib setup: styles unrolled"),(async()=>{try{await document.fonts.load("32px barbs"),await document.fonts.load("32px arrows")}catch{m("WxTile lib setup: fonts not loaded")}})(),m("WxTile lib setup is done.")}function k(){return de}function Q(){return fe}function q(a,e,t){m("makeConverter: From=",a," To=",e);let r=g=>g;if(r.trivial=!0,a===e)return m("Trivial converter"),r;let n=Object.assign({},me,t),s=n[a],o=n[e];if(!s||!o)return m("Inconvertible units. Trivial converter"),r;let[i,u,c]=s,[l,f,x]=o;if(i!==l||!u||!f)return m("Inconvertible units. Trivial converter"),r;let p=u/f,h=((c||0)-(x||0))/f;return h?g=>p*g+h:g=>p*g}function Xe(a){let e=Object.assign({},F);for(let s in a){let o=a[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=Object.assign({},F.base),r=(s,o)=>{if(o==="base")return t;let i=s[o];if(!i)return t;(!i.parent||!(i.parent in s))&&(i.parent="base");let u=r(s,i.parent);return Object.assign(i,Object.assign({},u,i,{parent:"base"}))},n={base:t};for(let s in e)n[s]=r(e,s);return n}function E(a){let e=new Map,t=(r,...n)=>{let s=e.get(r);if(s)return s;let o=a(r,...n);return e.set(r,o),o.catch(i=>i.name==="AbortError"&&e.delete(r)),o};return t.clearCache=()=>e.clear(),t}async function qe(a,e){let t=await fetch(a,e);if(t.status!==200&&t.status!==304)throw{name:"Tile loading failed",reason:t.headers.get("x-reason"),status:t.status};return await createImageBitmap(await t.blob(),{premultiplyAlpha:"none"})}var X=class{constructor(e,t,r,n){this.raw=e;this.dmin=t;this.dmax=r;this.dmul=n;this.radius=0}get integral(){return this.integral_||(this.integral_=Ye(this.raw))}};function P(a,e,t=!0){let r=Object.assign(document.createElement("canvas"),{width:a,height:e,imageSmoothingEnabled:!1}).getContext("2d",{willReadFrequently:t});if(!r)throw new Error("Cannot get canvas context");return r}function Ee(a){let{width:e,height:t}=a,r=P(e,t);return r.drawImage(a,0,0),r.getImageData(0,0,e,t)}async function ee(a,e){return Ee(await qe(a,e))}function Oe(a){a.data[34]<1&&m("Warning: image is in too old format. Check the version of the Splitter.");let e=new Uint16Array(a.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]=a.data[u*4+2];let n=new DataView(r.buffer),s=n.getFloat32(0,!0),o=n.getFloat32(4,!0),i=(o-s)/65535;return new X(t,s,o,i)}async function pe(a,e){return Oe(await ee(a,e))}function Ye(a){let e=new Uint32Array(66564),t=new Uint32Array(258*258);e[0]=a[0],t[0]=a[0]?1:0;for(let r=1;r<258;++r){e[r]=a[r]+e[r-1],t[r]=(a[r]?1:0)+t[r-1];let n=258*r;e[n]=a[n]+e[n-258],t[n]=(a[n]?1:0)+t[n-258]}for(let r=1;r<258;++r)for(let n=1;n<258;++n){let s=258*r+n;e[s]=a[s]+e[s-258]+e[s-1]-e[s-259],t[s]=(a[s]?1:0)+t[s-258]+t[s-1]-t[s-259]}return{integral:e,integralNZ:t[66563]===66564?null:t}}function je(a){let{integral:e}=a.integral;a.raw[0]=e[0];for(let t=1;t<258;t++){a.raw[t]=e[t]-e[t-1],a.raw[258*t]=e[258*t]-e[258*(t-1)];for(let r=1;r<258;r++){let n=258*t+r;a.raw[n]=e[n-259]+e[n]-e[n-258]-e[n-1]}}return a}function he(a,e){if(e<0&&(e=0),e===a.radius)return a;if(a.radius=e,!e)return je(a);let{integral:t,integralNZ:r}=a.integral;for(let n=2;n<256;n++)for(let s=2;s<256;s++){let o=258*n+s;if(!a.raw[o])continue;let i=Math.min(e,s-1,256-s),u=Math.min(e,n-1,256-n),c=258*(n-u-1)+s,l=258*(n+u)+s,f;if(r){let y=r[c-i-1],W=r[c+i],b=r[l-i-1],w=r[l+i];f=y+w-W-b}else f=(2*i+1)*(2*u+1);let x=t[c-i-1],p=t[c+i],h=t[l-i-1],g=t[l+i],d=x+g-p-h;a.raw[o]=d/f}for(let n=2;n<256;n++){let s=258+n;if(a.raw[s]){let c=n,l=Math.min(e,c-1,256-c),f=258+c,x;if(r){let T=r[f-l-1];x=0+r[f+l]-0-T}else x=(2*l+1)*2;let p=0,h=0,g=t[f-l-1],d=t[f+l],W=(p+d-h-g)/x;a.raw[s-258]=W,a.raw[s]=W}let o=258*256+n;if(a.raw[o]){let c=n,l=Math.min(e,c-1,256-c),f=258*255+c,x=258*257+c,p=t[f-l-1],h=t[f+l],g=t[x-l-1],d=t[x+l],y=p+d-h-g,W;if(r){let w=r[f-l-1],T=r[f+l],S=r[x-l-1],M=r[x+l];W=w+M-T-S}else W=(2*l+1)*2;let b=y/W;a.raw[o]=b,a.raw[o+258]=b}let i=258*n+1;if(a.raw[i]){let c=n,l=Math.min(e,c-1,256-c),f=258*(c-l-1)+1,x=258*(c+l)+1,p;if(r){let T=r[f],S=0;p=0+r[x]-T-S}else p=(2*l+1)*2;let h=0,g=t[f],d=0,y=t[x],b=(h+y-g-d)/p;a.raw[i-1]=b,a.raw[i]=b}let u=258*n+256;if(a.raw[u]){let c=n,l=Math.min(e,c-1,256-c),f=258*(c-l-1)+256,x=258*(c+l)+256,p;if(r){let w=r[f-1],T=r[f+1],S=r[x-1],M=r[x+1];p=w+M-T-S}else p=2*(2*l+1);let h=t[f-1],g=t[f+1],d=t[x-1],y=t[x+1],b=(h+y-g-d)/p;a.raw[u]=b,a.raw[u+1]=b}}return a}function D(a){let e=a>>0&255,t=a>>8&255,r=a>>16&255,n=e.toString(16),s=t.toString(16),o=r.toString(16);return n=n.length===2?n:"0"+n,s=s.length===2?s:"0"+s,o=o.length===2?o:"0"+o,"#"+n+s+o}function C(a){if(a[0]==="#"){if(a.length===4)return+("0xff"+a[3]+a[3]+a[2]+a[2]+a[1]+a[1]);if(a.length===7)return+("0xff"+a[5]+a[6]+a[3]+a[4]+a[1]+a[2]);if(a.length===9)return+("0x"+a[7]+a[8]+a[5]+a[6]+a[3]+a[4]+a[1]+a[2])}return m("wrong color format",a),0}async function v(a,e){let t=await fetch(a,e);if(!t.ok)throw new Error("error:"+a+" - "+t.statusText);return t.json()}function te(a,e,t){let r=a>>0&255,n=a>>8&255,s=a>>16&255,o=a>>>24,i=e>>0&255,u=e>>8&255,c=e>>16&255,l=e>>>24,f=r+t*(i-r),x=n+t*(u-n),p=s+t*(c-s),h=o+t*(l-o);return f|x<<8|p<<16|h<<24}function ge(a,e,t){let r=[];for(let n=0;n<t;++n)r.push(n*(e-a)/(t-1)+a);return r}var J=!1,m=(...a)=>{};function Ge(a){J=!!a,console.log("WXLOGing",J),m=typeof a=="function"?a:J?console.log:()=>{}}function re(a){return a[0]==="#"&&a.length===4?"#"+a[1]+a[1]+a[2]+a[2]+a[3]+a[3]:a}function O(a,{x:e,y:t,z:r}){return a.replace("{x}",`${e}`).replace("{y}",`${t}`).replace("{z}",`${r}`)}function Y({x:a,y:e,z:t}){return`${t}-${a}-${e}`}var ze="A".charCodeAt(0);var A=class{constructor(e,t){this._qtree={nodes:null};this._qtreedepth=0;m("QTree.constructor"),this._ready=this._load(e,t)}get ready(){return this._ready}async _load(e,t){if(e!="none"){try{let r=await v(e,t);this._qtree=ye(r,{pos:0})}catch(r){throw new Error(`Failed to load QTree: ${r.message}`)}this._qtreedepth=be(this._qtree),m(`QTree.load: qtreedepth=${this._qtreedepth}`)}}check(e){let t=e.z-this._qtreedepth,r=t>=0,n=r?{x:e.x>>t,y:e.y>>t,z:this._qtreedepth}:{...e};return We(this._qtree,n,r)}};function ye(a,e){let t=a.charCodeAt(e.pos)-ze;e.pos++;let r=[1,2,4,8].map(n=>t&n?ye(a,e):null);return{nodes:r.some(n=>n)?r:null}}function be(a){return a?.nodes?1+Math.max(...a.nodes.map(be)):0}function We(a,e,t){return a===null?"land":t&&!e.z?"mixed":a.nodes===null?"sea":e.z?(e.z--,We(a.nodes[(e.y>>e.z&1)<<1|e.x>>e.z&1],e,t)):"mixed"}var He=2*Math.PI*6378137/256,j=2*Math.PI*6378137/2;function Ke(a,e){let t=a/j*180,r=e/j*180;return r=180/Math.PI*(2*Math.atan(Math.exp(r*Math.PI/180))-Math.PI/2),[r,t]}function Je(a,e,t){let r=Qe(t),n=a*r-j,s=e*r-j;return[n,s]}function Qe(a){return He/2**a}function ae(a,e,t){let[r,n]=Ke(...Je(a,e,t));return[n,-r]}function we(a,e){return[a*256,e*256]}function ne(a,e,t){let r=((e-a)%360+540)%360-180;return(a+r*t+360)%360}function et(a,e,t,r,n,s,o,i){switch((a?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 0:return 0;case 1:return a;case 2:return e;case 3:t=a,r=e;break;case 4:return t;case 5:e=a,r=t;break;case 6:r=e+t>>1,a=r;break;case 7:r=e+t>>1;break;case 8:return r;case 9:e=a+r>>1,t=e;break;case 10:a=e,t=r;break;case 11:t=a+r>>1;break;case 12:a=t,e=r;break;case 13:e=a+r>>1;break;case 14:a=e+t>>1;break}a=o+i*a,e=o+i*e,t=o+i*t,r=o+i*r;let c=ne(a,e,n),l=ne(t,r,n),f=(ne(c,l,s)-o)/i;return f<1?1:f}function Se(a,e,t,r,n,s,o,i){switch((a?1:0)|(e?2:0)|(t?4:0)|(r?8:0)){case 7:return n+s<1?n*(e-a)+s*(t-a)+a:0;case 14:return n+s<1?0:n*(r-t)+s*(r-e)+e+t-r;case 11:return s<n?(1-n)*(a-e)+s*(r-e)+e:0;case 13:return s<n?0:(1-n)*(t-r)+s*(t-a)+a+r-t;case 15:return n+s<1?n*(e-a)+s*(t-a)+a:n*(r-t)+s*(r-e)+e+t-r;default:return 0}}function Te(a,e,t){let r=1/2**t.z,n=t.x*256*r-.5,s=t.y*256*r-.5,{raw:o,dmin:i,dmax:u,dmul:c}=e,l={raw:new Uint16Array(258*258),dmin:i,dmax:u,dmul:c},{raw:f}=l;for(let x=-1,p=0,h=s-r+1;x<=256;x++,h+=r){let g=Math.floor(h),d=h-g,y=g*258;for(let W=-1,b=n-r+1;W<=256;W++,p++,b+=r){let w=Math.floor(b),T=b-w,S=w+y,M=o[S],_=o[S+1],I=o[S+258],L=o[S+258+1];f[p]=a(M,_,I,L,T,d,i,c)}}return l}function Me(a,e,t){if(!e)return a;let r=l=>l<0?0:l>254?254:l,n=1/2**e.z,s=e.x*256*n-.5,o=e.y*256*n-.5,{data:i}=a,u=new ImageData(256,256),{data:c}=u;for(let l=0,f=t,x=o;l<256;l++,x+=n){let p=~~r(x),h=x-p,g=p*256;for(let d=0,y=s;d<256;d++,f+=4,y+=n){let W=~~r(y),b=y-W,w=(W+g)*4+t,T=i[w],S=i[w+4],M=i[w+4*256],_=i[w+4*256+4],I=Se(T,S,M,_,b,h,0,0);c[f]=I>127?255:0}}return u}function De(a,e){return e?Te(Se,a,e):a}function Ce(a,e){return e?Te(et,a,e):a}function _e(a,{data:e},t,r){let n=r==="sea",{raw:s}=a;for(let o=t,i=259,u=0;u<256;i+=2,u++)for(let c=0;c<256;c++,i++,o+=4)n===!e[o]&&(s[i]=0);return a}function Ie(a){let[e,t]=we(a.x,a.y),[r,n]=ae(e,t,a.z),[s,o]=ae(e+256,t+256,a.z);return{west:r,north:n,east:s,south:o}}function se(a,e){let t=a.z-e;if(t<=0)return{upCoords:a};let r={x:a.x>>>t,y:a.y>>>t,z:e},n={x:a.x&(1<<t)-1,y:a.y&(1<<t)-1,z:t};return{upCoords:r,subCoords:n}}var R=class{constructor(e){this._loadDataFunc=E(pe);this._layer=e}async load(e,t){let r=await this.cacheLoad(e,this._layer.tilesURIs,t);if(!r)return null;let{rawdata:n,subCoords:s,tileType:o}=r,{units:i}=this._layer.currentVariableMeta,u=i==="degree"?Ce:De,c=f=>u(he(f,this._layer.style.blurRadius),s),l=n.map(c);return this._vectorMagnitudesPrepare(l),await this._applyMask(l,e,o,!s&&n.length===1),{data:l,slines:this._createStreamLines(l)}}async cacheLoad(e,t,r){if(!this._checkInsideBoundaries(e))return null;let n=this._checkTypeAndMask(e);if(!n)return null;let{upCoords:s,subCoords:o}=se(e,this._layer.getCoarseMaxZoom()),i=t.map(l=>O(l,s)),u=Object.assign({},this._layer.wxdatasetManager.wxAPI.requestInit,{signal:r?.signal});return{rawdata:await Promise.all(i.map(l=>this._loadDataFunc(l,u))),subCoords:o,tileType:n}}clearCache(){this._loadDataFunc.clearCache()}async _applyMask(e,t,r,n){let{style:s}=this._layer;if((s.mask==="land"||s.mask==="sea")&&r==="mixed"){if(n){let{raw:u,dmin:c,dmax:l,dmul:f}=e[0];e[0]={raw:new Uint16Array(u),dmin:c,dmax:l,dmul:f}}let o,{wxAPI:i}=this._layer.wxdatasetManager;try{let{upCoords:u,subCoords:c}=se(t,i.maskDepth);o=await i.loadMaskFunc(u),o=Me(o,c,i.maskChannel)}catch{s.mask=void 0,m("Can't load Mask. Masking is disabled");return}_e(e[0],o,i.maskChannel,s.mask)}}_vectorMagnitudesPrepare(e){if(e.length===1)return;e.unshift({raw:new Uint16Array(258*258),dmin:0,dmax:0,dmul:0});let[t,r,n]=e;t.dmax=1.42*Math.max(-r.dmin,r.dmax,-n.dmin,n.dmax),t.dmul=(t.dmax-t.dmin)/65535;for(let s=0;s<258*258;++s){if(!r.raw[s]||!n.raw[s])continue;let o=r.dmin+r.dmul*r.raw[s],i=n.dmin+n.dmul*n.raw[s];t.raw[s]=Math.sqrt(i*i+o*o)/t.dmul}}_checkTypeAndMask(e){let{mask:t}=this._layer.style;if(t==="land"||t==="sea"){let r=this._layer.wxdatasetManager.wxAPI.qtree.check(e);return t===r?void 0:r}return"mixed"}_checkInsideBoundaries(e){let t=this._layer.getBoundaries();if(t?.boundaries180){let r=Ie(e),n=s=>!(r.west>s.east||s.west>r.east||r.south>s.north||s.south>r.north);if(!t.boundaries180.some(n))return!1}return!0}_createStreamLines(e){if(e.length!==3)return[];let{style:t}=this._layer;if(t.streamLineColor==="none")return[];let r=[],[n,s,o]=e,i=(t.streamLineSpeedFactor||1)/n.dmax,u=t.addDegrees?.017453292519943*t.addDegrees:0,c=t.streamLineGridStep||64,l=t.streamLineSteps||300;for(let f=0;f<=256;f+=c)for(let x=0;x<=256;x+=c){if(!n.raw[1+x+(1+f)*258])continue;let p=[],h=x,g=f,d=-1,y=0,W=0;for(let T=0;T<=l&&h>=0&&h<=256&&g>=0&&g<=256;T++){T%(l/10)||p.push({x:~~h,y:~~g});let S=~~h+1+(~~g+1)*258;if(S!==d){if(!n.raw[S])break;d=S;let M=n.dmin+n.raw[S]*n.dmul,_=s.dmin+s.raw[S]*s.dmul,I=o.dmin+o.raw[S]*o.dmul,L=Math.atan2(_,I)+u;y=i*M*Math.sin(L),W=i*M*Math.cos(L)}h+=y,g-=W}let b=x,w=f;d=-1;for(let T=1;T<=l&&b>=0&&b<=256&&w>=0&&w<=256;T++){T%(l/10)||p.unshift({x:~~b,y:~~w});let S=~~b+1+(~~w+1)*258;if(S!==d){if(!n.raw[S])break;d=S;let M=n.dmin+n.raw[S]*n.dmul,_=s.dmin+s.raw[S]*s.dmul,I=o.dmin+o.raw[S]*o.dmul,L=Math.atan2(_,I)+u;y=i*M*Math.sin(L),W=i*M*Math.cos(L)}b-=y,w+=W}p.length>2&&r.push(p)}return r}};var U=class{constructor(e){this._layer=e}paint({data:e,ctxFill:t,ctxText:r,ctxStreamLines:n}){let{_layer:s}=this,{units:o}=s.currentVariableMeta,i=new ImageData(256,256),u=new Uint32Array(i.data.buffer);t.clearRect(0,0,256,256),r.clearRect(0,0,256,256),n.clearRect(0,0,256,256),tt(e.data[0],u,s);let c=rt(u,e.data[0],s);t.putImageData(i,0,0),at(c,r,s),ot(e.data,r,s),it(e.data[0],r,o,s),lt(e,r,s)}getPaintedCanvas(e,t,r){return t?(this.imprintVectorAnimationLinesStep(e,r),e.ctxStreamLines.canvas):e.ctxFill.canvas}imprintVectorAnimationLinesStep({data:e,ctxFill:t,ctxStreamLines:r},n){let{_layer:s}=this;r.clearRect(0,0,256,256),r.drawImage(t.canvas,0,0),!(e.slines.length===0||s.style.streamLineStatic||s.style.streamLineColor==="none")&&ct(e,r,s,n)}};function tt(a,e,{CLUT:t,style:r}){let{raw:n}=a,{colorsI:s}=t;if(r.fill!=="none")for(let o=0,i=0,u=259;o<256;++o,u+=2)for(let c=0;c<256;++c,++i,++u)e[i]=s[n[u]];else e.fill(0)}function rt(a,e,{CLUT:t,style:r}){let{raw:n}=e,{levelIndex:s,colorsI:o}=t,i=[];if(r.isolineColor!=="none"){let u=r.isolineColor[0]==="#"?C(r.isolineColor):0;for(let c=0,l=0;c<256;c+=1)for(let f=0;f<256;f+=1){let x=(c+1)*258+(f+1),p=n[x],h=n[x+1],g=n[x+258];if(!p||!h||!g)continue;let d=s[p],y=s[h],W=s[g];if(d!==y||d!==W){let b=Math.max(d,y,W),w=Math.max(p,h,g),T=c*256+f;switch(r.isolineColor){case"inverted":a[T]=~o[w]|4278190080;break;case"fill":a[T]=o[w]|4278190080;break;default:a[T]=u;break}r.isolineText&&!(++l%255)&&f>20&&f<235&&c>20&&c<235&&i.push({x:f,y:c,d:p,dr:h,db:g,mli:b})}}}return i}function at(a,e,{CLUT:t,style:r}){if(a.length){let n=r.isolineTextSizeEm||1.1;e.font=n.toString()+"em Sans-serif",e.lineWidth=2,e.strokeStyle="white",e.fillStyle="black",e.textAlign="center",e.textBaseline="middle";let s=e.measureText("-.0123456789"),o=s.actualBoundingBoxAscent+s.actualBoundingBoxDescent,u=1.5*o,c=s.actualBoundingBoxAscent+(u-o)/2,l=1.1,f=n*2.5,x=r.isolineTextBackground?nt:st;for(let{x:p,y:h,d:g,dr:d,db:y,mli:W}of a){let b=Math.atan2(g-d,y-g);e.save(),e.translate(p,h),e.rotate(b<-1.57||b>1.57?b+3.14:b);let w=t.ticks[W].dataString;x(w,e,{height:u,hOffset:c,wScale:l,radii:f}),e.fillText(w,0,0),e.restore()}}}function nt(a,e,t){e.strokeText(a,0,0)}function st(a,e,{height:t,hOffset:r,wScale:n,radii:s}){let o=e.fillStyle;e.fillStyle=e.strokeStyle;let i=n*e.measureText(a).width;e.beginPath(),e.roundRect(-i/2,-r,i,t,s),e.closePath(),e.fill(),e.fillStyle=o}function ot(a,e,{CLUT:t,style:r}){if(!t.DataToKnots||r.vectorColor==="none"||r.vectorType==="none")return;if(a.length!==3)throw new Error("data.length !== 3");let[n,s,o]=a;switch(r.vectorType){case"barbs":e.font="40px barbs";break;case"arrows":e.font="50px arrows";break;default:e.font=r.vectorType}e.textAlign="center",e.textBaseline="middle",e.fillStyle=r.vectorColor;let i=r.addDegrees?.017453292519943*r.addDegrees:0,u=32;for(let c=u/2;c<256;c+=u)for(let l=u/2;l<256;l+=u){let f=l+1+(c+1)*258;if(!n.raw[f])continue;let x=Math.atan2(s.dmin+s.raw[f]*s.dmul,o.dmin+o.raw[f]*o.dmul),p=n.dmin+n.raw[f]*n.dmul,h=r.vectorType!=="barbs"?r.vectorFactor*.5:.2,g=Math.min(~~(t.DataToKnots(p)*h),25)+65,d=String.fromCharCode(g);switch(r.vectorColor){case"inverted":e.fillStyle=D(~t.colorsI[n.raw[f]]);break;case"fill":e.fillStyle=D(t.colorsI[n.raw[f]]);break}e.save(),e.translate(l,c),e.rotate(x+i),e.fillText(d,0,0),e.restore()}}function it(a,e,t,{CLUT:r,style:n}){if(t!=="degree")return;let s=.017453292519943*n.addDegrees;e.font="50px arrows",e.textAlign="center",e.textBaseline="middle",e.fillStyle=n.vectorColor;let o="L",i=32;for(let u=i/2;u<256;u+=i)for(let c=i/2;c<256;c+=i){let l=c+1+(u+1)*258;if(!a.raw[l])continue;let x=(a.dmin+a.raw[l]*a.dmul+180)*.01745329251;switch(n.vectorColor){case"inverted":e.fillStyle=D(~r.colorsI[a.raw[l]]);break;case"fill":e.fillStyle=D(r.colorsI[a.raw[l]]);break}e.save(),e.translate(c,u),e.rotate(x+s),e.fillText(o,0,0),e.restore()}}function lt(a,e,{CLUT:t,style:r}){let{data:n,slines:s}=a;if(!s.length||!r.streamLineStatic||r.streamLineColor==="none")return;let o=n[0];e.lineWidth=1,r.streamLineColor[0]==="#"&&(e.strokeStyle=re(r.streamLineColor));for(let i=s.length;i--;){let u=s[i];for(let c=0;c<u.length-1;++c){let l=u[c],f=u[c+1],x=l.x+1+(l.y+1)*258;switch(r.streamLineColor){case"inverted":e.strokeStyle=D(~t.colorsI[o.raw[x]]);break;case"fill":e.strokeStyle=D(t.colorsI[o.raw[x]]);break}e.beginPath(),e.moveTo(l.x,l.y),e.lineTo(f.x,f.y),e.stroke()}}}function ct(a,e,{CLUT:t,style:r},n){let{data:s,slines:o}=a,i=s[0],u=r.streamLineColor[0]==="#"?re(r.streamLineColor).substring(0,7):"#000000";n=n>>5;for(let c=0;c<o.length;++c){let l=o[c],f=l.length-1,x=(n+(1+l[0].x)*(1+l[0].y))%30;for(let p=0;p<f;++p){let h=l[p],g=l[p+1],d=1-(x-p)/f;(d<0||d>1)&&(d=0);let y=(~~(d*255)).toString(16).padStart(2,"0"),W=1+~~((1.2-d)*5);e.lineWidth=W;let b=h.x+1+(h.y+1)*258;switch(r.streamLineColor){case"inverted":u=D(~t.colorsI[i.raw[b]]);break;case"fill":u=D(t.colorsI[i.raw[b]]);break}e.strokeStyle=u+y,e.beginPath(),e.moveTo(h.x,h.y),e.lineTo(g.x,g.y),e.stroke()}}}function ut(a,e,t){return a>t?t:a<e?e:a}var G=class{constructor(e,t,[r,n],s){m("RawCLUT.constructor"),this.levelIndex=new Uint32Array(65536),this.colorsI=new Uint32Array(65536);let o;this.DataToStyle=q(t,e.units,e.extraUnits),this.DataToStyle.trivial&&(e.units=t),s&&(this.DataToKnots=q(t,"knot"));let i=q(e.units,t,e.extraUnits),u=d=>~~(65535*ut((i(d)-r)/(n-r),0,1));if(e.colorMap?.length)o=e.colorMap.sort((d,y)=>d[0]-y[0]).map(([d])=>u(d));else{e.levels||(e.levels=ge(this.DataToStyle(r),this.DataToStyle(n),10)),e.levels.sort((y,W)=>y-W);let d=Q();e.colors||(e.colors=d[e.colorScheme]||["#ffffffff","#000000ff"]),o=e.levels.map(u)}let c=n-r,l=ve(65536,e);this.ticks=l.ticks;let f=l.ticks[0].data,p=l.ticks[l.ticks.length-1].data-f,h=e.showBelowMin?l.colors[0]:0,g=e.showAboveMax?l.colors[65535]:0;this.colorsI[0]=0;for(let d=1;d<65536;++d){let y=this.DataToStyle(c*d/65535+r),W=Math.round(65535*(y-f)/p);this.colorsI[d]=W<=0?h:W>65535?g:l.colors[W]}for(let d=0;d<o[0];++d)this.levelIndex[d]=0;for(let d=0;d<o.length-1;d++)for(let y=o[d];y<o[d+1]+1;++y)this.levelIndex[y]=d;for(let d=o[o.length-1];d<65536;++d)this.levelIndex[d]=o.length-1}};function Le(a){if(a!==0&&-.1<a&&a<.1)return a.toExponential(2);let e=a.toString();return e.split(".")[1]?.length>2?a.toFixed(2):e}function ve(a,e){let t={size:a,showBelowMin:e.showBelowMin,showAboveMax:e.showAboveMax,units:e.units,colors:new Uint32Array(a),ticks:[]},{colorMap:r,levels:n,colors:s}=e,o=e.fill!=="solid";if(r){let x=r[0][0],p=(a-1)/(r[r.length-1][0]-x);t.ticks=r.map(([h,g])=>({data:h,dataString:Le(h),color:g,pos:~~((h-x)*p)}));for(let h=0;h<r.length-1;h++){let g=t.ticks[h].pos,d=t.ticks[h+1].pos,y=C(r[h][1]),W=o?C(r[h+1][1]):0;for(let b=g;b<d;++b)t.colors[b]=o?te(y,W,(b-g)/(d-g)):y}return t.colors[a-1]=C(r[r.length-1][1]),t}if(!s||!n)return t;let i=0,u=0,c=-1;for(let x=0;x<a;++x){let p=x*(s.length-1)/a;c!==~~p&&(c=~~p,i=C(s[c]),u=s.length>c+1?C(s[c+1]):i),t.colors[x]=o?te(i,u,p-c):i}t.colors[a-1]=C(s[s.length-1]);let l=n[0],f=(a-1)/(n[n.length-1]-l);return t.ticks=n.map(x=>{let p=~~((x-l)*f);return{data:x,dataString:Le(x),pos:p,color:D(t.colors[p])}}),t}var N=class extends Map{clear(){m("TilesCache.clear()"),this.forEach(e=>{e.rd&&(e.rd.gl.deleteTexture(e.rd.vectorTextureU),e.rd.gl.deleteTexture(e.rd.vectorTextureV))}),super.clear()}},B=class{constructor(e){this.tilesRasterCache=new N;this.coarseLevel=0;this._painter=new U(this);this._loader=new R(this);if(m(`WxLayer.constructor:
|
|
2
2
|
datasetName: ${e.wxdatasetManager.datasetName},
|
|
3
3
|
variables: ${e.variables.join(", ")},
|
|
4
4
|
wxstyleName: ${e.wxstyleName},
|
|
5
5
|
wxstyle: ${JSON.stringify(e.wxstyle)},
|
|
6
|
-
time: ${e.time}`),!e.variables?.length||e.variables.length>2)throw new Error(`datasetName: ${e.wxdatasetManager.datasetName}: only 1 or 2 variables are supported but ${e.variables} was given`);e.variables.forEach(s=>{if(!e.wxdatasetManager.checkVariableValid(s))throw new Error(`datasetName: ${e.wxdatasetManager.datasetName}: variable ${s} is not valid`)}),this.variables=e.variables,this.wxdatasetManager=e.wxdatasetManager,[this.tilesURIs,this.time]=this._createURLsAndTime(e.time);let t=A(),r=t.base,n=e.wxstyleName&&t[e.wxstyleName];this.currentVariableMeta=this._getCurrentVariableMeta(),[this.style,this.CLUT]=this._createStyleAndCLUT({...r,...n,...e.wxstyle})}get nonanimatable(){return u("WxLayer.nonanimatabl()"),this.variables.length<2||this.style.streamLineStatic||this.style.streamLineColor==="none"}getMaxZoom(){return u("WxLayer.getMaxZoom"),this.wxdatasetManager.isInstanced()?this.wxdatasetManager.getInstanceMeta(this.getTime()).maxZoom:this.wxdatasetManager.getMaxZoom()}getCoarseMaxZoom(){return u("WxLayer.getCoarseMaxZoom"),this.getMaxZoom()-this.coarseLevel}getBoundaries(){return this.wxdatasetManager.isInstanced()?this.wxdatasetManager.getInstanceMeta(this.getTime()).boundaries:this.wxdatasetManager.getBoundaries()}getTime(){return u("WxLayer.getTime"),this.time}clearCache(){u("WxLayer.clearCache"),this.tilesCache.clear(),this.loader.clearCache()}getCurrentStyleObjectCopy(){return u("WxLayer.getCurrentStyleObjectCopy"),Object.assign({},this.style)}updateCurrentStyleObject(e){u(`WxLayer.updateCurrentStyleObject ${JSON.stringify(e)}`),[this.style,this.CLUT]=this._createStyleAndCLUT(e)}getTileData(e,t){let r=this.tilesCache.get(E(e));if(!r)return;let n=this._getPixelInfo(t,r.data.data);if(!n)return;let{raw:s,data:i}=n,o=s.map(l=>this.CLUT.colorsI[l]),m=o.map(C),c=i.map(l=>this.CLUT.DataToStyle(l));return{data:i,raw:s,rgba:o,hexColor:m,inStyleUnits:c,tilePoint:t,styleUnits:this.style.units,dataUnits:this.currentVariableMeta.units}}setURLsAndTime(e){u(`WxLayer.setURLsAndTime time=${e}`),[this.tilesURIs,this.time]=this._createURLsAndTime(e),this.wxdatasetManager.isInstanced()&&(this.currentVariableMeta=this._getCurrentVariableMeta(),[this.style,this.CLUT]=this._createStyleAndCLUT())}async loadTile(e,t){return this._loadCacheDrawTile(e,this.tilesCache,t).catch(r=>{if(r.name==="AbortError")throw r;return null})}async preloadTime(e,t,r){u(`WxLayer.preloadTime time=${e}`);let[n]=this._createURLsAndTime(e);await Promise.allSettled(t.map(s=>this.loader.cacheLoad(s,n,r)))}async reloadTiles(e,t){u("WxLayer.reloadTiles");let r=new j;await Promise.allSettled(e.map(n=>this._loadCacheDrawTile(n,r,t))),t?.signal?.aborted?r.clear():(this.tilesCache.clear(),this.tilesCache=r)}async _loadCacheDrawTile(e,t,r){let n=t.get(E(e));if(n)return n;let s=await this.loader.load(e,r);if(!s)return null;let i=k(256,256),o=i,m=this.variables.length===2?k(256,256):i,c={ctxFill:i,ctxText:o,ctxStreamLines:m,data:s};return this.painter.paint(c),t.set(E(e),c),c}_getCurrentVariableMeta(){let e=this.variables.map(i=>{let o=this.wxdatasetManager.getInstanceVariableMeta(i,this.time);if(!o)throw new Error(`WxLayer ${this.wxdatasetManager.datasetName}: variable ${i} is not valid`);return o}),{min:t,max:r,units:n,vector:s}=e[0];return this.variables.length>1&&(t=0,r=1.42*Math.max(-e[0].min,e[0].max,-e[1].min,e[1].max)),{min:t,max:r,units:n,vector:s}}_getPixelInfo({x:e,y:t},r){u(`WxLayer._getPixelInfo x=${e} y=${t}`);let n=(t+1)*258+(e+1);if(r?.[0]?.raw?.[n])return{raw:r.map(s=>s.raw[n]),data:r.map(s=>s.raw[n]*s.dmul+s.dmin)}}_createStyleAndCLUT(e){let t=Object.assign({},this.style,e),r=this._prepareCLUT(t);return[t,r]}_prepareCLUT(e){let{min:t,max:r,units:n}=this.currentVariableMeta;return new $(e,n,[t,r],this.variables.length===2)}_createURLsAndTime(e){let t=this.wxdatasetManager.getValidTime(e);return[this.variables.map(n=>this.wxdatasetManager.createURI(n,t)),t]}};var Ae=Ze(ke()),V=class extends Ae.default.GridLayer{constructor(t){super(t);this.id=t.id}};var G=class extends V{constructor(t,r){u(`WxLayerBaseImplementation.constructor (${r.id})`);super(r);this.animation=!1;this.animationSeed=0;this.layer=new B(t)}get wxdatasetManager(){return u(`WxLayerBaseImplementation.wxdatasetManager (${this.id})`),this.layer.wxdatasetManager}getCurrentVariableMeta(){return u(`WxLayerBaseImplementation.getCurrentVariableMeta (${this.id})`),{...this.layer.currentVariableMeta}}getDatasetMeta(){return this.layer.wxdatasetManager.getInstanceMeta(this.getTime())}getMetadata(){return u(`WxLayerBaseImplementation.getMetadata (${this.id})`),{...this.layer.currentVariableMeta}}getVariables(){return u(`WxLayerBaseImplementation.getVariables (${this.id})`),[...this.layer.variables]}clearCache(){u(`WxLayerBaseImplementation.clearCache (${this.id})`),this.layer.clearCache()}getCache(){return this.layer.tilesCache}getCurrentStyleObjectCopy(){return u(`WxLayerBaseImplementation.getCurrentStyleObjectCopy (${this.id})`),this.layer.getCurrentStyleObjectCopy()}getTime(){return u(`WxLayerBaseImplementation.getTime (${this.id})`),this.layer.getTime()}getTimes(){return u(`WxLayerBaseImplementation.getTimes (${this.id})`),this.layer.wxdatasetManager.getTimes()}async setTime(t,r){u(`WxLayerBaseImplementation.setTime (${this.id}) time=${t}`);let n=this.getTime();return this.layer.setURLsAndTime(t),await this._reloadVisible(r),r?.signal?.aborted&&this.layer.setURLsAndTime(n),this.getTime()}async preloadTime(t,r){return u(`WxLayerBaseImplementation.preloadTime (${this.id}) time=${t}`),this.layer.preloadTime(t,this.coveringTiles(),r)}startAnimation(){if(this.animation){u(`WxLayerBaseImplementation.startAnimation (${this.id}) already started`);return}if(this.layer.nonanimatable){u(`WxLayerBaseImplementation.startAnimation (${this.id}) nonanimatable`);return}u(`WxLayerBaseImplementation.startAnimation (${this.id})`),this.animation=!0;let t=async r=>{if(u(`WxLayerBaseImplementation.startAnimation (${this.id}) animationStep`),!this.animation||this.layer.nonanimatable){this.animation=!1;return}this.animationSeed=r,await this._redrawTiles(),requestAnimationFrame(t)};requestAnimationFrame(t)}async stopAnimation(){return u(`WxLayerBaseImplementation.stopAnimation (${this.id})`),this.animation=!1,this._redrawTiles()}async setCoarseLevel(t=2){this.layer.coarseLevel=Math.max(0,Math.min(t,this.wxdatasetManager.getMaxZoom()))}async unsetCoarseLevel(){return this.layer.coarseLevel=0,this._reloadVisible()}async setStyleByName(t,r=!0){return u(`WxLayerBaseImplementation.setStyleByName (${this.id}) wxstyleName=${t} reload=${r}`),this.updateCurrentStyleObject(A()[t],r)}async updateCurrentStyleObject(t,r=!0,n){if(u(`WxLayerBaseImplementation.updateCurrentStyleObject (${this.id}) style=${t} reload=${r}`),this.layer.updateCurrentStyleObject(t),this.startAnimation(),r)return this._reloadVisible(n)}_redrawTiles(){return this.redrawRequested?this.redrawRequested:(this.redrawRequested=new Promise(t=>{requestAnimationFrame(()=>{u(`WxTileSource _redrawTiles (${this.id})`),this.update(),t(),this.redrawRequested=void 0})}),this.redrawRequested)}async _reloadVisible(t){}coveringTiles(){return[]}update(){}};var z=class{constructor(e,t,r){this.coords=e;this.ctx=t;this.raster_data=r;this.draw(r?.ctxFill.canvas)}draw(e){this.ctx.clearRect(0,0,256,256),e&&this.ctx.drawImage(e,0,0)}},Z=class extends G{constructor(e,t){super(e,t),u("WxTileSource constructor: ",e)}getLayerInfoAtLatLon(e,t){if(u(`WxTileSource getLayerInfoAtLatLon (${this.layer.wxdatasetManager.datasetName})`,e),!this._map)return;let r=this._map.getZoom(),n=this._map.project(e,r),s=n.divideBy(256).floor(),i=n.subtract(s.multiplyBy(256)).floor();return this.layer.getTileData({x:s.x,y:s.y,z:r},i)}async _reloadVisible(e){if(u(`WxTileSource _reloadVisible (${this.layer.wxdatasetManager.datasetName})`),await this.layer.reloadTiles(this.coveringTiles(),e),e?.signal?.aborted){u(`WxTileSource _reloadVisible (${this.layer.wxdatasetManager.datasetName}) aborted`);return}return await Promise.allSettled(this._ForEachWxTile(async t=>{t.raster_data=await this.layer.loadTile(t.coords)},"_reloadVisible")),this._redrawTiles()}coveringTiles(){u(`WxTileSource coveringTiles (${this.layer.wxdatasetManager.datasetName})`);let e=[];for(let t in this._tiles){let r=this._tiles[t].el?.wxtile;r&&e.push(r.coords)}return e}update(){u(`WxTileSource update (${this.layer.wxdatasetManager.datasetName})`),this._ForEachWxTile(e=>{e.draw(e.raster_data&&this.layer.painter.getPaintedCanvas(e.raster_data,this.animation,this.animationSeed))},"_redrawTiles")}_ForEachWxTile(e,t){u(`WxTileSource _ForEachWxTile (${this.layer.wxdatasetManager.datasetName}) func=${t}`);let r=[];for(let n in this._tiles){let s=this._tiles[n].el?.wxtile;s&&r.push(e(s))}return r}createTile(e,t){let r=k(256,256),n=r.canvas;return this.layer.loadTile(e).then(s=>{n.wxtile=new z(e,r,s)}).catch(()=>{n.wxtile=new z(e,r,null)}).finally(t),n}onRemove(e){return super.onRemove(e),u(`WxTileSource onRemove (${this.layer.wxdatasetManager.datasetName})`),this.animation=!1,this}};var F=class{constructor({datasetName:e,datasetCurrentInstance:t,instanced:r,datasetCurrentMeta:n,metas:s,wxAPI:i}){if(!i.datasetsMetas.allDatasetsList.includes(e))throw new Error(`Dataset ${e} not found`);this.datasetName=e,this.instanced=r,this.datasetCurrentInstance=t,this.datasetCurrentMeta=n,this.metas=s,this.wxAPI=i,u(`WxDataSetManager.constructor: ${this.datasetName}`)}isInstanced(){return!!this.instanced}getValidTime(e=Date()){u(`WxDataSetManager.getValidTime: ${this.datasetName}, ${e}`);let t=this.getTimes();if(e==="")return t[t.length-1];if(typeof e=="string"){let s=t.indexOf(e);if(s!==-1)return t[s]}if(typeof e=="number"){if(e<=0)return t[0];if(e<t.length)return t[e]}let r=new Date(e).getTime();return isNaN(r)?t[t.length-1]:t.find(s=>new Date(s).getTime()>=r)||t[t.length-1]}getTimes(){return u(`WxDataSetManager.getTimes: ${this.datasetName}`),this.instanced||this.datasetCurrentMeta.times}getVariables(){return u(`WxDataSetManager.getVariables: ${this.datasetName}`),this.datasetCurrentMeta.variables}getVariableMeta(e){return u(`WxDataSetManager.getVariableMeta: ${this.datasetName}, ${e}`),this.datasetCurrentMeta.variablesMeta[e]}getInstanceVariableMeta(e,t){return u(`WxDataSetManager.getInstanceVariableMeta: ${this.datasetName}, ${e}, ${t}`),this.getInstanceMeta(t).variablesMeta[e]}getMaxZoom(){return u(`WxDataSetManager.getMaxZoom: ${this.datasetName}`),this.datasetCurrentMeta.maxZoom}getBoundaries(){return u(`WxDataSetManager.getBoundaries: ${this.datasetName}`),this.datasetCurrentMeta.boundaries}getInstanceMeta(e){return u(`WxDataSetManager.getInstanceMeta: ${this.datasetName}, ${e}`),this.instanced&&this.metas.get(e)||this.datasetCurrentMeta}createURI(e,t,r="png"){if(u(`WxDataSetManager.createURI: ${this.datasetName}, ${e}, ${t}`),!this.checkVariableValid(e))throw new Error(`in dataset ${this.datasetName} variable ${e} not found`);let n=this.instanced?t:this.datasetCurrentInstance;return`${this.wxAPI.dataServerURL+this.datasetName}/${n}/${e}/${t}/{z}/{x}/{y}.${r}`}checkVariableValid(e){return u(`WxDataSetManager.checkVariableValid: ${this.datasetName}, ${e}`),this.getVariableMeta(e)!==void 0}checkCombineVariableIfVector(e){u(`WxDataSetManager.checkCombineVariableIfVector: ${this.datasetName}, ${e}`);let t=this.getVariableMeta(e);if(!t)throw new Error(`in dataset ${this.datasetName} variable ${e} not found`);return t.vector||[e]}createSourceLayer(e,t){u(`WxDataSetManager.createSourceLayer: ${this.datasetName}`);let r={...e,variables:this.checkCombineVariableIfVector(e.variable),wxdatasetManager:this};return new Z(r,t)}async checkDatasetOutdated(){return u(`WxDataSetManager.checkDatasetOutdated: ${this.datasetName}`),await this.wxAPI.initDone,await this.getDatasetInstance()===this.datasetCurrentInstance}async getDatasetInstance(){u(`WxDataSetManager.getDatasetInstance: ${this.datasetName}`);let e=await this.getDatasetInstances();return e[e.length-1]}async getDatasetInstances(){u(`WxDataSetManager.getDatasetInstances: ${this.datasetName}`);try{let e=await P(this.wxAPI.dataServerURL+this.datasetName+"/instances.json",this.wxAPI.requestInit);if(e.length===0)throw new Error(`No instances found for dataset ${this.datasetName}`);return e}catch(e){throw new Error(`getting dataset instances failure message: ${e.message} datasetName: ${this.datasetName} (they are likely removed from API)`)}}};var oe=class{constructor({dataServerURL:e,maskURL:t="none",maskChannel:r="R",maskDepth:n=11,qtreeURL:s="none",requestInit:i,colorStyles:o,units:m,colorSchemes:c}){this.maskURL="auto";this.datasetsMetas={allDatasetsList:[]};this.qtree=new _;this.loadMaskFunc=()=>Promise.reject(new Error("maskURL not defined"));if(u("WxAPI.constructor",e),xe({colorStyles:o,units:m,colorSchemes:c}),this.dataServerURL=e,this.requestInit=i,s=s==="auto"?e+"masks/11+1.seamask.qtree":s,t!=="none"){let l=R(Q);this.maskURL=t=t==="auto"?e+"masks/{z}/{x}/{y}.png":t,this.loadMaskFunc=f=>l(q(t,f),i)}this.maskChannel=r==="R"?0:r==="G"?1:r==="B"?2:r==="A"?3:0,this.maskDepth=n,this.initDone=Promise.all([P(e+"datasetsmeta.json",i),s!=="none"?this.qtree.load(s,i):Promise.resolve()]).then(([l,f])=>{l.allDatasetsList||(l.allDatasetsList=Object.keys(l)),this.datasetsMetas=l,u("WxAPI.constructor initDone")})}getDatasetShortMeta(e){if(u("WxAPI.getDatasetShortMeta",e),e!=="allDatasetsList")return this.datasetsMetas[e]}getDatasetInatance(e){return u("WxAPI.getDatasetInatance",e),this.getDatasetShortMeta(e)?.instance}async getDatasetVariables(e){return await this.initDone,u("WxAPI.getDatasetVariables",e),this.datasetsMetas[e]?.variables}async createDatasetManager(e){await this.initDone,u("WxAPI.createDatasetManager",e);let t=this.getDatasetShortMeta(e),r=t?.instance;if(!r)throw new Error("Dataset/instance not found:"+e);let n=t.instanced,s=c=>P(this.dataServerURL+e+"/"+c+"/meta.json",this.requestInit),i=async c=>[c,await s(c)],o=await s(r),m=new Map(n?await Promise.all(n.map(i)):[[r,o]]);return new F({datasetName:e,datasetCurrentInstance:r,datasetCurrentMeta:o,instanced:n,metas:m,wxAPI:this})}async createAllDatasetsManagers(){return await this.initDone,u("WxAPI.createAllDatasetsManagers"),Promise.allSettled(this.datasetsMetas.allDatasetsList.map(t=>this.createDatasetManager(t)))}async filterDatasetsByVariableName(e){return await this.initDone,u("WxAPI.filterDatasetsByVariableName",e),this.datasetsMetas.allDatasetsList.filter(t=>this.datasetsMetas[t]?.variables?.includes?.(e))}async getAllDatasetsNames(){return await this.initDone,u("WxAPI.getAllDatasetsNames"),this.datasetsMetas.allDatasetsList}};var ie=class{};export{ie as CustomWxTilesLayer,V as FrameworkParentClass,N as Loader,U as Painter,_ as QTree,$ as RawCLUT,u as WXLOG,oe as WxAPI,we as WxCreateLegend,F as WxDataSetManager,J as WxGetColorSchemes,A as WxGetColorStyles,B as WxLayer,Z as WxTileSource,je as WxTilesLogging};
|
|
6
|
+
time: ${e.time}`),!e.variables?.length||e.variables.length>2)throw new Error(`datasetName: ${e.wxdatasetManager.datasetName}: only 1 or 2 variables are supported but ${e.variables} was given`);e.variables.forEach(s=>{if(!e.wxdatasetManager.isVariableValid(s))throw new Error(`datasetName: ${e.wxdatasetManager.datasetName}: variable ${s} is not valid`)}),this.variables=e.variables,this.wxdatasetManager=e.wxdatasetManager,[this.tilesURIs,this._time]=this._createURLsAndTime(e.time);let t=k(),r=t.base,n=e.wxstyleName&&t[e.wxstyleName];this.currentVariableMeta=this._getCurrentVariableMeta(),[this.style,this.CLUT]=this._createStyleAndCLUT({...r,...n,...e.wxstyle})}get nonanimatable(){return m("WxLayer.nonanimatabl()"),this.variables.length<2||this.style.streamLineStatic||this.style.streamLineColor==="none"}getMaxZoom(){return m("WxLayer.getMaxZoom"),this.wxdatasetManager.isInstanced()?this.wxdatasetManager.getInstanceMeta(this.getTime()).maxZoom:this.wxdatasetManager.getMaxZoom()}getCoarseMaxZoom(){return m("WxLayer.getCoarseMaxZoom"),this.getMaxZoom()-this.coarseLevel}getBoundaries(){return this.wxdatasetManager.isInstanced()?this.wxdatasetManager.getInstanceMeta(this.getTime()).boundaries:this.wxdatasetManager.getBoundaries()}getTime(){return m("WxLayer.getTime"),this._time}clearCache(){m("WxLayer.clearCache"),this.tilesRasterCache.clear(),this._loader.clearCache()}getCurrentStyleObjectCopy(){return m("WxLayer.getCurrentStyleObjectCopy"),Object.assign({},this.style)}updateCurrentStyleObject(e){m(`WxLayer.updateCurrentStyleObject ${JSON.stringify(e)}`),[this.style,this.CLUT]=this._createStyleAndCLUT(e)}getTileData(e,t){let r=this.tilesRasterCache.get(Y(e));if(!r)return;let n=this._getPixelInfo(t,r.data.data);if(!n)return;let{raw:s,data:o}=n,i=s.map(l=>this.CLUT.colorsI[l]),u=i.map(D),c=o.map(l=>this.CLUT.DataToStyle(l));return{data:o,raw:s,rgba:i,hexColor:u,inStyleUnits:c,tilePoint:t,styleUnits:this.style.units,dataUnits:this.currentVariableMeta.units}}setURLsAndTime(e){m(`WxLayer.setURLsAndTime time=${e}`),[this.tilesURIs,this._time]=this._createURLsAndTime(e),this.wxdatasetManager.isInstanced()&&(this.currentVariableMeta=this._getCurrentVariableMeta(),[this.style,this.CLUT]=this._createStyleAndCLUT())}getPaintedCanvas(e,t,r){return this._painter.getPaintedCanvas(e,t,r)}async loadTile(e,t){return this._loadCacheDrawTile(e,this.tilesRasterCache,t)}async preloadTime(e,t,r){m(`WxLayer.preloadTime time=${e}`);let[n]=this._createURLsAndTime(e);await Promise.allSettled(t.map(s=>this._loader.cacheLoad(s,n,r)))}async reloadTiles(e,t){m("WxLayer.reloadTiles");let r=new N;await Promise.allSettled(e.map(n=>this._loadCacheDrawTile(n,r,t))),t?.signal?.aborted?r.clear():(this.tilesRasterCache.clear(),this.tilesRasterCache=r)}async _loadCacheDrawTile(e,t,r){let n=t.get(Y(e));if(n)return n;let s=await this._loader.load(e,r);if(!s)return null;let o=P(256,256),i=o,u=this.variables.length===2?P(256,256):o,c={ctxFill:o,ctxText:i,ctxStreamLines:u,data:s};return this._painter.paint(c),t.set(Y(e),c),c}_getCurrentVariableMeta(){let e=this.variables.map(o=>{let i=this.wxdatasetManager.getInstanceVariableMeta(o,this._time);if(!i)throw new Error(`datasetName ${this.wxdatasetManager.datasetName}: variable ${o} is not valid`);return i}),{min:t,max:r,units:n,vector:s}=e[0];return this.variables.length>1&&(t=0,r=1.42*Math.max(-e[0].min,e[0].max,-e[1].min,e[1].max)),{min:t,max:r,units:n,vector:s}}_getPixelInfo({x:e,y:t},r){m(`WxLayer._getPixelInfo x=${e} y=${t}`);let n=(t+1)*258+(e+1);if(r?.[0]?.raw?.[n])return{raw:r.map(s=>s.raw[n]),data:r.map(s=>s.raw[n]*s.dmul+s.dmin)}}_createStyleAndCLUT(e){let t=Object.assign({},this.style,e),r=this._prepareCLUT(t);return[t,r]}_prepareCLUT(e){let{min:t,max:r,units:n}=this.currentVariableMeta;return new G(e,n,[t,r],this.variables.length===2)}_createURLsAndTime(e){let t=this.wxdatasetManager.getNearestValidTime(e);return[this.variables.map(n=>this.wxdatasetManager.createURI(n,t)),t]}};var Ae=Fe(ke()),z=class extends Ae.default.GridLayer{constructor(t){super(t);this.id=t.id}};var $=class extends z{constructor(t,r){m(`WxLayerBaseImplementation.constructor (${r.id})`);super(r);this._animation=!1;this._animationSeed=0;this._needUpdateDSManager=!1;this._layer=new B(t)}get wxdatasetManager(){return m(`WxLayerBaseImplementation.wxdatasetManager (${this.id})`),this._layer.wxdatasetManager}getCurrentVariableMeta(){return m(`WxLayerBaseImplementation.getCurrentVariableMeta (${this.id})`),{...this._layer.currentVariableMeta}}getDatasetMeta(){return this._layer.wxdatasetManager.getInstanceMeta(this.getTime())}getMetadata(){return m(`WxLayerBaseImplementation.getMetadata (${this.id})`),{...this._layer.currentVariableMeta}}getVariablesNames(){return m(`WxLayerBaseImplementation.getVariables (${this.id})`),[...this._layer.variables]}clearCache(){m(`WxLayerBaseImplementation.clearCache (${this.id})`),this._layer.clearCache()}getCache(){return this._layer.tilesRasterCache}getCurrentStyleObjectCopy(){return m(`WxLayerBaseImplementation.getCurrentStyleObjectCopy (${this.id})`),this._layer.getCurrentStyleObjectCopy()}getTime(){return m(`WxLayerBaseImplementation.getTime (${this.id})`),this._layer.getTime()}getAllTimes(){return m(`WxLayerBaseImplementation.getTimes (${this.id})`),this._layer.wxdatasetManager.getAllTimes()}async setTime(t,r){m(`WxLayerBaseImplementation.setTime (${this.id}) time=${t}`);let n=this.getTime();return this._layer.setURLsAndTime(t),await this._reloadVisible(r),r?.signal?.aborted&&this._layer.setURLsAndTime(n),this.getTime()}async preloadTime(t,r){return m(`WxLayerBaseImplementation.preloadTime (${this.id}) time=${t}`),this._layer.preloadTime(t,this.coveringTiles(),r)}startAnimation(){if(this._animation){m(`WxLayerBaseImplementation.startAnimation (${this.id}) already started`);return}if(this._layer.nonanimatable){m(`WxLayerBaseImplementation.startAnimation (${this.id}) nonanimatable`);return}m(`WxLayerBaseImplementation.startAnimation (${this.id})`),this._animation=!0;let t=async r=>{if(m(`WxLayerBaseImplementation.startAnimation (${this.id}) animationStep`),!this._animation||this._layer.nonanimatable){this._animation=!1;return}this._animationSeed=r,await this._redrawTiles(),requestAnimationFrame(t)};requestAnimationFrame(t)}async stopAnimation(){return m(`WxLayerBaseImplementation.stopAnimation (${this.id})`),this._animation=!1,this._redrawTiles()}async setCoarseLevel(t=2){this._layer.coarseLevel=Math.max(0,Math.min(t,this.wxdatasetManager.getMaxZoom()))}async unsetCoarseLevel(){return this._layer.coarseLevel=0,this._reloadVisible()}async setStyleByName(t,r=!0){return m(`WxLayerBaseImplementation.setStyleByName (${this.id}) wxstyleName=${t} reload=${r}`),this.updateCurrentStyleObject(k()[t],r)}async updateCurrentStyleObject(t,r=!0,n){if(m(`WxLayerBaseImplementation.updateCurrentStyleObject (${this.id}) style=${t} reload=${r}`),this._layer.updateCurrentStyleObject(t),this.startAnimation(),r)return this._reloadVisible(n)}_redrawTiles(){return this._redrawRequested?this._redrawRequested:(this._redrawRequested=new Promise(t=>{requestAnimationFrame(()=>{m(`WxTileSource _redrawTiles (${this.id})`),this.update(),t(),this._redrawRequested=void 0})}),this._redrawRequested)}async _reloadVisible(t){}coveringTiles(){return[]}update(){}async _loadTileHelper(t,r){let n=null;if(!this._needUpdateDSManager)try{n=await this._layer.loadTile(t,r)}catch(s){if(s.name==="AbortError")throw s;s.reason==="instance-not-found"&&!this._needUpdateDSManager&&(this._needUpdateDSManager=!0,m(`WxTileSource.loadTile (${this.id}) instance-not-found. Trying to update wxdatasetManager and load again.`),this.wxdatasetManager.update().then(()=>{this._needUpdateDSManager=!1,this.setTime(this.getTime()).then(()=>this.fire("changed",this))}).catch(o=>{m(`WxTileSource.loadTile (${this.id}) instance-not-found. wxdatasetManager update failed.`,o)}))}return n}};var H=class{constructor(e,t,r){this.coords=e;this.ctx=t;this.raster_data=r;this.draw(r?.ctxFill.canvas)}draw(e){this.ctx.clearRect(0,0,256,256),e&&this.ctx.drawImage(e,0,0)}},Z=class extends ${constructor(e,t){super(e,t),m("WxTileSource constructor: ",e)}getLayerInfoAtLatLon(e,t){if(m(`WxTileSource getLayerInfoAtLatLon (${this._layer.wxdatasetManager.datasetName})`,e),!this._map)return;let r=this._map.getZoom(),n=this._map.project(e,r),s=n.divideBy(256).floor(),o=n.subtract(s.multiplyBy(256)).floor();return this._layer.getTileData({x:s.x,y:s.y,z:r},o)}async _reloadVisible(e){if(m(`WxTileSource _reloadVisible (${this._layer.wxdatasetManager.datasetName})`),await this._layer.reloadTiles(this.coveringTiles(),e),e?.signal?.aborted){m(`WxTileSource _reloadVisible (${this._layer.wxdatasetManager.datasetName}) aborted`);return}return await Promise.allSettled(this._ForEachWxTile(async t=>{t.raster_data=null,t.raster_data=await this._layer.loadTile(t.coords)},"_reloadVisible")),this._redrawTiles()}coveringTiles(){m(`WxTileSource coveringTiles (${this._layer.wxdatasetManager.datasetName})`);let e=[];for(let t in this._tiles){let r=this._tiles[t].el?.wxtile;r&&e.push(r.coords)}return e}update(){m(`WxTileSource update (${this._layer.wxdatasetManager.datasetName})`),this._ForEachWxTile(e=>{e.draw(e.raster_data&&this._layer.getPaintedCanvas(e.raster_data,this._animation,this._animationSeed))},"_redrawTiles")}_ForEachWxTile(e,t){m(`WxTileSource _ForEachWxTile (${this._layer.wxdatasetManager.datasetName}) func=${t}`);let r=[];for(let n in this._tiles){let s=this._tiles[n].el?.wxtile;s&&r.push(e(s))}return r}createTile(e,t){let r=P(256,256),n=r.canvas;return this._loadTileHelper(e).then(s=>{n.wxtile=new H(e,r,s)}).catch(()=>{n.wxtile=new H(e,r,null)}).finally(t),n}onRemove(e){return super.onRemove(e),m(`WxTileSource onRemove (${this._layer.wxdatasetManager.datasetName})`),this._animation=!1,this}};var V=class{constructor({datasetName:e,datasetCurrentInstance:t,instanced:r,datasetCurrentMeta:n,metas:s,wxAPI:o}){this.datasetName=e,this._instanced=r,this._datasetCurrentInstance=t,this._datasetCurrentMeta=n,this._metas=s,this.wxAPI=o,m(`WxDataSetManager.constructor: ${this.datasetName}`)}createSourceLayer(e,t){m(`WxDataSetManager.createSourceLayer: ${this.datasetName}`);let r={...e,variables:this._checkCombineVariableIfVector(e.variable),wxdatasetManager:this};return new Z(r,t)}getNearestValidTime(e=Date()){m(`WxDataSetManager.getValidTime: ${this.datasetName}, ${e}`);let t=this.getAllTimes();if(e==="")return t[t.length-1];if(typeof e=="string"){let s=t.indexOf(e);if(s!==-1)return t[s]}if(typeof e=="number"){if(e<=0)return t[0];if(e<t.length)return t[e]}let r=new Date(e).getTime();return isNaN(r)?t[t.length-1]:t.find(s=>new Date(s).getTime()>=r)||t[t.length-1]}getAllTimes(){return m(`WxDataSetManager.getTimes: ${this.datasetName}`),this._instanced||this._datasetCurrentMeta.times}getAllVariables(){return m(`WxDataSetManager.getVariables: ${this.datasetName}`),this._datasetCurrentMeta.variables}getVariableCurrentMeta(e){return m(`WxDataSetManager.getVariableCurrentMeta: ${this.datasetName}, ${e}`),this._datasetCurrentMeta.variablesMeta[e]}getInstanceVariableMeta(e,t){return m(`WxDataSetManager.getInstanceVariableMeta: ${this.datasetName}, ${e}, ${t}`),this.getInstanceMeta(t).variablesMeta[e]}getMaxZoom(){return m(`WxDataSetManager.getMaxZoom: ${this.datasetName}`),this._datasetCurrentMeta.maxZoom}getBoundaries(){return m(`WxDataSetManager.getBoundaries: ${this.datasetName}`),this._datasetCurrentMeta.boundaries}getInstanceMeta(e){return m(`WxDataSetManager.getInstanceMeta: ${this.datasetName}, ${e}`),e&&this._metas?.get(e)||this._datasetCurrentMeta}createURI(e,t,r="webp"){if(m(`WxDataSetManager.createURI: ${this.datasetName}, ${e}, ${t}`),!this.isVariableValid(e))throw new Error(`in dataset ${this.datasetName} variable ${e} not found`);let n=this._instanced?t:this._datasetCurrentInstance;return`${this.wxAPI.dataServerURL+this.datasetName}/${n}/${e}/${t}/{z}/{x}/{y}.${r}`}isVariableValid(e){return m(`WxDataSetManager.checkVariableValid: ${this.datasetName}, ${e}`),this._datasetCurrentMeta.variablesMeta[e]!==void 0}async update(){let e=await this.wxAPI.createDatasetManager(this.datasetName);this._datasetCurrentInstance=e._datasetCurrentInstance,this._instanced=e._instanced,this._datasetCurrentMeta=e._datasetCurrentMeta,this._metas=e._metas}isInstanced(){return this._instanced!==void 0}_checkCombineVariableIfVector(e){m(`WxDataSetManager.checkCombineVariableIfVector: ${this.datasetName}, ${e}`);let t=this._datasetCurrentMeta.variablesMeta[e];if(!t)throw new Error(`in dataset ${this.datasetName} variable ${e} not found`);return t.vector||[e]}},K=class{constructor(e){this.wxAPI=e;this.allDatasetsShortMetas={};this.ready=this.updateAll()}updateAll(){return this.ready=v(this.wxAPI.dataServerURL+"meta.json",this.wxAPI.requestInit),this.ready.then(e=>this.allDatasetsShortMetas=e),this.ready}async updateOne(e){try{let t=this.wxAPI.dataServerURL+e+"/meta.json",r=await v(t,this.wxAPI.requestInit);return Object.assign(this.allDatasetsShortMetas,r)}catch{return this.updateAll()}}};var oe=class{constructor({dataServerURL:e,maskURL:t="none",maskChannel:r="R",maskDepth:n=11,qtreeURL:s="none",requestInit:o,colorStyles:i,units:u,colorSchemes:c}){if(m("WxAPI.constructor",e),xe({colorStyles:i,units:u,colorSchemes:c}),s==="auto"&&(s=e+"masks/11+1.seamask.qtree"),t==="auto"&&(t=e+"masks/{z}/{x}/{y}.webp"),this.dataServerURL=e,this.requestInit=o,this.maskURL=t,this.maskChannel=r==="R"?0:r==="G"?1:r==="B"?2:r==="A"?3:0,this.maskDepth=n,this.maskURL!=="none"){let l=E(ee);this.loadMaskFunc=f=>l(O(this.maskURL,f),o)}else this.loadMaskFunc=()=>Promise.reject(new Error("maskURL not defined"));this._allDatasetsManager=new K(this),this.qtree=new A(s,o),this.initDone=Promise.all([this._allDatasetsManager.ready,this.qtree.ready]).then(()=>m("WxAPI.constructor initDone"))}async createDatasetManager(e){await this.initDone,await this._allDatasetsManager.updateOne(e),m("WxAPI.createDatasetManager",e);let t=this._allDatasetsManager.allDatasetsShortMetas[e],r=t?.instance;if(!r)throw new Error("Dataset/instance not found:"+e);let n=t.instanced,s=await v(this.dataServerURL+e+"/metafull.json"),o=s[0],i=n&&new Map(s.map(u=>[u.instance,u]));return new V({datasetName:e,datasetCurrentInstance:r,datasetCurrentMeta:o,instanced:n,metas:i,wxAPI:this})}async getDatasetAllVariables(e){return await this.initDone,m("WxAPI.getDatasetVariables",e),this._allDatasetsManager.allDatasetsShortMetas[e]?.variables}async filterDatasetsByVariableName(e){await this.initDone,m("WxAPI.filterDatasetsByVariableName:",e);let{allDatasetsShortMetas:t}=this._allDatasetsManager;return Object.keys(t).filter(r=>t[r].variables.includes(e))}async getAllDatasetsNames(){return await this.initDone,m("WxAPI.getAllDatasetsNames"),Object.keys(this._allDatasetsManager.allDatasetsShortMetas)}};var ie=class{};export{ie as CustomWxTilesLayer,X as DataIntegral,R as Loader,U as Painter,A as QTree,N as TilesCache,m as WXLOG,oe as WxAPI,ve as WxCreateLegend,V as WxDataSetManager,Q as WxGetColorSchemes,k as WxGetColorStyles,B as WxLayer,$ as WxLayerBaseImplementation,Z as WxTileSource,Ge as WxTilesLogging};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Converter, WxColorStyleStrict } from './wxtools';
|
|
1
|
+
import type { Converter, WxColorStyleStrict } from './wxtools';
|
|
2
2
|
/** data values of the legend */
|
|
3
3
|
export interface WxTick {
|
|
4
4
|
/** the data value */
|
|
@@ -11,6 +11,7 @@ export interface WxTick {
|
|
|
11
11
|
pos: number;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
+
* @internal
|
|
14
15
|
* Class contains information about the color style and the legend
|
|
15
16
|
* Based on the idea of CLUT (Color Look Up Table) to fill tiles with colors from the style
|
|
16
17
|
*/
|
|
@@ -26,12 +27,12 @@ export declare class RawCLUT {
|
|
|
26
27
|
/** data values of the legend */
|
|
27
28
|
ticks: WxTick[];
|
|
28
29
|
/**
|
|
29
|
-
* @param style the color style
|
|
30
|
-
* @param dUnits the units of the data
|
|
31
|
-
* @param minmax the array of minimum and maximum data values
|
|
32
|
-
* @param vector if true, the style is for vector data
|
|
30
|
+
* @param {WxColorStyleStrict} style the color style
|
|
31
|
+
* @param {string} dUnits the units of the data
|
|
32
|
+
* @param {[number, number]} minmax the array of minimum and maximum data values
|
|
33
|
+
* @param {boolean} vector if true, the style is for vector data
|
|
33
34
|
* */
|
|
34
|
-
constructor(style: WxColorStyleStrict, dUnits: string, [
|
|
35
|
+
constructor(style: WxColorStyleStrict, dUnits: string, [dataMin, dataMax]: [number, number], vector: boolean);
|
|
35
36
|
}
|
|
36
37
|
/** Legend - data structure that contains information for rendering legends */
|
|
37
38
|
export interface WxLegend {
|
|
@@ -49,8 +50,8 @@ export interface WxLegend {
|
|
|
49
50
|
ticks: WxTick[];
|
|
50
51
|
}
|
|
51
52
|
/** Create a legend for a given color style
|
|
52
|
-
* @param
|
|
53
|
+
* @param legendSize - number of colors in the legend
|
|
53
54
|
* @param style - color style
|
|
54
55
|
* @returns legend
|
|
55
56
|
* */
|
|
56
|
-
export declare function WxCreateLegend(
|
|
57
|
+
export declare function WxCreateLegend(legendSize: number, style: WxColorStyleStrict): WxLegend;
|
package/dist/es/utils/qtree.d.ts
CHANGED
|
@@ -17,9 +17,11 @@ export declare enum TileType {
|
|
|
17
17
|
}
|
|
18
18
|
/** class QTree utilizes quad-tree structure to get the type of the tile at the given coord */
|
|
19
19
|
export declare class QTree {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
protected _qtree: Tree;
|
|
21
|
+
protected _qtreedepth: number;
|
|
22
|
+
protected _ready: Promise<void>;
|
|
23
|
+
constructor(input: RequestInfo, requestInit?: RequestInit | undefined);
|
|
24
|
+
get ready(): Promise<void>;
|
|
25
|
+
protected _load(input: RequestInfo, requestInit?: RequestInit | undefined): Promise<void>;
|
|
24
26
|
check(coord: XYZ): TileType;
|
|
25
27
|
}
|
|
@@ -51,6 +51,10 @@ export interface WxColorStyleStrict {
|
|
|
51
51
|
isolineColor: 'none' | 'inverted' | 'fill' | `#${string}`;
|
|
52
52
|
/** if true then render isoline text values */
|
|
53
53
|
isolineText: boolean;
|
|
54
|
+
/** Font size of isoline text values in ems */
|
|
55
|
+
isolineTextSizeEm: number;
|
|
56
|
+
/** if true then render a solid background behind isoline text values */
|
|
57
|
+
isolineTextBackground: boolean;
|
|
54
58
|
/**
|
|
55
59
|
* Representation of the wind/current field.
|
|
56
60
|
* - **'none'** do not render vectors.
|
|
@@ -123,7 +127,7 @@ export interface WxColorStyleStrict {
|
|
|
123
127
|
* - **'land'** - make land transparent.
|
|
124
128
|
* */
|
|
125
129
|
mask?: 'land' | 'sea' | 'none';
|
|
126
|
-
/** If
|
|
130
|
+
/** If exists then try to use WebGL to render tiles */
|
|
127
131
|
gl?: {
|
|
128
132
|
animationSpeed?: number;
|
|
129
133
|
noiseTexturePow?: number;
|
|
@@ -163,7 +167,7 @@ export declare function WxGetColorStyles(): WxColorStylesStrict;
|
|
|
163
167
|
* */
|
|
164
168
|
export declare function WxGetColorSchemes(): WxColorSchemes;
|
|
165
169
|
/** A function type with extra properties. */
|
|
166
|
-
export interface Converter {
|
|
170
|
+
export interface Converter extends Function {
|
|
167
171
|
/** interface of a function - unit cinverter*/
|
|
168
172
|
(x: number): number;
|
|
169
173
|
/** true if the converter is a trivial one */
|
|
@@ -183,9 +187,15 @@ export interface Converter {
|
|
|
183
187
|
* */
|
|
184
188
|
export declare function makeConverter(from: string, to: string, customUnits?: WxUnits): Converter;
|
|
185
189
|
/** Function type to load image from URL, with additional properties */
|
|
186
|
-
|
|
190
|
+
interface UriLoaderPromiseFunc<T> extends Function {
|
|
191
|
+
(url: string, ...props: any): Promise<T>;
|
|
192
|
+
}
|
|
193
|
+
export interface CachedUriLoaderPromiseFunc<T> extends UriLoaderPromiseFunc<T> {
|
|
194
|
+
(url: string, ...props: any): Promise<T>;
|
|
195
|
+
clearCache: () => void;
|
|
196
|
+
}
|
|
187
197
|
/** Makes a cachable function that loads image from URL, with additional properties */
|
|
188
|
-
export declare function cacheUriPromise<T>(fn: UriLoaderPromiseFunc<T>):
|
|
198
|
+
export declare function cacheUriPromise<T>(fn: UriLoaderPromiseFunc<T>): CachedUriLoaderPromiseFunc<T>;
|
|
189
199
|
/**
|
|
190
200
|
* abortable 'loadImage'
|
|
191
201
|
* @param url - image url
|
|
@@ -216,7 +226,7 @@ export declare class DataIntegral implements DataPicture {
|
|
|
216
226
|
dmin: number;
|
|
217
227
|
dmax: number;
|
|
218
228
|
dmul: number;
|
|
219
|
-
|
|
229
|
+
protected integral_?: IntegralPare;
|
|
220
230
|
radius: number;
|
|
221
231
|
constructor(raw: Uint16Array, dmin: number, dmax: number, dmul: number);
|
|
222
232
|
get integral(): IntegralPare;
|
|
@@ -348,3 +358,4 @@ export declare function uriXYZ(uri: string, { x, y, z }: XYZ): string;
|
|
|
348
358
|
* @returns string hash
|
|
349
359
|
* */
|
|
350
360
|
export declare function HashXYZ({ x, y, z }: XYZ): string;
|
|
361
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import './wxtiles.css';
|
|
2
|
+
import { XYZ } from '../utils/wxtools';
|
|
3
|
+
import { QTree } from '../utils/qtree';
|
|
4
|
+
import { WxDataSetManager } from './WxDataSetManager';
|
|
5
|
+
import { WxAllDatasetsManager } from './WxDataSetManager';
|
|
6
|
+
import { WxAPIOptions } from './WxAPItypes';
|
|
7
|
+
/**
|
|
8
|
+
* WxAPI is an initialisation object for the library. See {@link WxAPIOptions} for options.
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { WxAPI } from 'wx-tiles';
|
|
12
|
+
* const wxapi = new WxAPI({
|
|
13
|
+
* dataServerURL: 'https://server.com/',
|
|
14
|
+
* // other options
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class WxAPI {
|
|
19
|
+
/** resolved when {@link WxAPI} is ready to be used */
|
|
20
|
+
readonly initDone: Promise<void>;
|
|
21
|
+
/** see {@link WxAPIOptions}*/
|
|
22
|
+
readonly dataServerURL: string;
|
|
23
|
+
/** see {@link WxAPIOptions}*/
|
|
24
|
+
readonly requestInit?: RequestInit;
|
|
25
|
+
/************************/
|
|
26
|
+
/************************/
|
|
27
|
+
/** @internal see {@link WxAPIOptions}*/
|
|
28
|
+
readonly maskURL: string;
|
|
29
|
+
/** @internal see {@link WxAPIOptions}*/
|
|
30
|
+
readonly maskChannel: number;
|
|
31
|
+
/** @internal see {@link WxAPIOptions}*/
|
|
32
|
+
readonly maskDepth: number;
|
|
33
|
+
/** @internal instance of the qtree object */
|
|
34
|
+
readonly qtree: QTree;
|
|
35
|
+
/** @internal function to load mask tiles */
|
|
36
|
+
readonly loadMaskFunc: ({ x, y, z }: XYZ) => Promise<ImageData>;
|
|
37
|
+
/** @ignore @internal a manager for all datasets. Operates with short datasets*/
|
|
38
|
+
protected readonly _allDatasetsManager: WxAllDatasetsManager;
|
|
39
|
+
/************************/
|
|
40
|
+
/************************/
|
|
41
|
+
/** @param options - see {@link WxAPIOptions} */
|
|
42
|
+
constructor({ dataServerURL, maskURL, maskChannel, maskDepth, qtreeURL, requestInit, colorStyles, units, colorSchemes, }: WxAPIOptions);
|
|
43
|
+
/**
|
|
44
|
+
* Create {@link WxDataSetManager} object for the given dataset name.
|
|
45
|
+
* @param datasetName - dataset name
|
|
46
|
+
* @returns {Promise<WxDataSetManager>} - WxDataSetManager object for the given dataset name */
|
|
47
|
+
createDatasetManager(datasetName: string): Promise<WxDataSetManager>;
|
|
48
|
+
/**
|
|
49
|
+
* Get all variables for the given dataset name.
|
|
50
|
+
* @param datasetName - dataset name
|
|
51
|
+
* @returns {Promise<string[]>} - list of all available variables for the dataset */
|
|
52
|
+
getDatasetAllVariables(datasetName: string): Promise<string[] | undefined>;
|
|
53
|
+
/**
|
|
54
|
+
* Returns datasets names which have given variable
|
|
55
|
+
* @argument {string} varName - variable name to search for in datasets
|
|
56
|
+
* @returns {Promise<string[]>} - list of datasets' names */
|
|
57
|
+
filterDatasetsByVariableName(varName: string): Promise<string[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Get the list of all available datasets' names
|
|
60
|
+
* @returns {Promise<string[]>} - list of all available datasets' names
|
|
61
|
+
* */
|
|
62
|
+
getAllDatasetsNames(): Promise<string[]>;
|
|
63
|
+
}
|