@openglobus/og 0.18.4 → 0.19.0

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 (64) hide show
  1. package/README.md +19 -68
  2. package/css/og.css +308 -45
  3. package/lib/@openglobus/og.css +1 -1
  4. package/lib/@openglobus/og.esm.js +1 -1
  5. package/lib/@openglobus/og.esm.js.map +1 -1
  6. package/lib/@openglobus/og.umd.js +1 -1
  7. package/lib/@openglobus/og.umd.js.map +1 -1
  8. package/lib/js/Globe.d.ts +2 -0
  9. package/lib/js/Globe.js +3 -1
  10. package/lib/js/camera/PlanetCamera.d.ts +2 -2
  11. package/lib/js/camera/PlanetCamera.js +3 -2
  12. package/lib/js/control/DebugInfo.js +5 -0
  13. package/lib/js/control/EarthCoordinates.js +2 -2
  14. package/lib/js/control/LayerSwitcher.d.ts +18 -3
  15. package/lib/js/control/LayerSwitcher.js +111 -11
  16. package/lib/js/control/MouseNavigation.d.ts +2 -0
  17. package/lib/js/control/MouseNavigation.js +15 -15
  18. package/lib/js/control/elevationProfile/ElevationProfile.d.ts +41 -25
  19. package/lib/js/control/elevationProfile/ElevationProfile.js +106 -75
  20. package/lib/js/control/elevationProfile/ElevationProfileButtonsView.d.ts +14 -0
  21. package/lib/js/control/elevationProfile/ElevationProfileButtonsView.js +61 -0
  22. package/lib/js/control/elevationProfile/ElevationProfileControl.d.ts +33 -0
  23. package/lib/js/control/elevationProfile/ElevationProfileControl.js +153 -0
  24. package/lib/js/control/elevationProfile/ElevationProfileLegend.d.ts +20 -0
  25. package/lib/js/control/elevationProfile/ElevationProfileLegend.js +82 -0
  26. package/lib/js/control/elevationProfile/ElevationProfileScene.d.ts +80 -0
  27. package/lib/js/control/elevationProfile/ElevationProfileScene.js +539 -0
  28. package/lib/js/control/elevationProfile/ElevationProfileView.d.ts +63 -0
  29. package/lib/js/control/elevationProfile/ElevationProfileView.js +504 -0
  30. package/lib/js/control/elevationProfile/PointListDialog.d.ts +12 -0
  31. package/lib/js/control/elevationProfile/PointListDialog.js +57 -0
  32. package/lib/js/control/heightRuler/HeightRulerScene.js +1 -1
  33. package/lib/js/control/index.d.ts +2 -1
  34. package/lib/js/control/index.js +2 -1
  35. package/lib/js/control/ruler/RulerScene.js +3 -3
  36. package/lib/js/control/selection/SelectionScene.js +2 -2
  37. package/lib/js/entity/Entity.js +5 -1
  38. package/lib/js/entity/Polyline.js +1 -1
  39. package/lib/js/layer/GeoImage.js +3 -0
  40. package/lib/js/layer/Layer.d.ts +18 -4
  41. package/lib/js/layer/Layer.js +25 -4
  42. package/lib/js/layer/XYZ.d.ts +0 -1
  43. package/lib/js/quadTree/Node.d.ts +21 -3
  44. package/lib/js/quadTree/Node.js +173 -62
  45. package/lib/js/renderer/Renderer.d.ts +0 -1
  46. package/lib/js/renderer/Renderer.js +22 -44
  47. package/lib/js/renderer/RendererEvents.d.ts +1 -0
  48. package/lib/js/renderer/RendererEvents.js +5 -7
  49. package/lib/js/scene/Planet.d.ts +33 -4
  50. package/lib/js/scene/Planet.js +206 -84
  51. package/lib/js/segment/Segment.d.ts +7 -1
  52. package/lib/js/segment/Segment.js +40 -12
  53. package/lib/js/shaders/drawnode.js +21 -2
  54. package/lib/js/shaders/geoObject.js +26 -18
  55. package/lib/js/terrain/GlobusTerrain.d.ts +3 -0
  56. package/lib/js/terrain/GlobusTerrain.js +15 -3
  57. package/lib/js/terrain/MapboxTerrain.js +29 -29
  58. package/lib/js/ui/Dialog.js +1 -1
  59. package/lib/js/utils/TerrainWorker.js +1 -1
  60. package/lib/js/utils/shared.d.ts +3 -1
  61. package/lib/js/utils/shared.js +22 -3
  62. package/package.json +2 -2
  63. package/lib/js/shaders/pickingMask.d.ts +0 -2
  64. package/lib/js/shaders/pickingMask.js +0 -22
