@metoceanapi/wxtiles-common 0.0.10 → 0.0.11-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/.github/workflows/lint.yml +1 -1
- package/.github/workflows/validate-pull-request-title.yml +17 -0
- package/LICENSE.txt +1 -1
- package/biome.json +16 -3
- package/controls/WxAPIControl/WxAPIControl-busy.ts +16 -0
- package/controls/WxAPIControl/WxAPIControl-datasets.ts +102 -0
- package/controls/WxAPIControl/WxAPIControl-filter.ts +66 -0
- package/controls/WxAPIControl/WxAPIControl-variables.ts +73 -0
- package/controls/WxAPIControl.ts +87 -120
- package/controls/WxInfoControl.ts +87 -2
- package/controls/WxLegendControl.ts +28 -2
- package/controls/WxStyleEditorControl.ts +129 -7
- package/controls/WxTimeControl.ts +133 -5
- package/docs/docs/.nojekyll +1 -0
- package/docs/docs/assets/highlight.css +92 -0
- package/docs/docs/assets/icons.svg +1 -0
- package/docs/docs/assets/style.css +1610 -0
- package/docs/docs/classes/controls_WxAPIControl.WxAPIControl.html +28 -0
- package/docs/docs/classes/controls_WxInfoControl.WxInfoControl.html +20 -0
- package/docs/docs/classes/controls_WxLegendControl.WxLegendControl.html +19 -0
- package/docs/docs/classes/controls_WxStyleEditorControl.WxStyleEditorControl.html +111 -0
- package/docs/docs/classes/controls_WxTimeControl.WxTimeControl.html +28 -0
- package/docs/docs/classes/managers_BaseDatasetManager.BaseDatasetManager.html +104 -0
- package/docs/docs/classes/managers_WxAllDatasetsManager.WxAllDatasetsManager.html +24 -0
- package/docs/docs/classes/types.WxRasterDataCache.html +27 -0
- package/docs/docs/classes/utils_RawCLUT.RawCLUT.html +18 -0
- package/docs/docs/classes/utils_qtree.QTree.html +22 -0
- package/docs/docs/classes/utils_wxtools.DataIntegral.html +10 -0
- package/docs/docs/classes/wxapi.WxAPI.html +45 -0
- package/docs/docs/classes/wxlayer_loader.Loader.html +31 -0
- package/docs/docs/classes/wxlayer_painter.Painter.html +20 -0
- package/docs/docs/classes/wxlayer_wxlayer.WxLayer.html +57 -0
- package/docs/docs/enums/utils_qtree.TileType.html +5 -0
- package/docs/docs/functions/utils_RawCLUT.WxCreateLegend.html +5 -0
- package/docs/docs/functions/utils_mercator.LatLonToPixels.html +6 -0
- package/docs/docs/functions/utils_mercator.PixelsToLatLon.html +6 -0
- package/docs/docs/functions/utils_mercator.PixelsToLonLat.html +6 -0
- package/docs/docs/functions/utils_mercator.coordToPixel.html +5 -0
- package/docs/docs/functions/utils_tests_wxtools.tests.html +1 -0
- package/docs/docs/functions/utils_wxtools.HEXtoRGBA.html +3 -0
- package/docs/docs/functions/utils_wxtools.HashXYZ.html +4 -0
- package/docs/docs/functions/utils_wxtools.RGBAtoHEX.html +3 -0
- package/docs/docs/functions/utils_wxtools.RGBtoHEX.html +3 -0
- package/docs/docs/functions/utils_wxtools.WXLOG.html +2 -0
- package/docs/docs/functions/utils_wxtools.WxGetColorSchemes.html +2 -0
- package/docs/docs/functions/utils_wxtools.WxGetColorStyles.html +2 -0
- package/docs/docs/functions/utils_wxtools.WxTilesLibSetup.html +3 -0
- package/docs/docs/functions/utils_wxtools.WxTilesLogging.html +5 -0
- package/docs/docs/functions/utils_wxtools.blurData.html +7 -0
- package/docs/docs/functions/utils_wxtools.buildIntegralPare.html +6 -0
- package/docs/docs/functions/utils_wxtools.cacheUriPromise.html +2 -0
- package/docs/docs/functions/utils_wxtools.create2DContext.html +6 -0
- package/docs/docs/functions/utils_wxtools.createEl.html +5 -0
- package/docs/docs/functions/utils_wxtools.createLevels.html +6 -0
- package/docs/docs/functions/utils_wxtools.fetchJson.html +6 -0
- package/docs/docs/functions/utils_wxtools.getClosestTimeString.html +5 -0
- package/docs/docs/functions/utils_wxtools.loadDataIntegral.html +5 -0
- package/docs/docs/functions/utils_wxtools.loadImage.html +4 -0
- package/docs/docs/functions/utils_wxtools.loadImageData.html +5 -0
- package/docs/docs/functions/utils_wxtools.makeConverter.html +9 -0
- package/docs/docs/functions/utils_wxtools.mixColor.html +3 -0
- package/docs/docs/functions/utils_wxtools.refineColor.html +3 -0
- package/docs/docs/functions/utils_wxtools.uriXYZ.html +5 -0
- package/docs/docs/functions/wxlayer_WxImplementation.WxLayerBaseImplementationMixin.html +4 -0
- package/docs/docs/functions/wxlayer_loadertools.applyMask.html +10 -0
- package/docs/docs/functions/wxlayer_loadertools.makeBox.html +4 -0
- package/docs/docs/functions/wxlayer_loadertools.splitCoords.html +6 -0
- package/docs/docs/functions/wxlayer_loadertools.subData.html +5 -0
- package/docs/docs/functions/wxlayer_loadertools.subDataDegree.html +5 -0
- package/docs/docs/functions/wxlayer_loadertools.subMask.html +5 -0
- package/docs/docs/hierarchy.html +1 -0
- package/docs/docs/index.html +7 -0
- package/docs/docs/interfaces/types.IsoInfo.html +8 -0
- package/docs/docs/interfaces/types.SLinePoint.html +4 -0
- package/docs/docs/interfaces/types.WxAPIOptions.html +37 -0
- package/docs/docs/interfaces/types.WxAllBoundariesMeta.html +8 -0
- package/docs/docs/interfaces/types.WxAllDatasetsShortMetas.html +4 -0
- package/docs/docs/interfaces/types.WxBoundaryMeta.html +10 -0
- package/docs/docs/interfaces/types.WxData.html +10 -0
- package/docs/docs/interfaces/types.WxDataSetManagerOptions.html +14 -0
- package/docs/docs/interfaces/types.WxDatasetMeta.html +20 -0
- package/docs/docs/interfaces/types.WxDatasetShortMeta.html +9 -0
- package/docs/docs/interfaces/types.WxLayerAPI.html +24 -0
- package/docs/docs/interfaces/types.WxLayerBaseAPI.html +16 -0
- package/docs/docs/interfaces/types.WxLayerOptions.html +12 -0
- package/docs/docs/interfaces/types.WxLngLat.html +6 -0
- package/docs/docs/interfaces/types.WxRasterData.html +13 -0
- package/docs/docs/interfaces/types.WxRequestInit.html +3 -0
- package/docs/docs/interfaces/types.WxTileInfo.html +18 -0
- package/docs/docs/interfaces/types.WxVariableMeta.html +13 -0
- package/docs/docs/interfaces/types.WxVariablesMetas.html +4 -0
- package/docs/docs/interfaces/utils_RawCLUT.WxLegend.html +14 -0
- package/docs/docs/interfaces/utils_RawCLUT.WxTick.html +10 -0
- package/docs/docs/interfaces/utils_qtree.Tree.html +7 -0
- package/docs/docs/interfaces/utils_wxtools.CachedUriLoaderPromiseFunc.html +2 -0
- package/docs/docs/interfaces/utils_wxtools.ColorStylesIncomplete.html +2 -0
- package/docs/docs/interfaces/utils_wxtools.Converter.html +5 -0
- package/docs/docs/interfaces/utils_wxtools.DataPicture.html +6 -0
- package/docs/docs/interfaces/utils_wxtools.IntegralPare.html +6 -0
- package/docs/docs/interfaces/utils_wxtools.WxColorSchemes.html +3 -0
- package/docs/docs/interfaces/utils_wxtools.WxColorStyleStrict.html +95 -0
- package/docs/docs/interfaces/utils_wxtools.WxColorStyleWeak.html +95 -0
- package/docs/docs/interfaces/utils_wxtools.WxColorStylesStrict.html +2 -0
- package/docs/docs/interfaces/utils_wxtools.WxColorStylesWeakMixed.html +2 -0
- package/docs/docs/interfaces/utils_wxtools.WxTilesLibOptions.html +8 -0
- package/docs/docs/interfaces/utils_wxtools.WxUnits.html +2 -0
- package/docs/docs/interfaces/utils_wxtools.XYZ.html +5 -0
- package/docs/docs/modules/controls_WxAPIControl.html +1 -0
- package/docs/docs/modules/controls_WxInfoControl.html +1 -0
- package/docs/docs/modules/controls_WxLegendControl.html +1 -0
- package/docs/docs/modules/controls_WxStyleEditorControl.html +1 -0
- package/docs/docs/modules/controls_WxTimeControl.html +1 -0
- package/docs/docs/modules/defaults_colorschemes.html +1 -0
- package/docs/docs/modules/defaults_styles.html +1 -0
- package/docs/docs/modules/defaults_uconv.html +1 -0
- package/docs/docs/modules/managers_BaseDatasetManager.html +1 -0
- package/docs/docs/modules/managers_WxAllDatasetsManager.html +1 -0
- package/docs/docs/modules/types.html +1 -0
- package/docs/docs/modules/utils_RawCLUT.html +1 -0
- package/docs/docs/modules/utils_mercator.html +1 -0
- package/docs/docs/modules/utils_qtree.html +1 -0
- package/docs/docs/modules/utils_tests_wxtools.html +1 -0
- package/docs/docs/modules/utils_wxtools.html +1 -0
- package/docs/docs/modules/wxapi.html +1 -0
- package/docs/docs/modules/wxlayer_WxImplementation.html +1 -0
- package/docs/docs/modules/wxlayer_loader.html +1 -0
- package/docs/docs/modules/wxlayer_loadertools.html +1 -0
- package/docs/docs/modules/wxlayer_painter.html +1 -0
- package/docs/docs/modules/wxlayer_wxlayer.html +1 -0
- package/docs/docs/modules.html +1 -0
- package/docs/docs/types/types.ListenerMethod.html +1 -0
- package/docs/docs/types/types.SLine.html +2 -0
- package/docs/docs/types/types.WxDate.html +9 -0
- package/docs/docs/types/types.WxEventType.html +1 -0
- package/docs/docs/types/types.WxInstances.html +2 -0
- package/docs/docs/types/types.WxLayerVarsNames.html +2 -0
- package/docs/docs/types/types.WxURIs.html +2 -0
- package/docs/docs/types/utils_qtree.SubTrees.html +2 -0
- package/docs/docs/types/utils_qtree.SubTreesN.html +2 -0
- package/docs/docs/types/utils_qtree.TreeN.html +2 -0
- package/docs/docs/types/utils_wxtools.DataIntegrals.html +2 -0
- package/docs/docs/types/utils_wxtools.DataPictures.html +2 -0
- package/docs/docs/types/utils_wxtools.WxUnitTuple.html +2 -0
- package/docs/docs/types/utils_wxtools.colorMapTuple.html +2 -0
- package/docs/docs/variables/defaults_colorschemes.__colorSchemes_default_preset.html +1 -0
- package/docs/docs/variables/defaults_styles.__colorStyles_default_preset.html +1 -0
- package/docs/docs/variables/defaults_uconv.__units_default_preset.html +1 -0
- package/managers/BaseDatasetManager.ts +2 -4
- package/managers/WxAllDatasetsManager.ts +1 -1
- package/package.json +5 -3
- package/tsconfig.json +31 -0
- package/typedoc.json +4 -0
- package/types.ts +1 -1
- package/utils/qtree.ts +2 -1
- package/utils/tests_wxtools.ts +10 -10
- package/utils/wxtools.ts +1 -0
- package/wxapi.ts +3 -4
- package/wxlayer/WxImplementation.ts +8 -6
- package/wxlayer/loadertools.ts +14 -10
- package/wxlayer/painter.ts +4 -4
|
@@ -1,43 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents information about a weather tile, including its data,
|
|
3
|
+
* style units, and associated metadata.
|
|
4
|
+
*/
|
|
1
5
|
declare interface WxTileInfo {
|
|
6
|
+
/**
|
|
7
|
+
* @param data - Array of numerical data values associated with the tile.
|
|
8
|
+
* @param inStyleUnits - Array of numerical values converted to style units.
|
|
9
|
+
* @param styleUnits - A string representing the unit type used for styling the tile.
|
|
10
|
+
* @param dataUnits - A string representing the unit type of the raw data values.
|
|
11
|
+
*/
|
|
2
12
|
data: number[];
|
|
3
13
|
inStyleUnits: number[];
|
|
4
14
|
styleUnits: string;
|
|
5
15
|
dataUnits: string;
|
|
6
16
|
}
|
|
7
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Represents metadata about a weather dataset, including its source ID,
|
|
20
|
+
* atmospheric model, and general model information.
|
|
21
|
+
*
|
|
22
|
+
* @param sourceID - An optional string representing the source identifier of the dataset.
|
|
23
|
+
* @param baseAtmosphericModel - An optional string representing the base atmospheric model used.
|
|
24
|
+
* @param model - An optional string representing the specific model of the dataset.
|
|
25
|
+
*/
|
|
8
26
|
declare interface WxDatasetMeta {
|
|
9
27
|
sourceID?: string;
|
|
10
28
|
baseAtmosphericModel?: string;
|
|
11
29
|
model?: string;
|
|
12
30
|
}
|
|
13
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Manages weather datasets and provides metadata for instances of datasets.
|
|
34
|
+
*
|
|
35
|
+
* @param datasetName - The name of the dataset managed by this instance.
|
|
36
|
+
* @param getInstanceMeta - A method that returns metadata for a specific dataset instance.
|
|
37
|
+
* If no instance is provided, it returns the general metadata.
|
|
38
|
+
*/
|
|
14
39
|
declare interface WxDataSetManager {
|
|
15
40
|
readonly datasetName: string;
|
|
16
41
|
getInstanceMeta(instance?: string): WxDatasetMeta;
|
|
17
42
|
}
|
|
18
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Represents metadata for a weather variable, including its units and range.
|
|
46
|
+
*
|
|
47
|
+
* @param units - The unit of measurement for the variable (e.g., "°C", "mm").
|
|
48
|
+
* @param min - The minimum value for the variable.
|
|
49
|
+
* @param max - The maximum value for the variable.
|
|
50
|
+
*/
|
|
19
51
|
declare interface WxVariableMeta {
|
|
20
52
|
units: string;
|
|
21
53
|
min: number;
|
|
22
54
|
max: number;
|
|
23
55
|
}
|
|
24
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Represents the names of weather layer variables, which can be either a single variable
|
|
59
|
+
* or a pair of variables.
|
|
60
|
+
*
|
|
61
|
+
* @param [string] - A tuple containing a single variable name.
|
|
62
|
+
* @param [string, string] - A tuple containing two variable names.
|
|
63
|
+
*/
|
|
25
64
|
declare type WxLayerVarsNames = [string] | [string, string];
|
|
26
65
|
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Represents a geographic coordinate with longitude and latitude.
|
|
69
|
+
*
|
|
70
|
+
* @param lng - The longitude coordinate of the location.
|
|
71
|
+
* @param lat - The latitude coordinate of the location.
|
|
72
|
+
*/
|
|
27
73
|
declare interface WxLngLat {
|
|
28
74
|
lng: number;
|
|
29
75
|
lat: number;
|
|
30
76
|
}
|
|
31
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Represents a weather tile source that provides dataset management,
|
|
80
|
+
* variable metadata, and information about specific layers.
|
|
81
|
+
*
|
|
82
|
+
* @param wxdatasetManager - A getter for the dataset manager associated with the tile source.
|
|
83
|
+
* @param getCurrentVariableMeta - A method to retrieve the metadata for the current variable.
|
|
84
|
+
* @param getTime - A method to retrieve the time associated with the dataset.
|
|
85
|
+
* @param getVariablesNames - A method to retrieve the names of the variables used in the dataset.
|
|
86
|
+
* @param getLayerInfoAtLatLon - A method to retrieve layer information for a specific latitude and longitude.
|
|
87
|
+
* It accepts a `WxLngLat` coordinate and a map of arbitrary data (`anymap`), returning layer info or `undefined`.
|
|
88
|
+
*/
|
|
32
89
|
declare interface WxTileSource {
|
|
33
90
|
get wxdatasetManager(): WxDataSetManager;
|
|
34
91
|
getCurrentVariableMeta(): WxVariableMeta;
|
|
35
92
|
getTime(): string;
|
|
36
93
|
getVariablesNames(): WxLayerVarsNames;
|
|
94
|
+
// biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
|
|
37
95
|
getLayerInfoAtLatLon(lnglat: WxLngLat, anymap: any): WxTileInfo | undefined;
|
|
38
96
|
}
|
|
39
97
|
|
|
40
|
-
|
|
41
98
|
// // Leaflet
|
|
42
99
|
// const infoControl = new WxInfoControl();
|
|
43
100
|
// map.addControl(new (L.Control.extend(infoControl.extender()))({ position: 'topright' }));
|
|
@@ -46,6 +103,14 @@ declare interface WxTileSource {
|
|
|
46
103
|
// const infoControl = new WxInfoControl();
|
|
47
104
|
// map.addControl(infoControl, 'top-right');
|
|
48
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Represents a control for displaying weather information on a map.
|
|
108
|
+
* The control shows details about the weather dataset, including variable metadata,
|
|
109
|
+
* dataset information, and weather values at a given position.
|
|
110
|
+
*
|
|
111
|
+
* @param div - The HTMLDivElement that represents the control's container.
|
|
112
|
+
* @param pos - The position (longitude, latitude) of the control.
|
|
113
|
+
*/
|
|
49
114
|
export class WxInfoControl {
|
|
50
115
|
private readonly div: HTMLDivElement;
|
|
51
116
|
private pos: { lng: number; lat: number } = { lng: 0, lat: 0 };
|
|
@@ -59,14 +124,29 @@ export class WxInfoControl {
|
|
|
59
124
|
this.div = div;
|
|
60
125
|
}
|
|
61
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Adds the control to the map and returns the div element.
|
|
129
|
+
*
|
|
130
|
+
* @returns The div element representing the control.
|
|
131
|
+
*/
|
|
62
132
|
onAdd(/* map */) {
|
|
63
133
|
return this.div;
|
|
64
134
|
}
|
|
65
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Removes the control from the map.
|
|
138
|
+
*/
|
|
66
139
|
onRemove() {
|
|
67
140
|
this.div.parentNode?.removeChild(this.div);
|
|
68
141
|
}
|
|
69
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Updates the control with new weather information and position.
|
|
145
|
+
*
|
|
146
|
+
* @param wxsource - The WxTileSource instance used to retrieve weather data.
|
|
147
|
+
* @param map - The map object (typically for map-based operations, but suppressed here).
|
|
148
|
+
* @param pos_ - An optional position to update the control's location.
|
|
149
|
+
*/
|
|
70
150
|
update(
|
|
71
151
|
wxsource: WxTileSource | undefined,
|
|
72
152
|
// biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
|
|
@@ -107,7 +187,12 @@ export class WxInfoControl {
|
|
|
107
187
|
this.div.innerHTML += "style=outside<br>source=outside<br>";
|
|
108
188
|
}
|
|
109
189
|
}
|
|
110
|
-
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Returns methods to integrate this control with a Leaflet map.
|
|
193
|
+
*
|
|
194
|
+
* @returns An object containing the `onAdd` and `onRemove` methods for Leaflet integration.
|
|
195
|
+
*/
|
|
111
196
|
extender() {
|
|
112
197
|
return { onAdd: () => this.onAdd(), onRemove: () => this.onRemove() };
|
|
113
198
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WxCreateLegend } from '../utils/RawCLUT';
|
|
2
|
-
import {
|
|
2
|
+
import type { WxColorStyleStrict } from '../utils/wxtools';
|
|
3
3
|
|
|
4
4
|
// // Leaflet
|
|
5
5
|
// const legendControl = new WxLegendControl();
|
|
@@ -9,6 +9,11 @@ import { type WxColorStyleStrict } from '../utils/wxtools';
|
|
|
9
9
|
// const legendControl = new WxLegendControl();
|
|
10
10
|
// map.addControl(legendControl, 'top-right');
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Represents a control for displaying a weather legend on a map.
|
|
14
|
+
* The control shows a color gradient legend based on weather data values.
|
|
15
|
+
* It allows for drawing the legend with specific styles and clearing the canvas.
|
|
16
|
+
*/
|
|
12
17
|
export class WxLegendControl {
|
|
13
18
|
private readonly _div: HTMLDivElement;
|
|
14
19
|
private readonly _canvas: HTMLCanvasElement;
|
|
@@ -27,14 +32,28 @@ export class WxLegendControl {
|
|
|
27
32
|
div.appendChild(this._canvas);
|
|
28
33
|
}
|
|
29
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Adds the legend control to the map and returns the div element.
|
|
37
|
+
*
|
|
38
|
+
* @returns The div element representing the legend control.
|
|
39
|
+
*/
|
|
30
40
|
onAdd(/* map */) {
|
|
31
41
|
return this._div;
|
|
32
42
|
}
|
|
33
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Removes the legend control from the map.
|
|
46
|
+
*/
|
|
34
47
|
onRemove() {
|
|
35
48
|
this._div.parentNode?.removeChild(this._div);
|
|
36
49
|
}
|
|
37
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Draws the legend on the canvas based on the provided color style.
|
|
53
|
+
* The legend includes a color gradient and ticks for data values.
|
|
54
|
+
*
|
|
55
|
+
* @param style - The WxColorStyleStrict object defining the color style for the legend.
|
|
56
|
+
*/
|
|
38
57
|
drawLegend(style: WxColorStyleStrict) {
|
|
39
58
|
const { _canvas } = this;
|
|
40
59
|
const { width, height } = _canvas;
|
|
@@ -115,6 +134,9 @@ export class WxLegendControl {
|
|
|
115
134
|
ctx.strokeRect(1, 1, width - 3, height - 2); //for white background
|
|
116
135
|
}
|
|
117
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Clears the canvas, removing any existing legend or graphics.
|
|
139
|
+
*/
|
|
118
140
|
clear() {
|
|
119
141
|
const { _canvas } = this;
|
|
120
142
|
const { width, height } = _canvas;
|
|
@@ -125,7 +147,11 @@ export class WxLegendControl {
|
|
|
125
147
|
ctx.clearRect(0, 0, width, height);
|
|
126
148
|
}
|
|
127
149
|
|
|
128
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Returns methods to integrate this legend control with a Leaflet map.
|
|
152
|
+
*
|
|
153
|
+
* @returns An object containing the `onAdd` and `onRemove` methods for Leaflet integration.
|
|
154
|
+
*/
|
|
129
155
|
extender() {
|
|
130
156
|
return { onAdd: () => this.onAdd(), onRemove: () => this.onRemove() };
|
|
131
157
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
type WxColorStyleStrict,
|
|
3
|
+
type WxColorStyleWeak,
|
|
4
|
+
WxGetColorSchemes,
|
|
5
|
+
WxGetColorStyles,
|
|
6
6
|
} from '../utils/wxtools';
|
|
7
7
|
|
|
8
8
|
// // Leaflet
|
|
@@ -13,69 +13,111 @@ import {
|
|
|
13
13
|
// const editor = new WxStyleEditorControl();
|
|
14
14
|
// map.addControl(editor, 'top-left');
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* A control for editing and managing style settings for WxColorStyle.
|
|
18
|
+
* This class provides an interface for manipulating various style properties,
|
|
19
|
+
* including colors, vectors, streamlines, and other visual aspects for a weather visualization.
|
|
20
|
+
*/
|
|
16
21
|
export class WxStyleEditorControl {
|
|
22
|
+
/**
|
|
23
|
+
* Event handler triggered when style changes.
|
|
24
|
+
* This handler is expected to return a promise for async operations.
|
|
25
|
+
* @param style The updated style to apply.
|
|
26
|
+
* @param nonnative Optional flag for non-native style handling.
|
|
27
|
+
*/
|
|
17
28
|
onchange?: (style: WxColorStyleWeak, nonnative?: boolean) => Promise<void>;
|
|
18
29
|
|
|
19
30
|
editorTextAreaEl: HTMLTextAreaElement;
|
|
20
31
|
editorDivEl: HTMLDivElement;
|
|
21
32
|
|
|
22
33
|
// inputs
|
|
34
|
+
/** Input for the parent of the style */
|
|
23
35
|
parentInput: HTMLInputElement; // string
|
|
24
36
|
|
|
37
|
+
/** Input for the name of the style */
|
|
25
38
|
nameInput: HTMLInputElement; // string
|
|
26
39
|
|
|
40
|
+
/** Dropdown select for fill style */
|
|
27
41
|
fillSelect: HTMLSelectElement; // string
|
|
28
42
|
|
|
43
|
+
/** Dropdown select for isoline color */
|
|
29
44
|
isolineColorSelect: HTMLSelectElement; // string
|
|
45
|
+
/** Input for isoline color */
|
|
30
46
|
isolineColorInput: HTMLInputElement;
|
|
31
47
|
|
|
48
|
+
/** Input for isoline text visibility */
|
|
32
49
|
isolineTextInput: HTMLInputElement; // boolean
|
|
33
50
|
|
|
51
|
+
/** Dropdown select for vector type */
|
|
34
52
|
vectorTypeSelect: HTMLSelectElement; // string
|
|
35
53
|
|
|
54
|
+
/** Dropdown select for vector color */
|
|
36
55
|
vectorColorSelect: HTMLSelectElement; // string
|
|
56
|
+
/** Input for vector color */
|
|
37
57
|
vectorColorInput: HTMLInputElement; // string
|
|
38
58
|
|
|
59
|
+
/** Input for vector factor (strength) */
|
|
39
60
|
vectorFactorInput: HTMLInputElement; // number
|
|
40
61
|
|
|
62
|
+
/** Dropdown select for stream line color */
|
|
41
63
|
streamLineColorSelect: HTMLSelectElement; // string
|
|
64
|
+
/** Input for stream line color */
|
|
42
65
|
streamLineColorInput: HTMLInputElement; // string
|
|
43
66
|
|
|
67
|
+
/** Input for stream line speed factor */
|
|
44
68
|
streamLineSpeedFactorInput: HTMLInputElement; // number
|
|
45
69
|
|
|
70
|
+
/** Input for stream line static */
|
|
46
71
|
streamLineStaticInput: HTMLInputElement; // boolean
|
|
47
72
|
|
|
73
|
+
/** Input for show below min */
|
|
48
74
|
showBelowMinInput: HTMLInputElement; // boolean
|
|
49
75
|
|
|
76
|
+
/** Input for show above max */
|
|
50
77
|
showAboveMaxInput: HTMLInputElement; // boolean
|
|
51
78
|
|
|
79
|
+
/** Dropdown select for color scheme */
|
|
52
80
|
colorSchemeSelect: HTMLSelectElement; // string
|
|
53
81
|
|
|
82
|
+
/** Input for colors */
|
|
54
83
|
colorsInput: HTMLInputElement; // string[];
|
|
55
84
|
|
|
85
|
+
/** Input for color map */
|
|
56
86
|
colorMapInput: HTMLInputElement; // [number, string][];
|
|
57
87
|
|
|
88
|
+
/** Input for levels */
|
|
58
89
|
levelsInput: HTMLInputElement; // number[];
|
|
59
90
|
|
|
91
|
+
/** Input for blur radius */
|
|
60
92
|
blurRadiusInput: HTMLInputElement; // number
|
|
61
93
|
|
|
94
|
+
/** Input for add degrees */
|
|
62
95
|
addDegreesInput: HTMLInputElement; // number
|
|
63
96
|
|
|
97
|
+
/** Input for units */
|
|
64
98
|
unitsInput: HTMLInputElement; // string
|
|
65
99
|
|
|
100
|
+
/** Input for extra units */
|
|
66
101
|
extraUnitsInput: HTMLInputElement; // WxUnits as { [name: string]: [string, number, ?number] };
|
|
67
102
|
|
|
103
|
+
/** Dropdown select for mask */
|
|
68
104
|
maskSelect: HTMLSelectElement; // string
|
|
69
105
|
|
|
106
|
+
/** Input for animation speed */
|
|
70
107
|
animationSpeed: HTMLInputElement; // number
|
|
108
|
+
/** Input for noise texture power */
|
|
71
109
|
noiseTexturePow: HTMLInputElement; // number
|
|
110
|
+
/** Input for vector field factor */
|
|
72
111
|
vectorFieldFactor: HTMLInputElement; // number
|
|
112
|
+
/** Input for animation intensity */
|
|
73
113
|
animationIntensity: HTMLInputElement; // number
|
|
114
|
+
/** Input for waves count */
|
|
74
115
|
wavesCount: HTMLInputElement; // number
|
|
75
116
|
|
|
117
|
+
/** Base style for WxColorStyle */
|
|
76
118
|
styleBase: WxColorStyleStrict;
|
|
77
119
|
|
|
78
|
-
|
|
120
|
+
/** Main container for the editor */
|
|
79
121
|
parent: HTMLDivElement;
|
|
80
122
|
|
|
81
123
|
constructor() {
|
|
@@ -90,7 +132,7 @@ export class WxStyleEditorControl {
|
|
|
90
132
|
this.parent.onmousemove =
|
|
91
133
|
this.parent.ondblclick =
|
|
92
134
|
this.parent.onclick =
|
|
93
|
-
(e) => e.stopPropagation?.(); // in case of Leaflet
|
|
135
|
+
(e: MouseEvent | PointerEvent) => e.stopPropagation?.(); // in case of Leaflet
|
|
94
136
|
|
|
95
137
|
const { base } = WxGetColorStyles();
|
|
96
138
|
this.styleBase = base;
|
|
@@ -350,19 +392,42 @@ export class WxStyleEditorControl {
|
|
|
350
392
|
});
|
|
351
393
|
}
|
|
352
394
|
|
|
353
|
-
|
|
395
|
+
/**
|
|
396
|
+
* Returns an object with methods to add and remove the control from a map.
|
|
397
|
+
*
|
|
398
|
+
* This method is used to integrate the control into map libraries that require
|
|
399
|
+
* `onAdd` and `onRemove` methods, such as Leaflet or Mapbox.
|
|
400
|
+
*
|
|
401
|
+
* @returns An object with two methods:
|
|
402
|
+
* - `onAdd`: Adds the control to the map.
|
|
403
|
+
* - `onRemove`: Removes the control from the map.
|
|
404
|
+
*/
|
|
354
405
|
extender() {
|
|
355
406
|
return { onAdd: () => this.onAdd(), onRemove: () => this.onRemove() };
|
|
356
407
|
}
|
|
357
408
|
|
|
409
|
+
/**
|
|
410
|
+
* Adds the control to the map by returning the parent container element.
|
|
411
|
+
*/
|
|
358
412
|
onAdd(/* map */) {
|
|
359
413
|
return this.parent;
|
|
360
414
|
}
|
|
361
415
|
|
|
416
|
+
/**
|
|
417
|
+
* Removes the control from the map by removing its parent node from the DOM.
|
|
418
|
+
*/
|
|
362
419
|
onRemove() {
|
|
363
420
|
this.parent.parentNode?.removeChild(this.parent);
|
|
364
421
|
}
|
|
365
422
|
|
|
423
|
+
/**
|
|
424
|
+
* Retrieves the current style of the control.
|
|
425
|
+
*
|
|
426
|
+
* This method calls a private method `_getStyleFromDiv` to get the style from the control's div element.
|
|
427
|
+
* It returns the style as a `WxColorStyleWeak` object, which represents the current styling properties.
|
|
428
|
+
*
|
|
429
|
+
* @returns The current style of the control as a `WxColorStyleWeak` object.
|
|
430
|
+
*/
|
|
366
431
|
getStyle(): WxColorStyleWeak {
|
|
367
432
|
return this._getStyleFromDiv();
|
|
368
433
|
}
|
|
@@ -377,9 +442,19 @@ export class WxStyleEditorControl {
|
|
|
377
442
|
this._setStyleToTextArea(this._getStyleFromDiv());
|
|
378
443
|
}
|
|
379
444
|
|
|
445
|
+
/**
|
|
446
|
+
* Sets the style of the control.
|
|
447
|
+
*
|
|
448
|
+
* This method applies a given `WxColorStyleWeak` style to the control. If the style includes a `colorMap`,
|
|
449
|
+
* it filters out `colors` and `levels` before applying the style to the control. The style is then set to
|
|
450
|
+
* the control's div and reflected in the text area using the `_setStyleToTextArea` method.
|
|
451
|
+
*
|
|
452
|
+
* @param style The `WxColorStyleWeak` object representing the new style to be applied.
|
|
453
|
+
*/
|
|
380
454
|
protected _getStyleFromDiv(): WxColorStyleWeak {
|
|
381
455
|
const objFromValue = (field: string) => {
|
|
382
456
|
try {
|
|
457
|
+
// @ts-ignore
|
|
383
458
|
return this[field].value ? JSON.parse(this[field].value) : undefined;
|
|
384
459
|
} catch (e) {
|
|
385
460
|
console.log(field, " : parsing error: ", e);
|
|
@@ -448,6 +523,14 @@ export class WxStyleEditorControl {
|
|
|
448
523
|
return style;
|
|
449
524
|
}
|
|
450
525
|
|
|
526
|
+
/**
|
|
527
|
+
* Sets the style to the editor's text area.
|
|
528
|
+
*
|
|
529
|
+
* This method serializes the given `WxColorStyleWeak` style into a sorted JSON string and sets it as the value
|
|
530
|
+
* of the editor's text area. The style is sorted using the `JSONsort` function before being applied.
|
|
531
|
+
*
|
|
532
|
+
* @param style The `WxColorStyleWeak` object representing the style to be set in the text area.
|
|
533
|
+
*/
|
|
451
534
|
protected _setStyleToTextArea(style: WxColorStyleWeak): void {
|
|
452
535
|
this.editorTextAreaEl.value = JSON.stringify(JSONsort(style), null, 2);
|
|
453
536
|
}
|
|
@@ -512,10 +595,19 @@ export class WxStyleEditorControl {
|
|
|
512
595
|
}
|
|
513
596
|
}
|
|
514
597
|
|
|
598
|
+
/**
|
|
599
|
+
* Handles changes made to the control's div and updates the style.
|
|
600
|
+
*
|
|
601
|
+
* This method retrieves the current style from the div, removes any properties that are undefined,
|
|
602
|
+
* empty, or have a length of zero, and updates the text area with the modified style.
|
|
603
|
+
* Afterward, it calls the `onchange` callback (if defined) with the updated style.
|
|
604
|
+
*/
|
|
515
605
|
protected _onDivChange(): void {
|
|
516
606
|
const style = this._getStyleFromDiv();
|
|
517
607
|
for (const key of Object.keys(style)) {
|
|
608
|
+
// @ts-ignore
|
|
518
609
|
if (style[key] === undefined || style[key] === "" || style[key].length === 0) {
|
|
610
|
+
// @ts-ignore
|
|
519
611
|
delete style[key];
|
|
520
612
|
}
|
|
521
613
|
}
|
|
@@ -526,6 +618,19 @@ export class WxStyleEditorControl {
|
|
|
526
618
|
}
|
|
527
619
|
}
|
|
528
620
|
|
|
621
|
+
/**
|
|
622
|
+
* Creates a new HTML element of the specified type, appends it to the given container,
|
|
623
|
+
* and returns the element.
|
|
624
|
+
*
|
|
625
|
+
* @param container - The parent HTML element to which the new element will be appended.
|
|
626
|
+
* @param tag - The type of HTML element to create (e.g., 'div', 'span', 'button').
|
|
627
|
+
* @param params - An optional object containing properties to assign to the created element.
|
|
628
|
+
* These properties are assigned directly to the element.
|
|
629
|
+
*
|
|
630
|
+
* @returns The newly created HTML element of the specified type.
|
|
631
|
+
*
|
|
632
|
+
* @template K - The type of HTML element to create, derived from HTMLElementTagNameMap.
|
|
633
|
+
*/
|
|
529
634
|
function createEl<K extends keyof HTMLElementTagNameMap>(
|
|
530
635
|
container: HTMLElement,
|
|
531
636
|
tag: K,
|
|
@@ -538,7 +643,23 @@ function createEl<K extends keyof HTMLElementTagNameMap>(
|
|
|
538
643
|
return el;
|
|
539
644
|
}
|
|
540
645
|
|
|
646
|
+
/**
|
|
647
|
+
* Recursively sorts the keys of an object or elements of an array in a case-insensitive manner.
|
|
648
|
+
* If the input is an object, it sorts the keys alphabetically (case-insensitive) and applies
|
|
649
|
+
* the sorting recursively to its values. If the input is an array, it recursively sorts each element.
|
|
650
|
+
*
|
|
651
|
+
* @param o - The object or array to be sorted. If it's an object, the function will sort its keys.
|
|
652
|
+
* If it's an array, it will recursively sort its elements.
|
|
653
|
+
*
|
|
654
|
+
* @returns A new object or array with its keys or elements sorted.
|
|
655
|
+
*
|
|
656
|
+
* @remarks
|
|
657
|
+
* - The function handles both arrays and objects and will recursively sort their nested structures.
|
|
658
|
+
* - If an object contains keys that differ only by case (e.g., 'name' and 'Name'), they will be
|
|
659
|
+
* treated as distinct and sorted alphabetically in a case-insensitive manner.
|
|
660
|
+
*/
|
|
541
661
|
// biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
|
|
662
|
+
// @ts-ignore
|
|
542
663
|
function JSONsort(o: any) {
|
|
543
664
|
if (Array.isArray(o)) {
|
|
544
665
|
return o.map(JSONsort);
|
|
@@ -552,6 +673,7 @@ function JSONsort(o: any) {
|
|
|
552
673
|
return aa === bb ? 0 : aa > bb ? 1 : -1;
|
|
553
674
|
});
|
|
554
675
|
return keys.reduce((a, k) => {
|
|
676
|
+
// @ts-ignore
|
|
555
677
|
a[k] = JSONsort(o[k]);
|
|
556
678
|
return a;
|
|
557
679
|
}, {});
|