gridviz 3.0.6 → 3.0.8

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.6",
3
+ "version": "3.0.8",
4
4
  "description": "Visualization tool for gridded statistics",
5
5
  "keywords": [
6
6
  "statistics",
@@ -107,7 +107,7 @@ export class Dataset {
107
107
  if (this.mixedResolution) {
108
108
  for (const c of cells) {
109
109
  /** @type {number} */
110
- const r = this.mixedResolution(c)
110
+ const r = +this.mixedResolution(c)
111
111
  if (posGeo.x < c.x) continue
112
112
  else if (c.x + r < posGeo.x) continue
113
113
  else if (posGeo.y < c.y) continue
package/src/core/Map.js CHANGED
@@ -304,7 +304,7 @@ export class Map {
304
304
 
305
305
  //rare case for a dataset with mixed resolutions
306
306
  if (dsc.mixedResolution) {
307
- const r = dsc.mixedResolution(cell)
307
+ const r = +dsc.mixedResolution(cell)
308
308
  const html = layer.cellInfoHTML(cell, r)
309
309
  if (!html) return undefined
310
310
  return { cell: cell, html: html, resolution: r }
package/src/index.js CHANGED
@@ -6,6 +6,7 @@ export { Map } from './core/Map.js'
6
6
  export { GeoCanvas } from './core/GeoCanvas.js'
7
7
  export { Style } from './core/Style.js'
8
8
  export { Layer } from './core/Layer.js'
9
+ export { Dataset } from './core/Dataset.js'
9
10
  export { MultiResolutionDataset } from './core/MultiResolutionDataset.js'
10
11
 
11
12
  // export dataset types
@@ -39,6 +40,7 @@ export { ImageStyle } from './style/ImageStyle.js'
39
40
  export { GridLayer } from './layer/GridLayer.js'
40
41
  export { BackgroundLayer } from './layer/BackgroundLayer.js'
41
42
  export { BackgroundLayerWMS } from './layer/BackgroundLayerWMS.js'
43
+ export { BackgroundLayerImage } from './layer/BackgroundLayerImage.js'
42
44
  export { LabelLayer } from './layer/LabelLayer.js'
43
45
  export { GeoJSONLayer } from './layer/GeoJSONLayer.js'
44
46
 
@@ -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
+ }