@metoceanapi/wxtiles-leaflet 2.0.9 → 2.1.1

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 (40) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/es/controls/WxAPIControl.d.ts +1 -1
  3. package/dist/es/controls/WxInfoControl.d.ts +2 -1
  4. package/dist/es/index.js +2 -2
  5. package/dist/es/wxAPI/WxDataSetManager.d.ts +40 -16
  6. package/dist/es/wxAPI/wxAPI.d.ts +1 -1
  7. package/dist/es/wxlayer/WxImplementation.d.ts +17 -6
  8. package/dist/es/wxlayer/loader.d.ts +2 -0
  9. package/dist/es/wxlayer/painter.d.ts +5 -0
  10. package/dist/es/wxlayer/wxlayer.d.ts +29 -14
  11. package/dist/es/wxsource/wxsource.d.ts +5 -0
  12. package/dist/web/index.js +2 -2
  13. package/docs/docs/assets/search.js +1 -1
  14. package/docs/docs/classes/DataIntegral.html +9 -9
  15. package/docs/docs/classes/FrameworkParentClass.html +3 -3
  16. package/docs/docs/classes/Loader.html +12 -5
  17. package/docs/docs/classes/Painter.html +6 -6
  18. package/docs/docs/classes/WxAPI.html +3 -3
  19. package/docs/docs/classes/WxDataSetManager.html +125 -68
  20. package/docs/docs/classes/WxLayer.html +62 -43
  21. package/docs/docs/classes/WxLayerBaseImplementation.html +66 -19
  22. package/docs/docs/classes/WxTileSource.html +74 -22
  23. package/docs/docs/functions/WXLOG.html +1 -1
  24. package/docs/docs/functions/WxTilesLogging.html +1 -1
  25. package/docs/docs/interfaces/DataPicture.html +5 -5
  26. package/docs/docs/interfaces/FrameworkOptions.html +2 -2
  27. package/docs/docs/interfaces/IntegralPare.html +3 -3
  28. package/docs/docs/interfaces/WxDataSetManagerOptions.html +33 -24
  29. package/docs/docs/interfaces/WxDatasetMeta.html +4 -4
  30. package/docs/docs/interfaces/WxLayerAPI.html +29 -29
  31. package/docs/docs/interfaces/WxLayerBaseAPI.html +20 -20
  32. package/docs/docs/interfaces/WxLayerOptions.html +6 -15
  33. package/docs/docs/interfaces/WxRasterData.html +18 -2
  34. package/docs/docs/interfaces/WxSourceLayerOptions.html +6 -16
  35. package/docs/docs/types/DataIntegrals.html +1 -1
  36. package/docs/docs/types/DataPictures.html +1 -1
  37. package/docs/script/script.js +4 -4
  38. package/package.json +1 -1
  39. package/src_example/frwrkdeps.ts +1 -2
  40. package/src_example/start.ts +26 -25
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metoceanapi/wxtiles-leaflet",
3
- "version": "2.0.9",
3
+ "version": "2.1.1",
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",
@@ -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, idS: string, idL: string, layer: L.Layer) {
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) {
@@ -14,10 +14,10 @@ export const OPACITY = 0.8;
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(false);
17
+ // WxTilesLogging(console.trace);
18
18
  // const dataServerURL = 'http://localhost:9191/data/';
19
19
  // const dataServerURL = 'https://68.171.214.87/data/'
20
- const dataServerURL = 'https://tiles.metoceanapi.com/data/';
20
+ const dataServerURL = 'https://tilestest.metoceanapi.com/data/';
21
21
  // const dataServerURL = 'http://tiles3.metoceanapi.com/';
22
22
  const myHeaders = new Headers();
23
23
  // myHeaders.append('x-api-key', 'SpV3J1RypVrv2qkcJE91gG');
@@ -29,15 +29,15 @@ export async function start() {
29
29
  requestInit: { headers: myHeaders },
30
30
  });
31
31
 
