@openglobus/og 0.13.8 → 0.13.12

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 (85) hide show
  1. package/README.md +1 -1
  2. package/css/og.css +388 -129
  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 +20 -19
  9. package/src/og/Globe.js +15 -16
  10. package/src/og/Object3d.js +33 -0
  11. package/src/og/control/GeoImageDragControl.js +102 -75
  12. package/src/og/control/LayerAnimation.js +306 -38
  13. package/src/og/control/LayerSwitcher.js +506 -159
  14. package/src/og/control/Lighting.js +27 -27
  15. package/src/og/control/RulerSwitcher.js +69 -0
  16. package/src/og/control/UIhelpers.js +146 -0
  17. package/src/og/control/index.js +3 -1
  18. package/src/og/control/ruler/RulerScene.js +6 -2
  19. package/src/og/control/visibleExtent/Segment.js +2 -1
  20. package/src/og/ellipsoid/wgs84.js +1 -1
  21. package/src/og/entity/LabelHandler.js +2 -2
  22. package/src/og/entity/LabelWorker.js +36 -54
  23. package/src/og/layer/BaseGeoImage.js +347 -312
  24. package/src/og/layer/CanvasTiles.js +312 -290
  25. package/src/og/layer/GeoImage.js +222 -214
  26. package/src/og/layer/GeoVideo.js +291 -291
  27. package/src/og/layer/Layer.js +71 -30
  28. package/src/og/layer/Material.js +109 -109
  29. package/src/og/layer/Vector.js +1 -0
  30. package/src/og/layer/XYZ.js +20 -12
  31. package/src/og/light/LightSource.js +364 -363
  32. package/src/og/math.js +2 -2
  33. package/src/og/quadTree/Node.js +7 -5
  34. package/src/og/renderer/Renderer.js +1 -1
  35. package/src/og/scene/Planet.js +103 -42
  36. package/src/og/segment/Segment.js +34 -56
  37. package/src/og/segment/Slice.js +1 -1
  38. package/src/og/shaders/drawnode.js +1 -1
  39. package/src/og/terrain/GlobusTerrain.js +31 -20
  40. package/src/og/terrain/MapboxTerrain.js +1 -1
  41. package/src/og/utils/BaseWorker.js +46 -0
  42. package/src/og/utils/GeoImageCreator.js +164 -161
  43. package/src/og/utils/Loader.js +60 -33
  44. package/src/og/utils/NormalMapCreator.js +403 -412
  45. package/src/og/utils/PlainSegmentWorker.js +29 -55
  46. package/src/og/utils/TerrainWorker.js +572 -589
  47. package/src/og/utils/functionComposition.js +13 -0
  48. package/src/og/webgl/Handler.js +42 -41
  49. package/types/Object3d.d.ts +1 -0
  50. package/types/camera/PlanetCamera.d.ts +4 -0
  51. package/types/control/GeoImageDragControl.d.ts +2 -0
  52. package/types/control/LayerAnimation.d.ts +73 -0
  53. package/types/control/LayerSwitcher.d.ts +55 -11
  54. package/types/control/MouseNavigation.d.ts +1 -0
  55. package/types/control/MouseWheelZoomControl.d.ts +1 -0
  56. package/types/control/Sun.d.ts +1 -0
  57. package/types/control/TouchNavigation.d.ts +1 -0
  58. package/types/control/UIhelpers.d.ts +13 -0
  59. package/types/control/index.d.ts +2 -1
  60. package/types/entity/LabelHandler.d.ts +2 -0
  61. package/types/entity/LabelWorker.d.ts +5 -7
  62. package/types/layer/BaseGeoImage.d.ts +9 -1
  63. package/types/layer/CanvasTiles.d.ts +5 -1
  64. package/types/layer/GeoImage.d.ts +1 -0
  65. package/types/layer/GeoTexture2d.d.ts +1 -0
  66. package/types/layer/Layer.d.ts +5 -1
  67. package/types/layer/Vector.d.ts +7 -0
  68. package/types/layer/WMS.d.ts +1 -0
  69. package/types/layer/XYZ.d.ts +8 -6
  70. package/types/math.d.ts +1 -1
  71. package/types/quadTree/EntityCollectionNode.d.ts +7 -0
  72. package/types/quadTree/Node.d.ts +1 -2
  73. package/types/renderer/Renderer.d.ts +1 -1
  74. package/types/renderer/RendererEvents.d.ts +16 -0
  75. package/types/scene/Planet.d.ts +19 -4
  76. package/types/segment/SegmentLonLat.d.ts +2 -0
  77. package/types/terrain/BilTerrain.d.ts +6 -0
  78. package/types/terrain/GlobusTerrain.d.ts +7 -0
  79. package/types/terrain/MapboxTerrain.d.ts +8 -0
  80. package/types/utils/BaseWorker.d.ts +14 -0
  81. package/types/utils/Loader.d.ts +3 -1
  82. package/types/utils/PlainSegmentWorker.d.ts +4 -6
  83. package/types/utils/TerrainWorker.d.ts +4 -6
  84. package/types/utils/functionComposition.d.ts +5 -0
  85. package/types/webgl/Handler.d.ts +4 -1
