@pirireis/webglobeplugins 0.6.31-a → 0.6.34

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.
@@ -63,136 +63,15 @@ export class CircleLineChainPlugin {
63
63
 
64
64
  // init
65
65
 
66
- init(globe, gl) {
67
- this.gl = gl;
68
- this.globe = globe
69
- this._initOrchestrations()
70
- }
71
-
72
- _checktextWritersMap(textWritersMap) {
73
- if (!(textWritersMap instanceof Map)) throw new Error("textWritersMap is not an instance of Map");
74
- textWritersMap.forEach((v) => {
75
- if (!(v instanceof ContextTextWriter3)) throw new Error("textWritersMap element is not an instance of ContextTextWriter3");
76
- });
77
- }
78
-
79
- _initOrchestrations() {
80
- const { gl, globe } = this;
81
- this.lineProgram = LineOnGlobeCache.get(globe);
82
- this.circleProgram2d = CircleCache.get(globe);
83
- this.circle3DProgram = Circle3DCache.get(globe);
84
-
85
- // this.lineToTheOriginProgram = LineToTheOriginCache.get(globe);
86
- const _circleFlatEdgeCount = this._circleFlatEdgeCount;
87
- {
88
- // createBuffers
89
- const bufferType = "DYNAMIC_DRAW";
90
- const initialCapacity = this.bufferOrchestrator.capacity;
91
- this.bufferManagersCompMap = new Map(
92
- [
93
- ["centerCoords2d", {
94
- 'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
95
- 'adaptor': (item) => new Float32Array(globe.api_GetMercator2DPoint(item.long, item.lat)),
96
- }],
97
- ["centerCoords3d", {
98
- 'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
99
- 'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.long, item.lat, 0, 0)),
100
- }],
101
- ["targetCoords2d", {
102
- 'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
103
- 'adaptor': (item) => new Float32Array(globe.api_GetMercator2DPoint(item.targetLong, item.targetLat)),
104
- }],
105
- ["targetCoords3d", {
106
- 'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
107
- 'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.targetLong, item.targetLat, 0, 0)),
108
- }],
109
- ["rgba", {
110
- 'bufferManager': new BufferManager(gl, 4, { bufferType, initialCapacity }),
111
- 'adaptor': (item) => {
112
- if (item.lineProperties?.rgba) return new Float32Array(item.lineProperties.rgba);
113
- return new Float32Array(item.chainProperties.rgba);
114
- }
115
- }],
116
- ["bigRadius", {
117
- 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
118
- 'adaptor': (item) => new Float32Array([item.bigRadius])
119
- }],
120
- ["dashRatio", {
121
- 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
122
- 'adaptor': (item) => new Float32Array([item.chainProperties.dashRatio])
123
- }],
124
-
125
- ["dashOpacity", {
126
- 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
127
- 'adaptor': (item) => new Float32Array([item.chainProperties.dashOpacity])
128
- }],
129
- ["circleDashAngle", {
130
- 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
131
- 'adaptor': (item) => {
132
- if (item.circleProperties?.circleDashAngle) return new Float32Array([item.circleProperties.circleDashAngle / 360]);
133
- return new Float32Array([item.chainProperties.circleDashAngle / 360]);
134
- }
135
- }],
136
- ["rgbaCircle", {
137
- "bufferManager": new BufferManager(gl, 4, { bufferType, initialCapacity }),
138
- "adaptor": (item) => {
139
- if (item.circleProperties?.rgba) return new Float32Array(item.circleProperties.rgba);
140
- return new Float32Array(item.chainProperties.rgba);
141
- }
142
- }],
143
- // Mercator buffers
144
- ["circleDashAngleMercator", {
145
- 'bufferManager': new BufferManager(gl, 1 * _circleFlatEdgeCount, { bufferType, initialCapacity }),
146
- 'adaptor': (item) => {
147
- if (item.circleProperties?.circleDashAngle) return new Float32Array([item.circleProperties.circleDashAngle / 360]);
148
- return populateFloat32Array.fillFloat32Array(_circleFlatEdgeCount, item.chainProperties.circleDashAngle / 360);
149
- }
150
- }],
151
- ["rgbaCircleMercator", { // 62
152
- "bufferManager": new BufferManager(gl, 4 * _circleFlatEdgeCount, { bufferType, initialCapacity }),
153
- "adaptor": (item) => {
154
- if (item.circleProperties?.rgba) return populateFloat32Array.fillWithListData(_circleFlatEdgeCount, item.circleProperties.rgba);
155
- return populateFloat32Array.fillWithListData(_circleFlatEdgeCount, item.chainProperties.rgba);
156
- }
157
- }],
158
- ["dashOpacityMercator", {
159
- 'bufferManager': new BufferManager(gl, 1 * _circleFlatEdgeCount, { bufferType, initialCapacity }),
160
- 'adaptor': (item) => populateFloat32Array.fillFloat32Array(_circleFlatEdgeCount, item.chainProperties.dashOpacity)
161
- }],
162
- ["centerCoords2dMercator", {
163
- 'bufferManager': new BufferManager(gl, 2 * _circleFlatEdgeCount, { bufferType, initialCapacity }),
164
- 'adaptor': (item) => item.centerCoords2dflat,
165
- }],
166
- ]
167
- );
168
- // (startPotisionBufferObj, endPositionBufferObj, dashRatioBufferObj, colorBufferObj)
169
- const obj = function (bufferManagerComp) {
170
- return { 'buffer': bufferManagerComp.bufferManager.buffer, 'stride': 0, 'offset': 0 }
171
- };
172
- this.lineVao = this.lineProgram.createVAO(
173
- ...['centerCoords2d', 'centerCoords3d', 'targetCoords2d', 'targetCoords3d', 'dashRatio', 'dashOpacity', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
174
- this.circleVao2d = this.circleProgram2d.createVAO(
175
- ...["centerCoords2dMercator", "rgbaCircleMercator", "circleDashAngleMercator", "dashOpacityMercator"].map(key => obj(this.bufferManagersCompMap.get(key))));
176
- // this.toOriginVao = this.lineToTheOriginProgram.createVAO(
177
- // ...["targetCoords3d", "rgba"].map(key => obj(this.bufferManagersCompMap.get(key))));
178
- this.circle3DVao = this.circle3DProgram.createVAO(
179
- ...["centerCoords3d", "bigRadius", "rgbaCircle", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key)))
180
- );
181
-
182
- }
183
-
184
- }
185
-
186
-
187
66
  // API
188
67
  setDrawCircleOn(bool) {
189
68
  if (typeof bool !== 'boolean') throw new Error("setDrawCircleOn parameter must be a boolean");
190
69
  this._drawCircleOn = bool;
191
70
  this.globe.DrawRender();
192
71
  }
193
- // -- update bulk family
72
+
73
+ // ---- updateBulk
194
74
  /**
195
- *
196
75
  * @param {Array<chain>} data
197
76
  * @typedef chain
198
77
  * @property {string} chainKey
@@ -220,7 +99,6 @@ export class CircleLineChainPlugin {
220
99
 
221
100
 
222
101
  /**
223
- *
224
102
  * @param {*} chainKey
225
103
  * @param {Array<{nodeKey, circleProperties:Map[propertyName ,value], lineProperties:Map[propertyName ,value] }} propertyMap
226
104
  */
@@ -232,7 +110,6 @@ export class CircleLineChainPlugin {
232
110
  }
233
111
 
234
112
  /**
235
- *
236
113
  * @param {*} chainKey
237
114
  * @param {Map<propertyName ,value} propertyMap
238
115
  */
@@ -242,7 +119,23 @@ export class CircleLineChainPlugin {
242
119
  if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
243
120
  }
244
121
 
245
- // ---- insertBulk family
122
+
123
+ updateNodeCoordinates(node, chainKey, { textWriterIDs = [] } = {}) {
124
+ this._chainListMap.updateCoordsinatesOfNode(node, chainKey);
125
+ if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
126
+ this._reconstructChains([chainKey]);
127
+ this.globe.DrawRender();
128
+ }
129
+
130
+
131
+ updateText(textWriterIDs) {
132
+ const chainKeyIterator = this._chainListMap.getAllChainKeysIterator();
133
+ this._updateTexts(chainKeyIterator, textWriterIDs);
134
+ this.globe.DrawRender();
135
+ }
136
+
137
+
138
+ // ---- insertBulk
246
139
  /**
247
140
  *
248
141
  * @param {Array<chain>} data
@@ -275,7 +168,6 @@ export class CircleLineChainPlugin {
275
168
  }
276
169
 
277
170
  /**
278
- *
279
171
  * @param {{key, long, lat}} node
280
172
  * @param {*} chainKey
281
173
  * @param {*} theNodeKeyFront | node key of the next node, null places to the last
@@ -289,16 +181,6 @@ export class CircleLineChainPlugin {
289
181
  }
290
182
 
291
183
 
292
-
293
- updateNodeCoordinates(node, chainKey, { textWriterIDs = [] } = {}) {
294
- this._chainListMap.updateCoordsinatesOfNode(node, chainKey);
295
- if (textWriterIDs) this._updateTexts([chainKey], textWriterIDs);
296
- this._reconstructChains([chainKey]);
297
- this.globe.DrawRender();
298
- }
299
-
300
-
301
-
302
184
  setOpacity(opacity) {
303
185
  if (typeof opacity !== 'number') throw new Error("opacity must be a number");
304
186
  if (opacity < 0 || 1 < opacity) throw new Error("opacity must be between 0-1");
@@ -349,14 +231,126 @@ export class CircleLineChainPlugin {
349
231
  }
350
232
 
351
233
 
352
- updateText(textWriterIDs) {
353
- const chainKeyIterator = this._chainListMap.getAllChainKeysIterator();
354
- this._updateTexts(chainKeyIterator, textWriterIDs);
234
+ init(globe, gl) {
235
+ this.gl = gl;
236
+ this.globe = globe
237
+ this._initOrchestrations()
355
238
  }
356
239
 
357
-
358
240
  // implicit
359
241
 
242
+ _checktextWritersMap(textWritersMap) {
243
+ if (!(textWritersMap instanceof Map)) throw new Error("textWritersMap is not an instance of Map");
244
+ textWritersMap.forEach((v) => {
245
+ if (!(v instanceof ContextTextWriter3)) throw new Error("textWritersMap element is not an instance of ContextTextWriter3");
246
+ });
247
+ }
248
+
249
+ _initOrchestrations() {
250
+ const { gl, globe } = this;
251
+ this.lineProgram = LineOnGlobeCache.get(globe);
252
+ this.circleProgram2d = CircleCache.get(globe);
253
+ this.circle3DProgram = Circle3DCache.get(globe);
254
+
255
+ // this.lineToTheOriginProgram = LineToTheOriginCache.get(globe);
256
+ const _circleFlatEdgeCount = this._circleFlatEdgeCount;
257
+ {
258
+ // createBuffers
259
+ const bufferType = "DYNAMIC_DRAW";
260
+ const initialCapacity = this.bufferOrchestrator.capacity;
261
+ this.bufferManagersCompMap = new Map(
262
+ [
263
+ ["centerCoords2d", {
264
+ 'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
265
+ 'adaptor': (item) => new Float32Array(globe.api_GetMercator2DPoint(item.long, item.lat)),
266
+ }],
267
+ ["centerCoords3d", {
268
+ 'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
269
+ 'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.long, item.lat, 0, 0)),
270
+ }],
271
+ ["targetCoords2d", {
272
+ 'bufferManager': new BufferManager(gl, 2, { bufferType, initialCapacity }),
273
+ 'adaptor': (item) => new Float32Array(globe.api_GetMercator2DPoint(item.targetLong, item.targetLat)),
274
+ }],
275
+ ["targetCoords3d", {
276
+ 'bufferManager': new BufferManager(gl, 3, { bufferType, initialCapacity }),
277
+ 'adaptor': (item) => new Float32Array(globe.api_GetCartesian3DPoint(item.targetLong, item.targetLat, 0, 0)),
278
+ }],
279
+ ["rgba", {
280
+ 'bufferManager': new BufferManager(gl, 4, { bufferType, initialCapacity }),
281
+ 'adaptor': (item) => {
282
+ if (item.lineProperties?.rgba) return new Float32Array(item.lineProperties.rgba);
283
+ return new Float32Array(item.chainProperties.rgba);
284
+ }
285
+ }],
286
+ ["bigRadius", {
287
+ 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
288
+ 'adaptor': (item) => new Float32Array([item.bigRadius])
289
+ }],
290
+ ["dashRatio", {
291
+ 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
292
+ 'adaptor': (item) => new Float32Array([item.chainProperties.dashRatio])
293
+ }],
294
+ ["dashOpacity", {
295
+ 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
296
+ 'adaptor': (item) => new Float32Array([item.chainProperties.dashOpacity])
297
+ }],
298
+ ["circleDashAngle", {
299
+ 'bufferManager': new BufferManager(gl, 1, { bufferType, initialCapacity }),
300
+ 'adaptor': (item) => {
301
+ if (item.circleProperties?.circleDashAngle) return new Float32Array([item.circleProperties.circleDashAngle / 360]);
302
+ return new Float32Array([item.chainProperties.circleDashAngle / 360]);
303
+ }
304
+ }],
305
+ ["rgbaCircle", {
306
+ "bufferManager": new BufferManager(gl, 4, { bufferType, initialCapacity }),
307
+ "adaptor": (item) => {
308
+ if (item.circleProperties?.rgba) return new Float32Array(item.circleProperties.rgba);
309
+ return new Float32Array(item.chainProperties.rgba);
310
+ }
311
+ }],
312
+ // Mercator buffers
313
+ ["circleDashAngleMercator", {
314
+ 'bufferManager': new BufferManager(gl, 1 * _circleFlatEdgeCount, { bufferType, initialCapacity }),
315
+ 'adaptor': (item) => {
316
+ if (item.circleProperties?.circleDashAngle) return new Float32Array([item.circleProperties.circleDashAngle / 360]);
317
+ return populateFloat32Array.fillFloat32Array(_circleFlatEdgeCount, item.chainProperties.circleDashAngle / 360);
318
+ }
319
+ }],
320
+ ["rgbaCircleMercator", { // 62
321
+ "bufferManager": new BufferManager(gl, 4 * _circleFlatEdgeCount, { bufferType, initialCapacity }),
322
+ "adaptor": (item) => {
323
+ if (item.circleProperties?.rgba) return populateFloat32Array.fillWithListData(_circleFlatEdgeCount, item.circleProperties.rgba);
324
+ return populateFloat32Array.fillWithListData(_circleFlatEdgeCount, item.chainProperties.rgba);
325
+ }
326
+ }],
327
+ ["dashOpacityMercator", {
328
+ 'bufferManager': new BufferManager(gl, 1 * _circleFlatEdgeCount, { bufferType, initialCapacity }),
329
+ 'adaptor': (item) => populateFloat32Array.fillFloat32Array(_circleFlatEdgeCount, item.chainProperties.dashOpacity)
330
+ }],
331
+ ["centerCoords2dMercator", {
332
+ 'bufferManager': new BufferManager(gl, 2 * _circleFlatEdgeCount, { bufferType, initialCapacity }),
333
+ 'adaptor': (item) => item.centerCoords2dflat,
334
+ }],
335
+ ]
336
+ );
337
+ const obj = function (bufferManagerComp) {
338
+ return { 'buffer': bufferManagerComp.bufferManager.buffer, 'stride': 0, 'offset': 0 }
339
+ };
340
+ this.lineVao = this.lineProgram.createVAO(
341
+ ...['centerCoords2d', 'centerCoords3d', 'targetCoords2d', 'targetCoords3d', 'dashRatio', 'dashOpacity', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
342
+ this.circleVao2d = this.circleProgram2d.createVAO(
343
+ ...["centerCoords2dMercator", "rgbaCircleMercator", "circleDashAngleMercator", "dashOpacityMercator"].map(key => obj(this.bufferManagersCompMap.get(key))));
344
+ this.circle3DVao = this.circle3DProgram.createVAO(
345
+ ...["centerCoords3d", "bigRadius", "rgbaCircle", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key)))
346
+ );
347
+
348
+ }
349
+
350
+ }
351
+
352
+
353
+
360
354
  _updateTexts(chainKeys, textWriterIDs) {
361
355
  if (textWriterIDs.length === 0) return;
362
356
  const textWriters = textWriterGetOrThrow(this._textWritersMap, textWriterIDs)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.6.31-a",
3
+ "version": "0.6.34",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -48,7 +48,8 @@ export default class
48
48
  const { gl } = this;
49
49
  const ubo = gl.createBuffer();
50
50
  gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
51
- gl.bufferData(gl.UNIFORM_BUFFER, 184, gl.STREAM_DRAW);
51
+ // 184 bytes in reality. Overflow on linux for some reason. So, 200 bytes.
52
+ gl.bufferData(gl.UNIFORM_BUFFER, 200, gl.STREAM_DRAW);
52
53
  gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, ubo);
53
54
  gl.bindBuffer(gl.UNIFORM_BUFFER, null);
54
55
  return ubo;
@@ -0,0 +1,80 @@
1
+ import { latLongToPixelXY } from "../util";
2
+
3
+
4
+
5
+ /**
6
+ * @param {Array.<Array.<number>>} coordinates
7
+ * @param {Array.<number>} timestamps
8
+ * @param {Array.<String>} styleGroupNameArray
9
+ * @param {Object.<string, TrackStyleGroup>} _groupColorMap
10
+ * @param {Float32Array} floatArray
11
+ * @param {number} offset
12
+ *
13
+ * create floatArray with createFloat32Array before calling this function.
14
+ * start offset from 0.
15
+ * feed the floatArray with a track data and offset that is returned from the previous call.
16
+ */
17
+ function featuresToLineStringData(data) {
18
+ /**
19
+ * features are the tracks
20
+ * feature[i].geometry.coordinates are the points of the track
21
+ * feature[i].properties.messageTime are the timestamps of the points
22
+ *
23
+ */
24
+ const features = data.features;
25
+ let size = data.features.length - 1;
26
+
27
+ let startTime = features[0].properties.messageTime[0];
28
+ let endTime = features[0].properties.messageTime[features[0].properties.messageTime.length - 1];
29
+
30
+ for (let feature of features) {
31
+ size += feature.properties.messageTime.length;
32
+ startTime = Math.min(startTime, feature.properties.messageTime[0]);
33
+ endTime = Math.max(endTime, feature.properties.messageTime[feature.properties.messageTime.length - 1]);
34
+ }
35
+ const array = new Float32Array(size * 9);
36
+ let offset = 0;
37
+
38
+ {
39
+ const feature = features[0];
40
+ const coordinates = feature.geometry.coordinates;
41
+ const timestamps = feature.properties.messageTime.map((time) => (time - startTime) / 1000);
42
+ offset = fillSliceOfFloat32ArrayLineStrip(array, offset, coordinates, timestamps);
43
+ }
44
+ for (let i = 1; i < features.length; i++) {
45
+ const feature = features[i];
46
+ const coordinates = feature.geometry.coordinates;
47
+ const timestamps = feature.properties.messageTime.map((time) => (time - startTime) / 1000);
48
+ offset = addCuttingPointLineStrip(array, offset);
49
+ offset = fillSliceOfFloat32ArrayLineStrip(array, offset, coordinates, timestamps);
50
+ }
51
+
52
+ return { data: array, startTime, endTime };
53
+ }
54
+
55
+
56
+ function fillSliceOfFloat32ArrayLineStrip(floatArray, offset, coordinates, timestamps, { styleGroupNameArray = null, groupColorFunction = () => [Math.random(), Math.random(), Math.random()] } = {}) {
57
+ const startTime = timestamps[0];
58
+ const endTime = timestamps[timestamps.length - 1];
59
+ for (let i = 0; i < coordinates.length; i++) {
60
+ const time = timestamps[i];
61
+ const coord = coordinates[i];
62
+ const styleGroupName = styleGroupNameArray ? styleGroupNameArray[i] : "default";
63
+ const { x, y } = latLongToPixelXY(coord[1], coord[0]);
64
+ const z = coord[2] ? coord[2] / 1000.0 : 0;
65
+ floatArray.set([x, y, z, time, ...groupColorFunction(styleGroupName), startTime, endTime], offset);
66
+ offset += 9;
67
+ }
68
+ return offset;
69
+ }
70
+
71
+ function addCuttingPointLineStrip(floatArray, offset) {
72
+ floatArray.set([0, 0, 0, 0, -1.0, -1.0, -1.0, 0, 0], offset);
73
+ return offset + 9;
74
+ }
75
+
76
+
77
+
78
+
79
+
80
+ export { addCuttingPointLineStrip, featuresToLineStringData, fillSliceOfFloat32ArrayLineStrip, latLongToPixelXY };
@@ -1,3 +1,6 @@
1
1
  import TimeTracks from './plugin';
2
2
  import { Adaptor, fillSliceOfFloat32Array, createFloat32Array } from './adaptors';
3
- export { Adaptor, fillSliceOfFloat32Array, createFloat32Array, TimeTracks };
3
+
4
+ import TimeTracksLineStrip from './plugin-line-strip';
5
+ import { addCuttingPointLineStrip, featuresToLineStringData, fillSliceOfFloat32ArrayLineStrip, latLongToPixelXY } from './adaptors-line-strip';
6
+ export { Adaptor, fillSliceOfFloat32Array, createFloat32Array, TimeTracks, TimeTracksLineStrip, addCuttingPointLineStrip, featuresToLineStringData, fillSliceOfFloat32ArrayLineStrip, latLongToPixelXY };