@metoceanapi/wxtiles-leaflet 2.0.6 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +13 -18
- package/dist/es/controls/WxStyleEditorControl.d.ts +1 -1
- package/dist/es/controls/WxTimeControl .d.ts +2 -2
- package/dist/es/index.d.ts +6 -6
- package/dist/es/index.js +6 -1
- package/dist/es/utils/wxtools.d.ts +64 -44
- package/dist/es/wxAPI/WxDataSetManager.d.ts +7 -1
- package/dist/es/wxlayer/WxImplementation.d.ts +3 -3
- package/dist/es/wxlayer/loadertools.d.ts +1 -1
- package/dist/es/wxlayer/wxlayer.d.ts +5 -7
- package/dist/es/wxsource/wxsource.d.ts +2 -2
- package/dist/es/wxsource/wxsourcetypes.d.ts +3 -0
- package/dist/web/index.js +6 -1
- package/docs/docs/assets/search.js +1 -1
- package/docs/docs/classes/FrameworkParentClass.html +21 -9
- package/docs/docs/classes/Loader.html +7 -7
- package/docs/docs/classes/Painter.html +6 -6
- package/docs/docs/classes/QTree.html +6 -6
- package/docs/docs/classes/RawCLUT.html +7 -7
- package/docs/docs/classes/WxAPI.html +18 -18
- package/docs/docs/classes/WxDataSetManager.html +37 -20
- package/docs/docs/classes/WxLayer.html +25 -25
- package/docs/docs/classes/WxLayerBaseImplementation.html +33 -20
- package/docs/docs/classes/WxTileSource.html +40 -22
- package/docs/docs/enums/TileType.html +4 -4
- package/docs/docs/functions/WXLOG.html +4 -3
- package/docs/docs/functions/WxCreateLegend.html +2 -1
- package/docs/docs/functions/WxGetColorSchemes.html +2 -1
- package/docs/docs/functions/WxGetColorStyles.html +2 -1
- package/docs/docs/functions/WxTilesLogging.html +4 -3
- package/docs/docs/index.html +10 -8
- package/docs/docs/interfaces/ColorStylesIncomplete.html +2 -1
- package/docs/docs/interfaces/Converter.html +2 -2
- package/docs/docs/interfaces/DataIntegral.html +7 -7
- package/docs/docs/interfaces/DataPicture.html +5 -5
- package/docs/docs/interfaces/FrameworkOptions.html +20 -63
- package/docs/docs/interfaces/IntegralPare.html +3 -3
- package/docs/docs/interfaces/SLinePoint.html +3 -3
- package/docs/docs/interfaces/Tree.html +2 -2
- package/docs/docs/interfaces/WxAPIOptions.html +10 -10
- package/docs/docs/interfaces/WxAllBoundariesMeta.html +4 -4
- package/docs/docs/interfaces/WxBoundaryMeta.html +5 -5
- package/docs/docs/interfaces/WxColorSchemes.html +2 -1
- package/docs/docs/interfaces/WxColorStyleStrict.html +80 -60
- package/docs/docs/interfaces/WxColorStyleWeak.html +80 -60
- package/docs/docs/interfaces/WxColorStylesStrict.html +2 -2
- package/docs/docs/interfaces/WxColorStylesWeakMixed.html +2 -1
- package/docs/docs/interfaces/WxData.html +3 -3
- package/docs/docs/interfaces/WxDataSetManagerOptions.html +6 -6
- package/docs/docs/interfaces/WxDataSetsMetasJSON.html +2 -2
- package/docs/docs/interfaces/WxDatasetMeta.html +9 -9
- package/docs/docs/interfaces/WxDatasetShortMeta.html +4 -4
- package/docs/docs/interfaces/WxLayerAPI.html +19 -19
- package/docs/docs/interfaces/WxLayerBaseAPI.html +15 -15
- package/docs/docs/interfaces/WxLayerOptions.html +17 -10
- package/docs/docs/interfaces/WxLegend.html +7 -7
- package/docs/docs/interfaces/WxLngLat.html +3 -3
- package/docs/docs/interfaces/WxRasterData.html +5 -5
- package/docs/docs/interfaces/WxRequestInit.html +2 -2
- package/docs/docs/interfaces/WxSourceLayerOptions.html +109 -0
- package/docs/docs/interfaces/WxTick.html +5 -5
- package/docs/docs/interfaces/WxTileInfo.html +9 -9
- package/docs/docs/interfaces/WxTilesLibOptions.html +4 -4
- package/docs/docs/interfaces/WxUnits.html +2 -1
- package/docs/docs/interfaces/WxVariableMeta.html +6 -6
- package/docs/docs/interfaces/WxVariablesMetas.html +2 -1
- package/docs/docs/interfaces/XYZ.html +4 -4
- package/docs/docs/modules.html +2 -0
- package/docs/docs/types/DataIntegrals.html +2 -1
- package/docs/docs/types/DataPictures.html +2 -1
- package/docs/docs/types/SLine.html +2 -1
- package/docs/docs/types/SubTrees.html +2 -1
- package/docs/docs/types/SubTreesN.html +2 -1
- package/docs/docs/types/TreeN.html +2 -1
- package/docs/docs/types/UriLoaderPromiseFunc.html +2 -1
- package/docs/docs/types/WxDate.html +2 -1
- package/docs/docs/types/WxURIs.html +2 -1
- package/docs/docs/types/WxUnitTuple.html +2 -1
- package/docs/docs/types/WxVars.html +2 -1
- package/docs/script/script.js +8 -3
- package/package.json +2 -2
- package/src_example/index.ts +111 -54
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metoceanapi/wxtiles-leaflet",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "WxTile JS lib to render wxtiles datalayers",
|
|
5
5
|
"main": "dist/es/index.js",
|
|
6
6
|
"types": "dist/es/index.d.ts",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"build_DEMO_Docs": "npm run build && npm run buildDOCS && node build-for-docs.js",
|
|
9
9
|
"start": "PORT=3002 node watch-public.js",
|
|
10
10
|
"build": "rm -rf dist/ && node build.js && tsc",
|
|
11
|
-
"buildDOCS": "./node_modules/.bin/typedoc --out docs/docs --excludeExternals src",
|
|
11
|
+
"buildDOCS": "./node_modules/.bin/typedoc --out docs/docs --excludeExternals -gitRevision main src",
|
|
12
12
|
"preversion": "npm run build",
|
|
13
13
|
"version": "changelogkeeper && git add CHANGELOG.md",
|
|
14
14
|
"npm_reinstall": "rm -rf node_modules package-lock.json && npm i",
|
package/src_example/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'leaflet/dist/leaflet.css';
|
|
2
2
|
import L from 'leaflet'; // goes first always!
|
|
3
3
|
|
|
4
|
-
import { WxTileSource, type WxVars, WxAPI, WxTilesLogging, type WxTileInfo, FrameworkOptions } from '../src/index';
|
|
4
|
+
import { WxTileSource, type WxVars, WxAPI, WxTilesLogging, type WxTileInfo, FrameworkOptions, WxGetColorStyles, WXLOG } from '../src/index';
|
|
5
5
|
import { WxLegendControl } from '../src/controls/WxLegendControl';
|
|
6
6
|
import { WxStyleEditorControl } from '../src/controls/WxStyleEditorControl';
|
|
7
7
|
import { WxInfoControl } from '../src/controls/WxInfoControl';
|
|
@@ -10,6 +10,7 @@ import { WxAPIControl } from '../src/controls/WxAPIControl';
|
|
|
10
10
|
|
|
11
11
|
start();
|
|
12
12
|
// simpleDemo();
|
|
13
|
+
// twoLayersDemo();
|
|
13
14
|
|
|
14
15
|
const OPACITY = 1;
|
|
15
16
|
|
|
@@ -28,12 +29,14 @@ async function start() {
|
|
|
28
29
|
const wxapi = new WxAPI({
|
|
29
30
|
dataServerURL,
|
|
30
31
|
maskURL: dataServerURL + 'masks/{z}/{x}/{y}.png',
|
|
32
|
+
maskChannel: 'R',
|
|
33
|
+
maskDepth: 9, // currently only max 9 is supported
|
|
31
34
|
qtreeURL: dataServerURL + 'masks/9+1.seamask.qtree',
|
|
32
35
|
requestInit: { headers: myHeaders },
|
|
33
36
|
});
|
|
34
37
|
|
|
35
38
|
let datasetName = 'gfs.global'; /* 'mercator.global/'; */ /* 'ecwmf.global/'; */ /* 'obs-radar.rain.nzl.national/'; */
|
|
36
|
-
let
|
|
39
|
+
let variable = 'air.temperature.at-2m';
|
|
37
40
|
// let variables: WxVars = ['wind.speed.eastward.at-10m', 'wind.speed.northward.at-10m'];
|
|
38
41
|
|
|
39
42
|
// let datasetName = 'ww3-ecmwf.global';
|
|
@@ -43,52 +46,44 @@ async function start() {
|
|
|
43
46
|
// let variables: WxVars = ['reflectivity'];
|
|
44
47
|
|
|
45
48
|
// get datasetName from URL
|
|
46
|
-
const urlParams = window.location.toString().split('
|
|
49
|
+
const urlParams = window.location.toString().split('##')[1];
|
|
47
50
|
const params = urlParams?.split('/');
|
|
48
51
|
datasetName = params?.[0] || datasetName;
|
|
49
|
-
if (params?.[1])
|
|
52
|
+
if (params?.[1]) variable = params[1];
|
|
50
53
|
let time = params?.[2] || '';
|
|
51
54
|
const zoom = (params && parseFloat(params[3])) || 0;
|
|
52
55
|
const lng = (params && parseFloat(params[4])) || 0;
|
|
53
56
|
const lat = (params && parseFloat(params[5])) || 0;
|
|
54
57
|
const bearing = (params && parseFloat(params[6])) || 0;
|
|
55
|
-
const pitch = (params && parseFloat(params[
|
|
56
|
-
|
|
58
|
+
const pitch = (params && parseFloat(params[7])) || 0;
|
|
59
|
+
const str = params?.[8] && params[8];
|
|
60
|
+
const styleHolder = { style: {} };
|
|
61
|
+
try {
|
|
62
|
+
// get style from URL
|
|
63
|
+
styleHolder.style = str && { ...{ levels: undefined }, ...JSON.parse(decodeURI(str)) }; // reset levels if change units
|
|
64
|
+
} catch (e) {
|
|
65
|
+
/* ignore errors silently */
|
|
66
|
+
console.log(e);
|
|
67
|
+
}
|
|
57
68
|
|
|
58
|
-
map
|
|
59
|
-
map.on('drag', () => setURL(map, time, datasetName, variables));
|
|
60
|
-
map.on('rotate', () => setURL(map, time, datasetName, variables));
|
|
61
|
-
map.on('pitch', () => setURL(map, time, datasetName, variables));
|
|
69
|
+
flyTo(map, zoom, lng, lat, bearing, pitch);
|
|
62
70
|
|
|
63
|
-
const
|
|
71
|
+
const sth = { style: {} };
|
|
72
|
+
map.on('zoom', () => setURL(map, time, datasetName, variable, sth.style));
|
|
73
|
+
map.on('drag', () => setURL(map, time, datasetName, variable, sth.style));
|
|
74
|
+
map.on('rotate', () => setURL(map, time, datasetName, variable, sth.style));
|
|
75
|
+
map.on('pitch', () => setURL(map, time, datasetName, variable, sth.style));
|
|
64
76
|
|
|
65
77
|
let wxsource: WxTileSource | undefined;
|
|
66
78
|
|
|
67
79
|
const legendControl = new WxLegendControl();
|
|
68
80
|
addControl(map, legendControl, 'top-right');
|
|
69
81
|
|
|
70
|
-
const
|
|
82
|
+
const frameworkOptions = { id: 'wxsource', opacity: OPACITY, attribution: 'WxTiles' };
|
|
83
|
+
const apiControl = new WxAPIControl(wxapi, datasetName, variable);
|
|
71
84
|
addControl(map, apiControl, 'top-left');
|
|
72
|
-
|
|
73
|
-
const timeControl = new WxTimeControl(10);
|
|
74
|
-
addControl(map, timeControl, 'top-left');
|
|
75
|
-
timeControl.onchange = (time_) => setURL(map, (time = time_), datasetName, variables);
|
|
76
|
-
|
|
77
|
-
const customStyleEditorControl = new WxStyleEditorControl();
|
|
78
|
-
addControl(map, customStyleEditorControl, 'top-left');
|
|
79
|
-
customStyleEditorControl.onchange = async (style) => {
|
|
80
|
-
if (!wxsource) return;
|
|
81
|
-
await wxsource.updateCurrentStyleObject(style);
|
|
82
|
-
const nstyle = wxsource.getCurrentStyleObjectCopy();
|
|
83
|
-
legendControl.drawLegend(nstyle);
|
|
84
|
-
customStyleEditorControl.setStyle(nstyle);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const infoControl = new WxInfoControl();
|
|
88
|
-
addControl(map, infoControl, 'bottom-left');
|
|
89
|
-
map.on('mousemove', (e) => infoControl.update(wxsource, map, position(e)));
|
|
90
|
-
|
|
91
85
|
apiControl.onchange = async (datasetName_: string, variable: string): Promise<void> => {
|
|
86
|
+
WXLOG('apiControl.onchange datasetName=', datasetName_, 'variable=', variable);
|
|
92
87
|
// remove existing source and layer
|
|
93
88
|
removeLayer(map, frameworkOptions.id, wxsource);
|
|
94
89
|
//
|
|
@@ -96,23 +91,51 @@ async function start() {
|
|
|
96
91
|
datasetName = datasetName_;
|
|
97
92
|
const wxdatasetManager = await wxapi.createDatasetManager(datasetName);
|
|
98
93
|
const meta = wxdatasetManager.getVariableMeta(variable);
|
|
99
|
-
variables = wxdatasetManager.checkCombineVariableIfVector(variable); // check if variable is vector and use vector components if so
|
|
100
94
|
if (meta?.units === 'RGB') {
|
|
101
|
-
addRaster(map, frameworkOptions.id, 'wxtiles', wxdatasetManager.createURI(
|
|
95
|
+
addRaster(map, frameworkOptions.id, 'wxtiles', wxdatasetManager.createURI(variable, 0), wxdatasetManager.getMaxZoom());
|
|
102
96
|
timeControl.setTimes(wxdatasetManager.getTimes());
|
|
103
97
|
legendControl.clear();
|
|
104
98
|
} else {
|
|
105
|
-
wxsource =
|
|
99
|
+
wxsource = wxdatasetManager.createSourceLayer({ variable, time, wxstyle: styleHolder.style }, frameworkOptions);
|
|
106
100
|
await addLayer(map, frameworkOptions.id, 'wxtiles', wxsource);
|
|
107
|
-
|
|
108
|
-
legendControl.drawLegend(
|
|
109
|
-
|
|
101
|
+
const styleCopy = wxsource.getCurrentStyleObjectCopy();
|
|
102
|
+
legendControl.drawLegend(styleCopy); // first draw legend with current style
|
|
103
|
+
styleCopy.levels = undefined; // no need to show defaults it in the editor and URL
|
|
104
|
+
styleCopy.colors = undefined; // no need to show defaults it in the editor and URL
|
|
105
|
+
await customStyleEditorControl.onchange?.(styleCopy, true);
|
|
110
106
|
}
|
|
107
|
+
|
|
108
|
+
timeControl.updateSource(wxsource);
|
|
111
109
|
};
|
|
112
110
|
|
|
113
|
-
|
|
111
|
+
const timeControl = new WxTimeControl(50);
|
|
112
|
+
addControl(map, timeControl, 'top-left');
|
|
113
|
+
timeControl.onchange = (time_) => {
|
|
114
|
+
setURL(map, (time = time_), datasetName, variable, sth.style);
|
|
115
|
+
};
|
|
114
116
|
|
|
115
|
-
|
|
117
|
+
const customStyleEditorControl = new WxStyleEditorControl();
|
|
118
|
+
addControl(map, customStyleEditorControl, 'top-right');
|
|
119
|
+
customStyleEditorControl.onchange = async (style, nonnativecall) => {
|
|
120
|
+
WXLOG('customStyleEditorControl.onchange');
|
|
121
|
+
if (!wxsource) return;
|
|
122
|
+
!nonnativecall && (await wxsource.updateCurrentStyleObject(style)); // if called manually, do not update wxsource's style
|
|
123
|
+
const nstyle = wxsource.getCurrentStyleObjectCopy();
|
|
124
|
+
legendControl.drawLegend(nstyle);
|
|
125
|
+
nstyle.levels = style?.levels; // keep levels empty if they are not defined
|
|
126
|
+
nstyle.colors = style?.colors; // keep colors empty if they are not defined
|
|
127
|
+
customStyleEditorControl.setStyle(nstyle); // if called from wxsource, update customStyleEditorControl
|
|
128
|
+
sth.style = nstyle;
|
|
129
|
+
setURL(map, time, datasetName, variable, sth.style);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const infoControl = new WxInfoControl();
|
|
133
|
+
addControl(map, infoControl, 'bottom-left');
|
|
134
|
+
// map.on('mousemove', (e) => infoControl.update(wxsource, map, position(e)));
|
|
135
|
+
|
|
136
|
+
await apiControl.onchange(datasetName, variable); // initial load
|
|
137
|
+
|
|
138
|
+
/*/ DEMO: more interactive - additional level and a bit of the red transparentness around the level made from current mouse position
|
|
116
139
|
if (wxsource) {
|
|
117
140
|
let busy = false;
|
|
118
141
|
await wxsource.updateCurrentStyleObject({ levels: undefined }); // await always !!
|
|
@@ -196,26 +219,29 @@ async function start() {
|
|
|
196
219
|
//*/
|
|
197
220
|
|
|
198
221
|
/*/ DEMO: Dynamic blur effect /
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
b += db;
|
|
206
|
-
if (b > 16 || b < 0) db = -db;
|
|
207
|
-
setTimeout(nextAnim, 1);
|
|
208
|
-
};
|
|
209
|
-
setTimeout(nextAnim, 2000); //*/
|
|
222
|
+
wxsource &&
|
|
223
|
+
(async function step(n: number = 0) {
|
|
224
|
+
await wxsource.updateCurrentStyleObject({ isolineText: false, blurRadius: ~~(10 * Math.sin(n / 500) + 10) }); // await always !!
|
|
225
|
+
requestAnimationFrame(step);
|
|
226
|
+
})();
|
|
227
|
+
//*/
|
|
210
228
|
}
|
|
211
229
|
|
|
212
230
|
function flyTo(map: L.Map, zoom: number, lng: number, lat: number, bearing: number, pitch: number) {
|
|
213
231
|
map.flyTo([lat, lng], zoom);
|
|
214
232
|
}
|
|
215
233
|
|
|
216
|
-
function setURL(map: L.Map, time: string, datasetName: string,
|
|
217
|
-
const
|
|
218
|
-
|
|
234
|
+
function setURL(map: L.Map, time: string, datasetName: string, variable: string, style: any) {
|
|
235
|
+
const base = WxGetColorStyles()['base'];
|
|
236
|
+
for (const i in style) style[i] === base[i] && delete style[i]; // remove default values
|
|
237
|
+
|
|
238
|
+
const center = map.getCenter().wrap();
|
|
239
|
+
const href =
|
|
240
|
+
`##${datasetName}/${variable}/${time}/${map.getZoom().toFixed(2)}/${center.lng.toFixed(2)}/${center.lat.toFixed(2)}/0/0` +
|
|
241
|
+
(style ? '/' + JSON.stringify(style) : '');
|
|
242
|
+
|
|
243
|
+
history.replaceState(null, '', href);
|
|
244
|
+
// location.href = `#${datasetName}/${variables.join(',')}/${time}/${map.getZoom().toFixed(2)}/${center.lng.toFixed(2)}/${center.lat.toFixed(2)}`;
|
|
219
245
|
}
|
|
220
246
|
|
|
221
247
|
async function initFrameWork() {
|
|
@@ -282,7 +308,7 @@ async function simpleDemo() {
|
|
|
282
308
|
const variables = wxdatasetManager.checkCombineVariableIfVector(variable);
|
|
283
309
|
|
|
284
310
|
// create a layer
|
|
285
|
-
const leafletOptions: FrameworkOptions = { opacity: 1, attribution: 'WxTiles' };
|
|
311
|
+
const leafletOptions: FrameworkOptions = { id: 'wxsource', opacity: 1, attribution: 'WxTiles' };
|
|
286
312
|
const wxsource = new WxTileSource({ wxdatasetManager, variables }, leafletOptions);
|
|
287
313
|
|
|
288
314
|
// add the layer to the map
|
|
@@ -291,3 +317,34 @@ async function simpleDemo() {
|
|
|
291
317
|
// await for the first load
|
|
292
318
|
await new Promise((done) => wxsource.once('load', done)); // highly recommended to await for the first load
|
|
293
319
|
}
|
|
320
|
+
|
|
321
|
+
async function twoLayersDemo() {
|
|
322
|
+
const dataServerURL = 'https://tiles.metoceanapi.com/data/';
|
|
323
|
+
const requestInit: RequestInit = {
|
|
324
|
+
// headers: new Headers([['x-api-key', '--proper-key-value--']]),
|
|
325
|
+
}; // add more options if needed such as headers, mode, credentials, etc
|
|
326
|
+
|
|
327
|
+
// Get the API ready - should be ONE per application
|
|
328
|
+
WxTilesLogging(true); // If needed
|
|
329
|
+
const wxapi = new WxAPI({ dataServerURL, maskURL: 'none', qtreeURL: 'none', requestInit });
|
|
330
|
+
|
|
331
|
+
// Create a dataset manager (may be used for many layers from this dataset)
|
|
332
|
+
const wxdatasetManager = await wxapi.createDatasetManager('gfs.global');
|
|
333
|
+
|
|
334
|
+
// create a layer
|
|
335
|
+
const leafletOptions = { id: 'wxsource', attribution: 'WxTiles' };
|
|
336
|
+
const wxsource = wxdatasetManager.createSourceLayer({ variable: 'air.temperature.at-2m' }, leafletOptions);
|
|
337
|
+
|
|
338
|
+
// create a layer
|
|
339
|
+
const leafletOptions1 = { id: 'wxsource1', opacity: 0.5 };
|
|
340
|
+
const wxsource1 = wxdatasetManager.createSourceLayer({ variable: 'air.visibility' }, leafletOptions1);
|
|
341
|
+
|
|
342
|
+
// MAP
|
|
343
|
+
const map = L.map('map', { center: [0, 0], zoom: 2, zoomControl: true });
|
|
344
|
+
// add leaflet layerGroup to map
|
|
345
|
+
const group = L.layerGroup([wxsource, wxsource1]).addTo(map);
|
|
346
|
+
// create control
|
|
347
|
+
const control = L.control.layers(undefined, { wxsource, wxsource1 }).addTo(map);
|
|
348
|
+
// add the group to the control layer
|
|
349
|
+
control.addOverlay(group, 'wxsources group');
|
|
350
|
+
}
|