gridviz 3.0.21 → 3.0.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gridviz",
3
- "version": "3.0.21",
3
+ "version": "3.0.23",
4
4
  "description": "Visualization tool for gridded statistics",
5
5
  "keywords": [
6
6
  "statistics",
@@ -20,7 +20,8 @@ export class BackgroundLayer extends Layer {
20
20
  super(opts)
21
21
  opts = opts || {}
22
22
 
23
- /** The image cache, indexed by z/y/x */
23
+ /** The image cache, indexed by z/y/x
24
+ * @private */
24
25
  this.cache = {}
25
26
 
26
27
  /**
@@ -29,18 +30,31 @@ export class BackgroundLayer extends Layer {
29
30
  /** @type {function(number,number,number):string} */
30
31
  this.urlFun = opts.urlFun || ((x, y, z) => this.url + z + '/' + x + '/' + y + '.png')
31
32
 
32
- /** @type {Array.<number>} */
33
+ /** The ground resolutions of the zoom levels, starting from the smallest (most zoomed-out, usually 0) to the largest (most zoomed-in).
34
+ * Usually divided by 2 for each zoom level increment.
35
+ * @type {Array.<number>} */
33
36
  this.resolutions = opts.resolutions
34
37
  if (!this.resolutions || this.resolutions.length == 0)
35
38
  throw new Error('No resolutions provided for background layer')
36
39
 
37
- /** @type {number} */
40
+ /** The tile size, in number of pixels
41
+ * @type {number} */
38
42
  this.nbPix = opts.nbPix || 256
39
- /** CRS coordinates of top left corner
43
+
44
+ /** CRS coordinates of top left corner of the top left tile, the one with code /0/0.png.
40
45
  * @type {Array.<number>} */
41
46
  this.origin = opts.origin || [0, 0]
42
- /** @type {number} */
47
+
48
+ /** The code of the smallest (most zoomed-out) zoom level, in case it is not 0.
49
+ * @type {number} */
43
50
  this.z0 = opts.z0 || 0
51
+
52
+ /** A coefficient to adjust the backgroun resolution with the screen resolution.
53
+ * If the background images are too pixelised, reduce the value.
54
+ * If there are too many images to download, increase the value.
55
+ * Default value is 1.0
56
+ * @type {number} */
57
+ this.pixelationCoefficient = opts.pixelationCoefficient || 1.0
44
58
  }
45
59
 
46
60
  /**
@@ -60,7 +74,7 @@ export class BackgroundLayer extends Layer {
60
74
  }
61
75
 
62
76
  /**
63
- * Get z/x/y cache data.
77
+ * Put image in cache.
64
78
  * @param {HTMLImageElement|string} img
65
79
  * @param {number} z
66
80
  * @param {number} x
@@ -86,18 +100,15 @@ export class BackgroundLayer extends Layer {
86
100
 
87
101
  //
88
102
  const z = geoCanvas.view.z
89
- const x0 = this.origin[0],
90
- y0 = this.origin[1]
103
+ const x0 = this.origin[0], y0 = this.origin[1]
91
104
 
92
105
  //get zoom level and resolution
93
106
  let z_ = 0
94
- for (z_ = 0; z_ < this.resolutions.length; z_++) if (this.resolutions[z_] < z) break
107
+ for (z_ = 0; z_ < this.resolutions.length; z_++) if (this.resolutions[z_] < z * this.pixelationCoefficient) break
95
108
  z_ -= 1
96
109
  z_ = Math.max(0, z_)
97
110
  z_ = Math.min(z_, this.resolutions.length - 1)
98
- //console.log(this.resolutions.length, z)
99
111
  const res = this.resolutions[z_]
100
-
101
112
  z_ += this.z0
102
113
 
103
114
  const sizeG = this.nbPix * res
@@ -117,7 +128,7 @@ export class BackgroundLayer extends Layer {
117
128
  //get image
118
129
  let img = this.get(z_, x, y)
119
130
 
120
- //load image
131
+ //no image: load image from URL
121
132
  if (!img) {
122
133
  const img = new Image()
123
134
  this.put(img, z_, x, y)
@@ -132,7 +143,7 @@ export class BackgroundLayer extends Layer {
132
143
  continue
133
144
  }
134
145
 
135
- //case when no image
146
+ //case when no image available
136
147
  if (img === 'failed') continue
137
148
  if (!(img instanceof HTMLImageElement)) {
138
149
  console.log(img)
@@ -80,7 +80,7 @@ export class ColorDiscreteLegend extends Legend {
80
80
  for (let i = 1; i < nb; i++) {
81
81
  let label = breaks[i - 1]
82
82
  if (isNaN(label) || label == undefined) continue
83
- if (this.labelFormat) label = this.labelFormat(label)
83
+ if (this.labelFormat) label = this.labelFormat(label, i)
84
84
 
85
85
  //label
86
86
  svg.append('text')