@openglobus/og 0.13.3 → 0.13.6

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 (45) hide show
  1. package/dist/@openglobus/og.esm.js +2 -2
  2. package/dist/@openglobus/og.esm.js.map +1 -1
  3. package/dist/@openglobus/og.umd.js +2 -2
  4. package/dist/@openglobus/og.umd.js.map +1 -1
  5. package/package.json +1 -1
  6. package/src/og/Events.js +188 -188
  7. package/src/og/Globe.js +1 -0
  8. package/src/og/control/KeyboardNavigation.js +48 -2
  9. package/src/og/control/TouchNavigation.js +340 -319
  10. package/src/og/control/ZoomControl.js +1 -1
  11. package/src/og/ellipsoid/Ellipsoid.js +1 -1
  12. package/src/og/entity/Billboard.js +165 -165
  13. package/src/og/entity/BillboardHandler.js +1 -1
  14. package/src/og/entity/GeoObject.js +4 -0
  15. package/src/og/entity/GeoObjectHandler.js +22 -33
  16. package/src/og/entity/Geometry.js +319 -319
  17. package/src/og/entity/Label.js +348 -346
  18. package/src/og/entity/LabelHandler.js +44 -37
  19. package/src/og/input/input.js +7 -1
  20. package/src/og/layer/KML.js +181 -12
  21. package/src/og/layer/Layer.js +4 -2
  22. package/src/og/renderer/RendererEvents.js +1065 -1051
  23. package/src/og/scene/Planet.js +45 -27
  24. package/src/og/shaders/billboard.js +8 -0
  25. package/src/og/shaders/label.js +56 -13
  26. package/src/og/terrain/EmptyTerrain.js +159 -146
  27. package/src/og/terrain/Geoid.js +246 -241
  28. package/src/og/terrain/GlobusTerrain.js +17 -18
  29. package/src/og/terrain/MapboxTerrain.js +292 -294
  30. package/src/og/utils/FontAtlas.js +25 -15
  31. package/src/og/utils/PlainSegmentWorker.js +38 -26
  32. package/src/og/utils/TextureAtlas.js +291 -280
  33. package/types/control/KeyboardNavigation.d.ts +3 -0
  34. package/types/entity/GeoObject.d.ts +1 -0
  35. package/types/entity/Label.d.ts +1 -0
  36. package/types/entity/LabelHandler.d.ts +1 -1
  37. package/types/input/input.d.ts +6 -0
  38. package/types/layer/KML.d.ts +26 -1
  39. package/types/renderer/RendererEvents.d.ts +2 -0
  40. package/types/scene/Planet.d.ts +5 -0
  41. package/types/terrain/EmptyTerrain.d.ts +3 -1
  42. package/types/terrain/Geoid.d.ts +1 -10
  43. package/types/terrain/GlobusTerrain.d.ts +0 -1
  44. package/types/terrain/MapboxTerrain.d.ts +1 -1
  45. package/types/utils/TextureAtlas.d.ts +2 -0
@@ -613,21 +613,36 @@ export class Planet extends RenderNode {
613
613
  this._quadTree.destroyBranches();
614
614
  }
615
615
 
616
- if (terrain._geoid) {
617
- if (!terrain._geoid.model) {
618
- terrain._geoid.model = null;
619
- Geoid.loadModel(terrain._geoid.src)
620
- .then((m) => {
621
- terrain.getGeoid().setModel(m);
622
- this._plainSegmentWorker.setGeoid(terrain.getGeoid());
623
- })
624
- .catch((err) => {
625
- console.log(err);
626
- });
627
- } else {
628
- this._plainSegmentWorker.setGeoid(terrain.getGeoid());
629
- }
616
+ //if (terrain._geoid) {
617
+
618
+ if (terrain._geoid.model) {
619
+ this._plainSegmentWorker.setGeoid(terrain.getGeoid());
620
+ terrain._isReady = true;
621
+ } else {
622
+ Geoid.loadModel(terrain._geoid.src)
623
+ .then((m) => {
624
+ terrain.getGeoid().setModel(m);
625
+ this._plainSegmentWorker.setGeoid(terrain.getGeoid());
626
+ terrain._isReady = true;
627
+ })
628
+ .catch((err) => {
629
+ console.log(err);
630
+ });
630
631
  }
632
+
633
+ // if (!terrain._geoid.model) {
634
+ // Geoid.loadModel(terrain._geoid.src)
635
+ // .then((m) => {
636
+ // terrain.getGeoid().setModel(m);
637
+ // this._plainSegmentWorker.setGeoid(terrain.getGeoid());
638
+ // })
639
+ // .catch((err) => {
640
+ // console.log(err);
641
+ // });
642
+ // } else {
643
+ // this._plainSegmentWorker.setGeoid(terrain.getGeoid());
644
+ // }
645
+ //}
631
646
  }
