@pirireis/webglobeplugins 1.2.21 → 1.2.23

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": "1.2.21",
3
+ "version": "1.2.23",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT",
@@ -178,7 +178,6 @@ function sendToSubWorker(wrapper) {
178
178
  wrapper.lastBBOXData === null &&
179
179
  !_stateChanged)
180
180
  return false;
181
- _stateChanged = false;
182
181
  wrapper.inProgress = true;
183
182
  wrapper.worker.postMessage({
184
183
  pickableState: _pickableState,
@@ -195,11 +194,16 @@ function triggerAllWorkers() {
195
194
  // If a batch is already running, do not start another one.
196
195
  if (_batchInFlight)
197
196
  return;
197
+ const shouldClearStateChanged = _stateChanged;
198
198
  let dispatched = 0;
199
199
  for (const w of _workers) {
200
200
  if (sendToSubWorker(w))
201
201
  dispatched++;
202
202
  }
203
+ // Only clear after we've attempted dispatching to all workers,
204
+ // so every worker can observe the new state.
205
+ if (shouldClearStateChanged)
206
+ _stateChanged = false;
203
207
  // Start barrier only if we actually dispatched work.
204
208
  if (dispatched > 0) {
205
209
  _batchInFlight = true;
@@ -15,6 +15,7 @@ export class TerrainPolygonSemiPlugin {
15
15
  pickable: false,
16
16
  pickablePause: false,
17
17
  variativeColorsOn: false,
18
+ useDepthTestOnExceedingTiltThresholdAngle: false,
18
19
  polygonStyle: {
19
20
  defaultColor: [0.5, 0.5, 1, 1],
20
21
  changeColorOnHover: true,
@@ -249,6 +250,13 @@ export class TerrainPolygonSemiPlugin {
249
250
  this._uboForRealEdgeArcs?.updateSingle("opacity", this._effectiveOpacity("edgeArc"));
250
251
  this.globe.DrawRender();
251
252
  }
253
+ setUseDepthTestOnExceedingTiltThresholdAngle(state) {
254
+ const oldState = this._options.useDepthTestOnExceedingTiltThresholdAngle;
255
+ if (oldState === state)
256
+ return;
257
+ this._options.useDepthTestOnExceedingTiltThresholdAngle = state;
258
+ this.globe.DrawRender();
259
+ }
252
260
  setChangeColorOnHoverState(state, target = "polygon") {
253
261
  const oldState = this._options[`${target}Style`].changeHoverColor;
254
262
  if (oldState === state)
@@ -270,30 +278,6 @@ export class TerrainPolygonSemiPlugin {
270
278
  this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([state ? 0.0 : 1.0]));
271
279
  this.globe.DrawRender();
272
280
  }
273
- setPickableState(state) {
274
- throw new Error("setPickableState is buggy. use setPausePickableState instead.");
275
- const oldState = this._options.pickable;
276
- if (oldState === state)
277
- return;
278
- if (oldState === false && state === true) {
279
- this._pickIndexBuffer = this.globe.gl.createBuffer();
280
- this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([1.0]));
281
- this._uboHandler.updateSingle("hoverColor", new Float32Array(this._options.polygonStyle.hoverColor));
282
- this._pickerDisplayer = new PickerDisplayer(this.globe, "R32I");
283
- }
284
- else if (oldState === true && state === false) {
285
- this.globe.gl.deleteBuffer(this._pickIndexBuffer);
286
- this._pickIndexBuffer = null;
287
- this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([0.0]));
288
- this._uboHandler.updateSingle("private_pickedIndex", new Float32Array([-1]));
289
- this._pickerDisplayer?.free();
290
- this._pickerDisplayer = null;
291
- this._lastPickedPolygon = null;
292
- }
293
- this._options.pickable = state;
294
- this._workerContact.setPickableState(state);
295
- this.globe.DrawRender();
296
- }
297
281
  getPickedPolygon() {
298
282
  if (this._options.pickable === false) {
299
283
  throw new Error("TerrainPolygonSemiPlugin is not pickable. Set pickable option to true on construction to enable picking.");
@@ -399,6 +383,9 @@ export class TerrainPolygonSemiPlugin {
399
383
  }
400
384
  }
401
385
  _useDepth() {
386
+ if (!this._options.useDepthTestOnExceedingTiltThresholdAngle) {
387
+ return false;
388
+ }
402
389
  const { Tilt } = this.globe.api_GetCurrentLookInfo();
403
390
  const useDepth = Tilt > DEPTH_START_ANGLE;
404
391
  if (this._lastPickedPolygon !== null && useDepth) {
@@ -408,10 +395,14 @@ export class TerrainPolygonSemiPlugin {
408
395
  }
409
396
  return useDepth;
410
397
  }
411
- getDepthStartAngle() {
398
+ getExceedingTiltThresholdAngle() {
412
399
  return DEPTH_START_ANGLE;
413
400
  }
414
401
  draw3D() {
402
+ if (!this.globe) {
403
+ console.warn("TerrainPolygonSemiPlugin.draw3D called before init");
404
+ return;
405
+ }
415
406
  const gl = this.globe.gl;
416
407
  const useDepth = this._useDepth();
417
408
  gl.enable(gl.BLEND);
@@ -496,6 +487,12 @@ export class TerrainPolygonSemiPlugin {
496
487
  }
497
488
  return targetUBO;
498
489
  }
490
+ sagUst4W(long, lat, rowSize, colSize, cellWidth = 100, cellHeight = 100, rotationAngle = 0) {
491
+ const globe = this.globe;
492
+ const data = calculateAndSetCoordinates(globe, "sol_ust", rowSize, colSize, 0, 0, 0, 0, cellWidth, cellHeight, [0.75, 0, 0, 1], rotationAngle, { long, lat });
493
+ //@ts-ignore
494
+ this.insertBulk(data);
495
+ }
499
496
  }
500
497
  function inputCheck(input) {
501
498
  if (!input.geometry || !Array.isArray(input.geometry) || input.geometry.length === 0) {
@@ -522,3 +519,111 @@ function roundTo6(n) {
522
519
  const rounded = Math.round(n * 1e6) / 1e6;
523
520
  return rounded;
524
521
  }
522
+ function calculateAndSetCoordinates(globe, startType, // n13, sol_ust, sol_alt
523
+ rowSize, // only sol_ust, sol_alt
524
+ colSize, // only sol_ust, sol_alt
525
+ topRowSize, // only n13
526
+ bottomRowSize, // only n13
527
+ leftColSize, // only n13
528
+ rightColSize, // only n13
529
+ cellWidth, cellHeight, cellColor = [0.75, 0, 0, 1], rotationAngle, // 0-360
530
+ centerCoords) {
531
+ let totalRowSize, totalColSize, startRowOffset, startColOffset;
532
+ if (startType === 'n13') {
533
+ totalRowSize = topRowSize + bottomRowSize;
534
+ totalColSize = leftColSize + rightColSize;
535
+ startRowOffset = -topRowSize;
536
+ startColOffset = -leftColSize;
537
+ }
538
+ else if (startType === 'sol_ust') {
539
+ totalRowSize = rowSize;
540
+ totalColSize = colSize;
541
+ startRowOffset = 0;
542
+ startColOffset = 0;
543
+ }
544
+ else if (startType === 'sol_alt') {
545
+ totalRowSize = rowSize;
546
+ totalColSize = colSize;
547
+ startRowOffset = -rowSize;
548
+ startColOffset = 0;
549
+ }
550
+ else {
551
+ return;
552
+ }
553
+ const toRightAngle = 90 - rotationAngle;
554
+ const toBottomAngle = 180 - rotationAngle;
555
+ const toTopAngle = 0 - rotationAngle;
556
+ const toLeftAngle = 270 - rotationAngle;
557
+ // Traverses each cell (and 1 extra row) and:
558
+ // 3. Population of terrain polygon semi-plugin (tpsp) data
559
+ // Initialize flatArray
560
+ const coordsLength = (totalRowSize + 1) * (totalColSize + 1); // e.g. 3x5 grid has (3+1)*(5+1) = 24 coords (vertices)
561
+ const flatArray = Array(coordsLength);
562
+ // Calculate all vertex positions from center
563
+ for (let rowIndex = 0; rowIndex < totalRowSize + 1; rowIndex++) {
564
+ for (let colIndex = 0; colIndex < totalColSize + 1; colIndex++) {
565
+ const vertexIndex = rowIndex * (totalColSize + 1) + colIndex;
566
+ // Calculate offset from center in terms of cells
567
+ const rowOffsetFromCenter = startRowOffset + rowIndex;
568
+ const colOffsetFromCenter = startColOffset + colIndex;
569
+ // Calculate the actual position
570
+ // First move vertically from center
571
+ const verticalDistance = Math.abs(rowOffsetFromCenter) * cellHeight;
572
+ const verticalAngle = rowOffsetFromCenter < 0 ? toTopAngle : toBottomAngle;
573
+ let coords;
574
+ if (rowOffsetFromCenter === 0) {
575
+ coords = { ...centerCoords };
576
+ }
577
+ else {
578
+ coords = globe.Math.FindPointByPolar(centerCoords.long, centerCoords.lat, verticalDistance, verticalAngle);
579
+ }
580
+ // Then move horizontally
581
+ if (colOffsetFromCenter !== 0) {
582
+ const horizontalDistance = Math.abs(colOffsetFromCenter) * cellWidth;
583
+ const horizontalAngle = colOffsetFromCenter < 0 ? toLeftAngle : toRightAngle;
584
+ coords = globe.Math.FindPointByPolar(coords.long, coords.lat, horizontalDistance, horizontalAngle);
585
+ }
586
+ flatArray[vertexIndex] = { ...coords };
587
+ }
588
+ }
589
+ // Initialize tpspData array
590
+ const tpspData = [];
591
+ // Populate cells using the pre-calculated vertex positions
592
+ for (let rowIndex = 0; rowIndex < totalRowSize; rowIndex++) {
593
+ for (let colIndex = 0; colIndex < totalColSize; colIndex++) {
594
+ const cellIndex = rowIndex * totalColSize + colIndex;
595
+ // ******************************************** //
596
+ // * 1. Get coordinates from flatArray * //
597
+ // ******************************************** //
598
+ const tlCoordsIndex = rowIndex * (totalColSize + 1) + colIndex;
599
+ const trCoordsIndex = tlCoordsIndex + 1;
600
+ const blCoordsIndex = (rowIndex + 1) * (totalColSize + 1) + colIndex;
601
+ const brCoordsIndex = blCoordsIndex + 1;
602
+ const tlCoords = flatArray[tlCoordsIndex];
603
+ const trCoords = flatArray[trCoordsIndex];
604
+ const blCoords = flatArray[blCoordsIndex];
605
+ const brCoords = flatArray[brCoordsIndex];
606
+ tpspData.push({
607
+ key: cellIndex + Date.now().toString(),
608
+ geometry: [
609
+ {
610
+ vertices: [
611
+ tlCoords.long,
612
+ tlCoords.lat,
613
+ trCoords.long,
614
+ trCoords.lat,
615
+ brCoords.long,
616
+ brCoords.lat,
617
+ blCoords.long,
618
+ blCoords.lat,
619
+ ],
620
+ holes: [],
621
+ },
622
+ ],
623
+ color: cellColor,
624
+ });
625
+ }
626
+ }
627
+ // Bulk insert cell data to terrain polygon semi-plugin
628
+ return tpspData;
629
+ }