@openglobus/og 0.13.8 → 0.13.10

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 (85) hide show
  1. package/README.md +1 -1
  2. package/css/og.css +388 -129
  3. package/dist/@openglobus/og.css +1 -1
  4. package/dist/@openglobus/og.esm.js +2 -2
  5. package/dist/@openglobus/og.esm.js.map +1 -1
  6. package/dist/@openglobus/og.umd.js +2 -2
  7. package/dist/@openglobus/og.umd.js.map +1 -1
  8. package/package.json +20 -19
  9. package/src/og/Globe.js +15 -16
  10. package/src/og/Object3d.js +33 -0
  11. package/src/og/control/GeoImageDragControl.js +102 -75
  12. package/src/og/control/LayerAnimation.js +306 -38
  13. package/src/og/control/LayerSwitcher.js +506 -159
  14. package/src/og/control/Lighting.js +27 -27
  15. package/src/og/control/RulerSwitcher.js +69 -0
  16. package/src/og/control/UIhelpers.js +146 -0
  17. package/src/og/control/index.js +3 -1
  18. package/src/og/control/ruler/RulerScene.js +6 -2
  19. package/src/og/control/visibleExtent/Segment.js +2 -1
  20. package/src/og/ellipsoid/wgs84.js +1 -1
  21. package/src/og/entity/LabelHandler.js +5 -2
  22. package/src/og/entity/LabelWorker.js +38 -53
  23. package/src/og/layer/BaseGeoImage.js +347 -312
  24. package/src/og/layer/CanvasTiles.js +312 -290
  25. package/src/og/layer/GeoImage.js +222 -214
  26. package/src/og/layer/GeoVideo.js +291 -291
  27. package/src/og/layer/Layer.js +71 -30
  28. package/src/og/layer/Material.js +109 -109
  29. package/src/og/layer/Vector.js +1 -0
  30. package/src/og/layer/XYZ.js +20 -12
  31. package/src/og/light/LightSource.js +364 -363
  32. package/src/og/math.js +2 -2
  33. package/src/og/quadTree/Node.js +7 -5
  34. package/src/og/renderer/Renderer.js +1 -1
  35. package/src/og/scene/Planet.js +103 -42
  36. package/src/og/segment/Segment.js +34 -56
  37. package/src/og/segment/Slice.js +1 -1
  38. package/src/og/shaders/drawnode.js +1 -1
  39. package/src/og/terrain/GlobusTerrain.js +31 -20
  40. package/src/og/terrain/MapboxTerrain.js +1 -1
  41. package/src/og/utils/BaseWorker.js +46 -0
  42. package/src/og/utils/GeoImageCreator.js +164 -161
  43. package/src/og/utils/Loader.js +60 -33
  44. package/src/og/utils/NormalMapCreator.js +403 -412
  45. package/src/og/utils/PlainSegmentWorker.js +29 -55
  46. package/src/og/utils/TerrainWorker.js +572 -589
  47. package/src/og/utils/functionComposition.js +13 -0
  48. package/src/og/webgl/Handler.js +42 -41
  49. package/types/Object3d.d.ts +1 -0
  50. package/types/camera/PlanetCamera.d.ts +4 -0
  51. package/types/control/GeoImageDragControl.d.ts +2 -0
  52. package/types/control/LayerAnimation.d.ts +73 -0
  53. package/types/control/LayerSwitcher.d.ts +55 -11
  54. package/types/control/MouseNavigation.d.ts +1 -0
  55. package/types/control/MouseWheelZoomControl.d.ts +1 -0
  56. package/types/control/Sun.d.ts +1 -0
  57. package/types/control/TouchNavigation.d.ts +1 -0
  58. package/types/control/UIhelpers.d.ts +13 -0
  59. package/types/control/index.d.ts +2 -1
  60. package/types/entity/LabelHandler.d.ts +2 -0
  61. package/types/entity/LabelWorker.d.ts +5 -7
  62. package/types/layer/BaseGeoImage.d.ts +9 -1
  63. package/types/layer/CanvasTiles.d.ts +5 -1
  64. package/types/layer/GeoImage.d.ts +1 -0
  65. package/types/layer/GeoTexture2d.d.ts +1 -0
  66. package/types/layer/Layer.d.ts +5 -1
  67. package/types/layer/Vector.d.ts +7 -0
  68. package/types/layer/WMS.d.ts +1 -0
  69. package/types/layer/XYZ.d.ts +8 -6
  70. package/types/math.d.ts +1 -1
  71. package/types/quadTree/EntityCollectionNode.d.ts +7 -0
  72. package/types/quadTree/Node.d.ts +1 -2
  73. package/types/renderer/Renderer.d.ts +1 -1
  74. package/types/renderer/RendererEvents.d.ts +16 -0
  75. package/types/scene/Planet.d.ts +19 -4
  76. package/types/segment/SegmentLonLat.d.ts +2 -0
  77. package/types/terrain/BilTerrain.d.ts +6 -0
  78. package/types/terrain/GlobusTerrain.d.ts +7 -0
  79. package/types/terrain/MapboxTerrain.d.ts +8 -0
  80. package/types/utils/BaseWorker.d.ts +14 -0
  81. package/types/utils/Loader.d.ts +3 -1
  82. package/types/utils/PlainSegmentWorker.d.ts +4 -6
  83. package/types/utils/TerrainWorker.d.ts +4 -6
  84. package/types/utils/functionComposition.d.ts +5 -0
  85. package/types/webgl/Handler.d.ts +4 -1
