@openglobus/og 0.15.3 → 0.15.5

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 (71) hide show
  1. package/README.md +3 -7
  2. package/css/og.css +24 -15
  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 +1 -1
  9. package/src/og/Globe.js +4 -0
  10. package/src/og/LonLat.js +207 -193
  11. package/src/og/Object3d.js +1 -1
  12. package/src/og/camera/Camera.js +4 -16
  13. package/src/og/camera/PlanetCamera.js +12 -6
  14. package/src/og/control/DebugInfo.js +263 -165
  15. package/src/og/control/KeyboardNavigation.js +153 -169
  16. package/src/og/control/MouseNavigation.js +0 -20
  17. package/src/og/control/RulerSwitcher.js +4 -1
  18. package/src/og/control/SimpleNavigation.js +123 -128
  19. package/src/og/control/heightRuler/HeightRuler.js +12 -0
  20. package/src/og/control/heightRuler/HeightRulerScene.js +224 -0
  21. package/src/og/control/heightRuler/HeightRulerSwitcher.js +15 -0
  22. package/src/og/control/index.js +2 -0
  23. package/src/og/control/ruler/RulerScene.js +106 -79
  24. package/src/og/ellipsoid/Ellipsoid.js +20 -3
  25. package/src/og/entity/Entity.js +6 -6
  26. package/src/og/entity/EntityCollection.js +4 -0
  27. package/src/og/entity/GeoObjectHandler.js +3 -0
  28. package/src/og/layer/BaseGeoImage.js +152 -16
  29. package/src/og/layer/GeoImage.js +0 -91
  30. package/src/og/layer/GeoTexture2d.js +54 -143
  31. package/src/og/layer/GeoVideo.js +6 -107
  32. package/src/og/layer/Material.js +1 -1
  33. package/src/og/layer/Vector.js +8 -6
  34. package/src/og/layer/XYZ.js +2 -2
  35. package/src/og/quadTree/EntityCollectionNode.js +8 -2
  36. package/src/og/renderer/Renderer.js +91 -94
  37. package/src/og/renderer/RendererEvents.js +39 -23
  38. package/src/og/scene/BaseNode.js +113 -113
  39. package/src/og/scene/Planet.js +20 -13
  40. package/src/og/scene/RenderNode.js +42 -9
  41. package/src/og/segment/Segment.js +38 -45
  42. package/src/og/shaders/geoObject.js +12 -10
  43. package/src/og/shaders/pickingMask.js +1 -1
  44. package/src/og/utils/GeoImageCreator.js +61 -21
  45. package/src/og/utils/VectorTileCreator.js +32 -49
  46. package/src/og/webgl/Framebuffer.js +5 -0
  47. package/types/LonLat.d.ts +8 -0
  48. package/types/camera/PlanetCamera.d.ts +1 -1
  49. package/types/control/DebugInfo.d.ts +4 -0
  50. package/types/control/SimpleNavigation.d.ts +1 -0
  51. package/types/control/heightRuler/HeightRuler.d.ts +6 -0
  52. package/types/control/heightRuler/HeightRulerScene.d.ts +23 -0
  53. package/types/control/index.d.ts +2 -1
  54. package/types/control/ruler/RulerScene.d.ts +8 -5
  55. package/types/control/selection/SelectionScene.d.ts +0 -1
  56. package/types/ellipsoid/Ellipsoid.d.ts +13 -1
  57. package/types/entity/EntityCollection.d.ts +1 -0
  58. package/types/layer/BaseGeoImage.d.ts +17 -3
  59. package/types/layer/GeoImage.d.ts +0 -8
  60. package/types/layer/GeoTexture2d.d.ts +0 -2
  61. package/types/layer/GeoVideo.d.ts +0 -8
  62. package/types/layer/XYZ.d.ts +1 -1
  63. package/types/renderer/Renderer.d.ts +12 -3
  64. package/types/scene/Axes.d.ts +1 -1
  65. package/types/scene/BaseNode.d.ts +2 -2
  66. package/types/scene/Planet.d.ts +0 -5
  67. package/types/scene/RenderNode.d.ts +16 -9
  68. package/types/scene/SkyBox.d.ts +1 -1
  69. package/types/segment/Segment.d.ts +2 -3
  70. package/types/utils/VectorTileCreator.d.ts +1 -3
  71. package/types/webgl/Framebuffer.d.ts +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openglobus/og",
3
- "version": "0.15.3",
3
+ "version": "0.15.5",
4
4
  "description": "[OpenGlobus](https://www.openglobus.org/) is a javascript 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"
