@metoceanapi/wxtiles-leaflet 2.4.0-1 → 2.4.1-2
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 +214 -92
- package/dist/es/index.d.ts +12 -16
- package/dist/es/index.js +4 -4
- package/dist/es/wxAPI/WxAPI.d.ts +17 -0
- package/dist/es/wxAPI/WxDataSetManager.d.ts +14 -4
- package/dist/es/wxsource/wxsource.d.ts +23 -19
- package/dist/es/wxsource/wxsourcetypes.d.ts +22 -10
- package/dist/web/index.js +4 -4
- package/docs/docs/assets/highlight.css +12 -19
- package/docs/docs/assets/search.js +1 -1
- package/docs/docs/classes/WxAPI.html +31 -18
- package/docs/docs/classes/WxAPIControl.html +70 -24
- package/docs/docs/classes/WxDataSetManager.html +22 -21
- package/docs/docs/classes/WxInfoControl.html +37 -10
- package/docs/docs/classes/WxLegendControl.html +33 -11
- package/docs/docs/classes/WxStyleEditorControl.html +206 -94
- package/docs/docs/classes/WxTileSource.html +40 -40
- package/docs/docs/classes/WxTimeControl.html +58 -20
- package/docs/docs/index.html +188 -101
- package/docs/docs/interfaces/FrameworkOptions.html +3 -3
- package/docs/docs/interfaces/WxSourceLayerOptions.html +5 -5
- package/docs/docs/modules.html +12 -130
- package/docs/docs/types/Loader.html +3 -59
- package/docs/docs/types/Painter.html +3 -59
- package/docs/docs/types/WxLayer.html +3 -59
- package/docs/docs/variables/WxLayerBaseImplementation.html +3 -59
- package/docs/script/script.css +1 -1
- package/docs/script/script.js +6 -6
- package/package.json +3 -3
- package/src_example/frwrkdeps.ts +131 -80
- package/src_example/index.ts +2 -53
- package/src_example/start.ts +143 -300
- package/dep.dot +0 -33
- package/dep.svg +0 -233
- package/docs/docs/classes/DataIntegral.html +0 -154
- package/docs/docs/classes/QTree.html +0 -185
- package/docs/docs/classes/RawCLUT.html +0 -143
- package/docs/docs/classes/TilesCache.html +0 -108
- package/docs/docs/enums/TileType.html +0 -80
- package/docs/docs/functions/WXLOG.html +0 -127
- package/docs/docs/functions/WxCreateLegend.html +0 -135
- package/docs/docs/functions/WxGetColorSchemes.html +0 -122
- package/docs/docs/functions/WxGetColorStyles.html +0 -122
- package/docs/docs/functions/WxTilesLogging.html +0 -130
- package/docs/docs/interfaces/CachedUriLoaderPromiseFunc.html +0 -108
- package/docs/docs/interfaces/ColorStylesIncomplete.html +0 -125
- package/docs/docs/interfaces/Converter.html +0 -81
- package/docs/docs/interfaces/DataPicture.html +0 -95
- package/docs/docs/interfaces/IntegralPare.html +0 -81
- package/docs/docs/interfaces/SLinePoint.html +0 -77
- package/docs/docs/interfaces/Tree.html +0 -74
- package/docs/docs/interfaces/WxAPIOptions.html +0 -173
- package/docs/docs/interfaces/WxAllBoundariesMeta.html +0 -90
- package/docs/docs/interfaces/WxAllDatasetsShortMetas.html +0 -125
- package/docs/docs/interfaces/WxBoundaryMeta.html +0 -99
- package/docs/docs/interfaces/WxColorSchemes.html +0 -126
- package/docs/docs/interfaces/WxColorStyleStrict.html +0 -359
- package/docs/docs/interfaces/WxColorStyleWeak.html +0 -388
- package/docs/docs/interfaces/WxColorStylesStrict.html +0 -74
- package/docs/docs/interfaces/WxColorStylesWeakMixed.html +0 -125
- package/docs/docs/interfaces/WxData.html +0 -85
- package/docs/docs/interfaces/WxDataSetManagerOptions.html +0 -117
- package/docs/docs/interfaces/WxDatasetMeta.html +0 -144
- package/docs/docs/interfaces/WxDatasetShortMeta.html +0 -91
- package/docs/docs/interfaces/WxLayerAPI.html +0 -375
- package/docs/docs/interfaces/WxLayerBaseAPI.html +0 -242
- package/docs/docs/interfaces/WxLayerOptions.html +0 -113
- package/docs/docs/interfaces/WxLegend.html +0 -118
- package/docs/docs/interfaces/WxLngLat.html +0 -81
- package/docs/docs/interfaces/WxRasterData.html +0 -118
- package/docs/docs/interfaces/WxRequestInit.html +0 -70
- package/docs/docs/interfaces/WxTick.html +0 -100
- package/docs/docs/interfaces/WxTileInfo.html +0 -142
- package/docs/docs/interfaces/WxUnits.html +0 -125
- package/docs/docs/interfaces/WxVariableMeta.html +0 -109
- package/docs/docs/interfaces/WxVariablesMetas.html +0 -125
- package/docs/docs/interfaces/XYZ.html +0 -84
- package/docs/docs/types/DataIntegrals.html +0 -118
- package/docs/docs/types/DataPictures.html +0 -118
- package/docs/docs/types/ListenerMethod.html +0 -134
- package/docs/docs/types/SLine.html +0 -118
- package/docs/docs/types/SubTrees.html +0 -118
- package/docs/docs/types/SubTreesN.html +0 -118
- package/docs/docs/types/TreeN.html +0 -118
- package/docs/docs/types/WxDate.html +0 -125
- package/docs/docs/types/WxEventType.html +0 -121
- package/docs/docs/types/WxInstances.html +0 -118
- package/docs/docs/types/WxLayerVarsNames.html +0 -118
- package/docs/docs/types/WxURIs.html +0 -118
- package/docs/docs/types/WxUnitTuple.html +0 -118
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metoceanapi/wxtiles-leaflet",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.1-2",
|
|
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.mjs",
|
|
10
10
|
"build": "rm -rf dist/ && node build.js && tsc",
|
|
11
|
-
"buildDOCS": "./node_modules/.bin/typedoc --out docs/docs
|
|
11
|
+
"buildDOCS": "./node_modules/.bin/typedoc --excludeExternals --out docs/docs -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",
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
"typescript": "^4.9.5"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@metoceanapi/wxtiles-common": "^0.0.
|
|
41
|
+
"@metoceanapi/wxtiles-common": "^0.0.11"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src_example/frwrkdeps.ts
CHANGED
|
@@ -1,110 +1,161 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { WxGetColorStyles } from '@metoceanapi/wxtiles-common/utils/wxtools';
|
|
2
|
+
import L from 'leaflet';
|
|
3
3
|
|
|
4
|
-
export function flyTo(
|
|
5
|
-
|
|
6
|
-
zoom: number,
|
|
7
|
-
lng: number,
|
|
8
|
-
lat: number,
|
|
9
|
-
bearing: number,
|
|
10
|
-
pitch: number,
|
|
11
|
-
) {
|
|
12
|
-
map.flyTo([lat, lng], zoom);
|
|
4
|
+
export function flyTo(map: L.Map, zoom: number, lng: number, lat: number, bearing: number, pitch: number) {
|
|
5
|
+
map.flyTo([lat, lng], zoom);
|
|
13
6
|
}
|
|
14
7
|
|
|
15
8
|
export function setURL(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
map: L.Map,
|
|
10
|
+
time: string,
|
|
11
|
+
datasetName: string,
|
|
12
|
+
variable: string,
|
|
13
|
+
// biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
|
|
14
|
+
style: any,
|
|
22
15
|
) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const href =
|
|
36
|
-
`##${datasetName}/${variable}/${time}/${map.getZoom().toFixed(2)}/${center.lng.toFixed(2)}/${center.lat.toFixed(2)}/0/0${newStyle ? `/${JSON.stringify(newStyle)}` : ""}`;
|
|
16
|
+
let newStyle = style;
|
|
17
|
+
const { base } = WxGetColorStyles();
|
|
18
|
+
for (const i in style) style[i] === base[i] && delete style[i]; // remove default values
|
|
19
|
+
if (style.gl) {
|
|
20
|
+
for (const i in style.gl) style.gl[i] === base.gl?.[i] && delete style.gl[i]; // remove default values from gl
|
|
21
|
+
if (Object.keys(style.gl).length === 0) {
|
|
22
|
+
const { gl, ...rest } = style; // Destructure to exclude gl
|
|
23
|
+
newStyle = rest; // Assign the new object back to style
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const center = map.getCenter().wrap();
|
|
27
|
+
const href = `##${datasetName}/${variable}/${time}/${map.getZoom().toFixed(2)}/${center.lng.toFixed(2)}/${center.lat.toFixed(2)}/0/0${newStyle ? `/${JSON.stringify(newStyle)}` : ''}`;
|
|
37
28
|
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
history.replaceState(null, '', href);
|
|
30
|
+
// location.href = `#${datasetName}/${variables.join(',')}/${time}/${map.getZoom().toFixed(2)}/${center.lng.toFixed(2)}/${center.lat.toFixed(2)}`;
|
|
40
31
|
}
|
|
41
32
|
|
|
42
33
|
export async function initFrameWork() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
const map = L.map('map', {
|
|
35
|
+
center: [-40.75, 174.5],
|
|
36
|
+
zoom: 7,
|
|
37
|
+
zoomControl: false,
|
|
38
|
+
});
|
|
48
39
|
|
|
49
|
-
|
|
40
|
+
L.control.zoom({ position: 'bottomright' }).addTo(map);
|
|
50
41
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
// class WxDebugLayer extends L.GridLayer {
|
|
43
|
+
// createTile(coords: { x: number; y: number; z: number }) {
|
|
44
|
+
// const tile = document.createElement('div');
|
|
45
|
+
// tile.innerHTML = [coords.x, coords.y, coords.z].join(', ');
|
|
46
|
+
// tile.style.outline = '1px solid red';
|
|
47
|
+
// return tile;
|
|
48
|
+
// }
|
|
49
|
+
// }
|
|
50
|
+
// map.addLayer(new WxDebugLayer().setZIndex(1000));
|
|
60
51
|
|
|
61
|
-
|
|
52
|
+
return map;
|
|
62
53
|
}
|
|
63
54
|
|
|
64
55
|
export function addControl(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
map: L.Map,
|
|
57
|
+
// biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
|
|
58
|
+
control: { extender: () => any },
|
|
59
|
+
position: string,
|
|
69
60
|
) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
61
|
+
const newPosition = position.replace('-', '');
|
|
62
|
+
map.addControl(
|
|
63
|
+
// biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
|
|
64
|
+
new (L.Control.extend(control.extender()))({ position: newPosition as any }),
|
|
65
|
+
);
|
|
75
66
|
}
|
|
76
67
|
|
|
77
68
|
export function position(e: L.LeafletMouseEvent): L.LatLng {
|
|
78
|
-
|
|
69
|
+
return e.latlng.wrap(); // (mapbox)
|
|
79
70
|
}
|
|
80
71
|
|
|
81
72
|
export function removeLayer(map: L.Map, layerId: string, layer?: L.Layer) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
73
|
+
// biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
|
|
74
|
+
map.eachLayer((l: any) => {
|
|
75
|
+
if (l.options.id === layerId) {
|
|
76
|
+
map.removeLayer(l);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
88
79
|
}
|
|
89
80
|
|
|
90
81
|
export async function addLayer(map: L.Map, idL: string, layer: L.Layer) {
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
map.addLayer(layer);
|
|
83
|
+
await new Promise((done) => layer.once('load', done)); // highly recommended to await for the first load
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function fetchImage(url, callback, errback, headers, abort) {
|
|
87
|
+
const controller = new AbortController();
|
|
88
|
+
const signal = controller.signal;
|
|
89
|
+
if (abort) {
|
|
90
|
+
abort.subscribe(() => {
|
|
91
|
+
controller.abort();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
await fetch(url, {
|
|
95
|
+
method: 'GET',
|
|
96
|
+
headers: headers,
|
|
97
|
+
mode: 'cors',
|
|
98
|
+
signal: signal,
|
|
99
|
+
})
|
|
100
|
+
.then((resp) => {
|
|
101
|
+
if (resp.ok) {
|
|
102
|
+
return resp.blob();
|
|
103
|
+
}
|
|
104
|
+
throw new Error(`Unexpected response: ${resp.status} (${resp.type})`);
|
|
105
|
+
})
|
|
106
|
+
.then((blob) => callback(blob))
|
|
107
|
+
.catch((error) => errback(error));
|
|
93
108
|
}
|
|
94
109
|
|
|
110
|
+
L.TileLayerWithHeaders = L.TileLayer.extend({
|
|
111
|
+
initialize: function (url, options, headers, abort) {
|
|
112
|
+
L.TileLayer.prototype.initialize.call(this, url, options);
|
|
113
|
+
this.headers = headers;
|
|
114
|
+
this.abort = abort;
|
|
115
|
+
},
|
|
116
|
+
createTile(coords, done) {
|
|
117
|
+
const url = this.getTileUrl(coords);
|
|
118
|
+
const img = document.createElement('img');
|
|
119
|
+
img.setAttribute('role', 'presentation');
|
|
120
|
+
fetchImage(
|
|
121
|
+
url,
|
|
122
|
+
(resp) => {
|
|
123
|
+
if (resp.size > 0) {
|
|
124
|
+
const reader = new FileReader();
|
|
125
|
+
reader.onload = () => {
|
|
126
|
+
img.src = reader.result;
|
|
127
|
+
};
|
|
128
|
+
reader.readAsDataURL(resp);
|
|
129
|
+
done(null, img);
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
(error) => console.log(error),
|
|
133
|
+
this.headers,
|
|
134
|
+
this.abort,
|
|
135
|
+
);
|
|
136
|
+
return img;
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
L.tileLayerWithHeaders = function (url, options, headers, abort) {
|
|
141
|
+
return new L.TileLayerWithHeaders(url, options, headers, abort);
|
|
142
|
+
};
|
|
143
|
+
|
|
95
144
|
export function addRaster(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
145
|
+
map: L.Map,
|
|
146
|
+
idS: string,
|
|
147
|
+
idL: string,
|
|
148
|
+
URL: string,
|
|
149
|
+
maxZoom: number,
|
|
150
|
+
// biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
|
|
151
|
+
bounds?: any,
|
|
152
|
+
headers?: any,
|
|
103
153
|
) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
154
|
+
const options = {
|
|
155
|
+
id: idS,
|
|
156
|
+
maxNativeZoom: maxZoom,
|
|
157
|
+
zIndex: idL === 'baseL' ? 1 : 0,
|
|
158
|
+
};
|
|
159
|
+
const layer = headers ? L.tileLayerWithHeaders(URL, options, headers) : L.tileLayer(URL, options);
|
|
160
|
+
map.addLayer(layer);
|
|
110
161
|
}
|
package/src_example/index.ts
CHANGED
|
@@ -1,55 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'leaflet/dist/leaflet.css';
|
|
2
2
|
|
|
3
|
-
import { start } from
|
|
3
|
+
import { start } from './start';
|
|
4
4
|
start();
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
import L from 'leaflet'; // goes first always!
|
|
8
|
-
import { WxTileSource, WxAPI, WxTilesLogging, FrameworkOptions } from '../src/index';
|
|
9
|
-
|
|
10
|
-
start1();
|
|
11
|
-
async function start1() {
|
|
12
|
-
//// Leaflet initialization START
|
|
13
|
-
const map = L.map('map', { center: [0, 0], zoom: 2, zoomControl: true });
|
|
14
|
-
// add navigation controls
|
|
15
|
-
L.control.zoom({ position: 'bottomright' }).addTo(map);
|
|
16
|
-
//// Leaflet initialization END
|
|
17
|
-
|
|
18
|
-
//// Helper
|
|
19
|
-
const addWxLayer = async (wxsource) => {
|
|
20
|
-
map.addLayer(wxsource);
|
|
21
|
-
await new Promise((done) => wxsource.once('load', done)); // highly recommended to await for the first load
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const getCoords = (e) => e.latlng.wrap();
|
|
25
|
-
//// Helpers END
|
|
26
|
-
|
|
27
|
-
//// WXTILES START
|
|
28
|
-
// grab the WxTiles API
|
|
29
|
-
// const { WxTilesLogging, WxAPI } = window.wxtilesleaflet;
|
|
30
|
-
|
|
31
|
-
WxTilesLogging(true); // log WxTiles info to console if needed
|
|
32
|
-
|
|
33
|
-
const dataServerURL = 'https://tiles.metoceanapi.com/data/';
|
|
34
|
-
// Get the API ready - should be ONE per application
|
|
35
|
-
const wxapi = new WxAPI({ dataServerURL, maskURL: 'auto', qtreeURL: 'auto' });
|
|
36
|
-
|
|
37
|
-
// Define the dataset and variable
|
|
38
|
-
const datasetName = 'gfs.global';
|
|
39
|
-
// const variable = 'air.temperature.at-2m'; // Scalar example
|
|
40
|
-
const variable = 'wind.speed.eastward.at-10m'; // Vector example
|
|
41
|
-
|
|
42
|
-
// Create a dataset manager (may be used for many layers from this dataset)
|
|
43
|
-
const wxdatasetManager = await wxapi.createDatasetManager(datasetName);
|
|
44
|
-
|
|
45
|
-
// create a layer
|
|
46
|
-
const layerFrameworkOptions = { id: 'wxsource', opacity: 1, attribution: 'WxTiles' };
|
|
47
|
-
const wxsource = wxdatasetManager.createSourceLayer({ variable, time: 0 }, layerFrameworkOptions);
|
|
48
|
-
|
|
49
|
-
// add the layer to the map
|
|
50
|
-
await addWxLayer(wxsource);
|
|
51
|
-
|
|
52
|
-
// extra magic
|
|
53
|
-
await wxsource.updateCurrentStyleObject({ streamLineColor: 'inverted' });
|
|
54
|
-
}
|
|
55
|
-
// */
|