@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,133 @@
1
+ import { latLongToPixelXY } from "../util";
2
+ const _latLongToPixelXY = latLongToPixelXY;
3
+
4
+
5
+
6
+ class Adaptor {
7
+ /**
8
+ * @param {Object.<string, Color>} groupColorMap
9
+ * @typedef {Array} Color | [r, g, b] | between 0-1
10
+ */
11
+ constructor(groupColorMap) {
12
+ this._groupColorMap = groupColorMap;
13
+ }
14
+
15
+ /**
16
+ * @param {Object} geojsonObject
17
+ * @param {number} startTime
18
+ * @param {string} timePropertyName
19
+ * @param {string} styleGroupPropertyName
20
+ * @returns {lineData} lineData for Plugin
21
+ */
22
+ fromGeoJson(geojsonObject, startTime, timePropertyName = "messageTime", styleGroupPropertyName = "styleGroup") {
23
+ const features = geojsonObject.features.filter(feature => feature.geometry.coordinates.length > 1);
24
+
25
+ const buffer = createFloat32Array(features.map(feature => feature.geometry.coordinates));
26
+
27
+ let offset = 0;
28
+ for (let feature of features) {
29
+ const coordinates = feature.geometry.coordinates;
30
+ const timestamps = feature.properties[timePropertyName].map((time) => (time - startTime) / 1000);
31
+ const styleGroupNameArray = feature.properties[styleGroupPropertyName];
32
+ offset = fillSliceOfFloat32Array(coordinates, timestamps, styleGroupNameArray, this._groupColorMap, buffer, offset);
33
+ }
34
+ return buffer;
35
+ }
36
+
37
+ /**
38
+ * Inputs are lists of tracks. Each track is a list of coordinates, timestamps and styleGroupNames.
39
+ * @param {Array.<Array.<Array.<number>>>} coordinatesList | [ [ [lon, lat, z], [lon, lat, z], ...], ...
40
+ * @param {Array.<Array.<number>>} timestampsList | [ [time, time, ...], ...
41
+ * @param {Array.<Array.<String>>} colorGroupList | [ [styleGroupName, styleGroupName, ...], ...
42
+ * @param {number} startTime | epoch time
43
+ * @returns {lineData} lineData for Plugin
44
+ */
45
+ fromLists(coordinatesList, timestampsList, colorGroupList, startTime) {
46
+
47
+ const buffer = createFloat32Array(coordinatesList);
48
+
49
+ let offset = 0;
50
+ for (let i = 0; i < coordinatesList.length; i++) {
51
+ const coordinates = coordinatesList[i];
52
+ const timestamps = timestampsList[i].map((time) => (time - startTime) / 1000);
53
+ const styleGroupNameArray = colorGroupList[i];
54
+ offset = fillSliceOfFloat32Array(coordinates, timestamps, styleGroupNameArray, this._groupColorMap, buffer, offset);
55
+ }
56
+ return buffer;
57
+ }
58
+ }
59
+
60
+ /**
61
+ * @param {Array.<Array.<number>>} coordinates
62
+ * @param {Array.<number>} timestamps
63
+ * @param {Array.<String>} styleGroupNameArray
64
+ * @param {Object.<string, TrackStyleGroup>} _groupColorMap
65
+ * @param {Float32Array} floatArray
66
+ * @param {number} offset
67
+ *
68
+ * create floatArray with createFloat32Array before calling this function.
69
+ * start offset from 0.
70
+ * feed the floatArray with a track data and offset that is returned from the previous call.
71
+ */
72
+ function fillSliceOfFloat32Array(coordinates, timestamps, styleGroupNameArray, _groupColorMap, floatArray, offset) {
73
+
74
+ if (coordinates[0].length === 2) {
75
+ const startTime = timestamps[0];
76
+ const endTime = timestamps[timestamps.length - 1];
77
+ let prevPointData = null;
78
+ { // first point
79
+ const { x, y } = _latLongToPixelXY(coordinates[0][1], coordinates[0][0]);
80
+ prevPointData = [x, y, 0, timestamps[0], ..._groupColorMap[styleGroupNameArray[0]]];
81
+ }
82
+ { // middle points until end
83
+ for (let i = 1; i < coordinates.length; i++) {
84
+ const time = timestamps[i];
85
+ const coord = coordinates[i];
86
+ const { x, y } = _latLongToPixelXY(coord[1], coord[0]);
87
+ floatArray.set([...prevPointData, startTime, endTime, x, y, 0, time, ..._groupColorMap[styleGroupNameArray[i]], startTime, endTime], offset);
88
+ prevPointData = [x, y, 0, time, ..._groupColorMap[styleGroupNameArray[i]]];
89
+ offset += 18;
90
+ }
91
+ }
92
+ } else {
93
+
94
+ const startTime = timestamps[0];
95
+ const endTime = timestamps[timestamps.length - 1];
96
+ let prevPointData = null;
97
+ { // first point
98
+ const { x, y } = _latLongToPixelXY(coordinates[0][1], coordinates[0][0]);
99
+ prevPointData = [x, y, coordinates[0][2] / 1000.0, timestamps[0], ..._groupColorMap[styleGroupNameArray[0]]];
100
+ }
101
+ { // middle points until end
102
+ for (let i = 1; i < coordinates.length; i++) {
103
+ const time = timestamps[i];
104
+ const coord = coordinates[i];
105
+ const { x, y } = _latLongToPixelXY(coord[1], coord[0]);
106
+ floatArray.set([...prevPointData, startTime, endTime, x, y, coord[2] / 1000.0, time, ..._groupColorMap[styleGroupNameArray[i]], startTime, endTime], offset);
107
+ prevPointData = [x, y, coord[2] / 1000.0, time, ..._groupColorMap[styleGroupNameArray[i]]];
108
+ offset += 18;
109
+ }
110
+ }
111
+ }
112
+ return offset;
113
+ }
114
+
115
+
116
+ /**
117
+ *
118
+ * @param {*} coordinatesArray
119
+ * @returns Float32Array
120
+ * Coordinates array is needed to calculate the size of the buffer.
121
+ */
122
+ function createFloat32Array(coordinatesArray) {
123
+ let filteredSize = 0;
124
+ for (let coordinates of coordinatesArray) {
125
+ filteredSize += coordinates.length * 2 - 2;
126
+ }
127
+ const array = new Float32Array(filteredSize * 9);
128
+ return array;
129
+ }
130
+
131
+
132
+
133
+ export { Adaptor, fillSliceOfFloat32Array, createFloat32Array };
@@ -0,0 +1,3 @@
1
+ import TimeTracks from './plugin';
2
+ import { Adaptor, fillSliceOfFloat32Array, createFloat32Array } from './adaptors';
3
+ export { Adaptor, fillSliceOfFloat32Array, createFloat32Array, TimeTracks };
@@ -0,0 +1,304 @@
1
+ /**
2
+ * Author: Toprak Nihat Deniz Ozturk
3
+ */
4
+
5
+
6
+
7
+ import TrackGlowLineProgram from './program';
8
+ import PointProgram from './programpoint';
9
+
10
+ /**
11
+ * @typedef {Float32Array} TimeTrackMultiColorData | A linestring is representation, let A{a1, a2, a3}, B{b1, b2} be the points of the line.
12
+ * TimeTrackMultiColorData is [
13
+ * a1x, a1y, a1z, a1time, a1r, a1g, a1b, a1time, a3time, a2x, a2y, a2z, a2time, a2r, a2g, a2b, a1time, a3time,
14
+ * a2x, a2y, a2z, a2time, a2r, a2g, a2b, a1time, a3time, a3x, a3y, a3z, a3time, a3r, a3g, a3b, a1time, a3time,
15
+ * b1x, b1y, b1z, b1time, b1r, b1g, b1b, b1time, b2time, b2x, b2y, b2z, b2time, b2r, b2g, b2b, BstartTime, BendTime
16
+ * ]
17
+ * As you can see, the middle points of a line is repeated.
18
+ * Start Time is the first time of the line, End Time is the last time of the line.
19
+ * startTime of A = a1time, endTime time of A = a3time
20
+ * Check Adaptor to create TimeTrackMultiColorData. import {Adaptor} from '.';
21
+ */
22
+
23
+
24
+
25
+
26
+
27
+ /**
28
+ * Access following methods through `plugin.program.` :
29
+ * * setGamma
30
+ * * setExposure
31
+ * * setAlphaThreshold
32
+ * * setWeights
33
+ * * setHeadPercentage
34
+ * * setRouteAlpha
35
+ * * setFinalAlphaRatio
36
+
37
+ uses float32array in a * {@link TimeTrackMultiColorData} format
38
+
39
+ */
40
+ export default class TimeTrackMultiColorPlugin {
41
+ /**
42
+ * @param {String} id
43
+ * @param {Object} options
44
+ * @param {TimeTrackMultiColorData} options.data {@link TimeTrackMultiColorData}
45
+ * @param {number} options.headPercentage 0 ~ 1
46
+ * @param {number} options.routeAlpha 0 ~ 1
47
+ * @param {Array.<Number>} options.weights [w1, w2, w3, w4, w5]
48
+ * @param {number} options.alphaThreshold 0 ~ 1
49
+ * @param {number} options.exposure 0 ~ inf
50
+ * @param {number} options.gamma 0 ~ inf
51
+ * @param {number} options.finalAlphaRatio 0 ~ 1
52
+ * @param {number} pointOptions.opacity 0 ~ 1
53
+ * @param {number} pointOptions.pointSize 0 ~ inf
54
+ * @param {boolean} pointOptions.isOn true | false
55
+ */
56
+ constructor(id, options = {}, { opacity = 1.0, pointSize = 1, isOn = false } = {}) {
57
+ this.id = id;
58
+
59
+ this.globe = null;
60
+ this.gl = null;
61
+ this.program = null;
62
+ this._headTime = 0;
63
+ this._tailTime = 0;
64
+
65
+ this._data = options.data || null;
66
+ this._options = options;
67
+ this._pointOptions = { opacity, pointSize, isOn };
68
+ this.program = null;
69
+
70
+ this._transporArr = new Float32Array(3);
71
+
72
+ this._ready = false;
73
+
74
+ this.pointProgram = null;
75
+
76
+ this._attrBuffer = null;
77
+ }
78
+
79
+ // ----------------------------------
80
+ // --- user methods ---
81
+ // ----------------------------------
82
+
83
+ setHeadAndTailTime(headTime, tailTime) {
84
+ this._headTime = headTime;
85
+ this._tailTime = tailTime;
86
+ this.pointProgram?.setHeadTime(headTime);
87
+ this.globe.DrawRender();
88
+ }
89
+
90
+ setGlow(isGlow) {
91
+ this.program.setGlow(isGlow);
92
+ this.globe.DrawRender();
93
+ }
94
+
95
+ setPremultipliedAlpha(isPremultiplied) {
96
+ this.program.setPremultipliedAlpha(isPremultiplied);
97
+ this.globe.DrawRender();
98
+ }
99
+
100
+ setBlurWeights(weights) {
101
+ this.program.setBlurWeights(weights);
102
+ this.globe.DrawRender();
103
+ }
104
+
105
+ setHeadPercentage(headPercentage) {
106
+ this.program.setHeadPercentage(headPercentage);
107
+ this.globe.DrawRender();
108
+ }
109
+
110
+ setRouteAlpha(routeAlpha) {
111
+ this.program.setRouteAlpha(routeAlpha);
112
+ this.globe.DrawRender();
113
+ }
114
+
115
+ setFinalAlphaRatio(finalAlphaRatio) {
116
+ this.program.setFinalAlphaRatio(finalAlphaRatio);
117
+ this.globe.DrawRender();
118
+ }
119
+
120
+ setGamma(gamma) {
121
+ this.program.setGamma(gamma);
122
+ this.globe.DrawRender();
123
+ }
124
+
125
+ setExposure(exposure) {
126
+ this.program.setExposure(exposure);
127
+ this.globe.DrawRender();
128
+ }
129
+
130
+ setBlurRepetition(repetition) {
131
+ this.program.setBlurRepetition(repetition);
132
+ this.globe.DrawRender();
133
+ }
134
+
135
+ setAlphaThreshold(alphaThreshold) {
136
+ this.program.setAlphaThreshold(alphaThreshold);
137
+ this.globe.DrawRender();
138
+ }
139
+
140
+ // ---------------point program setters-------------------
141
+
142
+ setPointOpacity(opacity) {
143
+ this._pointOptions.opacity = opacity;
144
+ if (this.pointProgram) {
145
+ this.pointProgram.setOpacity(opacity);
146
+ this.globe.DrawRender();
147
+ }
148
+ }
149
+
150
+ setPointSize(size) {
151
+ this._pointOptions.pointSize = size;
152
+ if (this.pointProgram) {
153
+ this.pointProgram.setPointSize(size);
154
+ this.globe.DrawRender();
155
+ }
156
+ }
157
+
158
+ pointSwitch(isOn) {
159
+ if (isOn && !this.pointProgram) {
160
+ this.pointProgram = this._createPointProgram();
161
+ } else {
162
+ this._deletePointProgram();
163
+ }
164
+
165
+ }
166
+
167
+ // ------------------------------------------------------------
168
+
169
+ _createPointProgram() {
170
+ const { gl } = this;
171
+ const program = new PointProgram(gl, this.globe, this._attrBuffer, this._pointOptions);
172
+ program.setDrawCount(this._totalSize / 2);
173
+ return program;
174
+ }
175
+
176
+ _deletePointProgram() {
177
+ if (this.pointProgram) this.pointProgram.free();
178
+ this.pointProgram = null;
179
+ }
180
+
181
+ // -------------------------------------------------------------
182
+
183
+ isReady() {
184
+ return this._ready;
185
+ }
186
+
187
+ /**
188
+ * @param {TimeTrackMultiColorData} data {@link TimeTrackMultiColorData}
189
+ * Check Class constructor
190
+ */
191
+ setData(data) {
192
+ if (this.gl) {
193
+ this._ready = false;
194
+ this.setDataAsFloat32Array(data);
195
+ this._ready = true;
196
+ } else {
197
+ this._data = data;
198
+ this._ready = false;
199
+ }
200
+ }
201
+
202
+ /**
203
+ * @param {TimeTrackMultiColorData} data {@link TimeTrackMultiColorData}
204
+ * @param {number} totalSize | if not provided, it is calculated from float32Array.length / 9. Use if you want to draw first n points.
205
+ */
206
+ setDataAsFloat32Array(data, totalSize = null) {
207
+
208
+ const { gl, _attrBuffer } = this;
209
+ gl.bindBuffer(gl.ARRAY_BUFFER, _attrBuffer);
210
+ gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
211
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
212
+
213
+
214
+ // this.program.setInBuffer(data);
215
+
216
+ // this.pointProgram.setData(data);
217
+ if (totalSize) {
218
+ this._totalSize = totalSize;
219
+ } else {
220
+ this._totalSize = data.length / 9;
221
+ }
222
+ this.program.setTotalLength(this._totalSize);
223
+ this.pointProgram?.setDrawCount(this._totalSize / 2);
224
+
225
+ this._ready = true;
226
+ }
227
+
228
+ // ------------------------------
229
+ // --- globe Methods ---
230
+ // ------------------------------
231
+
232
+ draw3D(projMatrix, modelviewMatrix, transPos) {
233
+ if (!this._ready) return;
234
+ const { _headTime, _tailTime, program, _transporArr, globe } = this;
235
+ this.pointProgram?.draw();
236
+
237
+ _transporArr.set([transPos.x, transPos.y, transPos.z], 0);
238
+ const geomType = globe.api_GetCurrentGeometry();
239
+ if (geomType === 0) {
240
+ program.draw(_headTime, _tailTime, projMatrix, modelviewMatrix, _transporArr);
241
+ } else if (geomType === 1) {
242
+ const { width, height } = globe.api_GetCurrentWorldWH();
243
+ program.draw(_headTime, _tailTime, projMatrix, modelviewMatrix, _transporArr,
244
+ [width, height]);
245
+ } else {
246
+ console.error("Unknown geometry type", geomType);
247
+ }
248
+ }
249
+
250
+ resize(width, height) {
251
+ const { program, globe } = this;
252
+ width = width || globe.api_ScrW();
253
+ height = height || globe.api_ScrH();
254
+ program.resize(width, height);
255
+ }
256
+
257
+
258
+ init(globe, gl) {
259
+ this.globe = globe;
260
+ this.gl = gl;
261
+ this._attrBuffer = gl.createBuffer();
262
+ this.program = new TrackGlowLineProgram(gl, this._attrBuffer, globe.api_ScrW(), globe.api_ScrH(), this._options);
263
+ if (this._pointOptions?.isOn) this.pointProgram = new PointProgram(gl, globe, this._attrBuffer);
264
+
265
+ // this.pointProgram.setAttrBuffer(_attrBuffer);
266
+ this.setGeometry();
267
+ if (this._data) {
268
+ this._ready = true;
269
+ this.setDataAsFloat32Array(this._data);
270
+
271
+ this._data = null;
272
+ }
273
+ this.resize();
274
+ }
275
+
276
+
277
+ free() {
278
+ const { gl, _attrBuffer } = this;
279
+ this.program.free();
280
+ gl.deleteBuffer(_attrBuffer);
281
+ }
282
+
283
+
284
+ setGeometry() {
285
+ const { globe, program } = this;
286
+ program.setIs3D(globe.api_GetCurrentGeometry() === 0);
287
+ }
288
+
289
+ // ----------------------------------
290
+ // --- implicit methods ---
291
+ // ----------------------------------
292
+
293
+
294
+ _latLongToPixelXY(latitude, longitude) {
295
+ return {
296
+ x: (longitude + 180) / 360,
297
+ y: (90 - latitude) / 180
298
+ };
299
+ }
300
+ }
301
+
302
+
303
+
304
+