package/src/og/Globe.js CHANGED
@@ -1,3 +1,5 @@
1
+ // StandWithUkraine
2
+
1
3
  /**
2
4
  * @module og/Globe
3
5
  */
@@ -76,6 +78,8 @@ class Globe {
76
78
  * @param {*} options
77
79
  */
78
80
  constructor(options) {
81
+ window.__globus__ = this;
82
+
79
83
  // Canvas creation
80
84
  var _canvasId = CANVAS_ID_PREFIX + Globe._staticCounter++;
81
85
 
package/src/og/LonLat.js CHANGED
@@ -1,193 +1,207 @@
1
- /**
2
- * @module og/LonLat
3
- */
4
-
5
- "use strict";
6
-
7
- import * as mercator from "./mercator.js";
8
-
9
- const HALF_PI = Math.PI * 0.5;
10
- const INV_PI_BY_180 = 180.0 / Math.PI;
11
- const INV_PI_BY_360 = INV_PI_BY_180 * 2.0;
12
- const PI_BY_360 = Math.PI / 360.0;
13
- const INV_PI_BY_180_HALF_PI = INV_PI_BY_180 * HALF_PI;
14
-
15
- /**
16
- * Represents a geographical point with a certain latitude, longitude and height.
17
- * @class
18
- * @param {number} [lon] - Longitude.
19
- * @param {number} [lat] - Latitude.
20
- * @param {number} [height] - Height over the surface.
21
- */
22
- export class LonLat {
23
- /**
24
- * @param {number} [lon] - Longitude.
25
- * @param {number} [lat] - Latitude.
26
- * @param {number} [height] - Height over the surface.
27
- */
28
- constructor(lon = 0 , lat = 0, height = 0) {
29
- /**
30
- * Longitude.
31
- * @public
32
- * @type {number}
33
- */
34
- this.lon = lon;
35
-
36
- /**
37
- * Latitude.
38
- * @public
39
- * @type {number}
40
- */
41
- this.lat = lat;
42
-
43
- /**
44
- * Height.
45
- * @public
46
- * @type {number}
47
- */
48
- this.height = height;
49
- }
50
-
51
- isZero() {
52
- return this.lon === 0.0 && this.lat === 0.0 && this.height === 0.0;
53
- }
54
-
55
- /**
56
- * Creates coordinates array.
57
- * @static
58
- * @param{Array.<Array<number>>} arr - Coordinates array data. (exactly 3 entries)
59
- * @return{Array.<LonLat>} the same coordinates array but each element is LonLat instance.
60
- */
61
- static join(arr) {
62
- var res = [];
63
- for (var i = 0; i < arr.length; i++) {
64
- var ai = arr[i];
65
- res[i] = new LonLat(ai[0], ai[1], ai[2]);
66
- }
67
- return res;
68
- }
69
-
70
- /**
71
- * Creates an object by coordinate array.
72
- * @static
73
- * @param {Array.<number>} arr - Coordiante array, where first is longitude, second is latitude and third is a height. (exactly 3 entries)
74
- * @returns {LonLat} -
75
- */
76
- static createFromArray(arr) {
77
- return new LonLat(arr[0], arr[1], arr[2]);
78
- }
79
-
80
- /**
81
- * Converts degrees to mercator coordinates.
82
- * @static
83
- * @param {number} lon - Degrees longitude.
84
- * @param {number} lat - Degrees latitude.
85
- * @param {number} [height] - Height.
86
- * @returns {LonLat} -
87
- */
88
- static forwardMercator(lon, lat, height) {
89
- return new LonLat(
90
- lon * mercator.POLE_BY_180,
91
- Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI,
92
- height
93
- );
94
- }
95
-
96
- /**
97
- * Converts mercator to degrees coordinates.
98
- * @static
99
- * @param {number} x - Mercator longitude.
100
- * @param {number} y - Mercator latitude.
101
- * @param {number} [height] - Height.
102
- * @returns {LonLat} -
103
- */
104
- static inverseMercator(x, y, height = 0) {
105
- return new LonLat(
106
- x * mercator.INV_POLE_BY_180,
107
- INV_PI_BY_360 * Math.atan(Math.exp(y * mercator.PI_BY_POLE)) - INV_PI_BY_180_HALF_PI,
108
- height
109
- );
110
- }
111
-
112
- /**
113
- * Sets coordinates.
114
- * @public
115
- * @param {number} [lon] - Longitude.
116
- * @param {number} [lat] - Latitude.
117
- * @param {number} [height] - Height.
118
- * @returns {LonLat} -
119
- */
120
- set(lon = 0, lat = 0, height = 0) {
121
- this.lon = lon;
122
- this.lat = lat;
123
- this.height = height;
124
- return this;
125
- }
126
-
127
- /**
128
- * Copy coordinates.
129
- * @public
130
- * @param {LonLat} [lonLat] - Coordinates to copy.
131
- * @returns {LonLat} -
132
- */
133
- copy(lonLat) {
134
- this.lon = lonLat.lon;
135
- this.lat = lonLat.lat;
136
- this.height = lonLat.height;
137
- return this;
138
- }
139
-
140
- /**
141
- * Clone the coordiante.
142
- * @public
143
- * @returns {LonLat} -
144
- */
145
- clone() {
146
- return new LonLat(this.lon, this.lat, this.height);
147
- }
148
-
149
- /**
150
- * Converts to mercator coordinates.
151
- * @public
152
- * @returns {LonLat} -
153
- */
154
- forwardMercator() {
155
- return LonLat.forwardMercator(this.lon, this.lat, this.height);
156
- }
157
-
158
- forwardMercatorEPS01() {
159
- var lat = this.lat;
160
- if (lat > 89.9) {
161
- lat = 89.9;
162
- } else if (lat < -89.9) {
163
- lat = -89.9;
164
- }
165
- return new LonLat(
166
- this.lon * mercator.POLE_BY_180,
167
- Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI
168
- );
169
- }
170
-
171
- /**
172
- * Converts from mercator coordinates.
173
- * @public
174
- * @returns {LonLat} -
175
- */
176
- inverseMercator() {
177
- return LonLat.inverseMercator(this.lon, this.lat, this.height);
178
- }
179
-
180
- /**
181
- * Compares coordinates.
182
- * @public
183
- * @param {LonLat} b - Coordinate to compare with.
184
- * @returns {boolean} -
185
- */
186
- equal(b) {
187
- if (b.height) {
188
- return this.lon === b.lon && this.lat === b.lat && this.height === b.height;
189
- } else {
190
- return this.lon === b.lon && this.lat === b.lat;
191
- }
192
- }
193
- }
1
+ /**
2
+ * @module og/LonLat
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import * as mercator from "./mercator.js";
8
+
9
+ const HALF_PI = Math.PI * 0.5;
10
+ const INV_PI_BY_180 = 180.0 / Math.PI;
11
+ const INV_PI_BY_360 = INV_PI_BY_180 * 2.0;
12
+ const PI_BY_360 = Math.PI / 360.0;
13
+ const INV_PI_BY_180_HALF_PI = INV_PI_BY_180 * HALF_PI;
14
+
15
+ /**
16
+ * Represents a geographical point with a certain latitude, longitude and height.
17
+ * @class
18
+ * @param {number} [lon] - Longitude.
19
+ * @param {number} [lat] - Latitude.
20
+ * @param {number} [height] - Height over the surface.
21
+ */
22
+ export class LonLat {
23
+ /**
24
+ * @param {number} [lon] - Longitude.
25
+ * @param {number} [lat] - Latitude.
26
+ * @param {number} [height] - Height over the surface.
27
+ */
28
+ constructor(lon = 0, lat = 0, height = 0) {
29
+ /**
30
+ * Longitude.
31
+ * @public
32
+ * @type {number}
33
+ */
34
+ this.lon = lon;
35
+
36
+ /**
37
+ * Latitude.
38
+ * @public
39
+ * @type {number}
40
+ */
41
+ this.lat = lat;
42
+
43
+ /**
44
+ * Height.
45
+ * @public
46
+ * @type {number}
47
+ */
48
+ this.height = height;
49
+ }
50
+
51
+ isZero() {
52
+ return this.lon === 0.0 && this.lat === 0.0 && this.height === 0.0;
53
+ }
54
+
55
+ /**
56
+ * Creates coordinates array.
57
+ * @static
58
+ * @param{Array.<Array<number>>} arr - Coordinates array data. (exactly 3 entries)
59
+ * @return{Array.<LonLat>} the same coordinates array but each element is LonLat instance.
60
+ */
61
+ static join(arr) {
62
+ var res = [];
63
+ for (var i = 0; i < arr.length; i++) {
64
+ var ai = arr[i];
65
+ res[i] = new LonLat(ai[0], ai[1], ai[2]);
66
+ }
67
+ return res;
68
+ }
69
+
70
+ /**
71
+ * Creates an object by coordinate array.
72
+ * @static
73
+ * @param {Array.<number>} arr - Coordiante array, where first is longitude, second is latitude and third is a height. (exactly 3 entries)
74
+ * @returns {LonLat} -
75
+ */
76
+ static createFromArray(arr) {
77
+ return new LonLat(arr[0], arr[1], arr[2]);
78
+ }
79
+
80
+ /**
81
+ * Converts degrees to mercator coordinates.
82
+ * @static
83
+ * @param {number} lon - Degrees longitude.
84
+ * @param {number} lat - Degrees latitude.
85
+ * @param {number} [height] - Height.
86
+ * @returns {LonLat} -
87
+ */
88
+ static forwardMercator(lon, lat, height) {
89
+ return new LonLat(
90
+ lon * mercator.POLE_BY_180,
91
+ Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI,
92
+ height
93
+ );
94
+ }
95
+
96
+ /**
97
+ * Converts degrees to mercator coordinates.
98
+ * @static
99
+ * @param {LonLat} lonLat - Input geodetic degree coordinates
100
+ * @param {LonLat} res - Output mercator coordinates
101
+ * @returns {LonLat} - Output mercator coordinates
102
+ */
103
+ static forwardMercatorRes(lonLat, res) {
104
+ res.lon = lonLat.lon * mercator.POLE_BY_180;
105
+ res.lat = Math.log(Math.tan((90.0 + lonLat.lat) * PI_BY_360)) * mercator.POLE_BY_PI,
106
+ res.height = lonLat.height;
107
+ return res;
108
+ }
109
+
110
+ /**
111
+ * Converts mercator to degrees coordinates.
112
+ * @static
113
+ * @param {number} x - Mercator longitude.
114
+ * @param {number} y - Mercator latitude.
115
+ * @param {number} [height] - Height.
116
+ * @returns {LonLat} -
117
+ */
118
+ static inverseMercator(x, y, height = 0) {
119
+ return new LonLat(
120
+ x * mercator.INV_POLE_BY_180,
121
+ INV_PI_BY_360 * Math.atan(Math.exp(y * mercator.PI_BY_POLE)) - INV_PI_BY_180_HALF_PI,
122
+ height
123
+ );
124
+ }
125
+
126
+ /**
127
+ * Sets coordinates.
128
+ * @public
129
+ * @param {number} [lon] - Longitude.
130
+ * @param {number} [lat] - Latitude.
131
+ * @param {number} [height] - Height.
132
+ * @returns {LonLat} -
133
+ */
134
+ set(lon = 0, lat = 0, height = 0) {
135
+ this.lon = lon;
136
+ this.lat = lat;
137
+ this.height = height;
138
+ return this;
139
+ }
140
+
141
+ /**
142
+ * Copy coordinates.
143
+ * @public
144
+ * @param {LonLat} [lonLat] - Coordinates to copy.
145
+ * @returns {LonLat} -
146
+ */
147
+ copy(lonLat) {
148
+ this.lon = lonLat.lon;
149
+ this.lat = lonLat.lat;
150
+ this.height = lonLat.height;
151
+ return this;
152
+ }
153
+
154
+ /**
155
+ * Clone the coordiante.
156
+ * @public
157
+ * @returns {LonLat} -
158
+ */
159
+ clone() {
160
+ return new LonLat(this.lon, this.lat, this.height);
161
+ }
162
+
163
+ /**
164
+ * Converts to mercator coordinates.
165
+ * @public
166
+ * @returns {LonLat} -
167
+ */
168
+ forwardMercator() {
169
+ return LonLat.forwardMercator(this.lon, this.lat, this.height);
170
+ }
171
+
172
+ forwardMercatorEPS01() {
173
+ var lat = this.lat;
174
+ if (lat > 89.9) {
175
+ lat = 89.9;
176
+ } else if (lat < -89.9) {
177
+ lat = -89.9;
178
+ }
179
+ return new LonLat(
180
+ this.lon * mercator.POLE_BY_180,
181
+ Math.log(Math.tan((90.0 + lat) * PI_BY_360)) * mercator.POLE_BY_PI
182
+ );
183
+ }
184
+
185
+ /**
186
+ * Converts from mercator coordinates.
187
+ * @public
188
+ * @returns {LonLat} -
189
+ */
190
+ inverseMercator() {
191
+ return LonLat.inverseMercator(this.lon, this.lat, this.height);
192
+ }
193
+
194
+ /**
195
+ * Compares coordinates.
196
+ * @public
197
+ * @param {LonLat} b - Coordinate to compare with.
198
+ * @returns {boolean} -
199
+ */
200
+ equal(b) {
201
+ if (b.height) {
202
+ return this.lon === b.lon && this.lat === b.lat && this.height === b.height;
203
+ } else {
204
+ return this.lon === b.lon && this.lat === b.lat;
205
+ }
206
+ }
207
+ }
@@ -44,7 +44,7 @@ class Object3d {
44
44
  this._normals = data.normals || [];
45
45
  } else {
46
46
  this._normals = Object3d.getNormals(this._vertices);
47
- this._indices = new Array(this._vertices.length);
47
+ this._indices = new Array(this._vertices.length/ 3);
48
48
  for (let i = 0, len = this._indices.length; i < len; i++) {
49
49
  this._indices[i] = i;
50
50
  }
@@ -255,22 +255,10 @@ class Camera {
255
255
  Vec3.doubleToTwoFloat32Array(eye, this.eyeHigh, this.eyeLow);
256
256
 
257
257
  this._viewMatrix.set([
258
- u.x,
259
- v.x,
260
- n.x,
261
- 0.0,
262
- u.y,
263
- v.y,
264
- n.y,
265
- 0.0,
266
- u.z,
267
- v.z,
268
- n.z,
269
- 0.0,
270
- -eye.dot(u),
271
- -eye.dot(v),
272
- -eye.dot(n),
273
- 1.0
258
+ u.x, v.x, n.x, 0.0,
259
+ u.y, v.y, n.y, 0.0,
260
+ u.z, v.z, n.z, 0.0,
261
+ -eye.dot(u), -eye.dot(v), -eye.dot(n), 1.0
274
262
  ]);
275
263
 
276
264
  // do not cleanup, someday it will be using
@@ -13,6 +13,7 @@ import { Ray } from "../math/Ray.js";
13
13
  import { Vec3 } from "../math/Vec3.js";
14
14
  import * as mercator from "../mercator.js";
15
15
  import { Camera } from "./Camera.js";
16
+ import { Ellipsoid } from "../ellipsoid/index.js";
16
17
 
17
18
  /**
18
19
  * Planet camera.
@@ -122,7 +123,7 @@ class PlanetCamera extends Camera {
122
123
  this._flying = false;
123
124
  this._checkTerrainCollision = true;
124
125
 
125
- this._velCart = new Vec3(0.0,0.0,0.0);
126
+ this._velCart = new Vec3(0.0, 0.0, 0.0);
126
127
  }
127
128
 
128
129
  setTerrainCollisionActivity(isActive) {
@@ -144,16 +145,17 @@ class PlanetCamera extends Camera {
144
145
  }
145
146
 
146
147
  super.update();
147
- this.updateGeodeticPosition();
148
+
148
149
  this.eyeNorm = this.eye.normal();
149
150
  this.slope = this._b.dot(this.eyeNorm);
151
+
150
152
  this.events.dispatch(this.events.viewchange, this);
151
153
  }
152
154
 
153
155
  updateGeodeticPosition() {
154
- this._lonLat = this.planet.ellipsoid.cartesianToLonLat(this.eye);
156
+ this.planet.ellipsoid.cartesianToLonLatRes(this.eye, this._lonLat);
155
157
  if (Math.abs(this._lonLat.lat) <= mercator.MAX_LAT) {
156
- this._lonLatMerc = this._lonLat.forwardMercator();
158
+ LonLat.forwardMercatorRes(this._lonLat, this._lonLatMerc);
157
159
  }
158
160
  }
159
161
 
@@ -163,11 +165,14 @@ class PlanetCamera extends Camera {
163
165
  * @param {number} alt - Altitude over the terrain.
164
166
  */
165
167
  setAltitude(alt) {
166
- var n = this.eye.normal();
167
- var t = this._terrainPoint;
168
+
169
+ let t = this._terrainPoint;
170
+ let n = this.planet.ellipsoid.getSurfaceNormal3v(this.eye);
171
+
168
172
  this.eye.x = n.x * alt + t.x;
169
173
  this.eye.y = n.y * alt + t.y;
170
174
  this.eye.z = n.z * alt + t.z;
175
+
171
176
  this._terrainAltitude = alt;
172
177
  }
173
178
 
@@ -633,6 +638,7 @@ class PlanetCamera extends Camera {
633
638
  if (this._terrainAltitude < this.minAltitude && this._checkTerrainCollision) {
634
639
  this.setAltitude(this.minAltitude);
635
640
  }
641
+ return this._terrainPoint;
636
642
  }
637
643
  }
638
644