gridviz 3.0.5 → 3.0.7

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.5",
3
+ "version": "3.0.7",
4
4
  "description": "Visualization tool for gridded statistics",
5
5
  "keywords": [
6
6
  "statistics",
@@ -42,9 +42,9 @@ export class Legend {
42
42
  /** @type {string} @deprecated */
43
43
  this['font-family'] = opts['font-family'] || 'Helvetica, Arial, sans-serif'
44
44
  /** @type {string} @deprecated */
45
- this.width = opts.width
45
+ //this.width = opts.width
46
46
  /** @type {string} @deprecated */
47
- this.height = opts.height
47
+ //this.height = opts.height
48
48
 
49
49
  //the div element
50
50
  if (this.id) this.div = select('#' + this.id)
@@ -62,9 +62,8 @@ export class Legend {
62
62
  this.div.style('box-shadow', this['box-shadow'])
63
63
  this.div.style('font-family', this['font-family'])
64
64
 
65
- if (this.width) this.div.style('width', this.width)
66
- if (this.height) this.div.style('height', this.height)
67
-
65
+ //if (this.width) this.div.style('width', this.width)
66
+ //if (this.height) this.div.style('height', this.height)
68
67
 
69
68
  //title
70
69
  this.title = opts.title
@@ -93,9 +92,10 @@ export class Legend {
93
92
  * Apply a style to the legend div.
94
93
  * @param {string} k
95
94
  * @param {string} v
96
- * @returns {this}
95
+ * @returns {this|string}
97
96
  */
98
97
  style(k, v) {
98
+ if (arguments.length == 1) return this.div.style(k)
99
99
  this.div.style(k, v)
100
100
  return this
101
101
  }
package/src/index.js CHANGED
@@ -39,6 +39,7 @@ export { ImageStyle } from './style/ImageStyle.js'
39
39
  export { GridLayer } from './layer/GridLayer.js'
40
40
  export { BackgroundLayer } from './layer/BackgroundLayer.js'
41
41
  export { BackgroundLayerWMS } from './layer/BackgroundLayerWMS.js'
42
+ export { BackgroundLayerImage } from './layer/BackgroundLayerImage.js'
42
43
  export { LabelLayer } from './layer/LabelLayer.js'
43
44
  export { GeoJSONLayer } from './layer/GeoJSONLayer.js'
44
45
 
@@ -0,0 +1,84 @@
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Layer } from '../core/Layer.js'
5
+
6
+ /**
7
+ *
8
+ * A map background layer composed of a single image file, geolocated.
9
+ *
10
+ * @module layer
11
+ * @author Julien Gaffuri
12
+ */
13
+ export class BackgroundLayerImage extends Layer {
14
+ /**
15
+ * @param {object} opts
16
+ */
17
+ constructor(opts) {
18
+ super(opts)
19
+ opts = opts || {}
20
+
21
+ /** The image file URL
22
+ * @type {string} */
23
+ this.url = opts.url
24
+
25
+ /** The image left coordinate
26
+ * @type {number} */
27
+ this.xMin = opts.xMin || 0;
28
+ /** The image top coordinate
29
+ * @type {number} */
30
+ this.yMax = opts.yMax || 0;
31
+
32
+ /** The image width, in geo unit
33
+ * @type {number} */
34
+ this.width = opts.width || 20000
35
+ /** The image height, in geo unit
36
+ * @type {number} */
37
+ this.height = opts.height || 20000
38
+
39
+ /** The image object
40
+ * @type {HTMLImageElement|undefined} */
41
+ this.img = undefined;
42
+ }
43
+
44
+ /**
45
+ * @param {import("../core/GeoCanvas.js").GeoCanvas} geoCanvas The canvas where to draw the layer.
46
+ * @returns {void}
47
+ */
48
+ draw(geoCanvas) {
49
+
50
+ //update map extent
51
+ //geoCanvas.updateExtentGeo(0)
52
+
53
+ if (this.img) {
54
+ //the image was already downloaded: draw it
55
+
56
+ //compute screen coordinates and size ratio
57
+ const x = geoCanvas.geoToPixX(this.xMin)
58
+ const y = geoCanvas.geoToPixY(this.yMax)
59
+ const z = geoCanvas.getView().z
60
+
61
+ //draw image
62
+ geoCanvas.initCanvasTransform()
63
+ geoCanvas.ctx.drawImage(this.img, x, y, this.width / z, this.height / z)
64
+
65
+ } else {
66
+ //retrieve image
67
+
68
+ if (!this.img) {
69
+ this.img = new Image()
70
+ this.img.onload = () => {
71
+ geoCanvas.redraw()
72
+ }
73
+ this.img.onerror = () => {
74
+ //case when no image
75
+ console.warn("Could not retrieve background image from", this.url)
76
+ }
77
+ }
78
+
79
+ //set URL to launch the download
80
+ this.img.src = this.url
81
+ }
82
+
83
+ }
84
+ }