gridviz 2.1.16 → 3.0.0

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 (67) hide show
  1. package/README.md +2 -3
  2. package/dist/gridviz.js +4971 -5654
  3. package/dist/gridviz.min.js +1 -1
  4. package/package.json +3 -2
  5. package/src/button/Button.js +14 -15
  6. package/src/button/FullscreenButton.js +14 -14
  7. package/src/button/ZoomButtons.js +2 -2
  8. package/src/{DatasetComponent.js → core/Dataset.js} +33 -12
  9. package/src/core/Drawable.js +60 -0
  10. package/src/{GeoCanvas.js → core/GeoCanvas.js} +65 -155
  11. package/src/core/Layer.js +24 -0
  12. package/src/{Legend.js → core/Legend.js} +24 -1
  13. package/src/core/Map.js +460 -0
  14. package/src/core/MultiResolutionDataset.js +96 -0
  15. package/src/core/Style.js +84 -0
  16. package/src/dataset/COGeo.js +5 -5
  17. package/src/dataset/CSVGrid.js +43 -41
  18. package/src/dataset/GeoTIFF.js +9 -14
  19. package/src/dataset/{LGrid.js → JSGrid.js} +9 -10
  20. package/src/dataset/TiledGrid.js +68 -45
  21. package/src/index.js +22 -29
  22. package/src/{BackgroundLayer.js → layer/BackgroundLayer.js} +27 -52
  23. package/src/{BackgroundLayerWMS.js → layer/BackgroundLayerWMS.js} +21 -45
  24. package/src/{LineLayer.js → layer/GeoJSONLayer.js} +22 -23
  25. package/src/layer/GridLayer.js +140 -0
  26. package/src/{LabelLayer.js → layer/LabelLayer.js} +25 -23
  27. package/src/legend/ColorCategoryLegend.js +9 -24
  28. package/src/legend/ColorDiscreteLegend.js +20 -24
  29. package/src/legend/ColorLegend.js +21 -33
  30. package/src/legend/OrientationLegend.js +90 -0
  31. package/src/legend/SizeLegend.js +153 -72
  32. package/src/style/CompositionStyle.js +71 -84
  33. package/src/style/ContourStyle.js +2 -36
  34. package/src/style/DotDensityStyle.js +50 -73
  35. package/src/style/IsoFenceStyle.js +59 -70
  36. package/src/style/JoyPlotStyle.js +41 -48
  37. package/src/style/LegoStyle.js +4 -4
  38. package/src/style/MosaicStyle.js +30 -39
  39. package/src/style/NinjaStarStyle.js +45 -68
  40. package/src/style/PillarStyle.js +70 -93
  41. package/src/style/SegmentStyle.js +37 -75
  42. package/src/style/ShapeColorSizeStyle.js +49 -98
  43. package/src/style/SideCategoryStyle.js +112 -0
  44. package/src/style/SideStyle.js +99 -133
  45. package/src/style/{SquareColorCatWGLStyle.js → SquareColorCategoryWebGLStyle.js} +28 -41
  46. package/src/style/{SquareColorWGLStyle.js → SquareColorWebGLStyle.js} +28 -49
  47. package/src/style/StrokeStyle.js +43 -70
  48. package/src/style/TanakaStyle.js +34 -132
  49. package/src/style/TextStyle.js +43 -64
  50. package/src/style/TimeSeriesStyle.js +44 -75
  51. package/src/utils/WebGLSquareColoringAdvanced.js +4 -4
  52. package/src/utils/scale.js +202 -0
  53. package/src/utils/stretching.js +86 -129
  54. package/src/utils/{Utils.js → utils.js} +15 -0
  55. package/src/utils/webGLUtils.js +4 -5
  56. package/src/utils/zoomUtils.js +30 -30
  57. package/src/App.js +0 -760
  58. package/src/Dataset.js +0 -76
  59. package/src/Layer.js +0 -103
  60. package/src/Style.js +0 -131
  61. package/src/dataset/GridTile.js +0 -41
  62. package/src/legend/SegmentOrientationLegend.js +0 -87
  63. package/src/legend/SegmentWidthLegend.js +0 -101
  64. package/src/style/CompositionStyle_.js +0 -293
  65. package/src/style/ShapeColorSizeStyle_.js +0 -108
  66. package/src/style/SideCatStyle.js +0 -172
  67. /package/src/{Tooltip.js → core/Tooltip.js} +0 -0