632
647
 
633
648
  /**
@@ -917,15 +932,7 @@ export class Planet extends RenderNode {
917
932
  }
918
933
  }
919
934
 
920
- if (this.renderer) {
921
- if (html.length) {
922
- this.renderer.div.attributions.style.display = "block";
923
- this.renderer.div.attributions.innerHTML = "<ul>" + html + "</ul>";
924
- } else {
925
- this.renderer.div.attributions.style.display = "none";
926
- this.renderer.div.attributions.innerHTML = "";
927
- }
928
- }
935
+ this._applyAttribution(html)
929
936
  }
930
937
 
931
938
  /**
@@ -971,17 +978,28 @@ export class Planet extends RenderNode {
971
978
  }
972
979
  }
973
980
 
981
+ this._applyAttribution(html);
982
+
983
+ this._sortLayers();
984
+ }
985
+
986
+ /**
987
+ * Apply to render list of layer attributions
988
+ * @private
989
+ */
990
+ _applyAttribution(html) {
974
991
  if (this.renderer) {
975
992
  if (html.length) {
976
- this.renderer.div.attributions.style.display = "block";
977
- this.renderer.div.attributions.innerHTML = "<ul>" + html + "</ul>";
993
+ html = "<ul>" + html + "</ul>";
994
+ if (this.renderer.div.attributions.innerHTML !== html) {
995
+ this.renderer.div.attributions.style.display = "block";
996
+ this.renderer.div.attributions.innerHTML = html;
997
+ }
978
998
  } else {
979
999
  this.renderer.div.attributions.style.display = "none";
980
1000
  this.renderer.div.attributions.innerHTML = "";
981
1001
  }
982
1002
  }
983
-
984
- this._sortLayers();
985
1003
  }
986
1004
 
