@openglobus/og 0.14.4 → 0.15.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 (102) hide show
  1. package/css/og.css +377 -274
  2. package/dist/@openglobus/og.css +1 -1
  3. package/dist/@openglobus/og.esm.js +2 -2
  4. package/dist/@openglobus/og.esm.js.map +1 -1
  5. package/dist/@openglobus/og.umd.js +2 -2
  6. package/dist/@openglobus/og.umd.js.map +1 -1
  7. package/package.json +18 -17
  8. package/src/og/Clock.js +218 -194
  9. package/src/og/Globe.js +1 -3
  10. package/src/og/Object3d.js +104 -145
  11. package/src/og/camera/Camera.js +23 -19
  12. package/src/og/cons.js +107 -107
  13. package/src/og/control/Atmosphere.js +396 -0
  14. package/src/og/control/CompassButton.js +11 -18
  15. package/src/og/control/Control.js +187 -188
  16. package/src/og/control/GeoImageDragControl.js +84 -66
  17. package/src/og/control/LayerSwitcher.js +46 -145
  18. package/src/og/control/Lighting.js +314 -186
  19. package/src/og/control/RulerSwitcher.js +24 -19
  20. package/src/og/control/SimpleSkyBackground.js +38 -12
  21. package/src/og/control/Sun.js +2 -0
  22. package/src/og/control/ZoomControl.js +30 -42
  23. package/src/og/control/ruler/RulerScene.js +5 -23
  24. package/src/og/control/selection/Selection.js +21 -50
  25. package/src/og/control/selection/SelectionScene.js +15 -29
  26. package/src/og/control/timeline/TimelineControl.js +99 -0
  27. package/src/og/control/timeline/TimelineModel.js +133 -0
  28. package/src/og/control/timeline/TimelineView.js +449 -0
  29. package/src/og/control/timeline/timelineUtils.js +132 -0
  30. package/src/og/entity/Entity.js +30 -3
  31. package/src/og/entity/EntityCollection.js +0 -2
  32. package/src/og/entity/GeoObject.js +72 -56
  33. package/src/og/entity/GeoObjectHandler.js +487 -656
  34. package/src/og/input/input.js +3 -1
  35. package/src/og/layer/CanvasTiles.js +39 -34
  36. package/src/og/layer/Layer.js +2 -0
  37. package/src/og/layer/Material.js +1 -8
  38. package/src/og/light/LightSource.js +2 -0
  39. package/src/og/quadTree/Node.js +2 -1
  40. package/src/og/renderer/Renderer.js +26 -42
  41. package/src/og/renderer/RendererEvents.js +4 -4
  42. package/src/og/scene/Planet.js +276 -59
  43. package/src/og/scene/RenderNode.js +27 -12
  44. package/src/og/segment/Segment.js +0 -5
  45. package/src/og/shaders/atmos.js +332 -0
  46. package/src/og/shaders/drawnode.js +475 -109
  47. package/src/og/shaders/geoObject.js +96 -51
  48. package/src/og/shaders/polyline.js +212 -17
  49. package/src/og/shaders/utils.js +88 -0
  50. package/src/og/terrain/GlobusTerrain.js +2 -2
  51. package/src/og/ui/Button.js +106 -0
  52. package/src/og/ui/ButtonGroup.js +57 -0
  53. package/src/og/ui/Dialog.js +242 -0
  54. package/src/og/ui/Slider.js +144 -0
  55. package/src/og/ui/ToggleButton.js +51 -0
  56. package/src/og/ui/View.js +190 -0
  57. package/src/og/utils/shared.js +51 -33
  58. package/src/og/webgl/Framebuffer.js +308 -387
  59. package/src/og/webgl/Handler.js +68 -21
  60. package/src/og/webgl/Multisample.js +8 -0
  61. package/types/Clock.d.ts +7 -2
  62. package/types/Object3d.d.ts +14 -3
  63. package/types/camera/Camera.d.ts +15 -14
  64. package/types/control/Atmosphere.d.ts +15 -0
  65. package/types/control/CompassButton.d.ts +1 -2
  66. package/types/control/GeoImageDragControl.d.ts +7 -1
  67. package/types/control/LayerSwitcher.d.ts +4 -5
  68. package/types/control/Lighting.d.ts +32 -7
  69. package/types/control/SimpleSkyBackground.d.ts +4 -0
  70. package/types/control/ZoomControl.d.ts +0 -1
  71. package/types/control/ruler/RulerScene.d.ts +0 -1
  72. package/types/control/selection/Selection.d.ts +2 -4
  73. package/types/control/selection/SelectionScene.d.ts +0 -1
  74. package/types/entity/Entity.d.ts +8 -0
  75. package/types/entity/GeoObject.d.ts +28 -22
  76. package/types/entity/GeoObjectHandler.d.ts +16 -56
  77. package/types/input/input.d.ts +2 -0
  78. package/types/layer/CanvasTiles.d.ts +1 -0
  79. package/types/layer/Layer.d.ts +1 -0
  80. package/types/math/Plane.d.ts +1 -1
  81. package/types/renderer/Renderer.d.ts +7 -1
  82. package/types/scene/Planet.d.ts +20 -2
  83. package/types/scene/RenderNode.d.ts +2 -1
  84. package/types/segment/Segment.d.ts +1 -1
  85. package/types/shaders/atmos.d.ts +4 -0
  86. package/types/shaders/drawnode.d.ts +3 -2
  87. package/types/shaders/utils.d.ts +1 -0
  88. package/types/terrain/GlobusTerrain.d.ts +1 -1
  89. package/types/ui/Button.d.ts +21 -0
  90. package/types/ui/Dialog.d.ts +41 -0
  91. package/types/ui/Slider.d.ts +30 -0
  92. package/types/ui/ToggleButton.d.ts +10 -0
  93. package/types/ui/View.d.ts +32 -0
  94. package/types/utils/shared.d.ts +16 -14
  95. package/types/webgl/Framebuffer.d.ts +2 -5
  96. package/types/webgl/Handler.d.ts +11 -9
  97. package/types/webgl/Multisample.d.ts +2 -0
  98. package/src/og/ajax.js +0 -204
  99. package/src/og/entity/Object3d.js +0 -504
  100. package/types/ajax.d.ts +0 -24
  101. /package/src/og/{control → ui}/UIhelpers.js +0 -0
  102. /package/types/{control → ui}/UIhelpers.d.ts +0 -0
