@pirireis/webglobeplugins 0.15.18-alpha → 0.15.20-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.15.18-alpha",
3
+ "version": "0.15.20-alpha",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT",
@@ -14,7 +14,7 @@ const _0vec3 = /* @__PURE__ */ [0, 0, 0];
14
14
  * @typedef {Array<Point>, rgba, trackID} Track
15
15
  */
16
16
  class PointTracksPlugin {
17
- constructor(id, { pointSize = 2, hoveredPointSize = 4, selectionPointFilling = 4, opacity = 1.0, objectStoreExtraParameters = ["long", "lat", "height"] } = {}) {
17
+ constructor(id, { pointSize = 2, hoveredPointSize = 4, selectionPointFilling = 4, opacity = 1.0, objectStoreExtraParameters = ["long", "lat", "height"], initialCapacity = 10000000 } = {}) {
18
18
  this.id = id;
19
19
  this._isFreed = false;
20
20
  this._pointProgram = null;
@@ -38,6 +38,7 @@ class PointTracksPlugin {
38
38
  this._objectStoreExtraParametersFiltered = objectStoreExtraParameters.filter(param => {
39
39
  return !["long", "lat", "height", "ID", "trackID"].includes(param);
40
40
  });
41
+ this._bufferOrchestrator = new BufferOrchestrator({ capacity: initialCapacity });
41
42
  }
42
43
  init(globe, gl) {
43
44
  this.globe = globe;
@@ -49,9 +50,8 @@ class PointTracksPlugin {
49
50
  }
50
51
  _initBufferManagers() {
51
52
  const { gl } = this;
52
- const initialCapacity = 10;
53
+ const initialCapacity = this._bufferOrchestrator.capacity;
53
54
  const bufferType = "DYNAMIC_DRAW";
54
- this._bufferOrchestrator = new BufferOrchestrator({ initialCapacity });
55
55
  this._bufferManagersMap = new Map([
56
56
  ["pos3D", {
57
57
  bufferManager: new BufferManager(gl, 3, { bufferType, initialCapacity }),
@@ -224,12 +224,19 @@ class PointTracksPlugin {
224
224
  return;
225
225
  this._isFreed = true;
226
226
  this._pickerDisplayer.free();
227
+ this._tracksToPointMap.clear();
227
228
  PointOnGlobeProgramCache.release(this.globe);
228
229
  this.gl.deleteBuffer(this._focusParams.elementBuffer);
229
230
  this._bufferManagersMap.forEach(({ bufferManager, adaptor }) => bufferManager.free());
230
231
  }
231
232
  draw3D() {
232
233
  const { gl, _pointProgram, _pickerDisplayer, _bufferOrchestrator, _vao } = this;
234
+ if (!gl) {
235
+ throw new Error("GL is not loaded, PointTracks Plugin");
236
+ }
237
+ if (this._isFreed) {
238
+ throw new Error("Plugin is unregistered, PointTracks Plugin");
239
+ }
233
240
  this.resize();
234
241
  _pickerDisplayer.bindFBO();
235
242
  _pickerDisplayer.clearTextures();
@@ -270,13 +277,17 @@ class PointTracksPlugin {
270
277
  const trackID = track.trackID;
271
278
  const points = track.points;
272
279
  if (!this._tracksToPointsMap.has(trackID)) {
273
- this._tracksToPointsMap.set(trackID, []); // TODO: alternative to Set?
274
- // this._tracksToPointsMap.set(trackID, new Set()); // TODO: alternative to Set?
280
+ this._tracksToPointsMap.set(trackID, new Set());
275
281
  }
276
- const pointList = this._tracksToPointsMap.get(trackID);
282
+ const pointSet = this._tracksToPointsMap.get(trackID);
277
283
  for (let p = 0; p < points.length; p++) {
278
284
  const pointID = points[p].ID;
279
- pointList.push(pointID);
285
+ if (!pointSet.has(pointID)) {
286
+ pointSet.add(pointID);
287
+ }
288
+ else {
289
+ console.warn(`Point with ID ${pointID} already exists in track ${trackID}. Skipping duplicate.`);
290
+ }
280
291
  }
281
292
  }
282
293
  }
@@ -286,15 +297,22 @@ class PointTracksPlugin {
286
297
  }
287
298
  }
288
299
  _deletePointsFromTracksMap(trackID, pointIDs) {
289
- const trackSet = this._tracksToPointsMap.get(trackID);
290
- const pointList = new Set(pointIDs);
291
- const newList = [];
292
- for (const pointID of trackSet) {
293
- if (!pointList.has(pointID)) {
294
- newList.push(pointID);
300
+ const trackIDs = this._tracksToPointsMap.get(trackID);
301
+ if (trackIDs === undefined) {
302
+ console.warn(`Track with ID ${trackID} not found.`);
303
+ return;
304
+ }
305
+ for (const pointID of pointIDs) {
306
+ if (!trackIDs.has(pointID)) {
307
+ console.warn(`Point with ID ${pointID} not found in track ${trackID}.`);
308
+ }
309
+ else {
310
+ trackIDs.delete(pointID);
295
311
  }
296
312
  }
297
- this._tracksToPointsMap.set(trackID, newList);
313
+ if (trackIDs.size === 0) {
314
+ this._tracksToPointsMap.delete(trackID);
315
+ }
298
316
  }
299
317
  _selfSelect() {
300
318
  const { globe } = this;
@@ -324,6 +342,9 @@ class PointTracksPlugin {
324
342
  for (const pointID of pointList) {
325
343
  const key = keyMethod(trackID, pointID);
326
344
  const index = this._bufferOrchestrator.offsetMap.get(key);
345
+ if (index === undefined) {
346
+ throw new Error;
347
+ }
327
348
  indexes.push(index);
328
349
  length++;
329
350
  }
@@ -63,8 +63,6 @@ export class BufferManager {
63
63
  insertConsecutiveBulk(items, offset, adapter, Constructor = Float32Array) {
64
64
  const { gl, buffer, itemSize } = this;
65
65
  const cpuBuffer = new Constructor(itemSize * items.length);
66
- console.log('cpuBuffer', cpuBuffer);
67
- console.log(typeof cpuBuffer);
68
66
  for (let i = 0; i < items.length; i++) {
69
67
  cpuBuffer.set(adapter(items[i]), i * itemSize);
70
68
  }