@metoceanapi/wxtiles-leaflet 2.4.0-1 → 2.4.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.
Files changed (91) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +214 -92
  3. package/dist/es/index.d.ts +12 -16
  4. package/dist/es/index.js +4 -4
  5. package/dist/es/wxAPI/WxAPI.d.ts +17 -0
  6. package/dist/es/wxAPI/WxDataSetManager.d.ts +14 -4
  7. package/dist/es/wxsource/wxsource.d.ts +24 -20
  8. package/dist/es/wxsource/wxsourcetypes.d.ts +22 -10
  9. package/dist/web/index.js +4 -4
  10. package/docs/docs/assets/highlight.css +12 -19
  11. package/docs/docs/assets/search.js +1 -1
  12. package/docs/docs/classes/WxAPI.html +31 -18
  13. package/docs/docs/classes/WxAPIControl.html +70 -24
  14. package/docs/docs/classes/WxDataSetManager.html +22 -21
  15. package/docs/docs/classes/WxInfoControl.html +37 -10
  16. package/docs/docs/classes/WxLegendControl.html +33 -11
  17. package/docs/docs/classes/WxStyleEditorControl.html +206 -94
  18. package/docs/docs/classes/WxTileSource.html +40 -40
  19. package/docs/docs/classes/WxTimeControl.html +58 -20
  20. package/docs/docs/index.html +188 -101
  21. package/docs/docs/interfaces/FrameworkOptions.html +3 -3
  22. package/docs/docs/interfaces/WxSourceLayerOptions.html +5 -5
  23. package/docs/docs/modules.html +12 -130
  24. package/docs/docs/types/Loader.html +3 -59
  25. package/docs/docs/types/Painter.html +3 -59
  26. package/docs/docs/types/WxLayer.html +3 -59
  27. package/docs/docs/variables/WxLayerBaseImplementation.html +3 -59
  28. package/docs/script/script.css +1 -1
  29. package/docs/script/script.js +6 -6
  30. package/package.json +3 -3
  31. package/src_example/frwrkdeps.ts +131 -80
  32. package/src_example/index.ts +2 -53
  33. package/src_example/start.ts +143 -300
  34. package/dep.dot +0 -33
  35. package/dep.svg +0 -233
  36. package/docs/docs/classes/DataIntegral.html +0 -154
  37. package/docs/docs/classes/QTree.html +0 -185
  38. package/docs/docs/classes/RawCLUT.html +0 -143
  39. package/docs/docs/classes/TilesCache.html +0 -108
  40. package/docs/docs/enums/TileType.html +0 -80
  41. package/docs/docs/functions/WXLOG.html +0 -127
  42. package/docs/docs/functions/WxCreateLegend.html +0 -135
  43. package/docs/docs/functions/WxGetColorSchemes.html +0 -122
  44. package/docs/docs/functions/WxGetColorStyles.html +0 -122
  45. package/docs/docs/functions/WxTilesLogging.html +0 -130
  46. package/docs/docs/interfaces/CachedUriLoaderPromiseFunc.html +0 -108
  47. package/docs/docs/interfaces/ColorStylesIncomplete.html +0 -125
  48. package/docs/docs/interfaces/Converter.html +0 -81
  49. package/docs/docs/interfaces/DataPicture.html +0 -95
  50. package/docs/docs/interfaces/IntegralPare.html +0 -81
  51. package/docs/docs/interfaces/SLinePoint.html +0 -77
  52. package/docs/docs/interfaces/Tree.html +0 -74
  53. package/docs/docs/interfaces/WxAPIOptions.html +0 -173
  54. package/docs/docs/interfaces/WxAllBoundariesMeta.html +0 -90
  55. package/docs/docs/interfaces/WxAllDatasetsShortMetas.html +0 -125
  56. package/docs/docs/interfaces/WxBoundaryMeta.html +0 -99
  57. package/docs/docs/interfaces/WxColorSchemes.html +0 -126
  58. package/docs/docs/interfaces/WxColorStyleStrict.html +0 -359
  59. package/docs/docs/interfaces/WxColorStyleWeak.html +0 -388
  60. package/docs/docs/interfaces/WxColorStylesStrict.html +0 -74
  61. package/docs/docs/interfaces/WxColorStylesWeakMixed.html +0 -125
  62. package/docs/docs/interfaces/WxData.html +0 -85
  63. package/docs/docs/interfaces/WxDataSetManagerOptions.html +0 -117
  64. package/docs/docs/interfaces/WxDatasetMeta.html +0 -144
  65. package/docs/docs/interfaces/WxDatasetShortMeta.html +0 -91
  66. package/docs/docs/interfaces/WxLayerAPI.html +0 -375
  67. package/docs/docs/interfaces/WxLayerBaseAPI.html +0 -242
  68. package/docs/docs/interfaces/WxLayerOptions.html +0 -113
  69. package/docs/docs/interfaces/WxLegend.html +0 -118
  70. package/docs/docs/interfaces/WxLngLat.html +0 -81
  71. package/docs/docs/interfaces/WxRasterData.html +0 -118
  72. package/docs/docs/interfaces/WxRequestInit.html +0 -70
  73. package/docs/docs/interfaces/WxTick.html +0 -100
  74. package/docs/docs/interfaces/WxTileInfo.html +0 -142
  75. package/docs/docs/interfaces/WxUnits.html +0 -125
  76. package/docs/docs/interfaces/WxVariableMeta.html +0 -109
  77. package/docs/docs/interfaces/WxVariablesMetas.html +0 -125
  78. package/docs/docs/interfaces/XYZ.html +0 -84
  79. package/docs/docs/types/DataIntegrals.html +0 -118
  80. package/docs/docs/types/DataPictures.html +0 -118
  81. package/docs/docs/types/ListenerMethod.html +0 -134
  82. package/docs/docs/types/SLine.html +0 -118
  83. package/docs/docs/types/SubTrees.html +0 -118
  84. package/docs/docs/types/SubTreesN.html +0 -118
  85. package/docs/docs/types/TreeN.html +0 -118
  86. package/docs/docs/types/WxDate.html +0 -125
  87. package/docs/docs/types/WxEventType.html +0 -121
  88. package/docs/docs/types/WxInstances.html +0 -118
  89. package/docs/docs/types/WxLayerVarsNames.html +0 -118
  90. package/docs/docs/types/WxURIs.html +0 -118
  91. 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.0-1",
