@metoceanapi/wxtiles-common 0.0.8 → 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 +26 -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 +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 +272 -0
- package/managers/WxAllDatasetsManager.ts +60 -0
- package/package.json +6 -3
- package/tsconfig.json +31 -0
- package/typedoc.json +4 -0
- package/types.ts +471 -0
- package/utils/qtree.ts +2 -1
- package/utils/tests_wxtools.ts +10 -10
- package/utils/wxtools.ts +1 -0
- package/wxapi.ts +222 -0
- package/wxlayer/WxImplementation.ts +374 -0
- package/wxlayer/loader.ts +305 -0
- package/wxlayer/loadertools.ts +380 -0
- package/wxlayer/painter.ts +451 -0
- package/wxlayer/wxlayer.ts +379 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { TileType } from "../utils/qtree";
|
|
2
|
+
import {
|
|
3
|
+
type CachedUriLoaderPromiseFunc,
|
|
4
|
+
type DataIntegral,
|
|
5
|
+
type DataIntegrals,
|
|
6
|
+
type DataPictures,
|
|
7
|
+
WXLOG,
|
|
8
|
+
type XYZ,
|
|
9
|
+
blurData,
|
|
10
|
+
cacheUriPromise,
|
|
11
|
+
loadDataIntegral,
|
|
12
|
+
uriXYZ,
|
|
13
|
+
} from "../utils/wxtools";
|
|
14
|
+
import type { WxBoundaryMeta, WxRequestInit, WxURIs, WxData, SLine} from "../types";
|
|
15
|
+
import {
|
|
16
|
+
applyMask,
|
|
17
|
+
makeBox,
|
|
18
|
+
splitCoords,
|
|
19
|
+
subData,
|
|
20
|
+
subDataDegree,
|
|
21
|
+
subMask,
|
|
22
|
+
} from "./loadertools";
|
|
23
|
+
import type { WxLayer } from "./wxlayer";
|
|
24
|
+
import type { BaseDatasetManager } from "../managers/BaseDatasetManager";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Class to load and preprocess data from PNG tiles.
|
|
28
|
+
* This class is used internally by {@link WxLayer}.
|
|
29
|
+
* Direct usage is not recommended.
|
|
30
|
+
*/
|
|
31
|
+
export class Loader<WxDatasetManagerT extends BaseDatasetManager> {
|
|
32
|
+
/** Reference to the associated WxLayer */
|
|
33
|
+
protected readonly _layer: WxLayer<WxDatasetManagerT>;
|
|
34
|
+
|
|
35
|
+
/** Function to load, decode, and cache tile data from a URL */
|
|
36
|
+
protected readonly _loadDataFunc: CachedUriLoaderPromiseFunc<DataIntegral> =
|
|
37
|
+
cacheUriPromise(loadDataIntegral);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Constructor - Do not use directly.
|
|
41
|
+
* Use WxLayer methods to manage this loader.
|
|
42
|
+
*/
|
|
43
|
+
constructor(layer: WxLayer<WxDatasetManagerT>) {
|
|
44
|
+
this._layer = layer;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Loads and preprocesses data for a single tile.
|
|
49
|
+
* @param tile - Tile coordinates (XYZ).
|
|
50
|
+
* @param requestInit - Optional HTTP request configuration.
|
|
51
|
+
* @returns A promise resolving to the processed tile data or `null` if the tile is invalid.
|
|
52
|
+
*/
|
|
53
|
+
async load(tile: XYZ, requestInit?: WxRequestInit): Promise<WxData | null> {
|
|
54
|
+
const preloaded = await this.cacheLoad(
|
|
55
|
+
tile,
|
|
56
|
+
this._layer.tilesURIs,
|
|
57
|
+
requestInit,
|
|
58
|
+
);
|
|
59
|
+
if (!preloaded) return null; // tile is cut by boundaries or mask QTree
|
|
60
|
+
const { rawdata, subCoords, tileType } = preloaded;
|
|
61
|
+
const { units } = this._layer.currentVariableMeta;
|
|
62
|
+
const interpolator = units === "degree" ? subDataDegree : subData;
|
|
63
|
+
const processor = (d: DataIntegral) =>
|
|
64
|
+
interpolator(blurData(d, this._layer.style.blurRadius), subCoords);
|
|
65
|
+
const data = <DataPictures>rawdata.map(processor); // preprocess all loaded data
|
|
66
|
+
this._vectorMagnitudesPrepare(data); // if vector data, prepare magnitudes
|
|
67
|
+
await this._applyMask(
|
|
68
|
+
data,
|
|
69
|
+
tile,
|
|
70
|
+
tileType,
|
|
71
|
+
!subCoords && rawdata.length === 1,
|
|
72
|
+
); // apply mask if needed
|
|
73
|
+
return { data, slines: this._createStreamLines(data) };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Loads tile data from the cache or API, ensuring validity against boundaries and masks.
|
|
78
|
+
* @param tile - Tile coordinates (XYZ).
|
|
79
|
+
* @param uris - URIs used to construct tile URLs.
|
|
80
|
+
* @param requestInit - Optional HTTP request configuration.
|
|
81
|
+
* @returns A promise resolving to raw tile data or `null` if the tile is invalid.
|
|
82
|
+
*/
|
|
83
|
+
async cacheLoad(
|
|
84
|
+
tile: XYZ,
|
|
85
|
+
uris: WxURIs,
|
|
86
|
+
requestInit?: WxRequestInit,
|
|
87
|
+
): Promise<{
|
|
88
|
+
rawdata: DataIntegrals;
|
|
89
|
+
subCoords?: XYZ | undefined;
|
|
90
|
+
tileType: TileType;
|
|
91
|
+
} | null> {
|
|
92
|
+
if (!this._checkInsideBoundaries(tile)) return null; // tile is cut by boundaries
|
|
93
|
+
|
|
94
|
+
const tileType = this._checkTypeAndMask(tile);
|
|
95
|
+
if (!tileType) return null; // tile is cut by mask
|
|
96
|
+
|
|
97
|
+
const { upCoords, subCoords } = splitCoords(
|
|
98
|
+
tile,
|
|
99
|
+
this._layer.getCoarseMaxZoom(),
|
|
100
|
+
);
|
|
101
|
+
const URLs = <WxURIs>uris.map((uri) => uriXYZ(uri, upCoords));
|
|
102
|
+
const requestInitCopy = Object.assign(
|
|
103
|
+
{},
|
|
104
|
+
this._layer.wxdatasetManager.wxAPI.requestInit,
|
|
105
|
+
{ signal: requestInit?.signal },
|
|
106
|
+
); // make initCopy, copy only signal
|
|
107
|
+
const rawdata = <DataIntegrals>(
|
|
108
|
+
await Promise.all(
|
|
109
|
+
URLs.map((url: string) => this._loadDataFunc(url, requestInitCopy)),
|
|
110
|
+
)
|
|
111
|
+
);
|
|
112
|
+
return { rawdata, subCoords, tileType };
|
|
113
|
+
// we don't need to process data, as it's for cache preloading only
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Clear cache */
|
|
117
|
+
clearCache(): void {
|
|
118
|
+
this._loadDataFunc.clearCache();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Applies a mask to the tile data based on the tile type and masking style.
|
|
123
|
+
* @param data - The processed tile data.
|
|
124
|
+
* @param tile - The tile coordinates (XYZ).
|
|
125
|
+
* @param tileType - Type of the tile (e.g., mixed, land, sea).
|
|
126
|
+
* @param needCopy - Whether to create a data copy before masking.
|
|
127
|
+
* @returns A promise resolving once the mask has been applied.
|
|
128
|
+
*/
|
|
129
|
+
protected async _applyMask(
|
|
130
|
+
data: DataPictures,
|
|
131
|
+
tile: XYZ,
|
|
132
|
+
tileType: TileType,
|
|
133
|
+
needCopy: boolean,
|
|
134
|
+
): Promise<void> {
|
|
135
|
+
const { style } = this._layer;
|
|
136
|
+
if (
|
|
137
|
+
(style.mask === "land" || style.mask === "sea") &&
|
|
138
|
+
tileType === TileType.Mixed
|
|
139
|
+
) {
|
|
140
|
+
if (needCopy) {
|
|
141
|
+
// !!make a copy before masking!! or original data will be spoiled
|
|
142
|
+
// needCopy is false if this is a subTile (already copied from parent)
|
|
143
|
+
const { raw: inRaw, dmin, dmax, dmul } = data[0];
|
|
144
|
+
data[0] = { raw: new Uint16Array(inRaw), dmin, dmax, dmul };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let maskImage: ImageData;
|
|
148
|
+
const { wxAPI } = this._layer.wxdatasetManager;
|
|
149
|
+
try {
|
|
150
|
+
const { upCoords, subCoords } = splitCoords(tile, wxAPI.maskDepth);
|
|
151
|
+
maskImage = await wxAPI.loadMaskFunc(upCoords);
|
|
152
|
+
maskImage = subMask(maskImage, subCoords, wxAPI.maskChannel);
|
|
153
|
+
} catch (e) {
|
|
154
|
+
style.mask = undefined;
|
|
155
|
+
WXLOG("Can't load Mask. Masking is disabled");
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
applyMask(data[0], maskImage, wxAPI.maskChannel, style.mask);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** @no_this @ignore */
|
|
164
|
+
protected _vectorMagnitudesPrepare(data: DataPictures): void {
|
|
165
|
+
if (data.length === 1) return; // no need to process
|
|
166
|
+
data.unshift({
|
|
167
|
+
raw: new Uint16Array(258 * 258),
|
|
168
|
+
dmin: 0,
|
|
169
|
+
dmax: 0,
|
|
170
|
+
dmul: 0,
|
|
171
|
+
});
|
|
172
|
+
const [l, u, v] = data; // length, u, v components
|
|
173
|
+
l.dmax = 1.42 * Math.max(-u.dmin, u.dmax, -v.dmin, v.dmax);
|
|
174
|
+
l.dmul = (l.dmax - l.dmin) / 65535;
|
|
175
|
+
for (let i = 0; i < 258 * 258; ++i) {
|
|
176
|
+
if (!u.raw[i] || !v.raw[i]) {
|
|
177
|
+
// l.raw[i] = 0; // by default it's 0
|
|
178
|
+
continue;
|
|
179
|
+
} // NODATA
|
|
180
|
+
const _u = u.dmin + u.dmul * u.raw[i]; // unpack U data
|
|
181
|
+
const _v = v.dmin + v.dmul * v.raw[i]; // unpack V data
|
|
182
|
+
l.raw[i] = Math.sqrt(_v * _v + _u * _u) / l.dmul; // pack data back to use the original rendering approach
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** @ignore */
|
|
187
|
+
protected _checkTypeAndMask(coords: XYZ): TileType | undefined {
|
|
188
|
+
const { mask } = this._layer.style;
|
|
189
|
+
if (mask === "land" || mask === "sea") {
|
|
190
|
+
const tileType = this._layer.wxdatasetManager.wxAPI.qtree.check(coords); // check 'type' of the tile
|
|
191
|
+
return mask === tileType ? undefined /* cut by QTree */ : tileType;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return TileType.Mixed;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** @ignore */
|
|
198
|
+
protected _checkInsideBoundaries(coords: XYZ): boolean {
|
|
199
|
+
const boundaries = this._layer.getBoundaries();
|
|
200
|
+
if (boundaries?.boundaries180) {
|
|
201
|
+
const bbox = makeBox(coords);
|
|
202
|
+
const rectIntersect = (b: WxBoundaryMeta) =>
|
|
203
|
+
!(
|
|
204
|
+
bbox.west > b.east ||
|
|
205
|
+
b.west > bbox.east ||
|
|
206
|
+
bbox.south > b.north ||
|
|
207
|
+
b.south > bbox.north
|
|
208
|
+
);
|
|
209
|
+
if (!boundaries.boundaries180.some(rectIntersect)) {
|
|
210
|
+
return false; // cut by boundaries
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** @ignore */
|
|
218
|
+
protected _createStreamLines(data: DataPictures): SLine[] {
|
|
219
|
+
if (data.length !== 3) return [];
|
|
220
|
+
const { style } = this._layer;
|
|
221
|
+
if (style.streamLineColor === "none") return [];
|
|
222
|
+
const streamLines: SLine[] = []; // an array of stremllines. Each section of streamline represents a position and size of a particle.
|
|
223
|
+
|
|
224
|
+
// idea is taken from the LIC (linear integral convolution) algorithm and the 'multipartical vector field visualisation'
|
|
225
|
+
// Having the stream lines as precalculated trajectories makes an animation more predictable and (IMHO) representative.
|
|
226
|
+
// Algorithm: use U and V as an increment to build a trajectory. To make trajectory more or less correct the algo
|
|
227
|
+
// does 20 moc steps and stores the point into streamline (sLine).
|
|
228
|
+
// Algo does two passes: forward and backward, to cope boundaries and improve visual effect.
|
|
229
|
+
const [l, u, v] = data;
|
|
230
|
+
const factor = (style.streamLineSpeedFactor || 1) / l.dmax;
|
|
231
|
+
const addDegrees = style.addDegrees
|
|
232
|
+
? 0.017453292519943 * style.addDegrees
|
|
233
|
+
: 0;
|
|
234
|
+
const gridStep = style.streamLineGridStep || 64;
|
|
235
|
+
const steps = style.streamLineSteps || 300;
|
|
236
|
+
for (let y = 0; y <= 256; y += gridStep) {
|
|
237
|
+
for (let x = 0; x <= 256; x += gridStep) {
|
|
238
|
+
if (!l.raw[1 + x + (1 + y) * 258]) continue; // NODATA
|
|
239
|
+
const sLine: SLine = []; // streamline
|
|
240
|
+
let xforw = x;
|
|
241
|
+
let yforw = y;
|
|
242
|
+
let oldDi = -1; // previous di. The first di will never be -1
|
|
243
|
+
let dx = 0;
|
|
244
|
+
let dy = 0;
|
|
245
|
+
for (
|
|
246
|
+
let i = 0;
|
|
247
|
+
i <= steps &&
|
|
248
|
+
xforw >= 0 &&
|
|
249
|
+
xforw <= 256 &&
|
|
250
|
+
yforw >= 0 &&
|
|
251
|
+
yforw <= 256;
|
|
252
|
+
i++
|
|
253
|
+
) {
|
|
254
|
+
// forward
|
|
255
|
+
if (!(i % (steps / 10))) sLine.push({ x: ~~xforw, y: ~~yforw }); // push each (steps/10)-th point // 7 points max
|
|
256
|
+
const di = ~~xforw + 1 + (~~yforw + 1) * 258;
|
|
257
|
+
if (di !== oldDi) {
|
|
258
|
+
// calc dx, dy only if di changed
|
|
259
|
+
if (!l.raw[di]) break; // NODATA - stop streamline creation
|
|
260
|
+
oldDi = di; // save old di
|
|
261
|
+
const dl = l.dmin + l.raw[di] * l.dmul;
|
|
262
|
+
const du = u.dmin + u.raw[di] * u.dmul;
|
|
263
|
+
const dv = v.dmin + v.raw[di] * v.dmul;
|
|
264
|
+
const ang = Math.atan2(du, dv) + addDegrees;
|
|
265
|
+
dx = factor * dl * Math.sin(ang);
|
|
266
|
+
dy = factor * dl * Math.cos(ang);
|
|
267
|
+
}
|
|
268
|
+
xforw += dx;
|
|
269
|
+
yforw -= dy; // negative - due to Lat goes up but screen's coordinates go down
|
|
270
|
+
} // for i forward
|
|
271
|
+
let xback = x;
|
|
272
|
+
let yback = y;
|
|
273
|
+
oldDi = -1; // previous di. The first di will never be -1
|
|
274
|
+
for (
|
|
275
|
+
let i = 1;
|
|
276
|
+
i <= steps &&
|
|
277
|
+
xback >= 0 &&
|
|
278
|
+
xback <= 256 &&
|
|
279
|
+
yback >= 0 &&
|
|
280
|
+
yback <= 256;
|
|
281
|
+
i++
|
|
282
|
+
) {
|
|
283
|
+
// backward // i = 1 because otherwise it produces the same first point hence visual artefact! 2 hours debugging!
|
|
284
|
+
if (!(i % (steps / 10))) sLine.unshift({ x: ~~xback, y: ~~yback }); // push each (steps/10)-th point // 6 points max
|
|
285
|
+
const di = ~~xback + 1 + (~~yback + 1) * 258;
|
|
286
|
+
if (di !== oldDi) {
|
|
287
|
+
// calc dx, dy only if di changed
|
|
288
|
+
if (!l.raw[di]) break; // NODATA - stop streamline creation
|
|
289
|
+
oldDi = di; // save old di
|
|
290
|
+
const dl = l.dmin + l.raw[di] * l.dmul;
|
|
291
|
+
const du = u.dmin + u.raw[di] * u.dmul;
|
|
292
|
+
const dv = v.dmin + v.raw[di] * v.dmul;
|
|
293
|
+
const ang = Math.atan2(du, dv) + addDegrees;
|
|
294
|
+
dx = factor * dl * Math.sin(ang);
|
|
295
|
+
dy = factor * dl * Math.cos(ang);
|
|
296
|
+
}
|
|
297
|
+
xback -= dx;
|
|
298
|
+
yback += dy; // positive - due to Lat goes up but screen's coordinates go down
|
|
299
|
+
} // for i backward
|
|
300
|
+
sLine.length > 2 && streamLines.push(sLine);
|
|
301
|
+
} // for x
|
|
302
|
+
} // for y
|
|
303
|
+
return streamLines;
|
|
304
|
+
} // _createSLines
|
|
305
|
+
}
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { PixelsToLonLat, coordToPixel } from "../utils/mercator";
|
|
2
|
+
import type { DataPicture, XYZ } from "../utils/wxtools";
|
|
3
|
+
import type { WxBoundaryMeta } from "../types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Convert a degree to a value on a linear scale, wrapping around at 360 degrees.
|
|
7
|
+
* @param start - The starting angle in degrees.
|
|
8
|
+
* @param end - The ending angle in degrees.
|
|
9
|
+
* @param amount - The interpolation amount between the start and end.
|
|
10
|
+
* @returns The interpolated angle, wrapped to the [0, 360) degree range.
|
|
11
|
+
*/
|
|
12
|
+
function interpolatorDegreeLinear(
|
|
13
|
+
start: number,
|
|
14
|
+
end: number,
|
|
15
|
+
amount: number,
|
|
16
|
+
): number {
|
|
17
|
+
const shortestAngle = ((((end - start) % 360) + 540) % 360) - 180;
|
|
18
|
+
return (start + shortestAngle * amount + 360) % 360;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type InterpolatorSquare = (
|
|
22
|
+
a: number,
|
|
23
|
+
b: number,
|
|
24
|
+
c: number,
|
|
25
|
+
d: number,
|
|
26
|
+
dxt: number,
|
|
27
|
+
dyt: number,
|
|
28
|
+
dmin: number,
|
|
29
|
+
dmul: number,
|
|
30
|
+
) => number;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Interpolator function for square-based bilinear interpolation.
|
|
34
|
+
* This function calculates the interpolated value based on the corners of the square.
|
|
35
|
+
* The interpolation is applied within a 2D grid of values.
|
|
36
|
+
*
|
|
37
|
+
* @param a_ - Value at the top-left corner of the square.
|
|
38
|
+
* @param b_ - Value at the top-right corner of the square.
|
|
39
|
+
* @param c_ - Value at the bottom-left corner of the square.
|
|
40
|
+
* @param d_ - Value at the bottom-right corner of the square.
|
|
41
|
+
* @param dxt - Interpolation coefficient in the x-direction.
|
|
42
|
+
* @param dyt - Interpolation coefficient in the y-direction.
|
|
43
|
+
* @param dmin - Minimum data value.
|
|
44
|
+
* @param dmul - Multiplication factor for scaling.
|
|
45
|
+
* @returns The interpolated value within the square.
|
|
46
|
+
*/
|
|
47
|
+
function interpolatorSquareDegree(
|
|
48
|
+
a_: number,
|
|
49
|
+
b_: number,
|
|
50
|
+
c_: number,
|
|
51
|
+
d_: number,
|
|
52
|
+
dxt: number,
|
|
53
|
+
dyt: number,
|
|
54
|
+
dmin: number,
|
|
55
|
+
dmul: number,
|
|
56
|
+
): number {
|
|
57
|
+
// a----b
|
|
58
|
+
// | |
|
|
59
|
+
// | |
|
|
60
|
+
// c----d
|
|
61
|
+
let a = a_;
|
|
62
|
+
let b = b_;
|
|
63
|
+
let c = c_;
|
|
64
|
+
let d = d_;
|
|
65
|
+
|
|
66
|
+
// 16 possible variants for a,b,c,d != 0 ( != NaN)
|
|
67
|
+
const sq = (a ? 1 : 0) | (b ? 2 : 0) | (c ? 4 : 0) | (d ? 8 : 0);
|
|
68
|
+
switch (sq) {
|
|
69
|
+
case 0b0000:
|
|
70
|
+
return 0; // NaN
|
|
71
|
+
case 0b0001: // only a != NaN
|
|
72
|
+
return a;
|
|
73
|
+
case 0b0010: // only b != NaN
|
|
74
|
+
return b;
|
|
75
|
+
case 0b0011: // a, b != NaN
|
|
76
|
+
c = a;
|
|
77
|
+
d = b;
|
|
78
|
+
break;
|
|
79
|
+
case 0b0100: // ... etc
|
|
80
|
+
return c;
|
|
81
|
+
case 0b0101:
|
|
82
|
+
b = a;
|
|
83
|
+
d = c;
|
|
84
|
+
break;
|
|
85
|
+
case 0b0110:
|
|
86
|
+
d = (b + c) >> 1;
|
|
87
|
+
a = d;
|
|
88
|
+
break;
|
|
89
|
+
case 0b0111:
|
|
90
|
+
d = (b + c) >> 1;
|
|
91
|
+
break;
|
|
92
|
+
case 0b1000:
|
|
93
|
+
return d;
|
|
94
|
+
case 0b1001:
|
|
95
|
+
b = (a + d) >> 1;
|
|
96
|
+
c = b;
|
|
97
|
+
break;
|
|
98
|
+
case 0b1010:
|
|
99
|
+
a = b;
|
|
100
|
+
c = d;
|
|
101
|
+
break;
|
|
102
|
+
case 0b1011:
|
|
103
|
+
c = (a + d) >> 1;
|
|
104
|
+
break;
|
|
105
|
+
case 0b1100:
|
|
106
|
+
a = c;
|
|
107
|
+
b = d;
|
|
108
|
+
break;
|
|
109
|
+
case 0b1101:
|
|
110
|
+
b = (a + d) >> 1;
|
|
111
|
+
break;
|
|
112
|
+
case 0b1110:
|
|
113
|
+
a = (b + c) >> 1;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// decode Data
|
|
118
|
+
a = dmin + dmul * a;
|
|
119
|
+
b = dmin + dmul * b;
|
|
120
|
+
c = dmin + dmul * c;
|
|
121
|
+
d = dmin + dmul * d;
|
|
122
|
+
|
|
123
|
+
// 2) bilinear
|
|
124
|
+
const u = interpolatorDegreeLinear(a, b, dxt); // upper line
|
|
125
|
+
const l = interpolatorDegreeLinear(c, d, dxt); // lower line
|
|
126
|
+
// Encode Data back before returning
|
|
127
|
+
const ul = (interpolatorDegreeLinear(u, l, dyt) - dmin) / dmul;
|
|
128
|
+
if (ul < 1) return 1; // As 0 is NaN, we don't need NaN here! so return 1 instead of NaN
|
|
129
|
+
return ul;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Interpolator function for square-based interpolation.
|
|
134
|
+
* This function calculates the interpolated value within a square grid.
|
|
135
|
+
*
|
|
136
|
+
* @param a - Value at the top-left corner of the square.
|
|
137
|
+
* @param b - Value at the top-right corner of the square.
|
|
138
|
+
* @param c - Value at the bottom-left corner of the square.
|
|
139
|
+
* @param d - Value at the bottom-right corner of the square.
|
|
140
|
+
* @param dxt - Interpolation coefficient in the x-direction.
|
|
141
|
+
* @param dyt - Interpolation coefficient in the y-direction.
|
|
142
|
+
* @param dmin - Minimum data value.
|
|
143
|
+
* @param dmul - Multiplication factor for scaling.
|
|
144
|
+
* @returns The interpolated value within the square.
|
|
145
|
+
*/
|
|
146
|
+
function interpolatorSquare(
|
|
147
|
+
a: number,
|
|
148
|
+
b: number,
|
|
149
|
+
c: number,
|
|
150
|
+
d: number,
|
|
151
|
+
dxt: number,
|
|
152
|
+
dyt: number,
|
|
153
|
+
_dmin: number,
|
|
154
|
+
_dmul: number,
|
|
155
|
+
): number {
|
|
156
|
+
// 0 1
|
|
157
|
+
// a --- b default version a --- b flipped version
|
|
158
|
+
// | / | | \ |
|
|
159
|
+
// | / x | - pyt | \ |
|
|
160
|
+
// c --- d c --- d
|
|
161
|
+
// 2 | 3
|
|
162
|
+
// pxt
|
|
163
|
+
//
|
|
164
|
+
// x - point to interpolate
|
|
165
|
+
// a, b, c, d - corners of the square
|
|
166
|
+
// 16 possible variants for a,b,c,d != 0 ( != NaN)
|
|
167
|
+
const sq = (a ? 1 : 0) | (b ? 2 : 0) | (c ? 4 : 0) | (d ? 8 : 0);
|
|
168
|
+
switch (sq) {
|
|
169
|
+
case 0b0111: // -cba -default version
|
|
170
|
+
return dxt + dyt < 1 ? dxt * (b - a) + dyt * (c - a) + a : 0;
|
|
171
|
+
case 0b1110: // dcb- -default version
|
|
172
|
+
return dxt + dyt < 1 ? 0 : dxt * (d - c) + dyt * (d - b) + b + c - d;
|
|
173
|
+
case 0b1011: // d-ba - flipped version
|
|
174
|
+
return dyt < dxt ? (1 - dxt) * (a - b) + dyt * (d - b) + b : 0;
|
|
175
|
+
case 0b1101: // dc-a - flipped version
|
|
176
|
+
return dyt < dxt ? 0 : (1 - dxt) * (c - d) + dyt * (c - a) + a + d - c;
|
|
177
|
+
case 0b1111: // dcba - default version
|
|
178
|
+
return dxt + dyt < 1
|
|
179
|
+
? dxt * (b - a) + dyt * (c - a) + a
|
|
180
|
+
: dxt * (d - c) + dyt * (d - b) + b + c - d;
|
|
181
|
+
default:
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Subdivide a data picture using a specified interpolation method.
|
|
188
|
+
* The interpolation is performed to extract a sub-region (subtile) from a larger data picture.
|
|
189
|
+
*
|
|
190
|
+
* @param interpolator - The interpolation function to use.
|
|
191
|
+
* @param inputData - The input data picture from which to extract the subtile.
|
|
192
|
+
* @param subCoords - The coordinates of the subtile within the grid.
|
|
193
|
+
* @returns The subdivided data picture containing the interpolated subtile.
|
|
194
|
+
*/
|
|
195
|
+
function subDataPicture(
|
|
196
|
+
interpolator: InterpolatorSquare,
|
|
197
|
+
inputData: DataPicture,
|
|
198
|
+
subCoords: XYZ,
|
|
199
|
+
): DataPicture {
|
|
200
|
+
const subTileSize = 1 / 2 ** subCoords.z; // a size of a subtile
|
|
201
|
+
const subTileStartX = subCoords.x * 256 * subTileSize - 0.5; // upper left point of a subtile Shifted by 0.5 to get the center of the pixel
|
|
202
|
+
const subTileStartY = subCoords.y * 256 * subTileSize - 0.5;
|
|
203
|
+
const { raw: inRaw, dmin, dmax, dmul } = inputData;
|
|
204
|
+
const subData: DataPicture = {
|
|
205
|
+
raw: new Uint16Array(258 * 258),
|
|
206
|
+
dmin,
|
|
207
|
+
dmax,
|
|
208
|
+
dmul,
|
|
209
|
+
};
|
|
210
|
+
const { raw: outRaw } = subData;
|
|
211
|
+
for (
|
|
212
|
+
let outY = -1,
|
|
213
|
+
outIndex = 0,
|
|
214
|
+
inYf = subTileStartY - subTileSize + 1 /*+1 to shift index */;
|
|
215
|
+
outY <= 256;
|
|
216
|
+
outY++, inYf += subTileSize
|
|
217
|
+
) {
|
|
218
|
+
const inYi = Math.floor(inYf); // don't use `~~` because of negatives on left and upper borders
|
|
219
|
+
const yt = inYf - inYi; // [0, 1] - `y` interpolati`on coeff
|
|
220
|
+
const inYi258 = inYi * 258;
|
|
221
|
+
for (
|
|
222
|
+
let outX = -1,
|
|
223
|
+
inXf = subTileStartX - subTileSize + 1 /*+1 to shift index */;
|
|
224
|
+
outX <= 256;
|
|
225
|
+
outX++, outIndex++, inXf += subTileSize
|
|
226
|
+
) {
|
|
227
|
+
const inXi = Math.floor(inXf); // don't use ~~ because of negatives
|
|
228
|
+
const xt = inXf - inXi;
|
|
229
|
+
const inIndex = inXi + inYi258; // data index
|
|
230
|
+
// interpolation inside a rectangular
|
|
231
|
+
const a = inRaw[inIndex]; // upper left corner
|
|
232
|
+
const b = inRaw[inIndex + 1]; // upper right
|
|
233
|
+
const c = inRaw[inIndex + 258]; // lower left
|
|
234
|
+
const d = inRaw[inIndex + 258 + 1]; // lower right
|
|
235
|
+
outRaw[outIndex] = interpolator(a, b, c, d, xt, yt, dmin, dmul);
|
|
236
|
+
} // for x
|
|
237
|
+
} // for y
|
|
238
|
+
|
|
239
|
+
return subData;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Get sub-tile of a mask via baricemrtric interpolation
|
|
244
|
+
* @param {ImageData} inputData - input data
|
|
245
|
+
* @param {XYZ | undefined} subCoords - subtile coordinates
|
|
246
|
+
* @returns {ImageData} subtile data
|
|
247
|
+
* */
|
|
248
|
+
export function subMask(
|
|
249
|
+
inputData: ImageData,
|
|
250
|
+
subCoords: XYZ | undefined,
|
|
251
|
+
channel: number,
|
|
252
|
+
): ImageData {
|
|
253
|
+
if (!subCoords) return inputData;
|
|
254
|
+
|
|
255
|
+
const clamp = (v: number) => (v < 0 ? 0 : v > 254 ? 254 : v);
|
|
256
|
+
const subTileSize = 1 / 2 ** subCoords.z; // a size of a subtile
|
|
257
|
+
const subTileStartX = subCoords.x * 256 * subTileSize - 0.5; // upper left point of a subtile Shifted by 0.5 to get the center of the pixel
|
|
258
|
+
const subTileStartY = subCoords.y * 256 * subTileSize - 0.5;
|
|
259
|
+
const { data: inData } = inputData;
|
|
260
|
+
const subData: ImageData = new ImageData(256, 256);
|
|
261
|
+
const { data: outData } = subData;
|
|
262
|
+
for (
|
|
263
|
+
let outY = 0, outIndex = channel, inYf = subTileStartY;
|
|
264
|
+
outY < 256;
|
|
265
|
+
outY++, inYf += subTileSize
|
|
266
|
+
) {
|
|
267
|
+
const inYi = ~~clamp(inYf);
|
|
268
|
+
const yt = inYf - inYi; // [0, 1] - `y` interpolation coeff
|
|
269
|
+
const inYi256 = inYi * 256;
|
|
270
|
+
for (
|
|
271
|
+
let outX = 0, inXf = subTileStartX;
|
|
272
|
+
outX < 256;
|
|
273
|
+
outX++, outIndex += 4, inXf += subTileSize
|
|
274
|
+
) {
|
|
275
|
+
const inXi = ~~clamp(inXf);
|
|
276
|
+
const xt = inXf - inXi;
|
|
277
|
+
const inIndex = (inXi + inYi256) * 4 + channel; // data index to pixel/channel used as a mask
|
|
278
|
+
// interpolation inside a rectangular
|
|
279
|
+
const a = inData[inIndex]; // upper left corner
|
|
280
|
+
const b = inData[inIndex + 4]; // upper right
|
|
281
|
+
const c = inData[inIndex + 4 * 256]; // lower left
|
|
282
|
+
const d = inData[inIndex + 4 * 256 + 4]; // lower right
|
|
283
|
+
const r = interpolatorSquare(a, b, c, d, xt, yt, 0, 0);
|
|
284
|
+
// const r = xt + yt < 1 ? xt * (b - a) + yt * (c - a) + a : xt * (d - c) + yt * (d - b) + b + c - d; // barycentric interpolation
|
|
285
|
+
outData[outIndex] = r > 127 ? 255 : 0;
|
|
286
|
+
} // for x
|
|
287
|
+
} // for y
|
|
288
|
+
|
|
289
|
+
return subData;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Get sub-tile of a regular data via baricemrtric interpolation
|
|
294
|
+
* @param {DataPicture} inputData - input data
|
|
295
|
+
* @param {XYZ | undefined} subCoords - subtile coordinates
|
|
296
|
+
* @returns {DataPicture} subtile data
|
|
297
|
+
* */
|
|
298
|
+
export function subData(inputData: DataPicture, subCoords?: XYZ): DataPicture {
|
|
299
|
+
if (!subCoords) return inputData;
|
|
300
|
+
return subDataPicture(interpolatorSquare, inputData, subCoords);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Get sub-tile of a degree data tile via bilinear degree interpolation, so middle of 350..10 degree is 0 degree.
|
|
305
|
+
* @param {DataPicture} inputData - input data
|
|
306
|
+
* @param {XYZ | undefined} subCoords - subtile coordinates
|
|
307
|
+
* @returns {DataPicture} subtile data
|
|
308
|
+
* */
|
|
309
|
+
export function subDataDegree(
|
|
310
|
+
inputData: DataPicture,
|
|
311
|
+
subCoords?: XYZ,
|
|
312
|
+
): DataPicture {
|
|
313
|
+
if (!subCoords) return inputData;
|
|
314
|
+
return subDataPicture(interpolatorSquareDegree, inputData, subCoords);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Upply sea/land mask to a data tile
|
|
319
|
+
* 0 - for the masks from Sarah (current), 3 - for the masks from Mapbox
|
|
320
|
+
* @param {DataPicture} dataIn - data tile
|
|
321
|
+
* @param {ImageData} mask - sea/land mask
|
|
322
|
+
* @param {number} mc - mask channel of the mask picture to use (0 - Red, 1 - Green, 2 - Blue, 3 - Alpha)
|
|
323
|
+
* @param {'sea' | 'land'} maskType - sea or land masking to apply
|
|
324
|
+
* @returns {DataPicture} - masked data tile
|
|
325
|
+
* */
|
|
326
|
+
export function applyMask(
|
|
327
|
+
dataIn: DataPicture,
|
|
328
|
+
{ data }: ImageData,
|
|
329
|
+
mc: number,
|
|
330
|
+
maskType: "land" | "sea",
|
|
331
|
+
): DataPicture {
|
|
332
|
+
const sea = maskType === "sea";
|
|
333
|
+
const { raw } = dataIn;
|
|
334
|
+
for (let i = mc, j = 259, y = 0; y < 256; j += 2, y++) {
|
|
335
|
+
for (let x = 0; x < 256; x++, j++, i += 4) {
|
|
336
|
+
if (sea === !data[i]) {
|
|
337
|
+
raw[j] = 0; // Perform assignment clearly in the if block
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return dataIn;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Create a bounding box for a tile
|
|
347
|
+
* @param coords - tile coordinates
|
|
348
|
+
* @returns {WxBoundaryMeta} [minLon, minLat, maxLon, maxLat]
|
|
349
|
+
* */
|
|
350
|
+
export function makeBox(coords: XYZ): WxBoundaryMeta {
|
|
351
|
+
const [px, py] = coordToPixel(coords.x, coords.y);
|
|
352
|
+
const [west, north] = PixelsToLonLat(px, py, coords.z);
|
|
353
|
+
const [east, south] = PixelsToLonLat(px + 256, py + 256, coords.z);
|
|
354
|
+
return { west, north, east, south };
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Splits tile coordinates into a tile coords at maximum zoom and a subtile coords.
|
|
359
|
+
* If the tile is below maximum zoom, the subtile coords are undefined.
|
|
360
|
+
* @param coords - tile coordinates
|
|
361
|
+
* @param maxZoom - maximum zoom
|
|
362
|
+
* @returns [tile coords, subtile coords (or undefined)]
|
|
363
|
+
* */
|
|
364
|
+
export function splitCoords(
|
|
365
|
+
coords: XYZ,
|
|
366
|
+
maxZoom: number,
|
|
367
|
+
): { upCoords: XYZ; subCoords?: XYZ } {
|
|
368
|
+
const zDif = coords.z - maxZoom;
|
|
369
|
+
if (zDif <= 0) {
|
|
370
|
+
return { upCoords: coords };
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const upCoords = { x: coords.x >>> zDif, y: coords.y >>> zDif, z: maxZoom };
|
|
374
|
+
const subCoords = {
|
|
375
|
+
x: coords.x & ((1 << zDif) - 1),
|
|
376
|
+
y: coords.y & ((1 << zDif) - 1),
|
|
377
|
+
z: zDif,
|
|
378
|
+
};
|
|
379
|
+
return { upCoords, subCoords };
|
|
380
|
+
}
|