gridviz 2.0.40 → 2.0.42
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/README.md +119 -119
- package/dist/gridviz.js +15722 -33305
- package/dist/gridviz.min.js +2 -2
- package/package.json +76 -77
- package/src/App.js +642 -698
- package/src/BackgroundLayer.js +182 -182
- package/src/BackgroundLayerWMS.js +131 -131
- package/src/Dataset.js +76 -76
- package/src/DatasetComponent.js +101 -103
- package/src/GeoCanvas.js +420 -419
- package/src/LabelLayer.js +190 -190
- package/src/Layer.js +92 -92
- package/src/Legend.js +86 -86
- package/src/LineLayer.js +150 -150
- package/src/Style.js +114 -114
- package/src/Tooltip.js +168 -168
- package/src/dataset/COGeo.js +24 -24
- package/src/dataset/CSVGrid.js +104 -104
- package/src/dataset/GeoTIFF.js +127 -127
- package/src/dataset/GridTile.js +41 -41
- package/src/dataset/TiledGrid.js +264 -296
- package/src/index.js +176 -174
- package/src/legend/ColorCategoryLegend.js +124 -124
- package/src/legend/ColorDiscreteLegend.js +103 -105
- package/src/legend/ColorLegend.js +124 -125
- package/src/legend/SegmentOrientationLegend.js +87 -87
- package/src/legend/SegmentWidthLegend.js +97 -97
- package/src/legend/SizeLegend.js +141 -141
- package/src/style/CompositionStyle.js +300 -300
- package/src/style/ContourStyle.js +54 -54
- package/src/style/DotDensityStyle.js +156 -156
- package/src/style/JoyPlotStyle.js +135 -135
- package/src/style/LegoStyle.js +112 -112
- package/src/style/MosaicStyle.js +107 -107
- package/src/style/NinjaStarStyle.js +124 -124
- package/src/style/PillarStyle.js +230 -230
- package/src/style/SegmentStyle.js +142 -142
- package/src/style/ShapeColorSizeStyle.js +126 -126
- package/src/style/SideCatStyle.js +172 -172
- package/src/style/SideStyle.js +218 -218
- package/src/style/SquareColorCatWGLStyle.js +120 -120
- package/src/style/SquareColorWGLStyle.js +146 -146
- package/src/style/StrokeStyle.js +131 -131
- package/src/style/TanakaStyle.js +160 -160
- package/src/style/TextStyle.js +132 -132
- package/src/utils/Utils.js +35 -35
- package/src/utils/WebGLRectangleColoring.js +106 -106
- package/src/utils/WebGLSquareColoring.js +118 -118
- package/src/utils/WebGLSquareColoringAdvanced.js +230 -230
- package/src/utils/WebGLSquareColoringCatAdvanced.js +133 -133
- package/src/utils/WebGLSquareColoringKS.js +153 -153
- package/src/utils/stretching.js +131 -131
- package/src/utils/webGLUtils.js +71 -71
- package/src/utils/zoomUtils.js +142 -142
- package/src/dataset/ParquetGrid.js +0 -122
package/src/utils/zoomUtils.js
CHANGED
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
//@ts-check
|
|
2
|
-
'use strict'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {import("../App").App} app
|
|
7
|
-
* @param {number} zfTarget
|
|
8
|
-
* @param {number} factor
|
|
9
|
-
* @param {number} delayMs
|
|
10
|
-
* @param {function|undefined} callback
|
|
11
|
-
* @param {number} delayBeforeCallBackMs
|
|
12
|
-
* @returns
|
|
13
|
-
*/
|
|
14
|
-
export function zoomTo(
|
|
15
|
-
app,
|
|
16
|
-
zfTarget,
|
|
17
|
-
factor = 1.01,
|
|
18
|
-
delayMs = 0,
|
|
19
|
-
callback = undefined,
|
|
20
|
-
delayBeforeCallBackMs = 0
|
|
21
|
-
) {
|
|
22
|
-
//ensure good factor value: >1
|
|
23
|
-
factor = factor || 1.01
|
|
24
|
-
if (factor < 1) {
|
|
25
|
-
console.error('Unexpected value for factor: ' + factor + '. Set to default value 1.01')
|
|
26
|
-
factor = 1.01
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const zfIni = app.getZoomFactor()
|
|
30
|
-
if (zfTarget == zfIni) return
|
|
31
|
-
if (zfTarget < zfIni) factor = 1 / factor
|
|
32
|
-
let zf = zfIni
|
|
33
|
-
let timer = setInterval(() => {
|
|
34
|
-
//compute new zoom level
|
|
35
|
-
zf = app.getZoomFactor() * factor
|
|
36
|
-
if (zfTarget > zfIni && zf > zfTarget) zf = zfTarget
|
|
37
|
-
if (zfTarget < zfIni && zf < zfTarget) zf = zfTarget
|
|
38
|
-
|
|
39
|
-
//set new zoom level
|
|
40
|
-
app.setZoomFactor(zf)
|
|
41
|
-
app.redraw()
|
|
42
|
-
|
|
43
|
-
//target reached
|
|
44
|
-
if (zf == zfTarget) {
|
|
45
|
-
clearInterval(timer)
|
|
46
|
-
//trigger callback, if any
|
|
47
|
-
if (callback)
|
|
48
|
-
setTimeout(() => {
|
|
49
|
-
callback()
|
|
50
|
-
}, delayBeforeCallBackMs)
|
|
51
|
-
}
|
|
52
|
-
}, delayMs)
|
|
53
|
-
return timer
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
* @param {import("../App").App} app
|
|
59
|
-
* @param {number} xTarget
|
|
60
|
-
* @param {number} yTarget
|
|
61
|
-
* @param {number} zfTarget
|
|
62
|
-
* @param {number} progressFactorPix
|
|
63
|
-
* @param {number} delayMs
|
|
64
|
-
* @param {function|undefined} callback
|
|
65
|
-
* @param {number} delayBeforeCallBackMs
|
|
66
|
-
* @returns
|
|
67
|
-
*/
|
|
68
|
-
export function goToStraight(
|
|
69
|
-
app,
|
|
70
|
-
xTarget = NaN,
|
|
71
|
-
yTarget = NaN,
|
|
72
|
-
zfTarget = NaN,
|
|
73
|
-
progressFactorPix = 5,
|
|
74
|
-
delayMs = 0,
|
|
75
|
-
callback = undefined,
|
|
76
|
-
delayBeforeCallBackMs = 0
|
|
77
|
-
) {
|
|
78
|
-
//store initial position/zoom
|
|
79
|
-
const zfIni = app.getZoomFactor()
|
|
80
|
-
const cIni = app.getGeoCenter()
|
|
81
|
-
|
|
82
|
-
//default
|
|
83
|
-
xTarget = isNaN(xTarget) ? cIni.x : xTarget
|
|
84
|
-
yTarget = isNaN(yTarget) ? cIni.y : yTarget
|
|
85
|
-
zfTarget = isNaN(zfTarget) ? zfIni : zfTarget
|
|
86
|
-
|
|
87
|
-
//prepare for pan
|
|
88
|
-
const dx = xTarget - cIni.x
|
|
89
|
-
const dy = yTarget - cIni.y
|
|
90
|
-
let d = Math.hypot(dx, dy)
|
|
91
|
-
const ddx = (progressFactorPix * zfIni * dx) / d
|
|
92
|
-
const ddy = (progressFactorPix * zfIni * dy) / d
|
|
93
|
-
|
|
94
|
-
//prepare for zoom
|
|
95
|
-
let r = zfTarget / zfIni
|
|
96
|
-
const n = d / (progressFactorPix * zfIni)
|
|
97
|
-
const zoomFactor = d > 0 ? Math.pow(r, 1 / n) : Math.pow(r, 1 / 10) //TODO not 10 ?
|
|
98
|
-
|
|
99
|
-
//timer
|
|
100
|
-
let timer = setInterval(() => {
|
|
101
|
-
//compute and set new position
|
|
102
|
-
if (d > 0) {
|
|
103
|
-
const c = app.getGeoCenter()
|
|
104
|
-
let nx = c.x + ddx
|
|
105
|
-
let ny = c.y + ddy
|
|
106
|
-
//if went too far, stop at target values
|
|
107
|
-
if (nx < xTarget && xTarget < c.x) nx = xTarget
|
|
108
|
-
if (c.x < xTarget && xTarget < nx) nx = xTarget
|
|
109
|
-
if (ny < yTarget && yTarget < c.y) ny = yTarget
|
|
110
|
-
if (c.y < yTarget && yTarget < ny) ny = yTarget
|
|
111
|
-
app.setGeoCenter({ x: nx, y: ny })
|
|
112
|
-
if (nx == xTarget && ny == yTarget) d = 0
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
//compute and set new zoom
|
|
116
|
-
if (r != 1) {
|
|
117
|
-
const zf = app.getZoomFactor()
|
|
118
|
-
let nzf = zoomFactor * zf
|
|
119
|
-
//if went too far, stop at target values
|
|
120
|
-
if (nzf < zfTarget && zfTarget < zf) nzf = zfTarget
|
|
121
|
-
if (zf < zfTarget && zfTarget < nzf) nzf = zfTarget
|
|
122
|
-
app.setZoomFactor(nzf)
|
|
123
|
-
if (nzf == zfTarget) r = 1
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
//redraw
|
|
127
|
-
app.redraw()
|
|
128
|
-
|
|
129
|
-
//if target reached, stop
|
|
130
|
-
if (d == 0 && r == 1) {
|
|
131
|
-
//console.log("OK !")
|
|
132
|
-
clearInterval(timer)
|
|
133
|
-
//trigger callback, if any
|
|
134
|
-
if (callback)
|
|
135
|
-
setTimeout(() => {
|
|
136
|
-
callback()
|
|
137
|
-
}, delayBeforeCallBackMs)
|
|
138
|
-
}
|
|
139
|
-
}, delayMs)
|
|
140
|
-
|
|
141
|
-
return timer
|
|
142
|
-
}
|
|
1
|
+
//@ts-check
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {import("../App").App} app
|
|
7
|
+
* @param {number} zfTarget
|
|
8
|
+
* @param {number} factor
|
|
9
|
+
* @param {number} delayMs
|
|
10
|
+
* @param {function|undefined} callback
|
|
11
|
+
* @param {number} delayBeforeCallBackMs
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export function zoomTo(
|
|
15
|
+
app,
|
|
16
|
+
zfTarget,
|
|
17
|
+
factor = 1.01,
|
|
18
|
+
delayMs = 0,
|
|
19
|
+
callback = undefined,
|
|
20
|
+
delayBeforeCallBackMs = 0
|
|
21
|
+
) {
|
|
22
|
+
//ensure good factor value: >1
|
|
23
|
+
factor = factor || 1.01
|
|
24
|
+
if (factor < 1) {
|
|
25
|
+
console.error('Unexpected value for factor: ' + factor + '. Set to default value 1.01')
|
|
26
|
+
factor = 1.01
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const zfIni = app.getZoomFactor()
|
|
30
|
+
if (zfTarget == zfIni) return
|
|
31
|
+
if (zfTarget < zfIni) factor = 1 / factor
|
|
32
|
+
let zf = zfIni
|
|
33
|
+
let timer = setInterval(() => {
|
|
34
|
+
//compute new zoom level
|
|
35
|
+
zf = app.getZoomFactor() * factor
|
|
36
|
+
if (zfTarget > zfIni && zf > zfTarget) zf = zfTarget
|
|
37
|
+
if (zfTarget < zfIni && zf < zfTarget) zf = zfTarget
|
|
38
|
+
|
|
39
|
+
//set new zoom level
|
|
40
|
+
app.setZoomFactor(zf)
|
|
41
|
+
app.redraw()
|
|
42
|
+
|
|
43
|
+
//target reached
|
|
44
|
+
if (zf == zfTarget) {
|
|
45
|
+
clearInterval(timer)
|
|
46
|
+
//trigger callback, if any
|
|
47
|
+
if (callback)
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
callback()
|
|
50
|
+
}, delayBeforeCallBackMs)
|
|
51
|
+
}
|
|
52
|
+
}, delayMs)
|
|
53
|
+
return timer
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @param {import("../App").App} app
|
|
59
|
+
* @param {number} xTarget
|
|
60
|
+
* @param {number} yTarget
|
|
61
|
+
* @param {number} zfTarget
|
|
62
|
+
* @param {number} progressFactorPix
|
|
63
|
+
* @param {number} delayMs
|
|
64
|
+
* @param {function|undefined} callback
|
|
65
|
+
* @param {number} delayBeforeCallBackMs
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
68
|
+
export function goToStraight(
|
|
69
|
+
app,
|
|
70
|
+
xTarget = NaN,
|
|
71
|
+
yTarget = NaN,
|
|
72
|
+
zfTarget = NaN,
|
|
73
|
+
progressFactorPix = 5,
|
|
74
|
+
delayMs = 0,
|
|
75
|
+
callback = undefined,
|
|
76
|
+
delayBeforeCallBackMs = 0
|
|
77
|
+
) {
|
|
78
|
+
//store initial position/zoom
|
|
79
|
+
const zfIni = app.getZoomFactor()
|
|
80
|
+
const cIni = app.getGeoCenter()
|
|
81
|
+
|
|
82
|
+
//default
|
|
83
|
+
xTarget = isNaN(xTarget) ? cIni.x : xTarget
|
|
84
|
+
yTarget = isNaN(yTarget) ? cIni.y : yTarget
|
|
85
|
+
zfTarget = isNaN(zfTarget) ? zfIni : zfTarget
|
|
86
|
+
|
|
87
|
+
//prepare for pan
|
|
88
|
+
const dx = xTarget - cIni.x
|
|
89
|
+
const dy = yTarget - cIni.y
|
|
90
|
+
let d = Math.hypot(dx, dy)
|
|
91
|
+
const ddx = (progressFactorPix * zfIni * dx) / d
|
|
92
|
+
const ddy = (progressFactorPix * zfIni * dy) / d
|
|
93
|
+
|
|
94
|
+
//prepare for zoom
|
|
95
|
+
let r = zfTarget / zfIni
|
|
96
|
+
const n = d / (progressFactorPix * zfIni)
|
|
97
|
+
const zoomFactor = d > 0 ? Math.pow(r, 1 / n) : Math.pow(r, 1 / 10) //TODO not 10 ?
|
|
98
|
+
|
|
99
|
+
//timer
|
|
100
|
+
let timer = setInterval(() => {
|
|
101
|
+
//compute and set new position
|
|
102
|
+
if (d > 0) {
|
|
103
|
+
const c = app.getGeoCenter()
|
|
104
|
+
let nx = c.x + ddx
|
|
105
|
+
let ny = c.y + ddy
|
|
106
|
+
//if went too far, stop at target values
|
|
107
|
+
if (nx < xTarget && xTarget < c.x) nx = xTarget
|
|
108
|
+
if (c.x < xTarget && xTarget < nx) nx = xTarget
|
|
109
|
+
if (ny < yTarget && yTarget < c.y) ny = yTarget
|
|
110
|
+
if (c.y < yTarget && yTarget < ny) ny = yTarget
|
|
111
|
+
app.setGeoCenter({ x: nx, y: ny })
|
|
112
|
+
if (nx == xTarget && ny == yTarget) d = 0
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//compute and set new zoom
|
|
116
|
+
if (r != 1) {
|
|
117
|
+
const zf = app.getZoomFactor()
|
|
118
|
+
let nzf = zoomFactor * zf
|
|
119
|
+
//if went too far, stop at target values
|
|
120
|
+
if (nzf < zfTarget && zfTarget < zf) nzf = zfTarget
|
|
121
|
+
if (zf < zfTarget && zfTarget < nzf) nzf = zfTarget
|
|
122
|
+
app.setZoomFactor(nzf)
|
|
123
|
+
if (nzf == zfTarget) r = 1
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//redraw
|
|
127
|
+
app.redraw()
|
|
128
|
+
|
|
129
|
+
//if target reached, stop
|
|
130
|
+
if (d == 0 && r == 1) {
|
|
131
|
+
//console.log("OK !")
|
|
132
|
+
clearInterval(timer)
|
|
133
|
+
//trigger callback, if any
|
|
134
|
+
if (callback)
|
|
135
|
+
setTimeout(() => {
|
|
136
|
+
callback()
|
|
137
|
+
}, delayBeforeCallBackMs)
|
|
138
|
+
}
|
|
139
|
+
}, delayMs)
|
|
140
|
+
|
|
141
|
+
return timer
|
|
142
|
+
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
//@ts-check
|
|
2
|
-
'use strict'
|
|
3
|
-
|
|
4
|
-
import { DatasetComponent } from '../DatasetComponent.js'
|
|
5
|
-
import { tableFromIPC } from 'apache-arrow'
|
|
6
|
-
//import { readParquet } from "parquet-wasm"
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A dataset composed of a single parquet file (not tiled).
|
|
10
|
-
*
|
|
11
|
-
* @author Julien Gaffuri
|
|
12
|
-
*/
|
|
13
|
-
export class ParquetGrid 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), readParquetFun?:Function}} opts
|
|
18
|
-
*/
|
|
19
|
-
constructor(url, resolution, opts = {}) {
|
|
20
|
-
super(url, resolution, opts)
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @private
|
|
24
|
-
* @type {Array.<import("../Dataset").Cell>} */
|
|
25
|
-
this.cells = []
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @type {string}
|
|
29
|
-
* @private */
|
|
30
|
-
this.infoLoadingStatus = 'notLoaded'
|
|
31
|
-
|
|
32
|
-
if (!opts.readParquetFun) throw new Error('readParquet function needed for parquet dataset')
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @type {Function}
|
|
36
|
-
* @private */
|
|
37
|
-
this.readParquetFun = opts.readParquetFun
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Request data within a geographic envelope.
|
|
42
|
-
*
|
|
43
|
-
* @param {import("../Dataset").Envelope|undefined} e
|
|
44
|
-
* @param {function():void} redraw
|
|
45
|
-
*/
|
|
46
|
-
getData(e, redraw) {
|
|
47
|
-
//check if data already loaded
|
|
48
|
-
if (this.infoLoadingStatus != 'notLoaded') return this
|
|
49
|
-
|
|
50
|
-
//load data
|
|
51
|
-
this.infoLoadingStatus = 'loading'
|
|
52
|
-
;(async () => {
|
|
53
|
-
try {
|
|
54
|
-
const resp = await fetch(this.url)
|
|
55
|
-
const parquetUint8Array = new Uint8Array(await resp.arrayBuffer())
|
|
56
|
-
const arrowUint8Array = this.readParquetFun(parquetUint8Array)
|
|
57
|
-
|
|
58
|
-
const t = tableFromIPC(arrowUint8Array)
|
|
59
|
-
//see https://arrow.apache.org/docs/js/
|
|
60
|
-
//https://loaders.gl/arrowjs/docs/developer-guide/tables#record-tojson-and-toarray
|
|
61
|
-
|
|
62
|
-
this.cells = []
|
|
63
|
-
for (const e of t) {
|
|
64
|
-
//get cell
|
|
65
|
-
const c = e.toJSON()
|
|
66
|
-
|
|
67
|
-
//preprocess/filter
|
|
68
|
-
if (this.preprocess) {
|
|
69
|
-
const b = this.preprocess(c)
|
|
70
|
-
if (b == false) continue
|
|
71
|
-
this.cells.push(c)
|
|
72
|
-
} else {
|
|
73
|
-
this.cells.push(c)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
//TODO check if redraw is necessary
|
|
78
|
-
//that is if the dataset belongs to a layer which is visible at the current zoom level
|
|
79
|
-
|
|
80
|
-
//execute the callback, usually a draw function
|
|
81
|
-
if (redraw) redraw()
|
|
82
|
-
|
|
83
|
-
this.infoLoadingStatus = 'loaded'
|
|
84
|
-
} catch (error) {
|
|
85
|
-
//mark as failed
|
|
86
|
-
this.infoLoadingStatus = 'failed'
|
|
87
|
-
this.cells = []
|
|
88
|
-
}
|
|
89
|
-
})()
|
|
90
|
-
|
|
91
|
-
return this
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Fill the view cache with all cells which are within a geographical envelope.
|
|
96
|
-
*
|
|
97
|
-
* @param {import("../Dataset").Envelope} extGeo
|
|
98
|
-
* @returns {void}
|
|
99
|
-
*/
|
|
100
|
-
updateViewCache(extGeo) {
|
|
101
|
-
//data not loaded yet
|
|
102
|
-
if (!this.cells) return
|
|
103
|
-
|
|
104
|
-
this.cellsViewCache = []
|
|
105
|
-
for (const cell of this.cells) {
|
|
106
|
-
if (+cell.x + this.resolution < extGeo.xMin) continue
|
|
107
|
-
if (+cell.x - this.resolution > extGeo.xMax) continue
|
|
108
|
-
if (+cell.y + this.resolution < extGeo.yMin) continue
|
|
109
|
-
if (+cell.y - this.resolution > extGeo.yMax) continue
|
|
110
|
-
this.cellsViewCache.push(cell)
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Retrieve parquet wasm decoder
|
|
117
|
-
*/
|
|
118
|
-
const getReadParquet = async () => {
|
|
119
|
-
//const parquetModule = await import("https://unpkg.com/parquet-wasm@0.4.0-beta.5/esm/arrow2.js");
|
|
120
|
-
//await parquetModule.default();
|
|
121
|
-
//return parquetModule.readParquet;
|
|
122
|
-
}
|