@@ -299,7 +299,8 @@ export function drawnode_screen_wl_webgl2NoAtmos() {
299
299
  ambient: "vec3",
300
300
  specular: "vec4",
301
301
  camHeight: "float",
302
- nightTextureCoefficient: "float"
302
+ nightTextureCoefficient: "float",
303
+ transitionOpacity: "float"
303
304
  }, attributes: {
304
305
  aVertexPositionHigh: "vec3",
305
306
  aVertexPositionLow: "vec3",
@@ -373,6 +374,8 @@ export function drawnode_screen_wl_webgl2NoAtmos() {
373
374
 
374
375
  uniform int samplerCount;
375
376
  uniform float nightTextureCoefficient;
377
+
378
+ uniform float transitionOpacity;
376
379
 
377
380
  uniform float camHeight;
378
381
 
@@ -424,8 +427,10 @@ export function drawnode_screen_wl_webgl2NoAtmos() {
424
427
  vec4 lightWeighting = vec4(ambient + diffuse * diffuseLightWeighting + night, 1.0);
425
428
 
426
429
  diffuseColor = texture( defaultTexture, vTextureCoord.xy );
430
+
427
431
  if( samplerCount == 0 ) {
428
432
  diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);
433
+ diffuseColor *= transitionOpacity;
429
434
  return;
430
435
  }
431
436
 
@@ -434,29 +439,34 @@ export function drawnode_screen_wl_webgl2NoAtmos() {
434
439
  blend(diffuseColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);
435
440
  if( samplerCount == 1 ) {
436
441
  diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);
442
+ diffuseColor *= transitionOpacity;
437
443
  return;
438
444
  }
439
445
 
440
446
  blend(diffuseColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);
441
447
  if( samplerCount == 2 ) {
442
448
  diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);
449
+ diffuseColor *= transitionOpacity;
443
450
  return;
444
451
  }
445
452
 
446
453
  blend(diffuseColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);
447
454
  if( samplerCount == 3 ) {
448
455
  diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);
456
+ diffuseColor *= transitionOpacity;
449
457
  return;
450
458
  }
451
459
 
452
460
  blend(diffuseColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);
453
461
  if( samplerCount == 4 ) {
454
462
  diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);
463
+ diffuseColor *= transitionOpacity;
455
464
  return;
456
465
  }
457
466
 
458
467
  blend(diffuseColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);
459
468
  diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);
469
+ diffuseColor *= transitionOpacity;
460
470
  }`
461
471
  });
462
472
  }
@@ -486,7 +496,8 @@ export function drawnode_screen_wl_webgl2Atmos() {
486
496
  scatteringTexture: "sampler2D",
487
497
  camHeight: "float",
488
498
  nightTextureCoefficient: "float",
489
- maxMinOpacity: "vec2"
499
+ maxMinOpacity: "vec2",
500
+ transitionOpacity: "float"
490
501
  }, attributes: {
491
502
  aVertexPositionHigh: "vec3",
492
503
  aVertexPositionLow: "vec3",
@@ -566,6 +577,8 @@ export function drawnode_screen_wl_webgl2Atmos() {
566
577
 
567
578
  uniform vec2 maxMinOpacity;
568
579
  uniform float camHeight;
580
+
581
+ uniform float transitionOpacity;
569
582
 
570
583
  in vec4 vTextureCoord;
571
584
  in vec3 v_vertex;
@@ -749,6 +762,7 @@ export function drawnode_screen_wl_webgl2Atmos() {
749
762
  diffuseColor = texture( defaultTexture, vTextureCoord.xy );
750
763
  if( samplerCount == 0 ) {
751
764
  diffuseColor = mix(diffuseColor * lightWeighting, atmosColor, fadingOpacity) + vec4(spec, 0.0);
765
+ diffuseColor *= transitionOpacity;
752
766
  return;
753
767
  }
754
768
 
@@ -757,29 +771,34 @@ export function drawnode_screen_wl_webgl2Atmos() {
757
771
  blend(diffuseColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);
758
772
  if( samplerCount == 1 ) {
759
773
  diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);
774
+ diffuseColor *= transitionOpacity;
760
775
  return;
761
776
  }
762
777
 
763
778
  blend(diffuseColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);
764
779
  if( samplerCount == 2 ) {
765
780
  diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);
781
+ diffuseColor *= transitionOpacity;
766
782
  return;
767
783
  }
768
784
 
769
785
  blend(diffuseColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);
770
786
  if( samplerCount == 3 ) {
771
787
  diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);
788
+ diffuseColor *= transitionOpacity;
772
789
  return;
773
790
  }
774
791
 
775
792
  blend(diffuseColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);
776
793
  if( samplerCount == 4 ) {
777
794
  diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);
795
+ diffuseColor *= transitionOpacity;
778
796
  return;
779
797
  }
780
798
 
781
799
  blend(diffuseColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);
782
800
  diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);
801
+ diffuseColor *= transitionOpacity;
783
802
  }`
784
803
  });
785
804
  }
