@pirireis/webglobeplugins 0.0.1

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.
Files changed (82) hide show
  1. package/arrowfield/adaptor.js +11 -0
  2. package/arrowfield/index.js +4 -0
  3. package/arrowfield/plugin.js +128 -0
  4. package/compassrose/compassrose.js +394 -0
  5. package/compassrose/index.js +2 -0
  6. package/heatwavemaps/index.js +4 -0
  7. package/heatwavemaps/isobar/objectarraylabels.js +247 -0
  8. package/heatwavemaps/isobar/plugin.js +337 -0
  9. package/heatwavemaps/isobar/quadtreecontours.js +338 -0
  10. package/heatwavemaps/plugins/heatwaveglobeshell.js +257 -0
  11. package/index.js +8 -0
  12. package/package.json +7 -0
  13. package/programs/arrowfield/index.js +2 -0
  14. package/programs/arrowfield/logic.js +284 -0
  15. package/programs/arrowfield/object.js +89 -0
  16. package/programs/float2legendwithratio/index.js +3 -0
  17. package/programs/float2legendwithratio/logic.js +189 -0
  18. package/programs/float2legendwithratio/object.js +132 -0
  19. package/programs/globeshell/index.js +2 -0
  20. package/programs/globeshell/noise/noises.js +0 -0
  21. package/programs/globeshell/wiggle/index.js +6 -0
  22. package/programs/globeshell/wiggle/logic.js +374 -0
  23. package/programs/globeshell/wiggle/object.js +94 -0
  24. package/programs/helpers/blender/index.js +0 -0
  25. package/programs/helpers/blender/program.js +91 -0
  26. package/programs/helpers/fadeaway/index.js +3 -0
  27. package/programs/helpers/fadeaway/logic.js +76 -0
  28. package/programs/helpers/fadeaway/object.js +20 -0
  29. package/programs/helpers/index.js +2 -0
  30. package/programs/index.js +21 -0
  31. package/programs/programcache.js +119 -0
  32. package/programs/rings/distancering/circleflatprogram.js +135 -0
  33. package/programs/rings/distancering/circlepaddysharedbuffer.js +502 -0
  34. package/programs/rings/distancering/index.js +5 -0
  35. package/programs/rings/distancering/paddyflatprogram.js +131 -0
  36. package/programs/rings/distancering/shader.js +0 -0
  37. package/programs/rings/index.js +9 -0
  38. package/programs/totems/camerauniformblock.js +129 -0
  39. package/programs/totems/index.js +2 -0
  40. package/programs/util.js +17 -0
  41. package/programs/vectorfields/index.js +3 -0
  42. package/programs/vectorfields/logics/drawrectangleparticles.js +125 -0
  43. package/programs/vectorfields/logics/index.js +5 -0
  44. package/programs/vectorfields/logics/pixelbased.js +161 -0
  45. package/programs/vectorfields/logics/ubo.js +64 -0
  46. package/programs/vectorfields/pingpongbuffermanager.js +80 -0
  47. package/rangerings/index.js +3 -0
  48. package/rangerings/rangerings.js +88 -0
  49. package/timetracks/adaptors.js +133 -0
  50. package/timetracks/index.js +3 -0
  51. package/timetracks/plugin.js +304 -0
  52. package/timetracks/program.js +850 -0
  53. package/timetracks/programpoint.js +168 -0
  54. package/util/datamanager/datamanager.js +168 -0
  55. package/util/datamanager/index.js +3 -0
  56. package/util/datamanager/pointcoordinatesdatacalculator.js +133 -0
  57. package/util/datamanager/pointcoordsmeta.js +22 -0
  58. package/util/geometry/geodatafromtexture.js +52 -0
  59. package/util/geometry/index.js +44 -0
  60. package/util/index.js +13 -0
  61. package/util/jshelpers/index.js +1 -0
  62. package/util/jshelpers/timefilters.js +32 -0
  63. package/util/jshelpers/timemethods.js +19 -0
  64. package/util/programs/index.js +2 -0
  65. package/util/programs/shapesonglobe.js +248 -0
  66. package/util/programs/supersampletotextures.js +142 -0
  67. package/util/programs/texturetoglobe.js +203 -0
  68. package/util/shaderfunctions/geometrytransformations.js +129 -0
  69. package/util/shaderfunctions/index.js +2 -0
  70. package/util/shaderfunctions/nodata.js +10 -0
  71. package/util/shaderfunctions/noisefunctions.js +44 -0
  72. package/util/webglobe/gldefaultstates.js +4 -0
  73. package/util/webglobe/index.js +2 -0
  74. package/util/webglobe/rasteroverlay.js +96 -0
  75. package/util/webglobjectbuilders.js +256 -0
  76. package/waveparticles/adaptor.js +16 -0
  77. package/waveparticles/index.js +4 -0
  78. package/waveparticles/plugin.js +281 -0
  79. package/wind/imagetovectorfieldandmagnitude.js +39 -0
  80. package/wind/index.js +7 -0
  81. package/wind/plugin.js +1032 -0
  82. package/wind/vectorfieldimage.js +27 -0