@@ -12,7 +12,7 @@ import { LonLat } from "../LonLat.js";
12
12
  import { Material } from "./Material.js";
13
13
  import { Vec3 } from "../math/Vec3.js";
14
14
 
15
- export const FADING_FACTOR = 0.29;
15
+ const FADING_RATIO = 15.8;
16
16
 
17
17
  /**
18
18
  * @classdesc
@@ -27,6 +27,7 @@ export const FADING_FACTOR = 0.29;
27
27
  * @param {string} [options.attribution] - Layer attribution that displayed in the attribution area on the screen.
28
28
  * @param {boolean} [options.isBaseLayer=false] - This is a base layer.
29
29
  * @param {boolean} [options.visibility=true] - Layer visibility.
30
+ * @param {boolean} [options.displayInLayerSwitcher=true] - Presence of layer in dialog window of LayerSwitcher control.
30
31
  * @param {boolean} [options.isSRGB=false] - Layer image webgl nternal format.
31
32
  * @param {Extent} [options.extent=[[-180.0, -90.0], [180.0, 90.0]]] - Visible extent.
32
33
  * @param {string} [options.textureFilter="anisotropic"] - Image texture filter. Available values: "nearest", "linear", "mipmap" and "anisotropic".
@@ -67,6 +68,8 @@ class Layer {
67
68
  */
68
69
  this.name = name || "noname";
69
70
 
71
+ this.properties = options.properties || {};
72
+
70
73
  this._labelMaxLetters = options.labelMaxLetters;
71
74
 
72
75
  this.displayInLayerSwitcher =