32
- let datasetName = 'gfs.global'; /* 'mercator.global/'; */ /* 'ecwmf.global/'; */ /* 'obs-radar.rain.nzl.national/'; */
33
- let variable = 'air.temperature.at-2m';
32
+ // let datasetName = 'gfs.global'; /* 'mercator.global/'; */ /* 'ecwmf.global/'; */ /* 'obs-radar.rain.nzl.national/'; */
33
+ // let variable = 'air.temperature.at-2m';
34
34
  // let variables: WxVars = ['wind.speed.eastward.at-10m', 'wind.speed.northward.at-10m'];
35
35
 
36
36
  // let datasetName = 'ww3-ecmwf.global';
37
37
  // let variable = 'wave.direction.mean';
38
38
 
39
- // let datasetName = 'obs-radar.rain.nzl.national';
40
- // let variables: WxVars = ['reflectivity'];
39
+ let datasetName = 'obs-radar.rain.nzl.national';
40
+ let variable = 'reflectivity';
41
41
 
42
42
  // get datasetName from URL
43
43
  const urlParams = window.location.toString().split('##')[1];
@@ -59,18 +59,17 @@ export async function start() {
59
59
  sth.style = str && { ...JSON.parse(decodeURI(str)) }; // reset levels if change units
60
60
  } catch (e) {
61
61
  /* ignore errors silently */
62
- console.log(e);
62
+ console.log("Can't parse style from URL");
63
63
  }
64
64
 
65
- flyTo(map, zoom, lng, lat, bearing, pitch);
65
+ params && flyTo(map, zoom, lng, lat, bearing, pitch); // if no params stay at default position set in initFrameWork()
66
66
 
67
- // const sth = { style: {} };
68
67
  map.on('zoom', () => setURL(map, time, datasetName, variable, sth.style));
69
68
  map.on('drag', () => setURL(map, time, datasetName, variable, sth.style));
70
69
  map.on('rotate', () => setURL(map, time, datasetName, variable, sth.style));
71
70
  map.on('pitch', () => setURL(map, time, datasetName, variable, sth.style));
72
71
 
73
- let wxsource: WxTileSource | undefined;
72
+ let wxsourceLayer: WxTileSource | undefined;
74
73
 
75
74
  const legendControl = new WxLegendControl();
76
75
  addControl(map, legendControl, 'top-right');
