@pirireis/webglobeplugins 0.10.9-alpha → 0.10.11-alpha

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.
@@ -1,248 +0,0 @@
1
- /**
2
- * Author: Toprak Nihat Deniz Ozturk
3
- */
4
- import TrackGlowLineProgram from './program';
5
- import PointProgram from './programpoint';
6
- /**
7
- * @typedef {Float32Array} TimeTrackMultiColorData | A linestring is representation, let A{a1, a2, a3}, B{b1, b2} be the points of the line.
8
- * TimeTrackMultiColorData is [
9
- * a1x, a1y, a1z, a1time, a1r, a1g, a1b, a1time, a3time, a2x, a2y, a2z, a2time, a2r, a2g, a2b, a1time, a3time,
10
- * a2x, a2y, a2z, a2time, a2r, a2g, a2b, a1time, a3time, a3x, a3y, a3z, a3time, a3r, a3g, a3b, a1time, a3time,
11
- * b1x, b1y, b1z, b1time, b1r, b1g, b1b, b1time, b2time, b2x, b2y, b2z, b2time, b2r, b2g, b2b, BstartTime, BendTime
12
- * ]
13
- * As you can see, the middle points of a line is repeated.
14
- * Start Time is the first time of the line, End Time is the last time of the line.
15
- * startTime of A = a1time, endTime time of A = a3time
16
- * Check Adaptor to create TimeTrackMultiColorData. import {Adaptor} from '.';
17
- */
18
- /**
19
- * Access following methods through `plugin.program.` :
20
- * * setGamma
21
- * * setExposure
22
- * * setAlphaThreshold
23
- * * setWeights
24
- * * setHeadPercentage
25
- * * setRouteAlpha
26
- * * setFinalAlphaRatio
27
-
28
- uses float32array in a * {@link TimeTrackMultiColorData} format
29
-
30
- */
31
- export default class TimeTrackMultiColorPlugin {
32
- /**
33
- * @param {String} id
34
- * @param {Object} options
35
- * @param {TimeTrackMultiColorData} options.data {@link TimeTrackMultiColorData}
36
- * @param {number} options.headPercentage 0 ~ 1
37
- * @param {number} options.routeAlpha 0 ~ 1
38
- * @param {Array.<Number>} options.weights [w1, w2, w3, w4, w5]
39
- * @param {number} options.alphaThreshold 0 ~ 1
40
- * @param {number} options.exposure 0 ~ inf
41
- * @param {number} options.gamma 0 ~ inf
42
- * @param {number} options.finalAlphaRatio 0 ~ 1
43
- * @param {number} pointOptions.opacity 0 ~ 1
44
- * @param {number} pointOptions.pointSize 0 ~ inf
45
- * @param {boolean} pointOptions.isOn true | false
46
- */
47
- constructor(id, options = {}, { opacity = 1.0, pointSize = 1, isOn = false } = {}) {
48
- this.id = id;
49
- this.globe = null;
50
- this.gl = null;
51
- this.program = null;
52
- this._headTime = 0;
53
- this._tailTime = 0;
54
- this._data = options.data || null;
55
- this._options = options;
56
- this._pointOptions = { opacity, pointSize, isOn };
57
- this.program = null;
58
- this._transporArr = new Float32Array(3);
59
- this._ready = false;
60
- this.pointProgram = null;
61
- this._attrBuffer = null;
62
- }
63
- // ----------------------------------
64
- // --- user methods ---
65
- // ----------------------------------
66
- setHeadAndTailTime(headTime, tailTime) {
67
- this._headTime = headTime;
68
- this._tailTime = tailTime;
69
- this.pointProgram?.setHeadTime(headTime);
70
- this.globe.DrawRender();
71
- }
72
- setGlow(isGlow) {
73
- this.program.setGlow(isGlow);
74
- this.globe.DrawRender();
75
- }
76
- setPremultipliedAlpha(isPremultiplied) {
77
- this.program.setPremultipliedAlpha(isPremultiplied);
78
- this.globe.DrawRender();
79
- }
80
- setBlurWeights(weights) {
81
- this.program.setBlurWeights(weights);
82
- this.globe.DrawRender();
83
- }
84
- setHeadPercentage(headPercentage) {
85
- this.program.setHeadPercentage(headPercentage);
86
- this.globe.DrawRender();
87
- }
88
- setRouteAlpha(routeAlpha) {
89
- this.program.setRouteAlpha(routeAlpha);
90
- this.globe.DrawRender();
91
- }
92
- setFinalAlphaRatio(finalAlphaRatio) {
93
- this.program.setFinalAlphaRatio(finalAlphaRatio);
94
- this.globe.DrawRender();
95
- }
96
- setGamma(gamma) {
97
- this.program.setGamma(gamma);
98
- this.globe.DrawRender();
99
- }
100
- setExposure(exposure) {
101
- this.program.setExposure(exposure);
102
- this.globe.DrawRender();
103
- }
104
- setBlurRepetition(repetition) {
105
- this.program.setBlurRepetition(repetition);
106
- this.globe.DrawRender();
107
- }
108
- setAlphaThreshold(alphaThreshold) {
109
- this.program.setAlphaThreshold(alphaThreshold);
110
- this.globe.DrawRender();
111
- }
112
- // ---------------point program setters-------------------
113
- setPointOpacity(opacity) {
114
- this._pointOptions.opacity = opacity;
115
- if (this.pointProgram) {
116
- this.pointProgram.setOpacity(opacity);
117
- this.globe.DrawRender();
118
- }
119
- }
120
- setPointSize(size) {
121
- this._pointOptions.pointSize = size;
122
- if (this.pointProgram) {
123
- this.pointProgram.setPointSize(size);
124
- this.globe.DrawRender();
125
- }
126
- }
127
- pointSwitch(isOn) {
128
- if (isOn && !this.pointProgram) {
129
- this.pointProgram = this._createPointProgram();
130
- }
131
- else {
132
- this._deletePointProgram();
133
- }
134
- }
135
- // ------------------------------------------------------------
136
- _createPointProgram() {
137
- const { gl } = this;
138
- const program = new PointProgram(gl, this.globe, this._attrBuffer, this._pointOptions);
139
- program.setDrawCount(this._totalSize / 2);
140
- return program;
141
- }
142
- _deletePointProgram() {
143
- if (this.pointProgram)
144
- this.pointProgram.free();
145
- this.pointProgram = null;
146
- }
147
- // -------------------------------------------------------------
148
- isReady() {
149
- return this._ready;
150
- }
151
- /**
152
- * @param {TimeTrackMultiColorData} data {@link TimeTrackMultiColorData}
153
- * Check Class constructor
154
- */
155
- setData(data) {
156
- if (this.gl) {
157
- this._ready = false;
158
- this.setDataAsFloat32Array(data);
159
- this._ready = true;
160
- }
161
- else {
162
- this._data = data;
163
- this._ready = false;
164
- }
165
- }
166
- /**
167
- * @param {TimeTrackMultiColorData} data {@link TimeTrackMultiColorData}
168
- * @param {number} totalSize | if not provided, it is calculated from float32Array.length / 9. Use if you want to draw first n points.
169
- */
170
- setDataAsFloat32Array(data, totalSize = null) {
171
- const { gl, _attrBuffer } = this;
172
- gl.bindBuffer(gl.ARRAY_BUFFER, _attrBuffer);
173
- gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
174
- gl.bindBuffer(gl.ARRAY_BUFFER, null);
175
- // this.program.setInBuffer(data);
176
- // this.pointProgram.setData(data);
177
- if (totalSize) {
178
- this._totalSize = totalSize;
179
- }
180
- else {
181
- this._totalSize = data.length / 9;
182
- }
183
- this.program.setTotalLength(this._totalSize);
184
- this.pointProgram?.setDrawCount(this._totalSize / 2);
185
- this._ready = true;
186
- }
187
- // ------------------------------
188
- // --- globe Methods ---
189
- // ------------------------------
190
- draw3D(projMatrix, modelviewMatrix, transPos) {
191
- if (!this._ready)
192
- return;
193
- const { _headTime, _tailTime, program, _transporArr, globe } = this;
194
- this.pointProgram?.draw();
195
- _transporArr.set([transPos.x, transPos.y, transPos.z], 0);
196
- const geomType = globe.api_GetCurrentGeometry();
197
- if (geomType === 0) {
198
- program.draw(_headTime, _tailTime, projMatrix, modelviewMatrix, _transporArr);
199
- }
200
- else if (geomType === 1) {
201
- const { width, height } = globe.api_GetCurrentWorldWH();
202
- program.draw(_headTime, _tailTime, projMatrix, modelviewMatrix, _transporArr, [width, height]);
203
- }
204
- else {
205
- console.error("Unknown geometry type", geomType);
206
- }
207
- }
208
- resize(width, height) {
209
- const { program, globe } = this;
210
- width = width || globe.api_ScrW();
211
- height = height || globe.api_ScrH();
212
- program.resize(width, height);
213
- }
214
- init(globe, gl) {
215
- this.globe = globe;
216
- this.gl = gl;
217
- this._attrBuffer = gl.createBuffer();
218
- this.program = new TrackGlowLineProgram(gl, this._attrBuffer, globe.api_ScrW(), globe.api_ScrH(), this._options);
219
- if (this._pointOptions?.isOn)
220
- this.pointProgram = new PointProgram(gl, globe, this._attrBuffer);
221
- // this.pointProgram.setAttrBuffer(_attrBuffer);
222
- this.setGeometry();
223
- if (this._data) {
224
- this._ready = true;
225
- this.setDataAsFloat32Array(this._data);
226
- this._data = null;
227
- }
228
- this.resize();
229
- }
230
- free() {
231
- const { gl, _attrBuffer } = this;
232
- this.program.free();
233
- gl.deleteBuffer(_attrBuffer);
234
- }
235
- setGeometry() {
236
- const { globe, program } = this;
237
- program.setIs3D(globe.api_GetCurrentGeometry() === 0);
238
- }
239
- // ----------------------------------
240
- // --- implicit methods ---
241
- // ----------------------------------
242
- _latLongToPixelXY(latitude, longitude) {
243
- return {
244
- x: (longitude + 180) / 360,
245
- y: (90 - latitude) / 180
246
- };
247
- }
248
- }