@@ -0,0 +1,338 @@
1
+ // © 2019 3D Robotics. License: Apache-2.0
2
+ /* eslint no-plusplus: "off", prefer-rest-params: "off" */
3
+ const OUTSIDE = 0;
4
+ const ABOVE = 1;
5
+ const BELOW = 2;
6
+ const WITHIN = 3;
7
+
8
+ // Build mipmap layer N from layer N+1
9
+ function mipmapReduce({ min, max, width, height, scale }) {
10
+ const outWidth = Math.ceil(width / 2);
11
+ const outHeight = Math.ceil(height / 2);
12
+
13
+ function reduceWith(data, reduce) {
14
+ const out = new Float32Array(outWidth * outHeight);
15
+ let x;
16
+ let y;
17
+
18
+ for (y = 0; y < Math.floor(height / 2); y++) {
19
+ for (x = 0; x < Math.floor(width / 2); x++) {
20
+ out[y * outWidth + x] = reduce(
21
+ data[(y * 2 + 0) * width + (x * 2 + 0)], data[(y * 2 + 0) * width + (x * 2 + 1)],
22
+ data[(y * 2 + 1) * width + (x * 2 + 0)], data[(y * 2 + 1) * width + (x * 2 + 1)],
23
+ );
24
+ }
25
+ if (x < outWidth) {
26
+ out[y * outWidth + x] = reduce(
27
+ data[(y * 2 + 0) * width + (x * 2 + 0)],
28
+ data[(y * 2 + 1) * width + (x * 2 + 0)],
29
+ );
30
+ }
31
+ }
32
+ if (y < outHeight) {
33
+ for (x = 0; x < Math.floor(width / 2); x++) {
34
+ out[y * outWidth + x] = reduce(
35
+ data[(y * 2 + 0) * width + (x * 2 + 0)], data[(y * 2 + 0) * width + (x * 2 + 1)],
36
+ );
37
+ }
38
+ }
39
+ if (x < outWidth && y < outHeight) {
40
+ out[y * outWidth + x] = reduce(data[(y * 2 + 0) * width + (x * 2 + 0)]);
41
+ }
42
+ return out;
43
+ }
44
+
45
+ function minFinite() {
46
+ let r = Infinity;
47
+ for (let i = 0; i < arguments.length; i++) { // significantly faster than the code Babel generates for ...args
48
+ const v = arguments[i];
49
+ if (v < r) r = v;
50
+ }
51
+ return r;
52
+ }
53
+
54
+ function maxFinite() {
55
+ let r = -Infinity;
56
+ for (let i = 0; i < arguments.length; i++) {
57
+ const v = arguments[i];
58
+ if (v > r) r = v;
59
+ }
60
+ return r;
61
+ }
62
+
63
+ return {
64
+ min: reduceWith(min, minFinite),
65
+ max: reduceWith(max, maxFinite),
66
+ width: outWidth,
67
+ height: outHeight,
68
+ scale: scale * 2,
69
+ };
70
+ }
71
+
72
+ class ContourMipmap {
73
+ constructor(raster, width, height) {
74
+ // Bottom mipmap layer is just the raster: at each pixel the minimum and maximum are the same
75
+ this.levels = [{ min: raster, max: raster, width, height, scale: 1 }];
76
+
77
+ while (this.levels[0].width > 1 || this.levels[0].height > 1) {
78
+ this.levels.unshift(mipmapReduce(this.levels[0]));
79
+ }
80
+ }
81
+
82
+ // Get the minimum elevation in the mipmap
83
+ min() { return this.levels[0].min[0] }
84
+
85
+ // Get the maximum elevation in the mipmap
86
+ max() { return this.levels[0].max[0] }
87
+
88
+ // Get an array of contour levels for a specified contour interval
89
+ intervals(interval) {
90
+ if (interval <= 0) throw new Error('Contour interval must be positive');
91
+
92
+ const min = this.min();
93
+ const max = this.max();
94
+
95
+ const levels = [];
96
+ let level = Math.ceil(min / interval) * interval;
97
+ while (level < max) {
98
+ levels.push(level);
99
+ level += interval;
100
+ }
101
+ return levels;
102
+ }
103
+
104
+ // Walk the quadtree for a specified contour level, and pass quadtree nodes
105
+ // and contour line segments to the callbacks. This is used for visualizing
106
+ // the quadtree; in most cases you should use .contour() instead, which
107
+ // assembles the line segments into lines and rings.
108
+ evaluateContour(contourLevel, { maxMipmapLevel }, addLine, addNode) {
109
+ maxMipmapLevel = maxMipmapLevel || this.levels.length - 1;
110
+ // Test the mipmap at the given coordinate and level, returning whether the contour line is ABOVE, BELOW, or WITHIN this mipmap cell
111
+ // If the mipmap is out of bounds or NaN at that point, OUTSIDE is returned.
112
+ const evaluate = (l, x, y) => {
113
+ const ml = this.levels[l];
114
+ const i = ml.width * y + x;
115
+ if (x >= ml.width || y >= ml.height || !Number.isFinite(ml.min[i]) || !Number.isFinite(ml.max[i])) return OUTSIDE;
116
+ if (ml.min[i] >= contourLevel) return ABOVE;
117
+ if (ml.max[i] < contourLevel) return BELOW;
118
+
119
+ // If we've reached the maximum mipmap level, arbitrarily decide that cells that contain
120
+ // the contour elevation go inside the contour line.
121
+ if (l >= maxMipmapLevel) return ABOVE;
122
+
123
+ return WITHIN;
124
+ }
125
+
126
+ // Add any vertical contour lines that exist between passed mipmap cell and
127
+ // its horizontal neighbor to the right. If the line exists at this mipmap
128
+ // level, it is added directly, otherwise split the edge and recurse at a
129
+ // more detailed mipmap level.
130
+ function edgeH(l, x, y) {
131
+ const e1 = evaluate(l, x, y);
132
+ const e2 = evaluate(l, x + 1, y);
133
+
134
+ if (e1 === ABOVE && e2 === BELOW) {
135
+ addLine(l, x + 1, y + 1, x + 1, y);
136
+ } else if (e2 === ABOVE && e1 === BELOW) {
137
+ // reverse order of coordinates compared to case above so that lines
138
+ // go counterclockwise around the region above the contour value
139
+ addLine(l, x + 1, y, x + 1, y + 1);
140
+ } else if (e1 === WITHIN || e2 === WITHIN) {
141
+ edgeH(l + 1, x * 2 + 1, y * 2 + 0);
142
+ edgeH(l + 1, x * 2 + 1, y * 2 + 1);
143
+ }
144
+ }
145
+
146
+ // Like edgeH, but for horizontal contour lines between the passed cell
147
+ // and its vertical neighbor below.
148
+ function edgeV(l, x, y) {
149
+ const e1 = evaluate(l, x, y);
150
+ const e2 = evaluate(l, x, y + 1);
151
+
152
+ if (e1 === ABOVE && e2 === BELOW) {
153
+ addLine(l, x, y + 1, x + 1, y + 1);
154
+ } else if (e2 === ABOVE && e1 === BELOW) {
155
+ addLine(l, x + 1, y + 1, x, y + 1);
156
+ } else if (e1 === WITHIN || e2 === WITHIN) {
157
+ edgeV(l + 1, x * 2 + 0, y * 2 + 1);
158
+ edgeV(l + 1, x * 2 + 1, y * 2 + 1);
159
+ }
160
+ }
161
+
162
+ // Add all contour lines within a mipmap cell.
163
+ // It recurses into the four quadrants of the cell, and also uses edgeH and
164
+ // edgeV to add the contour lines that exist between quadrants.
165
+ function node(l, x, y) {
166
+ let e = evaluate(l, x, y);
167
+ if (e === WITHIN) {
168
+ node(l + 1, x * 2 + 0, y * 2 + 0);
169
+ node(l + 1, x * 2 + 1, y * 2 + 0);
170
+ node(l + 1, x * 2 + 0, y * 2 + 1);
171
+ node(l + 1, x * 2 + 1, y * 2 + 1);
172
+ edgeH(l + 1, x * 2 + 0, y * 2 + 0);
173
+ edgeV(l + 1, x * 2 + 0, y * 2 + 0);
174
+ edgeH(l + 1, x * 2 + 0, y * 2 + 1);
175
+ edgeV(l + 1, x * 2 + 1, y * 2 + 0);
176
+ } else {
177
+ if (addNode) addNode(l, x, y, e);
178
+ }
179
+ }
180
+
181
+ node(0, 0, 0);
182
+ }
183
+
184
+ // Generate a contour line for a specified value
185
+ //
186
+ // level: Value in the input array at which to draw a contour line
187
+ // opts: {
188
+ // maxMipmapLevel: Maximum recursion depth in the mipmap. As if you rescaled
189
+ // the input to a maximum dimension of 2^n pixels.
190
+ // (default unlimited)
191
+ // minPoints: Lines and rings with fewer points are removed. (default 0)
192
+ // smoothKernelWidth: Width of the rectangular filter for smoothing (default 2)
193
+ // smoothCycles: Number of iterations of smoothing (default 2)
194
+ // }
195
+ //
196
+ // Returns an array of lines, where each line is an array of [x, y] pairs.
197
+ contour(level, { maxMipmapLevel, smoothKernelWidth = 2, smoothCycles = 2, minPoints = 0 } = {}) {
198
+ // Use the quadtree algorithm to generate line segments that make up the contour
199
+ const segments = [];
200
+ this.evaluateContour(level, { maxMipmapLevel }, (l, x1, y1, x2, y2) => {
201
+ const scale = this.levels[l].scale;
202
+
203
+ const start = [scale * x1, scale * y1];
204
+ const end = [scale * x2, scale * y2];
205
+
206
+ segments.push({ start, end });
207
+ });
208
+
209
+ segments.sort((a, b) => key(a.start) - key(b.start));
210
+
211
+ // .. and then join them together into rings
212
+
213
+ // An arbitrary function to use a 2D point as a Map key
214
+ function key(a) { return a[0] + a[1] * 65536; }
215
+
216
+ const fragmentStart = new Map();
217
+ const fragmentEnd = new Map();
218
+ const rings = [];
219
+
220
+ segments.forEach(({ start, end }) => {
221
+ const a = fragmentEnd.get(key(start));
222
+ const b = fragmentStart.get(key(end));
223
+
224
+ if (a && b) {
225
+ fragmentEnd.delete(key(start));
226
+ fragmentStart.delete(key(end));
227
+
228
+ if (a === b) {
229
+ // Close a ring
230
+ a.push(end);
231
+ rings.push(a);
232
+ } else {
233
+ // Join two lines together
234
+ const c = a.concat(b);
235
+ fragmentStart.set(key(c[0]), c);
236
+ fragmentEnd.set(key(c[c.length - 1]), c);
237
+ }
238
+ } else if (a) {
239
+ // Extend an existing line from the end
240
+ fragmentEnd.delete(key(start));
241
+ a.push(end);
242
+ fragmentEnd.set(key(end), a);
243
+ } else if (b) {
244
+ // Extend an existing line from the start
245
+ fragmentStart.delete(key(end));
246
+ b.unshift(start);
247
+ fragmentStart.set(key(start), b);
248
+ } else {
249
+ // New line doesn't connect to any existing line
250
+ const c = [start, end];
251
+ fragmentStart.set(key(start), c);
252
+ fragmentEnd.set(key(end), c);
253
+ }
254
+
255
+ if (fragmentStart.size !== fragmentEnd.size) {
256
+ // TODO: is there a better assert function to use?
257
+ // eslint-disable-next-line
258
+ console.error(`Contour remaining fragment size mismatch ${fragmentStart.size} ${fragmentEnd.size}`);
259
+ }
260
+ });
261
+
262
+ const smoothOpts = {
263
+ kernelWidth: smoothKernelWidth,
264
+ cycles: smoothCycles,
265
+ };
266
+
267
+ // Closed rings and any unclosed line strings
268
+ return [...rings, ...fragmentStart.values()]
269
+ .filter(l => l.length >= minPoints && l.length >= smoothKernelWidth * 2)
270
+ .map(l => smooth(l, smoothOpts))
271
+ }
272
+ }
273
+
274
+ // Smooth a line by repeatedly applying a rectangular filter to approximate
275
+ // a gaussian filter. It detects closed loops and preserves them.
276
+ // The line is passed as an array of `[x, y]` pairs.
277
+ //
278
+ // kernelWidth: Width of the rectangular filter kernel
279
+ // cycles: Number of times to apply the kernel
280
+ function smooth(line, { kernelWidth = 2, cycles = 2 }) {
281
+ const isLoop = line[0][0] === line[line.length - 1][0] && line[0][1] === line[line.length - 1][1];
282
+
283
+ let pointAt;
284
+ if (isLoop) {
285
+ pointAt = i => line[(i + line.length) % line.length];
286
+ } else {
287
+ pointAt = i => line[Math.min(Math.max(i, 0), line.length - 1)];
288
+ }
289
+
290
+ const sc = 1.0 / (kernelWidth * 2);
291
+
292
+ for (let cycle = 0; cycle < cycles; cycle++) {
293
+ let px = 0;
294
+ let py = 0;
295
+
296
+ if (isLoop) {
297
+ for (let i = line.length - kernelWidth; i < line.length; i++) {
298
+ px += line[i][0];
299
+ py += line[i][1];
300
+ }
301
+ } else {
302
+ px = line[0][0] * kernelWidth;
303
+ py = line[0][1] * kernelWidth;
304
+ }
305
+
306
+ for (let i = 0; i < kernelWidth; i++) {
307
+ px += line[i][0];
308
+ py += line[i][1];
309
+ }
310
+
311
+ const res = line.slice();
312
+
313
+ for (let i = 0; i < line.length; i++) {
314
+ res[i] = [px * sc, py * sc];
315
+ px += pointAt(i + kernelWidth)[0] - pointAt(i - kernelWidth)[0];
316
+ py += pointAt(i + kernelWidth)[1] - pointAt(i - kernelWidth)[1];
317
+ }
318
+
319
+ if (isLoop) {
320
+ // Keep the loop closed
321
+ res[res.length - 1] = res[0].slice();
322
+ }
323
+
324
+ line = res;
325
+ }
326
+
327
+ return line;
328
+ }
329
+
330
+ function scaleParameters(minLongitude, minLatitude, maxLongitude, maxLatitude, width, height) {
331
+ const scaleX = (maxLongitude - minLongitude) / width;
332
+ const scaleY = (maxLatitude - minLatitude) / height;
333
+ return { scaleX, scaleY };
334
+ }
335
+
336
+
337
+ export default ContourMipmap;
338
+ export { scaleParameters };
@@ -0,0 +1,257 @@
1
+ import { getColorRampModed, DataManager, PointCoordinatesDataCalculator } from "../../util";
2
+
3
+ import { GlobeShellWiggle, Float2LegendWithRatio } from "../../programs";
4
+
5
+
6
+ /**
7
+ * @param id : string
8
+ * @param dataManager : DataManager
9
+ * @param colorRampData : {values: string[], thresholds: number[], mode: string}
10
+ * @param dataWidthHeight : {width: number, height: number}
11
+ * @param options : {bbox: number[], minMaxEdges: {min: number, max: number}, escapeValue: number, resolution: number[], meshPartition: number[]}
12
+ */
13
+ export default class Plugin {
14
+ constructor(id, dataManager, colorRampData, dataWidthHeight,
15
+ {
16
+ bbox = [-180, -90, 180, 90],
17
+ minMaxEdges = { min: -99999, max: 99999 },
18
+ escapeValue = 99999,
19
+ resolution = [2056, 2056],
20
+ } = {}) {
21
+ this.id = id;
22
+ this.dataManager = dataManager;
23
+ this._dataWidthHeight = dataWidthHeight;
24
+
25
+ this._isOn = true;
26
+ this._bbox = bbox
27
+ this._minMaxEdges = minMaxEdges;
28
+ this._escapeValue = escapeValue
29
+ this._resolution = resolution;
30
+
31
+ this._colorRampData = colorRampData; // holds until init
32
+
33
+ this._lastTexture0data = null;
34
+ this._lastTexture1data = null;
35
+
36
+ // output of heatProgram is written to ._coloredHeatTexture
37
+ this._frameBuffer = null
38
+ this._coloredHeatTexture = null;
39
+
40
+ this.isAble = false;
41
+ }
42
+
43
+
44
+ setHeight(height) {
45
+ this.globeShell.setHeight(height);
46
+ }
47
+
48
+
49
+ drawHeat() {
50
+ const gl = this.gl;
51
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
52
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._coloredHeatTexture, 0);
53
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
54
+ const currentWidth = gl.canvas.width;
55
+ const currentHeight = gl.canvas.height;
56
+ gl.viewport(0, 0, ...this._resolution);
57
+ this.heatProgram.draw()
58
+ gl.viewport(0, 0, currentWidth, currentHeight);
59
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
60
+ gl.useProgram(currentProgram);
61
+ this.globe.DrawRender();
62
+ }
63
+
64
+
65
+ setEscapeValue(escapeValue) {
66
+ this._escapeValue = escapeValue;
67
+ this.heatProgram.setEscapeValue(escapeValue);
68
+ }
69
+
70
+
71
+ _createPointCoordinatesDataCalculator() {
72
+ this.coordinatesDataCalculator = new PointCoordinatesDataCalculator(this._bbox, this._dataWidthHeight.width, this._dataWidthHeight.height);
73
+ this.dataManager.register(this._coordinatesDataCalculatorID(), this.coordinatesDataCalculator.updateData.bind(this.coordinatesDataCalculator));
74
+ }
75
+
76
+
77
+ _coordinatesDataCalculatorID() {
78
+ return this.id + "_coordinatesDataCalculator";
79
+ }
80
+
81
+
82
+ updateTime(time) {
83
+ this.dataManager.updateTime(time);
84
+ this.globe.DrawRender();
85
+ }
86
+
87
+ setWiggle({ wiggleInKm = null, wiggleSpeed = null } = {}) {
88
+ this.globeShell.setWiggle({ wiggleInKm, wiggleSpeed });
89
+ }
90
+
91
+
92
+ setMinMaxEdges(min = null, max = null) {
93
+ if (min) this._minMaxEdges.min = min;
94
+ if (max) this._minMaxEdges.max = max;
95
+ this.heatProgram.setMinMaxEdges(this._minMaxEdges.min, this._minMaxEdges.max);
96
+ this.drawHeat();
97
+ }
98
+
99
+
100
+ setBBox(minLon, minLat, maxLon, maxLat) {
101
+ this._bbox = [minLon, minLat, maxLon, maxLat];
102
+ this.globeShell.setBBox({ minLon, minLat, maxLon, maxLat });
103
+ this.drawHeat();
104
+ }
105
+
106
+
107
+ getPointCoordinatesDataCalculator() {
108
+ if (!this.coordinatesDataCalculator) this._createPointCoordinatesDataCalculator();
109
+ return this.coordinatesDataCalculator;
110
+ }
111
+
112
+
113
+ /**
114
+ * @param {*} values n + 1 number of color hex values without alpha channel. Ex: ["#ff0000", "#00ff00", "#0000ff"]
115
+ * @param {*} thresholds n number of thresholds. Ex: [0, 10, 20]
116
+ * @param {*} mode "discrete" or "interpolated"
117
+ *
118
+ * There are maximum 256 pixels in the color ramp.
119
+ * The first values array is minimum edge value which is the first pixel, the second comes one pixel after the first.
120
+ */
121
+ setColorRamp(values, thresholds, mode = "interpolated") {
122
+ const lowest = thresholds[0];
123
+ const highest = thresholds[thresholds.length - 1];
124
+ const range = highest - lowest;
125
+ const clampedThresholds = thresholds.map((t) => (t - lowest) / range);
126
+ const colors = getColorRampModed(values, clampedThresholds, mode);
127
+ this.heatProgram.setColorRampTextureData(colors, 256);
128
+ this.heatProgram.setColorRampRange(lowest, highest);
129
+ this.drawHeat();
130
+ }
131
+
132
+
133
+ off() {
134
+ this._isOn = false;
135
+ }
136
+
137
+
138
+ on() {
139
+ this._isOn = true;
140
+ }
141
+
142
+
143
+
144
+
145
+ _updateData(ratio, textureData0 = null, textureData1 = null) {
146
+ if (!textureData0 || !textureData1) {
147
+ this.isAble = false;
148
+ return;
149
+ };
150
+ this.heatProgram.setBlendRatio(ratio);
151
+ if (this._lastTexture0data !== textureData0 || this._lastTexture1data !== textureData1) {
152
+ this.isAble = true;
153
+ this._lastTexture0data = textureData0;
154
+ this._lastTexture1data = textureData1;
155
+ this.heatProgram.setFloatTextureData(textureData0, textureData1, this._dataWidthHeight.width, this._dataWidthHeight.height);
156
+ }
157
+ this.drawHeat();
158
+ }
159
+
160
+
161
+ setDataWidthHeight(width, height) {
162
+ this._dataWidthHeight = { width, height };
163
+ this.heatProgram.setDataWidthHeight(width, height);
164
+ this.setGeometry();
165
+ }
166
+
167
+
168
+ draw3D() {
169
+ if (!this._isOn) return;
170
+ if (!this.isAble) return;
171
+ this.gl.disable(this.gl.DEPTH_TEST);
172
+ this.globeShell.draw();
173
+ this.gl.enable(this.gl.DEPTH_TEST);
174
+ }
175
+
176
+
177
+ setOpacity(opacity) {
178
+ this.globeShell.setOpacity(opacity);
179
+ }
180
+
181
+
182
+ _setAfterInit() {
183
+ {
184
+ const [minLon, minLat, maxLon, maxLat] = this._bbox;
185
+ this.globeShell.setBBox({ minLon, minLat, maxLon, maxLat });
186
+ }
187
+ {
188
+ this.setColorRamp(this._colorRampData.values, this._colorRampData.thresholds, this._colorRampData.mode);
189
+ delete this._colorRampData;
190
+ }
191
+ this.setMinMaxEdges(this._minMaxEdges.min, this._minMaxEdges.max);
192
+ this.setEscapeValue(this._escapeValue);
193
+ }
194
+
195
+
196
+ _init(globe, gl) {
197
+ this.globeShell = new GlobeShellWiggle(gl, globe, {
198
+ minLon: this._bbox[0],
199
+ minLat: this._bbox[1],
200
+ maxLon: this._bbox[2],
201
+ maxLat: this._bbox[3],
202
+ color: [1.0, 0.1, 0.4, 0.2],
203
+ height: 0,
204
+ wiggleInKM: 2,
205
+ eastWestTied: false,
206
+ displayMesh: false
207
+ });
208
+ this.heatProgram = new Float2LegendWithRatio(gl);
209
+ this._frameBuffer = gl.createFramebuffer();
210
+
211
+ this.dataManager.register(this.id, (ratio, t1, t2) => this._updateData(ratio, t1, t2));
212
+ this.setResolution(this._resolution[0], this._resolution[1]);
213
+ }
214
+
215
+
216
+
217
+ init(globe, gl) {
218
+ this.globe = globe;
219
+ this.gl = gl;
220
+ this._init(globe, gl);
221
+ this._setAfterInit();
222
+ }
223
+
224
+ setGeometry() {
225
+ // globeShell has an implicit program, registered and sets its own geometry.
226
+ return;
227
+ }
228
+
229
+
230
+ // sets Density of middle texture which is used with framebuffers
231
+ setResolution(width, height) {
232
+ const gl = this.gl;
233
+ this._resolution = [width, height];
234
+ this._coloredHeatTexture = gl.createTexture();
235
+ gl.bindTexture(gl.TEXTURE_2D, this._coloredHeatTexture);
236
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
237
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
238
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
239
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
240
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
241
+ gl.bindTexture(gl.TEXTURE_2D, null);
242
+ this.globeShell.setTexture(this._coloredHeatTexture);
243
+ }
244
+
245
+
246
+ free() {
247
+ if (this.coordinatesDataCalculator) {
248
+ this.dataManager.unregister(this._coordinatesDataCalculatorID());
249
+ this.coordinatesDataCalculator = null;
250
+ }
251
+ this.dataManager.unregister(this.id);
252
+ this.globeShell.free();
253
+ this.heatProgram.free();
254
+ }
255
+
256
+
257
+ }
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import * as wind from "./wind";
2
+ import * as waveparticles from "./waveparticles";
3
+ import * as timetracks from "./timetracks";
4
+ import { RangeRings } from "./rangerings";
5
+ import * as compassrose from "./compassrose";
6
+ import * as heatmap from "./heatwavemaps";
7
+
8
+ export { wind, waveparticles, timetracks, RangeRings, compassrose, heatmap };
package/package.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@pirireis/webglobeplugins",
3
+ "version": "0.0.1",
4
+ "main": "index.js",
5
+ "author": "Toprak Nihat Deniz Ozturk",
6
+ "license": "MIT"
7
+ }
@@ -0,0 +1,2 @@
1
+ import ArrowField from './object';
2
+ export default ArrowField;