@@ -0,0 +1,84 @@
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Drawable } from "./Drawable.js"
5
+
6
+ /** @typedef {"square"|"circle"|"diamond"|"donut"|"none"} Shape */
7
+
8
+ /**
9
+ * viewScale type
10
+ * Returns an object from a list of cells,
11
+ * @typedef {function(Array.<import('./Dataset.js').Cell>,number, number):*} ViewScale */
12
+
13
+ /**
14
+ * A style, to show a grid dataset.
15
+ *
16
+ * @author Joseph Davies, Julien Gaffuri
17
+ */
18
+ export class Style extends Drawable {
19
+ /**
20
+ * @abstract
21
+ * @param {{filter?:function(import('./Dataset').Cell):boolean, offset?:function(import('./Dataset').Cell, number, number):{dx:number,dy:number}, visible?:function(number):boolean,alpha?:function(number):number,blendOperation?:function(number):GlobalCompositeOperation,drawFun?:function,viewScale?:ViewScale}} opts
22
+ */
23
+ constructor(opts) {
24
+ super(opts)
25
+ opts = opts || {}
26
+
27
+ /**
28
+ * @type {ViewScale|undefined} */
29
+ this.viewScale = opts.viewScale
30
+
31
+ /** A filter function to apply to the cell list, to filter out some cells not to be drawn (such as for example the cells with value=0).
32
+ * @protected
33
+ * @type {function(import('./Dataset').Cell):boolean} */
34
+ this.filter = opts.filter || (() => true)
35
+
36
+ /** An offset. This is to alter the position of all symbols in a given direction. In geographical unit.
37
+ * @protected
38
+ * @type {function(import('./Dataset').Cell,number,number):{dx:number,dy:number}} */
39
+ this.offset = opts.offset || ((c, r, z) => ({ dx: 0, dy: 0 }))
40
+
41
+ /** A draw function for the style.
42
+ * @type {function|undefined} */
43
+ this.drawFun = opts.drawFun
44
+
45
+ /**
46
+ * @public
47
+ * @type {Array.<import("./Legend").Legend>} */
48
+ this.legends = []
49
+ }
50
+
51
+ /**
52
+ * Draw cells.
53
+ *
54
+ * @param {Array.<import('./Dataset').Cell>} cells The cells to draw.
55
+ * @param {import("./GeoCanvas").GeoCanvas} geoCanvas The canvas where to draw them.
56
+ * @param {number} resolution Their resolution (in geographic unit)
57
+ * @abstract
58
+ */
59
+ draw(cells, geoCanvas, resolution) {
60
+ if (this.drawFun) this.drawFun(cells, geoCanvas, resolution)
61
+ else throw new Error('Method draw not implemented.')
62
+ }
63
+
64
+ //getters and setters
65
+
66
+ /** @returns {function(import('./Dataset').Cell,number,number):{dx:number,dy:number}} */
67
+ getOffset() {
68
+ return this.offset
69
+ }
70
+ /** @param {function(import('./Dataset').Cell,number,number):{dx:number,dy:number}} val @returns {this} */
71
+ setOffset(val) {
72
+ this.offset = val
73
+ return this
74
+ }
75
+
76
+ /** Hide all legend elements of the style, if any
77
+ * @param {object} opts
78
+ * @returns {this} */
79
+ updateLegends(opts) {
80
+ for (const lg of this.legends) lg.update(opts)
81
+ return this
82
+ }
83
+
84
+ }
@@ -1,7 +1,7 @@
1
1
  //@ts-check