@@ -141,7 +144,7 @@ class Layer {
141
144
 
142
145
  this._fading = options.fading || false;
143
146
 
144
- this._fadingFactor = FADING_FACTOR;
147
+ this._fadingFactor = this._opacity / FADING_RATIO;
145
148
 
146
149
  if (this._fading) {
147
150
  this._fadingOpacity = this._visibility ? this._opacity : 0.0;
@@ -204,7 +207,7 @@ class Layer {
204
207
  * @public
205
208
  * @type {Events}
206
209
  */
207
- this.events = new Events(EVENT_NAMES, this);
210
+ this.events = new Events(options.events ? [...EVENT_NAMES, ...options.events] : EVENT_NAMES, this);
208
211
  }
209
212
 
210
213
  static getTMS(x, y, z) {
@@ -239,20 +242,18 @@ class Layer {
239
242
  }
240
243
 
241
244
  set opacity(opacity) {
242
- if (this._fading) {
243
- if (opacity > this._opacity) {
244
- this._fadingFactor = (opacity - this._opacity) / 2.8;
245
- } else if (opacity < this._opacity) {
246
- this._fadingFactor = (opacity - this._opacity) / 2.8;
245
+ if (opacity !== this._opacity) {
246
+ if (this._fading) {
247
+ if (opacity > this._opacity) {
248
+ this._fadingFactor = (opacity - this._opacity) / FADING_RATIO;
249
+ } else if (opacity < this._opacity) {
250
+ this._fadingFactor = (opacity - this._opacity) / FADING_RATIO;
251
+ }
252
+ } else {
253
+ this._fadingOpacity = opacity;
247
254
  }
248
- } else {
249
- this._fadingOpacity = opacity;
255
+ this._opacity = opacity;
250
256
  }
251
- this._opacity = opacity;
252
- }
253
-
254
- get opacity() {
255
- return this._opacity;
256
257
  }
257
258
 
258
259
  set pickingEnabled(picking) {
@@ -289,7 +290,7 @@ class Layer {
289
290
  * @returns {boolean} - Returns true if the layers is the same instance of the input.
290
291
  */
291
292
  isEqual(layer) {
292
- return layer._id === this._id;
293
+ return layer && (layer._id === this._id);
293
294
  }
294
295
 
295
296
  /**
@@ -308,7 +309,9 @@ class Layer {
308
309
 
309
310
  this.createTexture = planet.renderer.handler.createTexture[this._textureFilter];
310
311
 
311
- planet.layers.push(this);
312
+ // TODO: replace to planet
313
+ planet._layers.push(this);
314
+
312
315
  this._planet = planet;
313
316
  this.events.on("visibilitychange", planet._onLayerVisibilityChanged, planet);
314
317
  if (this._isBaseLayer && this._visibility) {
@@ -325,6 +328,10 @@ class Layer {
325
328
  this._bindPicking();
326
329
  }
327
330
 
331
+ get isIdle() {
332
+ return this._planet && this._planet._terrainCompletedActivated;
333
+ }
334
+
328
335
  /**
329
336
  * Assign picking color to the layer.
330
337
  * @protected
@@ -352,17 +359,20 @@ class Layer {
352
359
  * @returns {Layer} -This layer.
353
360
  */
354
361
  remove() {
355
- var p = this._planet;
362
+ let p = this._planet;
356
363
  if (p) {
357
- for (var i = 0; i < p.layers.length; i++) {
358
- if (this.isEqual(p.layers[i])) {
364
+ //TODO: replace to planet
365
+ for (let i = 0; i < p._layers.length; i++) {
366
+ if (this.isEqual(p._layers[i])) {
359
367
  p.renderer.clearPickingColor(this);
360
- p.layers.splice(i, 1);
368
+ p._layers.splice(i, 1);
361
369
  p.updateVisibleLayers();
362
370
  this.clear();
363
371
  p.events.dispatch(p.events.layerremove, this);
364
372
  this.events.dispatch(this.events.remove, p);
365
373
  this._planet = null;
374
+ this._internalFormat = null;
375
+ this.createTexture = null;
366
376
  return this;
367
377
  }
368
378
  }
@@ -377,8 +387,6 @@ class Layer {
377
387
  clear() {
378
388
  if (this._planet) {
379
389
  this._planet._clearLayerMaterial(this);
380
- this._internalFormat = null;
381
- this.createTexture = null;
382
390
  }
383
391
  }
384
392
 
@@ -513,7 +521,7 @@ class Layer {
513
521
  this._planet._renderCompleted = false;
514
522
  }
515
523
 
516
- this.applyMaterial(m);
524
+ this.applyMaterial(m, true);
517
525
  }
518
526
 
519
527
  _preLoadRecursive(node, maxZoom) {
@@ -603,6 +611,14 @@ class Layer {
603
611
  // }
604
612
  }
605
613
 
614
+ get opacity() {
615
+ return this._opacity;
616
+ }
617
+
618
+ get screenOpacity() {
619
+ return this._fading ? this._fadingOpacity : this._opacity;
620
+ }
621
+
606
622
  _refreshFadingOpacity() {
607
623
  var p = this._planet;
608
624
  if (
@@ -620,20 +636,45 @@ class Layer {
620
636
  ) {
621
637
  this._fadingOpacity = this._opacity;
622
638
  }
639
+
623
640
  return false;
624
641
  } else {
625
- this._fadingOpacity -= FADING_FACTOR;
626
-
627
- if (this._fadingOpacity < 0.0) {
628
- this._fadingOpacity = 0.0;
629
- return !this._visibility;
630
- }
642
+ //this._fadingOpacity -= this._opacity / FADING_RATIO;
643
+ //if (this._fadingOpacity < 0.0) {
644
+ this._fadingOpacity = 0.0;
645
+ //}
646
+ return !this._visibility;
631
647
  }
632
648
  }
633
649
 
634
650
  createMaterial(segment) {
635
651
  return new Material(segment, this);
636
652
  }
653
+
654
+ redraw() {
655
+ if (this._planet) {
656
+ this._planet._quadTree.traverseTree((n) => {
657
+ if (n.segment.materials[this._id]) {
658
+ n.segment.materials[this._id].clear();
659
+ }
660
+ }
661
+ );
662
+
663
+ this._planet._quadTreeNorth.traverseTree((n) => {
664
+ if (n.segment.materials[this._id]) {
665
+ n.segment.materials[this._id].clear();
666
+ }
667
+ }
668
+ );
669
+
670
+ this._planet._quadTreeSouth.traverseTree((n) => {
671
+ if (n.segment.materials[this._id]) {
672
+ n.segment.materials[this._id].clear();
673
+ }
674
+ }
675
+ );
676
+ }
677
+ }
637
678
  }
638
679
 
639
680
  const EVENT_NAMES = [
@@ -1,109 +1,109 @@
1
- /**
2
- * @module og/layer/Material
3
- */
4
-
5
- "use strict";
6
-
7
- class Material {
8
- /**
9
- *
10
- * @param {*} segment
11
- * @param {*} layer
12
- */
13
- constructor(segment, layer) {
14
- this.segment = segment;
15
- this.layer = layer;
16
- this.isReady = false;
17
- this.isLoading = false;
18
- this.texture = null;
19
- this.pickingMask = null;
20
- //this.image = null;
21
- this.textureExists = false;
22
- this.appliedNodeId = 0;
23
- this.texOffset = [0.0, 0.0, 1.0, 1.0];
24
- this.loadingAttempts = 0;
25
-
26
- // vector data
27
- this._updateTexture = null;
28
- this._updatePickingMask = null;
29
- this.pickingReady = false;
30
- }
31
-
32
- ///**
33
- // * @param {*} layer
34
- // */
35
- //assignLayer(layer) {
36
- // this.layer = layer;
37
- //}
38
-
39
- /**
40
- *
41
- */
42
- abortLoading() {
43
- this.layer.abortMaterialLoading(this);
44
- }
45
-
46
- _createTexture(img) {
47
- return this.layer.createTexture(img, this.layer._internalFormat);
48
- }
49
-
50
- /**
51
- *
52
- * @param {*} img
53
- */
54
- applyImage(img) {
55
- if (this.segment.initialized) {
56
- this._updateTexture = null;
57
- //this.image = img;
58
- this.texture = this._createTexture(img);
59
- this.appliedNodeId = this.segment.node.nodeId;
60
- this.isReady = true;
61
- this.pickingReady = true;
62
- this.textureExists = true;
63
- this.isLoading = false;
64
- this.texOffset = [0.0, 0.0, 1.0, 1.0];
65
- }
66
- }
67
-
68
- /**
69
- *
70
- * @param {*} texture
71
- * @param {*} pickingMask
72
- */
73
- applyTexture(texture, pickingMask) {
74
- if (this.segment.initialized) {
75
- this.texture = texture;
76
- this._updateTexture = null;
77
- this.pickingMask = pickingMask || null;
78
- this._updatePickingMask = null;
79
- this.isReady = true;
80
- this.pickingReady = true;
81
- this.textureExists = true;
82
- this.isLoading = false;
83
- this.appliedNodeId = this.segment.node.nodeId;
84
- this.texOffset = [0.0, 0.0, 1.0, 1.0];
85
- }
86
- }
87
-
88
- /**
89
- *
90
- */
91
- textureNotExists() {
92
- if (this.segment.initialized) {
93
- this.pickingReady = true;
94
- this.isLoading = false;
95
- this.isReady = true;
96
- this.textureExists = false;
97
- }
98
- }
99
-
100
- /**
101
- *
102
- */
103
- clear() {
104
- this.loadingAttempts = 0;
105
- this.layer.clearMaterial(this);
106
- }
107
- }
108
-
109
- export { Material };
1
+ /**
2
+ * @module og/layer/Material
3
+ */
4
+
5
+ "use strict";
6
+
7
+ class Material {
8
+ /**
9
+ *
10
+ * @param {*} segment
11
+ * @param {*} layer
12
+ */
13
+ constructor(segment, layer) {
14
+ this.segment = segment;
15
+ this.layer = layer;
16
+ this.isReady = false;
17
+ this.isLoading = false;
18
+ this.texture = null;
19
+ this.pickingMask = null;
20
+ //this.image = null;
21
+ this.textureExists = false;
22
+ this.appliedNodeId = 0;
23
+ this.texOffset = [0.0, 0.0, 1.0, 1.0];
24
+ this.loadingAttempts = 0;
25
+
26
+ // vector data
27
+ this._updateTexture = null;
28
+ this._updatePickingMask = null;
29
+ this.pickingReady = false;
30
+ }
31
+
32
+ ///**
33
+ // * @param {*} layer
34
+ // */
35
+ //assignLayer(layer) {
36
+ // this.layer = layer;
37
+ //}
38
+
39
+ /**
40
+ *
41
+ */
42
+ abortLoading() {
43
+ this.layer.abortMaterialLoading(this);
44
+ }
45
+
46
+ _createTexture(img) {
47
+ return this.layer._planet && this.layer.createTexture(img, this.layer._internalFormat);
48
+ }
49
+
50
+ /**
51
+ *
52
+ * @param {*} img
53
+ */
54
+ applyImage(img) {
55
+ if (this.segment.initialized) {
56
+ this._updateTexture = null;
57
+ //this.image = img;
58
+ this.texture = this._createTexture(img);
59
+ this.appliedNodeId = this.segment.node.nodeId;
60
+ this.isReady = true;
61
+ this.pickingReady = true;
62
+ this.textureExists = true;
63
+ this.isLoading = false;
64
+ this.texOffset = [0.0, 0.0, 1.0, 1.0];
65
+ }
66
+ }
67
+
68
+ /**
69
+ *
70
+ * @param {*} texture
71
+ * @param {*} pickingMask
72
+ */
73
+ applyTexture(texture, pickingMask) {
74
+ if (this.segment.initialized) {
75
+ this.texture = texture;
76
+ this._updateTexture = null;
77
+ this.pickingMask = pickingMask || null;
78
+ this._updatePickingMask = null;
79
+ this.isReady = true;
80
+ this.pickingReady = true;
81
+ this.textureExists = true;
82
+ this.isLoading = false;
83
+ this.appliedNodeId = this.segment.node.nodeId;
84
+ this.texOffset = [0.0, 0.0, 1.0, 1.0];
85
+ }
86
+ }
87
+
88
+ /**
89
+ *
90
+ */
91
+ textureNotExists() {
92
+ if (this.segment.initialized) {
93
+ this.pickingReady = true;
94
+ this.isLoading = false;
95
+ this.isReady = true;
96
+ this.textureExists = false;
97
+ }
98
+ }
99
+
100
+ /**
101
+ *
102
+ */
103
+ clear() {
104
+ this.loadingAttempts = 0;
105
+ this.layer.clearMaterial(this);
106
+ }
107
+ }
108
+
109
+ export { Material };
@@ -83,6 +83,7 @@ class Vector extends Layer {
83
83
 
84
84
  this._hasImageryTiles = false;
85
85
 
86
+
86
87
  /**
87
88
  * First index - near distance to the entity, after that entity becomes full scale.
88
89
  * Second index - far distance to the entity, when entity becomes zero scale.
@@ -76,11 +76,6 @@ class XYZ extends Layer {
76
76
  */
77
77
  this.maxNativeZoom = options.maxNativeZoom || 19;
78
78
 
79
- /**
80
- * @protected
81
- */
82
- this._crossOrigin = options.crossOrigin === undefined ? "" : options.crossOrigin;
83
-
84
79
  /**
85
80
  * Rewrites imagery tile url query.
86
81
  * @private
@@ -90,10 +85,16 @@ class XYZ extends Layer {
90
85
  * @returns {string} - Url query string.
91
86
  */
92
87
  this._urlRewriteCallback = options.urlRewrite || null;
88
+
89
+ this._requestsPeerSubdomian = 4;
90
+ this._requestCount = 0;
93
91
  }
94
92
 
93
+ /**
94
+ * @warning Use XYZ.isIdle in requesAnimationFrame(after setVisibility)
95
+ */
95
96
  get isIdle() {
96
- return !this._planet || this._planet._tileLoader.isIdle(this);
97
+ return super.isIdle && this._planet._tileLoader.getRequestCounter(this) === 0;
97
98
  }
98
99
 
99
100
  get instanceName() {
@@ -106,7 +107,7 @@ class XYZ extends Layer {
106
107
  */
107
108
  abortLoading() {
108
109
  if (this._planet) {
109
- this._planet._tileLoader.abort();
110
+ this._planet._tileLoader.abort(this);
110
111
  }
111
112
  }
112
113
 
@@ -118,13 +119,17 @@ class XYZ extends Layer {
118
119
  setVisibility(visibility) {
119
120
  if (visibility !== this._visibility) {
120
121
  super.setVisibility(visibility);
121
-
122
122
  if (!visibility) {
123
123
  this.abortLoading();
124
124
  }
125
125
  }
126
126
  }
127
127
 
128
+ remove() {
129
+ this.abortLoading();
130
+ super.remove();
131
+ }
132
+
128
133
  /**
129
134
  * Sets imagery tiles url source template.
130
135
  * @public
@@ -148,6 +153,7 @@ class XYZ extends Layer {
148
153
  * @param {Material} material - Loads current material.
149
154
  */
150
155
  loadMaterial(material, forceLoading) {
156
+
151
157
  let seg = material.segment;
152
158
 
153
159
  if (this._isBaseLayer) {
@@ -216,7 +222,9 @@ class XYZ extends Layer {
216
222
  }
217
223
 
218
224
  _getSubdomain() {
219
- return this._s[Math.floor(Math.random() * this._s.length)];
225
+ this._requestCount++;
226
+ return this._s[Math.floor(this._requestCount % (this._requestsPeerSubdomian * this._s.length) / this._requestsPeerSubdomian)];
227
+
220
228
  }
221
229
 
222
230
  /**
@@ -240,7 +248,7 @@ class XYZ extends Layer {
240
248
  this._urlRewriteCallback = ur;
241
249
  }
242
250
 
243
- applyMaterial(material) {
251
+ applyMaterial(material, forceLoading) {
244
252
  if (material.isReady) {
245
253
  return material.texOffset;
246
254
  } else if (material.segment.tileZoom <= this.minNativeZoom) {
@@ -267,7 +275,7 @@ class XYZ extends Layer {
267
275
  if (pn.segment.tileZoom === maxNativeZoom) {
268
276
  material.textureNotExists();
269
277
  } else if (material.segment.tileZoom <= maxNativeZoom) {
270
- !material.isLoading && !material.isReady && this.loadMaterial(material);
278
+ !material.isLoading && !material.isReady && this.loadMaterial(material, forceLoading);
271
279
  } else {
272
280
  let pn = segment.node;
273
281
  while (pn.segment.tileZoom > material.layer.maxNativeZoom) {
@@ -309,7 +317,7 @@ class XYZ extends Layer {
309
317
  clearMaterial(material) {
310
318
  if (material.isReady && material.textureExists) {
311
319
  !material.texture.default &&
312
- material.segment.handler.gl.deleteTexture(material.texture);
320
+ material.segment.handler.gl.deleteTexture(material.texture);
313
321
  material.texture = null;
314
322
 
315
323
  if (material.image) {