@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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: "Validate Pull Request Title"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request_target:
|
|
5
|
+
types: [opened, edited, synchronize]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
pull-requests: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
main:
|
|
12
|
+
name: Validate PR title
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: amannn/action-semantic-pull-request@v5
|
|
16
|
+
env:
|
|
17
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
package/LICENSE.txt
CHANGED
package/biome.json
CHANGED
|
@@ -6,7 +6,13 @@
|
|
|
6
6
|
"linter": {
|
|
7
7
|
"enabled": true,
|
|
8
8
|
"rules": {
|
|
9
|
-
"recommended": true
|
|
9
|
+
"recommended": true,
|
|
10
|
+
"suspicious": {
|
|
11
|
+
"noExplicitAny": "off"
|
|
12
|
+
},
|
|
13
|
+
"style": {
|
|
14
|
+
"noParameterAssign": "off"
|
|
15
|
+
}
|
|
10
16
|
}
|
|
11
17
|
},
|
|
12
18
|
"files": {
|
|
@@ -14,11 +20,18 @@
|
|
|
14
20
|
},
|
|
15
21
|
"javascript": {
|
|
16
22
|
"formatter": {
|
|
17
|
-
"trailingCommas": "
|
|
23
|
+
"trailingCommas": "all",
|
|
18
24
|
"quoteStyle": "single",
|
|
19
25
|
"jsxQuoteStyle": "single",
|
|
20
26
|
"arrowParentheses": "always",
|
|
21
|
-
"lineWidth": 160
|
|
27
|
+
"lineWidth": 160,
|
|
28
|
+
"indentStyle": "space",
|
|
29
|
+
"indentWidth": 2
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"json": {
|
|
33
|
+
"formatter": {
|
|
34
|
+
"indentStyle": "space"
|
|
22
35
|
}
|
|
23
36
|
}
|
|
24
37
|
}
|
|
@@ -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,15 @@
|
|
|
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 = (dataset: string, variable: string, resetStyleAndFlyTo?: boolean) => Promise<void>;
|
|
5
13
|
|
|
6
14
|
// // Leaflet
|
|
7
15
|
// const apiControl = new WxAPIControl();
|
|
@@ -11,121 +19,80 @@ declare interface WxAPI {
|
|
|
11
19
|
// const apiControl = new WxAPIControl();
|
|
12
20
|
// map.addControl(apiControl, 'top-right');
|
|
13
21
|
|
|
22
|
+
/** Control for selecting dataset and variable */
|
|
14
23
|
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
|
-
}
|
|
24
|
+
public busy: ControlBusy;
|
|
25
|
+
private readonly _div: HTMLDivElement;
|
|
26
|
+
private readonly filter: ControlFilter;
|
|
27
|
+
private readonly dataset: ControlDataset;
|
|
28
|
+
|
|
29
|
+
/** Callback for dataset and variable */
|
|
30
|
+
onchange?: onChangeControl;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Constructor
|
|
34
|
+
* @param wxapi WxAPI object - API to get datasets and variables
|
|
35
|
+
* @param dataset dataset - dataset name to be selected
|
|
36
|
+
* @param variable variable - variable name to be selected
|
|
37
|
+
* @param opts object - options for the control
|
|
38
|
+
* @param opts.filter string - initial filter value for datasets
|
|
39
|
+
*/
|
|
40
|
+
constructor(
|
|
41
|
+
wxapi: WxAPI,
|
|
42
|
+
dataset?: string,
|
|
43
|
+
variable?: string,
|
|
44
|
+
opts: {
|
|
45
|
+
filter?: string;
|
|
46
|
+
} = {},
|
|
47
|
+
) {
|
|
48
|
+
const div = document.createElement('div');
|
|
49
|
+
div.className = 'mapboxgl-ctrl leaflet-control';
|
|
50
|
+
div.style.borderStyle = 'solid';
|
|
51
|
+
div.style.borderColor = '#000';
|
|
52
|
+
div.style.backgroundColor = '#aaaaaaaa';
|
|
53
|
+
div.style.padding = '5px';
|
|
54
|
+
div.style.display = 'flex';
|
|
55
|
+
div.style.flexDirection = 'column';
|
|
56
|
+
this._div = div;
|
|
57
|
+
|
|
58
|
+
// Add filter input field
|
|
59
|
+
this.busy = new ControlBusy(div);
|
|
60
|
+
this.filter = new ControlFilter(opts.filter);
|
|
61
|
+
this.dataset = new ControlDataset(wxapi, this.busy, this.onChange);
|
|
62
|
+
|
|
63
|
+
this.filter.attachToDom(div);
|
|
64
|
+
this.dataset.attachToDom(div);
|
|
65
|
+
|
|
66
|
+
this.dataset.init({
|
|
67
|
+
dataset,
|
|
68
|
+
variable,
|
|
69
|
+
cb: () => this.filter.init({ datasets: this.dataset.datasetInput }),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
protected onChange = async () => {
|
|
74
|
+
this.onchange?.(this.dataset.getValue(), this.dataset.variables.getValue());
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Add control to map
|
|
79
|
+
* @param map map - map to add control
|
|
80
|
+
*/
|
|
81
|
+
onAdd(/* map */) {
|
|
82
|
+
return this._div;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Remove control from map
|
|
87
|
+
*/
|
|
88
|
+
onRemove() {
|
|
89
|
+
this._div.parentNode?.removeChild(this._div);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Extender for Leaflet
|
|
94
|
+
*/
|
|
95
|
+
extender() {
|
|
96
|
+
return { onAdd: () => this.onAdd(), onRemove: () => this.onRemove() };
|
|
97
|
+
}
|
|
131
98
|
}
|