gridviz 3.0.41 → 3.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gridviz",
3
- "version": "3.0.41",
3
+ "version": "3.1.0",
4
4
  "description": "Visualization tool for gridded statistics",
5
5
  "keywords": [
6
6
  "statistics",
@@ -41,7 +41,7 @@
41
41
  "server": "webpack serve -c webpack.config.dev.cjs",
42
42
  "doc": "jsdoc -c docs/jsdoc/jsdoc.conf.json",
43
43
  "build-prod": "webpack --config webpack.config.prod.cjs",
44
- "test": "jest",
44
+ "test": "node --test \"test/*.test.js\"",
45
45
  "format": "prettier --write ."
46
46
  },
47
47
  "files": [
@@ -1,6 +1,19 @@
1
1
  //@ts-check
2
2
  'use strict'
3
3
 
4
+ /**
5
+ * Tells if an element (a layer or a style) is visible at a zoom level: its visible property is a function of the zoom
6
+ * level, or a boolean; it is visible when not specified. Works for any object, whether it is a Drawable or not.
7
+ *
8
+ * @param {{visible?: (function(number):boolean)|boolean}} element
9
+ * @param {number} z The zoom level.
10
+ * @returns {boolean}
11
+ */
12
+ export function isVisibleAt(element, z) {
13
+ const v = element.visible
14
+ return typeof v === 'function' ? !!v(z) : v !== false
15
+ }
16
+
4
17
  /**
5
18
  * This is an abstract class used to group elements shared between Layer and Style classes.
6
19
  *
@@ -15,9 +28,9 @@ export class Drawable {
15
28
  constructor(opts) {
16
29
  opts = opts || {}
17
30
 
18
- /** A function specifying if the element should be visible or not.
19
- * The function parameter is the zoom level.
20
- * @type {function(number):boolean} */
31
+ /** Specifies if the element should be visible or not: a function of the zoom level, or a boolean
32
+ * (to show or hide the element, then call map.redraw()). Visible when not specified.
33
+ * @type {(function(number):boolean)|boolean|undefined} */
21
34
  this.visible = opts.visible
22
35
 
23
36
  /** A function returning the alpha (transparency/opacity), between 0.0 (fully transparent) and 1.0 (fully opaque).
@@ -38,6 +51,15 @@ export class Drawable {
38
51
  this.filterBlendOperation = opts.filterBlendOperation // (z) => "multiply"
39
52
  }
40
53
 
54
+ /**
55
+ * Tells if the element is visible at a zoom level.
56
+ * @param {number} z The zoom level.
57
+ * @returns {boolean}
58
+ */
59
+ isVisible(z) {
60
+ return isVisibleAt(this, z)
61
+ }
62
+
41
63
  /**
42
64
  * Draw filter.
43
65
  *