@openglobus/og 0.13.7 → 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.
- package/README.md +1 -1
- package/css/og.css +388 -129
- package/dist/@openglobus/og.css +1 -1
- package/dist/@openglobus/og.esm.js +2 -2
- package/dist/@openglobus/og.esm.js.map +1 -1
- package/dist/@openglobus/og.umd.js +2 -2
- package/dist/@openglobus/og.umd.js.map +1 -1
- package/package.json +20 -19
- package/src/og/Globe.js +15 -16
- package/src/og/Object3d.js +417 -0
- package/src/og/arial.js +1705 -1703
- package/src/og/camera/Camera.js +640 -640
- package/src/og/control/EarthCoordinates.js +1 -1
- package/src/og/control/GeoImageDragControl.js +102 -75
- package/src/og/control/LayerAnimation.js +383 -0
- package/src/og/control/LayerSwitcher.js +506 -159
- package/src/og/control/Lighting.js +27 -27
- package/src/og/control/MouseNavigation.js +460 -460
- package/src/og/control/RulerSwitcher.js +69 -0
- package/src/og/control/Sun.js +170 -170
- package/src/og/control/UIhelpers.js +146 -0
- package/src/og/control/ZoomControl.js +0 -2
- package/src/og/control/index.js +5 -1
- package/src/og/control/ruler/Ruler.js +43 -0
- package/src/og/control/ruler/RulerScene.js +374 -0
- package/src/og/control/visibleExtent/Segment.js +3 -5
- package/src/og/ellipsoid/Ellipsoid.js +19 -0
- package/src/og/ellipsoid/wgs84.js +1 -1
- package/src/og/entity/Entity.js +1 -1
- package/src/og/entity/GeoObject.js +1 -1
- package/src/og/entity/LabelHandler.js +6 -2
- package/src/og/entity/LabelWorker.js +38 -53
- package/src/og/layer/BaseGeoImage.js +347 -312
- package/src/og/layer/CanvasTiles.js +312 -290
- package/src/og/layer/GeoImage.js +222 -214
- package/src/og/layer/GeoVideo.js +291 -291
- package/src/og/layer/Layer.js +94 -70
- package/src/og/layer/Material.js +109 -109
- package/src/og/layer/Vector.js +81 -14
- package/src/og/layer/XYZ.js +23 -11
- package/src/og/light/LightSource.js +364 -363
- package/src/og/math/Vec3.js +1 -1
- package/src/og/math.js +6 -6
- package/src/og/quadTree/Node.js +8 -6
- package/src/og/renderer/Renderer.js +2 -3
- package/src/og/res/images.js +0 -2
- package/src/og/scene/Planet.js +106 -44
- package/src/og/segment/Segment.js +34 -64
- package/src/og/segment/Slice.js +1 -1
- package/src/og/shaders/drawnode.js +1 -1
- package/src/og/shaders/label.js +30 -42
- package/src/og/terrain/GlobusTerrain.js +31 -20
- package/src/og/terrain/MapboxTerrain.js +1 -1
- package/src/og/utils/BaseWorker.js +46 -0
- package/src/og/utils/FontAtlas.js +1 -2
- package/src/og/utils/GeoImageCreator.js +164 -161
- package/src/og/utils/Loader.js +187 -153
- package/src/og/utils/NormalMapCreator.js +403 -412
- package/src/og/utils/PlainSegmentWorker.js +29 -55
- package/src/og/utils/TerrainWorker.js +572 -589
- package/src/og/utils/VectorTileCreator.js +1 -1
- package/src/og/utils/functionComposition.js +13 -0
- package/src/og/webgl/Handler.js +42 -41
- package/src/og/webgl/ProgramController.js +143 -143
- package/types/Object3d.d.ts +22 -0
- package/types/arial.d.ts +1 -0
- package/types/camera/PlanetCamera.d.ts +4 -0
- package/types/control/GeoImageDragControl.d.ts +2 -0
- package/types/control/LayerAnimation.d.ts +73 -0
- package/types/control/LayerSwitcher.d.ts +55 -11
- package/types/control/MouseNavigation.d.ts +1 -0
- package/types/control/MouseWheelZoomControl.d.ts +1 -0
- package/types/control/Sun.d.ts +2 -1
- package/types/control/TouchNavigation.d.ts +1 -0
- package/types/control/UIhelpers.d.ts +13 -0
- package/types/control/index.d.ts +3 -1
- package/types/control/ruler/Ruler.d.ts +13 -0
- package/types/control/ruler/RulerScene.d.ts +48 -0
- package/types/ellipsoid/Ellipsoid.d.ts +8 -0
- package/types/entity/LabelHandler.d.ts +2 -0
- package/types/entity/LabelWorker.d.ts +5 -7
- package/types/layer/BaseGeoImage.d.ts +9 -1
- package/types/layer/CanvasTiles.d.ts +5 -1
- package/types/layer/GeoImage.d.ts +1 -0
- package/types/layer/GeoTexture2d.d.ts +1 -0
- package/types/layer/Layer.d.ts +28 -32
- package/types/layer/Vector.d.ts +9 -0
- package/types/layer/WMS.d.ts +1 -0
- package/types/layer/XYZ.d.ts +8 -5
- package/types/math.d.ts +2 -2
- package/types/quadTree/EntityCollectionNode.d.ts +7 -0
- package/types/quadTree/Node.d.ts +1 -2
- package/types/renderer/Renderer.d.ts +1 -1
- package/types/renderer/RendererEvents.d.ts +16 -0
- package/types/res/images.d.ts +0 -1
- package/types/scene/Planet.d.ts +21 -6
- package/types/segment/SegmentLonLat.d.ts +2 -0
- package/types/terrain/BilTerrain.d.ts +6 -0
- package/types/terrain/GlobusTerrain.d.ts +7 -0
- package/types/terrain/MapboxTerrain.d.ts +8 -0
- package/types/utils/BaseWorker.d.ts +14 -0
- package/types/utils/Loader.d.ts +4 -1
- package/types/utils/PlainSegmentWorker.d.ts +4 -6
- package/types/utils/TerrainWorker.d.ts +4 -6
- package/types/utils/functionComposition.d.ts +5 -0
- package/types/webgl/Handler.d.ts +4 -1
|
@@ -183,12 +183,12 @@ class EarthCoordinates extends Control {
|
|
|
183
183
|
|
|
184
184
|
_grabCoordinates(px) {
|
|
185
185
|
let scrPx;
|
|
186
|
+
let r = this.renderer;
|
|
186
187
|
if (this._centerMode) {
|
|
187
188
|
scrPx = r.handler.getCenter();
|
|
188
189
|
} else {
|
|
189
190
|
scrPx = px;
|
|
190
191
|
}
|
|
191
|
-
let r = this.renderer;
|
|
192
192
|
this._lonLat = this.planet.getLonLatFromPixelTerrain(scrPx);
|
|
193
193
|
this._showFn(this._lonLat);
|
|
194
194
|
}
|
|
@@ -1,76 +1,103 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module og/control/GeoImageDragControl
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
|
-
import { Control } from './Control.js';
|
|
8
|
-
import { BaseGeoImage } from '../layer/BaseGeoImage.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module og/control/GeoImageDragControl
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
import { Control } from './Control.js';
|
|
8
|
+
import { BaseGeoImage } from '../layer/BaseGeoImage.js';
|
|
9
|
+
import { elementFactory, btnClickHandler } from "./UIhelpers.js";
|
|
10
|
+
|
|
11
|
+
class GeoImageDragControl extends Control {
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
super(options);
|
|
14
|
+
this._cornerIndex = -1;
|
|
15
|
+
this._catchCorner = false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
oninit() {
|
|
19
|
+
let p = this.planet;
|
|
20
|
+
this.createDraggerButton();
|
|
21
|
+
|
|
22
|
+
p.events.on('layeradd', function (e) {
|
|
23
|
+
this._bindLayer(e);
|
|
24
|
+
}, this);
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < p.layers.length; i++) {
|
|
27
|
+
if (p.layers[i] instanceof BaseGeoImage) {
|
|
28
|
+
this._bindLayer(p.layers[i]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
btnClickHandler('og-geo-image-dragger-menu-btn', null, null, '#og-geo-image-dragger-menu-icon'); // btn_id, dialog_id, dialog_selector, icon_id
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Create a button to activate-deactivate control
|
|
35
|
+
createDraggerButton() {
|
|
36
|
+
let btn = elementFactory('div', {
|
|
37
|
+
id: 'og-geo-image-dragger-menu-btn',
|
|
38
|
+
class: 'og-geo-image-dragger og-menu-btn og-OFF'
|
|
39
|
+
},
|
|
40
|
+
elementFactory('div', { id: 'og-geo-image-dragger-menu-icon', class: 'og-icon-holder' }));
|
|
41
|
+
this.renderer.div.appendChild(btn);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_bindLayer(layer) {
|
|
45
|
+
if (layer instanceof BaseGeoImage) { // if the layer is a geoImage layer
|
|
46
|
+
|
|
47
|
+
var p = this.planet;
|
|
48
|
+
|
|
49
|
+
layer.events.on('mousemove', function (ms) {
|
|
50
|
+
var btn = document.getElementById('og-geo-image-dragger-menu-btn');
|
|
51
|
+
var btn_off = btn.classList.contains('og-OFF');
|
|
52
|
+
if (this._active && !btn_off) { // active layer and button ON
|
|
53
|
+
if (this._catchCorner) {// mouse is catching a corner
|
|
54
|
+
var corners = layer.getCornersLonLat();
|
|
55
|
+
corners[this._cornerIndex] = p.getLonLatFromPixelTerrain(ms, true);
|
|
56
|
+
layer.setCornersLonLat(corners);
|
|
57
|
+
} else { // mouse isn't catching
|
|
58
|
+
this._cornerIndex = -1;
|
|
59
|
+
for (var i = 0; i < layer._cornersWgs84.length; i++) {
|
|
60
|
+
var ground = p.getLonLatFromPixelTerrain(ms, true);
|
|
61
|
+
// mouse is near
|
|
62
|
+
if (ground && p.ellipsoid.getGreatCircleDistance(layer._cornersWgs84[i], ground) / p.getDistanceFromPixel(ms, true) <= 0.05) {
|
|
63
|
+
this._cornerIndex = i;
|
|
64
|
+
document.body.style.cursor = 'move';
|
|
65
|
+
break;
|
|
66
|
+
// mouse is far
|
|
67
|
+
} else {
|
|
68
|
+
document.body.style.cursor = 'auto';
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
layer.events.on("mouseleave", function () {
|
|
76
|
+
document.body.style.cursor = 'auto';
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
}, this);
|
|
80
|
+
|
|
81
|
+
layer.events.on('ldown', function (ms) {
|
|
82
|
+
if (this._active && this._cornerIndex !== -1) {
|
|
83
|
+
this._catchCorner = true;
|
|
84
|
+
ms.renderer.controls.mouseNavigation.deactivate();
|
|
85
|
+
}
|
|
86
|
+
}, this);
|
|
87
|
+
|
|
88
|
+
layer.events.on('lup', function (ms) {
|
|
89
|
+
if (this._active) {
|
|
90
|
+
this._catchCorner = false;
|
|
91
|
+
ms.renderer.controls.mouseNavigation.activate();
|
|
92
|
+
}
|
|
93
|
+
}, this);
|
|
94
|
+
|
|
95
|
+
layer.events.on('rdblclick', function () {
|
|
96
|
+
alert(layer.getID());
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
76
103
|
export { GeoImageDragControl };
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module og/control/LayerAnimation
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
import { Control } from "./Control.js";
|
|
8
|
+
import { Events } from '../Events.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @class
|
|
13
|
+
* @extends {Control}
|
|
14
|
+
* @param {Object} [options] - Control options.
|
|
15
|
+
*/
|
|
16
|
+
class LayerAnimation extends Control {
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
super(options);
|
|
19
|
+
|
|
20
|
+
this.events = new Events(["change", "idle", "play", "pause", "stop"])
|
|
21
|
+
|
|
22
|
+
this._name = options.name || `layerAnimation-${this._id}`;
|
|
23
|
+
|
|
24
|
+
this._layersArr = options.layers ? [].concat(options.layers) : [];
|
|
25
|
+
this._currentIndex = -1;
|
|
26
|
+
|
|
27
|
+
this._playInterval = options.playInterval || 120;
|
|
28
|
+
this._playIntervalHandler = -1;
|
|
29
|
+
this._playIndex = 0;
|
|
30
|
+
|
|
31
|
+
this._frameSize = options.frameSize || 50;
|
|
32
|
+
|
|
33
|
+
this.repeat = options.repeat != undefined ? options.repeat : true;
|
|
34
|
+
|
|
35
|
+
this.skipTimeout = options.skipTimeout || 5000;
|
|
36
|
+
|
|
37
|
+
this._timeoutStart = 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
_onViewchange() {
|
|
41
|
+
this._timeoutStart = performance.now();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_getFramesNum() {
|
|
45
|
+
return Math.ceil(this._layersArr.length / this._frameSize);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_setFrame(frameIndex) {
|
|
49
|
+
for (let i = 0, len = this._getFramesNum(); i < len; i++) {
|
|
50
|
+
if (i !== frameIndex) {
|
|
51
|
+
this._removeFrameFromPlanet(i);
|
|
52
|
+
} else {
|
|
53
|
+
this._appendFrameToPlanet(i);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_getFrameIndex(layerIndex) {
|
|
59
|
+
return Math.floor(layerIndex / this._frameSize);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
_appendFrameToPlanet(frameIndex) {
|
|
63
|
+
if (this.planet) {
|
|
64
|
+
let minIndex = frameIndex * this._frameSize;
|
|
65
|
+
let maxIndex = minIndex + this._frameSize;
|
|
66
|
+
for (let i = minIndex, len = maxIndex > this._layersArr.length ? this._layersArr.length : maxIndex; i < len; i++) {
|
|
67
|
+
this.planet.addLayer(this._layersArr[i]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
_removeFrameFromPlanet(frameIndex) {
|
|
73
|
+
if (this.planet) {
|
|
74
|
+
let minIndex = frameIndex * this._frameSize;
|
|
75
|
+
let maxIndex = minIndex + this._frameSize;
|
|
76
|
+
for (let i = minIndex, len = maxIndex > this._layersArr.length ? this._layersArr.length : maxIndex; i < len; i++) {
|
|
77
|
+
this._layersArr[i].abortLoading();
|
|
78
|
+
this._layersArr[i].remove();
|
|
79
|
+
this._layersArr[i].setVisibility(false);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
oninit() {
|
|
85
|
+
super.oninit();
|
|
86
|
+
this.onactivate();
|
|
87
|
+
this._initLayers();
|
|
88
|
+
this._onLayerLoadend_ = this._onLayerLoadend.bind(this);
|
|
89
|
+
this.planet.events.on("layerloadend", this._onLayerLoadend_, this);
|
|
90
|
+
this._setCurrentIndexAsync(0, false, true);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
onactivate() {
|
|
94
|
+
super.onactivate();
|
|
95
|
+
this._onViewchange_ = this._onViewchange.bind(this);
|
|
96
|
+
this.planet.camera.events.on("viewchange", this._onViewchange_, this);
|
|
97
|
+
|
|
98
|
+
this._onVisibityChange_ = this._onVisibityChange.bind(this);
|
|
99
|
+
this.planet.renderer.handler.events.on("visibilitychange", this._onVisibityChange_, this);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
ondeactivate() {
|
|
103
|
+
super.ondeactivate();
|
|
104
|
+
this.planet.camera.events.off("viewchange", this._onViewchange_);
|
|
105
|
+
this._onViewchange_ = null;
|
|
106
|
+
|
|
107
|
+
for (let i = 0; i < this._layersArr.length; i++) {
|
|
108
|
+
this._layersArr[i].setVisibility(false);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
this.planet.events.off("layerloadend", this._onLayerLoadend_);
|
|
112
|
+
this._onLayerLoadend_ = null;
|
|
113
|
+
|
|
114
|
+
this.planet.renderer.handler.events.off("visibilitychange", this._onVisibityChange_);
|
|
115
|
+
this._onVisibityChange_ = null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
_onVisibityChange(isVisible) {
|
|
119
|
+
if (!isVisible) {
|
|
120
|
+
this.pause();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
clear() {
|
|
125
|
+
this.stop();
|
|
126
|
+
this._currentIndex = -1;
|
|
127
|
+
this._currVisibleIndex = -1;
|
|
128
|
+
let layersToRemove = this._layersArr;
|
|
129
|
+
this._layersArr = [];
|
|
130
|
+
for (let i = 0; i < layersToRemove.length; i++) {
|
|
131
|
+
layersToRemove[i].remove();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
_initLayers() {
|
|
136
|
+
if (this.planet) {
|
|
137
|
+
for (let i = 0, len = this._layersArr.length; i < len; i++) {
|
|
138
|
+
let li = this._layersArr[i];
|
|
139
|
+
li.setVisibility(false);
|
|
140
|
+
li.setBaseLayer(false);
|
|
141
|
+
li.opacity = 0.0;
|
|
142
|
+
}
|
|
143
|
+
this._appendFrameToPlanet(0);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
setLayers(layers) {
|
|
148
|
+
this.clear();
|
|
149
|
+
this._layersArr = [].concat(layers);
|
|
150
|
+
this._initLayers();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
appendLayer(layer) {
|
|
154
|
+
this._layersArr.push(layer);
|
|
155
|
+
layer.setVisibility(false);
|
|
156
|
+
layer.setBaseLayer(false);
|
|
157
|
+
layer.opacity = 0.0;
|
|
158
|
+
if (this.planet) {
|
|
159
|
+
//check current frame
|
|
160
|
+
this.planet.addLayer(layer);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* warning: Use XYZ.isIdle in requesAnimationFrame(after setVisibility)
|
|
166
|
+
* @returns {boolean} Returns truw if current layer is idle
|
|
167
|
+
*/
|
|
168
|
+
get isIdle() {
|
|
169
|
+
let currLayer = this._layersArr[this._currentIndex];
|
|
170
|
+
return currLayer && currLayer.isIdle || !currLayer;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
get playInterval() {
|
|
174
|
+
return this._playInterval;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
set playInterval(val) {
|
|
178
|
+
if (val !== this._playInterval) {
|
|
179
|
+
this._playInterval = val;
|
|
180
|
+
if (this.isPlaying) {
|
|
181
|
+
this.pause();
|
|
182
|
+
this.play();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
get isPlaying() {
|
|
188
|
+
return this._playIntervalHandler !== -1;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
get layers() {
|
|
192
|
+
return this._layersArr;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
_checkEnd() {
|
|
196
|
+
if (this._playIndex > this._layersArr.length) {
|
|
197
|
+
if (this.repeat) {
|
|
198
|
+
this._playIndex = 0;
|
|
199
|
+
} else {
|
|
200
|
+
this.pause();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
play() {
|
|
206
|
+
if (!this.isPlaying) {
|
|
207
|
+
|
|
208
|
+
if (this._currentIndex >= this._layersArr.length - 1) {
|
|
209
|
+
this.stop();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
this._timeoutStart = performance.now();
|
|
213
|
+
|
|
214
|
+
this._playIntervalHandler = setInterval(() => {
|
|
215
|
+
this._checkEnd();
|
|
216
|
+
this._setCurrentIndexAsync(this._playIndex);
|
|
217
|
+
|
|
218
|
+
requestAnimationFrame(() => {
|
|
219
|
+
if (this.isIdle || (performance.now() - this._timeoutStart > this.skipTimeout)) {
|
|
220
|
+
this._playIndex++;
|
|
221
|
+
this._timeoutStart = performance.now();
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
}, this._playInterval);
|
|
226
|
+
|
|
227
|
+
this.events.dispatch(this.events.play);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
stop() {
|
|
232
|
+
if (this._playIndex > 0) {
|
|
233
|
+
this._clearInterval();
|
|
234
|
+
this._playIndex = 0;
|
|
235
|
+
this.setCurrentIndex(0);
|
|
236
|
+
this.events.dispatch(this.events.stop);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
pause() {
|
|
241
|
+
if (this.isPlaying) {
|
|
242
|
+
this._clearInterval();
|
|
243
|
+
this.events.dispatch(this.events.pause);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
_clearInterval() {
|
|
248
|
+
clearInterval(this._playIntervalHandler);
|
|
249
|
+
this._playIntervalHandler = -1;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Waiting for the current index layer loadend and make it non transparent,
|
|
254
|
+
* and make prev layer transparent, also check previous frame index to cleanup.
|
|
255
|
+
* @param {Layer} layer
|
|
256
|
+
* @private
|
|
257
|
+
*/
|
|
258
|
+
_onLayerLoadend(layer) {
|
|
259
|
+
|
|
260
|
+
let currLayer = this._layersArr[this._currentIndex];
|
|
261
|
+
|
|
262
|
+
if (currLayer && currLayer.isEqual(layer)) {
|
|
263
|
+
|
|
264
|
+
// BRUTE
|
|
265
|
+
let currFrame = this._getFrameIndex(this._currentIndex);
|
|
266
|
+
let from = currFrame * this._frameSize,
|
|
267
|
+
to = this._currentIndex;
|
|
268
|
+
for (let i = from; i < to; i++) {
|
|
269
|
+
let li = this._layersArr[i];
|
|
270
|
+
li.opacity = 0;
|
|
271
|
+
li.setVisibility(false);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// * Make CURRENT Layer VISIBLE *
|
|
275
|
+
currLayer.opacity = 1.0;
|
|
276
|
+
|
|
277
|
+
let currVisibleLayer = this._layersArr[this._currVisibleIndex];
|
|
278
|
+
if (currVisibleLayer) {
|
|
279
|
+
currVisibleLayer.opacity = 0.0;
|
|
280
|
+
currVisibleLayer.setVisibility(false);
|
|
281
|
+
|
|
282
|
+
// If frame is changed - remove it from the planet
|
|
283
|
+
let prevFrame = this._getFrameIndex(this._currVisibleIndex);
|
|
284
|
+
if (this._getFrameIndex(this._currentIndex) !== prevFrame) {
|
|
285
|
+
this._removeFrameFromPlanet(prevFrame);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
this.events.dispatch(this.events.idle, currLayer);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Function sets layer index visible.
|
|
296
|
+
* @param {number} index
|
|
297
|
+
* @param {boolean} [stopPropagation]
|
|
298
|
+
*/
|
|
299
|
+
setCurrentIndex(index, stopPropagation) {
|
|
300
|
+
this._setCurrentIndexAsync(index, true, stopPropagation);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Function sets layer index visible. If the layer is idle (all visible tiles loaded), sets opacity to one,
|
|
305
|
+
* otherwise to ZERO it means that when all visible tiles will be loaded the opacity becomes ONE. So, previous
|
|
306
|
+
* layer remains non transparent (opacity = 1) till current layer is loading.
|
|
307
|
+
* @param {number} index
|
|
308
|
+
* @param {boolean} [forceVisibility]
|
|
309
|
+
* @param {boolean} [stopPropagation]
|
|
310
|
+
*/
|
|
311
|
+
_setCurrentIndexAsync(index, forceVisibility, stopPropagation) {
|
|
312
|
+
|
|
313
|
+
if (index != this._currentIndex && index >= 0 && index < this._layersArr.length) {
|
|
314
|
+
|
|
315
|
+
let prevCurrIndex = this._currentIndex;
|
|
316
|
+
this._currentIndex = index;
|
|
317
|
+
this._playIndex = index;
|
|
318
|
+
|
|
319
|
+
let prevCurrFrame = this._getFrameIndex(prevCurrIndex);
|
|
320
|
+
let currFrame = this._getFrameIndex(this._currentIndex);
|
|
321
|
+
|
|
322
|
+
let prevCurrLayer = this._layersArr[prevCurrIndex],
|
|
323
|
+
currLayer = this._layersArr[index];
|
|
324
|
+
|
|
325
|
+
let frameChanged = currFrame != prevCurrFrame;
|
|
326
|
+
if (frameChanged) {
|
|
327
|
+
this._appendFrameToPlanet(currFrame);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (prevCurrLayer) {
|
|
331
|
+
if (prevCurrLayer.isIdle) {
|
|
332
|
+
this._currVisibleIndex = prevCurrIndex;
|
|
333
|
+
} else {
|
|
334
|
+
prevCurrLayer.opacity = 0;
|
|
335
|
+
prevCurrLayer.setVisibility(false);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (currLayer) {
|
|
340
|
+
|
|
341
|
+
currLayer.opacity = 0.0;
|
|
342
|
+
currLayer.setVisibility(true);
|
|
343
|
+
|
|
344
|
+
requestAnimationFrame(() => {
|
|
345
|
+
if (currLayer.isIdle || forceVisibility) {
|
|
346
|
+
|
|
347
|
+
currLayer.opacity = 1.0;
|
|
348
|
+
|
|
349
|
+
// If frame is changed - remove it from the planet
|
|
350
|
+
if (frameChanged) {
|
|
351
|
+
this._removeFrameFromPlanet(prevCurrFrame);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (prevCurrLayer) {
|
|
355
|
+
prevCurrLayer.opacity = 0.0;
|
|
356
|
+
prevCurrLayer.setVisibility(false);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
let currVisibleLayer = this._layersArr[this._currVisibleIndex];
|
|
360
|
+
if (currVisibleLayer) {
|
|
361
|
+
currVisibleLayer.opacity = 0.0;
|
|
362
|
+
currVisibleLayer.setVisibility(false);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
if (!stopPropagation) {
|
|
368
|
+
this.events.dispatch(this.events.change, this._currentIndex, prevCurrIndex);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export function
|
|
376
|
+
|
|
377
|
+
layerAnimation(options) {
|
|
378
|
+
return LayerAnimation(options);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export {
|
|
382
|
+
LayerAnimation
|
|
383
|
+
};
|