987
1005
  /**
@@ -92,6 +92,14 @@ export function billboardPicking() {
92
92
  vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);
93
93
  vec4 projPos = projectionMatrix * posRTE;
94
94
 
95
+ float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos));
96
+ if(camSlope > 0.5) {
97
+ float dist = dot(look, normalize(cameraPos));
98
+ projPos.z += dist * 0.02;
99
+ }else{
100
+ projPos.z += -(abs(projPos.z)) * 0.002;
101
+ }
102
+
95
103
  projPos.z += depthOffset + a_offset.z;
96
104
 
97
105
  vec2 screenPos = project(projPos);
@@ -6,6 +6,10 @@
6
6
 
7
7
  import { Program } from '../webgl/Program.js';
8
8
 
9
+ const DEFINE = `
10
+ #define EMPTY -1.0
11
+ #define RTL 1.0`;
12
+
9
13
  const PROJECT = `vec2 project(vec4 p) {
10
14
  return (0.5 * p.xyz / p.w + 0.5).xy * viewport;
11
15
  }`;
@@ -47,7 +51,9 @@ export function label_webgl2() {
47
51
  },
48
52
  vertexShader:
49
53
  `#version 300 es
50
-
54
+
55
+ ${DEFINE}
56
+
51
57
  in float a_outline;
52
58
  in vec4 a_gliphParam;
53
59
  in vec2 a_vertices;
@@ -77,14 +83,14 @@ export function label_webgl2() {
77
83
  uniform float depthOffset;
78
84
 
79
85
  const vec3 ZERO3 = vec3(0.0);
80
-
86
+
81
87
  ${PROJECT}
82
88
 
83
89
  ${ROTATE2D}
84
90
 
85
91
  void main() {
86
92
 
87
- if(a_texCoord.z == -1.0) {
93
+ if(a_texCoord.w == EMPTY) {
88
94
  gl_Position = vec4(0.0);
89
95
  return;
90
96
  }
@@ -95,7 +101,7 @@ export function label_webgl2() {
95
101
  v_outline = a_outline;
96
102
 
97
103
  v_fontIndex = int(a_fontIndex);
98
- v_uv = vec2(a_texCoord.xy);
104
+ v_uv = a_texCoord.xy;
99
105
  vec3 look = a_positions - cameraPos;
100
106
  float lookDist = length(look);
101
107
  v_rgba = a_rgba;
@@ -127,8 +133,18 @@ export function label_webgl2() {
127
133
  projPos.z += depthOffset + a_offset.z;
128
134
 
129
135
  vec2 screenPos = project(projPos);
130
-
131
- vec2 v = screenPos + rotate2d(a_rotation) * ((a_vertices * a_gliphParam.xy + a_gliphParam.zw + vec2(a_texCoord.z, 0.0) + vec2(a_texCoord.w, 0.0)) * a_size * scd + a_offset.xy);
136
+
137
+ vec2 vert = a_vertices;
138
+ vec4 gp = a_gliphParam;
139
+ if(a_texCoord.w == RTL){
140
+ vert.x = step(vert.x * 0.5 + 1.0, 1.0);
141
+ gp.x = -a_gliphParam.x;
142
+ gp.z = -(a_gliphParam.z + a_texCoord.z);
143
+ }else{
144
+ gp.z = a_gliphParam.z + a_texCoord.z;
145
+ }
146
+
147
+ vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);
132
148
 
133
149
  gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);
134
150
  }`,
@@ -270,7 +286,9 @@ export function label_screen() {
270
286
  a_fontIndex: "float"
271
287
  },
272
288
  vertexShader:
273
- `
289
+ `
290
+ ${DEFINE}
291
+
274
292
  attribute float a_outline;
275
293
  attribute vec4 a_gliphParam;
276
294
  attribute vec2 a_vertices;
@@ -306,7 +324,7 @@ export function label_screen() {
306
324
 
307
325
  void main() {
308
326
 
309
- if(a_texCoord.z == -1.0) {
327
+ if(a_texCoord.w == EMPTY) {
310
328
  gl_Position = vec4(0.0);
311
329
  return;
312
330
  }
@@ -349,9 +367,19 @@ export function label_screen() {
349
367
  projPos.z += depthOffset + a_offset.z;
350
368
 
351
369
  vec2 screenPos = project(projPos);
352
-
353
- vec2 v = screenPos + rotate2d(a_rotation) * ((a_vertices * a_gliphParam.xy + a_gliphParam.zw + vec2(a_texCoord.z, 0.0) + vec2(a_texCoord.w, 0.0)) * a_size * scd + a_offset.xy);
354
-
370
+
371
+ vec2 vert = a_vertices;
372
+ vec4 gp = a_gliphParam;
373
+ if(a_texCoord.w == RTL){
374
+ vert.x = step(vert.x * 0.5 + 1.0, 1.0);
375
+ gp.x = -a_gliphParam.x;
376
+ gp.z = -(a_gliphParam.z + a_texCoord.z);
377
+ }else{
378
+ gp.z = a_gliphParam.z + a_texCoord.z;
379
+ }
380
+
381
+ vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);
382
+
355
383
  gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);
356
384
  }`,
357
385
  fragmentShader:
@@ -487,6 +515,9 @@ export function labelPicking() {
487
515
  },
488
516
  vertexShader:
489
517
  `
518
+
519
+ ${DEFINE}
520
+
490
521
  attribute vec4 a_gliphParam;
491
522
  attribute vec2 a_vertices;
492
523
  attribute vec4 a_texCoord;
@@ -519,7 +550,7 @@ export function labelPicking() {
519
550
  vec3 a_positions = a_positionsHigh + a_positionsLow;
520
551
  vec3 cameraPos = eyePositionHigh + eyePositionLow;
521
552
 
522
- if(a_texCoord.z == -1.0){
553
+ if(a_texCoord.w == EMPTY) {
523
554
  gl_Position = vec4(0.0);
524
555
  return;
525
556
  }
@@ -554,7 +585,19 @@ export function labelPicking() {
554
585
  projPos.z += depthOffset + a_offset.z;
555
586
 
556
587
  vec2 screenPos = project(projPos);
557
- vec2 v = screenPos + rotate2d(a_rotation) * ((a_vertices * a_gliphParam.xy + a_gliphParam.zw + vec2(a_texCoord.z, 0.0) + vec2(a_texCoord.w, 0.0)) * a_size * scd + a_offset.xy);
588
+
589
+ vec2 vert = a_vertices;
590
+ vec4 gp = a_gliphParam;
591
+ if(a_texCoord.w == RTL){
592
+ vert.x = step(vert.x * 0.5 + 1.0, 1.0);
593
+ gp.x = -a_gliphParam.x;
594
+ gp.z = -(a_gliphParam.z + a_texCoord.z);
595
+ }else{
596
+ gp.z = a_gliphParam.z + a_texCoord.z;
597
+ }
598
+
599
+ vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);
600
+
558
601
  gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);
559
602
  }`,
560
603
  fragmentShader:
@@ -1,148 +1,161 @@
1
- /**
2
- * @module og/terrainProvider/EmptyTerrain
3
- */
4
-
5
- "use strict";
6
-
7
- import { binarySearchFast } from "../utils/shared.js";
8
-
9
- /**
10
- * Class represents terrain provider without elevation data.
11
- * @class
12
- */
13
- class EmptyTerrain {
14
- constructor(options = {}) {
15
- this.equalizeVertices = false;
16
-
1
+ /**
2
+ * @module og/terrainProvider/EmptyTerrain
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import { binarySearchFast } from "../utils/shared.js";
8
+ import { Geoid } from "./Geoid.js";
9
+
10
+ /**
11
+ * Class represents terrain provider without elevation data.
12
+ * @class
13
+ */
14
+ class EmptyTerrain {
15
+ constructor(options = {}) {
16
+ this.equalizeVertices = false;
17
+
17
18
  this.equalizeNormals = false;
18
19
 
19
- this.isEmpty = true;
20
-
21
- /**
22
- * Provider name is "empty"
23
- * @public
24
- * @type {string}
25
- */
26
- this.name = "empty";
27
-
28
- /**
29
- * Minimal z-index value for segment elevation data handling.
30
- * @public
31
- * @type {number}
32
- */
33
- this.minZoom = 1000000;
34
-
35
- /**
36
- * Maximal z-index value for segment elevation data handling.
37
- * @public
38
- * @type {number}
39
- */
40
- this.maxZoom = 21;
41
-
42
- /**
43
- * @public
44
- * @type {Array.<number>}
45
- */
46
- this.gridSizeByZoom = options.gridSizeByZoom || [
47
- 32, 16, 16, 8, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
48
- ];
49
- //this.gridSizeByZoom = options.gridSizeByZoom || [32, 16, 16, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2];
50
-
51
- this._maxNodeZoom = this.gridSizeByZoom.length - 1;
52
-
53
- /**
54
- * Elevation grid size. Currend is 2x2 is the smallest grid size.
55
- * @public
56
- * @type {number}
57
- */
58
- this.plainGridSize = 2;
59
-
60
- /**
61
- * Planet node.
62
- * @protected
63
- * @type {Planet}
64
- */
65
- this._planet = null;
66
-
67
- this._geoid = null;
68
-
69
- // const _ellToAltFn = [
70
- // (lon, lat, alt, callback) => callback(alt),
71
- // (lon, lat, alt, callback) => callback(alt - this._geoid.getHeight(lon, lat)),
72
- // (lon, lat, alt, callback) => {
73
-
74
- // let x = mercator.getTileX(lon, zoom),
75
- // y = mercator.getTileY(lat, zoom);
76
-
77
- // let mslAlt = alt - this._geoid.getHeight(lon, lat);
78
-
79
- // if (true) {
80
-
81
- // } else {
82
-
83
- // }
84
-
85
- // return callback(mslAlt);
86
- // },
87
- // ];
88
- }
89
-
90
- static checkNoDataValue(noDataValues, value) {
91
- return binarySearchFast(noDataValues, value) !== -1;
92
- }
93
-
94
- isBlur() {
95
- return false;
96
- }
97
-
98
- set maxNodeZoom(val) {
99
- if (val > this.gridSizeByZoom.length - 1) {
100
- val = this.gridSizeByZoom.length - 1;
101
- }
102
- this._maxNodeZoom = val;
103
- }
104
-
105
- get maxNodeZoom() {
106
- return this._maxNodeZoom;
107
- }
108
-
109
- set geoid(geoid) {
110
- this._geoid = geoid;
111
- }
112
-
113
- get geoid() {
114
- return this._geoid;
115
- }
116
-
117
- /**
118
- * Loads or creates segment elevation data.
119
- * @public
120
- * @virtual
121
- * @param {Segment} segment - Segment to create elevation data.
122
- */
123
- handleSegmentTerrain(segment) {
124
- segment.terrainIsLoading = false;
125
- segment.terrainReady = true;
126
- segment.terrainExists = true;
127
- }
128
-
129
- isReady() {
130
- return (this._geoid && this._geoid.model) || !this._geoid;
131
- }
132
-
133
- /**
134
- * Abstract function
135
- * @public
136
- * @abstract
137
- */
138
- abortLoading() {}
139
-
140
- /**
141
- * Abstract function
142
- * @public
143
- * @abstract
144
- */
145
- clearCache() {}
146
- }
147
-
148
- export { EmptyTerrain };
20
+ this.isEmpty = true;
21
+
22
+ /**
23
+ * Provider name is "empty"
24
+ * @public
25
+ * @type {string}
26
+ */
27
+ this.name = "empty";
28
+
29
+ /**
30
+ * Minimal z-index value for segment elevation data handling.
31
+ * @public
32
+ * @type {number}
33
+ */
34
+ this.minZoom = 1000000;
35
+
36
+ /**
37
+ * Maximal z-index value for segment elevation data handling.
38
+ * @public
39
+ * @type {number}
40
+ */
41
+ this.maxZoom = 21;
42
+
43
+ /**
44
+ * @public
45
+ * @type {Array.<number>}
46
+ */
47
+ this.gridSizeByZoom = options.gridSizeByZoom || [
48
+ 32, 16, 16, 8, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
49
+ ];
50
+ //this.gridSizeByZoom = options.gridSizeByZoom || [32, 16, 16, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2];
51
+
52
+ this._maxNodeZoom = this.gridSizeByZoom.length - 1;
53
+
54
+ /**
55
+ * Elevation grid size. Currend is 2x2 is the smallest grid size.
56
+ * @public
57
+ * @type {number}
58
+ */
59
+ this.plainGridSize = 2;
60
+
61
+ /**
62
+ * Planet node.
63
+ * @protected
64
+ * @type {Planet}
65
+ */
66
+ this._planet = null;
67
+
68
+ this._geoid =
69
+ options.geoid ||
70
+ new Geoid({
71
+ src: options.geoidSrc || null
72
+ });
73
+
74
+ this._isReady = false;
75
+
76
+ // const _ellToAltFn = [
77
+ // (lon, lat, alt, callback) => callback(alt),
78
+ // (lon, lat, alt, callback) => callback(alt - this._geoid.getHeight(lon, lat)),
79
+ // (lon, lat, alt, callback) => {
80
+
81
+ // let x = mercator.getTileX(lon, zoom),
82
+ // y = mercator.getTileY(lat, zoom);
83
+
84
+ // let mslAlt = alt - this._geoid.getHeight(lon, lat);
85
+
86
+ // if (true) {
87
+
88
+ // } else {
89
+
90
+ // }
91
+
92
+ // return callback(mslAlt);
93
+ // },
94
+ // ];
95
+ }
96
+
97
+ static checkNoDataValue(noDataValues, value) {
98
+ return binarySearchFast(noDataValues, value) !== -1;
99
+ }
100
+
101
+ isBlur() {
102
+ return false;
103
+ }
104
+
105
+ set maxNodeZoom(val) {
106
+ if (val > this.gridSizeByZoom.length - 1) {
107
+ val = this.gridSizeByZoom.length - 1;
108
+ }
109
+ this._maxNodeZoom = val;
110
+ }
111
+
112
+ get maxNodeZoom() {
113
+ return this._maxNodeZoom;
114
+ }
115
+
116
+ set geoid(geoid) {
117
+ this._geoid = geoid;
118
+ }
119
+
120
+ get geoid() {
121
+ return this._geoid;
122
+ }
123
+
124
+ getGeoid() {
125
+ return this._geoid;
126
+ }
127
+
128
+ /**
129
+ * Loads or creates segment elevation data.
130
+ * @public
131
+ * @virtual
132
+ * @param {Segment} segment - Segment to create elevation data.
133
+ */
134
+ handleSegmentTerrain(segment) {
135
+ segment.terrainIsLoading = false;
136
+ segment.terrainReady = true;
137
+ segment.terrainExists = true;
138
+ }
139
+
140
+ isReady() {
141
+ return this._isReady;
142
+ }
143
+
144
+ /**
145
+ * Abstract function
146
+ * @public
147
+ * @abstract
148
+ */
149
+ abortLoading() {
150
+ }
151
+
152
+ /**
153
+ * Abstract function
154
+ * @public
155
+ * @abstract
156
+ */
157
+ clearCache() {
158
+ }
159
+ }
160
+
161
+ export { EmptyTerrain };