@@ -68,18 +68,22 @@ export const geo_object = () => new Program("geo_object", {
68
68
  vColor = aColor;
69
69
  vTexCoords = aTexCoord;
70
70
 
71
- float roll = aPitchRoll.y;
71
+ float cos_roll = cos(aPitchRoll.y);
72
+ float sin_roll = sin(aPitchRoll.y);
73
+
72
74
  mat3 rotZ = mat3(
73
- vec3(cos(roll), sin(roll), 0.0),
74
- vec3(-sin(roll), cos(roll), 0.0),
75
+ vec3(cos_roll, sin_roll, 0.0),
76
+ vec3(-sin_roll, cos_roll, 0.0),
75
77
  vec3(0.0, 0.0, 1.0)
76
78
  );
77
79
 
78
- float pitch = aPitchRoll.x;
80
+ float cos_pitch = cos(aPitchRoll.x);
81
+ float sin_pitch = sin(aPitchRoll.x);
82
+
79
83
  mat3 rotX = mat3(
80
84
  vec3(1.0, 0.0, 0.0),
81
- vec3(0.0, cos(pitch), sin(pitch)),
82
- vec3(0.0, -sin(pitch), cos(pitch))
85
+ vec3(0.0, cos_pitch, sin_pitch),
86
+ vec3(0.0, -sin_pitch, cos_pitch)
83
87
  );
84
88
 
85
89
  vec3 position = aPositionHigh + aPositionLow;
@@ -200,19 +204,23 @@ export const geo_object_picking = () => new Program("geo_object_picking", {
200
204
 
201
205
  vColor = aPickingColor;
202
206
 
203
- float roll = aPitchRoll.y;
204
- mat3 rotZ = mat3(
205
- vec3(cos(roll), sin(roll), 0.0),
206
- vec3(-sin(roll), cos(roll), 0.0),
207
- vec3(0.0, 0.0, 1.0)
208
- );
209
-
210
- float pitch = aPitchRoll.x;
211
- mat3 rotX = mat3(
212
- vec3(1.0, 0.0, 0.0),
213
- vec3(0.0, cos(pitch), sin(pitch)),
214
- vec3(0.0, -sin(pitch), cos(pitch))
207
+ float cos_roll = cos(aPitchRoll.y);
208
+ float sin_roll = sin(aPitchRoll.y);
209
+
210
+ mat3 rotZ = mat3(
211
+ vec3(cos_roll, sin_roll, 0.0),
212
+ vec3(-sin_roll, cos_roll, 0.0),
213
+ vec3(0.0, 0.0, 1.0)
215
214
  );
215
+
216
+ float cos_pitch = cos(aPitchRoll.x);
217
+ float sin_pitch = sin(aPitchRoll.x);
218
+
219
+ mat3 rotX = mat3(
220
+ vec3(1.0, 0.0, 0.0),
221
+ vec3(0.0, cos_pitch, sin_pitch),
222
+ vec3(0.0, -sin_pitch, cos_pitch)
223
+ );
216
224
 
217
225
  vec3 position = aPositionHigh + aPositionLow;
218
226
  vec3 cameraPosition = eyePositionHigh + eyePositionLow;
@@ -12,6 +12,7 @@ export interface IGlobusTerrainParams extends IEmptyTerrainParams {
12
12
  urlRewrite?: UrlRewriteFunc;
13
13
  noDataValues?: number[];
14
14
  plainGridSize?: number;
15
+ heightFactor?: number;
15
16
  }
16
17
  type TileData = {
17
18
  heights: number[] | TypedArray | null;
@@ -33,6 +34,7 @@ type UrlRewriteFunc = (segment: Segment, url: string) => string;
33
34
  * @param {string} [options.responseType="arraybuffer"] - Response type.
34
35
  * @param {number} [options.MAX_LOADING_TILES] - Maximum at one time loading tiles.
35
36
  * @param {Array.<number>} [gridSizeByZoom] - Array of values, where each value corresponds to the size of a tile(or segment) on the globe. Each value must be power of two.
37
+ * @param {number} [heightFactor=1] - Elevation height multiplier.
36
38
  *
37
39
  * @fires GlobusTerrainEvents#load
38
40
  * @fires GlobusTerrainEvents#loadend
@@ -59,6 +61,7 @@ declare class GlobusTerrain extends EmptyTerrain {
59
61
  * @type {Function} -
60
62
  */
61
63
  protected _urlRewriteCallback: UrlRewriteFunc | null;
64
+ protected _heightFactor: number;
62
65
  constructor(name?: string, options?: IGlobusTerrainParams);
63
66
  get loader(): Loader<GlobusTerrain>;
64
67
  clearCache(): void;
@@ -26,6 +26,7 @@ import { Vec3 } from "../math/Vec3";
26
26
  * @param {string} [options.responseType="arraybuffer"] - Response type.
27
27
  * @param {number} [options.MAX_LOADING_TILES] - Maximum at one time loading tiles.
28
28
  * @param {Array.<number>} [gridSizeByZoom] - Array of values, where each value corresponds to the size of a tile(or segment) on the globe. Each value must be power of two.
29
+ * @param {number} [heightFactor=1] - Elevation height multiplier.
29
30
  *
30
31
  * @fires GlobusTerrainEvents#load
31
32
  * @fires GlobusTerrainEvents#loadend
@@ -33,7 +34,7 @@ import { Vec3 } from "../math/Vec3";
33
34
  class GlobusTerrain extends EmptyTerrain {
34
35
  constructor(name = "", options = {}) {
35
36
  super({
36
- geoidSrc: "//openglobus.org/geoid/egm84-30.pgm",
37
+ geoidSrc: "https://openglobus.org/geoid/egm84-30.pgm",
37
38
  maxNativeZoom: options.maxNativeZoom || 14,
38
39
  ...options
39
40
  });
@@ -44,11 +45,15 @@ class GlobusTerrain extends EmptyTerrain {
44
45
  this.isEmpty = false;
45
46
  this.equalizeNormals = true;
46
47
  this.name = name || "openglobus";
47
- this.url = options.url || "//{s}.srtm3.openglobus.org/{z}/{y}/{x}.ddm";
48
+ this.url = options.url || "https://{s}.srtm3.openglobus.org/{z}/{y}/{x}.ddm";
48
49
  this.gridSizeByZoom = options.gridSizeByZoom || [
49
- 64, 32, 32, 16, 16, 8, 8, 8, 8, 16, 16, 16, 16, 32, 32, 16, 8, 4, 2, 2, 2, 2, 2, 2
50
+ 64, 32, 32, 16, 16, 8, 8, 8, 16, 16, 16, 32, 32, 32, 32, 16, 8, 4, 2, 2, 2, 2, 2, 2
50
51
  ];
52
+ this._heightFactor = options.heightFactor != undefined ? options.heightFactor : 1.0;
51
53
  this.noDataValues = options.noDataValues || [];
54
+ for (let i = 0; i < this.noDataValues.length; i++) {
55
+ this.noDataValues[i] *= this._heightFactor;
56
+ }
52
57
  this.plainGridSize = options.plainGridSize || 32;
53
58
  this._extent = createExtent(options.extent, new Extent(new LonLat(-180.0, -90.0), new LonLat(180.0, 90.0)));
54
59
  this._dataType = "arrayBuffer";
@@ -299,6 +304,13 @@ class GlobusTerrain extends EmptyTerrain {
299
304
  * @returns {Array.<number>} -
300
305
  */
301
306
  _createHeights(data, tileIndex, x, y, z, extent, isMaxZoom) {
307
+ if (this._heightFactor !== 1) {
308
+ let res = new Float32Array(data);
309
+ for (let i = 0, len = res.length; i < len; i++) {
310
+ res[i] = res[i] * this._heightFactor;
311
+ }
312
+ return res;
313
+ }
302
314
  return new Float32Array(data);
303
315
  }
304
316
  /**
@@ -15,17 +15,17 @@ class MapboxTerrain extends GlobusTerrain {
15
15
  super(name || "MapboxTerrain", {
16
16
  equalizeVertices: options.equalizeVertices != undefined ? options.equalizeVertices : true,
17
17
  maxZoom: options.maxZoom || 17,
18
+ noDataValues: options.noDataValues || [-65537, -10000],
19
+ plainGridSize: options.plainGridSize || 128,
20
+ url: options.url != undefined
21
+ ? options.url
22
+ : `//api.mapbox.com/v4/mapbox.terrain-rgb/{z}/{x}/{y}.pngraw?access_token=${options.key || KEY}`,
23
+ gridSizeByZoom: options.gridSizeByZoom || [
24
+ 64, 32, 16, 8, 8, 8, 8, 16, 16, 16, 16, 16, 32, 16, 32, 16, 32, 16, 32, 16, 8, 4
25
+ ],
18
26
  ...options
19
27
  });
20
28
  this.equalizeNormals = options.equalizeNormals || false;
21
- this.gridSizeByZoom = options.gridSizeByZoom || [
22
- 64, 32, 16, 8, 8, 8, 8, 16, 16, 16, 16, 16, 32, 16, 32, 16, 32, 16, 32, 16, 8, 4
23
- ];
24
- this.url = options.url != undefined
25
- ? options.url
26
- : `//api.mapbox.com/v4/mapbox.terrain-rgb/{z}/{x}/{y}.pngraw?access_token=${options.key || KEY}`;
27
- this.noDataValues = options.noDataValues || [-65537, -10000];
28
- this.plainGridSize = options.plainGridSize || 128;
29
29
  this._dataType = "imageBitmap";
30
30
  this._imageSize = options.imageSize || 256;
31
31
  this._ctx = this._createTemporalCanvas(this._imageSize);
@@ -52,7 +52,7 @@ class MapboxTerrain extends GlobusTerrain {
52
52
  //
53
53
  if (!isPowerOfTwo(this._imageSize) && SIZE === this._imageSize) {
54
54
  let outCurrenElevations = new Float32Array(SIZE * SIZE);
55
- extractElevationTilesMapboxNonPowerOfTwo(rgbaData, outCurrenElevations);
55
+ extractElevationTilesMapboxNonPowerOfTwo(rgbaData, outCurrenElevations, this._heightFactor);
56
56
  return outCurrenElevations;
57
57
  }
58
58
  if (this._imageSize === this.plainGridSize) {
@@ -61,22 +61,22 @@ class MapboxTerrain extends GlobusTerrain {
61
61
  for (let k = 0, len = this._imageSize * this._imageSize; k < len; k++) {
62
62
  let j = k % this._imageSize, i = Math.floor(k / this._imageSize);
63
63
  let fromInd4 = k * 4;
64
- let h = rgb2Height(rgbaData[fromInd4], rgbaData[fromInd4 + 1], rgbaData[fromInd4 + 2]);
64
+ let h = this._heightFactor * rgb2Height(rgbaData[fromInd4], rgbaData[fromInd4 + 1], rgbaData[fromInd4 + 2]);
65
65
  outCurrenElevations[i * (this._imageSize + 1) + j] = h;
66
66
  }
67
67
  for (let i = 0, len = this._imageSize; i < len; i++) {
68
68
  let j = this._imageSize - 1;
69
69
  let fromInd4 = (i * this._imageSize + j) * 4;
70
- let h = rgb2Height(rgbaData[fromInd4], rgbaData[fromInd4 + 1], rgbaData[fromInd4 + 2]);
70
+ let h = this._heightFactor * rgb2Height(rgbaData[fromInd4], rgbaData[fromInd4 + 1], rgbaData[fromInd4 + 2]);
71
71
  outCurrenElevations[i * (this._imageSize + 1) + this._imageSize] = h;
72
72
  }
73
73
  for (let j = 0, len = this._imageSize; j < len; j++) {
74
74
  let i = this._imageSize - 1;
75
75
  let fromInd4 = (i * this._imageSize + j) * 4;
76
- let h = rgb2Height(rgbaData[fromInd4], rgbaData[fromInd4 + 1], rgbaData[fromInd4 + 2]);
76
+ let h = this._heightFactor * rgb2Height(rgbaData[fromInd4], rgbaData[fromInd4 + 1], rgbaData[fromInd4 + 2]);
77
77
  outCurrenElevations[this._imageSize * (this._imageSize + 1) + j] = h;
78
78
  }
79
- let h = rgb2Height(rgbaData[rgbaData.length - 4], rgbaData[rgbaData.length - 3], rgbaData[rgbaData.length - 2]);
79
+ let h = this._heightFactor * rgb2Height(rgbaData[rgbaData.length - 4], rgbaData[rgbaData.length - 3], rgbaData[rgbaData.length - 2]);
80
80
  outCurrenElevations[outCurrenElevations.length - 1] = h;
81
81
  return outCurrenElevations;
82
82
  }
@@ -94,10 +94,10 @@ class MapboxTerrain extends GlobusTerrain {
94
94
  }
95
95
  }
96
96
  if (preventChildren) {
97
- extractElevationTilesMapboxNoChildren(rgbaData, this.noDataValues, outCurrenElevations);
97
+ extractElevationTilesMapboxNoChildren(rgbaData, this._heightFactor, this.noDataValues, outCurrenElevations);
98
98
  }
99
99
  else {
100
- extractElevationTilesMapbox(rgbaData, this.noDataValues, outCurrenElevations, outChildrenElevations);
100
+ extractElevationTilesMapbox(rgbaData, this._heightFactor, this.noDataValues, outCurrenElevations, outChildrenElevations);
101
101
  }
102
102
  this._elevationCache[tileIndex] = {
103
103
  heights: outCurrenElevations,
@@ -129,7 +129,7 @@ class MapboxTerrain extends GlobusTerrain {
129
129
  let index = (i * this._imageSize + j) * 4;
130
130
  if (this._imageDataCache[tileIndex]) {
131
131
  let data = this._imageDataCache[tileIndex];
132
- callback(rgb2Height(data[index], data[index + 1], data[index + 2]));
132
+ callback(this._heightFactor * rgb2Height(data[index], data[index + 1], data[index + 2]));
133
133
  return true;
134
134
  }
135
135
  if (!this._fetchCache[tileIndex]) {
@@ -145,7 +145,7 @@ class MapboxTerrain extends GlobusTerrain {
145
145
  this._ctx.drawImage(response.data, 0, 0);
146
146
  let data = this._ctx.getImageData(0, 0, 256, 256).data;
147
147
  this._imageDataCache[tileIndex] = data;
148
- callback(rgb2Height(data[index], data[index + 1], data[index + 2]));
148
+ callback(this._heightFactor * rgb2Height(data[index], data[index + 1], data[index + 2]));
149
149
  }
150
150
  else if (response.status === "error") {
151
151
  callback(0);
@@ -159,13 +159,13 @@ class MapboxTerrain extends GlobusTerrain {
159
159
  return false;
160
160
  }
161
161
  }
162
- function extractElevationTilesMapboxNonPowerOfTwo(rgbaData, outCurrenElevations) {
162
+ function extractElevationTilesMapboxNonPowerOfTwo(rgbaData, outCurrenElevations, heightFactor = 1) {
163
163
  for (let i = 0, len = outCurrenElevations.length; i < len; i++) {
164
164
  let i4 = i * 4;
165
- outCurrenElevations[i] = rgb2Height(rgbaData[i4], rgbaData[i4 + 1], rgbaData[i4 + 2]);
165
+ outCurrenElevations[i] = heightFactor * rgb2Height(rgbaData[i4], rgbaData[i4 + 1], rgbaData[i4 + 2]);
166
166
  }
167
167
  }
168
- function extractElevationTilesMapbox(rgbaData, noDataValues, outCurrenElevations, outChildrenElevations) {
168
+ function extractElevationTilesMapbox(rgbaData, heightFactor, noDataValues, outCurrenElevations, outChildrenElevations) {
169
169
  let destSize = Math.sqrt(outCurrenElevations.length) - 1;
170
170
  let destSizeOne = destSize + 1;
171
171
  let sourceSize = Math.sqrt(rgbaData.length / 4);
@@ -173,7 +173,7 @@ function extractElevationTilesMapbox(rgbaData, noDataValues, outCurrenElevations
173
173
  let rightHeight = 0, bottomHeight = 0, sourceSize4 = 0;
174
174
  for (let k = 0, currIndex = 0, sourceDataLength = rgbaData.length / 4; k < sourceDataLength; k++) {
175
175
  let k4 = k * 4;
176
- let height = rgb2Height(rgbaData[k4], rgbaData[k4 + 1], rgbaData[k4 + 2]);
176
+ let height = heightFactor * rgb2Height(rgbaData[k4], rgbaData[k4 + 1], rgbaData[k4 + 2]);
177
177
  let isNoDataCurrent = MapboxTerrain.checkNoDataValue(noDataValues, height), isNoDataRight = false, isNoDataBottom = false;
178
178
  let i = Math.floor(k / sourceSize), j = k % sourceSize;
179
179
  let tileX = Math.floor(j / destSize), tileY = Math.floor(i / destSize);
@@ -186,7 +186,7 @@ function extractElevationTilesMapbox(rgbaData, noDataValues, outCurrenElevations
186
186
  }
187
187
  if ((j + 1) % destSize === 0 && j !== sourceSize - 1) {
188
188
  //current tile
189
- rightHeight = rgb2Height(rgbaData[k4 + 4], rgbaData[k4 + 5], rgbaData[k4 + 6]);
189
+ rightHeight = heightFactor * rgb2Height(rgbaData[k4 + 4], rgbaData[k4 + 5], rgbaData[k4 + 6]);
190
190
  isNoDataRight = MapboxTerrain.checkNoDataValue(noDataValues, rightHeight);
191
191
  let middleHeight = height;
192
192
  if (!(isNoDataCurrent || isNoDataRight)) {
@@ -204,7 +204,7 @@ function extractElevationTilesMapbox(rgbaData, noDataValues, outCurrenElevations
204
204
  if ((i + 1) % destSize === 0 && i !== sourceSize - 1) {
205
205
  //current tile
206
206
  sourceSize4 = sourceSize * 4;
207
- bottomHeight = rgb2Height(rgbaData[k4 + sourceSize4], rgbaData[k4 + sourceSize4 + 1], rgbaData[k4 + sourceSize4 + 2]);
207
+ bottomHeight = heightFactor * rgb2Height(rgbaData[k4 + sourceSize4], rgbaData[k4 + sourceSize4 + 1], rgbaData[k4 + sourceSize4 + 2]);
208
208
  isNoDataBottom = MapboxTerrain.checkNoDataValue(noDataValues, bottomHeight);
209
209
  let middleHeight = (height + bottomHeight) * 0.5;
210
210
  if (!(isNoDataCurrent || isNoDataBottom)) {
@@ -222,7 +222,7 @@ function extractElevationTilesMapbox(rgbaData, noDataValues, outCurrenElevations
222
222
  if ((j + 1) % destSize === 0 && j !== sourceSize - 1 &&
223
223
  (i + 1) % destSize === 0 && i !== sourceSize - 1) {
224
224
  //current tile
225
- let rightBottomHeight = rgb2Height(rgbaData[k4 + sourceSize4 + 4], rgbaData[k4 + sourceSize4 + 5], rgbaData[k4 + sourceSize4 + 6]);
225
+ let rightBottomHeight = heightFactor * rgb2Height(rgbaData[k4 + sourceSize4 + 4], rgbaData[k4 + sourceSize4 + 5], rgbaData[k4 + sourceSize4 + 6]);
226
226
  let isNoDataRightBottom = MapboxTerrain.checkNoDataValue(noDataValues, rightBottomHeight);
227
227
  let middleHeight = height;
228
228
  if (!(isNoDataCurrent || isNoDataRight || isNoDataBottom || isNoDataRightBottom)) {
@@ -243,14 +243,14 @@ function extractElevationTilesMapbox(rgbaData, noDataValues, outCurrenElevations
243
243
  }
244
244
  }
245
245
  }
246
- function extractElevationTilesMapboxNoChildren(rgbaData, noDataValues, outCurrenElevations) {
246
+ function extractElevationTilesMapboxNoChildren(rgbaData, heightFactor, noDataValues, outCurrenElevations) {
247
247
  let destSize = Math.sqrt(outCurrenElevations.length) - 1;
248
248
  let sourceSize = Math.sqrt(rgbaData.length / 4);
249
249
  let dt = sourceSize / destSize;
250
250
  let rightHeight = 0, bottomHeight = 0, sourceSize4 = 0;
251
251
  for (let k = 0, currIndex = 0, sourceDataLength = rgbaData.length / 4; k < sourceDataLength; k++) {
252
252
  let k4 = k * 4;
253
- let height = rgb2Height(rgbaData[k4], rgbaData[k4 + 1], rgbaData[k4 + 2]);
253
+ let height = heightFactor * rgb2Height(rgbaData[k4], rgbaData[k4 + 1], rgbaData[k4 + 2]);
254
254
  let isNoDataCurrent = MapboxTerrain.checkNoDataValue(noDataValues, height), isNoDataRight = false, isNoDataBottom = false;
255
255
  let i = Math.floor(k / sourceSize), j = k % sourceSize;
256
256
  let tileX = Math.floor(j / destSize), tileY = Math.floor(i / destSize);
@@ -259,7 +259,7 @@ function extractElevationTilesMapboxNoChildren(rgbaData, noDataValues, outCurren
259
259
  }
260
260
  if ((j + 1) % destSize === 0 && j !== sourceSize - 1) {
261
261
  //current tile
262
- rightHeight = rgb2Height(rgbaData[k4 + 4], rgbaData[k4 + 5], rgbaData[k4 + 6]);
262
+ rightHeight = heightFactor * rgb2Height(rgbaData[k4 + 4], rgbaData[k4 + 5], rgbaData[k4 + 6]);
263
263
  isNoDataRight = MapboxTerrain.checkNoDataValue(noDataValues, rightHeight);
264
264
  let middleHeight = height;
265
265
  if (!(isNoDataCurrent || isNoDataRight)) {
@@ -272,7 +272,7 @@ function extractElevationTilesMapboxNoChildren(rgbaData, noDataValues, outCurren
272
272
  if ((i + 1) % destSize === 0 && i !== sourceSize - 1) {
273
273
  //current tile
274
274
  sourceSize4 = sourceSize * 4;
275
- bottomHeight = rgb2Height(rgbaData[k4 + sourceSize4], rgbaData[k4 + sourceSize4 + 1], rgbaData[k4 + sourceSize4 + 2]);
275
+ bottomHeight = heightFactor * rgb2Height(rgbaData[k4 + sourceSize4], rgbaData[k4 + sourceSize4 + 1], rgbaData[k4 + sourceSize4 + 2]);
276
276
  isNoDataBottom = MapboxTerrain.checkNoDataValue(noDataValues, bottomHeight);
277
277
  let middleHeight = (height + bottomHeight) * 0.5;
278
278
  if (!(isNoDataCurrent || isNoDataBottom)) {
@@ -285,7 +285,7 @@ function extractElevationTilesMapboxNoChildren(rgbaData, noDataValues, outCurren
285
285
  if ((j + 1) % destSize === 0 && j !== sourceSize - 1 &&
286
286
  (i + 1) % destSize === 0 && i !== sourceSize - 1) {
287
287
  //current tile
288
- let rightBottomHeight = rgb2Height(rgbaData[k4 + sourceSize4 + 4], rgbaData[k4 + sourceSize4 + 5], rgbaData[k4 + sourceSize4 + 6]);
288
+ let rightBottomHeight = heightFactor * rgb2Height(rgbaData[k4 + sourceSize4 + 4], rgbaData[k4 + sourceSize4 + 5], rgbaData[k4 + sourceSize4 + 6]);
289
289
  let isNoDataRightBottom = MapboxTerrain.checkNoDataValue(noDataValues, rightBottomHeight);
290
290
  let middleHeight = height;
291
291
  if (!(isNoDataCurrent || isNoDataRight || isNoDataBottom || isNoDataRightBottom)) {
@@ -19,7 +19,7 @@ class Dialog extends View {
19
19
  display: getDefault(options.visible, true) ? "flex" : "none",
20
20
  resize: getDefault(options.resizable, true) ? "both" : "none",
21
21
  width: options.width || 300,
22
- height: options.height ? `height:${options.height || 200}` : "",
22
+ height: options.height ? `height: ${options.height || 200}px` : "",
23
23
  left: options.left || 0,
24
24
  top: options.top || 0,
25
25
  minHeight: options.minHeight ? `${options.minHeight}px` : 'unset',
@@ -59,7 +59,7 @@ const TERRAIN_PROGRAM = `'use strict';
59
59
  end = arr.length - 1;
60
60
  while (start <= end) {
61
61
  let k = Math.floor((start + end) * 0.5);
62
- if (arr[k] === x)
62
+ if (Math.abs(arr[k] - x) < 1e-3)
63
63
  return k;
64
64
  else if (arr[k] < x)
65
65
  start = k + 1;
@@ -78,6 +78,7 @@ export declare function binarySearchFast(arr: number[] | TypedArray, x: number):
78
78
  */
79
79
  export declare function binarySearch(ar: any[], el: any, compare_fn: Function): number;
80
80
  /**
81
+ * @todo: replace any with generic
81
82
  * Binary insertion that uses binarySearch algorithm.
82
83
  * @param {any[]} ar - The sorted array to insert.
83
84
  * @param {any} el - The item to insert.
@@ -132,7 +133,7 @@ export declare function base64StringToBlog(string: string): Blob;
132
133
  * @param {Number} limit
133
134
  * @param {boolean} [skip]
134
135
  */
135
- export declare function throttle(func: Function, limit: number, skip: boolean): () => void;
136
+ export declare function throttle(func: Function, limit: number, skip?: boolean): () => void;
136
137
  /**
137
138
  *
138
139
  * y2-----Q12--------------Q22---
@@ -264,4 +265,5 @@ export declare function loadImage(url: string): Promise<HTMLImageElement>;
264
265
  */
265
266
  export declare function isImageLoaded(image: HTMLImageElement): boolean;
266
267
  export declare function distanceFormat(v: number): string;
268
+ export declare function distanceFormatExt(v: number): [string, string];
267
269
  export declare function getUrlParam(paramName: string): number | undefined;
@@ -245,7 +245,7 @@ export function binarySearchFast(arr, x) {
245
245
  let start = 0, end = arr.length - 1;
246
246
  while (start <= end) {
247
247
  let k = Math.floor((start + end) * 0.5);
248
- if (arr[k] === x) {
248
+ if (Math.abs(arr[k] - x) < 1e-3) {
249
249
  return k;
250
250
  }
251
251
  else if (arr[k] < x) {
@@ -292,6 +292,7 @@ export function binarySearch(ar, el, compare_fn) {
292
292
  return -m - 1;
293
293
  }
294
294
  /**
295
+ * @todo: replace any with generic
295
296
  * Binary insertion that uses binarySearch algorithm.
296
297
  * @param {any[]} ar - The sorted array to insert.
297
298
  * @param {any} el - The item to insert.
@@ -510,7 +511,7 @@ export function base64StringToBlog(string) {
510
511
  * @param {Number} limit
511
512
  * @param {boolean} [skip]
512
513
  */
513
- export function throttle(func, limit, skip) {
514
+ export function throttle(func, limit, skip = false) {
514
515
  let lastFunc;
515
516
  let lastRan = 0;
516
517
  return function () {
@@ -875,7 +876,7 @@ export function isImageLoaded(image) {
875
876
  }
876
877
  export function distanceFormat(v) {
877
878
  if (v > 1000) {
878
- return `${(v / 1000).toFixed(1)} km`;
879
+ return `${(v / 1000).toFixed(2)} km`;
879
880
  }
880
881
  else if (v > 9) {
881
882
  return `${Math.round(v)} m`;
@@ -884,6 +885,24 @@ export function distanceFormat(v) {
884
885
  return `${v.toFixed(1)} m`;
885
886
  }
886
887
  }
888
+ export function distanceFormatExt(v) {
889
+ if (v > 1000) {
890
+ let d = v - Math.floor(v);
891
+ if (d !== 0) {
892
+ return [(v / 1000).toFixed(2), "km"];
893
+ }
894
+ return [(v / 1000).toFixed(0), "km"];
895
+ }
896
+ else if (v > 9) {
897
+ return [Math.round(v).toString(), "m"];
898
+ }
899
+ else {
900
+ if (v <= 0.01) {
901
+ return ["0", "m"];
902
+ }
903
+ return [v.toFixed(1), "m"];
904
+ }
905
+ }
887
906
  export function getUrlParam(paramName) {
888
907
  let urlParams = new URLSearchParams(location.search);
889
908
  let param = urlParams.get(paramName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openglobus/og",
3
- "version": "0.18.4",
3
+ "version": "0.19.0",
4
4
  "description": "[openglobus](https://www.openglobus.org/) is a javascript/typescript library designed to display interactive 3d maps and planets with map tiles, imagery and vector data, markers, and 3D objects. It uses the WebGL technology, open source, and completely free.",
5
5
  "directories": {
6
6
  "example": "./sandbox"
@@ -47,7 +47,7 @@
47
47
  "jsdoc": "^4.0.2",
48
48
  "lint-staged": "^14.0.1",
49
49
  "local-web-server": "^5.3.0",
50
- "postcss": "^8.4.29",
50
+ "postcss": "^8.4.31",
51
51
  "prettier": "^3.0.3",
52
52
  "rollup": "^3.29.2",
53
53
  "rollup-plugin-copy": "^3.5.0",
@@ -1,2 +0,0 @@
1
- import { Program } from '../webgl/Program';
2
- export declare function pickingMask(): Program;
@@ -1,22 +0,0 @@
1
- import { Program } from '../webgl/Program';
2
- export function pickingMask() {
3
- return new Program("pickingMask", {
4
- uniforms: {
5
- offset: "vec2"
6
- },
7
- attributes: {
8
- coordinates: "vec2"
9
- },
10
- vertexShader: `attribute vec2 coordinates;
11
- uniform vec2 offset;
12
- void main() {
13
-
14
- gl_Position = vec4(coordinates + offset, 0.0, 1.0);
15
- gl_PointSize = 5.0;
16
- }`,
17
- fragmentShader: `precision highp float;
18
- void main(void) {
19
- gl_FragColor = vec4(1.0);
20
- }`
21
- });
22
- }