@metoceanapi/wxtiles-leaflet 2.1.0 → 2.1.3
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 +4 -0
- package/dist/es/controls/WxAPIControl.d.ts +1 -1
- package/dist/es/controls/WxInfoControl.d.ts +2 -1
- package/dist/es/controls/WxStyleEditorControl.d.ts +5 -0
- package/dist/es/customlayer/customlayer.d.ts +2 -0
- package/dist/es/index.d.ts +1 -0
- package/dist/es/index.js +2 -2
- package/dist/es/utils/tests_wxtools.d.ts +1 -0
- package/dist/es/utils/wxtools.d.ts +22 -2
- package/dist/es/wxAPI/WxDataSetManager.d.ts +35 -18
- package/dist/es/wxAPI/wxAPI.d.ts +1 -1
- package/dist/es/wxlayer/WxImplementation.d.ts +17 -11
- package/dist/es/wxlayer/painter.d.ts +5 -0
- package/dist/es/wxlayer/wxlayer.d.ts +32 -14
- package/dist/es/wxsource/wxsource.d.ts +5 -0
- package/dist/web/index.js +2 -2
- package/docs/docs/assets/main.js +56 -52
- package/docs/docs/assets/search.js +1 -1
- package/docs/docs/assets/style.css +27 -5
- package/docs/docs/classes/CustomWxTilesLayer.html +68 -0
- package/docs/docs/classes/DataIntegral.html +13 -13
- package/docs/docs/classes/FrameworkParentClass.html +3 -3
- package/docs/docs/classes/Loader.html +1 -1
- package/docs/docs/classes/Painter.html +6 -6
- package/docs/docs/classes/WxAPI.html +5 -5
- package/docs/docs/classes/WxDataSetManager.html +119 -71
- package/docs/docs/classes/WxLayer.html +78 -40
- package/docs/docs/classes/WxLayerBaseImplementation.html +66 -19
- package/docs/docs/classes/WxTileSource.html +74 -22
- package/docs/docs/functions/WXLOG.html +3 -2
- package/docs/docs/functions/WxCreateLegend.html +2 -1
- package/docs/docs/functions/WxGetColorSchemes.html +3 -2
- package/docs/docs/functions/WxGetColorStyles.html +3 -2
- package/docs/docs/functions/WxTilesLogging.html +3 -2
- package/docs/docs/index.html +2 -1
- package/docs/docs/interfaces/ColorStylesIncomplete.html +2 -1
- package/docs/docs/interfaces/Converter.html +2 -2
- package/docs/docs/interfaces/DataPicture.html +5 -5
- package/docs/docs/interfaces/FrameworkOptions.html +2 -2
- package/docs/docs/interfaces/IntegralPare.html +3 -3
- package/docs/docs/interfaces/WxAPIOptions.html +3 -3
- package/docs/docs/interfaces/WxColorSchemes.html +2 -1
- package/docs/docs/interfaces/WxColorStyleStrict.html +22 -0
- package/docs/docs/interfaces/WxColorStyleWeak.html +23 -0
- package/docs/docs/interfaces/WxColorStylesStrict.html +2 -2
- package/docs/docs/interfaces/WxColorStylesWeakMixed.html +2 -1
- package/docs/docs/interfaces/WxDataSetManagerOptions.html +29 -29
- package/docs/docs/interfaces/WxDatasetMeta.html +4 -4
- package/docs/docs/interfaces/WxLayerAPI.html +29 -29
- package/docs/docs/interfaces/WxLayerBaseAPI.html +20 -20
- package/docs/docs/interfaces/WxLayerOptions.html +6 -15
- package/docs/docs/interfaces/WxRasterData.html +18 -2
- package/docs/docs/interfaces/WxSourceLayerOptions.html +6 -16
- package/docs/docs/interfaces/WxTilesLibOptions.html +4 -4
- package/docs/docs/interfaces/WxUnits.html +2 -1
- package/docs/docs/interfaces/WxVariablesMetas.html +2 -1
- package/docs/docs/modules.html +3 -1
- package/docs/docs/types/DataIntegrals.html +3 -2
- package/docs/docs/types/DataPictures.html +3 -2
- 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 +3 -2
- 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/examples/seaMaskAndAnimatedBlur.html +2 -2
- package/docs/examples/simpleDemo.html +2 -2
- package/docs/script/script.js +4 -4
- package/package.json +6 -7
- package/src_example/frwrkdeps.ts +1 -2
- package/src_example/start.ts +28 -24
- package/watch-public.mjs +99 -0
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metoceanapi/wxtiles-leaflet",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
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",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build_DEMO_Docs": "npm run build && npm run buildDOCS && node build-for-docs.js",
|
|
9
|
-
"start": "PORT=3002 node watch-public.
|
|
9
|
+
"start": "PORT=3002 node watch-public.mjs",
|
|
10
10
|
"build": "rm -rf dist/ && node build.js && tsc",
|
|
11
11
|
"buildDOCS": "./node_modules/.bin/typedoc --out docs/docs --excludeExternals -gitRevision main src",
|
|
12
12
|
"preversion": "npm run build",
|
|
@@ -25,13 +25,12 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/metoceanapi/wxtiles-leaflet#readme",
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/leaflet": "^1.9.
|
|
28
|
+
"@types/leaflet": "^1.9.3",
|
|
29
29
|
"changelogkeeper": "^1.2.0",
|
|
30
|
-
"esbuild": "^0.
|
|
30
|
+
"esbuild": "^0.17.18",
|
|
31
31
|
"esbuild-plugin-external-global": "^1.0.1",
|
|
32
|
-
"express": "^4.18.2",
|
|
33
32
|
"leaflet": "^1.9.3",
|
|
34
|
-
"typedoc": "^0.23.
|
|
35
|
-
"typescript": "^4.9.
|
|
33
|
+
"typedoc": "^0.23.28",
|
|
34
|
+
"typescript": "^4.9.5"
|
|
36
35
|
}
|
|
37
36
|
}
|
package/src_example/frwrkdeps.ts
CHANGED
|
@@ -57,10 +57,9 @@ export function removeLayer(map: L.Map, layerId: string, layer?: L.Layer) {
|
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export async function addLayer(map: L.Map,
|
|
60
|
+
export async function addLayer(map: L.Map, idL: string, layer: L.Layer) {
|
|
61
61
|
map.addLayer(layer);
|
|
62
62
|
await new Promise((done) => layer.once('load', done)); // highly recommended to await for the first load
|
|
63
|
-
console.log('layer loaded', idS, idL);
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
export function addRaster(map: L.Map, idS: string, idL: string, URL: string, maxZoom: number) {
|
package/src_example/start.ts
CHANGED
|
@@ -7,17 +7,18 @@ import { WxAPIControl } from '../src/controls/WxAPIControl';
|
|
|
7
7
|
import { initFrameWork, addRaster, flyTo, setURL, addControl, removeLayer, addLayer, position } from './frwrkdeps';
|
|
8
8
|
|
|
9
9
|
export const OPACITY = 0.8;
|
|
10
|
-
|
|
10
|
+
// new EventSource('/esbuild').addEventListener('change', () => location.reload());
|
|
11
11
|
// this is universal function for Leaflet and Mapbox.
|
|
12
12
|
// Functions below are just framework specific wrappers for this universal function
|
|
13
13
|
// start() is the fully interchangable function for Leaflet and Mapbox
|
|
14
14
|
export async function start() {
|
|
15
15
|
const map = await initFrameWork();
|
|
16
16
|
addRaster(map, 'baseS', 'baseL', 'https://tiles.metoceanapi.com/base-lines/{z}/{x}/{y}', 5);
|
|
17
|
-
WxTilesLogging(
|
|
18
|
-
|
|
19
|
-
// const dataServerURL = 'https://68.171.214.87/data/'
|
|
20
|
-
const dataServerURL = 'https://
|
|
17
|
+
// WxTilesLogging(console.trace);
|
|
18
|
+
const dataServerURL = 'data/'; // different sources manged in 'start' script in package.json
|
|
19
|
+
// const dataServerURL = 'https://68.171.214.87/data/'; // hihi1
|
|
20
|
+
// const dataServerURL = 'https://68.171.214.81/data/'; // hihi2
|
|
21
|
+
// const dataServerURL = 'https://tiles.metoceanapi.com/data/';
|
|
21
22
|
// const dataServerURL = 'http://tiles3.metoceanapi.com/';
|
|
22
23
|
const myHeaders = new Headers();
|
|
23
24
|
// myHeaders.append('x-api-key', 'SpV3J1RypVrv2qkcJE91gG');
|
|
@@ -30,8 +31,10 @@ export async function start() {
|
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
let datasetName = 'gfs.global'; /* 'mercator.global/'; */ /* 'ecwmf.global/'; */ /* 'obs-radar.rain.nzl.national/'; */
|
|
34
|
+
// let variable = 'cloud.cover';
|
|
33
35
|
let variable = 'air.temperature.at-2m';
|
|
34
|
-
// let
|
|
36
|
+
// let variable = 'wind.speed.eastward.at-10m';
|
|
37
|
+
// let variable = 'wave.direction.peak';
|
|
35
38
|
|
|
36
39
|
// let datasetName = 'ww3-ecmwf.global';
|
|
37
40
|
// let variable = 'wave.direction.mean';
|
|
@@ -59,18 +62,17 @@ export async function start() {
|
|
|
59
62
|
sth.style = str && { ...JSON.parse(decodeURI(str)) }; // reset levels if change units
|
|
60
63
|
} catch (e) {
|
|
61
64
|
/* ignore errors silently */
|
|
62
|
-
console.log(
|
|
65
|
+
console.log("Can't parse style from URL");
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
params && flyTo(map, zoom, lng, lat, bearing, pitch); // if no params stay at default position set in initFrameWork()
|
|
66
69
|
|
|
67
|
-
// const sth = { style: {} };
|
|
68
70
|
map.on('zoom', () => setURL(map, time, datasetName, variable, sth.style));
|
|
69
71
|
map.on('drag', () => setURL(map, time, datasetName, variable, sth.style));
|
|
70
72
|
map.on('rotate', () => setURL(map, time, datasetName, variable, sth.style));
|
|
71
73
|
map.on('pitch', () => setURL(map, time, datasetName, variable, sth.style));
|
|
72
74
|
|
|
73
|
-
let
|
|
75
|
+
let wxsourceLayer: WxTileSource | undefined;
|
|
74
76
|
|
|
75
77
|
const legendControl = new WxLegendControl();
|
|
76
78
|
addControl(map, legendControl, 'top-right');
|
|
@@ -78,53 +80,55 @@ export async function start() {
|
|
|
78
80
|
const frameworkOptions = { id: 'wxsource', opacity: OPACITY, attribution: 'WxTiles' };
|
|
79
81
|
const apiControl = new WxAPIControl(wxapi, datasetName, variable);
|
|
80
82
|
addControl(map, apiControl, 'top-left');
|
|
81
|
-
apiControl.onchange = async (datasetName_, variable_,
|
|
83
|
+
apiControl.onchange = async (datasetName_, variable_, resetStyleAndFlyTo = true): Promise<void> => {
|
|
82
84
|
WXLOG('apiControl.onchange datasetName=', datasetName_, 'variable=', variable_);
|
|
83
85
|
// remove existing source and layer
|
|
84
|
-
removeLayer(map, frameworkOptions.id,
|
|
86
|
+
removeLayer(map, frameworkOptions.id, wxsourceLayer);
|
|
85
87
|
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
resetStyleAndFlyTo && (sth.style = {}); // reset style if change dataset/variable
|
|
89
|
+
wxsourceLayer = undefined;
|
|
88
90
|
datasetName = datasetName_;
|
|
89
91
|
variable = variable_;
|
|
90
92
|
const wxdatasetManager = await wxapi.createDatasetManager(datasetName);
|
|
91
93
|
const boundaries = wxdatasetManager.getBoundaries();
|
|
92
|
-
if (boundaries &&
|
|
94
|
+
if (boundaries && resetStyleAndFlyTo) {
|
|
93
95
|
const { east, west, north, south } = boundaries.boundariesnorm;
|
|
94
96
|
const zoom = Math.round(Math.log((360 * 360) / Math.max((east - west + 360) % 360, north - south) / 360) / Math.LN2); // from https://stackoverflow.com/questions/6048975/google-maps-v3-how-to-calculate-the-zoom-level-for-a-given-bounds
|
|
95
97
|
flyTo(map, zoom, (east + west) / 2, (north + south) / 2, 0, 0);
|
|
96
98
|
}
|
|
97
99
|
const meta = wxdatasetManager.getVariableMeta(variable);
|
|
98
100
|
if (meta?.units === 'RGB') {
|
|
99
|
-
addRaster(map, frameworkOptions.id, 'wxtiles', wxdatasetManager.createURI(variable, 0), wxdatasetManager.getMaxZoom());
|
|
101
|
+
addRaster(map, frameworkOptions.id, 'wxtiles', wxdatasetManager.createURI(variable, wxdatasetManager.getTimes()[0]), wxdatasetManager.getMaxZoom());
|
|
100
102
|
timeControl.setTimes(wxdatasetManager.getTimes());
|
|
101
103
|
legendControl.clear();
|
|
102
104
|
} else {
|
|
103
|
-
|
|
104
|
-
await addLayer(map,
|
|
105
|
-
|
|
105
|
+
wxsourceLayer = wxdatasetManager.createSourceLayer({ variable, time, wxstyle: sth.style }, frameworkOptions);
|
|
106
|
+
await addLayer(map, 'wxtiles', wxsourceLayer);
|
|
107
|
+
// wxsource.startAnimation();
|
|
108
|
+
const styleCopy = wxsourceLayer.getCurrentStyleObjectCopy();
|
|
106
109
|
legendControl.drawLegend(styleCopy); // first draw legend with current style
|
|
107
110
|
styleCopy.levels = sth.style?.levels; // no need to show defaults it in the editor and URL
|
|
108
111
|
styleCopy.colors = sth.style?.colors; // no need to show defaults it in the editor and URL
|
|
109
112
|
await customStyleEditorControl.onchange?.(styleCopy, true);
|
|
110
113
|
}
|
|
111
114
|
|
|
112
|
-
timeControl.updateSource(
|
|
115
|
+
timeControl.updateSource(wxsourceLayer);
|
|
113
116
|
};
|
|
114
117
|
|
|
115
118
|
const timeControl = new WxTimeControl(50);
|
|
116
119
|
addControl(map, timeControl, 'top-left');
|
|
117
120
|
timeControl.onchange = (time_) => {
|
|
118
121
|
setURL(map, (time = time_), datasetName, variable, sth.style);
|
|
122
|
+
infoControl.update(wxsourceLayer, map);
|
|
119
123
|
};
|
|
120
124
|
|
|
121
125
|
const customStyleEditorControl = new WxStyleEditorControl();
|
|
122
126
|
addControl(map, customStyleEditorControl, 'top-right');
|
|
123
127
|
customStyleEditorControl.onchange = async (style, nonnativecall) => {
|
|
124
128
|
WXLOG('customStyleEditorControl.onchange');
|
|
125
|
-
if (!
|
|
126
|
-
nonnativecall || (await
|
|
127
|
-
const nstyle =
|
|
129
|
+
if (!wxsourceLayer) return;
|
|
130
|
+
nonnativecall || (await wxsourceLayer.updateCurrentStyleObject(style)); // if called manually, do not update wxsource's style
|
|
131
|
+
const nstyle = wxsourceLayer.getCurrentStyleObjectCopy();
|
|
128
132
|
legendControl.drawLegend(nstyle);
|
|
129
133
|
nstyle.levels = style?.levels; // keep levels empty if they are not defined
|
|
130
134
|
nstyle.colors = style?.colors; // keep colors empty if they are not defined
|
|
@@ -135,9 +139,9 @@ export async function start() {
|
|
|
135
139
|
|
|
136
140
|
const infoControl = new WxInfoControl();
|
|
137
141
|
addControl(map, infoControl, 'bottom-left');
|
|
138
|
-
map.on('mousemove', (e) => infoControl.update(
|
|
142
|
+
map.on('mousemove', (e) => infoControl.update(wxsourceLayer, map, position(e)));
|
|
139
143
|
|
|
140
|
-
await apiControl.onchange(datasetName, variable,
|
|
144
|
+
await apiControl.onchange(datasetName, variable, false); // initial load
|
|
141
145
|
|
|
142
146
|
/*/ DEMO: more interactive - additional level and a bit of the red transparentness around the level made from current mouse position
|
|
143
147
|
if (wxsource) {
|
package/watch-public.mjs
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// import { type BuildOptions, context } from 'esbuild';
|
|
2
|
+
import * as esbuild from 'esbuild';
|
|
3
|
+
import http from 'node:http';
|
|
4
|
+
|
|
5
|
+
const PORT = +process.env.PORT || 3000;
|
|
6
|
+
|
|
7
|
+
const buildOptions = {
|
|
8
|
+
entryPoints: ['src_example/index.ts'],
|
|
9
|
+
bundle: true,
|
|
10
|
+
loader: {
|
|
11
|
+
'.png': 'base64',
|
|
12
|
+
'.woff': 'base64',
|
|
13
|
+
},
|
|
14
|
+
format: 'iife',
|
|
15
|
+
outfile: 'public/script/script.js',
|
|
16
|
+
sourcemap: true,
|
|
17
|
+
minify: false,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
let ctx = await esbuild.context(buildOptions);
|
|
21
|
+
await ctx.watch();
|
|
22
|
+
console.log('watching...');
|
|
23
|
+
|
|
24
|
+
const { host, port } = await ctx.serve({ host: 'localhost', port: PORT + 1000, servedir: 'public' });
|
|
25
|
+
console.log(`Dev is running at ${host}:${PORT}`);
|
|
26
|
+
|
|
27
|
+
// Then start a proxy server on PORT
|
|
28
|
+
// https://esbuild.github.io/api/#serve-proxy
|
|
29
|
+
http
|
|
30
|
+
.createServer((req, res) => {
|
|
31
|
+
const options = {
|
|
32
|
+
hostname: host,
|
|
33
|
+
port: port,
|
|
34
|
+
path: req.url,
|
|
35
|
+
method: req.method,
|
|
36
|
+
headers: req.headers,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
if (req.url.startsWith('/data/masks')) {
|
|
40
|
+
options.port = 9191; // all from local 'simple NGINX'
|
|
41
|
+
} else if (req.url.startsWith('/data')) {
|
|
42
|
+
// options.port = undefined;
|
|
43
|
+
// options.hostname = 'hihi2.metoceanapi.com';
|
|
44
|
+
// options.path = 'https://' + options.hostname + req.url;
|
|
45
|
+
|
|
46
|
+
// options.port = 9191; // local 'simple NGINX'
|
|
47
|
+
|
|
48
|
+
options.port = 5050; // wxtiles-http-server
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Forward each incoming request to esbuild
|
|
52
|
+
const proxyReq = http.request(options, (proxyRes) => {
|
|
53
|
+
res.writeHead(proxyRes.statusCode, proxyRes.headers);
|
|
54
|
+
proxyRes.pipe(res, { end: true });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Forward the body of the request to esbuild
|
|
58
|
+
req.pipe(proxyReq, { end: true });
|
|
59
|
+
})
|
|
60
|
+
.listen(PORT);
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
// OLD CODE using express. Works with esbuild 0.15, but not with 0.17
|
|
64
|
+
esbuild
|
|
65
|
+
.build({
|
|
66
|
+
entryPoints: ['src_example/index.ts'],
|
|
67
|
+
bundle: true,
|
|
68
|
+
plugins: [],
|
|
69
|
+
loader: {
|
|
70
|
+
'.png': 'base64',
|
|
71
|
+
'.woff': 'base64',
|
|
72
|
+
},
|
|
73
|
+
target: 'es2020',
|
|
74
|
+
format: 'iife',
|
|
75
|
+
outfile: 'public/script/script.js',
|
|
76
|
+
sourcemap: true,
|
|
77
|
+
minify: false,
|
|
78
|
+
watch: {
|
|
79
|
+
onRebuild(error, result) {
|
|
80
|
+
if (error) {
|
|
81
|
+
console.error('watch build failed:', error);
|
|
82
|
+
} else {
|
|
83
|
+
console.log('rebuilded', new Date());
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
.then((result) => {
|
|
89
|
+
const app = express();
|
|
90
|
+
app.use(express.static('public'));
|
|
91
|
+
|
|
92
|
+
const url = `http://localhost:${PORT}`;
|
|
93
|
+
app.listen(PORT, () => {
|
|
94
|
+
console.log(`Dev is running at ${url}`);
|
|
95
|
+
});
|
|
96
|
+
})
|
|
97
|
+
.catch((e) => console.error(e.message));
|
|
98
|
+
|
|
99
|
+
*/
|