@openglobus/og 0.14.10 → 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 (140) hide show
  1. package/css/og.css +378 -275
  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 +5 -5
  10. package/src/og/Object3d.js +104 -145
  11. package/src/og/camera/Camera.js +31 -27
  12. package/src/og/camera/PlanetCamera.js +22 -14
  13. package/src/og/cons.js +107 -107
  14. package/src/og/control/Atmosphere.js +396 -0
  15. package/src/og/control/CompassButton.js +11 -18
  16. package/src/og/control/Control.js +187 -188
  17. package/src/og/control/GeoImageDragControl.js +84 -66
  18. package/src/og/control/LayerSwitcher.js +56 -138
  19. package/src/og/control/Lighting.js +314 -186
  20. package/src/og/control/MouseNavigation.js +2 -2
  21. package/src/og/control/RulerSwitcher.js +24 -19
  22. package/src/og/control/ScaleControl.js +30 -10
  23. package/src/og/control/SimpleSkyBackground.js +210 -0
  24. package/src/og/control/Sun.js +2 -0
  25. package/src/og/control/ZoomControl.js +30 -42
  26. package/src/og/control/index.js +6 -0
  27. package/src/og/control/ruler/RulerScene.js +5 -23
  28. package/src/og/control/selection/Selection.js +99 -0
  29. package/src/og/control/selection/SelectionScene.js +350 -0
  30. package/src/og/control/timeline/TimelineControl.js +99 -0
  31. package/src/og/control/timeline/TimelineModel.js +133 -0
  32. package/src/og/control/timeline/TimelineView.js +449 -0
  33. package/src/og/control/timeline/timelineUtils.js +132 -0
  34. package/src/og/ellipsoid/Ellipsoid.js +120 -93
  35. package/src/og/ellipsoid/wgs84.js +13 -13
  36. package/src/og/entity/Entity.js +36 -9
  37. package/src/og/entity/EntityCollection.js +0 -2
  38. package/src/og/entity/GeoObject.js +72 -56
  39. package/src/og/entity/GeoObjectHandler.js +487 -656
  40. package/src/og/entity/GeometryHandler.js +1341 -1337
  41. package/src/og/entity/Polyline.js +0 -16
  42. package/src/og/entity/Ray.js +0 -10
  43. package/src/og/entity/RayHandler.js +3 -44
  44. package/src/og/entity/Strip.js +1 -6
  45. package/src/og/index.js +10 -6
  46. package/src/og/input/input.js +3 -1
  47. package/src/og/layer/CanvasTiles.js +39 -34
  48. package/src/og/layer/Layer.js +69 -9
  49. package/src/og/layer/Material.js +1 -8
  50. package/src/og/layer/WMS.js +16 -5
  51. package/src/og/light/LightSource.js +2 -0
  52. package/src/og/math/Line3.js +140 -139
  53. package/src/og/math/Plane.js +118 -117
  54. package/src/og/math/Ray.js +242 -239
  55. package/src/og/math/Vec3.js +56 -37
  56. package/src/og/math/Vec4.js +3 -4
  57. package/src/og/math.js +21 -21
  58. package/src/og/quadTree/Node.js +5 -4
  59. package/src/og/quadTree/index.js +12 -0
  60. package/src/og/renderer/Renderer.js +64 -37
  61. package/src/og/renderer/RendererEvents.js +1071 -1065
  62. package/src/og/scene/Planet.js +352 -172
  63. package/src/og/scene/RenderNode.js +27 -12
  64. package/src/og/segment/Segment.js +0 -5
  65. package/src/og/shaders/atmos.js +332 -0
  66. package/src/og/shaders/drawnode.js +475 -109
  67. package/src/og/shaders/geoObject.js +96 -51
  68. package/src/og/shaders/polyline.js +212 -17
  69. package/src/og/shaders/ray.js +13 -6
  70. package/src/og/shaders/toneMapping.js +5 -5
  71. package/src/og/shaders/utils.js +88 -0
  72. package/src/og/terrain/GlobusTerrain.js +5 -4
  73. package/src/og/terrain/MapboxTerrain.js +231 -52
  74. package/src/og/ui/Button.js +106 -0
  75. package/src/og/ui/ButtonGroup.js +57 -0
  76. package/src/og/ui/Dialog.js +242 -0
  77. package/src/og/ui/Slider.js +144 -0
  78. package/src/og/ui/ToggleButton.js +51 -0
  79. package/src/og/{control → ui}/UIhelpers.js +11 -2
  80. package/src/og/ui/View.js +190 -0
  81. package/src/og/utils/shared.js +960 -942
  82. package/src/og/webgl/Framebuffer.js +308 -387
  83. package/src/og/webgl/Handler.js +90 -30
  84. package/src/og/webgl/Multisample.js +8 -0
  85. package/types/Clock.d.ts +7 -2
  86. package/types/Object3d.d.ts +14 -3
  87. package/types/camera/Camera.d.ts +18 -17
  88. package/types/camera/PlanetCamera.d.ts +3 -1
  89. package/types/control/Atmosphere.d.ts +15 -0
  90. package/types/control/CompassButton.d.ts +1 -2
  91. package/types/control/GeoImageDragControl.d.ts +7 -1
  92. package/types/control/LayerSwitcher.d.ts +5 -6
  93. package/types/control/Lighting.d.ts +32 -7
  94. package/types/control/ScaleControl.d.ts +2 -1
  95. package/types/control/SimpleSkyBackground.d.ts +15 -0
  96. package/types/control/ZoomControl.d.ts +0 -1
  97. package/types/control/index.d.ts +4 -1
  98. package/types/control/ruler/RulerScene.d.ts +0 -1
  99. package/types/control/selection/Selection.d.ts +49 -0
  100. package/types/control/selection/SelectionScene.d.ts +34 -0
  101. package/types/ellipsoid/Ellipsoid.d.ts +3 -2
  102. package/types/entity/Entity.d.ts +8 -0
  103. package/types/entity/GeoObject.d.ts +28 -22
  104. package/types/entity/GeoObjectHandler.d.ts +16 -56
  105. package/types/entity/Ray.d.ts +0 -3
  106. package/types/entity/RayHandler.d.ts +0 -4
  107. package/types/index.d.ts +7 -5
  108. package/types/input/input.d.ts +2 -0
  109. package/types/layer/CanvasTiles.d.ts +1 -0
  110. package/types/layer/Layer.d.ts +9 -0
  111. package/types/layer/WMS.d.ts +7 -3
  112. package/types/math/Plane.d.ts +1 -1
  113. package/types/math/Vec3.d.ts +19 -16
  114. package/types/math/Vec4.d.ts +2 -3
  115. package/types/math.d.ts +20 -20
  116. package/types/quadTree/index.d.ts +10 -0
  117. package/types/renderer/Renderer.d.ts +11 -37
  118. package/types/scene/Planet.d.ts +27 -1
  119. package/types/scene/RenderNode.d.ts +2 -1
  120. package/types/segment/Segment.d.ts +1 -1
  121. package/types/shaders/atmos.d.ts +4 -0
  122. package/types/shaders/drawnode.d.ts +3 -2
  123. package/types/shaders/utils.d.ts +1 -0
  124. package/types/terrain/GlobusTerrain.d.ts +1 -1
  125. package/types/terrain/MapboxTerrain.d.ts +2 -1
  126. package/types/ui/Button.d.ts +21 -0
  127. package/types/ui/Dialog.d.ts +41 -0
  128. package/types/ui/Slider.d.ts +30 -0
  129. package/types/ui/ToggleButton.d.ts +10 -0
  130. package/types/{control → ui}/UIhelpers.d.ts +1 -1
  131. package/types/ui/View.d.ts +32 -0
  132. package/types/utils/shared.d.ts +16 -14
  133. package/types/webgl/Framebuffer.d.ts +2 -5
  134. package/types/webgl/Handler.d.ts +15 -10
  135. package/types/webgl/Multisample.d.ts +2 -0
  136. package/src/og/ajax.js +0 -204
  137. package/src/og/entity/Object3d.js +0 -504
  138. package/src/og/utils/quadTreeType.js +0 -11
  139. package/types/ajax.d.ts +0 -24
  140. package/types/utils/quadTreeType.d.ts +0 -8