2
2
  'use strict'
3
3
 
4
- import { DatasetComponent } from '../DatasetComponent.js'
4
+ import { Dataset } from '../core/Dataset.js'
5
5
 
6
6
  /**
7
7
  * @todo
@@ -10,14 +10,14 @@ import { DatasetComponent } from '../DatasetComponent.js'
10
10
  *
11
11
  * @author Joseph Davies, Julien Gaffuri
12
12
  */
13
- export class COGeo extends DatasetComponent {
13
+ export class COGeo extends Dataset {
14
14
  /**
15
15
  *
16
16
  * @param {String} url
17
- * @param {{preprocess?:(function(import("../Dataset").Cell):boolean)}} opts
17
+ * @param {{preprocess?:(function(import("../core/Dataset").Cell):boolean)}} opts
18
18
  */
19
- constructor(url, opts = {}) {
20
- super(url, 0, opts)
19
+ constructor(map, url, opts = {}) {
20
+ super(map, url, 0, opts)
21
21
  }
22
22
 
23
23
  //TODO Use https://geotiffjs.github.io/
@@ -1,83 +1,85 @@
1
1
  //@ts-check
2
2
  'use strict'
3
3
 
4
- /** @typedef {{ dims: object, crs: string, tileSizeCell: number, originPoint: {x:number,y:number}, resolutionGeo: number, tilingBounds:import("../Dataset").Envelope }} GridInfo */
4
+ /** @typedef {{ dims: object, crs: string, tileSizeCell: number, originPoint: {x:number,y:number}, resolutionGeo: number, tilingBounds:import("../core/GeoCanvas.js").Envelope }} GridInfo */
5
5
 
6
6
  import { csv } from 'd3-fetch'
7
- import { DatasetComponent } from '../DatasetComponent.js'
7
+ import { Dataset } from '../core/Dataset.js'
8
8
 
9
9
  /**
10
10
  * A dataset composed of a single CSV file (not tiled).
11
11
  *
12
12
  * @author Joseph Davies, Julien Gaffuri
13
13
  */
14
- export class CSVGrid extends DatasetComponent {
14
+ export class CSVGrid extends Dataset {
15
15
  /**
16
+ * @param {import("../core/Map.js").Map} map The map.
16
17
  * @param {string} url The URL of the dataset.
17
18
  * @param {number} resolution The dataset resolution in geographical unit.
18
- * @param {{preprocess?:(function(import("../Dataset").Cell):boolean)}} opts
19
+ * @param {{preprocess?:(function(import("../core/Dataset.js").Cell):boolean)}} opts
19
20
  */
20
- constructor(url, resolution, opts = {}) {
21
- super(url, resolution, opts)
21
+ constructor(map, url, resolution, opts = {}) {
22
+ super(map, url, resolution, opts)
22
23
 
23
24
  /**
24
25
  * @private
25
- * @type {Array.<import("../Dataset").Cell>} */
26
+ * @type {Array.<import("../core/Dataset.js").Cell>} */
26
27
  this.cells = []
27
28
 
28
29
  /**
29
30
  * @type {string}
30
31
  * @private */
31
32
  this.infoLoadingStatus = 'notLoaded'
33
+
34
+ //get data
35
+ this.getData(undefined)
32
36
  }
33
37
 
34
38
  /**
35
39
  * Request data within a geographic envelope.
36
- *
37
- * @param {import("../Dataset").Envelope|undefined} e
38
- * @param {function():void} redraw
40
+ * @param {import("../core/GeoCanvas.js").Envelope|undefined} e
39
41
  */
40
- getData(e, redraw) {
42
+ getData(e) {
41
43
  //check if data already loaded
42
44
  if (this.infoLoadingStatus != 'notLoaded') return this
43
45
 
44
46
  //load data
45
47
  this.infoLoadingStatus = 'loading'
46
- ;(async () => {
47
- try {
48
- const data = await csv(this.url)
49
-
50
- //convert coordinates in numbers
51
- for (const c of data) {
52
- c.x = +c.x
53
- c.y = +c.y
54
- }
48
+ ; (async () => {
49
+ try {
50
+ const data = await csv(this.url)
55
51
 
56
- //preprocess/filter
57
- if (this.preprocess) {
58
- this.cells = []
52
+ //convert coordinates in numbers
59
53
  for (const c of data) {
60
- const b = this.preprocess(c)
61
- if (b == false) continue
62
- this.cells.push(c)
54
+ c.x = +c.x
55
+ c.y = +c.y
63
56
  }
64
- } else {
65
- this.cells = data
66
- }
67
57
 
68
- //TODO check if redraw is necessary
69
- //that is if the dataset belongs to a layer which is visible at the current zoom level
58
+ //preprocess/filter
59
+ if (this.preprocess) {
60
+ this.cells = []
61
+ for (const c of data) {
62
+ const b = this.preprocess(c)
63
+ if (b == false) continue
64
+ this.cells.push(c)
65
+ }
66
+ } else {
67
+ this.cells = data
68
+ }
69
+
70
+ //TODO check if redraw is necessary
71
+ //that is if the dataset belongs to a layer which is visible at the current zoom level
70
72
 
71
- //execute the callback, usually a draw function
72
- if (redraw) redraw()
73
+ //execute the callback, usually a draw function
74
+ if (this.map) this.map.redraw()
73
75
 
74
- this.infoLoadingStatus = 'loaded'
75
- } catch (error) {
76
- //mark as failed
77
- this.infoLoadingStatus = 'failed'
78
- this.cells = []
79
- }
80
- })()
76
+ this.infoLoadingStatus = 'loaded'
77
+ } catch (error) {
78
+ //mark as failed
79
+ this.infoLoadingStatus = 'failed'
80
+ this.cells = []
81
+ }
82
+ })()
81
83
 
82
84
  return this
83
85
  }
@@ -85,7 +87,7 @@ export class CSVGrid extends DatasetComponent {
85
87
  /**
86
88
  * Fill the view cache with all cells which are within a geographical envelope.
87
89
  *
88
- * @param {import("../Dataset").Envelope} extGeo
90
+ * @param {import("../core/GeoCanvas.js").Envelope} extGeo
89
91
  * @returns {void}
90
92
  */
91
93
  updateViewCache(extGeo) {
@@ -1,7 +1,7 @@
1
1
  //@ts-check
2
2
  'use strict'
3
3
 
4
- import { DatasetComponent } from '../DatasetComponent.js'
4
+ import { Dataset } from '../core/Dataset.js'
5
5
  //import { fromUrl } from "geotiff"
6
6
 
7
7
  /**
@@ -10,18 +10,14 @@ import { DatasetComponent } from '../DatasetComponent.js'
10
10
  *
11
11
  * @author Joseph Davies, Julien Gaffuri
12
12
  */
13
- export class GeoTIFF extends DatasetComponent {
14
- /**
15
- * @param {string} url The URL of the dataset.
16
- * @param {number} resolution The dataset resolution in geographical unit.
17
- * @param {{preprocess?:(function(import("../Dataset").Cell):boolean)}} opts
18
- */
19
- constructor(url, resolution, opts = {}) {
20
- super(url, resolution, opts)
13
+ export class GeoTIFF extends Dataset {
14
+
15
+ constructor(map, url, resolution, opts = {}) {
16
+ super(map, url, resolution, opts)
21
17
 
22
18
  /**
23
19
  * @private
24
- * @type {Array.<import("../Dataset").Cell>} */
20
+ * @type {Array.<import("../core/Dataset").Cell>} */
25
21
  this.cells = []
26
22
 
27
23
  /**
@@ -33,10 +29,9 @@ export class GeoTIFF extends DatasetComponent {
33
29
  /**
34
30
  * Request data within a geographic envelope.
35
31
  *
36
- * @param {import("../Dataset").Envelope|undefined} e
37
- * @param {function():void} redraw
32
+ * @param {import("../core/GeoCanvas.js").Envelope|undefined} e
38
33
  */
39
- getData(e, redraw) {
34
+ getData(e) {
40
35
  //check if data already loaded
41
36
  if (this.infoLoadingStatus != 'notLoaded') return this
42
37
 
@@ -108,7 +103,7 @@ export class GeoTIFF extends DatasetComponent {
108
103
  /**
109
104
  * Fill the view cache with all cells which are within a geographical envelope.
110
105
  *
111
- * @param {import("../Dataset").Envelope} extGeo
106
+ * @param {import("../core/GeoCanvas.js").Envelope} extGeo
112
107
  * @returns {void}
113
108
  */
114
109
  updateViewCache(extGeo) {
@@ -1,41 +1,40 @@
1
1
  //@ts-check
2
2
  'use strict'
3
3
 
4
- /** @typedef {{ dims: object, crs: string, tileSizeCell: number, originPoint: {x:number,y:number}, resolutionGeo: number, tilingBounds:import("../Dataset.js").Envelope }} GridInfo */
4
+ /** @typedef {{ dims: object, crs: string, tileSizeCell: number, originPoint: {x:number,y:number}, resolutionGeo: number, tilingBounds:import("../core/GeoCanvas.js").Envelope }} GridInfo */
5
5
 
6
- import { DatasetComponent } from '../DatasetComponent.js'
6
+ import { Dataset } from '../core/Dataset.js'
7
7
 
8
8
  /**
9
- * A dataset composed of a single CSV file (not tiled).
9
+ * A dataset composed of cells defined in javascript, or loaded outside of gridviz map.
10
10
  *
11
11
  * @author Joseph Davies, Julien Gaffuri
12
12
  */
13
- export class LGrid extends DatasetComponent {
13
+ export class JSGrid extends Dataset {
14
14
  /**
15
15
  * @param {number} resolution The dataset resolution in geographical unit.
16
16
  * @param {Array.<Object>} cells The cells.
17
17
  */
18
18
  constructor(resolution, cells) {
19
- super("", resolution)
19
+ super(undefined, "", resolution)
20
20
 
21
21
  /**
22
22
  * @private
23
- * @type {Array.<import("../Dataset.js").Cell>} */
23
+ * @type {Array.<import("../core/MultiResolutionDataset.js").Cell>} */
24
24
  this.cells = cells || []
25
25
  }
26
26
 
27
27
  /**
28
28
  * Request data within a geographic envelope.
29
29
  *
30
- * @param {import("../Dataset.js").Envelope|undefined} e
31
- * @param {function():void} redraw
30
+ * @param {import("../core/GeoCanvas.js").Envelope|undefined} e
32
31
  */
33
- getData(e, redraw) { return this }
32
+ getData(e) { return this }
34
33
 
35
34
  /**
36
35
  * Fill the view cache with all cells which are within a geographical envelope.
37
36
  *
38
- * @param {import("../Dataset.js").Envelope} extGeo
37
+ * @param {import("../core/GeoCanvas.js").Envelope} extGeo
39
38
  * @returns {void}
40
39
  */
41
40
  updateViewCache(extGeo) {
@@ -1,13 +1,11 @@
1
1
  //@ts-check
2
2
  'use strict'
3
3
 
4
- /** @typedef {{ dims: object, crs: string, tileSizeCell: number, originPoint: {x:number,y:number}, resolutionGeo: number, tilingBounds:import("../Dataset").Envelope, format:import("../DatasetComponent").Format }} GridInfo */
4
+ /** @typedef {{ dims: object, crs: string, tileSizeCell: number, originPoint: {x:number,y:number}, resolutionGeo: number, tilingBounds:import("../core/GeoCanvas.js").Envelope }} GridInfo */
5
5
 
6
6
  // internal
7
- import { GridTile } from './GridTile.js'
8
- import { App } from '../App.js'
9
- import { DatasetComponent } from '../DatasetComponent.js'
10
- import { monitor, monitorDuration } from '../utils/Utils.js'
7
+ import { Dataset } from '../core/Dataset.js'
8
+ //import { monitor, monitorDuration } from '../utils/Utils.js'
11
9
 
12
10
  // external
13
11
  import { json, csv } from 'd3-fetch'
@@ -17,20 +15,14 @@ import { json, csv } from 'd3-fetch'
17
15
  *
18
16
  * @author Joseph Davies, Julien Gaffuri
19
17
  */
20
- export class TiledGrid extends DatasetComponent {
18
+ export class TiledGrid extends Dataset {
21
19
  /**
20
+ * @param {import("../core/Map.js").Map} map The map.
22
21
  * @param {string} url The URL of the dataset.
23
- * @param {App} app The application.
24
- * @param {{preprocess?:(function(import("../Dataset").Cell):boolean) }} opts
22
+ * @param {{preprocess?:(function(import("../core/Dataset.js").Cell):boolean) }} opts
25
23
  */
26
- constructor(url, app, opts = {}) {
27
- super(url, 0, opts)
28
-
29
- /**
30
- * The app being used.
31
- * @type {App}
32
- */
33
- this.app = app
24
+ constructor(map, url, opts = {}) {
25
+ super(map, url, 0, opts)
34
26
 
35
27
  /**
36
28
  * The grid info object, from the info.json file.
@@ -52,15 +44,15 @@ export class TiledGrid extends DatasetComponent {
52
44
  * */
53
45
  this.cache = {}
54
46
 
47
+ //launch loading
48
+ this.loadInfo()
55
49
  }
56
50
 
57
51
  /**
58
52
  * Load the info.json from the url.
59
- *
60
- * @param {function():void} callback
61
53
  * @returns this
62
54
  */
63
- loadInfo(callback) {
55
+ loadInfo() {
64
56
  if (!this.info && this.infoLoadingStatus === 'notLoaded') {
65
57
  ; (async () => {
66
58
  try {
@@ -68,14 +60,14 @@ export class TiledGrid extends DatasetComponent {
68
60
  this.info = data
69
61
  this.resolution = data.resolutionGeo
70
62
  this.infoLoadingStatus = 'loaded'
71
- if (callback) callback()
63
+ this.map.redraw()
72
64
  } catch (error) {
73
65
  //mark as failed
74
66
  this.infoLoadingStatus = 'failed'
75
67
  }
76
68
  })()
77
- } else if (callback && (this.infoLoadingStatus === 'loaded' || this.infoLoadingStatus === 'failed'))
78
- callback()
69
+ } else if ((this.infoLoadingStatus === 'loaded' || this.infoLoadingStatus === 'failed'))
70
+ this.map.redraw()
79
71
  return this
80
72
  }
81
73
 
@@ -83,12 +75,12 @@ export class TiledGrid extends DatasetComponent {
83
75
  * Compute a tiling envelope from a geographical envelope.
84
76
  * This is the function to use to know which tiles to download for a geographical view.
85
77
  *
86
- * @param {import("../Dataset").Envelope} e
87
- * @returns {import("../Dataset").Envelope|undefined}
78
+ * @param {import("../core/GeoCanvas.js").Envelope} e
79
+ * @returns {import("../core/GeoCanvas.js").Envelope|undefined}
88
80
  */
89
81
  getTilingEnvelope(e) {
90
82
  if (!this.info) {
91
- this.loadInfo(() => { })
83
+ this.loadInfo()
92
84
  return
93
85
  }
94
86
 
@@ -107,23 +99,22 @@ export class TiledGrid extends DatasetComponent {
107
99
  /**
108
100
  * Request data within a geographic envelope.
109
101
  *
110
- * @param {import("../Dataset").Envelope} extGeo
111
- * @param {function():void} redrawFun
102
+ * @param {import('../core/GeoCanvas.js').Envelope} extGeo
112
103
  * @returns {this}
113
104
  */
114
- getData(extGeo, redrawFun) {
105
+ getData(extGeo) {
115
106
  //TODO empty cache when it gets too big ?
116
107
 
117
108
  //check if info has been loaded
118
109
  if (!this.info) return this
119
110
 
120
111
  //tiles within the scope
121
- /** @type {import("../Dataset").Envelope|undefined} */
112
+ /** @type {import("../core/GeoCanvas.js").Envelope|undefined} */
122
113
  const tb = this.getTilingEnvelope(extGeo)
123
114
  if (!tb) return this
124
115
 
125
116
  //grid bounds
126
- /** @type {import("../Dataset").Envelope} */
117
+ /** @type {import("../core/GeoCanvas.js").Envelope} */
127
118
  const gb = this.info.tilingBounds
128
119
 
129
120
  for (let xT = Math.max(tb.xMin, gb.xMin); xT <= Math.min(tb.xMax, gb.xMax); xT++) {
@@ -132,7 +123,7 @@ export class TiledGrid extends DatasetComponent {
132
123
  if (!this.cache[xT]) this.cache[xT] = {}
133
124
 
134
125
  //check if tile exists in the cache
135
- /** @type {GridTile} */
126
+ /** @type {object} */
136
127
  let tile = this.cache[xT][yT]
137
128
  if (tile) continue
138
129
 
@@ -140,11 +131,11 @@ export class TiledGrid extends DatasetComponent {
140
131
  this.cache[xT][yT] = "loading";
141
132
  (async () => {
142
133
  //request tile
143
- /** @type {Array.<import("../Dataset").Cell>} */
134
+ /** @type {Array.<import("../core/Dataset.js").Cell>} */
144
135
  let cells
145
136
 
146
137
  try {
147
- /** @type {Array.<import("../Dataset").Cell>} */
138
+ /** @type {Array.<import("../core/Dataset.js").Cell>} */
148
139
  // @ts-ignore
149
140
  const data = await csv(this.url + xT + '/' + yT + '.csv')
150
141
 
@@ -174,23 +165,24 @@ export class TiledGrid extends DatasetComponent {
174
165
  console.error('Tile info inknown')
175
166
  return
176
167
  }
177
- const tile_ = new GridTile(cells, xT, yT, this.info)
168
+ const tile_ = getGridTile(cells, xT, yT, this.info)
178
169
  this.cache[xT][yT] = tile_
179
170
 
180
171
  //if (monitor) monitorDuration('storage')
181
172
 
182
173
  //if no redraw is specified, then leave
183
- if (!redrawFun) return
174
+ this.map.redraw()
184
175
 
185
176
  //check if redraw is really needed, that is if:
186
177
 
187
178
  // 1. the dataset belongs to a layer which is visible at the current zoom level
188
179
  let redraw = false
189
180
  //go through the layers
190
- const zf = this.app.getZoomFactor()
191
- for (const lay of this.app.layers) {
192
- if (!lay.visible) continue
193
- if (lay.getDatasetComponent(zf) != this) continue
181
+ const z = this.map.getZoom()
182
+ for (const lay of this.map.layers) {
183
+ if (lay.visible && !lay.visible(z)) continue
184
+ if (!lay.getDataset) continue
185
+ if (lay.getDataset(z) != this) continue
194
186
  //found one layer. No need to seek more.
195
187
  redraw = true
196
188
  break
@@ -200,7 +192,7 @@ export class TiledGrid extends DatasetComponent {
200
192
  if (!redraw) return
201
193
 
202
194
  // 2. the tile is within the view, that is its geo envelope intersects the viewer geo envelope.
203
- const env = this.app.updateExtentGeo()
195
+ const env = this.map.updateExtentGeo()
204
196
  const envT = tile_.extGeo
205
197
  if (env.xMax <= envT.xMin) return
206
198
  if (env.xMin >= envT.xMax) return
@@ -211,7 +203,7 @@ export class TiledGrid extends DatasetComponent {
211
203
  //if (monitor) monitorDuration('*** TiledGrid parse end')
212
204
 
213
205
  //redraw
214
- redrawFun()
206
+ this.map.redraw()
215
207
  })()
216
208
  }
217
209
  }
@@ -221,7 +213,7 @@ export class TiledGrid extends DatasetComponent {
221
213
  /**
222
214
  * Fill the view cache with all cells which are within a geographical envelope.
223
215
  * @abstract
224
- * @param {import("../Dataset").Envelope} extGeo
216
+ * @param {import("../core/GeoCanvas.js").Envelope} extGeo
225
217
  * @returns {void}
226
218
  */
227
219
  updateViewCache(extGeo) {
@@ -232,19 +224,19 @@ export class TiledGrid extends DatasetComponent {
232
224
  if (!this.info) return
233
225
 
234
226
  //tiles within the scope
235
- /** @type {import("../Dataset").Envelope|undefined} */
227
+ /** @type {import("../core/GeoCanvas.js").Envelope|undefined} */
236
228
  const tb = this.getTilingEnvelope(extGeo)
237
229
  if (!tb) return
238
230
 
239
231
  //grid bounds
240
- /** @type {import("../Dataset").Envelope} */
232
+ /** @type {import("../core/GeoCanvas.js").Envelope} */
241
233
  const gb = this.info.tilingBounds
242
234
 
243
235
  for (let xT = Math.max(tb.xMin, gb.xMin); xT <= Math.min(tb.xMax, gb.xMax); xT++) {
244
236
  if (!this.cache[xT]) continue
245
237
  for (let yT = Math.max(tb.yMin, gb.yMin); yT <= Math.min(tb.yMax, gb.yMax); yT++) {
246
238
  //get tile
247
- /** @type {GridTile} */
239
+ /** @type {object} */
248
240
  const tile = this.cache[xT][yT]
249
241
  if (!tile || typeof tile === 'string') continue
250
242
 
@@ -262,3 +254,34 @@ export class TiledGrid extends DatasetComponent {
262
254
  }
263
255
  }
264
256
  }
257
+
258
+ function getGridTile(cells, xT, yT, gridInfo) {
259
+
260
+ const tile = {}
261
+
262
+ /** @type {Array.<import("../core/Dataset").Cell>} */
263
+ tile.cells = cells
264
+ /** @type {number} */
265
+ tile.x = xT
266
+ /** @type {number} */
267
+ tile.y = yT
268
+
269
+ const r = gridInfo.resolutionGeo
270
+ const s = gridInfo.tileSizeCell
271
+
272
+ /** @type {import("../core/GeoCanvas").Envelope} */
273
+ tile.extGeo = {
274
+ xMin: gridInfo.originPoint.x + r * s * tile.x,
275
+ xMax: gridInfo.originPoint.x + r * s * (tile.x + 1),
276
+ yMin: gridInfo.originPoint.y + r * s * tile.y,
277
+ yMax: gridInfo.originPoint.y + r * s * (tile.y + 1),
278
+ }
279
+
280
+ //convert cell coordinates into geographical coordinates
281
+ for (let cell of tile.cells) {
282
+ cell.x = tile.extGeo.xMin + cell.x * r
283
+ cell.y = tile.extGeo.yMin + cell.y * r
284
+ }
285
+
286
+ return tile
287
+ }