@openglobus/og 0.12.4 → 0.13.2

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 +887 -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 +607 -603
  56. package/src/og/shaders/label.js +576 -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,1010 +1,997 @@
1
- /**
2
- * @module og/layer/Vector
3
- */
4
-
5
- "use strict";
6
-
7
- import * as math from "../math.js";
8
- import * as mercator from "../mercator.js";
9
- import * as quadTree from "../quadTree/quadTree.js";
10
- import { Entity } from "../entity/Entity.js";
11
- import { EntityCollection } from "../entity/EntityCollection.js";
12
- import { Extent } from "../Extent.js";
13
- import {
14
- EntityCollectionNode,
15
- EntityCollectionNodeWGS84
16
- } from "../quadTree/EntityCollectionNode.js";
17
- import { GeometryHandler } from "../entity/GeometryHandler.js";
18
- import { Layer } from "./Layer.js";
19
- import { QueueArray } from "../QueueArray.js";
20
- import { Vec3 } from "../math/Vec3.js";
21
-
22
- /**
23
- * Creates entity instance array.
24
- * @param {Entity[]} entities - Entity array.
25
- * @returns {Entity[]} - Entity array.
26
- */
27
- function _entitiesConstructor(entities) {
28
- var res = [];
29
- for (var i = 0; i < entities.length; i++) {
30
- var ei = entities[i];
31
- if (ei.instanceName === "Entity") {
32
- res.push(ei);
33
- } else {
34
- res.push(new Entity(ei));
35
- }
36
- }
37
- return res;
38
- }
39
-
40
- /**
41
- * Vector layer represents alternative entities store. Used for geospatial data rendering like
42
- * points, lines, polygons, geometry objects etc.
43
- * @class
44
- * @extends {Layer}
45
- * @param {string} [name="noname"] - Layer name.
46
- * @param {Object} [options] - Layer options:
47
- * @param {number} [options.minZoom=0] - Minimal visible zoom. 0 is default
48
- * @param {number} [options.maxZoom=50] - Maximal visible zoom. 50 is default.
49
- * @param {string} [options.attribution] - Layer attribution.
50
- * @param {string} [options.zIndex=0] - Layer Z-order index. 0 is default.
51
- * @param {boolean} [options.visibility=true] - Layer visibility. True is default.
52
- * @param {boolean} [options.isBaseLayer=false] - Layer base layer. False is default.
53
- * @param {Array.<Entity>} [options.entities] - Entities array.
54
- * @param {Array.<number>} [options.scaleByDistance] - Scale by distance parameters. (exactly 3 entries)
55
- * First index - near distance to the entity, after entity becomes full scale.
56
- * Second index - far distance to the entity, when entity becomes zero scale.
57
- * Third index - far distance to the entity, when entity becomes invisible.
58
- * @param {number} [options.nodeCapacity=30] - Maximum entities quantity in the tree node. Rendering optimization parameter. 30 is default.
59
- * @param {boolean} [options.async=true] - Asynchronous vector data handling before rendering. True for optimization huge data.
60
- * @param {boolean} [options.clampToGround = false] - Clamp vector data to the ground.
61
- * @param {boolean} [options.relativeToGround = false] - Place vector data relative to the ground relief.
62
- * @param {Number} [options.polygonOffsetFactor=0.0] - The scale factor for the variable depth offset. The default value is 0.
63
- * @param {Number} [options.polygonOffsetUnits=-637000.0] - The multiplier by which an implementation-specific value is multiplied with to create a constant depth offset.
64
- *
65
- * @fires og.layer.Vector#entitymove
66
- * @fires og.layer.Vector#draw
67
- * @fires og.layer.Vector#add
68
- * @fires og.layer.Vector#remove
69
- * @fires og.layer.Vector#entityadd
70
- * @fires og.layer.Vector#entityremove
71
- * @fires og.layer.Vector#visibilitychange
72
- */
73
- class Vector extends Layer {
74
- /**
75
- * @param {string} name
76
- * @param {*} [options]
77
- */
78
- constructor(name, options = {}) {
79
- super(name, options);
80
-
81
- this.events.registerNames(EVENT_NAMES);
82
-
83
- this.isVector = true;
84
-
85
- this._hasImageryTiles = false;
86
-
87
- /**
88
- * First index - near distance to the entity, after that entity becomes full scale.
89
- * Second index - far distance to the entity, when entity becomes zero scale.
90
- * Third index - far distance to the entity, when entity becomes invisible.
91
- * @public
92
- * @type {Array.<number>} - (exactly 3 entries)
93
- */
94
- this.scaleByDistance = options.scaleByDistance || [math.MAX32, math.MAX32, math.MAX32];
95
-
96
- this.pickingScale = options.pickingScale || 1;
97
-
98
- /**
99
- * Asynchronous data handling before rendering.
100
- * @public
101
- * @type {boolean}
102
- */
103
- this.async = options.async !== undefined ? options.async : true;
104
-
105
- /**
106
- * Vector data clamp to ground flag.
107
- * @public
108
- * @type {boolean}
109
- */
110
- this.clampToGround = options.clampToGround || false;
111
-
112
- /**
113
- * Sets vector data relative to the ground relief.
114
- * @public
115
- * @type {boolean}
116
- */
117
- this.relativeToGround = options.relativeToGround || false;
118
-
119
- /**
120
- * Maximum entities quantity in the tree node.
121
- * @private
122
- */
123
- this._nodeCapacity = options.nodeCapacity || 30;
124
-
125
- /**
126
- * Stored entities.
127
- * @private
128
- */
129
- this._entities = _entitiesConstructor(options.entities || []);
130
-
131
- this._stripEntityCollection = new EntityCollection({
132
- pickingEnabled: this.pickingEnabled
133
- });
134
- this._bindEventsDefault(this._stripEntityCollection);
135
-
136
- this._polylineEntityCollection = new EntityCollection({
137
- pickingEnabled: this.pickingEnabled
138
- });
139
- this._bindEventsDefault(this._polylineEntityCollection);
140
-
141
- this._geometryHandler = new GeometryHandler(this);
142
-
143
- this._entityCollectionsTree = null;
144
- this._entityCollectionsTreeNorth = null;
145
- this._entityCollectionsTreeSouth = null;
146
-
147
- this._renderingNodes = {};
148
- this._renderingNodesNorth = {};
149
- this._renderingNodesSouth = {};
150
-
151
- this._counter = 0;
152
- this._deferredEntitiesPendingQueue = new QueueArray();
153
-
154
- this._pendingsQueue = [];
155
-
156
- // Creates collections tree
157
- this.setEntities(this._entities);
158
-
159
- /**
160
- * Specifies the scale factor for gl.polygonOffset function to calculate depth values, 0.0 is default.
161
- * @public
162
- * @type {Number}
163
- */
164
- this.polygonOffsetFactor =
165
- options.polygonOffsetFactor != undefined ? options.polygonOffsetFactor : 0.0;
166
-
167
- /**
168
- * Specifies the scale Units for gl.polygonOffset function to calculate depth values, 0.0 is default.
169
- * @public
170
- * @type {Number}
171
- */
172
- this.polygonOffsetUnits =
173
- options.polygonOffsetUnits != undefined ? options.polygonOffsetUnits : -637000.0;
174
-
175
- this.pickingEnabled = this._pickingEnabled;
176
- }
177
-
178
- get instanceName() {
179
- return "Vector";
180
- }
181
-
182
- _bindPicking() {
183
- this._pickingColor.clear();
184
- }
185
-
186
- /**
187
- * Adds layer to the planet.
188
- * @public
189
- * @param {Planet} planet - Planet scene object.
190
- * @returns {layer.Vector} -
191
- */
192
- addTo(planet) {
193
- if (!this._planet) {
194
- this._assignPlanet(planet);
195
- this._geometryHandler.assignHandler(planet.renderer.handler);
196
- this._polylineEntityCollection.addTo(planet, true);
197
- this._stripEntityCollection.addTo(planet, true);
198
- this.setEntities(this._entities);
199
- }
200
- return this;
201
- }
202
-
203
- /**
204
- * Returns stored entities.
205
- * @public
206
- * @returns {Array.<Entity>} -
207
- */
208
- getEntities() {
209
- return [].concat(this._entities);
210
- }
211
-
212
- //_fitExtent(entity) {
213
- // var ee = entity.getExtent(),
214
- // e = this._extent,
215
- // maxLon = -180, maxLat = -90,
216
- // minLon = 180, minLat = 90;
217
-
218
- // if (this._entities.length !== 0) {
219
- // maxLon = e.southWest.lon;
220
- // minLon = e.northEast.lon;
221
- // maxLat = e.northEast.lat;
222
- // minLat = e.southWest.lat;
223
- // }
224
-
225
- // if (ee.southWest.lon < minLon) {
226
- // e.southWest.lon = ee.southWest.lon;
227
- // }
228
- // if (ee.southWest.lat < minLat) {
229
- // e.southWest.lat = ee.southWest.lat;
230
- // }
231
- // if (ee.northEast.lon > maxLon) {
232
- // e.northEast.lon = ee.northEast.lon;
233
- // }
234
- // if (ee.northEast.lat > maxLat) {
235
- // e.northEast.lat = ee.northEast.lat;
236
- // }
237
- // this.setExtent(this._extent);
238
- //}
239
-
240
- /**
241
- * Adds entity to the layer.
242
- * @public
243
- * @param {Entity} entity - Entity.
244
- * @param {boolean} [rightNow] - Entity insertion option. False is deafult.
245
- * @returns {layer.Vector} - Returns this layer.
246
- */
247
- add(entity, rightNow) {
248
- if (!(entity._layer || entity._entityCollection)) {
249
- entity._layer = this;
250
- entity._layerIndex = this._entities.length;
251
- //this._fitExtent(entity);
252
- this._entities.push(entity);
253
- this._proceedEntity(entity, rightNow);
254
- }
255
- return this;
256
- }
257
-
258
- /**
259
- * Adds entity to the layer in the index position.
260
- * @public
261
- * @param {Entity} entity - Entity.
262
- * @param {Number} index - Index position.
263
- * @param {boolean} [rightNow] - Entity insertion option. False is deafult.
264
- * @returns {layer.Vector} - Returns this layer.
265
- */
266
- insert(entity, index, rightNow) {
267
- if (!(entity._layer || entity._entityCollection)) {
268
- entity._layer = this;
269
- entity._layerIndex = index;
270
- //this._fitExtent(entity);
271
- this._entities.splice(index, 0, entity);
272
- for (let i = index + 1, len = this._entities.length; i < len; i++) {
273
- this._entities[i]._layerIndex = i;
274
- }
275
-
276
- this._proceedEntity(entity, rightNow);
277
- }
278
-
279
- return this;
280
- }
281
-
282
- _proceedEntity(entity, rightNow) {
283
- let temp = this._hasImageryTiles;
284
-
285
- //
286
- // ...pointCloud, shape, model etc.
287
- //
288
-
289
- if (entity.strip) {
290
- this._stripEntityCollection.add(entity);
291
- }
292
-
293
- if (entity.polyline || entity.ray) {
294
- this._polylineEntityCollection.add(entity);
295
- }
296
-
297
- if (entity.geometry) {
298
- this._hasImageryTiles = true;
299
- if (this._planet) {
300
- this._planet.renderer.assignPickingColor(entity);
301
- this._geometryHandler.add(entity.geometry);
302
- }
303
- }
304
-
305
- if (entity.billboard || entity.label) {
306
- if (this._planet) {
307
- if (entity._cartesian.isZero() && !entity._lonlat.isZero()) {
308
- entity._setCartesian3vSilent(
309
- this._planet.ellipsoid.lonLatToCartesian(entity._lonlat)
310
- );
311
- } else {
312
- entity._lonlat = this._planet.ellipsoid.cartesianToLonLat(entity._cartesian);
313
- }
314
-
315
- // north tree
316
- if (entity._lonlat.lat > mercator.MAX_LAT) {
317
- this._entityCollectionsTreeNorth.__setLonLat__(entity);
318
- this._entityCollectionsTreeNorth.insertEntity(entity, rightNow);
319
- } else if (entity._lonlat.lat < mercator.MIN_LAT) {
320
- // south tree
321
- this._entityCollectionsTreeSouth.__setLonLat__(entity);
322
- this._entityCollectionsTreeSouth.insertEntity(entity, rightNow);
323
- } else {
324
- this._entityCollectionsTree.__setLonLat__(entity);
325
- this._entityCollectionsTree.insertEntity(entity, rightNow);
326
- }
327
- }
328
- }
329
-
330
- if (this._planet && this._hasImageryTiles !== temp) {
331
- this._planet.updateVisibleLayers();
332
- }
333
-
334
- this.events.dispatch(this.events.entityadd, entity);
335
- }
336
-
337
- /**
338
- * Adds entity array to the layer.
339
- * @public
340
- * @param {Array.<Entity>} entities - Entities array.
341
- * @param {boolean} [rightNow] - Entity insertion option. False is deafult.
342
- * @returns {layer.Vector} - Returns this layer.
343
- */
344
- addEntities(entities, rightNow) {
345
- var i = entities.length;
346
- while (i--) {
347
- this.add(entities[i], rightNow);
348
- }
349
- return this;
350
- }
351
-
352
- /**
353
- * Remove entity from layer.
354
- * TODO: memory leaks.
355
- * @public
356
- * @param {Entity} entity - Entity to remove.
357
- * @returns {layer.Vector} - Returns this layer.
358
- */
359
- removeEntity(entity) {
360
- if (entity._layer && this.isEqual(entity._layer)) {
361
- this._entities.splice(entity._layerIndex, 1);
362
- this._reindexEntitiesArray(entity._layerIndex);
363
- entity._layer = null;
364
- entity._layerIndex = -1;
365
-
366
- if (entity._entityCollection) {
367
- entity._entityCollection._removeEntitySilent(entity);
368
- let node = entity._nodePtr;
369
- while (node) {
370
- node.count--;
371
- node = node.parentNode;
372
- }
373
- if (
374
- entity._nodePtr &&
375
- entity._nodePtr.count === 0 &&
376
- entity._nodePtr.deferredEntities.length === 0
377
- ) {
378
- entity._nodePtr.entityCollection = null;
379
- //
380
- // ...
381
- //
382
- }
383
- } else if (entity._nodePtr && entity._nodePtr.deferredEntities.length) {
384
- var defEntities = entity._nodePtr.deferredEntities;
385
- var j = defEntities.length;
386
- while (j--) {
387
- if (defEntities[j].id === entity.id) {
388
- defEntities.splice(j, 1);
389
- let node = entity._nodePtr;
390
- while (node) {
391
- node.count--;
392
- node = node.parentNode;
393
- }
394
- break;
395
- }
396
- }
397
- }
398
-
399
- if (entity.geometry) {
400
- if (this._planet) {
401
- this._geometryHandler.remove(entity.geometry);
402
- this._planet.renderer.clearPickingColor(entity);
403
- }
404
- }
405
-
406
- entity._nodePtr && (entity._nodePtr = null);
407
- this.events.dispatch(this.events.entityremove, entity);
408
- }
409
- return this;
410
- }
411
-
412
- /**
413
- * Set layer picking events active.
414
- * @public
415
- * @param {boolean} picking - Picking enable flag.
416
- */
417
- set pickingEnabled(picking) {
418
- this._pickingEnabled = picking;
419
-
420
- this._stripEntityCollection.setPickingEnabled(picking);
421
-
422
- this._polylineEntityCollection.setPickingEnabled(picking);
423
-
424
- this._entityCollectionsTree &&
425
- this._entityCollectionsTree.traverseTree(function (node) {
426
- node.entityCollection.setPickingEnabled(picking);
427
- });
428
-
429
- this._entityCollectionsTreeNorth &&
430
- this._entityCollectionsTreeNorth.traverseTree(function (node) {
431
- node.entityCollection.setPickingEnabled(picking);
432
- });
433
-
434
- this._entityCollectionsTreeSouth &&
435
- this._entityCollectionsTreeSouth.traverseTree(function (node) {
436
- node.entityCollection.setPickingEnabled(picking);
437
- });
438
- }
439
-
440
- /**
441
- * Refresh collected entities indexes from startIndex entitytes collection array position.
442
- * @public
443
- * @param {number} startIndex - Entity array index.
444
- */
445
- _reindexEntitiesArray(startIndex) {
446
- var e = this._entities;
447
- for (var i = startIndex; i < e.length; i++) {
448
- e[i]._layerIndex = i;
449
- }
450
- }
451
-
452
- /**
453
- * Removes entities from layer.
454
- * @public
455
- * @param {Array.<Entity>} entities - Entity array.
456
- * @returns {layer.Vector} - Returns this layer.
457
- */
458
- removeEntities(entities) {
459
- var i = entities.length;
460
- while (i--) {
461
- this.removeEntity(entities[i]);
462
- }
463
- return this;
464
- }
465
-
466
- /**
467
- * Sets scale by distance parameters.
468
- * @public
469
- * @param {number} near - Full scale entity distance.
470
- * @param {number} far - Zerol scale entity distance.
471
- * @param {number} [farInvisible] - Entity visibility distance.
472
- * @returns {layer.Vector} -
473
- */
474
- setScaleByDistance(near, far, farInvisible) {
475
- this.scaleByDistance[0] = near;
476
- this.scaleByDistance[1] = far;
477
- this.scaleByDistance[2] = farInvisible || math.MAX32;
478
- return this;
479
- }
480
-
481
- /**
482
- * TODO: Clear the layer.
483
- * @public
484
- */
485
- clear() {
486
- let temp = new Array(this._entities.length);
487
-
488
- for (let i = 0; i < temp.length; i++) {
489
- temp[i] = this._entities[i];
490
- }
491
-
492
- let i = this._entities.length;
493
- while (i--) {
494
- this._entities[i].remove();
495
- }
496
-
497
- this._entities.length = 0;
498
- this._entities = [];
499
- for (let i = 0; i < temp.length; i++) {
500
- this._entities[i] = temp[i];
501
- }
502
-
503
- this._entityCollectionsTree = null;
504
- this._entityCollectionsTreeNorth = null;
505
- this._entityCollectionsTreeSouth = null;
506
- }
507
-
508
- /**
509
- * Safety entities loop.
510
- * @public
511
- * @param {callback} callback - Entity callback.
512
- */
513
- each(callback) {
514
- var e = this._entities;
515
- var i = e.length;
516
- while (i--) {
517
- callback(e[i], i);
518
- }
519
- }
520
-
521
- /**
522
- * Removes current entities from layer and adds new entities.
523
- * @public
524
- * @param {Array.<Entity>} entities - New entity array.
525
- * @returns {layer.Vector} - Returns layer instance.
526
- */
527
- setEntities(entities) {
528
- let temp = new Array(entities.length);
529
- for (let i = 0, len = entities.length; i < len; i++) {
530
- temp[i] = entities[i];
531
- }
532
-
533
- this.clear();
534
-
535
- //var e = this._extent;
536
-
537
- this._entities = new Array(temp.length);
538
-
539
- var entitiesForTree = [];
540
-
541
- for (var i = 0; i < temp.length; i++) {
542
- var ei = temp[i];
543
-
544
- ei._layer = this;
545
- ei._layerIndex = i;
546
-
547
- if (ei.strip) {
548
- this._stripEntityCollection.add(ei);
549
- } else if (ei.polyline || ei.ray) {
550
- this._polylineEntityCollection.add(ei);
551
- } else if (ei.billboard || ei.label || ei.shape) {
552
- entitiesForTree.push(ei);
553
- }
554
-
555
- if (ei.geometry) {
556
- this._hasImageryTiles = true;
557
- if (this._planet) {
558
- this._planet.renderer.assignPickingColor(ei);
559
- this._geometryHandler.add(ei.geometry);
560
- }
561
- }
562
-
563
- this._entities[i] = ei;
564
-
565
- //var ext = ei.getExtent();
566
- //if (ext.northEast.lon > e.northEast.lon) e.northEast.lon = ext.northEast.lon;
567
- //if (ext.northEast.lat > e.northEast.lat) e.northEast.lat = ext.northEast.lat;
568
- //if (ext.southWest.lon < e.southWest.lon) e.southWest.lon = ext.southWest.lon;
569
- //if (ext.southWest.lat < e.southWest.lat) e.southWest.lat = ext.southWest.lat;
570
- }
571
-
572
- this._createEntityCollectionsTree(entitiesForTree);
573
-
574
- return this;
575
- }
576
-
577
- _createEntityCollectionsTree(entitiesForTree) {
578
- if (this._planet) {
579
- this._entityCollectionsTree = new EntityCollectionNode(
580
- this,
581
- quadTree.NW,
582
- null,
583
- 0,
584
- Extent.createFromArray([-20037508.34, -20037508.34, 20037508.34, 20037508.34]),
585
- this._planet,
586
- 0
587
- );
588
- this._entityCollectionsTreeNorth = new EntityCollectionNodeWGS84(
589
- this,
590
- quadTree.NW,
591
- null,
592
- 0,
593
- Extent.createFromArray([-180, mercator.MAX_LAT, 180, 90]),
594
- this._planet,
595
- 0
596
- );
597
- this._entityCollectionsTreeSouth = new EntityCollectionNodeWGS84(
598
- this,
599
- quadTree.NW,
600
- null,
601
- 0,
602
- Extent.createFromArray([-180, -90, 180, mercator.MIN_LAT]),
603
- this._planet,
604
- 0
605
- );
606
-
607
- for (let i = 0, len = entitiesForTree.length; i < len; i++) {
608
- let entity = entitiesForTree[i];
609
- // north tree
610
- if (entity._lonlat.lat > mercator.MAX_LAT) {
611
- this._entityCollectionsTreeNorth.__setLonLat__(entity);
612
- } else if (entity._lonlat.lat < mercator.MIN_LAT) {
613
- // south tree
614
- this._entityCollectionsTreeSouth.__setLonLat__(entity);
615
- } else {
616
- this._entityCollectionsTree.__setLonLat__(entity);
617
- }
618
- }
619
-
620
- this._entityCollectionsTree.buildTree(entitiesForTree);
621
- this._entityCollectionsTreeNorth.buildTree(entitiesForTree);
622
- this._entityCollectionsTreeSouth.buildTree(entitiesForTree);
623
- }
624
- }
625
-
626
- _bindEventsDefault(entityCollection) {
627
- var ve = this.events;
628
- entityCollection.events.on("entitymove", function (e) {
629
- ve.dispatch(ve.entitymove, e);
630
- });
631
- entityCollection.events.on("mousemove", function (e) {
632
- ve.dispatch(ve.mousemove, e);
633
- });
634
- entityCollection.events.on("mouseenter", function (e) {
635
- ve.dispatch(ve.mouseenter, e);
636
- });
637
- entityCollection.events.on("mouseleave", function (e) {
638
- ve.dispatch(ve.mouseleave, e);
639
- });
640
- entityCollection.events.on("lclick", function (e) {
641
- ve.dispatch(ve.lclick, e);
642
- });
643
- entityCollection.events.on("rclick", function (e) {
644
- ve.dispatch(ve.rclick, e);
645
- });
646
- entityCollection.events.on("mclick", function (e) {
647
- ve.dispatch(ve.mclick, e);
648
- });
649
- entityCollection.events.on("ldblclick", function (e) {
650
- ve.dispatch(ve.ldblclick, e);
651
- });
652
- entityCollection.events.on("rdblclick", function (e) {
653
- ve.dispatch(ve.rdblclick, e);
654
- });
655
- entityCollection.events.on("mdblclick", function (e) {
656
- ve.dispatch(ve.mdblclick, e);
657
- });
658
- entityCollection.events.on("lup", function (e) {
659
- ve.dispatch(ve.lup, e);
660
- });
661
- entityCollection.events.on("rup", function (e) {
662
- ve.dispatch(ve.rup, e);
663
- });
664
- entityCollection.events.on("mup", function (e) {
665
- ve.dispatch(ve.mup, e);
666
- });
667
- entityCollection.events.on("ldown", function (e) {
668
- ve.dispatch(ve.ldown, e);
669
- });
670
- entityCollection.events.on("rdown", function (e) {
671
- ve.dispatch(ve.rdown, e);
672
- });
673
- entityCollection.events.on("mdown", function (e) {
674
- ve.dispatch(ve.mdown, e);
675
- });
676
- entityCollection.events.on("lhold", function (e) {
677
- ve.dispatch(ve.lhold, e);
678
- });
679
- entityCollection.events.on("rhold", function (e) {
680
- ve.dispatch(ve.rhold, e);
681
- });
682
- entityCollection.events.on("mhold", function (e) {
683
- ve.dispatch(ve.mhold, e);
684
- });
685
- entityCollection.events.on("mousewheel", function (e) {
686
- ve.dispatch(ve.mousewheel, e);
687
- });
688
- entityCollection.events.on("touchmove", function (e) {
689
- ve.dispatch(ve.touchmove, e);
690
- });
691
- entityCollection.events.on("touchstart", function (e) {
692
- ve.dispatch(ve.touchstart, e);
693
- });
694
- entityCollection.events.on("touchend", function (e) {
695
- ve.dispatch(ve.touchend, e);
696
- });
697
- entityCollection.events.on("doubletouch", function (e) {
698
- ve.dispatch(ve.doubletouch, e);
699
- });
700
- entityCollection.events.on("touchleave", function (e) {
701
- ve.dispatch(ve.touchleave, e);
702
- });
703
- entityCollection.events.on("touchenter", function (e) {
704
- ve.dispatch(ve.touchenter, e);
705
- });
706
- }
707
-
708
- _collectStripCollectionPASS(outArr) {
709
- var ec = this._stripEntityCollection;
710
-
711
- ec._fadingOpacity = this._fadingOpacity;
712
- ec.scaleByDistance = this.scaleByDistance;
713
- ec.pickingScale = this.pickingScale;
714
-
715
- ec.polygonOffsetFactor = this.polygonOffsetFactor;
716
- ec.polygonOffsetUnits = this.polygonOffsetUnits;
717
-
718
- outArr.push(ec);
719
- //
720
- // ...TODO: extent
721
- //
722
- }
723
-
724
- _collectPolylineCollectionPASS(outArr) {
725
- var ec = this._polylineEntityCollection;
726
-
727
- ec._fadingOpacity = this._fadingOpacity;
728
- ec.scaleByDistance = this.scaleByDistance;
729
- ec.pickingScale = this.pickingScale;
730
-
731
- ec.polygonOffsetFactor = this.polygonOffsetFactor;
732
- ec.polygonOffsetUnits = this.polygonOffsetUnits;
733
-
734
- outArr.push(ec);
735
-
736
- if (this.clampToGround || this.relativeToGround) {
737
- let rtg = Number(this.relativeToGround);
738
-
739
- var nodes = this._planet._renderedNodes;
740
- var visibleExtent = this._planet.getViewExtent();
741
- var e = ec._entities;
742
- var e_i = e.length;
743
- let res = new Vec3();
744
-
745
- while (e_i--) {
746
- var p = e[e_i].polyline;
747
- if (visibleExtent.overlaps(p._extent)) {
748
- // TODO:this works only for mercator area.
749
- // needs to be working on poles.
750
- let coords = p._pathLonLatMerc,
751
- c_j = coords.length;
752
- while (c_j--) {
753
- var c_j_h = coords[c_j].length;
754
- while (c_j_h--) {
755
- let ll = coords[c_j][c_j_h],
756
- n_k = nodes.length;
757
- while (n_k--) {
758
- var seg = nodes[n_k].segment;
759
- if (seg._extent.isInside(ll)) {
760
- let cart = p._path3v[c_j][c_j_h];
761
- seg.getTerrainPoint(cart, ll, res);
762
- p.setPoint3v(
763
- res.addA(res.normal().scale((rtg && p.altitude) || 0.0)),
764
- c_j_h,
765
- c_j,
766
- true
767
- );
768
- break;
769
- }
770
- }
771
- }
772
- }
773
- }
774
- }
775
- }
776
- }
777
-
778
- collectVisibleCollections(outArr) {
779
- var p = this._planet;
780
-
781
- if (
782
- (this._fading && this._fadingOpacity > 0.0) ||
783
- (this.minZoom <= this._planet.maxCurrZoom && this.maxZoom >= p.maxCurrZoom)
784
- ) {
785
- this._renderingNodes = {};
786
- this._renderingNodesNorth = {};
787
- this._renderingNodesSouth = {};
788
-
789
- // Common collections first
790
- this._collectStripCollectionPASS(outArr);
791
-
792
- this._collectPolylineCollectionPASS(outArr);
793
-
794
- // Merc nodes
795
- this._secondPASS = [];
796
- this._entityCollectionsTree.collectRenderCollectionsPASS1(p._visibleNodes, outArr);
797
- var i = this._secondPASS.length;
798
- while (i--) {
799
- this._secondPASS[i].collectRenderCollectionsPASS2(
800
- p._visibleNodes,
801
- outArr,
802
- this._secondPASS[i].nodeId
803
- );
804
- }
805
-
806
- // North nodes
807
- this._secondPASS = [];
808
- this._entityCollectionsTreeNorth.collectRenderCollectionsPASS1(
809
- p._visibleNodesNorth,
810
- outArr
811
- );
812
- i = this._secondPASS.length;
813
- while (i--) {
814
- this._secondPASS[i].collectRenderCollectionsPASS2(
815
- p._visibleNodesNorth,
816
- outArr,
817
- this._secondPASS[i].nodeId
818
- );
819
- }
820
-
821
- // South nodes
822
- this._secondPASS = [];
823
- this._entityCollectionsTreeSouth.collectRenderCollectionsPASS1(
824
- p._visibleNodesSouth,
825
- outArr
826
- );
827
- i = this._secondPASS.length;
828
- while (i--) {
829
- this._secondPASS[i].collectRenderCollectionsPASS2(
830
- p._visibleNodesSouth,
831
- outArr,
832
- this._secondPASS[i].nodeId
833
- );
834
- }
835
- }
836
- }
837
-
838
- _queueDeferredNode(node) {
839
- if (this._visibility) {
840
- node._inTheQueue = true;
841
- if (this._counter >= 1) {
842
- this._deferredEntitiesPendingQueue.push(node);
843
- } else {
844
- this._execDeferredNode(node);
845
- }
846
- }
847
- }
848
-
849
- _execDeferredNode(node) {
850
- this._counter++;
851
- var that = this;
852
- setTimeout(function () {
853
- node.applyCollection();
854
- that._counter--;
855
- if (that._deferredEntitiesPendingQueue.length && that._counter < 1) {
856
- while (that._deferredEntitiesPendingQueue.length) {
857
- var n = that._deferredEntitiesPendingQueue.pop();
858
- n._inTheQueue = false;
859
- if (n.isVisible()) {
860
- that._execDeferredNode(n);
861
- return;
862
- }
863
- }
864
- }
865
- }, 0);
866
- }
867
-
868
- /**
869
- * Start to load tile material.
870
- * @public
871
- * @virtual
872
- * @param {Segment.Material} material - Current material.
873
- */
874
- loadMaterial(material) {
875
- var seg = material.segment;
876
-
877
- if (this._isBaseLayer) {
878
- material.texture = seg._isNorth
879
- ? seg.planet.solidTextureOne
880
- : seg.planet.solidTextureTwo;
881
- } else {
882
- material.texture = seg.planet.transparentTexture;
883
- }
884
-
885
- if (this._planet.layerLock.isFree()) {
886
- material.isReady = false;
887
- material.isLoading = true;
888
- this._planet._vectorTileCreator.add(material);
889
- }
890
- }
891
-
892
- /**
893
- * Abort exact material loading.
894
- * @public
895
- * @param {Material} material - Segment material.
896
- */
897
- abortMaterialLoading(material) {
898
- material.isLoading = false;
899
- material.isReady = false;
900
- }
901
-
902
- applyMaterial(material) {
903
- if (material.isReady) {
904
- return [0, 0, 1, 1];
905
- } else {
906
- !material.isLoading && this.loadMaterial(material);
907
-
908
- var segment = material.segment;
909
- var pn = segment.node,
910
- notEmpty = false;
911
-
912
- var mId = this._id;
913
- var psegm = material;
914
-
915
- while (pn.parentNode) {
916
- if (psegm && psegm.isReady) {
917
- notEmpty = true;
918
- break;
919
- }
920
- pn = pn.parentNode;
921
- psegm = pn.segment.materials[mId];
922
- }
923
-
924
- if (notEmpty) {
925
- material.appliedNodeId = pn.nodeId;
926
- material.texture = psegm.texture;
927
- material.pickingMask = psegm.pickingMask;
928
- var dZ2 = 1.0 / (2 << (segment.tileZoom - pn.segment.tileZoom - 1));
929
- return [
930
- segment.tileX * dZ2 - pn.segment.tileX,
931
- segment.tileY * dZ2 - pn.segment.tileY,
932
- dZ2,
933
- dZ2
934
- ];
935
- } else {
936
- if (material.textureExists && material._updateTexture) {
937
- material.texture = material._updateTexture;
938
- material.pickingMask = material._updatePickingMask;
939
- } else {
940
- material.texture = segment.planet.transparentTexture;
941
- material.pickingMask = segment.planet.transparentTexture;
942
- }
943
- return [0, 0, 1, 1];
944
- }
945
- }
946
- }
947
-
948
- clearMaterial(material) {
949
- if (material.isReady) {
950
- var gl = material.segment.handler.gl;
951
-
952
- material.isReady = false;
953
- material.pickingReady = false;
954
-
955
- var t = material.texture;
956
- material.texture = null;
957
- t && !t.default && gl.deleteTexture(t);
958
-
959
- t = material.pickingMask;
960
- material.pickingMask = null;
961
- t && !t.default && gl.deleteTexture(t);
962
-
963
- t = material._updateTexture;
964
- material._updateTexture = null;
965
- t && !t.default && gl.deleteTexture(t);
966
-
967
- t = material._updatePickingMask;
968
- material._updatePickingMask = null;
969
- t && !t.default && gl.deleteTexture(t);
970
- }
971
-
972
- this.abortMaterialLoading(material);
973
-
974
- material.isLoading = false;
975
- material.textureExists = false;
976
- }
977
-
978
- update() {
979
- this._geometryHandler.update();
980
- this.events.dispatch(this.events.draw, this);
981
- }
982
- }
983
-
984
- const EVENT_NAMES = [
985
- /**
986
- * Triggered when entity has moved.
987
- * @event og.layer.Vector#draw
988
- */
989
- "entitymove",
990
-
991
- /**
992
- * Triggered when layer begin draw.
993
- * @event og.layer.Vector#draw
994
- */
995
- "draw",
996
-
997
- /**
998
- * Triggered when new entity added to the layer.
999
- * @event og.layer.Vector#entityadd
1000
- */
1001
- "entityadd",
1002
-
1003
- /**
1004
- * Triggered when entity removes from the collection.
1005
- * @event og.layer.Vector#entityremove
1006
- */
1007
- "entityremove"
1008
- ];
1009
-
1010
- export { Vector };
1
+ /**
2
+ * @module og/layer/Vector
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import * as math from "../math.js";
8
+ import * as mercator from "../mercator.js";
9
+ import * as quadTree from "../quadTree/quadTree.js";
10
+ import { Entity } from "../entity/Entity.js";
11
+ import { EntityCollection } from "../entity/EntityCollection.js";
12
+ import { Extent } from "../Extent.js";
13
+ import {
14
+ EntityCollectionNode,
15
+ EntityCollectionNodeWGS84
16
+ } from "../quadTree/EntityCollectionNode.js";
17
+ import { GeometryHandler } from "../entity/GeometryHandler.js";
18
+ import { Layer } from "./Layer.js";
19
+ import { QueueArray } from "../QueueArray.js";
20
+ import { Vec3 } from "../math/Vec3.js";
21
+
22
+ /**
23
+ * Creates entity instance array.
24
+ * @param {Entity[]} entities - Entity array.
25
+ * @returns {Entity[]} - Entity array.
26
+ */
27
+ function _entitiesConstructor(entities) {
28
+ var res = [];
29
+ for (var i = 0; i < entities.length; i++) {
30
+ var ei = entities[i];
31
+ if (ei.instanceName === "Entity") {
32
+ res.push(ei);
33
+ } else {
34
+ res.push(new Entity(ei));
35
+ }
36
+ }
37
+ return res;
38
+ }
39
+
40
+ /**
41
+ * Vector layer represents alternative entities store. Used for geospatial data rendering like
42
+ * points, lines, polygons, geometry objects etc.
43
+ * @class
44
+ * @extends {Layer}
45
+ * @param {string} [name="noname"] - Layer name.
46
+ * @param {Object} [options] - Layer options:
47
+ * @param {number} [options.minZoom=0] - Minimal visible zoom. 0 is default
48
+ * @param {number} [options.maxZoom=50] - Maximal visible zoom. 50 is default.
49
+ * @param {string} [options.attribution] - Layer attribution.
50
+ * @param {string} [options.zIndex=0] - Layer Z-order index. 0 is default.
51
+ * @param {boolean} [options.visibility=true] - Layer visibility. True is default.
52
+ * @param {boolean} [options.isBaseLayer=false] - Layer base layer. False is default.
53
+ * @param {Array.<Entity>} [options.entities] - Entities array.
54
+ * @param {Array.<number>} [options.scaleByDistance] - Scale by distance parameters. (exactly 3 entries)
55
+ * First index - near distance to the entity, after entity becomes full scale.
56
+ * Second index - far distance to the entity, when entity becomes zero scale.
57
+ * Third index - far distance to the entity, when entity becomes invisible.
58
+ * @param {number} [options.nodeCapacity=30] - Maximum entities quantity in the tree node. Rendering optimization parameter. 30 is default.
59
+ * @param {boolean} [options.async=true] - Asynchronous vector data handling before rendering. True for optimization huge data.
60
+ * @param {boolean} [options.clampToGround = false] - Clamp vector data to the ground.
61
+ * @param {boolean} [options.relativeToGround = false] - Place vector data relative to the ground relief.
62
+ * @param {Number} [options.polygonOffsetUnits=0.0] - The multiplier by which an implementation-specific value is multiplied with to create a constant depth offset.
63
+ *
64
+ * @fires og.layer.Vector#entitymove
65
+ * @fires og.layer.Vector#draw
66
+ * @fires og.layer.Vector#add
67
+ * @fires og.layer.Vector#remove
68
+ * @fires og.layer.Vector#entityadd
69
+ * @fires og.layer.Vector#entityremove
70
+ * @fires og.layer.Vector#visibilitychange
71
+ */
72
+ class Vector extends Layer {
73
+ /**
74
+ * @param {string} name
75
+ * @param {*} [options]
76
+ */
77
+ constructor(name, options = {}) {
78
+ super(name, options);
79
+
80
+ this.events.registerNames(EVENT_NAMES);
81
+
82
+ this.isVector = true;
83
+
84
+ this._hasImageryTiles = false;
85
+
86
+ /**
87
+ * First index - near distance to the entity, after that entity becomes full scale.
88
+ * Second index - far distance to the entity, when entity becomes zero scale.
89
+ * Third index - far distance to the entity, when entity becomes invisible.
90
+ * @public
91
+ * @type {Array.<number>} - (exactly 3 entries)
92
+ */
93
+ this.scaleByDistance = options.scaleByDistance || [math.MAX32, math.MAX32, math.MAX32];
94
+
95
+ this.pickingScale = options.pickingScale || 1;
96
+
97
+ /**
98
+ * Asynchronous data handling before rendering.
99
+ * @public
100
+ * @type {boolean}
101
+ */
102
+ this.async = options.async !== undefined ? options.async : true;
103
+
104
+ /**
105
+ * Vector data clamp to ground flag.
106
+ * @public
107
+ * @type {boolean}
108
+ */
109
+ this.clampToGround = options.clampToGround || false;
110
+
111
+ /**
112
+ * Sets vector data relative to the ground relief.
113
+ * @public
114
+ * @type {boolean}
115
+ */
116
+ this.relativeToGround = options.relativeToGround || false;
117
+
118
+ /**
119
+ * Maximum entities quantity in the tree node.
120
+ * @private
121
+ */
122
+ this._nodeCapacity = options.nodeCapacity || 30;
123
+
124
+ /**
125
+ * Stored entities.
126
+ * @private
127
+ */
128
+ this._entities = _entitiesConstructor(options.entities || []);
129
+
130
+ this._stripEntityCollection = new EntityCollection({
131
+ pickingEnabled: this.pickingEnabled
132
+ });
133
+ this._bindEventsDefault(this._stripEntityCollection);
134
+
135
+ this._polylineEntityCollection = new EntityCollection({
136
+ pickingEnabled: this.pickingEnabled
137
+ });
138
+ this._bindEventsDefault(this._polylineEntityCollection);
139
+
140
+ this._geometryHandler = new GeometryHandler(this);
141
+
142
+ this._entityCollectionsTree = null;
143
+ this._entityCollectionsTreeNorth = null;
144
+ this._entityCollectionsTreeSouth = null;
145
+
146
+ this._renderingNodes = {};
147
+ this._renderingNodesNorth = {};
148
+ this._renderingNodesSouth = {};
149
+
150
+ this._counter = 0;
151
+ this._deferredEntitiesPendingQueue = new QueueArray();
152
+
153
+ this._pendingsQueue = [];
154
+
155
+ // Creates collections tree
156
+ this.setEntities(this._entities);
157
+
158
+ /**
159
+ * Specifies the scale Units for gl.polygonOffset function to calculate depth values, 0.0 is default.
160
+ * @public
161
+ * @type {Number}
162
+ */
163
+ this.polygonOffsetUnits =
164
+ options.polygonOffsetUnits != undefined ? options.polygonOffsetUnits : 0.0;
165
+
166
+ this.pickingEnabled = this._pickingEnabled;
167
+ }
168
+
169
+ get instanceName() {
170
+ return "Vector";
171
+ }
172
+
173
+ _bindPicking() {
174
+ this._pickingColor.clear();
175
+ }
176
+
177
+ /**
178
+ * Adds layer to the planet.
179
+ * @public
180
+ * @param {Planet} planet - Planet scene object.
181
+ * @returns {layer.Vector} -
182
+ */
183
+ addTo(planet) {
184
+ if (!this._planet) {
185
+ this._assignPlanet(planet);
186
+ this._geometryHandler.assignHandler(planet.renderer.handler);
187
+ this._polylineEntityCollection.addTo(planet, true);
188
+ this._stripEntityCollection.addTo(planet, true);
189
+ this.setEntities(this._entities);
190
+ }
191
+ return this;
192
+ }
193
+
194
+ /**
195
+ * Returns stored entities.
196
+ * @public
197
+ * @returns {Array.<Entity>} -
198
+ */
199
+ getEntities() {
200
+ return [].concat(this._entities);
201
+ }
202
+
203
+ //_fitExtent(entity) {
204
+ // var ee = entity.getExtent(),
205
+ // e = this._extent,
206
+ // maxLon = -180, maxLat = -90,
207
+ // minLon = 180, minLat = 90;
208
+
209
+ // if (this._entities.length !== 0) {
210
+ // maxLon = e.southWest.lon;
211
+ // minLon = e.northEast.lon;
212
+ // maxLat = e.northEast.lat;
213
+ // minLat = e.southWest.lat;
214
+ // }
215
+
216
+ // if (ee.southWest.lon < minLon) {
217
+ // e.southWest.lon = ee.southWest.lon;
218
+ // }
219
+ // if (ee.southWest.lat < minLat) {
220
+ // e.southWest.lat = ee.southWest.lat;
221
+ // }
222
+ // if (ee.northEast.lon > maxLon) {
223
+ // e.northEast.lon = ee.northEast.lon;
224
+ // }
225
+ // if (ee.northEast.lat > maxLat) {
226
+ // e.northEast.lat = ee.northEast.lat;
227
+ // }
228
+ // this.setExtent(this._extent);
229
+ //}
230
+
231
+ /**
232
+ * Adds entity to the layer.
233
+ * @public
234
+ * @param {Entity} entity - Entity.
235
+ * @param {boolean} [rightNow] - Entity insertion option. False is deafult.
236
+ * @returns {layer.Vector} - Returns this layer.
237
+ */
238
+ add(entity, rightNow) {
239
+ if (!(entity._layer || entity._entityCollection)) {
240
+ entity._layer = this;
241
+ entity._layerIndex = this._entities.length;
242
+ //this._fitExtent(entity);
243
+ this._entities.push(entity);
244
+ this._proceedEntity(entity, rightNow);
245
+ }
246
+ return this;
247
+ }
248
+
249
+ /**
250
+ * Adds entity to the layer in the index position.
251
+ * @public
252
+ * @param {Entity} entity - Entity.
253
+ * @param {Number} index - Index position.
254
+ * @param {boolean} [rightNow] - Entity insertion option. False is deafult.
255
+ * @returns {layer.Vector} - Returns this layer.
256
+ */
257
+ insert(entity, index, rightNow) {
258
+ if (!(entity._layer || entity._entityCollection)) {
259
+ entity._layer = this;
260
+ entity._layerIndex = index;
261
+ //this._fitExtent(entity);
262
+ this._entities.splice(index, 0, entity);
263
+ for (let i = index + 1, len = this._entities.length; i < len; i++) {
264
+ this._entities[i]._layerIndex = i;
265
+ }
266
+
267
+ this._proceedEntity(entity, rightNow);
268
+ }
269
+
270
+ return this;
271
+ }
272
+
273
+ _proceedEntity(entity, rightNow) {
274
+ let temp = this._hasImageryTiles;
275
+
276
+ //
277
+ // ...pointCloud, shape, model etc.
278
+ //
279
+
280
+ if (entity.strip) {
281
+ this._stripEntityCollection.add(entity);
282
+ }
283
+
284
+ if (entity.polyline || entity.ray) {
285
+ this._polylineEntityCollection.add(entity);
286
+ }
287
+
288
+ if (entity.geometry) {
289
+ this._hasImageryTiles = true;
290
+ if (this._planet) {
291
+ this._planet.renderer.assignPickingColor(entity);
292
+ this._geometryHandler.add(entity.geometry);
293
+ }
294
+ }
295
+
296
+ if (entity.billboard || entity.label) {
297
+ if (this._planet) {
298
+ if (entity._cartesian.isZero() && !entity._lonlat.isZero()) {
299
+ entity._setCartesian3vSilent(
300
+ this._planet.ellipsoid.lonLatToCartesian(entity._lonlat)
301
+ );
302
+ } else {
303
+ entity._lonlat = this._planet.ellipsoid.cartesianToLonLat(entity._cartesian);
304
+ }
305
+
306
+ // north tree
307
+ if (entity._lonlat.lat > mercator.MAX_LAT) {
308
+ this._entityCollectionsTreeNorth.__setLonLat__(entity);
309
+ this._entityCollectionsTreeNorth.insertEntity(entity, rightNow);
310
+ } else if (entity._lonlat.lat < mercator.MIN_LAT) {
311
+ // south tree
312
+ this._entityCollectionsTreeSouth.__setLonLat__(entity);
313
+ this._entityCollectionsTreeSouth.insertEntity(entity, rightNow);
314
+ } else {
315
+ this._entityCollectionsTree.__setLonLat__(entity);
316
+ this._entityCollectionsTree.insertEntity(entity, rightNow);
317
+ }
318
+ }
319
+ }
320
+
321
+ if (this._planet && this._hasImageryTiles !== temp) {
322
+ this._planet.updateVisibleLayers();
323
+ }
324
+
325
+ this.events.dispatch(this.events.entityadd, entity);
326
+ }
327
+
328
+ /**
329
+ * Adds entity array to the layer.
330
+ * @public
331
+ * @param {Array.<Entity>} entities - Entities array.
332
+ * @param {boolean} [rightNow] - Entity insertion option. False is deafult.
333
+ * @returns {layer.Vector} - Returns this layer.
334
+ */
335
+ addEntities(entities, rightNow) {
336
+ var i = entities.length;
337
+ while (i--) {
338
+ this.add(entities[i], rightNow);
339
+ }
340
+ return this;
341
+ }
342
+
343
+ /**
344
+ * Remove entity from layer.
345
+ * TODO: memory leaks.
346
+ * @public
347
+ * @param {Entity} entity - Entity to remove.
348
+ * @returns {layer.Vector} - Returns this layer.
349
+ */
350
+ removeEntity(entity) {
351
+ if (entity._layer && this.isEqual(entity._layer)) {
352
+ this._entities.splice(entity._layerIndex, 1);
353
+ this._reindexEntitiesArray(entity._layerIndex);
354
+ entity._layer = null;
355
+ entity._layerIndex = -1;
356
+
357
+ if (entity._entityCollection) {
358
+ entity._entityCollection._removeEntitySilent(entity);
359
+ let node = entity._nodePtr;
360
+ while (node) {
361
+ node.count--;
362
+ node = node.parentNode;
363
+ }
364
+ if (
365
+ entity._nodePtr &&
366
+ entity._nodePtr.count === 0 &&
367
+ entity._nodePtr.deferredEntities.length === 0
368
+ ) {
369
+ entity._nodePtr.entityCollection = null;
370
+ //
371
+ // ...
372
+ //
373
+ }
374
+ } else if (entity._nodePtr && entity._nodePtr.deferredEntities.length) {
375
+ var defEntities = entity._nodePtr.deferredEntities;
376
+ var j = defEntities.length;
377
+ while (j--) {
378
+ if (defEntities[j].id === entity.id) {
379
+ defEntities.splice(j, 1);
380
+ let node = entity._nodePtr;
381
+ while (node) {
382
+ node.count--;
383
+ node = node.parentNode;
384
+ }
385
+ break;
386
+ }
387
+ }
388
+ }
389
+
390
+ if (entity.geometry) {
391
+ if (this._planet) {
392
+ this._geometryHandler.remove(entity.geometry);
393
+ this._planet.renderer.clearPickingColor(entity);
394
+ }
395
+ }
396
+
397
+ entity._nodePtr && (entity._nodePtr = null);
398
+ this.events.dispatch(this.events.entityremove, entity);
399
+ }
400
+ return this;
401
+ }
402
+
403
+ /**
404
+ * Set layer picking events active.
405
+ * @public
406
+ * @param {boolean} picking - Picking enable flag.
407
+ */
408
+ set pickingEnabled(picking) {
409
+ this._pickingEnabled = picking;
410
+
411
+ this._stripEntityCollection.setPickingEnabled(picking);
412
+
413
+ this._polylineEntityCollection.setPickingEnabled(picking);
414
+
415
+ this._entityCollectionsTree &&
416
+ this._entityCollectionsTree.traverseTree(function (node) {
417
+ node.entityCollection.setPickingEnabled(picking);
418
+ });
419
+
420
+ this._entityCollectionsTreeNorth &&
421
+ this._entityCollectionsTreeNorth.traverseTree(function (node) {
422
+ node.entityCollection.setPickingEnabled(picking);
423
+ });
424
+
425
+ this._entityCollectionsTreeSouth &&
426
+ this._entityCollectionsTreeSouth.traverseTree(function (node) {
427
+ node.entityCollection.setPickingEnabled(picking);
428
+ });
429
+ }
430
+
431
+ /**
432
+ * Refresh collected entities indexes from startIndex entitytes collection array position.
433
+ * @public
434
+ * @param {number} startIndex - Entity array index.
435
+ */
436
+ _reindexEntitiesArray(startIndex) {
437
+ var e = this._entities;
438
+ for (var i = startIndex; i < e.length; i++) {
439
+ e[i]._layerIndex = i;
440
+ }
441
+ }
442
+
443
+ /**
444
+ * Removes entities from layer.
445
+ * @public
446
+ * @param {Array.<Entity>} entities - Entity array.
447
+ * @returns {layer.Vector} - Returns this layer.
448
+ */
449
+ removeEntities(entities) {
450
+ var i = entities.length;
451
+ while (i--) {
452
+ this.removeEntity(entities[i]);
453
+ }
454
+ return this;
455
+ }
456
+
457
+ /**
458
+ * Sets scale by distance parameters.
459
+ * @public
460
+ * @param {number} near - Full scale entity distance.
461
+ * @param {number} far - Zerol scale entity distance.
462
+ * @param {number} [farInvisible] - Entity visibility distance.
463
+ * @returns {layer.Vector} -
464
+ */
465
+ setScaleByDistance(near, far, farInvisible) {
466
+ this.scaleByDistance[0] = near;
467
+ this.scaleByDistance[1] = far;
468
+ this.scaleByDistance[2] = farInvisible || math.MAX32;
469
+ return this;
470
+ }
471
+
472
+ /**
473
+ * TODO: Clear the layer.
474
+ * @public
475
+ */
476
+ clear() {
477
+ let temp = new Array(this._entities.length);
478
+
479
+ for (let i = 0; i < temp.length; i++) {
480
+ temp[i] = this._entities[i];
481
+ }
482
+
483
+ let i = this._entities.length;
484
+ while (i--) {
485
+ this._entities[i].remove();
486
+ }
487
+
488
+ this._entities.length = 0;
489
+ this._entities = [];
490
+ for (let i = 0; i < temp.length; i++) {
491
+ this._entities[i] = temp[i];
492
+ }
493
+
494
+ this._entityCollectionsTree = null;
495
+ this._entityCollectionsTreeNorth = null;
496
+ this._entityCollectionsTreeSouth = null;
497
+ }
498
+
499
+ /**
500
+ * Safety entities loop.
501
+ * @public
502
+ * @param {callback} callback - Entity callback.
503
+ */
504
+ each(callback) {
505
+ var e = this._entities;
506
+ var i = e.length;
507
+ while (i--) {
508
+ callback(e[i], i);
509
+ }
510
+ }
511
+
512
+ /**
513
+ * Removes current entities from layer and adds new entities.
514
+ * @public
515
+ * @param {Array.<Entity>} entities - New entity array.
516
+ * @returns {layer.Vector} - Returns layer instance.
517
+ */
518
+ setEntities(entities) {
519
+ let temp = new Array(entities.length);
520
+ for (let i = 0, len = entities.length; i < len; i++) {
521
+ temp[i] = entities[i];
522
+ }
523
+
524
+ this.clear();
525
+
526
+ //var e = this._extent;
527
+
528
+ this._entities = new Array(temp.length);
529
+
530
+ var entitiesForTree = [];
531
+
532
+ for (var i = 0; i < temp.length; i++) {
533
+ var ei = temp[i];
534
+
535
+ ei._layer = this;
536
+ ei._layerIndex = i;
537
+
538
+ if (ei.strip) {
539
+ this._stripEntityCollection.add(ei);
540
+ } else if (ei.polyline || ei.ray) {
541
+ this._polylineEntityCollection.add(ei);
542
+ } else if (ei.billboard || ei.label || ei.shape) {
543
+ entitiesForTree.push(ei);
544
+ }
545
+
546
+ if (ei.geometry) {
547
+ this._hasImageryTiles = true;
548
+ if (this._planet) {
549
+ this._planet.renderer.assignPickingColor(ei);
550
+ this._geometryHandler.add(ei.geometry);
551
+ }
552
+ }
553
+
554
+ this._entities[i] = ei;
555
+
556
+ //var ext = ei.getExtent();
557
+ //if (ext.northEast.lon > e.northEast.lon) e.northEast.lon = ext.northEast.lon;
558
+ //if (ext.northEast.lat > e.northEast.lat) e.northEast.lat = ext.northEast.lat;
559
+ //if (ext.southWest.lon < e.southWest.lon) e.southWest.lon = ext.southWest.lon;
560
+ //if (ext.southWest.lat < e.southWest.lat) e.southWest.lat = ext.southWest.lat;
561
+ }
562
+
563
+ this._createEntityCollectionsTree(entitiesForTree);
564
+
565
+ return this;
566
+ }
567
+
568
+ _createEntityCollectionsTree(entitiesForTree) {
569
+ if (this._planet) {
570
+ this._entityCollectionsTree = new EntityCollectionNode(
571
+ this,
572
+ quadTree.NW,
573
+ null,
574
+ 0,
575
+ Extent.createFromArray([-20037508.34, -20037508.34, 20037508.34, 20037508.34]),
576
+ this._planet,
577
+ 0
578
+ );
579
+ this._entityCollectionsTreeNorth = new EntityCollectionNodeWGS84(
580
+ this,
581
+ quadTree.NW,
582
+ null,
583
+ 0,
584
+ Extent.createFromArray([-180, mercator.MAX_LAT, 180, 90]),
585
+ this._planet,
586
+ 0
587
+ );
588
+ this._entityCollectionsTreeSouth = new EntityCollectionNodeWGS84(
589
+ this,
590
+ quadTree.NW,
591
+ null,
592
+ 0,
593
+ Extent.createFromArray([-180, -90, 180, mercator.MIN_LAT]),
594
+ this._planet,
595
+ 0
596
+ );
597
+
598
+ for (let i = 0, len = entitiesForTree.length; i < len; i++) {
599
+ let entity = entitiesForTree[i];
600
+ // north tree
601
+ if (entity._lonlat.lat > mercator.MAX_LAT) {
602
+ this._entityCollectionsTreeNorth.__setLonLat__(entity);
603
+ } else if (entity._lonlat.lat < mercator.MIN_LAT) {
604
+ // south tree
605
+ this._entityCollectionsTreeSouth.__setLonLat__(entity);
606
+ } else {
607
+ this._entityCollectionsTree.__setLonLat__(entity);
608
+ }
609
+ }
610
+
611
+ this._entityCollectionsTree.buildTree(entitiesForTree);
612
+ this._entityCollectionsTreeNorth.buildTree(entitiesForTree);
613
+ this._entityCollectionsTreeSouth.buildTree(entitiesForTree);
614
+ }
615
+ }
616
+
617
+ _bindEventsDefault(entityCollection) {
618
+ var ve = this.events;
619
+ entityCollection.events.on("entitymove", function (e) {
620
+ ve.dispatch(ve.entitymove, e);
621
+ });
622
+ entityCollection.events.on("mousemove", function (e) {
623
+ ve.dispatch(ve.mousemove, e);
624
+ });
625
+ entityCollection.events.on("mouseenter", function (e) {
626
+ ve.dispatch(ve.mouseenter, e);
627
+ });
628
+ entityCollection.events.on("mouseleave", function (e) {
629
+ ve.dispatch(ve.mouseleave, e);
630
+ });
631
+ entityCollection.events.on("lclick", function (e) {
632
+ ve.dispatch(ve.lclick, e);
633
+ });
634
+ entityCollection.events.on("rclick", function (e) {
635
+ ve.dispatch(ve.rclick, e);
636
+ });
637
+ entityCollection.events.on("mclick", function (e) {
638
+ ve.dispatch(ve.mclick, e);
639
+ });
640
+ entityCollection.events.on("ldblclick", function (e) {
641
+ ve.dispatch(ve.ldblclick, e);
642
+ });
643
+ entityCollection.events.on("rdblclick", function (e) {
644
+ ve.dispatch(ve.rdblclick, e);
645
+ });
646
+ entityCollection.events.on("mdblclick", function (e) {
647
+ ve.dispatch(ve.mdblclick, e);
648
+ });
649
+ entityCollection.events.on("lup", function (e) {
650
+ ve.dispatch(ve.lup, e);
651
+ });
652
+ entityCollection.events.on("rup", function (e) {
653
+ ve.dispatch(ve.rup, e);
654
+ });
655
+ entityCollection.events.on("mup", function (e) {
656
+ ve.dispatch(ve.mup, e);
657
+ });
658
+ entityCollection.events.on("ldown", function (e) {
659
+ ve.dispatch(ve.ldown, e);
660
+ });
661
+ entityCollection.events.on("rdown", function (e) {
662
+ ve.dispatch(ve.rdown, e);
663
+ });
664
+ entityCollection.events.on("mdown", function (e) {
665
+ ve.dispatch(ve.mdown, e);
666
+ });
667
+ entityCollection.events.on("lhold", function (e) {
668
+ ve.dispatch(ve.lhold, e);
669
+ });
670
+ entityCollection.events.on("rhold", function (e) {
671
+ ve.dispatch(ve.rhold, e);
672
+ });
673
+ entityCollection.events.on("mhold", function (e) {
674
+ ve.dispatch(ve.mhold, e);
675
+ });
676
+ entityCollection.events.on("mousewheel", function (e) {
677
+ ve.dispatch(ve.mousewheel, e);
678
+ });
679
+ entityCollection.events.on("touchmove", function (e) {
680
+ ve.dispatch(ve.touchmove, e);
681
+ });
682
+ entityCollection.events.on("touchstart", function (e) {
683
+ ve.dispatch(ve.touchstart, e);
684
+ });
685
+ entityCollection.events.on("touchend", function (e) {
686
+ ve.dispatch(ve.touchend, e);
687
+ });
688
+ entityCollection.events.on("doubletouch", function (e) {
689
+ ve.dispatch(ve.doubletouch, e);
690
+ });
691
+ entityCollection.events.on("touchleave", function (e) {
692
+ ve.dispatch(ve.touchleave, e);
693
+ });
694
+ entityCollection.events.on("touchenter", function (e) {
695
+ ve.dispatch(ve.touchenter, e);
696
+ });
697
+ }
698
+
699
+ _collectStripCollectionPASS(outArr) {
700
+ var ec = this._stripEntityCollection;
701
+
702
+ ec._fadingOpacity = this._fadingOpacity;
703
+ ec.scaleByDistance = this.scaleByDistance;
704
+ ec.pickingScale = this.pickingScale;
705
+ ec.polygonOffsetUnits = this.polygonOffsetUnits;
706
+
707
+ outArr.push(ec);
708
+ //
709
+ // ...TODO: extent
710
+ //
711
+ }
712
+
713
+ _collectPolylineCollectionPASS(outArr) {
714
+ var ec = this._polylineEntityCollection;
715
+
716
+ ec._fadingOpacity = this._fadingOpacity;
717
+ ec.scaleByDistance = this.scaleByDistance;
718
+ ec.pickingScale = this.pickingScale;
719
+ ec.polygonOffsetUnits = this.polygonOffsetUnits;
720
+
721
+ outArr.push(ec);
722
+
723
+ if (this.clampToGround || this.relativeToGround) {
724
+ let rtg = Number(this.relativeToGround);
725
+
726
+ var nodes = this._planet._renderedNodes;
727
+ var visibleExtent = this._planet.getViewExtent();
728
+ var e = ec._entities;
729
+ var e_i = e.length;
730
+ let res = new Vec3();
731
+
732
+ while (e_i--) {
733
+ var p = e[e_i].polyline;
734
+ if (visibleExtent.overlaps(p._extent)) {
735
+ // TODO:this works only for mercator area.
736
+ // needs to be working on poles.
737
+ let coords = p._pathLonLatMerc,
738
+ c_j = coords.length;
739
+ while (c_j--) {
740
+ var c_j_h = coords[c_j].length;
741
+ while (c_j_h--) {
742
+ let ll = coords[c_j][c_j_h],
743
+ n_k = nodes.length;
744
+ while (n_k--) {
745
+ var seg = nodes[n_k].segment;
746
+ if (seg._extent.isInside(ll)) {
747
+ let cart = p._path3v[c_j][c_j_h];
748
+ seg.getTerrainPoint(cart, ll, res);
749
+ p.setPoint3v(
750
+ res.addA(res.normal().scale((rtg && p.altitude) || 0.0)),
751
+ c_j_h,
752
+ c_j,
753
+ true
754
+ );
755
+ break;
756
+ }
757
+ }
758
+ }
759
+ }
760
+ }
761
+ }
762
+ }
763
+ }
764
+
765
+ collectVisibleCollections(outArr) {
766
+ var p = this._planet;
767
+
768
+ if (
769
+ (this._fading && this._fadingOpacity > 0.0) ||
770
+ (this.minZoom <= this._planet.maxCurrZoom && this.maxZoom >= p.maxCurrZoom)
771
+ ) {
772
+ this._renderingNodes = {};
773
+ this._renderingNodesNorth = {};
774
+ this._renderingNodesSouth = {};
775
+
776
+ // Common collections first
777
+ this._collectStripCollectionPASS(outArr);
778
+
779
+ this._collectPolylineCollectionPASS(outArr);
780
+
781
+ // Merc nodes
782
+ this._secondPASS = [];
783
+ this._entityCollectionsTree.collectRenderCollectionsPASS1(p._visibleNodes, outArr);
784
+ var i = this._secondPASS.length;
785
+ while (i--) {
786
+ this._secondPASS[i].collectRenderCollectionsPASS2(
787
+ p._visibleNodes,
788
+ outArr,
789
+ this._secondPASS[i].nodeId
790
+ );
791
+ }
792
+
793
+ // North nodes
794
+ this._secondPASS = [];
795
+ this._entityCollectionsTreeNorth.collectRenderCollectionsPASS1(
796
+ p._visibleNodesNorth,
797
+ outArr
798
+ );
799
+ i = this._secondPASS.length;
800
+ while (i--) {
801
+ this._secondPASS[i].collectRenderCollectionsPASS2(
802
+ p._visibleNodesNorth,
803
+ outArr,
804
+ this._secondPASS[i].nodeId
805
+ );
806
+ }
807
+
808
+ // South nodes
809
+ this._secondPASS = [];
810
+ this._entityCollectionsTreeSouth.collectRenderCollectionsPASS1(
811
+ p._visibleNodesSouth,
812
+ outArr
813
+ );
814
+ i = this._secondPASS.length;
815
+ while (i--) {
816
+ this._secondPASS[i].collectRenderCollectionsPASS2(
817
+ p._visibleNodesSouth,
818
+ outArr,
819
+ this._secondPASS[i].nodeId
820
+ );
821
+ }
822
+ }
823
+ }
824
+
825
+ _queueDeferredNode(node) {
826
+ if (this._visibility) {
827
+ node._inTheQueue = true;
828
+ if (this._counter >= 1) {
829
+ this._deferredEntitiesPendingQueue.push(node);
830
+ } else {
831
+ this._execDeferredNode(node);
832
+ }
833
+ }
834
+ }
835
+
836
+ _execDeferredNode(node) {
837
+ this._counter++;
838
+ var that = this;
839
+ setTimeout(function () {
840
+ node.applyCollection();
841
+ that._counter--;
842
+ if (that._deferredEntitiesPendingQueue.length && that._counter < 1) {
843
+ while (that._deferredEntitiesPendingQueue.length) {
844
+ var n = that._deferredEntitiesPendingQueue.pop();
845
+ n._inTheQueue = false;
846
+ if (n.isVisible()) {
847
+ that._execDeferredNode(n);
848
+ return;
849
+ }
850
+ }
851
+ }
852
+ }, 0);
853
+ }
854
+
855
+ /**
856
+ * Start to load tile material.
857
+ * @public
858
+ * @virtual
859
+ * @param {Segment.Material} material - Current material.
860
+ */
861
+ loadMaterial(material) {
862
+ var seg = material.segment;
863
+
864
+ if (this._isBaseLayer) {
865
+ material.texture = seg._isNorth
866
+ ? seg.planet.solidTextureOne
867
+ : seg.planet.solidTextureTwo;
868
+ } else {
869
+ material.texture = seg.planet.transparentTexture;
870
+ }
871
+
872
+ if (this._planet.layerLock.isFree()) {
873
+ material.isReady = false;
874
+ material.isLoading = true;
875
+ this._planet._vectorTileCreator.add(material);
876
+ }
877
+ }
878
+
879
+ /**
880
+ * Abort exact material loading.
881
+ * @public
882
+ * @param {Material} material - Segment material.
883
+ */
884
+ abortMaterialLoading(material) {
885
+ material.isLoading = false;
886
+ material.isReady = false;
887
+ }
888
+
889
+ applyMaterial(material) {
890
+ if (material.isReady) {
891
+ return [0, 0, 1, 1];
892
+ } else {
893
+ !material.isLoading && this.loadMaterial(material);
894
+
895
+ var segment = material.segment;
896
+ var pn = segment.node,
897
+ notEmpty = false;
898
+
899
+ var mId = this._id;
900
+ var psegm = material;
901
+
902
+ while (pn.parentNode) {
903
+ if (psegm && psegm.isReady) {
904
+ notEmpty = true;
905
+ break;
906
+ }
907
+ pn = pn.parentNode;
908
+ psegm = pn.segment.materials[mId];
909
+ }
910
+
911
+ if (notEmpty) {
912
+ material.appliedNodeId = pn.nodeId;
913
+ material.texture = psegm.texture;
914
+ material.pickingMask = psegm.pickingMask;
915
+ var dZ2 = 1.0 / (2 << (segment.tileZoom - pn.segment.tileZoom - 1));
916
+ return [
917
+ segment.tileX * dZ2 - pn.segment.tileX,
918
+ segment.tileY * dZ2 - pn.segment.tileY,
919
+ dZ2,
920
+ dZ2
921
+ ];
922
+ } else {
923
+ if (material.textureExists && material._updateTexture) {
924
+ material.texture = material._updateTexture;
925
+ material.pickingMask = material._updatePickingMask;
926
+ } else {
927
+ material.texture = segment.planet.transparentTexture;
928
+ material.pickingMask = segment.planet.transparentTexture;
929
+ }
930
+ return [0, 0, 1, 1];
931
+ }
932
+ }
933
+ }
934
+
935
+ clearMaterial(material) {
936
+ if (material.isReady) {
937
+ var gl = material.segment.handler.gl;
938
+
939
+ material.isReady = false;
940
+ material.pickingReady = false;
941
+
942
+ var t = material.texture;
943
+ material.texture = null;
944
+ t && !t.default && gl.deleteTexture(t);
945
+
946
+ t = material.pickingMask;
947
+ material.pickingMask = null;
948
+ t && !t.default && gl.deleteTexture(t);
949
+
950
+ t = material._updateTexture;
951
+ material._updateTexture = null;
952
+ t && !t.default && gl.deleteTexture(t);
953
+
954
+ t = material._updatePickingMask;
955
+ material._updatePickingMask = null;
956
+ t && !t.default && gl.deleteTexture(t);
957
+ }
958
+
959
+ this.abortMaterialLoading(material);
960
+
961
+ material.isLoading = false;
962
+ material.textureExists = false;
963
+ }
964
+
965
+ update() {
966
+ this._geometryHandler.update();
967
+ this.events.dispatch(this.events.draw, this);
968
+ }
969
+ }
970
+
971
+ const EVENT_NAMES = [
972
+ /**
973
+ * Triggered when entity has moved.
974
+ * @event og.layer.Vector#draw
975
+ */
976
+ "entitymove",
977
+
978
+ /**
979
+ * Triggered when layer begin draw.
980
+ * @event og.layer.Vector#draw
981
+ */
982
+ "draw",
983
+
984
+ /**
985
+ * Triggered when new entity added to the layer.
986
+ * @event og.layer.Vector#entityadd
987
+ */
988
+ "entityadd",
989
+
990
+ /**
991
+ * Triggered when entity removes from the collection.
992
+ * @event og.layer.Vector#entityremove
993
+ */
994
+ "entityremove"
995
+ ];
996
+
997
+ export { Vector };