@@ -0,0 +1,350 @@
1
+ 'use strict';
2
+
3
+ import * as math from '../../math.js';
4
+ import { RenderNode } from '../../scene/RenderNode.js';
5
+ import { Events } from '../../Events.js';
6
+ import { LonLat } from '../../LonLat.js';
7
+ import { Vec3 } from '../../math/Vec3.js';
8
+ import { Vec2 } from '../../math/Vec2.js';
9
+ import { Vector } from '../../layer/Vector.js';
10
+ import { Entity } from '../../entity/Entity.js';
11
+ import { Ellipsoid } from '../../ellipsoid/Ellipsoid.js';
12
+ import { Object3d } from '../../Object3d.js';
13
+
14
+ const OUTLINE_COUNT = 120;
15
+
16
+ const MAX_SCALE = 0.005;
17
+ const MIN_SCALE = 0.001;
18
+ const MAX_SCALE_HEIGHT = 3000.0;
19
+ const MIN_SCALE_HEIGHT = 19000000.0;
20
+
21
+ function distanceFormat(v) {
22
+ if (v > 1000) {
23
+ return `${(v / 1000).toFixed(1)} km`;
24
+ } else if (v > 9) {
25
+ return `${Math.round(v)} m`;
26
+ } else {
27
+ return `${v.toFixed(1)} m`;
28
+ }
29
+ }
30
+
31
+ class SelectionScene extends RenderNode {
32
+ constructor(options = {}) {
33
+ super(options.name);
34
+
35
+ this.events = new Events(EVENT_NAMES);
36
+
37
+ this._ignoreTerrain = options.ignoreTerrain != undefined ? options.ignoreTerrain : true;
38
+
39
+ this._onSelect = options.onSelect || null;
40
+
41
+ this._autoSelectionHide = options.autoSelectionHide || false;
42
+
43
+ this._planet = options.planet || null;
44
+
45
+ this._startLonLat = null;
46
+
47
+ this._heading = 0;
48
+
49
+ this._propsLabel = new Entity({
50
+ 'name': 'propsLabel',
51
+ 'label': {
52
+ text: "",
53
+ size: 11,
54
+ color: "rgba(455,455,455,1.0)",
55
+ outlineColor: "rgba(0,0,0,0.34)",
56
+ outline: 0.23,
57
+ align: "center",
58
+ offset: [0, 18]
59
+ }
60
+ });
61
+
62
+ this._propsLabel.label.setVisibility(false);
63
+
64
+ this._trackEntity = new Entity({
65
+ polyline: {
66
+ path3v: [],
67
+ thickness: 3.8,
68
+ color: "rgb(455,455,455)",
69
+ isClosed: false
70
+ }
71
+ });
72
+
73
+ this._trackEntity.polyline.altitude = 0.01;
74
+
75
+ let obj3d = Object3d.createCylinder(1.1, 0, 2.7, 20, 1, true, false, 0, 0, 0)
76
+
77
+ this._cornerEntity = [
78
+ new Entity({
79
+ geoObject: {
80
+ scale: 1,
81
+ instanced: true,
82
+ tag: "selection",
83
+ color: "rgb(0,305,0)",
84
+ object3d: obj3d
85
+ },
86
+ properties: {
87
+ name: "start"
88
+ }
89
+ }),
90
+ new Entity({
91
+ geoObject: {
92
+ scale: 1,
93
+ instanced: true,
94
+ tag: "selection",
95
+ color: "rgb(455,0,0)",
96
+ object3d: obj3d
97
+ },
98
+ properties: {
99
+ name: "end"
100
+ }
101
+ })
102
+ ];
103
+
104
+ this._trackLayer = new Vector("track", {
105
+ entities: [this._trackEntity, this._propsLabel],
106
+ pickingEnabled: false,
107
+ polygonOffsetUnits: -1.0,
108
+ relativeToGround: true,
109
+ displayInLayerSwitcher: false
110
+ });
111
+
112
+ this._cornersLayer = new Vector("corners", {
113
+ entities: [this._cornerEntity[0], this._cornerEntity[1]],
114
+ pickingEnabled: true,
115
+ displayInLayerSwitcher: false,
116
+ scaleByDistance: [1.0, 4000000, 0.01],
117
+ pickingScale: 2
118
+ });
119
+ }
120
+
121
+ set ignoreTerrain(v) {
122
+ this._ignoreTerrain = v;
123
+ if (v) {
124
+ //...redraw line
125
+ }
126
+ }
127
+
128
+ bindPlanet(planet) {
129
+ this._planet = planet;
130
+ }
131
+
132
+ init() {
133
+ this._activate();
134
+ }
135
+
136
+ onremove() {
137
+ this._deactivate();
138
+ }
139
+
140
+ _activate() {
141
+ this._propsLabel.label.setVisibility(false);
142
+
143
+ this._onMouseMove_ = this._onMouseMove.bind(this);
144
+ this.renderer.events.on("mousemove", this._onMouseMove_, this);
145
+
146
+ this._onMouseLdown_ = this._onMouseLdown.bind(this);
147
+ this.renderer.events.on("ldown", this._onMouseLdown_, this);
148
+
149
+ this._onMouseLup_ = this._onMouseLup.bind(this);
150
+ this.renderer.events.on("lup", this._onMouseLup_, this);
151
+
152
+ this._planet.addLayer(this._trackLayer);
153
+
154
+ this._planet.addLayer(this._cornersLayer);
155
+
156
+ }
157
+
158
+ _deactivate() {
159
+ this._startLonLat = null;
160
+ this._trackLayer.remove();
161
+ this._cornersLayer.remove();
162
+ this.renderer.events.off("mousemove", this._onMouseMove_);
163
+ this.renderer.events.off("ldown", this._onMouseLdown_);
164
+ this.renderer.events.off("lup", this._onMouseLup_);
165
+
166
+ this.clear();
167
+
168
+ this._onMouseMove_ = null;
169
+ this._onMouseLdown_ = null;
170
+ this._onMouseLup_ = null;
171
+ }
172
+
173
+ _onMouseLdown(e) {
174
+
175
+ //workaround to show pointer, because ogGrabbingPoiner keep !importanti which override pointer style
176
+ e.renderer.handler.canvas.classList.remove('ogGrabbingPoiner');
177
+
178
+ e.renderer.handler.canvas.style.cursor = 'pointer';
179
+
180
+ if (!this._startLonLat) {
181
+
182
+
183
+ this._propsLabel.label.setVisibility(false);
184
+
185
+ this._trackEntity.polyline.setPath3v([]);
186
+
187
+
188
+ this._cornerEntity[0].geoObject.setVisibility(true);
189
+ this._cornerEntity[1].geoObject.setVisibility(true);
190
+
191
+ this.renderer.controls.mouseNavigation.deactivate();
192
+ this._startLonLat = this._planet.getLonLatFromPixelTerrain(e);
193
+
194
+ let startPos = this._planet.ellipsoid.lonLatToCartesian(this._startLonLat);
195
+ this._cornerEntity[0].setCartesian3v(startPos);
196
+ this._cornerEntity[1].setCartesian3v(startPos);
197
+ }
198
+ }
199
+
200
+ _onMouseLup(e) {
201
+ if (this._startLonLat) {
202
+
203
+ this._pickedCorner = null;
204
+ this._anchorLonLat = null;
205
+
206
+ this._propsLabel.label.setVisibility(true);
207
+
208
+ if (this._onSelect && typeof this._onSelect === 'function') {
209
+ let startLonLat = this._cornerEntity[0].getLonLat();
210
+ let endLonLat = this._cornerEntity[1].getLonLat();
211
+
212
+ let extent = [
213
+ Math.min(startLonLat.lon, endLonLat.lon),
214
+ Math.min(startLonLat.lat, endLonLat.lat),
215
+ Math.max(startLonLat.lon, endLonLat.lon),
216
+ Math.max(startLonLat.lat, endLonLat.lat)
217
+ ];
218
+ this._onSelect(extent);
219
+ }
220
+
221
+ if (this._autoSelectionHide) {
222
+ this.clear();
223
+ }
224
+
225
+ this._startLonLat = null;
226
+ }
227
+ e.renderer.handler.canvas.style.cursor = 'default';
228
+ this.renderer.controls.mouseNavigation.activate();
229
+ }
230
+
231
+ _drawLine(startLonLat, endLonLat, startPos) {
232
+
233
+ if (!startPos) {
234
+ startPos = this._planet.ellipsoid.lonLatToCartesian(startLonLat);
235
+ }
236
+
237
+ let endPos = this._planet.ellipsoid.lonLatToCartesian(endLonLat);
238
+
239
+ let length = this._planet.ellipsoid.getGreatCircleDistance(startLonLat, endLonLat);
240
+
241
+ this._heading = Ellipsoid.getRhumbBearing(startLonLat, endLonLat);
242
+
243
+ let path = [];
244
+
245
+
246
+ this._cornerEntity[0].setCartesian3v(startPos);
247
+ this._cornerEntity[1].setCartesian3v(endPos);
248
+
249
+
250
+ let corners = [
251
+ startPos,
252
+ this._planet.ellipsoid.lonLatToCartesian(new LonLat(endLonLat.lon, startLonLat.lat, startLonLat.height)),
253
+ endPos,
254
+ this._planet.ellipsoid.lonLatToCartesian(new LonLat(startLonLat.lon, endLonLat.lat, startLonLat.height)),
255
+ startPos
256
+ ];
257
+
258
+
259
+ path.push(startPos);
260
+
261
+ let createPath = (sideA, sideB) => {
262
+ let dir = sideB.sub(sideA);
263
+ let dist = dir.length();
264
+ dir.normalize();
265
+
266
+ for (let i = 0; i < OUTLINE_COUNT; i++) {
267
+ let f = dir.scaleTo(i * dist / OUTLINE_COUNT).addA(sideA);
268
+ path.push(f);
269
+ }
270
+ };
271
+
272
+ for (let i = 0; i < corners.length - 1; i++) {
273
+ createPath(corners[i], corners[i + 1]);
274
+ }
275
+
276
+ this._trackEntity.polyline.setPath3v([path]);
277
+
278
+ if (this._ignoreTerrain) {
279
+ // this._propsLabel.setCartesian3v(path[Math.floor(path.length / 2)]);
280
+ // this._propsLabel.label.setText(`${distanceFormat(length)}, ${Math.round(this._heading)} deg`);
281
+ }
282
+ }
283
+
284
+ _onMouseMove(e) {
285
+ if (this._startLonLat) {
286
+ this._propsLabel.label.setVisibility(true);
287
+ let endLonLat = this._planet.getLonLatFromPixelTerrain(e);
288
+ if (!endLonLat)
289
+ return;
290
+ this._drawLine(this._startLonLat, endLonLat);
291
+ }
292
+ }
293
+
294
+ clear() {
295
+ this._trackEntity.polyline.clear();
296
+ this._cornerEntity[0].geoObject.setVisibility(false);
297
+ this._cornerEntity[1].geoObject.setVisibility(false);
298
+ }
299
+
300
+ frame() {
301
+ let t = this._trackEntity.polyline.getPath3v()[0];
302
+ if (t) {
303
+ if (!this._ignoreTerrain) {
304
+ let res = 0;
305
+ for (let i = 0, len = t.length - 1; i < len; i++) {
306
+ res += t[i + 1].distance(t[i]);
307
+ }
308
+
309
+ this._propsLabel.setCartesian3v(t[Math.floor(t.length / 2)]);
310
+ this._propsLabel.label.setText(`${distanceFormat(res)}, ${Math.round(this._heading)} deg`);
311
+ }
312
+ }
313
+ }
314
+
315
+ get ellipsoid() {
316
+ return this._planet ? this._planet.ellipsoid : null;
317
+ }
318
+ }
319
+
320
+ const EVENT_NAMES = [
321
+ "add",
322
+ "remove",
323
+ "mousemove",
324
+ "mouseenter",
325
+ "mouseleave",
326
+ "lclick",
327
+ "rclick",
328
+ "mclick",
329
+ "ldblclick",
330
+ "rdblclick",
331
+ "mdblclick",
332
+ "lup",
333
+ "rup",
334
+ "mup",
335
+ "ldown",
336
+ "rdown",
337
+ "mdown",
338
+ "lhold",
339
+ "rhold",
340
+ "mhold",
341
+ "mousewheel",
342
+ "touchmove",
343
+ "touchstart",
344
+ "touchend",
345
+ "doubletouch",
346
+ "touchleave",
347
+ "touchenter"
348
+ ];
349
+
350
+ export { SelectionScene };
@@ -0,0 +1,99 @@
1
+ 'use strict';
2
+
3
+ import { Control } from '../Control.js';
4
+ import { TimelineView } from './TimelineView.js';
5
+ import { Dialog } from "../../ui/Dialog.js";
6
+ import { ToggleButton } from "../../ui/ToggleButton.js";
7
+ import { UTCtoDate } from "../../astro/jd.js";
8
+
9
+ function addHours(date, hours) {
10
+ const temp = new Date(date);
11
+ temp.setHours(temp.getHours() + hours);
12
+ return temp;
13
+ }
14
+
15
+ const ICON_BUTTON_SVG = `<?xml version="1.0" encoding="utf-8"?>
16
+ <!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon -->
17
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
18
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">
19
+ <metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>
20
+ <g><path d="M500,10C229.4,10,10,229.4,10,500s219.4,490,490,490s490-219.4,490-490S770.6,10,500,10z M800.3,800.3c-39,39-84.5,69.7-135,91C613,913.5,557.4,924.7,500,924.7s-112.9-11.2-165.3-33.3c-50.5-21.3-95.9-52-135-91c-39-39-69.7-84.5-91-135C86.5,612.9,75.3,557.4,75.3,500s11.2-112.9,33.3-165.3c21.3-50.5,52-95.9,91-135c39-39,84.5-69.7,135-91C387.1,86.5,442.6,75.3,500,75.3s112.9,11.2,165.3,33.3c50.5,21.3,95.9,52,135,91c39,39,69.7,84.5,91,135c22.1,52.3,33.3,107.9,33.3,165.3s-11.2,112.9-33.3,165.3C869.9,715.8,839.3,761.2,800.3,800.3z"/><path d="M761.3,532.7H532.7V304c0-18.1-14.6-32.7-32.7-32.7s-32.7,14.6-32.7,32.7v261.3l0,0c0,18.1,14.6,32.7,32.7,32.7h261.3c18.1,0,32.7-14.6,32.7-32.7l0,0C794,547.3,779.4,532.7,761.3,532.7z"/></g>
21
+ </svg>`;
22
+
23
+ class TimelineControl extends Control {
24
+ constructor(options = {}) {
25
+ if (!options.name || options.name === "") {
26
+ options.name = "timeline";
27
+ }
28
+ super(options);
29
+
30
+ let currentDate = new Date();
31
+ let startDate = addHours(currentDate, -12), endDate = addHours(currentDate, 12);
32
+
33
+ this._timelineView = new TimelineView({
34
+ rangeStart: startDate,
35
+ rangeEnd: endDate
36
+ });
37
+
38
+ this._toggleBtn = new ToggleButton({
39
+ classList: ["og-map-button", "og-timeline_button"],
40
+ icon: ICON_BUTTON_SVG
41
+ });
42
+
43
+ this._dialog = new Dialog({
44
+ title: "Timeline",
45
+ visible: false,
46
+ resizable: true,
47
+ useHide: true,
48
+ top: 10,
49
+ left: 60,
50
+ width: 600,
51
+ height: 115,
52
+ minHeight: 115,
53
+ maxHeight: 110
54
+ });
55
+
56
+ this._dialog.on("visibility", (v) => {
57
+ this._toggleBtn.setActive(v);
58
+ });
59
+ }
60
+
61
+ oninit() {
62
+
63
+ let $container = this.renderer.div;
64
+
65
+ this._toggleBtn.appendTo($container);
66
+ this._dialog.appendTo($container);
67
+
68
+ this._toggleBtn.on("change", (isActive) => {
69
+ this._dialog.setVisibility(isActive);
70
+ if (isActive) {
71
+ this._timelineView.resize();
72
+ }
73
+ });
74
+
75
+ this._timelineView.appendTo(this._dialog.container);
76
+
77
+ this._timelineView.on("setcurrent", (d) => {
78
+ this.renderer.handler.defaultClock.setDate(d);
79
+ });
80
+
81
+ this._timelineView.on("startdrag", () => {
82
+ this.renderer.controls.mouseNavigation.deactivate();
83
+ });
84
+
85
+ this._timelineView.on("stopdrag", () => {
86
+ this.renderer.controls.mouseNavigation.activate();
87
+ });
88
+
89
+ this._timelineView.on("startdragcurrent", () => {
90
+ this.renderer.controls.mouseNavigation.deactivate();
91
+ });
92
+
93
+ this._timelineView.on("stopdragcurrent", () => {
94
+ this.renderer.controls.mouseNavigation.activate();
95
+ });
96
+ }
97
+ }
98
+
99
+ export { TimelineControl };
@@ -0,0 +1,133 @@
1
+ 'use strict';
2
+
3
+ import { addSeconds } from "./timelineUtils.js";
4
+ import { Events } from '../../Events.js';
5
+
6
+ class TimelineModel {
7
+ constructor(options = {}) {
8
+
9
+ this._events = new Events(["change", "current"/*, "tick"*/]);
10
+
11
+ this._current = options.current || new Date();
12
+ this._rangeStart = options.rangeStart || new Date();
13
+ this._rangeEnd = options.rangeEnd || addSeconds(this._rangeStart, 3600);
14
+ this._range = this._rangeEnd.getTime() - this._rangeStart.getTime();
15
+ this._minDate = options.minDate || null;
16
+ this._maxDate = options.maxDate || null;
17
+
18
+ this.multiplier = options.multiplier != undefined ? options.multiplier : 1.0;
19
+
20
+ this._requestAnimationFrameId = 0;
21
+ this._prevNow = 0;
22
+
23
+ this.dt = 0;
24
+ }
25
+
26
+ on(eventName, callback, sender) {
27
+ return this._events.on(eventName, callback, sender);
28
+ }
29
+
30
+ off(eventName, callback) {
31
+ return this._events.off(eventName, callback);
32
+ }
33
+
34
+ play() {
35
+ if (!this._requestAnimationFrameId) {
36
+ this._prevNow = window.performance.now();
37
+ this._animationFrameCallback();
38
+ }
39
+ }
40
+
41
+ stop() {
42
+ if (this._requestAnimationFrameId) {
43
+ window.cancelAnimationFrame(this._requestAnimationFrameId);
44
+ this._requestAnimationFrameId = 0;
45
+ }
46
+ }
47
+
48
+ _animationFrameCallback() {
49
+ this._requestAnimationFrameId = window.requestAnimationFrame(() => {
50
+ this._frame();
51
+ this._animationFrameCallback();
52
+ });
53
+ }
54
+
55
+ _frame() {
56
+ let now = window.performance.now();
57
+ this.dt = now - this._prevNow;
58
+ this._prevNow = now;
59
+
60
+ this.current = new Date(this.currentTime + this.dt * this.multiplier);
61
+
62
+ // // @ts-ignore
63
+ // this._events.dispatch(this._events.tick, this._current);
64
+ }
65
+
66
+ get range() {
67
+ return this._range
68
+ }
69
+
70
+ set(rangeStart, rangeEnd) {
71
+ if (rangeStart !== this._rangeStart || rangeEnd !== this._rangeEnd) {
72
+ this._rangeStart = rangeStart;
73
+ this._rangeEnd = rangeEnd;
74
+ this._range = this._rangeEnd.getTime() - this._rangeStart.getTime();
75
+ this._events.dispatch(this._events.change, rangeStart, rangeEnd);
76
+ }
77
+ }
78
+
79
+ get current() {
80
+ return this._current;
81
+ }
82
+
83
+ get rangeStart() {
84
+ return this._rangeStart;
85
+ }
86
+
87
+ get rangeEnd() {
88
+ return this._rangeEnd;
89
+ }
90
+
91
+ get rangeStartTime() {
92
+ return this._rangeStart.getTime();
93
+ }
94
+
95
+ get rangeEndTime() {
96
+ return this._rangeEnd.getTime();
97
+ }
98
+
99
+ get currentTime() {
100
+ return this._current.getTime();
101
+ }
102
+
103
+ set current(current) {
104
+ if (current !== this._current) {
105
+ if (this._maxDate && current > this._maxDate) {
106
+ this._current = this._maxDate;
107
+ } else if (this._minDate && current < this._minDate) {
108
+ this._current = this._minDate;
109
+ } else {
110
+ this._current = current;
111
+ }
112
+ this._events.dispatch(this._events.current, this._current);
113
+ }
114
+ }
115
+
116
+ set rangeStart(date) {
117
+ if (date !== this._rangeStart) {
118
+ this._rangeStart = date;
119
+ this._range = this._rangeEnd.getTime() - this._rangeStart.getTime();
120
+ this._events.dispatch(this._events.change, date);
121
+ }
122
+ }
123
+
124
+ set rangeEnd(date) {
125
+ if (date !== this._rangeEnd) {
126
+ this._rangeEnd = date;
127
+ this._range = this._rangeEnd.getTime() - this._rangeStart.getTime();
128
+ this._events.dispatch(this._events.change, date);
129
+ }
130
+ }
131
+ }
132
+
133
+ export { TimelineModel }