@@ -1,290 +1,312 @@
1
- /**
2
- * @module og/layer/CanvasTiles
3
- */
4
-
5
- "use strict";
6
-
7
- import * as quadTree from "../quadTree/quadTree.js";
8
- import { Layer } from "./Layer.js";
9
-
10
- /**
11
- * Maximum tiles per frame.
12
- * @const
13
- * @type {number}
14
- */
15
-
16
- const EVENT_NAMES = [
17
- /**
18
- * Triggered when current tile image has loaded before rendereing.
19
- * @event og.layer.CanvasTiles#load
20
- */
21
- "load",
22
-
23
- /**
24
- * Triggered when all tiles have loaded or loading has stopped.
25
- * @event og.layer.CanvasTiles#loadend
26
- */
27
- "loadend"
28
- ];
29
-
30
- /**
31
- * Layer used to rendering each tile as a separate canvas object.
32
- * @class
33
- * @extends {Layer}
34
- * //TODO: make asynchronous handler.
35
- * @param {String} [name="noname"] - Layer name.
36
- * @param {Object} options:
37
- * @param {number} [options.opacity=1.0] - Layer opacity.
38
- * @param {number} [options.minZoom=0] - Minimal visibility zoom level.
39
- * @param {number} [options.maxZoom=0] - Maximal visibility zoom level.
40
- * @param {string} [options.attribution] - Layer attribution that displayed in the attribution area on the screen.
41
- * @param {boolean} [options.isBaseLayer=false] - Base layer flag.
42
- * @param {boolean} [options.visibility=true] - Layer visibility.
43
- * @param {layer.CanvasTiles~drawTileCallback} [options.drawTile] - Draw tile callback.
44
- * @fires og.layer.CanvasTiles#load
45
- * @fires og.layer.CanvasTiles#loadend
46
- */
47
- class CanvasTiles extends Layer {
48
- constructor(name, options) {
49
- options = options || {};
50
-
51
- super(name, options);
52
-
53
- this.events.registerNames(EVENT_NAMES);
54
-
55
- /**
56
- * Current creating tiles couter.
57
- * @protected
58
- * @type {number}
59
- */
60
- this._counter = 0;
61
-
62
- /**
63
- * Tile pending queue that waiting for create.
64
- * @protected
65
- * @type {Array.<planetSegment.Material>}
66
- */
67
- this._pendingsQueue = []; // new og.QueueArray();
68
-
69
- /**
70
- * Draw tile callback.
71
- * @type {layer.CanvasTiles~drawTileCallback}
72
- * @public
73
- */
74
- this.drawTile = options.drawTile || null;
75
- }
76
-
77
- get instanceName() {
78
- return "CanvasTiles";
79
- }
80
-
81
- /**
82
- * Abort loading tiles.
83
- * @public
84
- */
85
- abortLoading() {
86
- var q = this._pendingsQueue;
87
- for (var i = q._shiftIndex + 1; i < q._popIndex + 1; i++) {
88
- if (q._array[i]) {
89
- this.abortMaterialLoading(q._array[i]);
90
- }
91
- }
92
- this._pendingsQueue = [];
93
- // this._pendingsQueue.clear();
94
- }
95
-
96
- /**
97
- * Sets layer visibility.
98
- * @public
99
- * @param {boolean} visibility - Layer visibility.
100
- */
101
- setVisibility(visibility) {
102
- if (visibility !== this._visibility) {
103
- super.setVisibility(visibility);
104
-
105
- if (!visibility) {
106
- this.abortLoading();
107
- }
108
- }
109
- }
110
-
111
- /**
112
- * Start to load tile material.
113
- * @public
114
- * @virtual
115
- * @param {Material} material -
116
- */
117
- loadMaterial(material) {
118
- var seg = material.segment;
119
-
120
- if (this._isBaseLayer) {
121
- material.texture = seg._isNorth
122
- ? seg.planet.solidTextureOne
123
- : seg.planet.solidTextureTwo;
124
- } else {
125
- material.texture = seg.planet.transparentTexture;
126
- }
127
-
128
- if (this._planet.layerLock.isFree() || material.segment.tileZoom < 2) {
129
- material.isReady = false;
130
- material.isLoading = true;
131
- if (CanvasTiles.__requestsCounter >= CanvasTiles.MAX_REQUESTS && this._counter) {
132
- this._pendingsQueue.push(material);
133
- } else {
134
- this._exec(material);
135
- }
136
- }
137
- }
138
-
139
- /**
140
- * Loads material image and apply it to the planet segment.
141
- * @protected
142
- * @param {Material} material - Loads material image.
143
- */
144
- _exec(material) {
145
- CanvasTiles.__requestsCounter++;
146
- this._counter++;
147
- var that = this;
148
- if (this.drawTile) {
149
- /**
150
- * Tile custom draw function.
151
- * @callback og.layer.CanvasTiles~drawTileCallback
152
- * @param {Material} material
153
- * @param {applyCanvasCallback} applyCanvasCallback
154
- */
155
- var e = that.events.load;
156
- if (e.handlers.length) {
157
- that.events.dispatch(e, material);
158
- }
159
- requestAnimationFrame(() => {
160
- that.drawTile(
161
- material,
162
- /**
163
- * Apply canvas.
164
- * @callback applyCanvasCallback
165
- * @param {Object} canvas -
166
- */
167
- function (canvas) {
168
- that._counter--;
169
- CanvasTiles.__requestsCounter--;
170
- if (material.isLoading) {
171
- material.applyImage(canvas);
172
- }
173
- that._dequeueRequest();
174
- }
175
- );
176
- });
177
- } else {
178
- material.textureNotExists();
179
- }
180
- }
181
-
182
- /**
183
- * Abort exact material loading.
184
- * @public
185
- * @param {Material} material - Segment material.
186
- */
187
- abortMaterialLoading(material) {
188
- if (material.isLoading && material.image) {
189
- material.image.src = "";
190
- this._counter--;
191
- CanvasTiles.__requestsCounter--;
192
- this._dequeueRequest();
193
- }
194
- material.isLoading = false;
195
- material.isReady = false;
196
- }
197
-
198
- _dequeueRequest() {
199
- if (this._pendingsQueue.length) {
200
- if (CanvasTiles.__requestsCounter < CanvasTiles.MAX_REQUESTS) {
201
- var pmat = this._whilePendings();
202
- if (pmat) {
203
- this._exec(pmat);
204
- }
205
- }
206
- } else if (this._counter === 0 && this._planet._terrainCompletedActivated) {
207
- this.events.dispatch(this.events.loadend);
208
- }
209
- }
210
-
211
- _whilePendings() {
212
- while (this._pendingsQueue.length) {
213
- var pmat = this._pendingsQueue.pop();
214
- if (pmat.segment.node) {
215
- if (
216
- pmat.segment.initialized &&
217
- pmat.segment.node.getState() === quadTree.RENDERING
218
- ) {
219
- return pmat;
220
- }
221
- pmat.isLoading = false;
222
- }
223
- }
224
- return null;
225
- }
226
-
227
- applyMaterial(material) {
228
- if (material.isReady) {
229
- return [0, 0, 1, 1];
230
- } else {
231
-
232
- var segment = material.segment;
233
- var pn = segment.node,
234
- notEmpty = false;
235
-
236
- if (segment.passReady && !material.isLoading) {
237
- this.loadMaterial(material);
238
- }
239
-
240
- var mId = this._id;
241
- var psegm = material;
242
- while (pn.parentNode) {
243
- pn = pn.parentNode;
244
- psegm = pn.segment.materials[mId];
245
- if (psegm && psegm.isReady) {
246
- notEmpty = true;
247
- break;
248
- }
249
- }
250
-
251
- if (notEmpty) {
252
- material.appliedNodeId = pn.nodeId;
253
- material.texture = psegm.texture;
254
- var dZ2 = 1.0 / (2 << (segment.tileZoom - pn.segment.tileZoom - 1));
255
- return [
256
- segment.tileX * dZ2 - pn.segment.tileX,
257
- segment.tileY * dZ2 - pn.segment.tileY,
258
- dZ2,
259
- dZ2
260
- ];
261
- } else {
262
- material.texture = segment.planet.transparentTexture;
263
- return [0, 0, 1, 1];
264
- }
265
- }
266
- }
267
-
268
- clearMaterial(material) {
269
- if (material.isReady) {
270
- material.isReady = false;
271
-
272
- !material.texture.default &&
273
- material.segment.handler.gl.deleteTexture(material.texture);
274
-
275
- material.texture = null;
276
- }
277
-
278
- this.abortMaterialLoading(material);
279
-
280
- material.isLoading = false;
281
- material.textureExists = false;
282
-
283
- if (material.image) {
284
- material.image.src = "";
285
- material.image = null;
286
- }
287
- }
288
- }
289
-
290
- export { CanvasTiles };
1
+ /**
2
+ * @module og/layer/CanvasTiles
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import * as quadTree from "../quadTree/quadTree.js";
8
+ import { Layer } from "./Layer.js";
9
+
10
+ /**
11
+ * Maximum tiles per frame.
12
+ * @const
13
+ * @type {number}
14
+ */
15
+
16
+ const EVENT_NAMES = [
17
+ /**
18
+ * Triggered when current tile image has loaded before rendereing.
19
+ * @event og.layer.CanvasTiles#load
20
+ */
21
+ "load",
22
+
23
+ /**
24
+ * Triggered when all tiles have loaded or loading has stopped.
25
+ * @event og.layer.CanvasTiles#loadend
26
+ */
27
+ "loadend"
28
+ ];
29
+
30
+ /**
31
+ * Layer used to rendering each tile as a separate canvas object.
32
+ * @class
33
+ * @extends {Layer}
34
+ * //TODO: make asynchronous handler.
35
+ * @param {String} [name="noname"] - Layer name.
36
+ * @param {Object} options:
37
+ * @param {number} [options.opacity=1.0] - Layer opacity.
38
+ * @param {number} [options.minZoom=0] - Minimal visibility zoom level.
39
+ * @param {number} [options.maxZoom=0] - Maximal visibility zoom level.
40
+ * @param {string} [options.attribution] - Layer attribution that displayed in the attribution area on the screen.
41
+ * @param {boolean} [options.isBaseLayer=false] - Base layer flag.
42
+ * @param {boolean} [options.visibility=true] - Layer visibility.
43
+ * @param {layer.CanvasTiles~drawTileCallback} [options.drawTile] - Draw tile callback.
44
+ * @fires og.layer.CanvasTiles#load
45
+ * @fires og.layer.CanvasTiles#loadend
46
+ */
47
+ class CanvasTiles extends Layer {
48
+ constructor(name, options = {}) {
49
+ super(name, options);
50
+
51
+ this.events.registerNames(EVENT_NAMES);
52
+
53
+ this.minNativeZoom = options.minNativeZoom || 0;
54
+ /**
55
+ * Current creating tiles couter.
56
+ * @protected
57
+ * @type {number}
58
+ */
59
+ this._counter = 0;
60
+
61
+ /**
62
+ * Tile pending queue that waiting for create.
63
+ * @protected
64
+ * @type {Array.<planetSegment.Material>}
65
+ */
66
+ this._pendingsQueue = []; // new og.QueueArray();
67
+
68
+ /**
69
+ * Draw tile callback.
70
+ * @type {layer.CanvasTiles~drawTileCallback}
71
+ * @public
72
+ */
73
+ this.drawTile = options.drawTile || null;
74
+ }
75
+
76
+ addTo(planet) {
77
+ this._onLoadend_ = this._onLoadend.bind(this);
78
+ this.events.on("loadend", this._onLoadend_, this);
79
+ return super.addTo(planet);
80
+ }
81
+
82
+ remove() {
83
+ this.events.off("loadend", this._onLoadend_);
84
+ this._onLoadend_ = null;
85
+ return super.remove();
86
+ }
87
+
88
+ _onLoadend() {
89
+ if (this._planet && this._planet._terrainCompletedActivated) {
90
+ this._planet.events.dispatch(this._planet.events.layerloadend, this);
91
+ }
92
+ }
93
+
94
+ get instanceName() {
95
+ return "CanvasTiles";
96
+ }
97
+
98
+ get isIdle() {
99
+ return super.isIdle && this._counter === 0;
100
+ }
101
+
102
+ /**
103
+ * Abort loading tiles.
104
+ * @public
105
+ */
106
+ abortLoading() {
107
+ var q = this._pendingsQueue;
108
+ for (var i = q._shiftIndex + 1; i < q._popIndex + 1; i++) {
109
+ if (q._array[i]) {
110
+ this.abortMaterialLoading(q._array[i]);
111
+ }
112
+ }
113
+ this._pendingsQueue = [];
114
+ // this._pendingsQueue.clear();
115
+ }
116
+
117
+ /**
118
+ * Sets layer visibility.
119
+ * @public
120
+ * @param {boolean} visibility - Layer visibility.
121
+ */
122
+ setVisibility(visibility) {
123
+ if (visibility !== this._visibility) {
124
+ super.setVisibility(visibility);
125
+
126
+ if (!visibility) {
127
+ this.abortLoading();
128
+ }
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Start to load tile material.
134
+ * @public
135
+ * @virtual
136
+ * @param {Material} material -
137
+ */
138
+ loadMaterial(material) {
139
+ let seg = material.segment;
140
+
141
+ if (this._isBaseLayer) {
142
+ material.texture = seg._isNorth ? seg.planet.solidTextureOne : seg.planet.solidTextureTwo;
143
+ } else {
144
+ material.texture = seg.planet.transparentTexture;
145
+ }
146
+
147
+ if (this._planet.layerLock.isFree() || material.segment.tileZoom < 2) {
148
+ material.isReady = false;
149
+ material.isLoading = true;
150
+ if (CanvasTiles.__requestsCounter >= CanvasTiles.MAX_REQUESTS && this._counter) {
151
+ this._pendingsQueue.push(material);
152
+ } else {
153
+ this._exec(material);
154
+ }
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Loads material image and apply it to the planet segment.
160
+ * @protected
161
+ * @param {Material} material - Loads material image.
162
+ */
163
+ _exec(material) {
164
+ CanvasTiles.__requestsCounter++;
165
+ this._counter++;
166
+ var that = this;
167
+ if (this.drawTile) {
168
+ /**
169
+ * Tile custom draw function.
170
+ * @callback og.layer.CanvasTiles~drawTileCallback
171
+ * @param {Material} material
172
+ * @param {applyCanvasCallback} applyCanvasCallback
173
+ */
174
+ var e = that.events.load;
175
+ if (e.handlers.length) {
176
+ that.events.dispatch(e, material);
177
+ }
178
+ requestAnimationFrame(() => {
179
+ that.drawTile(
180
+ material,
181
+ /**
182
+ * Apply canvas.
183
+ * @callback applyCanvasCallback
184
+ * @param {Object} canvas -
185
+ */
186
+ function (canvas) {
187
+ that._counter--;
188
+ CanvasTiles.__requestsCounter--;
189
+ if (material.isLoading) {
190
+ material.applyImage(canvas);
191
+ }
192
+ that._dequeueRequest();
193
+ }
194
+ );
195
+ });
196
+ } else {
197
+ material.textureNotExists();
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Abort exact material loading.
203
+ * @public
204
+ * @param {Material} material - Segment material.
205
+ */
206
+ abortMaterialLoading(material) {
207
+ if (material.isLoading && material.image) {
208
+ material.image.src = "";
209
+ this._counter--;
210
+ CanvasTiles.__requestsCounter--;
211
+ this._dequeueRequest();
212
+ }
213
+ material.isLoading = false;
214
+ material.isReady = false;
215
+ }
216
+
217
+ _dequeueRequest() {
218
+ if (this._pendingsQueue.length) {
219
+ if (CanvasTiles.__requestsCounter < CanvasTiles.MAX_REQUESTS) {
220
+ var pmat = this._whilePendings();
221
+ if (pmat) {
222
+ this._exec(pmat);
223
+ }
224
+ }
225
+ } else if (this._counter === 0 && this._planet && this._planet._terrainCompletedActivated) {
226
+ this.events.dispatch(this.events.loadend);
227
+ }
228
+ }
229
+
230
+ _whilePendings() {
231
+ while (this._pendingsQueue.length) {
232
+ var pmat = this._pendingsQueue.pop();
233
+ if (pmat.segment.node) {
234
+ if (
235
+ pmat.segment.initialized &&
236
+ pmat.segment.node.getState() === quadTree.RENDERING
237
+ ) {
238
+ return pmat;
239
+ }
240
+ pmat.isLoading = false;
241
+ }
242
+ }
243
+ return null;
244
+ }
245
+
246
+ applyMaterial(material) {
247
+ if (material.isReady) {
248
+ return [0, 0, 1, 1];
249
+ } else if (material.segment.tileZoom < this.minNativeZoom) {
250
+ material.textureNotExists();
251
+ } else {
252
+
253
+ let segment = material.segment;
254
+ let pn = segment.node,
255
+ notEmpty = false;
256
+
257
+ if (segment.passReady && !material.isLoading) {
258
+ this.loadMaterial(material);
259
+ }
260
+
261
+ let mId = this._id;
262
+ let psegm = material;
263
+ while (pn.parentNode) {
264
+ pn = pn.parentNode;
265
+ psegm = pn.segment.materials[mId];
266
+ if (psegm && psegm.isReady) {
267
+ notEmpty = true;
268
+ break;
269
+ }
270
+ }
271
+
272
+ if (notEmpty) {
273
+ material.appliedNodeId = pn.nodeId;
274
+ material.texture = psegm.texture;
275
+ let dZ2 = 1.0 / (2 << (segment.tileZoom - pn.segment.tileZoom - 1));
276
+ return [
277
+ segment.tileX * dZ2 - pn.segment.tileX,
278
+ segment.tileY * dZ2 - pn.segment.tileY,
279
+ dZ2,
280
+ dZ2
281
+ ];
282
+ } else {
283
+ material.texture = segment.planet.transparentTexture;
284
+ return [0, 0, 1, 1];
285
+ }
286
+ }
287
+ }
288
+
289
+ clearMaterial(material) {
290
+ if (material.isReady) {
291
+ material.isReady = false;
292
+ if (material.texture && !material.texture.default) {
293
+ material.segment.handler.gl.deleteTexture(material.texture);
294
+ material.texture = null;
295
+ }
296
+ }
297
+
298
+ this.abortMaterialLoading(material);
299
+ material.isLoading = false;
300
+ material.textureExists = false;
301
+
302
+ material.layer = null;
303
+ material.segment = null;
304
+
305
+ if (material.image) {
306
+ material.image.src = "";
307
+ material.image = null;
308
+ }
309
+ }
310
+ }
311
+
312
+ export { CanvasTiles };