@openglobus/og 0.12.4 → 0.13.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 (93) hide show
  1. package/README.md +0 -2
  2. package/dist/@openglobus/og.esm.js +2 -2
  3. package/dist/@openglobus/og.esm.js.map +1 -1
  4. package/dist/@openglobus/og.umd.js +2 -2
  5. package/dist/@openglobus/og.umd.js.map +1 -1
  6. package/package.json +7 -7
  7. package/src/og/Extent.js +3 -3
  8. package/src/og/Globe.js +277 -275
  9. package/src/og/ImageCanvas.js +3 -3
  10. package/src/og/LonLat.js +9 -9
  11. package/src/og/QueueArray.js +2 -2
  12. package/src/og/Rectangle.js +5 -5
  13. package/src/og/bv/Box.js +1 -1
  14. package/src/og/bv/Sphere.js +2 -2
  15. package/src/og/camera/Camera.js +1 -1
  16. package/src/og/camera/PlanetCamera.js +649 -646
  17. package/src/og/control/LayerSwitcher.js +1 -1
  18. package/src/og/control/MouseNavigation.js +22 -13
  19. package/src/og/control/MouseWheelZoomControl.js +2 -2
  20. package/src/og/control/ScaleControl.js +1 -1
  21. package/src/og/control/TouchNavigation.js +319 -319
  22. package/src/og/control/ZoomControl.js +132 -132
  23. package/src/og/control/visibleExtent/Segment.js +12 -12
  24. package/src/og/ellipsoid/Ellipsoid.js +577 -567
  25. package/src/og/entity/BillboardHandler.js +878 -1051
  26. package/src/og/entity/Entity.js +1 -1
  27. package/src/og/entity/EntityCollection.js +847 -857
  28. package/src/og/entity/GeoObjectHandler.js +2 -2
  29. package/src/og/entity/LabelHandler.js +888 -1040
  30. package/src/og/entity/LabelWorker.js +0 -6
  31. package/src/og/entity/PointCloud.js +495 -495
  32. package/src/og/entity/Polyline.js +2218 -2222
  33. package/src/og/entity/RayHandler.js +1 -1
  34. package/src/og/layer/CanvasTiles.js +6 -3
  35. package/src/og/layer/GeoImage.js +1 -1
  36. package/src/og/layer/KML.js +5 -5
  37. package/src/og/layer/Layer.js +800 -752
  38. package/src/og/layer/Vector.js +997 -1010
  39. package/src/og/layer/XYZ.js +359 -357
  40. package/src/og/math/Line2.js +4 -4
  41. package/src/og/math/Quat.js +2 -2
  42. package/src/og/math/Ray.js +2 -2
  43. package/src/og/math/Vec2.js +524 -524
  44. package/src/og/math/Vec3.js +900 -900
  45. package/src/og/math/Vec4.js +261 -261
  46. package/src/og/math.js +397 -398
  47. package/src/og/quadTree/EntityCollectionNode.js +389 -387
  48. package/src/og/renderer/Renderer.js +14 -20
  49. package/src/og/renderer/RendererEvents.js +1034 -1045
  50. package/src/og/scene/Planet.js +12 -9
  51. package/src/og/scene/RenderNode.js +347 -354
  52. package/src/og/segment/Segment.js +3 -1
  53. package/src/og/segment/SegmentLonLat.js +1 -4
  54. package/src/og/shaders/billboard.js +220 -204
  55. package/src/og/shaders/drawnode.js +603 -603
  56. package/src/og/shaders/label.js +596 -456
  57. package/src/og/shaders/polyline.js +365 -361
  58. package/src/og/terrain/MapboxTerrain.js +1 -1
  59. package/src/og/utils/FontAtlas.js +209 -200
  60. package/src/og/utils/GeoImageCreator.js +4 -5
  61. package/src/og/utils/TextureAtlas.js +4 -4
  62. package/src/og/utils/VectorTileCreator.js +414 -414
  63. package/src/og/utils/shared.js +1 -1
  64. package/src/og/webgl/Handler.js +28 -60
  65. package/src/og/webgl/Multisample.js +260 -260
  66. package/src/og/webgl/Program.js +411 -396
  67. package/types/bv/Box.d.ts +1 -1
  68. package/types/bv/Sphere.d.ts +1 -1
  69. package/types/camera/PlanetCamera.d.ts +3 -3
  70. package/types/control/LayerSwitcher.d.ts +1 -1
  71. package/types/ellipsoid/Ellipsoid.d.ts +9 -2
  72. package/types/entity/BillboardHandler.d.ts +0 -4
  73. package/types/entity/EntityCollection.d.ts +0 -8
  74. package/types/entity/LabelHandler.d.ts +0 -2
  75. package/types/entity/Polyline.d.ts +1 -1
  76. package/types/layer/KML.d.ts +11 -11
  77. package/types/layer/Layer.d.ts +4 -0
  78. package/types/layer/Vector.d.ts +1 -8
  79. package/types/math/Line2.d.ts +4 -4
  80. package/types/math/Ray.d.ts +2 -2
  81. package/types/math/Vec2.d.ts +1 -1
  82. package/types/math/Vec3.d.ts +1 -1
  83. package/types/math/Vec4.d.ts +2 -2
  84. package/types/math.d.ts +1 -1
  85. package/types/renderer/Renderer.d.ts +1 -1
  86. package/types/renderer/RendererEvents.d.ts +1 -1
  87. package/types/shaders/label.d.ts +1 -1
  88. package/types/utils/FontAtlas.d.ts +3 -2
  89. package/types/utils/TextureAtlas.d.ts +3 -3
  90. package/types/utils/VectorTileCreator.d.ts +4 -4
  91. package/types/utils/shared.d.ts +1 -1
  92. package/types/webgl/Handler.d.ts +6 -31
  93. package/types/webgl/Program.d.ts +2 -0