@@ -0,0 +1,132 @@
1
+ 'use strict';
2
+
3
+ import * as math from '../../math.js';
4
+
5
+ export function addSeconds(date, seconds) {
6
+ return new Date(+date + seconds * 1000);
7
+ }
8
+
9
+ export function dateToStr(date, showTime = true, showMilliseconds = false) {
10
+
11
+ let month = MONTHS[date.getMonth()],
12
+ day = date.getUTCDate(),
13
+ year = date.getUTCFullYear();
14
+
15
+ if (showTime) {
16
+ let h = date.getUTCHours().toString().padStart(2, '0'),
17
+ m = date.getUTCMinutes().toString().padStart(2, '0'),
18
+ s = date.getUTCSeconds().toString().padStart(2, '0');
19
+
20
+ if (showMilliseconds) {
21
+ let ms = date.getUTCMilliseconds().toString().padStart(3, '0');
22
+ return `${month} ${day} ${year} ${h}:${m}:${s}.${ms}`;
23
+ }
24
+
25
+ return `${month} ${day} ${year} ${h}:${m}:${s}`;
26
+ }
27
+
28
+ return `${month} ${day} ${year}`;
29
+ }
30
+
31
+ export function createCanvasHTML() {
32
+ return document.createElement("canvas");
33
+ }
34
+
35
+ export function getNearestTimeLeft(t, div) {
36
+ return t - (t % div);
37
+ }
38
+
39
+ export function drawNotch(ctx, xOffset = 0, size = 10, thickness = 2, color = "white") {
40
+ ctx.lineWidth = thickness;
41
+ ctx.strokeStyle = color;
42
+ ctx.beginPath();
43
+ ctx.moveTo(xOffset, 0);
44
+ ctx.lineTo(xOffset, size);
45
+ ctx.stroke();
46
+ }
47
+
48
+ export function drawText(ctx, text, x, y, font = "12px Arial", fillStyle = "black", align = "left", baseLine = "bottom", rotDeg) {
49
+ ctx.save();
50
+ ctx.translate(x, y);
51
+ ctx.rotate(rotDeg * math.RADIANS);
52
+ ctx.fillStyle = fillStyle;
53
+ ctx.textBaseline = baseLine;
54
+ ctx.font = font;
55
+ ctx.textAlign = align;
56
+ ctx.fillText(text, 0, 0);
57
+ ctx.restore();
58
+ }
59
+
60
+ export const SCALES = [
61
+ [0.001, 10],
62
+ [0.002, 10],
63
+ [0.005, 10],
64
+ [0.01, 10],
65
+ [0.02, 10],
66
+ [0.05, 10],
67
+ [0.1, 10],
68
+ [0.25, 10],
69
+ [0.5, 5],
70
+ [1.0, 10],
71
+ [2.0, 10],
72
+ [5.0, 5],
73
+ [10.0, 10],
74
+ [15.0, 15],
75
+ [30.0, 6],
76
+ [60.0, 12], // 1min
77
+ [120.0, 12], // 2min
78
+ [300.0, 5], // 5min
79
+ [600.0, 10], // 10min
80
+ [900.0, 15], // 15min
81
+ [1800.0, 6], // 30min
82
+ [3600.0, 12], // 1hr
83
+ [7200.0, 10], // 2hr
84
+ [14400.0, 4], // 4hr
85
+ [21600.0, 6], // 6hr
86
+ [43200.0, 12], // 12hr
87
+ [86400.0, 24], // 24hr
88
+ [172800.0, 2], // 2days
89
+ [345600.0, 4], // 4days
90
+ [604800.0, 7], // 7days
91
+ [1296000.0, 15], // 15days
92
+ [2592000.0, 5], // 30days
93
+ [5184000.0, 6], // 60days
94
+ [7776000.0, 9], // 90days
95
+ [15552000.0, 18], // 180days
96
+ [31536000.0, 12], // 365days
97
+ [63072000.0, 2], // 2years
98
+ [126144000.0, 4], // 4years
99
+ [157680000.0, 5], // 5years
100
+ [315360000.0, 10], // 10years
101
+ [630720000.0, 2], // 20years
102
+ [1261440000.0, 4], // 40years
103
+ [1576800000.0, 5], // 50years
104
+ [3153600000.0, 10], // 100years
105
+ [6307200000.0, 2], // 200years
106
+ [12614400000.0, 4], // 400years
107
+ [15768000000.0, 5], // 500years
108
+ [31536000000.0, 10], // 1000years
109
+ ];
110
+
111
+ export function getScale(seconds) {
112
+ for (let i = 0, len = SCALES.length; i < len; i++) {
113
+ if (SCALES[i][0] > seconds) {
114
+ return SCALES[i - 1];
115
+ }
116
+ }
117
+ }
118
+
119
+ export const MONTHS = [
120
+ "Jan",
121
+ "Feb",
122
+ "Mar",
123
+ "Apr",
124
+ "May",
125
+ "Jun",
126
+ "Jul",
127
+ "Aug",
128
+ "Sep",
129
+ "Oct",
130
+ "Nov",
131
+ "Dec",
132
+ ];
@@ -438,13 +438,40 @@ class Entity {
438
438
 
439
439
  let ec = this._entityCollection;
440
440
  if (ec && ec.renderNode && ec.renderNode.ellipsoid) {
441
- if (Math.abs(lonlat.lat) < mercator.MAX_LAT) {
442
- this._lonlatMerc = lonlat.forwardMercator();
441
+ if (Math.abs(l.lat) < mercator.MAX_LAT) {
442
+ this._lonlatMerc = l.forwardMercator();
443
443
  } else {
444
444
  this._lonlatMerc = null;
445
445
  }
446
446
 
447
- ec.renderNode.ellipsoid.lonLatToCartesianRes(lonlat, this._cartesian);
447
+ ec.renderNode.ellipsoid.lonLatToCartesianRes(l, this._cartesian);
448
+ this.setCartesian3v(this._cartesian);
449
+ }
450
+ }
451
+
452
+ /**
453
+ * Sets geodetic coordinates of the entity point object.
454
+ * @public
455
+ * @param {number} lon - Longitude.
456
+ * @param {number} lat - Latitude
457
+ * @param {number} [height] - Height
458
+ */
459
+ setLonLat2(lon, lat, height) {
460
+ let l = this._lonlat;
461
+
462
+ l.lon = lon;
463
+ l.lat = lat;
464
+ l.height = height != undefined ? height : l.height;
465
+
466
+ let ec = this._entityCollection;
467
+ if (ec && ec.renderNode && ec.renderNode.ellipsoid) {
468
+ if (Math.abs(l.lat) < mercator.MAX_LAT) {
469
+ this._lonlatMerc = l.forwardMercator();
470
+ } else {
471
+ this._lonlatMerc = null;
472
+ }
473
+
474
+ ec.renderNode.ellipsoid.lonLatToCartesianRes(l, this._cartesian);
448
475
  this.setCartesian3v(this._cartesian);
449
476
  }
450
477
  }
@@ -505,9 +505,7 @@ class EntityCollection {
505
505
  this.billboardHandler.setRenderer(renderNode.renderer);
506
506
  this.labelHandler.setRenderer(renderNode.renderer);
507
507
  this.rayHandler.setRenderer(renderNode.renderer);
508
-
509
508
  this.geoObjectHandler.setRenderNode(renderNode);
510
-
511
509
  this.shapeHandler.setRenderNode(renderNode);
512
510
  this.polylineHandler.setRenderNode(renderNode);
513
511
  this.pointCloudHandler.setRenderNode(renderNode);
@@ -17,11 +17,19 @@ import { Planet } from "../scene/Planet.js";
17
17
  */
18
18
 
19
19
  class GeoObject {
20
- constructor(options) {
21
- options = options || {};
20
+ constructor(options = {}) {
22
21
 
23
- this.scale = options.scale || 1.0;
24
- this.scaleByDistance = new Float32Array(options.scaleByDistance || [MAX32, MAX32, MAX32]);
22
+ this.tag = options.tag || "none";
23
+
24
+ // TODO: not instanced
25
+ this.instanced = true;
26
+
27
+ /**
28
+ * Entity instance that holds this geo object.
29
+ * @protected
30
+ * @type {Entity}
31
+ */
32
+ this._entity = null;
25
33
 
26
34
  /**
27
35
  * Geo object center cartesian position.
@@ -31,17 +39,14 @@ class GeoObject {
31
39
  this._position = utils.createVector3(options.position);
32
40
 
33
41
  this._positionHigh = new Vec3();
34
-
35
42
  this._positionLow = new Vec3();
36
-
37
43
  Vec3.doubleToTwoFloats(this._position, this._positionHigh, this._positionLow);
38
44
 
39
45
  this._pitch = options.pitch || 0.0;
40
46
  this._yaw = options.yaw || 0.0;
41
47
  this._roll = options.roll || 0.0;
42
48
 
43
- this._planet = options.planet || null;
44
- this._lonLatAlt = new LonLat(0, 0, 100000);
49
+ this._scale = options.scale || 1.0;
45
50
 
46
51
  /**
47
52
  * RGBA color.
@@ -54,25 +59,51 @@ class GeoObject {
54
59
 
55
60
  this._handler = null;
56
61
  this._handlerIndex = -1;
57
- this._vertices = options.vertices;
58
- this._normals = options.normals;
59
- this._indices = options.indices;
60
- this.instanced = options.instanced;
61
- this.tag = options.tag || "none";
62
- if (options.indices) {
63
- this._indicesCount = options.indices.length;
64
- }
65
- if (options.vertices) {
66
- this._verticesCount = Math.floor(options.vertices.length / 3);
67
- }
62
+
63
+ this._tagData = null;
64
+ this._tagDataIndex = -1;
65
+
66
+ this._object3d = options.object3d;
67
+ }
68
+
69
+ getPosition() {
70
+ return this._position;
71
+ }
72
+
73
+ getPitch() {
74
+ return this._pitch;
68
75
  }
69
76
 
70
- get planet() {
71
- return this._handler && this._handler._planet;
77
+ getYaw() {
78
+ return this._yaw;
72
79
  }
73
80
 
74
- get renderer() {
75
- return this.planet && this.planet.renderer;
81
+ getRoll() {
82
+ return this._roll;
83
+ }
84
+
85
+ getDirection() {
86
+ return this._direction;
87
+ }
88
+
89
+ get object3d() {
90
+ return this._object3d;
91
+ }
92
+
93
+ get vertices() {
94
+ return this._object3d.vertices;
95
+ }
96
+
97
+ get normals() {
98
+ return this._object3d.normals;
99
+ }
100
+
101
+ get texCoords() {
102
+ return this._object3d.texCoords;
103
+ }
104
+
105
+ get indices() {
106
+ return this._object3d.indices;
76
107
  }
77
108
 
78
109
  /**
@@ -86,7 +117,7 @@ class GeoObject {
86
117
  }
87
118
 
88
119
  /**
89
- * Sets RGBA color. Each channel from 0.0 to 1.0.
120
+ * Sets color.
90
121
  * @public
91
122
  * @param {number} r - Red.
92
123
  * @param {number} g - Green.
@@ -98,11 +129,11 @@ class GeoObject {
98
129
  this._color.y = g;
99
130
  this._color.z = b;
100
131
  a != undefined && (this._color.w = a);
101
- this._handler && this._handler.setRgbaArr(this._handlerIndex, this._color);
132
+ this._handler && this._handler.setRgbaArr(this._tagData, this._tagDataIndex, this._color);
102
133
  }
103
134
 
104
135
  /**
105
- * Sets RGBA color. Each channel from 0.0 to 1.0.
136
+ * Sets color.
106
137
  * @public
107
138
  * @param {og.Vec4} color - RGBA vector.
108
139
  */
@@ -111,7 +142,7 @@ class GeoObject {
111
142
  this._color.y = color.y;
112
143
  this._color.z = color.z;
113
144
  color.w != undefined && (this._color.w = color.w);
114
- this._handler && this._handler.setRgbaArr(this._handlerIndex, color);
145
+ this._handler && this._handler.setRgbaArr(this._tagData, this._tagDataIndex, color);
115
146
  }
116
147
 
117
148
  /**
@@ -121,11 +152,11 @@ class GeoObject {
121
152
  */
122
153
  setVisibility(visibility) {
123
154
  this._visibility = visibility;
124
- this._handler && this._handler.setVisibility(this._handlerIndex, visibility);
155
+ this._handler && this._handler.setVisibility(this._tagData, this._tagDataIndex, visibility);
125
156
  }
126
157
 
127
158
  /**
128
- * Returns geo object visibility.
159
+ * Returns geo object visibility.
129
160
  * @public
130
161
  * @returns {boolean}
131
162
  */
@@ -133,16 +164,8 @@ class GeoObject {
133
164
  return this._visibility;
134
165
  }
135
166
 
136
- setLonLat(lon, lat, alt) {
137
- this._lonLatAlt.lon = lon;
138
- this._lonLatAlt.lat = lat;
139
- this._lonLatAlt.height = alt;
140
- this._handler._planet.ellipsoid.lonLatToCartesianRes(this._lonLatAlt, this._position);
141
- this.setPosition3v(this._position);
142
- }
143
-
144
167
  /**
145
- * Sets geoObject position.
168
+ * Sets geo object position.
146
169
  * @public
147
170
  * @param {number} x - X coordinate.
148
171
  * @param {number} y - Y coordinate.
@@ -154,12 +177,12 @@ class GeoObject {
154
177
  this._position.z = z;
155
178
  Vec3.doubleToTwoFloats(this._position, this._positionHigh, this._positionLow);
156
179
  this._handler &&
157
- this._handler.setPositionArr(this._handlerIndex, this._positionHigh, this._positionLow);
180
+ this._handler.setPositionArr(this._tagData, this._tagDataIndex, this._positionHigh, this._positionLow);
158
181
  this.updateDirection();
159
182
  }
160
183
 
161
184
  /**
162
- * Sets billboard position.
185
+ * Sets geo object position.
163
186
  * @public
164
187
  * @param {og.Vec3} position - Cartesian coordinates.
165
188
  */
@@ -168,8 +191,7 @@ class GeoObject {
168
191
  this._position.y = position.y;
169
192
  this._position.z = position.z;
170
193
  Vec3.doubleToTwoFloats(position, this._positionHigh, this._positionLow);
171
- this._handler &&
172
- this._handler.setPositionArr(this._handlerIndex, this._positionHigh, this._positionLow);
194
+ this._handler && this._handler.setPositionArr(this._tagData, this._tagDataIndex, this._positionHigh, this._positionLow);
173
195
  this.updateDirection();
174
196
  }
175
197
 
@@ -180,21 +202,21 @@ class GeoObject {
180
202
 
181
203
  setPitch(pitch) {
182
204
  this._pitch = pitch;
183
- this._handler && this._handler.setPitchRollArr(this._handlerIndex, pitch, this._roll);
205
+ this._handler && this._handler.setPitchRollArr(this._tagData, this._tagDataIndex, pitch, this._roll);
184
206
  }
185
207
 
186
208
  setRoll(roll) {
187
209
  this._roll = roll;
188
- this._handler && this._handler.setPitchRollArr(this._handlerIndex, this._pitch, roll);
210
+ this._handler && this._handler.setPitchRollArr(this._tagData, this._tagDataIndex, this._pitch, roll);
189
211
  }
190
212
 
191
213
  setScale(scale) {
192
- this.scale = scale;
193
- this._handler && this._handler.setScaleArr(this._handlerIndex, scale);
214
+ this._scale = scale;
215
+ this._handler && this._handler.setScaleArr(this._tagData, this._tagDataIndex, scale);
194
216
  }
195
217
 
196
218
  getScale() {
197
- return this.scale;
219
+ return this._scale;
198
220
  }
199
221
 
200
222
  /**
@@ -212,20 +234,14 @@ class GeoObject {
212
234
  * @param {og.Vec3} color - Picking color.
213
235
  */
214
236
  setPickingColor3v(color) {
215
- this._handler && this._handler.setPickingColorArr(this._handlerIndex, color);
237
+ this._handler && this._handler.setPickingColorArr(this._tagData, this._tagDataIndex, color);
216
238
  }
217
239
 
218
240
  updateDirection() {
219
- if (this._entity && this._entity.renderNode && this._entity.renderNode.ellipsoid) {
220
- this._entity.renderNode.ellipsoid.lonLatToCartesianRes(this._lonLatAlt, this._position);
221
- }
222
241
  this._qNorthFrame = Planet.getBearingNorthRotationQuat(this._position);
223
-
224
- let qq = Quat.yRotation(this._yaw * RADIANS)
225
- .mul(this._qNorthFrame)
226
- .conjugate();
242
+ let qq = Quat.yRotation(this._yaw).mul(this._qNorthFrame).conjugate();
227
243
  this._direction = qq.mulVec3(new Vec3(0.0, 0.0, -1.0)).normalize();
228
- this._handler && this._handler.setDirectionArr(this._handlerIndex, this._direction);
244
+ this._handler && this._handler.setDirectionArr(this._tagData, this._tagDataIndex, this._direction);
229
245
  }
230
246
  }
231
247