@@ -78,53 +77,55 @@ export async function start() {
78
77
  const frameworkOptions = { id: 'wxsource', opacity: OPACITY, attribution: 'WxTiles' };
79
78
  const apiControl = new WxAPIControl(wxapi, datasetName, variable);
80
79
  addControl(map, apiControl, 'top-left');
81
- apiControl.onchange = async (datasetName_, variable_, nonnativecall): Promise<void> => {
80
+ apiControl.onchange = async (datasetName_, variable_, resetStyleAndFlyTo = true): Promise<void> => {
82
81
  WXLOG('apiControl.onchange datasetName=', datasetName_, 'variable=', variable_);
83
82
  // remove existing source and layer
84
- removeLayer(map, frameworkOptions.id, wxsource);
83
+ removeLayer(map, frameworkOptions.id, wxsourceLayer);
85
84
  //
86
- nonnativecall || (sth.style = {}); // reset style if change dataset/variable
87
- wxsource = undefined;
85
+ resetStyleAndFlyTo && (sth.style = {}); // reset style if change dataset/variable
86
+ wxsourceLayer = undefined;
88
87
  datasetName = datasetName_;
89
88
  variable = variable_;
90
89
  const wxdatasetManager = await wxapi.createDatasetManager(datasetName);
91
90
  const boundaries = wxdatasetManager.getBoundaries();
92
- if (boundaries && !nonnativecall) {
91
+ if (boundaries && resetStyleAndFlyTo) {
93
92
  const { east, west, north, south } = boundaries.boundariesnorm;
94
93
  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
94
  flyTo(map, zoom, (east + west) / 2, (north + south) / 2, 0, 0);
96
95
  }
97
96
  const meta = wxdatasetManager.getVariableMeta(variable);
98
97
  if (meta?.units === 'RGB') {
99
- addRaster(map, frameworkOptions.id, 'wxtiles', wxdatasetManager.createURI(variable, 0), wxdatasetManager.getMaxZoom());
98
+ addRaster(map, frameworkOptions.id, 'wxtiles', wxdatasetManager.createURI(variable, wxdatasetManager.getTimes()[0]), wxdatasetManager.getMaxZoom());
100
99
  timeControl.setTimes(wxdatasetManager.getTimes());
101
100
  legendControl.clear();
102
101
  } else {
103
- wxsource = wxdatasetManager.createSourceLayer({ variable, time, wxstyle: sth.style }, frameworkOptions);
104
- await addLayer(map, frameworkOptions.id, 'wxtiles', wxsource);
105
- const styleCopy = wxsource.getCurrentStyleObjectCopy();
102
+ wxsourceLayer = wxdatasetManager.createSourceLayer({ variable, time, wxstyle: sth.style }, frameworkOptions);
103
+ await addLayer(map, 'wxtiles', wxsourceLayer);
104
+ // wxsource.startAnimation();
105
+ const styleCopy = wxsourceLayer.getCurrentStyleObjectCopy();
106
106
  legendControl.drawLegend(styleCopy); // first draw legend with current style
107
107
  styleCopy.levels = sth.style?.levels; // no need to show defaults it in the editor and URL
108
108
  styleCopy.colors = sth.style?.colors; // no need to show defaults it in the editor and URL
109
109
  await customStyleEditorControl.onchange?.(styleCopy, true);
110
110
  }
111
111
 
112
- timeControl.updateSource(wxsource);
112
+ timeControl.updateSource(wxsourceLayer);
113
113
  };
114
114
 
115
115
  const timeControl = new WxTimeControl(50);
116
116
  addControl(map, timeControl, 'top-left');
117
117
  timeControl.onchange = (time_) => {
118
118
  setURL(map, (time = time_), datasetName, variable, sth.style);
119
+ infoControl.update(wxsourceLayer, map);
119
120
  };
120
121
 
121
122
  const customStyleEditorControl = new WxStyleEditorControl();
122
123
  addControl(map, customStyleEditorControl, 'top-right');
123
124
  customStyleEditorControl.onchange = async (style, nonnativecall) => {
124
125
  WXLOG('customStyleEditorControl.onchange');
125
- if (!wxsource) return;
126
- nonnativecall || (await wxsource.updateCurrentStyleObject(style)); // if called manually, do not update wxsource's style
127
- const nstyle = wxsource.getCurrentStyleObjectCopy();
126
+ if (!wxsourceLayer) return;
127
+ nonnativecall || (await wxsourceLayer.updateCurrentStyleObject(style)); // if called manually, do not update wxsource's style
128
+ const nstyle = wxsourceLayer.getCurrentStyleObjectCopy();
128
129
  legendControl.drawLegend(nstyle);
129
130
  nstyle.levels = style?.levels; // keep levels empty if they are not defined
130
131
  nstyle.colors = style?.colors; // keep colors empty if they are not defined
@@ -135,9 +136,9 @@ export async function start() {
135
136
 
136
137
  const infoControl = new WxInfoControl();
137
138
  addControl(map, infoControl, 'bottom-left');
138
- map.on('mousemove', (e) => infoControl.update(wxsource, map, position(e)));
139
+ map.on('mousemove', (e) => infoControl.update(wxsourceLayer, map, position(e)));
139
140
 
140
- await apiControl.onchange(datasetName, variable, true); // initial load
141
+ await apiControl.onchange(datasetName, variable, false); // initial load
141
142
 
142
143
  /*/ DEMO: more interactive - additional level and a bit of the red transparentness around the level made from current mouse position
143
144
  if (wxsource) {