@metoceanapi/wxtiles-common 0.0.10 → 0.0.11
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/LICENSE.txt +1 -1
- 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 +91 -120
- package/controls/WxInfoControl.ts +87 -2
- package/controls/WxLegendControl.ts +28 -2
- package/controls/WxStyleEditorControl.ts +123 -6
- package/controls/WxTimeControl.ts +132 -4
- 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 +1 -1
- package/package.json +5 -3
- package/tsconfig.json +19 -0
- package/typedoc.json +4 -0
- package/wxlayer/WxImplementation.ts +3 -3
- package/wxlayer/loadertools.ts +12 -8
- package/wxlayer/painter.ts +3 -3
package/LICENSE.txt
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Simple busy control to identify if action in progress */
|
|
2
|
+
export class ControlBusy {
|
|
3
|
+
public _busy: boolean;
|
|
4
|
+
constructor(private container: HTMLDivElement) {
|
|
5
|
+
this._busy = false;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Set busy state
|
|
10
|
+
* @param b busy state - true if busy
|
|
11
|
+
*/
|
|
12
|
+
setBusy(b: boolean) {
|
|
13
|
+
this._busy = b;
|
|
14
|
+
this.container.style.backgroundColor = b ? "yellow" : "lightgray";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { WxAPI } from "../../wxapi";
|
|
2
|
+
import type { ControlElement } from "../WxAPIControl";
|
|
3
|
+
import type { ControlBusy } from "./WxAPIControl-busy";
|
|
4
|
+
import { WxAPIControlVariable } from "./WxAPIControl-variables";
|
|
5
|
+
|
|
6
|
+
/** Control for updating form filed datasets */
|
|
7
|
+
export class ControlDataset implements ControlElement {
|
|
8
|
+
public datasetInput: HTMLSelectElement;
|
|
9
|
+
public variables: WxAPIControlVariable;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Constructor
|
|
13
|
+
* @param wxapi WxAPI object - API to get datasets and variables
|
|
14
|
+
* @param busy: ControlBusy - if the control is busy
|
|
15
|
+
* @param onChange function - middleware to be run
|
|
16
|
+
*/
|
|
17
|
+
constructor(
|
|
18
|
+
private readonly wxapi: WxAPI,
|
|
19
|
+
private readonly busy: ControlBusy,
|
|
20
|
+
private onChange: () => Promise<void> | undefined
|
|
21
|
+
) {
|
|
22
|
+
this.datasetInput = document.createElement("select");
|
|
23
|
+
this.variables = new WxAPIControlVariable(wxapi, busy, this.onChange);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public attachToDom(container: HTMLDivElement) {
|
|
27
|
+
const datasetslabel = document.createElement("label");
|
|
28
|
+
datasetslabel.innerText = "Dataset";
|
|
29
|
+
container.appendChild(datasetslabel);
|
|
30
|
+
container.appendChild(this.datasetInput);
|
|
31
|
+
this.variables.attachToDom(container);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public getValue() {
|
|
35
|
+
return this.datasetInput.value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public setValue(value: string) {
|
|
39
|
+
this.datasetInput.value = value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Fill datasets
|
|
44
|
+
* @param dataset dataset - dataset name to be selected
|
|
45
|
+
*/
|
|
46
|
+
private async fillDatasets({ dataset }: { dataset?: string }): Promise<void> {
|
|
47
|
+
this.datasetInput.options.length = 0;
|
|
48
|
+
const datasetsNames = await this.wxapi.getAllDatasetsNames();
|
|
49
|
+
for (const dataset of datasetsNames) {
|
|
50
|
+
const option = document.createElement("option");
|
|
51
|
+
option.value = dataset;
|
|
52
|
+
option.text = dataset;
|
|
53
|
+
this.datasetInput.appendChild(option);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (dataset) {
|
|
57
|
+
this.datasetInput.value = dataset;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Dynamically update datasets
|
|
63
|
+
*/
|
|
64
|
+
public async handleChange() {
|
|
65
|
+
if (!this.busy._busy) {
|
|
66
|
+
this.busy.setBusy(true);
|
|
67
|
+
const dataset = this.datasetInput.value;
|
|
68
|
+
await this.variables.fillVariables(dataset);
|
|
69
|
+
|
|
70
|
+
const variables = this.variables.variablesInput.value;
|
|
71
|
+
await this.onChange?.();
|
|
72
|
+
this.datasetInput.value = dataset;
|
|
73
|
+
this.variables.variablesInput.value = variables;
|
|
74
|
+
this.busy.setBusy(false);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public async init({
|
|
79
|
+
dataset,
|
|
80
|
+
variable,
|
|
81
|
+
cb,
|
|
82
|
+
}: {
|
|
83
|
+
dataset?: string;
|
|
84
|
+
variable?: string;
|
|
85
|
+
cb?: () => void;
|
|
86
|
+
}) {
|
|
87
|
+
this.variables.variablesInput.addEventListener("change", async () =>
|
|
88
|
+
this.variables.handleChange()
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
this.datasetInput.addEventListener("change", async () => {
|
|
92
|
+
await this.handleChange();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
this.setValue(dataset || "");
|
|
96
|
+
this.variables.setValue(variable || "");
|
|
97
|
+
await this.fillDatasets({ dataset });
|
|
98
|
+
await this.variables.fillVariables(this.getValue());
|
|
99
|
+
await this.variables.handleChange();
|
|
100
|
+
await cb?.();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ControlElement } from "../WxAPIControl";
|
|
2
|
+
|
|
3
|
+
/** Generate filter input / value */
|
|
4
|
+
const createFilterInput = () => {
|
|
5
|
+
// Add filter input field
|
|
6
|
+
const filter = document.createElement("input");
|
|
7
|
+
filter.type = "text";
|
|
8
|
+
filter.placeholder = "Type to filter datasets...";
|
|
9
|
+
filter.style.marginBottom = "5px";
|
|
10
|
+
return filter;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** Control for updating form datasets based on filtering */
|
|
14
|
+
export class ControlFilter implements ControlElement {
|
|
15
|
+
private filterInput: HTMLInputElement;
|
|
16
|
+
constructor(filterValue?: string) {
|
|
17
|
+
this.filterInput = createFilterInput();
|
|
18
|
+
this.filterInput.value = filterValue || "";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public getValue() {
|
|
22
|
+
return this.filterInput.value.trim();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public setValue(value: string) {
|
|
26
|
+
this.filterInput.value = value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public attachToDom(container: HTMLDivElement) {
|
|
30
|
+
// Add filter label
|
|
31
|
+
const filterlabel = document.createElement("label");
|
|
32
|
+
filterlabel.innerText = "Filter";
|
|
33
|
+
container.appendChild(filterlabel);
|
|
34
|
+
container.appendChild(this.filterInput);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public readonly init = ({ datasets }: { datasets: HTMLSelectElement }) => {
|
|
38
|
+
if (this.getValue()) {
|
|
39
|
+
this.filterUpdate({ datasets });
|
|
40
|
+
}
|
|
41
|
+
this.filterInput.addEventListener("input", () => {
|
|
42
|
+
this.filterUpdate({ datasets });
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Filter dataset based on input value
|
|
48
|
+
* @param dataset - dataset to be used to populate variables
|
|
49
|
+
*/
|
|
50
|
+
private filterUpdate = ({ datasets }: { datasets: HTMLSelectElement }) => {
|
|
51
|
+
const filterValue = this.getValue();
|
|
52
|
+
|
|
53
|
+
if (filterValue) {
|
|
54
|
+
// Filter the dataset options
|
|
55
|
+
for (const option of Array.from(datasets.options)) {
|
|
56
|
+
const isVisible = option.text.includes(filterValue);
|
|
57
|
+
option.style.display = isVisible ? "" : "none";
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
// Filter the dataset options
|
|
61
|
+
for (const option of Array.from(datasets.options)) {
|
|
62
|
+
(option as HTMLOptionElement).style.display = "";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { WxAPI } from "../../wxapi";
|
|
2
|
+
import type { ControlElement } from "../WxAPIControl";
|
|
3
|
+
import type { ControlBusy } from "./WxAPIControl-busy";
|
|
4
|
+
|
|
5
|
+
/** Control for updating form filed variables */
|
|
6
|
+
export class WxAPIControlVariable implements ControlElement {
|
|
7
|
+
public variablesInput: HTMLSelectElement;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Constructor
|
|
11
|
+
* @param wxapi WxAPI object - API to get datasets and variables
|
|
12
|
+
* @param busy: ControlBusy - if the control is busy
|
|
13
|
+
* @param onChange function - middleware to be run
|
|
14
|
+
*/
|
|
15
|
+
constructor(
|
|
16
|
+
private readonly wxapi: WxAPI,
|
|
17
|
+
private readonly busy: ControlBusy,
|
|
18
|
+
private onChange: () => Promise<void> | undefined
|
|
19
|
+
) {
|
|
20
|
+
this.variablesInput = document.createElement("select");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public getValue() {
|
|
24
|
+
return this.variablesInput.value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public setValue(value: string) {
|
|
28
|
+
this.variablesInput.value = value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public attachToDom(container: HTMLDivElement) {
|
|
32
|
+
const variableslabel = document.createElement("label");
|
|
33
|
+
variableslabel.innerText = "Variable";
|
|
34
|
+
container.appendChild(variableslabel);
|
|
35
|
+
container.appendChild(this.variablesInput);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public async handleChange() {
|
|
39
|
+
if (this.busy._busy) return;
|
|
40
|
+
this.busy.setBusy(true);
|
|
41
|
+
const variables = this.variablesInput.value;
|
|
42
|
+
await this.onChange?.();
|
|
43
|
+
this.variablesInput.value = variables;
|
|
44
|
+
this.busy.setBusy(false);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Fill variables for a dataset
|
|
49
|
+
* @param dataset - dataset to be used to populate variables
|
|
50
|
+
*/
|
|
51
|
+
async fillVariables(dataset: string): Promise<void> {
|
|
52
|
+
const variable = this.getValue().trim();
|
|
53
|
+
this.variablesInput.options.length = 0;
|
|
54
|
+
// const dataset = this.datasets.value;
|
|
55
|
+
const variables = await this.wxapi.getDatasetAllVariables(dataset);
|
|
56
|
+
if (variables) {
|
|
57
|
+
for (const variable of variables) {
|
|
58
|
+
const option = document.createElement("option");
|
|
59
|
+
option.value = variable;
|
|
60
|
+
option.text = variable;
|
|
61
|
+
this.variablesInput.appendChild(option);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const isVariableInDataset = this.variablesInput.options.namedItem(variable);
|
|
66
|
+
|
|
67
|
+
if (isVariableInDataset) {
|
|
68
|
+
this.variablesInput.value = variable;
|
|
69
|
+
} else {
|
|
70
|
+
this.variablesInput.value = this.variablesInput.options[0]?.value || "";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
package/controls/WxAPIControl.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
1
|
+
import type { WxAPI } from "../wxapi";
|
|
2
|
+
import { ControlBusy } from "./WxAPIControl/WxAPIControl-busy";
|
|
3
|
+
import { ControlDataset } from "./WxAPIControl/WxAPIControl-datasets";
|
|
4
|
+
import { ControlFilter } from "./WxAPIControl/WxAPIControl-filter";
|
|
5
|
+
|
|
6
|
+
export interface ControlElement {
|
|
7
|
+
attachToDom(container: HTMLDivElement): void;
|
|
8
|
+
getValue(): string;
|
|
9
|
+
setValue(value: string): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type onChangeControl = (
|
|
13
|
+
dataset: string,
|
|
14
|
+
variable: string,
|
|
15
|
+
resetStyleAndFlyTo?: boolean
|
|
16
|
+
) => Promise<void>;
|
|
5
17
|
|
|
6
18
|
// // Leaflet
|
|
7
19
|
// const apiControl = new WxAPIControl();
|
|
@@ -11,121 +23,80 @@ declare interface WxAPI {
|
|
|
11
23
|
// const apiControl = new WxAPIControl();
|
|
12
24
|
// map.addControl(apiControl, 'top-right');
|
|
13
25
|
|
|
26
|
+
/** Control for selecting dataset and variable */
|
|
14
27
|
export class WxAPIControl {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
option.value = dataset;
|
|
90
|
-
option.text = dataset;
|
|
91
|
-
this.datasets.appendChild(option);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (dataset) {
|
|
95
|
-
this.datasets.value = dataset;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
await this.fillVariables(variable);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async fillVariables(variable?: string): Promise<void> {
|
|
102
|
-
this.variables.options.length = 0;
|
|
103
|
-
const dataset = this.datasets.value;
|
|
104
|
-
const variables = await this.wxapi.getDatasetAllVariables(dataset);
|
|
105
|
-
if (variables) {
|
|
106
|
-
for (const variable of variables) {
|
|
107
|
-
const option = document.createElement("option");
|
|
108
|
-
option.value = variable;
|
|
109
|
-
option.text = variable;
|
|
110
|
-
this.variables.appendChild(option);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (variable && this.variables.options.length) {
|
|
115
|
-
this.variables.value = variable;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
onAdd(/* map */) {
|
|
120
|
-
return this._div;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
onRemove() {
|
|
124
|
-
this._div.parentNode?.removeChild(this._div);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// for Leaflet
|
|
128
|
-
extender() {
|
|
129
|
-
return { onAdd: () => this.onAdd(), onRemove: () => this.onRemove() };
|
|
130
|
-
}
|
|
28
|
+
public busy: ControlBusy;
|
|
29
|
+
private readonly _div: HTMLDivElement;
|
|
30
|
+
private readonly filter: ControlFilter;
|
|
31
|
+
private readonly dataset: ControlDataset;
|
|
32
|
+
|
|
33
|
+
/** Callback for dataset and variable */
|
|
34
|
+
onchange?: onChangeControl;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Constructor
|
|
38
|
+
* @param wxapi WxAPI object - API to get datasets and variables
|
|
39
|
+
* @param dataset dataset - dataset name to be selected
|
|
40
|
+
* @param variable variable - variable name to be selected
|
|
41
|
+
* @param opts object - options for the control
|
|
42
|
+
* @param opts.filter string - initial filter value for datasets
|
|
43
|
+
*/
|
|
44
|
+
constructor(
|
|
45
|
+
wxapi: WxAPI,
|
|
46
|
+
dataset?: string,
|
|
47
|
+
variable?: string,
|
|
48
|
+
opts: {
|
|
49
|
+
filter?: string;
|
|
50
|
+
} = {}
|
|
51
|
+
) {
|
|
52
|
+
const div = document.createElement("div");
|
|
53
|
+
div.className = "mapboxgl-ctrl leaflet-control";
|
|
54
|
+
div.style.borderStyle = "solid";
|
|
55
|
+
div.style.borderColor = "#000";
|
|
56
|
+
div.style.backgroundColor = "#aaaaaaaa";
|
|
57
|
+
div.style.padding = "5px";
|
|
58
|
+
div.style.display = "flex";
|
|
59
|
+
div.style.flexDirection = "column";
|
|
60
|
+
this._div = div;
|
|
61
|
+
|
|
62
|
+
// Add filter input field
|
|
63
|
+
this.busy = new ControlBusy(div);
|
|
64
|
+
this.filter = new ControlFilter(opts.filter);
|
|
65
|
+
this.dataset = new ControlDataset(wxapi, this.busy, this.onChange);
|
|
66
|
+
|
|
67
|
+
this.filter.attachToDom(div);
|
|
68
|
+
this.dataset.attachToDom(div);
|
|
69
|
+
|
|
70
|
+
this.dataset.init({
|
|
71
|
+
dataset,
|
|
72
|
+
variable,
|
|
73
|
+
cb: () => this.filter.init({ datasets: this.dataset.datasetInput }),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
protected onChange = async () => {
|
|
78
|
+
this.onchange?.(this.dataset.getValue(), this.dataset.variables.getValue());
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Add control to map
|
|
83
|
+
* @param map map - map to add control
|
|
84
|
+
*/
|
|
85
|
+
onAdd(/* map */) {
|
|
86
|
+
return this._div;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Remove control from map
|
|
91
|
+
*/
|
|
92
|
+
onRemove() {
|
|
93
|
+
this._div.parentNode?.removeChild(this._div);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Extender for Leaflet
|
|
98
|
+
*/
|
|
99
|
+
extender() {
|
|
100
|
+
return { onAdd: () => this.onAdd(), onRemove: () => this.onRemove() };
|
|
101
|
+
}
|
|
131
102
|
}
|
|
@@ -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
|
}
|