@@ -1,859 +1,849 @@
1
- /**
2
- * @module og/entity/EntityCollection
3
- */
4
-
5
- "use strict";
6
-
7
- import * as math from "../math.js";
8
- import { BillboardHandler } from "./BillboardHandler.js";
9
- import { Events } from "../Events.js";
10
- import { LabelHandler } from "./LabelHandler.js";
11
- import { PolylineHandler } from "./PolylineHandler.js";
12
- import { RayHandler } from "./RayHandler.js";
13
- import { PointCloudHandler } from "./PointCloudHandler.js";
14
- import { StripHandler } from "./StripHandler.js";
15
- import { ShapeHandler } from "./ShapeHandler.js";
16
- import { GeoObjectHandler } from "./GeoObjectHandler.js";
17
-
18
- /**
19
- * An observable collection of og.Entity instances where each entity has a unique id.
20
- * Entity collection provide handlers for an each type of entity like billboard, label or 3ds object.
21
- * @constructor
22
- * @param {Object} [options] - Entity options:
23
- * @param {Array.<Entity>} [options.entities] - Entities array.
24
- * @param {boolean} [options.visibility=true] - Entity visibility.
25
- * @param {Array.<number>} [options.scaleByDistance] - Entity scale by distance parameters. (exactly 3 entries)
26
- * First index - near distance to the entity, after entity becomes full scale.
27
- * Second index - far distance to the entity, when entity becomes zero scale.
28
- * Third index - far distance to the entity, when entity becomes invisible.
29
- * @param {number} [options.opacity] - Entity global opacity.
30
- * @param {boolean} [options.pickingEnabled=true] - Entity picking enable.
31
- * @param {Number} [options.polygonOffsetFactor=0.0] - The scale factor for the variable depth offset. The default value is 0.
32
- * @param {Number} [options.polygonOffsetUnits=0.0] - The multiplier by which an implementation-specific value is multiplied with to create a constant depth offset. The default value is 0.
33
- * @fires og.EntityCollection#entitymove
34
- * @fires og.EntityCollection#draw
35
- * @fires og.EntityCollection#drawend
36
- * @fires og.EntityCollection#add
37
- * @fires og.EntityCollection#remove
38
- * @fires og.EntityCollection#entityadd
39
- * @fires og.EntityCollection#entityremove
40
- * @fires og.EntityCollection#visibilitychange
41
- * @fires og.EntityCollection#mousemove
42
- * @fires og.EntityCollection#mouseenter
43
- * @fires og.EntityCollection#mouseleave
44
- * @fires og.EntityCollection#lclick
45
- * @fires og.EntityCollection#rclick
46
- * @fires og.EntityCollection#mclick
47
- * @fires og.EntityCollection#ldblclick
48
- * @fires og.EntityCollection#rdblclick
49
- * @fires og.EntityCollection#mdblclick
50
- * @fires og.EntityCollection#lup
51
- * @fires og.EntityCollection#rup
52
- * @fires og.EntityCollection#mup
53
- * @fires og.EntityCollection#ldown
54
- * @fires og.EntityCollection#rdown
55
- * @fires og.EntityCollection#mdown
56
- * @fires og.EntityCollection#lhold
57
- * @fires og.EntityCollection#rhold
58
- * @fires og.EntityCollection#mhold
59
- * @fires og.EntityCollection#mousewheel
60
- * @fires og.EntityCollection#touchmove
61
- * @fires og.EntityCollection#touchstart
62
- * @fires og.EntityCollection#touchend
63
- * @fires og.EntityCollection#doubletouch
64
- * @fires og.EntityCollection#touchleave
65
- * @fires og.EntityCollection#touchenter
66
- */
67
- class EntityCollection {
68
- constructor(options) {
69
- options = options || {};
70
-
71
- /**
72
- * Unic identifier.
73
- * @public
74
- * @readonly
75
- */
76
- this.id = EntityCollection._staticCounter++;
77
-
78
- /**
79
- * Render node collections array index.
80
- * @protected
81
- * @type {number}
82
- */
83
- this._renderNodeIndex = -1;
84
-
85
- /**
86
- * Render node context.
87
- * @public
88
- * @type {RenderNode}
89
- */
90
- this.renderNode = null;
91
-
92
- /**
93
- * Visibility option.
94
- * @protected
95
- * @type {boolean}
96
- */
97
- this._visibility = options.visibility == undefined ? true : options.visibility;
98
-
99
- /**
100
- * Specifies the scale factor for gl.polygonOffset function to calculate depth values, 0.0 is default.
101
- * @public
102
- * @type {Number}
103
- */
104
- this.polygonOffsetFactor =
105
- options.polygonOffsetFactor != undefined ? options.polygonOffsetFactor : 0.0;
106
-
107
- /**
108
- * Specifies the scale Units for gl.polygonOffset function to calculate depth values, 0.0 is default.
109
- * @public
110
- * @type {Number}
111
- */
112
- this.polygonOffsetUnits =
113
- options.polygonOffsetUnits != undefined ? options.polygonOffsetUnits : 0.0;
114
-
115
- /**
116
- * Billboards handler
117
- * @public
118
- * @type {BillboardHandler}
119
- */
120
- this.billboardHandler = new BillboardHandler(this);
121
-
122
- /**
123
- * Labels handler
124
- * @public
125
- * @type {LabelHandler}
126
- */
127
- this.labelHandler = new LabelHandler(this, options.labelMaxLetters);
128
-
129
- /**
130
- * Shape handler
131
- * @public
132
- * @type {ShapeHandler}
133
- */
134
- this.shapeHandler = new ShapeHandler(this);
135
-
136
- /**
137
- * Polyline handler
138
- * @public
139
- * @type {PolylineHandler}
140
- */
141
- this.polylineHandler = new PolylineHandler(this);
142
-
143
- /**
144
- * Ray handler
145
- * @public
146
- * @type {RayHandler}
147
- */
148
- this.rayHandler = new RayHandler(this);
149
-
150
- /**
151
- * PointCloud handler
152
- * @public
153
- * @type {PointCloudHandler}
154
- */
155
- this.pointCloudHandler = new PointCloudHandler(this);
156
-
157
- /**
158
- * Strip handler
159
- * @public
160
- * @type {StripHandler}
161
- */
162
- this.stripHandler = new StripHandler(this);
163
-
164
- /**
165
- * Geo object handler
166
- * @public
167
- * @type {og.GeoObjectHandler}
168
- */
169
- this.geoObjectHandler = new GeoObjectHandler(this);
170
-
171
- if (options.pickingEnabled != undefined) {
172
- this.setPickingEnabled(options.pickingEnabled);
173
- }
174
-
175
- /**
176
- * Entities array.
177
- * @protected
178
- * @type {Array.<Entity>}
179
- */
180
- this._entities = [];
181
-
182
- /**
183
- * First index - near distance to the entity, after entity becomes full scale.
184
- * Second index - far distance to the entity, when entity becomes zero scale.
185
- * Third index - far distance to the entity, when entity becomes invisible.
186
- * @public
187
- * @type {Array.<number>} - (exactly 3 entries)
188
- */
189
- this.scaleByDistance = options.scaleByDistance || [math.MAX32, math.MAX32, math.MAX32];
190
-
191
- this.pickingScale = options.pickingScale || 1.0;
192
-
193
- /**
194
- * Global opacity.
195
- * @protected
196
- * @type {number}
197
- */
198
- this._opacity = options.opacity == undefined ? 1.0 : options.opacity;
199
-
200
- /**
201
- * Opacity state during the animated opacity.
202
- * @protected
203
- * @type {number}
204
- */
205
- this._fadingOpacity = this._opacity;
206
-
207
- /**
208
- * Entity collection events handler.
209
- * @public
210
- * @type {Events}
211
- */
212
- this.events = new Events(EVENT_NAMES, this);
213
-
214
- this.rendererEvents = this.events;
215
-
216
- // initialize current entities
217
- if (options.entities) {
218
- this.addEntities(options.entities);
219
- }
220
- }
221
-
222
- static get _staticCounter() {
223
- if (!this._counter && this._counter !== 0) {
224
- this._counter = 0;
225
- }
226
- return this._counter;
227
- }
228
-
229
- static set _staticCounter(n) {
230
- this._counter = n;
231
- }
232
-
233
- setPolygonOffset(factor, units) {
234
- this.polygonOffsetFactor = factor;
235
- this.polygonOffsetUnits = units;
236
- }
237
-
238
- /**
239
- * Sets collection visibility.
240
- * @public
241
- * @param {boolean} visibility - Visibility flag.
242
- */
243
- setVisibility(visibility) {
244
- this._visibility = visibility;
245
- this._fadingOpacity = this._opacity * (visibility ? 1 : 0);
246
- this.events.dispatch(this.events.visibilitychange, this);
247
- }
248
-
249
- /**
250
- * Returns collection visibility.
251
- * @public
252
- * @returns {boolean} -
253
- */
254
- getVisibility() {
255
- return this._visibility;
256
- }
257
-
258
- /**
259
- * Sets collection opacity.
260
- * @public
261
- * @param {number} opacity - Opacity.
262
- */
263
- setOpacity(opacity) {
264
- this._opacity = opacity;
265
- }
266
-
267
- /**
268
- * Sets collection picking ability.
269
- * @public
270
- * @param {boolean} enable - Picking enable flag.
271
- */
272
- setPickingEnabled(enable) {
273
- this.billboardHandler.pickingEnabled = enable;
274
- this.labelHandler.pickingEnabled = enable;
275
- this.polylineHandler.pickingEnabled = enable;
276
- this.rayHandler.pickingEnabled = enable;
277
- this.shapeHandler.pickingEnabled = enable;
278
- this.pointCloudHandler.pickingEnabled = enable;
279
- this.stripHandler.pickingEnabled = enable;
280
- this.geoObjectHandler.pickingEnabled = enable;
281
- }
282
-
283
- /**
284
- * Gets collection opacity.
285
- * @public
286
- * @returns {number} -
287
- */
288
- getOpacity() {
289
- return this._opacity;
290
- }
291
-
292
- /**
293
- * Sets scale by distance parameters.
294
- * @public
295
- * @param {number} near - Full scale entity distance.
296
- * @param {number} far - Zerol scale entity distance.
297
- * @param {number} [farInvisible] - Entity visibility distance.
298
- */
299
- setScaleByDistance(near, far, farInvisible) {
300
- this.scaleByDistance[0] = near;
301
- this.scaleByDistance[1] = far;
302
- this.scaleByDistance[2] = farInvisible || math.MAX32;
303
- }
304
-
305
- _addRecursively(entity) {
306
- // billboard
307
- entity.billboard && this.billboardHandler.add(entity.billboard);
308
-
309
- // label
310
- entity.label && this.labelHandler.add(entity.label);
311
-
312
- // shape
313
- entity.shape && this.shapeHandler.add(entity.shape);
314
-
315
- // polyline
316
- entity.polyline && this.polylineHandler.add(entity.polyline);
317
-
318
- // ray
319
- entity.ray && this.rayHandler.add(entity.ray);
320
-
321
- // pointCloud
322
- entity.pointCloud && this.pointCloudHandler.add(entity.pointCloud);
323
-
324
- // strip
325
- entity.strip && this.stripHandler.add(entity.strip);
326
-
327
- //geoObject
328
- entity.geoObject && this.geoObjectHandler.add(entity.geoObject);
329
-
330
- this.events.dispatch(this.events.entityadd, entity);
331
-
332
- for (var i = 0; i < entity.childrenNodes.length; i++) {
333
- entity.childrenNodes[i]._entityCollection = this;
334
- entity.childrenNodes[i]._entityCollectionIndex = entity._entityCollectionIndex;
335
- entity.childrenNodes[i]._pickingColor = entity._pickingColor;
336
- this._addRecursively(entity.childrenNodes[i]);
337
- }
338
- }
339
-
340
- /**
341
- * Adds entity to the collection and returns collection.
342
- * @public
343
- * @param {Entity} entity - Entity.
344
- * @returns {EntityCollection} -
345
- */
346
- add(entity) {
347
- if (!entity._entityCollection) {
348
- entity._entityCollection = this;
349
- entity._entityCollectionIndex = this._entities.length;
350
- this._entities.push(entity);
351
- var rn = this.renderNode;
352
- if (rn) {
353
- rn.renderer && rn.renderer.assignPickingColor(entity);
354
- if (rn.ellipsoid && entity._cartesian.isZero()) {
355
- entity.setCartesian3v(rn.ellipsoid.lonLatToCartesian(entity._lonlat));
356
- }
357
- }
358
- this._addRecursively(entity);
359
- entity.setPickingColor();
360
- }
361
- return this;
362
- }
363
-
364
- /**
365
- * Adds entities array to the collection and returns collection.
366
- * @public
367
- * @param {Array.<Entity>} entities - Entities array.
368
- * @returns {EntityCollection} -
369
- */
370
- addEntities(entities) {
371
- for (let i = 0, len = entities.length; i < len; i++) {
372
- this.add(entities[i]);
373
- }
374
- return this;
375
- }
376
-
377
- /**
378
- * Returns true if the entity belongs this collection, otherwise returns false.
379
- * @public
380
- * @param {Entity} entity - Entity.
381
- * @returns {boolean} -
382
- */
383
- belongs(entity) {
384
- return (
385
- entity._entityCollection &&
386
- this._renderNodeIndex === entity._entityCollection._renderNodeIndex
387
- );
388
- }
389
-
390
- _removeRecursively(entity) {
391
- entity._entityCollection = null;
392
- entity._entityCollectionIndex = -1;
393
-
394
- // billboard
395
- entity.billboard && this.billboardHandler.remove(entity.billboard);
396
-
397
- // label
398
- entity.label && this.labelHandler.remove(entity.label);
399
-
400
- // shape
401
- entity.shape && this.shapeHandler.remove(entity.shape);
402
-
403
- // polyline
404
- entity.polyline && this.polylineHandler.remove(entity.polyline);
405
-
406
- // ray
407
- entity.ray && this.rayHandler.remove(entity.ray);
408
-
409
- // pointCloud
410
- entity.pointCloud && this.pointCloudHandler.remove(entity.pointCloud);
411
-
412
- // strip
413
- entity.strip && this.stripHandler.remove(entity.strip);
414
-
415
- // geoObject
416
- entity.geoObject && this.geoObjectHandler.remove(entity.geoObject);
417
-
418
- for (var i = 0; i < entity.childrenNodes.length; i++) {
419
- this._removeRecursively(entity.childrenNodes[i]);
420
- }
421
- }
422
-
423
- /**
424
- * Removes entity from this collection.
425
- * @public
426
- * @param {Entity} entity - Entity to remove.
427
- */
428
- removeEntity(entity) {
429
- this._entities.splice(entity._entityCollectionIndex, 1);
430
- this.reindexEntitiesArray(entity._entityCollectionIndex);
431
-
432
- // clear picking color
433
- if (this.renderNode && this.renderNode.renderer) {
434
- this.renderNode.renderer.clearPickingColor(entity);
435
- entity._pickingColor.clear();
436
- }
437
-
438
- if (this.belongs(entity)) {
439
- this._removeRecursively(entity);
440
- }
441
-
442
- this.events.dispatch(this.events.entityremove, entity);
443
- }
444
-
445
- _removeEntitySilent(entity) {
446
- this._entities.splice(entity._entityCollectionIndex, 1);
447
- this.reindexEntitiesArray(entity._entityCollectionIndex);
448
-
449
- // clear picking color
450
- if (this.renderNode && this.renderNode.renderer) {
451
- this.renderNode.renderer.clearPickingColor(entity);
452
- entity._pickingColor.clear();
453
- }
454
-
455
- if (this.belongs(entity)) {
456
- this._removeRecursively(entity);
457
- }
458
- }
459
-
460
- /**
461
- * Creates or refresh collected entities picking color.
462
- * @public
463
- */
464
- createPickingColors() {
465
- var e = this._entities;
466
- for (var i = 0; i < e.length; i++) {
467
- if (!e[i].parent) {
468
- this.renderNode.renderer.assignPickingColor(e[i]);
469
- e[i].setPickingColor();
470
- }
471
- }
472
- }
473
-
474
- /**
475
- * Refresh collected entities indexes from startIndex entitytes collection array position.
476
- * @public
477
- * @param {number} startIndex - Entities collection array index.
478
- */
479
- reindexEntitiesArray(startIndex) {
480
- var e = this._entities;
481
- for (var i = startIndex; i < e.length; i++) {
482
- e[i]._entityCollectionIndex = i;
483
- }
484
- }
485
-
486
- /**
487
- * Adds this collection to render node.
488
- * @public
489
- * @param {RenderNode} renderNode - Render node.
490
- * @param {boolean} [isHidden] - Uses in vector layers that render in planet render specific function.
491
- * @returns {EntityCollection} -
492
- */
493
- addTo(renderNode, isHidden) {
494
- if (!this.renderNode) {
495
- this.renderNode = renderNode;
496
- if (!isHidden) {
497
- this._renderNodeIndex = renderNode.entityCollections.length;
498
- renderNode.entityCollections.push(this);
499
- }
500
- renderNode.ellipsoid && this._updateGeodeticCoordinates(renderNode.ellipsoid);
501
-
502
- this.bindRenderNode(renderNode);
503
-
504
- this.events.dispatch(this.events.add, this);
505
- }
506
- return this;
507
- }
508
-
509
- /**
510
- * This function is called in the RenderNode assign function.
511
- * @param {RenderNode} renderNode
512
- */
513
- bindRenderNode(renderNode) {
514
- if (renderNode.renderer) {
515
- this.billboardHandler.setRenderer(renderNode.renderer);
516
- this.labelHandler.setRenderer(renderNode.renderer);
517
- this.rayHandler.setRenderer(renderNode.renderer);
518
-
519
- this.geoObjectHandler.setRenderNode(renderNode);
520
-
521
- this.shapeHandler.setRenderNode(renderNode);
522
- this.polylineHandler.setRenderNode(renderNode);
523
- this.pointCloudHandler.setRenderNode(renderNode);
524
- this.stripHandler.setRenderNode(renderNode);
525
-
526
- this.updateBillboardsTextureAtlas();
527
- this.updateLabelsFontAtlas();
528
- this.createPickingColors();
529
- }
530
- }
531
-
532
- /**
533
- * Updates coordiantes all lonLat entities in collection after collecction attached to the planet node.
534
- * @private
535
- * @param {Ellipsoid} ellipsoid - Globe ellipsoid.
536
- */
537
- _updateGeodeticCoordinates(ellipsoid) {
538
- var e = this._entities;
539
- var i = e.length;
540
- while (i--) {
541
- var ei = e[i];
542
- ei._lonlat && ei.setCartesian3v(ellipsoid.lonLatToCartesian(ei._lonlat));
543
- }
544
- }
545
-
546
- /**
547
- * Updates billboard texture atlas.
548
- * @public
549
- */
550
- updateBillboardsTextureAtlas() {
551
- var b = this.billboardHandler._billboards;
552
- for (var i = 0; i < b.length; i++) {
553
- b[i].setSrc(b[i]._src);
554
- }
555
- }
556
-
557
- /**
558
- * Updates labels font atlas.
559
- * @public
560
- */
561
- updateLabelsFontAtlas() {
562
- if (this.renderNode) {
1
+ /**
2
+ * @module og/entity/EntityCollection
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import * as math from "../math.js";
8
+ import { BillboardHandler } from "./BillboardHandler.js";
9
+ import { Events } from "../Events.js";
10
+ import { LabelHandler } from "./LabelHandler.js";
11
+ import { PolylineHandler } from "./PolylineHandler.js";
12
+ import { RayHandler } from "./RayHandler.js";
13
+ import { PointCloudHandler } from "./PointCloudHandler.js";
14
+ import { StripHandler } from "./StripHandler.js";
15
+ import { ShapeHandler } from "./ShapeHandler.js";
16
+ import { GeoObjectHandler } from "./GeoObjectHandler.js";
17
+
18
+ /**
19
+ * An observable collection of og.Entity instances where each entity has a unique id.
20
+ * Entity collection provide handlers for an each type of entity like billboard, label or 3ds object.
21
+ * @constructor
22
+ * @param {Object} [options] - Entity options:
23
+ * @param {Array.<Entity>} [options.entities] - Entities array.
24
+ * @param {boolean} [options.visibility=true] - Entity visibility.
25
+ * @param {Array.<number>} [options.scaleByDistance] - Entity scale by distance parameters. (exactly 3 entries)
26
+ * First index - near distance to the entity, after entity becomes full scale.
27
+ * Second index - far distance to the entity, when entity becomes zero scale.
28
+ * Third index - far distance to the entity, when entity becomes invisible.
29
+ * @param {number} [options.opacity] - Entity global opacity.
30
+ * @param {boolean} [options.pickingEnabled=true] - Entity picking enable.
31
+ * @param {Number} [options.polygonOffsetUnits=0.0] - The multiplier by which an implementation-specific value is multiplied with to create a constant depth offset. The default value is 0.
32
+ * @fires og.EntityCollection#entitymove
33
+ * @fires og.EntityCollection#draw
34
+ * @fires og.EntityCollection#drawend
35
+ * @fires og.EntityCollection#add
36
+ * @fires og.EntityCollection#remove
37
+ * @fires og.EntityCollection#entityadd
38
+ * @fires og.EntityCollection#entityremove
39
+ * @fires og.EntityCollection#visibilitychange
40
+ * @fires og.EntityCollection#mousemove
41
+ * @fires og.EntityCollection#mouseenter
42
+ * @fires og.EntityCollection#mouseleave
43
+ * @fires og.EntityCollection#lclick
44
+ * @fires og.EntityCollection#rclick
45
+ * @fires og.EntityCollection#mclick
46
+ * @fires og.EntityCollection#ldblclick
47
+ * @fires og.EntityCollection#rdblclick
48
+ * @fires og.EntityCollection#mdblclick
49
+ * @fires og.EntityCollection#lup
50
+ * @fires og.EntityCollection#rup
51
+ * @fires og.EntityCollection#mup
52
+ * @fires og.EntityCollection#ldown
53
+ * @fires og.EntityCollection#rdown
54
+ * @fires og.EntityCollection#mdown
55
+ * @fires og.EntityCollection#lhold
56
+ * @fires og.EntityCollection#rhold
57
+ * @fires og.EntityCollection#mhold
58
+ * @fires og.EntityCollection#mousewheel
59
+ * @fires og.EntityCollection#touchmove
60
+ * @fires og.EntityCollection#touchstart
61
+ * @fires og.EntityCollection#touchend
62
+ * @fires og.EntityCollection#doubletouch
63
+ * @fires og.EntityCollection#touchleave
64
+ * @fires og.EntityCollection#touchenter
65
+ */
66
+ class EntityCollection {
67
+ constructor(options) {
68
+ options = options || {};
69
+
70
+ /**
71
+ * Unic identifier.
72
+ * @public
73
+ * @readonly
74
+ */
75
+ this.id = EntityCollection._staticCounter++;
76
+
77
+ /**
78
+ * Render node collections array index.
79
+ * @protected
80
+ * @type {number}
81
+ */
82
+ this._renderNodeIndex = -1;
83
+
84
+ /**
85
+ * Render node context.
86
+ * @public
87
+ * @type {RenderNode}
88
+ */
89
+ this.renderNode = null;
90
+
91
+ /**
92
+ * Visibility option.
93
+ * @protected
94
+ * @type {boolean}
95
+ */
96
+ this._visibility = options.visibility == undefined ? true : options.visibility;
97
+
98
+ /**
99
+ * Specifies the scale Units for gl.polygonOffset function to calculate depth values, 0.0 is default.
100
+ * @public
101
+ * @type {Number}
102
+ */
103
+ this.polygonOffsetUnits =
104
+ options.polygonOffsetUnits != undefined ? options.polygonOffsetUnits : 0.0;
105
+
106
+ /**
107
+ * Billboards handler
108
+ * @public
109
+ * @type {BillboardHandler}
110
+ */
111
+ this.billboardHandler = new BillboardHandler(this);
112
+
113
+ /**
114
+ * Labels handler
115
+ * @public
116
+ * @type {LabelHandler}
117
+ */
118
+ this.labelHandler = new LabelHandler(this, options.labelMaxLetters);
119
+
120
+ /**
121
+ * Shape handler
122
+ * @public
123
+ * @type {ShapeHandler}
124
+ */
125
+ this.shapeHandler = new ShapeHandler(this);
126
+
127
+ /**
128
+ * Polyline handler
129
+ * @public
130
+ * @type {PolylineHandler}
131
+ */
132
+ this.polylineHandler = new PolylineHandler(this);
133
+
134
+ /**
135
+ * Ray handler
136
+ * @public
137
+ * @type {RayHandler}
138
+ */
139
+ this.rayHandler = new RayHandler(this);
140
+
141
+ /**
142
+ * PointCloud handler
143
+ * @public
144
+ * @type {PointCloudHandler}
145
+ */
146
+ this.pointCloudHandler = new PointCloudHandler(this);
147
+
148
+ /**
149
+ * Strip handler
150
+ * @public
151
+ * @type {StripHandler}
152
+ */
153
+ this.stripHandler = new StripHandler(this);
154
+
155
+ /**
156
+ * Geo object handler
157
+ * @public
158
+ * @type {og.GeoObjectHandler}
159
+ */
160
+ this.geoObjectHandler = new GeoObjectHandler(this);
161
+
162
+ if (options.pickingEnabled != undefined) {
163
+ this.setPickingEnabled(options.pickingEnabled);
164
+ }
165
+
166
+ /**
167
+ * Entities array.
168
+ * @protected
169
+ * @type {Array.<Entity>}
170
+ */
171
+ this._entities = [];
172
+
173
+ /**
174
+ * First index - near distance to the entity, after entity becomes full scale.
175
+ * Second index - far distance to the entity, when entity becomes zero scale.
176
+ * Third index - far distance to the entity, when entity becomes invisible.
177
+ * @public
178
+ * @type {Array.<number>} - (exactly 3 entries)
179
+ */
180
+ this.scaleByDistance = options.scaleByDistance || [math.MAX32, math.MAX32, math.MAX32];
181
+
182
+ this.pickingScale = options.pickingScale || 1.0;
183
+
184
+ /**
185
+ * Global opacity.
186
+ * @protected
187
+ * @type {number}
188
+ */
189
+ this._opacity = options.opacity == undefined ? 1.0 : options.opacity;
190
+
191
+ /**
192
+ * Opacity state during the animated opacity.
193
+ * @protected
194
+ * @type {number}
195
+ */
196
+ this._fadingOpacity = this._opacity;
197
+
198
+ /**
199
+ * Entity collection events handler.
200
+ * @public
201
+ * @type {Events}
202
+ */
203
+ this.events = new Events(EVENT_NAMES, this);
204
+
205
+ this.rendererEvents = this.events;
206
+
207
+ // initialize current entities
208
+ if (options.entities) {
209
+ this.addEntities(options.entities);
210
+ }
211
+ }
212
+
213
+ static get _staticCounter() {
214
+ if (!this._counter && this._counter !== 0) {
215
+ this._counter = 0;
216
+ }
217
+ return this._counter;
218
+ }
219
+
220
+ static set _staticCounter(n) {
221
+ this._counter = n;
222
+ }
223
+
224
+ // setPolygonOffset(factor, units) {
225
+ // this.polygonOffsetUnits = units;
226
+ // }
227
+
228
+ /**
229
+ * Sets collection visibility.
230
+ * @public
231
+ * @param {boolean} visibility - Visibility flag.
232
+ */
233
+ setVisibility(visibility) {
234
+ this._visibility = visibility;
235
+ this._fadingOpacity = this._opacity * (visibility ? 1 : 0);
236
+ this.events.dispatch(this.events.visibilitychange, this);
237
+ }
238
+
239
+ /**
240
+ * Returns collection visibility.
241
+ * @public
242
+ * @returns {boolean} -
243
+ */
244
+ getVisibility() {
245
+ return this._visibility;
246
+ }
247
+
248
+ /**
249
+ * Sets collection opacity.
250
+ * @public
251
+ * @param {number} opacity - Opacity.
252
+ */
253
+ setOpacity(opacity) {
254
+ this._opacity = opacity;
255
+ }
256
+
257
+ /**
258
+ * Sets collection picking ability.
259
+ * @public
260
+ * @param {boolean} enable - Picking enable flag.
261
+ */
262
+ setPickingEnabled(enable) {
263
+ this.billboardHandler.pickingEnabled = enable;
264
+ this.labelHandler.pickingEnabled = enable;
265
+ this.polylineHandler.pickingEnabled = enable;
266
+ this.rayHandler.pickingEnabled = enable;
267
+ this.shapeHandler.pickingEnabled = enable;
268
+ this.pointCloudHandler.pickingEnabled = enable;
269
+ this.stripHandler.pickingEnabled = enable;
270
+ this.geoObjectHandler.pickingEnabled = enable;
271
+ }
272
+
273
+ /**
274
+ * Gets collection opacity.
275
+ * @public
276
+ * @returns {number} -
277
+ */
278
+ getOpacity() {
279
+ return this._opacity;
280
+ }
281
+
282
+ /**
283
+ * Sets scale by distance parameters.
284
+ * @public
285
+ * @param {number} near - Full scale entity distance.
286
+ * @param {number} far - Zerol scale entity distance.
287
+ * @param {number} [farInvisible] - Entity visibility distance.
288
+ */
289
+ setScaleByDistance(near, far, farInvisible) {
290
+ this.scaleByDistance[0] = near;
291
+ this.scaleByDistance[1] = far;
292
+ this.scaleByDistance[2] = farInvisible || math.MAX32;
293
+ }
294
+
295
+ _addRecursively(entity) {
296
+ // billboard
297
+ entity.billboard && this.billboardHandler.add(entity.billboard);
298
+
299
+ // label
300
+ entity.label && this.labelHandler.add(entity.label);
301
+
302
+ // shape
303
+ entity.shape && this.shapeHandler.add(entity.shape);
304
+
305
+ // polyline
306
+ entity.polyline && this.polylineHandler.add(entity.polyline);
307
+
308
+ // ray
309
+ entity.ray && this.rayHandler.add(entity.ray);
310
+
311
+ // pointCloud
312
+ entity.pointCloud && this.pointCloudHandler.add(entity.pointCloud);
313
+
314
+ // strip
315
+ entity.strip && this.stripHandler.add(entity.strip);
316
+
317
+ //geoObject
318
+ entity.geoObject && this.geoObjectHandler.add(entity.geoObject);
319
+
320
+ this.events.dispatch(this.events.entityadd, entity);
321
+
322
+ for (var i = 0; i < entity.childrenNodes.length; i++) {
323
+ entity.childrenNodes[i]._entityCollection = this;
324
+ entity.childrenNodes[i]._entityCollectionIndex = entity._entityCollectionIndex;
325
+ entity.childrenNodes[i]._pickingColor = entity._pickingColor;
326
+ this._addRecursively(entity.childrenNodes[i]);
327
+ }
328
+ }
329
+
330
+ /**
331
+ * Adds entity to the collection and returns collection.
332
+ * @public
333
+ * @param {Entity} entity - Entity.
334
+ * @returns {EntityCollection} -
335
+ */
336
+ add(entity) {
337
+ if (!entity._entityCollection) {
338
+ entity._entityCollection = this;
339
+ entity._entityCollectionIndex = this._entities.length;
340
+ this._entities.push(entity);
341
+ var rn = this.renderNode;
342
+ if (rn) {
343
+ rn.renderer && rn.renderer.assignPickingColor(entity);
344
+ if (rn.ellipsoid && entity._cartesian.isZero()) {
345
+ entity.setCartesian3v(rn.ellipsoid.lonLatToCartesian(entity._lonlat));
346
+ }
347
+ }
348
+ this._addRecursively(entity);
349
+ entity.setPickingColor();
350
+ }
351
+ return this;
352
+ }
353
+
354
+ /**
355
+ * Adds entities array to the collection and returns collection.
356
+ * @public
357
+ * @param {Array.<Entity>} entities - Entities array.
358
+ * @returns {EntityCollection} -
359
+ */
360
+ addEntities(entities) {
361
+ for (let i = 0, len = entities.length; i < len; i++) {
362
+ this.add(entities[i]);
363
+ }
364
+ return this;
365
+ }
366
+
367
+ /**
368
+ * Returns true if the entity belongs this collection, otherwise returns false.
369
+ * @public
370
+ * @param {Entity} entity - Entity.
371
+ * @returns {boolean} -
372
+ */
373
+ belongs(entity) {
374
+ return (
375
+ entity._entityCollection &&
376
+ this._renderNodeIndex === entity._entityCollection._renderNodeIndex
377
+ );
378
+ }
379
+
380
+ _removeRecursively(entity) {
381
+ entity._entityCollection = null;
382
+ entity._entityCollectionIndex = -1;
383
+
384
+ // billboard
385
+ entity.billboard && this.billboardHandler.remove(entity.billboard);
386
+
387
+ // label
388
+ entity.label && this.labelHandler.remove(entity.label);
389
+
390
+ // shape
391
+ entity.shape && this.shapeHandler.remove(entity.shape);
392
+
393
+ // polyline
394
+ entity.polyline && this.polylineHandler.remove(entity.polyline);
395
+
396
+ // ray
397
+ entity.ray && this.rayHandler.remove(entity.ray);
398
+
399
+ // pointCloud
400
+ entity.pointCloud && this.pointCloudHandler.remove(entity.pointCloud);
401
+
402
+ // strip
403
+ entity.strip && this.stripHandler.remove(entity.strip);
404
+
405
+ // geoObject
406
+ entity.geoObject && this.geoObjectHandler.remove(entity.geoObject);
407
+
408
+ for (var i = 0; i < entity.childrenNodes.length; i++) {
409
+ this._removeRecursively(entity.childrenNodes[i]);
410
+ }
411
+ }
412
+
413
+ /**
414
+ * Removes entity from this collection.
415
+ * @public
416
+ * @param {Entity} entity - Entity to remove.
417
+ */
418
+ removeEntity(entity) {
419
+ this._entities.splice(entity._entityCollectionIndex, 1);
420
+ this.reindexEntitiesArray(entity._entityCollectionIndex);
421
+
422
+ // clear picking color
423
+ if (this.renderNode && this.renderNode.renderer) {
424
+ this.renderNode.renderer.clearPickingColor(entity);
425
+ entity._pickingColor.clear();
426
+ }
427
+
428
+ if (this.belongs(entity)) {
429
+ this._removeRecursively(entity);
430
+ }
431
+
432
+ this.events.dispatch(this.events.entityremove, entity);
433
+ }
434
+
435
+ _removeEntitySilent(entity) {
436
+ this._entities.splice(entity._entityCollectionIndex, 1);
437
+ this.reindexEntitiesArray(entity._entityCollectionIndex);
438
+
439
+ // clear picking color
440
+ if (this.renderNode && this.renderNode.renderer) {
441
+ this.renderNode.renderer.clearPickingColor(entity);
442
+ entity._pickingColor.clear();
443
+ }
444
+
445
+ if (this.belongs(entity)) {
446
+ this._removeRecursively(entity);
447
+ }
448
+ }
449
+
450
+ /**
451
+ * Creates or refresh collected entities picking color.
452
+ * @public
453
+ */
454
+ createPickingColors() {
455
+ var e = this._entities;
456
+ for (var i = 0; i < e.length; i++) {
457
+ if (!e[i].parent) {
458
+ this.renderNode.renderer.assignPickingColor(e[i]);
459
+ e[i].setPickingColor();
460
+ }
461
+ }
462
+ }
463
+
464
+ /**
465
+ * Refresh collected entities indexes from startIndex entitytes collection array position.
466
+ * @public
467
+ * @param {number} startIndex - Entities collection array index.
468
+ */
469
+ reindexEntitiesArray(startIndex) {
470
+ var e = this._entities;
471
+ for (var i = startIndex; i < e.length; i++) {
472
+ e[i]._entityCollectionIndex = i;
473
+ }
474
+ }
475
+
476
+ /**
477
+ * Adds this collection to render node.
478
+ * @public
479
+ * @param {RenderNode} renderNode - Render node.
480
+ * @param {boolean} [isHidden] - Uses in vector layers that render in planet render specific function.
481
+ * @returns {EntityCollection} -
482
+ */
483
+ addTo(renderNode, isHidden) {
484
+ if (!this.renderNode) {
485
+ this.renderNode = renderNode;
486
+ if (!isHidden) {
487
+ this._renderNodeIndex = renderNode.entityCollections.length;
488
+ renderNode.entityCollections.push(this);
489
+ }
490
+ renderNode.ellipsoid && this._updateGeodeticCoordinates(renderNode.ellipsoid);
491
+
492
+ this.bindRenderNode(renderNode);
493
+
494
+ this.events.dispatch(this.events.add, this);
495
+ }
496
+ return this;
497
+ }
498
+
499
+ /**
500
+ * This function is called in the RenderNode assign function.
501
+ * @param {RenderNode} renderNode
502
+ */
503
+ bindRenderNode(renderNode) {
504
+ if (renderNode.renderer) {
505
+ this.billboardHandler.setRenderer(renderNode.renderer);
506
+ this.labelHandler.setRenderer(renderNode.renderer);
507
+ this.rayHandler.setRenderer(renderNode.renderer);
508
+
509
+ this.geoObjectHandler.setRenderNode(renderNode);
510
+
511
+ this.shapeHandler.setRenderNode(renderNode);
512
+ this.polylineHandler.setRenderNode(renderNode);
513
+ this.pointCloudHandler.setRenderNode(renderNode);
514
+ this.stripHandler.setRenderNode(renderNode);
515
+
516
+ this.updateBillboardsTextureAtlas();
517
+ this.updateLabelsFontAtlas();
518
+ this.createPickingColors();
519
+ }
520
+ }
521
+
522
+ /**
523
+ * Updates coordiantes all lonLat entities in collection after collecction attached to the planet node.
524
+ * @private
525
+ * @param {Ellipsoid} ellipsoid - Globe ellipsoid.
526
+ */
527
+ _updateGeodeticCoordinates(ellipsoid) {
528
+ var e = this._entities;
529
+ var i = e.length;
530
+ while (i--) {
531
+ var ei = e[i];
532
+ ei._lonlat && ei.setCartesian3v(ellipsoid.lonLatToCartesian(ei._lonlat));
533
+ }
534
+ }
535
+
536
+ /**
537
+ * Updates billboard texture atlas.
538
+ * @public
539
+ */
540
+ updateBillboardsTextureAtlas() {
541
+ var b = this.billboardHandler._billboards;
542
+ for (var i = 0; i < b.length; i++) {
543
+ b[i].setSrc(b[i]._src);
544
+ }
545
+ }
546
+
547
+ /**
548
+ * Updates labels font atlas.
549
+ * @public
550
+ */
551
+ updateLabelsFontAtlas() {
552
+ if (this.renderNode) {
563
553
  var l = [].concat(this.labelHandler._billboards);
564
- this.labelHandler._billboards = [];
554
+ this.labelHandler._billboards = [];
565
555
  for (var i = 0; i < l.length; i++) {
566
- this.labelHandler.assignFontAtlas(l[i]);
567
- }
568
- }
569
- }
570
-
571
- /**
572
- * Removes collection from render node.
573
- * @public
574
- */
575
- remove() {
576
- if (this.renderNode) {
577
- if (this._renderNodeIndex !== -1) {
578
- this.renderNode.entityCollections.splice(this._renderNodeIndex, 1);
579
- // reindex in the renderNode
580
- for (
581
- var i = this._renderNodeIndex;
582
- i < this.renderNode.entityCollections.length;
583
- i++
584
- ) {
585
- this.renderNode.entityCollections._renderNodeIndex = i;
586
- }
587
- }
588
- this.renderNode = null;
589
- this._renderNodeIndex = -1;
590
- this.events.dispatch(this.events.remove, this);
591
- }
592
- }
593
-
594
- /**
595
- * Gets entity array.
596
- * @public
597
- * @returns {Array.<Entity>} -
598
- */
599
- getEntities() {
600
- return [].concat(this._entities);
601
- }
602
-
603
- /**
604
- * Safety entities loop.
605
- * @public
606
- * @param {function} callback - Entity callback.
607
- */
608
- each(callback) {
609
- var i = this._entities.length;
610
- while (i--) {
611
- var ei = this._entities[i];
612
- ei && callback(ei);
613
- }
614
- }
615
-
616
- /**
617
- * Removes all entities from colection and clear handlers.
618
- * @public
619
- */
620
- clear() {
621
- // TODO: Optimize by replace delete
622
- // code to the clearEntity function.
623
- this.billboardHandler.clear();
624
- this.labelHandler.clear();
625
- this.shapeHandler.clear();
626
- this.polylineHandler.clear();
627
- this.rayHandler.clear();
628
- this.pointCloudHandler.clear();
629
- this.stripHandler.clear();
630
- this.geoObjectHandler.clear();
631
-
632
- var i = this._entities.length;
633
- while (i--) {
634
- var ei = this._entities[i];
635
- if (this.renderNode && this.renderNode.renderer) {
636
- this.renderNode.renderer.clearPickingColor(ei);
637
- ei._pickingColor.clear();
638
- }
639
- this._clearEntity(ei);
640
- }
641
- this._entities.length = 0;
642
- this._entities = [];
643
- }
644
-
645
- /**
646
- * Clears entity recursevely.
647
- * @private
648
- * @param {Entity} entity - Entity to clear.
649
- */
650
- _clearEntity(entity) {
651
- entity._entityCollection = null;
652
- entity._entityCollectionIndex = -1;
653
- for (var i = 0; i < entity.childrenNodes.length; i++) {
654
- this._clearEntity(entity.childrenNodes[i]);
655
- }
656
- }
657
- }
658
-
659
- const EVENT_NAMES = [
660
- /**
661
- * Triggered when entity has moved.
662
- * @event og.EntityCollection#entitymove
663
- */
664
- "entitymove",
665
-
666
- /**
667
- * Triggered when collection entities begin draw.
668
- * @event og.EntityCollection#draw
669
- */
670
- "draw",
671
-
672
- /**
673
- * Triggered after collection has drawn.
674
- * @event og.EntityCollection#drawend
675
- */
676
- "drawend",
677
-
678
- /**
679
- * Triggered when added to the render node.
680
- * @event og.EntityCollection#add
681
- */
682
- "add",
683
-
684
- /**
685
- * Triggered when removed from the render node.
686
- * @event og.EntityCollection#remove
687
- */
688
- "remove",
689
-
690
- /**
691
- * Triggered when new entity added to the collection.
692
- * @event og.EntityCollection#entityadd
693
- */
694
- "entityadd",
695
-
696
- /**
697
- * Triggered when entity removes from the collection.
698
- * @event og.EntityCollection#entityremove
699
- */
700
- "entityremove",
701
-
702
- /**
703
- * Triggered when visibility changes.
704
- * @event og.EntityCollection#visibilitychange
705
- */
706
- "visibilitychange",
707
-
708
- /**
709
- * Triggered when mouse moves over the entity.
710
- * @event og.EntityCollection#mousemove
711
- */
712
- "mousemove",
713
-
714
- /**
715
- * Triggered when mouse has entered over the entity.
716
- * @event og.EntityCollection#mouseenter
717
- */
718
- "mouseenter",
719
-
720
- /**
721
- * Triggered when mouse leaves the entity.
722
- * @event og.EntityCollection#mouseleave
723
- */
724
- "mouseleave",
725
-
726
- /**
727
- * Mouse left button clicked.
728
- * @event og.EntityCollection#lclick
729
- */
730
- "lclick",
731
-
732
- /**
733
- * Mouse right button clicked.
734
- * @event og.EntityCollection#rclick
735
- */
736
- "rclick",
737
-
738
- /**
739
- * Mouse right button clicked.
740
- * @event og.EntityCollection#mclick
741
- */
742
- "mclick",
743
-
744
- /**
745
- * Mouse left button double click.
746
- * @event og.EntityCollection#ldblclick
747
- */
748
- "ldblclick",
749
-
750
- /**
751
- * Mouse right button double click.
752
- * @event og.EntityCollection#rdblclick
753
- */
754
- "rdblclick",
755
-
756
- /**
757
- * Mouse middle button double click.
758
- * @event og.EntityCollection#mdblclick
759
- */
760
- "mdblclick",
761
-
762
- /**
763
- * Mouse left button up(stop pressing).
764
- * @event og.EntityCollection#lup
765
- */
766
- "lup",
767
-
768
- /**
769
- * Mouse right button up(stop pressing).
770
- * @event og.EntityCollection#rup
771
- */
772
- "rup",
773
-
774
- /**
775
- * Mouse middle button up(stop pressing).
776
- * @event og.EntityCollection#mup
777
- */
778
- "mup",
779
-
780
- /**
781
- * Mouse left button is just pressed down(start pressing).
782
- * @event og.EntityCollection#ldown
783
- */
784
- "ldown",
785
-
786
- /**
787
- * Mouse right button is just pressed down(start pressing).
788
- * @event og.EntityCollection#rdown
789
- */
790
- "rdown",
791
-
792
- /**
793
- * Mouse middle button is just pressed down(start pressing).
794
- * @event og.EntityCollection#mdown
795
- */
796
- "mdown",
797
-
798
- /**
799
- * Mouse left button is pressing.
800
- * @event og.EntityCollection#lhold
801
- */
802
- "lhold",
803
-
804
- /**
805
- * Mouse right button is pressing.
806
- * @event og.EntityCollection#rhold
807
- */
808
- "rhold",
809
-
810
- /**
811
- * Mouse middle button is pressing.
812
- * @event og.EntityCollection#mhold
813
- */
814
- "mhold",
815
-
816
- /**
817
- * Mouse wheel is rotated.
818
- * @event og.EntityCollection#mousewheel
819
- */
820
- "mousewheel",
821
-
822
- /**
823
- * Triggered when touch moves over the entity.
824
- * @event og.EntityCollection#touchmove
825
- */
826
- "touchmove",
827
-
828
- /**
829
- * Triggered when entity begins to touch.
830
- * @event og.EntityCollection#touchstart
831
- */
832
- "touchstart",
833
-
834
- /**
835
- * Triggered when entity ends touching.
836
- * @event og.EntityCollection#touchend
837
- */
838
- "touchend",
839
-
840
- /**
841
- * Triggered entity double touch.
842
- * @event og.EntityCollection#doubletouch
843
- */
844
- "doubletouch",
845
-
846
- /**
847
- * Triggered when touching leaves entity.
848
- * @event og.EntityCollection#touchleave
849
- */
850
- "touchleave",
851
-
852
- /**
853
- * Triggered when touch enters over the entity.
854
- * @event og.EntityCollection#touchenter
855
- */
856
- "touchenter"
857
- ];
858
-
859
- export { EntityCollection };
556
+ this.labelHandler.assignFontAtlas(l[i]);
557
+ }
558
+ }
559
+ }
560
+
561
+ /**
562
+ * Removes collection from render node.
563
+ * @public
564
+ */
565
+ remove() {
566
+ if (this.renderNode) {
567
+ if (this._renderNodeIndex !== -1) {
568
+ this.renderNode.entityCollections.splice(this._renderNodeIndex, 1);
569
+ // reindex in the renderNode
570
+ for (
571
+ var i = this._renderNodeIndex;
572
+ i < this.renderNode.entityCollections.length;
573
+ i++
574
+ ) {
575
+ this.renderNode.entityCollections._renderNodeIndex = i;
576
+ }
577
+ }
578
+ this.renderNode = null;
579
+ this._renderNodeIndex = -1;
580
+ this.events.dispatch(this.events.remove, this);
581
+ }
582
+ }
583
+
584
+ /**
585
+ * Gets entity array.
586
+ * @public
587
+ * @returns {Array.<Entity>} -
588
+ */
589
+ getEntities() {
590
+ return [].concat(this._entities);
591
+ }
592
+
593
+ /**
594
+ * Safety entities loop.
595
+ * @public
596
+ * @param {function} callback - Entity callback.
597
+ */
598
+ each(callback) {
599
+ var i = this._entities.length;
600
+ while (i--) {
601
+ var ei = this._entities[i];
602
+ ei && callback(ei);
603
+ }
604
+ }
605
+
606
+ /**
607
+ * Removes all entities from colection and clear handlers.
608
+ * @public
609
+ */
610
+ clear() {
611
+ // TODO: Optimize by replace delete
612
+ // code to the clearEntity function.
613
+ this.billboardHandler.clear();
614
+ this.labelHandler.clear();
615
+ this.shapeHandler.clear();
616
+ this.polylineHandler.clear();
617
+ this.rayHandler.clear();
618
+ this.pointCloudHandler.clear();
619
+ this.stripHandler.clear();
620
+ this.geoObjectHandler.clear();
621
+
622
+ var i = this._entities.length;
623
+ while (i--) {
624
+ var ei = this._entities[i];
625
+ if (this.renderNode && this.renderNode.renderer) {
626
+ this.renderNode.renderer.clearPickingColor(ei);
627
+ ei._pickingColor.clear();
628
+ }
629
+ this._clearEntity(ei);
630
+ }
631
+ this._entities.length = 0;
632
+ this._entities = [];
633
+ }
634
+
635
+ /**
636
+ * Clears entity recursevely.
637
+ * @private
638
+ * @param {Entity} entity - Entity to clear.
639
+ */
640
+ _clearEntity(entity) {
641
+ entity._entityCollection = null;
642
+ entity._entityCollectionIndex = -1;
643
+ for (var i = 0; i < entity.childrenNodes.length; i++) {
644
+ this._clearEntity(entity.childrenNodes[i]);
645
+ }
646
+ }
647
+ }
648
+
649
+ const EVENT_NAMES = [
650
+ /**
651
+ * Triggered when entity has moved.
652
+ * @event og.EntityCollection#entitymove
653
+ */
654
+ "entitymove",
655
+
656
+ /**
657
+ * Triggered when collection entities begin draw.
658
+ * @event og.EntityCollection#draw
659
+ */
660
+ "draw",
661
+
662
+ /**
663
+ * Triggered after collection has drawn.
664
+ * @event og.EntityCollection#drawend
665
+ */
666
+ "drawend",
667
+
668
+ /**
669
+ * Triggered when added to the render node.
670
+ * @event og.EntityCollection#add
671
+ */
672
+ "add",
673
+
674
+ /**
675
+ * Triggered when removed from the render node.
676
+ * @event og.EntityCollection#remove
677
+ */
678
+ "remove",
679
+
680
+ /**
681
+ * Triggered when new entity added to the collection.
682
+ * @event og.EntityCollection#entityadd
683
+ */
684
+ "entityadd",
685
+
686
+ /**
687
+ * Triggered when entity removes from the collection.
688
+ * @event og.EntityCollection#entityremove
689
+ */
690
+ "entityremove",
691
+
692
+ /**
693
+ * Triggered when visibility changes.
694
+ * @event og.EntityCollection#visibilitychange
695
+ */
696
+ "visibilitychange",
697
+
698
+ /**
699
+ * Triggered when mouse moves over the entity.
700
+ * @event og.EntityCollection#mousemove
701
+ */
702
+ "mousemove",
703
+
704
+ /**
705
+ * Triggered when mouse has entered over the entity.
706
+ * @event og.EntityCollection#mouseenter
707
+ */
708
+ "mouseenter",
709
+
710
+ /**
711
+ * Triggered when mouse leaves the entity.
712
+ * @event og.EntityCollection#mouseleave
713
+ */
714
+ "mouseleave",
715
+
716
+ /**
717
+ * Mouse left button clicked.
718
+ * @event og.EntityCollection#lclick
719
+ */
720
+ "lclick",
721
+
722
+ /**
723
+ * Mouse right button clicked.
724
+ * @event og.EntityCollection#rclick
725
+ */
726
+ "rclick",
727
+
728
+ /**
729
+ * Mouse right button clicked.
730
+ * @event og.EntityCollection#mclick
731
+ */
732
+ "mclick",
733
+
734
+ /**
735
+ * Mouse left button double click.
736
+ * @event og.EntityCollection#ldblclick
737
+ */
738
+ "ldblclick",
739
+
740
+ /**
741
+ * Mouse right button double click.
742
+ * @event og.EntityCollection#rdblclick
743
+ */
744
+ "rdblclick",
745
+
746
+ /**
747
+ * Mouse middle button double click.
748
+ * @event og.EntityCollection#mdblclick
749
+ */
750
+ "mdblclick",
751
+
752
+ /**
753
+ * Mouse left button up(stop pressing).
754
+ * @event og.EntityCollection#lup
755
+ */
756
+ "lup",
757
+
758
+ /**
759
+ * Mouse right button up(stop pressing).
760
+ * @event og.EntityCollection#rup
761
+ */
762
+ "rup",
763
+
764
+ /**
765
+ * Mouse middle button up(stop pressing).
766
+ * @event og.EntityCollection#mup
767
+ */
768
+ "mup",
769
+
770
+ /**
771
+ * Mouse left button is just pressed down(start pressing).
772
+ * @event og.EntityCollection#ldown
773
+ */
774
+ "ldown",
775
+
776
+ /**
777
+ * Mouse right button is just pressed down(start pressing).
778
+ * @event og.EntityCollection#rdown
779
+ */
780
+ "rdown",
781
+
782
+ /**
783
+ * Mouse middle button is just pressed down(start pressing).
784
+ * @event og.EntityCollection#mdown
785
+ */
786
+ "mdown",
787
+
788
+ /**
789
+ * Mouse left button is pressing.
790
+ * @event og.EntityCollection#lhold
791
+ */
792
+ "lhold",
793
+
794
+ /**
795
+ * Mouse right button is pressing.
796
+ * @event og.EntityCollection#rhold
797
+ */
798
+ "rhold",
799
+
800
+ /**
801
+ * Mouse middle button is pressing.
802
+ * @event og.EntityCollection#mhold
803
+ */
804
+ "mhold",
805
+
806
+ /**
807
+ * Mouse wheel is rotated.
808
+ * @event og.EntityCollection#mousewheel
809
+ */
810
+ "mousewheel",
811
+
812
+ /**
813
+ * Triggered when touch moves over the entity.
814
+ * @event og.EntityCollection#touchmove
815
+ */
816
+ "touchmove",
817
+
818
+ /**
819
+ * Triggered when entity begins to touch.
820
+ * @event og.EntityCollection#touchstart
821
+ */
822
+ "touchstart",
823
+
824
+ /**
825
+ * Triggered when entity ends touching.
826
+ * @event og.EntityCollection#touchend
827
+ */
828
+ "touchend",
829
+
830
+ /**
831
+ * Triggered entity double touch.
832
+ * @event og.EntityCollection#doubletouch
833
+ */
834
+ "doubletouch",
835
+
836
+ /**
837
+ * Triggered when touching leaves entity.
838
+ * @event og.EntityCollection#touchleave
839
+ */
840
+ "touchleave",
841
+
842
+ /**
843
+ * Triggered when touch enters over the entity.
844
+ * @event og.EntityCollection#touchenter
845
+ */
846
+ "touchenter"
847
+ ];
848
+
849
+ export { EntityCollection };