3
+ "version": "2.4.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",
@@ -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 --excludeExternals -gitRevision main src",
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.10"
41
+ "@metoceanapi/wxtiles-common": "^0.0.11-1"
42
42
  }
43
43
  }
@@ -1,110 +1,161 @@
1
- import L from "leaflet";
2
- import { WxGetColorStyles } from "@metoceanapi/wxtiles-common/utils/wxtools";
1
+ import { WxGetColorStyles } from '@metoceanapi/wxtiles-common/utils/wxtools';
2
+ import L from 'leaflet';
3
3
 
4
- export function flyTo(
5
- map: L.Map,
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
- map: L.Map,
17
- time: string,
18
- datasetName: string,
19
- variable: string,
20
- // biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
21
- style: any,
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
- let newStyle = style
24
- const { base } = WxGetColorStyles();
25
- for (const i in style) style[i] === base[i] && delete style[i]; // remove default values
26
- if (style.gl) {
27
- for (const i in style.gl)
28
- style.gl[i] === base.gl?.[i] && delete style.gl[i]; // remove default values from gl
29
- if (Object.keys(style.gl).length === 0) {
30
- const { gl, ...rest } = style; // Destructure to exclude gl
31
- newStyle = rest; // Assign the new object back to style
32
- }
33
- }
34
- const center = map.getCenter().wrap();
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
- history.replaceState(null, "", href);
39
- // location.href = `#${datasetName}/${variables.join(',')}/${time}/${map.getZoom().toFixed(2)}/${center.lng.toFixed(2)}/${center.lat.toFixed(2)}`;
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
- const map = L.map("map", {
44
- center: [-40.75, 174.5],
45
- zoom: 7,
46
- zoomControl: false,
47
- });
34
+ const map = L.map('map', {
35
+ center: [-40.75, 174.5],
36
+ zoom: 7,
37
+ zoomControl: false,
38
+ });
48
39
 
49
- L.control.zoom({ position: "bottomright" }).addTo(map);
40
+ L.control.zoom({ position: 'bottomright' }).addTo(map);
50
41
 
51
- // class WxDebugLayer extends L.GridLayer {
52
- // createTile(coords: { x: number; y: number; z: number }) {
53
- // const tile = document.createElement('div');
54
- // tile.innerHTML = [coords.x, coords.y, coords.z].join(', ');
55
- // tile.style.outline = '1px solid red';
56
- // return tile;
57
- // }
58
- // }
59
- // map.addLayer(new WxDebugLayer().setZIndex(1000));
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
- return map;
52
+ return map;
62
53
  }
63
54
 
64
55
  export function addControl(
65
- map: L.Map,
66
- // biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
67
- control: { extender: () => any },
68
- position: string,
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
- const newPosition = position.replace("-", "");
71
- map.addControl(
72
- // biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
73
- new (L.Control.extend(control.extender()))({ position: newPosition as any }),
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
- return e.latlng.wrap(); // (mapbox)
69
+ return e.latlng.wrap(); // (mapbox)
79
70
  }
80
71
 
81
72
  export function removeLayer(map: L.Map, layerId: string, layer?: L.Layer) {
82
- // biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
83
- map.eachLayer((l: any) => {
84
- if (l.options.id === layerId) {
85
- map.removeLayer(l);
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
- map.addLayer(layer);
92
- await new Promise((done) => layer.once("load", done)); // highly recommended to await for the first load
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
- map: L.Map,
97
- idS: string,
98
- idL: string,
99
- URL: string,
100
- maxZoom: number,
101
- // biome-ignore lint/suspicious/noExplicitAny: Suppressing for specific use case
102
- bounds?: any,
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
- const layer = L.tileLayer(URL, {
105
- id: idS,
106
- maxNativeZoom: maxZoom,
107
- zIndex: idL === "baseL" ? 1 : 0,
108
- });
109
- map.addLayer(layer);
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
  }
@@ -1,55 +1,4 @@
1
- import "leaflet/dist/leaflet.css";
1
+ import 'leaflet/dist/leaflet.css';
2
2
 
3
- import { start } from "./start";
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
- // */