gridviz 3.0.35 → 3.0.37
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 +21056 -17487
- package/dist/gridviz.min.js +2 -2
- package/package.json +74 -74
- 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 +232 -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 +650 -568
- 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 +311 -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 +311 -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 +114 -118
- package/src/utils/WebGLSquareColoringAdvanced.js +223 -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 +178 -73
- package/src/utils/zoomUtils.js +142 -142
|
@@ -1,295 +1,312 @@
|
|
|
1
|
-
//@ts-check
|
|
2
|
-
'use strict'
|
|
3
|
-
|
|
4
|
-
import { Style } from '../core/Style.js'
|
|
5
|
-
import {
|
|
6
|
-
import { color } from 'd3-color'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, gl
|
|
172
|
-
gl.bufferData(gl.ARRAY_BUFFER,
|
|
173
|
-
|
|
174
|
-
gl.
|
|
175
|
-
gl
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
this.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
//
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
//
|
|
228
|
-
|
|
229
|
-
//
|
|
230
|
-
//
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
1
|
+
//@ts-check
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
import { Style } from '../core/Style.js'
|
|
5
|
+
import { getSharedWebGLCanvas, getProgram, getBuffer, bufferOwner } from '../utils/webGLUtils.js'
|
|
6
|
+
import { color } from 'd3-color'
|
|
7
|
+
|
|
8
|
+
const VERTEX_SHADER = `
|
|
9
|
+
attribute vec2 pos;
|
|
10
|
+
uniform float sizePix;
|
|
11
|
+
uniform mat3 mat;
|
|
12
|
+
attribute float i;
|
|
13
|
+
varying float vi;
|
|
14
|
+
void main() {
|
|
15
|
+
gl_Position = vec4(mat * vec3(pos, 1.0), 1.0);
|
|
16
|
+
gl_PointSize = sizePix;
|
|
17
|
+
vi = i;
|
|
18
|
+
}`
|
|
19
|
+
|
|
20
|
+
const FRAGMENT_SHADER = `
|
|
21
|
+
precision highp float;
|
|
22
|
+
varying float vi;
|
|
23
|
+
uniform sampler2D colorLUT;
|
|
24
|
+
uniform float lutSize;
|
|
25
|
+
void main(void) {
|
|
26
|
+
float idx = floor(vi + 0.5);
|
|
27
|
+
float u = (idx + 0.5) / lutSize;
|
|
28
|
+
gl_FragColor = texture2D(colorLUT, vec2(u, 0.5));
|
|
29
|
+
}`
|
|
30
|
+
|
|
31
|
+
// names of the buffers this style fills in the shared context (getBuffer)
|
|
32
|
+
const POSITION_BUFFER = 'SquareColorCategoryWebGLStyle.pos'
|
|
33
|
+
const INDEX_BUFFER = 'SquareColorCategoryWebGLStyle.i'
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Style based on webGL
|
|
37
|
+
* To show cells as colored squares, from categories.
|
|
38
|
+
* All cells are drawn as squares, with the same size
|
|
39
|
+
*
|
|
40
|
+
* @module style
|
|
41
|
+
* @author Julien Gaffuri
|
|
42
|
+
*/
|
|
43
|
+
export class SquareColorCategoryWebGLStyle extends Style {
|
|
44
|
+
/** @param {object} opts */
|
|
45
|
+
constructor(opts) {
|
|
46
|
+
super(opts)
|
|
47
|
+
opts = opts || {}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A function returning the category code of the cell, for coloring.
|
|
51
|
+
* @type {function(import('../core/Dataset.js').Cell, number, number, viewScale):string} */
|
|
52
|
+
this.code = opts.code // (c, resolution, z, viewScale) => "code1"
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The dictionary (code -> color) which gives the color of each category code.
|
|
56
|
+
* @type {object} */
|
|
57
|
+
opts.color = opts.color || undefined
|
|
58
|
+
|
|
59
|
+
/** @type { Array.<string> } */
|
|
60
|
+
const codes = Object.keys(opts.color)
|
|
61
|
+
|
|
62
|
+
/** @type { object } @private */
|
|
63
|
+
this.catToI = {}
|
|
64
|
+
for (let i = 0; i < codes.length; i++) this.catToI[codes[i]] = i + ''
|
|
65
|
+
|
|
66
|
+
/** @type { Array.<string> } @private */
|
|
67
|
+
this.colors = []
|
|
68
|
+
for (const code of codes) this.colors.push(opts.color['' + code])
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A function returning the size of the cells, in geographical unit. All cells have the same size.
|
|
72
|
+
* @type {function(number,number):number} */
|
|
73
|
+
this.size = opts.size // (resolution, z) => ...
|
|
74
|
+
|
|
75
|
+
/** The shared WebGL canvas this style last drew into (getSharedWebGLCanvas)
|
|
76
|
+
* @type {{canvas:HTMLCanvasElement, gl:WebGLRenderingContext, width:number, height:number }}*/
|
|
77
|
+
this.cvWGL = undefined
|
|
78
|
+
/** @type {WebGLRenderingContext|undefined} */
|
|
79
|
+
this.gl = undefined
|
|
80
|
+
this.program = undefined
|
|
81
|
+
this.lutTexture = undefined
|
|
82
|
+
/** Number of points in the shared buffers, for drawArrays */
|
|
83
|
+
this.pointsNb = 0
|
|
84
|
+
|
|
85
|
+
this.x = undefined
|
|
86
|
+
this.y = undefined
|
|
87
|
+
this.z = undefined
|
|
88
|
+
this.cellsNb = undefined
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Binds this style's program, colour lookup texture and uniforms in the shared WebGL
|
|
93
|
+
* context (getSharedWebGLCanvas): compiled once per context, so a new style instance
|
|
94
|
+
* (e.g. a setting change rebuilding the style) costs no new context or program.
|
|
95
|
+
* @returns {boolean} true when the context is new to this style (its data must be re-uploaded)
|
|
96
|
+
*/
|
|
97
|
+
init(w, h) {
|
|
98
|
+
this.cvWGL = getSharedWebGLCanvas(w, h)
|
|
99
|
+
const gl = this.cvWGL.gl
|
|
100
|
+
const contextChanged = this.gl !== gl
|
|
101
|
+
if (contextChanged) {
|
|
102
|
+
this.gl = gl
|
|
103
|
+
this.program = getProgram(gl, VERTEX_SHADER, FRAGMENT_SHADER)
|
|
104
|
+
this.lutTexture = undefined
|
|
105
|
+
}
|
|
106
|
+
gl.useProgram(this.program)
|
|
107
|
+
this.bindColors()
|
|
108
|
+
return contextChanged
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
bindColors() {
|
|
112
|
+
const gl = this.cvWGL.gl
|
|
113
|
+
const lutSize = this.colors.length
|
|
114
|
+
|
|
115
|
+
// created once per style and context
|
|
116
|
+
if (!this.lutTexture) {
|
|
117
|
+
const lutData = new Uint8Array(lutSize * 4) // RGBA for each entry
|
|
118
|
+
for (let i = 0; i < lutSize; i++) {
|
|
119
|
+
const c = color(this.colors[i])
|
|
120
|
+
lutData[i * 4] = +c.r
|
|
121
|
+
lutData[i * 4 + 1] = c.g
|
|
122
|
+
lutData[i * 4 + 2] = c.b
|
|
123
|
+
lutData[i * 4 + 3] = c?.opacity * 255
|
|
124
|
+
}
|
|
125
|
+
this.lutTexture = gl.createTexture()
|
|
126
|
+
gl.bindTexture(gl.TEXTURE_2D, this.lutTexture)
|
|
127
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, lutSize, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, lutData)
|
|
128
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
|
|
129
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
|
|
130
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
|
|
131
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
gl.uniform1i(gl.getUniformLocation(this.program, 'colorLUT'), 0) // Texture unit 0
|
|
135
|
+
gl.uniform1f(gl.getUniformLocation(this.program, 'lutSize'), lutSize)
|
|
136
|
+
gl.activeTexture(gl.TEXTURE0)
|
|
137
|
+
gl.bindTexture(gl.TEXTURE_2D, this.lutTexture)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Fills the shared position and colour index buffers with the cells to draw.
|
|
142
|
+
* @returns {number} the number of points uploaded (cells without a category are left out)
|
|
143
|
+
*/
|
|
144
|
+
bindVertices(cells, resolution, z, viewScale) {
|
|
145
|
+
const gl = this.cvWGL.gl
|
|
146
|
+
//add vertice and fragment data
|
|
147
|
+
const r2 = resolution / 2
|
|
148
|
+
let c,
|
|
149
|
+
nb = cells.length
|
|
150
|
+
const verticesBuffer = new Float32Array(2 * nb)
|
|
151
|
+
const iBuffer = new Float32Array(nb)
|
|
152
|
+
let n = 0
|
|
153
|
+
for (let i = 0; i < nb; i++) {
|
|
154
|
+
c = cells[i]
|
|
155
|
+
const cat = this.code(c, resolution, z, viewScale)
|
|
156
|
+
if (cat == undefined) {
|
|
157
|
+
//console.log('Unexpected category: ' + cat)
|
|
158
|
+
continue
|
|
159
|
+
}
|
|
160
|
+
const i_ = this.catToI[cat]
|
|
161
|
+
if (isNaN(+i_)) {
|
|
162
|
+
console.log('Unexpected category index: ' + cat + ' ' + i_)
|
|
163
|
+
continue
|
|
164
|
+
}
|
|
165
|
+
verticesBuffer[2 * n] = c.x + r2
|
|
166
|
+
verticesBuffer[2 * n + 1] = c.y + r2
|
|
167
|
+
iBuffer[n] = +i_
|
|
168
|
+
n++
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, getBuffer(gl, POSITION_BUFFER))
|
|
172
|
+
gl.bufferData(gl.ARRAY_BUFFER, verticesBuffer.subarray(0, 2 * n), gl.DYNAMIC_DRAW)
|
|
173
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, getBuffer(gl, INDEX_BUFFER))
|
|
174
|
+
gl.bufferData(gl.ARRAY_BUFFER, iBuffer.subarray(0, n), gl.DYNAMIC_DRAW)
|
|
175
|
+
bufferOwner(gl, POSITION_BUFFER, this)
|
|
176
|
+
return n
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Points the program's attributes at the shared buffers (whatever another style left bound). */
|
|
180
|
+
bindAttributes() {
|
|
181
|
+
const gl = this.cvWGL.gl
|
|
182
|
+
const position = gl.getAttribLocation(this.program, 'pos')
|
|
183
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, getBuffer(gl, POSITION_BUFFER))
|
|
184
|
+
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0)
|
|
185
|
+
gl.enableVertexAttribArray(position)
|
|
186
|
+
const i = gl.getAttribLocation(this.program, 'i')
|
|
187
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, getBuffer(gl, INDEX_BUFFER))
|
|
188
|
+
gl.vertexAttribPointer(i, 1, gl.FLOAT, false, 0, 0)
|
|
189
|
+
gl.enableVertexAttribArray(i)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// check if the vertices have to be bound again
|
|
193
|
+
mapContentChanged(v, cellsNb) {
|
|
194
|
+
if (v.x == this.x && v.y == this.y && v.z == this.z && this.cellsNb == cellsNb) return false
|
|
195
|
+
this.x = v.x
|
|
196
|
+
this.y = v.y
|
|
197
|
+
this.z = v.z
|
|
198
|
+
this.cellsNb = cellsNb
|
|
199
|
+
return true
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* @param {Array.<import("../core/Dataset.js").Cell>} cells
|
|
205
|
+
* @param {import("../core/GeoCanvas.js").GeoCanvas} geoCanvas
|
|
206
|
+
* @param {number} resolution
|
|
207
|
+
*/
|
|
208
|
+
draw(cells, geoCanvas, resolution) {
|
|
209
|
+
//filter
|
|
210
|
+
if (this.filter) cells = cells.filter(this.filter)
|
|
211
|
+
|
|
212
|
+
//
|
|
213
|
+
const z = geoCanvas.view.z
|
|
214
|
+
|
|
215
|
+
//get view scale
|
|
216
|
+
const viewScale = this.viewScale ? this.viewScale(cells, resolution, z) : undefined
|
|
217
|
+
|
|
218
|
+
//bind this style's program in the shared WebGL context
|
|
219
|
+
const contextChanged = this.init(geoCanvas.w, geoCanvas.h)
|
|
220
|
+
const gl = this.cvWGL.gl
|
|
221
|
+
const canvas = this.cvWGL.canvas
|
|
222
|
+
|
|
223
|
+
//bind sizePix
|
|
224
|
+
const sizePix = this.size ? this.size(resolution, z) / z : resolution / z + 0.2
|
|
225
|
+
gl.uniform1f(gl.getUniformLocation(this.program, 'sizePix'), 1.0 * sizePix)
|
|
226
|
+
|
|
227
|
+
// mapContentChanged() is a cheap proxy for "did the content change", based on view
|
|
228
|
+
// x/y/z and cell count alone. The upload is also needed when the shared buffers
|
|
229
|
+
// hold another style's data (bufferOwner), or the context is new to this style
|
|
230
|
+
// (e.g. replaced after being lost).
|
|
231
|
+
const contentChanged = this.mapContentChanged(geoCanvas.view, cells.length)
|
|
232
|
+
if (contentChanged || contextChanged || bufferOwner(gl, POSITION_BUFFER) !== this)
|
|
233
|
+
this.pointsNb = this.bindVertices(cells, resolution, z, viewScale)
|
|
234
|
+
this.bindAttributes()
|
|
235
|
+
|
|
236
|
+
//transformation
|
|
237
|
+
gl.uniformMatrix3fv(
|
|
238
|
+
gl.getUniformLocation(this.program, 'mat'),
|
|
239
|
+
false,
|
|
240
|
+
new Float32Array(geoCanvas.getWebGLTransform())
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
// Clear the color buffer bit
|
|
244
|
+
gl.clearColor(0, 0, 0, 0)
|
|
245
|
+
gl.clear(gl.COLOR_BUFFER_BIT)
|
|
246
|
+
|
|
247
|
+
// only the points actually uploaded: cells without a category are left out, and
|
|
248
|
+
// drawing past the end of the buffer is a WebGL error that draws nothing at all
|
|
249
|
+
gl.drawArrays(gl.POINTS, 0, this.pointsNb)
|
|
250
|
+
|
|
251
|
+
//draw in canvas geo
|
|
252
|
+
geoCanvas.initCanvasTransform()
|
|
253
|
+
geoCanvas.offscreenCtx.drawImage(canvas, 0, 0)
|
|
254
|
+
|
|
255
|
+
//update legends
|
|
256
|
+
this.updateLegends({ style: this, resolution: resolution, z: z, viewScale: viewScale })
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
// early tests for webgl2 migration
|
|
263
|
+
|
|
264
|
+
/*
|
|
265
|
+
function getVectorShader2() {
|
|
266
|
+
return `
|
|
267
|
+
#version 300 es
|
|
268
|
+
precision highp float;
|
|
269
|
+
|
|
270
|
+
in vec2 pos;
|
|
271
|
+
in int i;
|
|
272
|
+
|
|
273
|
+
uniform float sizePix;
|
|
274
|
+
uniform mat3 mat;
|
|
275
|
+
|
|
276
|
+
flat out int vi;
|
|
277
|
+
|
|
278
|
+
void main() {
|
|
279
|
+
gl_Position = vec4(mat * vec3(pos, 1.0), 1.0);
|
|
280
|
+
gl_PointSize = sizePix;
|
|
281
|
+
vi = i;
|
|
282
|
+
}
|
|
283
|
+
`
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
function getFragmentShader2(colors) {
|
|
288
|
+
|
|
289
|
+
//prepare fragment shader code
|
|
290
|
+
//declare the uniform and other variables
|
|
291
|
+
const out = []
|
|
292
|
+
out.push('#version 300 es\nprecision highp float;\nflat in int vi;\n')
|
|
293
|
+
|
|
294
|
+
//add color uniforms
|
|
295
|
+
//uniform vec4 colors[12];
|
|
296
|
+
out.push('uniform vec4 colors[')
|
|
297
|
+
out.push(colors.length)
|
|
298
|
+
out.push('];\n')
|
|
299
|
+
|
|
300
|
+
out.push('out vec4 fragColor;\n')
|
|
301
|
+
|
|
302
|
+
//start the main function
|
|
303
|
+
//void main() { fragColor = colors[clamp(vi, 0, 11)]; }
|
|
304
|
+
out.push('void main() { fragColor = colors[vi]; }\n')
|
|
305
|
+
|
|
306
|
+
/** Fragment shader program
|
|
307
|
+
const fshString = out.join('')
|
|
308
|
+
console.log(fshString)
|
|
309
|
+
return fshString
|
|
310
|
+
}
|
|
311
|
+
|
|
295
312
|
*/
|