gridviz 3.0.34 → 3.0.36
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 +129 -129
- package/dist/gridviz.js +17487 -17471
- package/dist/gridviz.min.js +2 -2
- package/package.json +73 -73
- package/src/button/Button.js +67 -67
- package/src/button/FullscreenButton.js +121 -121
- package/src/button/ZoomButtons.js +103 -103
- package/src/core/Dataset.js +154 -154
- package/src/core/Drawable.js +78 -78
- package/src/core/GeoCanvas.js +443 -443
- package/src/core/Layer.js +23 -23
- package/src/core/Legend.js +108 -108
- package/src/core/Map.js +568 -552
- package/src/core/MultiResolutionDataset.js +93 -93
- package/src/core/Style.js +98 -98
- package/src/core/Tooltip.js +182 -182
- package/src/dataset/COGeo.js +25 -25
- package/src/dataset/CSVGrid.js +112 -112
- package/src/dataset/GeoTIFF.js +122 -122
- package/src/dataset/JSGrid.js +55 -55
- package/src/dataset/TiledGrid.js +302 -302
- package/src/dataset/worker.js +18 -18
- package/src/index.js +79 -79
- package/src/layer/BackgroundLayer.js +173 -173
- package/src/layer/BackgroundLayerImage.js +81 -81
- package/src/layer/BackgroundLayerWMS.js +104 -104
- package/src/layer/GeoJSONLayer.js +276 -276
- package/src/layer/GridLayer.js +166 -166
- package/src/layer/LabelLayer.js +194 -194
- package/src/legend/ColorCategoryLegend.js +109 -109
- package/src/legend/ColorDiscreteLegend.js +100 -100
- package/src/legend/ColorLegend.js +115 -115
- package/src/legend/OrientationLegend.js +89 -89
- package/src/legend/SizeLegend.js +224 -224
- package/src/legend/TernaryLegend.js +302 -302
- package/src/style/CompositionStyle.js +291 -291
- package/src/style/DotDensityStyle.js +133 -133
- package/src/style/ImageStyle.js +100 -100
- package/src/style/Interpolator.js +258 -258
- package/src/style/IsoFenceStyle.js +217 -217
- package/src/style/JoyPlotStyle.js +180 -180
- package/src/style/LegoStyle.js +132 -132
- package/src/style/MosaicStyle.js +99 -99
- package/src/style/NinjaStarStyle.js +102 -102
- package/src/style/PillarStyle.js +207 -207
- package/src/style/SegmentStyle.js +105 -105
- package/src/style/ShadingRayStyle.js +280 -280
- package/src/style/ShadingStyle.js +72 -72
- package/src/style/ShapeColorSizeStyle.js +147 -147
- package/src/style/SideCategoryStyle.js +112 -112
- package/src/style/SideStyle.js +217 -217
- package/src/style/SideTanakaStyle.js +154 -154
- package/src/style/SquareColorCategoryWebGLStyle.js +307 -294
- package/src/style/SquareColorWebGLStyle.js +126 -126
- package/src/style/StrokeStyle.js +135 -135
- package/src/style/TextStyle.js +110 -110
- package/src/style/TimeSeriesStyle.js +222 -222
- package/src/utils/WebGLRectangleColoring.js +106 -106
- package/src/utils/WebGLSquareColoring.js +118 -118
- package/src/utils/WebGLSquareColoringAdvanced.js +227 -227
- package/src/utils/WebGLSquareColoringKS.js +153 -153
- package/src/utils/scale.js +255 -255
- package/src/utils/stretching.js +120 -120
- package/src/utils/ternary.js +208 -208
- package/src/utils/utils.js +125 -125
- package/src/utils/webGLUtils.js +73 -73
- package/src/utils/zoomUtils.js +142 -142
package/src/utils/utils.js
CHANGED
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
//@ts-check
|
|
2
|
-
'use strict'
|
|
3
|
-
|
|
4
|
-
import { min, max, extent } from 'd3-array'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Get the class id from a value and class break values
|
|
8
|
-
*
|
|
9
|
-
* @param {number} v the value
|
|
10
|
-
* @param {Array.<number>} breaks the breaks
|
|
11
|
-
* @returns The class id, from 0 to breaks.length
|
|
12
|
-
* @deprecated use getClassifier instead.
|
|
13
|
-
*/
|
|
14
|
-
export function getClass(v, breaks) {
|
|
15
|
-
if (!breaks) return
|
|
16
|
-
if (breaks.length == 0) return 0
|
|
17
|
-
if (v <= breaks[0]) return 0
|
|
18
|
-
for (let i = 1; i < breaks.length; i++) if (breaks[i - 1] < v && v <= breaks[i]) return i
|
|
19
|
-
return breaks.length
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
//take 'nice' value (power of ten, or multiple)
|
|
23
|
-
export function nice(v, multiples = [8, 6, 5, 4, 2.5, 2]) {
|
|
24
|
-
//compute bigger power of ten below
|
|
25
|
-
const v_ = Math.pow(10, Math.floor(Math.log10(v)))
|
|
26
|
-
for (let multiple of multiples) if (v_ * multiple <= v) return v_ * multiple
|
|
27
|
-
return v_
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* A grid cell.
|
|
32
|
-
* @typedef {{x: number, y: number}} Cell */
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Index cells by y and x
|
|
36
|
-
* @param {Array.<Cell>} cells
|
|
37
|
-
* @param {Function} [fun]
|
|
38
|
-
* @returns {Object}
|
|
39
|
-
*/
|
|
40
|
-
export function cellsToGrid(cells, fun) {
|
|
41
|
-
/** @type {Object} */
|
|
42
|
-
const ind = {}
|
|
43
|
-
for (const cell of cells) {
|
|
44
|
-
let row = ind[cell.y]
|
|
45
|
-
if (!row) {
|
|
46
|
-
row = {}
|
|
47
|
-
ind[cell.y] = row
|
|
48
|
-
}
|
|
49
|
-
row[cell.x] = fun ? fun(cell) : cell
|
|
50
|
-
}
|
|
51
|
-
return ind
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Cells to grid.
|
|
58
|
-
*
|
|
59
|
-
* @param {Array.<Cell>} cells
|
|
60
|
-
* @param {number} resolution
|
|
61
|
-
* @param {Function} [fun]
|
|
62
|
-
* @returns {Object}
|
|
63
|
-
* Grid[i][j] is the value for line i and column j.
|
|
64
|
-
* Numbered from top to bottom, from left to right.
|
|
65
|
-
* Properties x0 and y0 are the geo coordinates of the lower left corner of the top left cell.
|
|
66
|
-
* Properties minI, maxI, minJ, maxJ are the extent of the grid.
|
|
67
|
-
*/
|
|
68
|
-
export function cellsToMatrix(cells, resolution, fun) {
|
|
69
|
-
|
|
70
|
-
// get cells extent
|
|
71
|
-
const [minx, maxx] = extent(cells, c => c.x)
|
|
72
|
-
const [miny, maxy] = extent(cells, c => c.y)
|
|
73
|
-
|
|
74
|
-
// get grid dimension
|
|
75
|
-
const rows = Math.ceil((maxy - miny) / resolution) + 1
|
|
76
|
-
const cols = Math.ceil((maxx - minx) / resolution) + 1
|
|
77
|
-
|
|
78
|
-
// make empty grid
|
|
79
|
-
const grid = Array.from({ length: rows }, () => new Array(cols).fill(undefined));
|
|
80
|
-
grid.x0 = minx
|
|
81
|
-
grid.y0 = maxy
|
|
82
|
-
grid.resolution = resolution
|
|
83
|
-
|
|
84
|
-
for (const c of cells) {
|
|
85
|
-
const i = Math.floor((maxy - c.y) / resolution)
|
|
86
|
-
const j = Math.floor((c.x - minx) / resolution)
|
|
87
|
-
const v = fun ? fun(c) : c
|
|
88
|
-
grid[i][j] = v
|
|
89
|
-
}
|
|
90
|
-
return grid
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
/*
|
|
96
|
-
//no longer used
|
|
97
|
-
export function loadImage(src) {
|
|
98
|
-
return new Promise((resolve, reject) => {
|
|
99
|
-
const img = new Image();
|
|
100
|
-
img.onload = function () { resolve(img); };
|
|
101
|
-
img.onerror = function () { reject(new Error('Error loading image')); };
|
|
102
|
-
img.src = src;
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
/*
|
|
108
|
-
export let monitor = false
|
|
109
|
-
|
|
110
|
-
let previousDate
|
|
111
|
-
export function monitorDuration(message) {
|
|
112
|
-
const nowDate = Date.now()
|
|
113
|
-
|
|
114
|
-
//first call
|
|
115
|
-
if (!previousDate) {
|
|
116
|
-
previousDate = nowDate
|
|
117
|
-
console.log(previousDate, message)
|
|
118
|
-
return
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const d = nowDate - previousDate
|
|
122
|
-
previousDate = nowDate
|
|
123
|
-
console.log(d, message)
|
|
124
|
-
}
|
|
125
|
-
*/
|
|
1
|
+
//@ts-check
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
import { min, max, extent } from 'd3-array'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get the class id from a value and class break values
|
|
8
|
+
*
|
|
9
|
+
* @param {number} v the value
|
|
10
|
+
* @param {Array.<number>} breaks the breaks
|
|
11
|
+
* @returns The class id, from 0 to breaks.length
|
|
12
|
+
* @deprecated use getClassifier instead.
|
|
13
|
+
*/
|
|
14
|
+
export function getClass(v, breaks) {
|
|
15
|
+
if (!breaks) return
|
|
16
|
+
if (breaks.length == 0) return 0
|
|
17
|
+
if (v <= breaks[0]) return 0
|
|
18
|
+
for (let i = 1; i < breaks.length; i++) if (breaks[i - 1] < v && v <= breaks[i]) return i
|
|
19
|
+
return breaks.length
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//take 'nice' value (power of ten, or multiple)
|
|
23
|
+
export function nice(v, multiples = [8, 6, 5, 4, 2.5, 2]) {
|
|
24
|
+
//compute bigger power of ten below
|
|
25
|
+
const v_ = Math.pow(10, Math.floor(Math.log10(v)))
|
|
26
|
+
for (let multiple of multiples) if (v_ * multiple <= v) return v_ * multiple
|
|
27
|
+
return v_
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A grid cell.
|
|
32
|
+
* @typedef {{x: number, y: number}} Cell */
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Index cells by y and x
|
|
36
|
+
* @param {Array.<Cell>} cells
|
|
37
|
+
* @param {Function} [fun]
|
|
38
|
+
* @returns {Object}
|
|
39
|
+
*/
|
|
40
|
+
export function cellsToGrid(cells, fun) {
|
|
41
|
+
/** @type {Object} */
|
|
42
|
+
const ind = {}
|
|
43
|
+
for (const cell of cells) {
|
|
44
|
+
let row = ind[cell.y]
|
|
45
|
+
if (!row) {
|
|
46
|
+
row = {}
|
|
47
|
+
ind[cell.y] = row
|
|
48
|
+
}
|
|
49
|
+
row[cell.x] = fun ? fun(cell) : cell
|
|
50
|
+
}
|
|
51
|
+
return ind
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Cells to grid.
|
|
58
|
+
*
|
|
59
|
+
* @param {Array.<Cell>} cells
|
|
60
|
+
* @param {number} resolution
|
|
61
|
+
* @param {Function} [fun]
|
|
62
|
+
* @returns {Object}
|
|
63
|
+
* Grid[i][j] is the value for line i and column j.
|
|
64
|
+
* Numbered from top to bottom, from left to right.
|
|
65
|
+
* Properties x0 and y0 are the geo coordinates of the lower left corner of the top left cell.
|
|
66
|
+
* Properties minI, maxI, minJ, maxJ are the extent of the grid.
|
|
67
|
+
*/
|
|
68
|
+
export function cellsToMatrix(cells, resolution, fun) {
|
|
69
|
+
|
|
70
|
+
// get cells extent
|
|
71
|
+
const [minx, maxx] = extent(cells, c => c.x)
|
|
72
|
+
const [miny, maxy] = extent(cells, c => c.y)
|
|
73
|
+
|
|
74
|
+
// get grid dimension
|
|
75
|
+
const rows = Math.ceil((maxy - miny) / resolution) + 1
|
|
76
|
+
const cols = Math.ceil((maxx - minx) / resolution) + 1
|
|
77
|
+
|
|
78
|
+
// make empty grid
|
|
79
|
+
const grid = Array.from({ length: rows }, () => new Array(cols).fill(undefined));
|
|
80
|
+
grid.x0 = minx
|
|
81
|
+
grid.y0 = maxy
|
|
82
|
+
grid.resolution = resolution
|
|
83
|
+
|
|
84
|
+
for (const c of cells) {
|
|
85
|
+
const i = Math.floor((maxy - c.y) / resolution)
|
|
86
|
+
const j = Math.floor((c.x - minx) / resolution)
|
|
87
|
+
const v = fun ? fun(c) : c
|
|
88
|
+
grid[i][j] = v
|
|
89
|
+
}
|
|
90
|
+
return grid
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
/*
|
|
96
|
+
//no longer used
|
|
97
|
+
export function loadImage(src) {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
const img = new Image();
|
|
100
|
+
img.onload = function () { resolve(img); };
|
|
101
|
+
img.onerror = function () { reject(new Error('Error loading image')); };
|
|
102
|
+
img.src = src;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
/*
|
|
108
|
+
export let monitor = false
|
|
109
|
+
|
|
110
|
+
let previousDate
|
|
111
|
+
export function monitorDuration(message) {
|
|
112
|
+
const nowDate = Date.now()
|
|
113
|
+
|
|
114
|
+
//first call
|
|
115
|
+
if (!previousDate) {
|
|
116
|
+
previousDate = nowDate
|
|
117
|
+
console.log(previousDate, message)
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const d = nowDate - previousDate
|
|
122
|
+
previousDate = nowDate
|
|
123
|
+
console.log(d, message)
|
|
124
|
+
}
|
|
125
|
+
*/
|
package/src/utils/webGLUtils.js
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
//@ts-check
|
|
2
|
-
'use strict'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {string} width
|
|
6
|
-
* @param {string} height
|
|
7
|
-
* @param {object} opts
|
|
8
|
-
* @returns {{canvas:HTMLCanvasElement, gl:WebGLRenderingContext, width:number, height:number }}
|
|
9
|
-
*/
|
|
10
|
-
export function makeWebGLCanvas(width, height, opts = {}) {
|
|
11
|
-
const canvas = document.createElement('canvas')
|
|
12
|
-
canvas.setAttribute('width', width)
|
|
13
|
-
canvas.setAttribute('height', height)
|
|
14
|
-
const version2 = (opts && +opts.version==2)? "2" : ""
|
|
15
|
-
/** @type {WebGLRenderingContext} */
|
|
16
|
-
const gl = canvas.getContext('webgl' + version2, opts)
|
|
17
|
-
if (!gl) {
|
|
18
|
-
throw new Error('Unable to initialize WebGL'+version2+'. Your browser or machine may not support it.')
|
|
19
|
-
}
|
|
20
|
-
return { canvas: canvas, gl: gl, width: width, height: height }
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Initialize a shader program, so WebGL knows how to draw our data
|
|
25
|
-
*
|
|
26
|
-
* @param {WebGLRenderingContext} gl
|
|
27
|
-
* @param {...WebGLShader} shaders
|
|
28
|
-
* @returns {WebGLProgram}
|
|
29
|
-
*/
|
|
30
|
-
export function initShaderProgram(gl, ...shaders) {
|
|
31
|
-
/** @type {WebGLProgram|null} */
|
|
32
|
-
const program = gl.createProgram()
|
|
33
|
-
if (program == null) throw new Error('Cannot create webGL program')
|
|
34
|
-
for (const shader of shaders) gl.attachShader(program, shader)
|
|
35
|
-
gl.linkProgram(program)
|
|
36
|
-
if (gl.getProgramParameter(program, gl.LINK_STATUS)) return program
|
|
37
|
-
throw new Error(gl.getProgramInfoLog(program) || 'Cannot create webGL program (2)')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Creates a shader of the given type, uploads the source and compiles it.
|
|
42
|
-
*
|
|
43
|
-
* @param {WebGLRenderingContext} gl
|
|
44
|
-
* @param {number} type
|
|
45
|
-
* @param {...string} sources
|
|
46
|
-
* @returns {WebGLShader}
|
|
47
|
-
*/
|
|
48
|
-
export function createShader(gl, type, ...sources) {
|
|
49
|
-
/** @type {WebGLShader|null} */
|
|
50
|
-
const shader = gl.createShader(type)
|
|
51
|
-
if (shader == null) throw new Error('Cannot create webGL shader')
|
|
52
|
-
gl.shaderSource(shader, sources.join('\n'))
|
|
53
|
-
gl.compileShader(shader)
|
|
54
|
-
if (gl.getShaderParameter(shader, gl.COMPILE_STATUS)) return shader
|
|
55
|
-
throw new Error(gl.getShaderInfoLog(shader) || 'Cannot create webGL shader (2)')
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Check if webGL is supported
|
|
60
|
-
*
|
|
61
|
-
* @returns {boolean}
|
|
62
|
-
*/
|
|
63
|
-
export function checkWebGLSupport() {
|
|
64
|
-
try {
|
|
65
|
-
const canvas = document.createElement('canvas')
|
|
66
|
-
return !!(
|
|
67
|
-
!!window.WebGLRenderingContext &&
|
|
68
|
-
(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'))
|
|
69
|
-
)
|
|
70
|
-
} catch (err) {
|
|
71
|
-
return false
|
|
72
|
-
}
|
|
73
|
-
}
|
|
1
|
+
//@ts-check
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} width
|
|
6
|
+
* @param {string} height
|
|
7
|
+
* @param {object} opts
|
|
8
|
+
* @returns {{canvas:HTMLCanvasElement, gl:WebGLRenderingContext, width:number, height:number }}
|
|
9
|
+
*/
|
|
10
|
+
export function makeWebGLCanvas(width, height, opts = {}) {
|
|
11
|
+
const canvas = document.createElement('canvas')
|
|
12
|
+
canvas.setAttribute('width', width)
|
|
13
|
+
canvas.setAttribute('height', height)
|
|
14
|
+
const version2 = (opts && +opts.version==2)? "2" : ""
|
|
15
|
+
/** @type {WebGLRenderingContext} */
|
|
16
|
+
const gl = canvas.getContext('webgl' + version2, opts)
|
|
17
|
+
if (!gl) {
|
|
18
|
+
throw new Error('Unable to initialize WebGL'+version2+'. Your browser or machine may not support it.')
|
|
19
|
+
}
|
|
20
|
+
return { canvas: canvas, gl: gl, width: width, height: height }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Initialize a shader program, so WebGL knows how to draw our data
|
|
25
|
+
*
|
|
26
|
+
* @param {WebGLRenderingContext} gl
|
|
27
|
+
* @param {...WebGLShader} shaders
|
|
28
|
+
* @returns {WebGLProgram}
|
|
29
|
+
*/
|
|
30
|
+
export function initShaderProgram(gl, ...shaders) {
|
|
31
|
+
/** @type {WebGLProgram|null} */
|
|
32
|
+
const program = gl.createProgram()
|
|
33
|
+
if (program == null) throw new Error('Cannot create webGL program')
|
|
34
|
+
for (const shader of shaders) gl.attachShader(program, shader)
|
|
35
|
+
gl.linkProgram(program)
|
|
36
|
+
if (gl.getProgramParameter(program, gl.LINK_STATUS)) return program
|
|
37
|
+
throw new Error(gl.getProgramInfoLog(program) || 'Cannot create webGL program (2)')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates a shader of the given type, uploads the source and compiles it.
|
|
42
|
+
*
|
|
43
|
+
* @param {WebGLRenderingContext} gl
|
|
44
|
+
* @param {number} type
|
|
45
|
+
* @param {...string} sources
|
|
46
|
+
* @returns {WebGLShader}
|
|
47
|
+
*/
|
|
48
|
+
export function createShader(gl, type, ...sources) {
|
|
49
|
+
/** @type {WebGLShader|null} */
|
|
50
|
+
const shader = gl.createShader(type)
|
|
51
|
+
if (shader == null) throw new Error('Cannot create webGL shader')
|
|
52
|
+
gl.shaderSource(shader, sources.join('\n'))
|
|
53
|
+
gl.compileShader(shader)
|
|
54
|
+
if (gl.getShaderParameter(shader, gl.COMPILE_STATUS)) return shader
|
|
55
|
+
throw new Error(gl.getShaderInfoLog(shader) || 'Cannot create webGL shader (2)')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Check if webGL is supported
|
|
60
|
+
*
|
|
61
|
+
* @returns {boolean}
|
|
62
|
+
*/
|
|
63
|
+
export function checkWebGLSupport() {
|
|
64
|
+
try {
|
|
65
|
+
const canvas = document.createElement('canvas')
|
|
66
|
+
return !!(
|
|
67
|
+
!!window.WebGLRenderingContext &&
|
|
68
|
+
(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'))
|
|
69
|
+
)
|
|
70
|
+
} catch (err) {
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
73
|
+
}
|
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} zTarget
|
|
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
|
-
zTarget,
|
|
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 zIni = map.getZoom()
|
|
30
|
-
if (zTarget == zIni) return
|
|
31
|
-
if (zTarget < zIni) factor = 1 / factor
|
|
32
|
-
let z = zIni
|
|
33
|
-
let timer = setInterval(() => {
|
|
34
|
-
//compute new zoom level
|
|
35
|
-
z = map.getZoom() * factor
|
|
36
|
-
if (zTarget > zIni && z > zTarget) z = zTarget
|
|
37
|
-
if (zTarget < zIni && z < zTarget) z = zTarget
|
|
38
|
-
|
|
39
|
-
//set new zoom level
|
|
40
|
-
map.setZoom(z)
|
|
41
|
-
map.redraw()
|
|
42
|
-
|
|
43
|
-
//target reached
|
|
44
|
-
if (z == zTarget) {
|
|
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} zTarget
|
|
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
|
-
zTarget = NaN,
|
|
73
|
-
progressFactorPix = 5,
|
|
74
|
-
delayMs = 0,
|
|
75
|
-
callback = undefined,
|
|
76
|
-
delayBeforeCallBackMs = 0
|
|
77
|
-
) {
|
|
78
|
-
//store initial position/zoom
|
|
79
|
-
const zIni = map.getZoom()
|
|
80
|
-
const cIni = map.getView()
|
|
81
|
-
|
|
82
|
-
//default
|
|
83
|
-
xTarget = isNaN(xTarget) ? cIni.x : xTarget
|
|
84
|
-
yTarget = isNaN(yTarget) ? cIni.y : yTarget
|
|
85
|
-
zTarget = isNaN(zTarget) ? zIni : zTarget
|
|
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 * zIni * dx) / d
|
|
92
|
-
const ddy = (progressFactorPix * zIni * dy) / d
|
|
93
|
-
|
|
94
|
-
//prepare for zoom
|
|
95
|
-
let r = zTarget / zIni
|
|
96
|
-
const n = d / (progressFactorPix * zIni)
|
|
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 = map.getView()
|
|
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
|
-
map.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 z = map.getZoom()
|
|
118
|
-
let nz = zoomFactor * z
|
|
119
|
-
//if went too far, stop at target values
|
|
120
|
-
if (nz < zTarget && zTarget < z) nz = zTarget
|
|
121
|
-
if (z < zTarget && zTarget < nz) nz = zTarget
|
|
122
|
-
map.setZoom(nz)
|
|
123
|
-
if (nz == zTarget) r = 1
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
//redraw
|
|
127
|
-
map.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} zTarget
|
|
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
|
+
zTarget,
|
|
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 zIni = map.getZoom()
|
|
30
|
+
if (zTarget == zIni) return
|
|
31
|
+
if (zTarget < zIni) factor = 1 / factor
|
|
32
|
+
let z = zIni
|
|
33
|
+
let timer = setInterval(() => {
|
|
34
|
+
//compute new zoom level
|
|
35
|
+
z = map.getZoom() * factor
|
|
36
|
+
if (zTarget > zIni && z > zTarget) z = zTarget
|
|
37
|
+
if (zTarget < zIni && z < zTarget) z = zTarget
|
|
38
|
+
|
|
39
|
+
//set new zoom level
|
|
40
|
+
map.setZoom(z)
|
|
41
|
+
map.redraw()
|
|
42
|
+
|
|
43
|
+
//target reached
|
|
44
|
+
if (z == zTarget) {
|
|
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} zTarget
|
|
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
|
+
zTarget = NaN,
|
|
73
|
+
progressFactorPix = 5,
|
|
74
|
+
delayMs = 0,
|
|
75
|
+
callback = undefined,
|
|
76
|
+
delayBeforeCallBackMs = 0
|
|
77
|
+
) {
|
|
78
|
+
//store initial position/zoom
|
|
79
|
+
const zIni = map.getZoom()
|
|
80
|
+
const cIni = map.getView()
|
|
81
|
+
|
|
82
|
+
//default
|
|
83
|
+
xTarget = isNaN(xTarget) ? cIni.x : xTarget
|
|
84
|
+
yTarget = isNaN(yTarget) ? cIni.y : yTarget
|
|
85
|
+
zTarget = isNaN(zTarget) ? zIni : zTarget
|
|
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 * zIni * dx) / d
|
|
92
|
+
const ddy = (progressFactorPix * zIni * dy) / d
|
|
93
|
+
|
|
94
|
+
//prepare for zoom
|
|
95
|
+
let r = zTarget / zIni
|
|
96
|
+
const n = d / (progressFactorPix * zIni)
|
|
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 = map.getView()
|
|
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
|
+
map.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 z = map.getZoom()
|
|
118
|
+
let nz = zoomFactor * z
|
|
119
|
+
//if went too far, stop at target values
|
|
120
|
+
if (nz < zTarget && zTarget < z) nz = zTarget
|
|
121
|
+
if (z < zTarget && zTarget < nz) nz = zTarget
|
|
122
|
+
map.setZoom(nz)
|
|
123
|
+
if (nz == zTarget) r = 1
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//redraw
|
|
127
|
+
map.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
|
+
}
|