@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,2222 +1,2218 @@
1
- /**
2
- * @module og/entity/Polyline
3
- */
4
-
5
- "use strict";
6
-
7
- import {
8
- makeArrayTyped,
9
- makeArray,
10
- htmlColorToFloat32Array,
11
- htmlColorToRgba,
12
- cloneArray
13
- } from "../utils/shared.js";
14
- import { Extent } from "../Extent.js";
15
- import { LonLat } from "../LonLat.js";
16
- import { Vec3 } from "../math/Vec3.js";
17
-
18
- const VERTICES_BUFFER = 0;
19
- const INDEX_BUFFER = 1;
20
- const COLORS_BUFFER = 2;
21
-
22
- const DEFAULT_COLOR = "#0000FF";
23
-
24
- const R = 0;
25
- const G = 1;
26
- const B = 2;
27
- const A = 3;
28
-
29
- /**
30
- * Polyline object.
31
- * @class
32
- * @param {Object} [options] - Polyline options:
33
- * @param {number} [options.thickness] - Thickness in screen pixels 1.5 is default.
34
- * @param {Number} [options.altitude] - Relative to ground layers altitude value.
35
- * @param {Vec4} [options.color] - RGBA color.
36
- * @param {Boolean} [options.opacity] - Line opacity.
37
- * @param {Boolean} [options.visibility] - Polyline visibility. True default.
38
- * @param {Boolean} [options.isClosed] - Closed geometry type identificator.
39
- * @param {Array.<Array.<number>>} [options.pathLonLat] - Polyline geodetic coordinates array. [[0,0,0], [1,1,1],...]
40
- * @param {Array.<Array.<number>>} [options.path3v] - LinesString cartesian coordinates array. [[0,0,0], [1,1,1],...]
41
- * @param {Array.<Array.<number>>} [options.pathColors] - Coordinates color. [[1,0,0,1], [0,1,0,1],...] for right and green colors.
42
- */
43
- class Polyline {
44
- constructor(options) {
45
- options = options || {};
46
-
47
- /**
48
- * Object unic identifier.
49
- * @public
50
- * @readonly
51
- * @type {number}
52
- */
53
- this.id = Polyline._staticCounter++;
54
-
55
- this.altitude = options.altitude || 0.0;
56
-
57
- /**
58
- * Polyline thickness in screen pixels.
59
- * @public
60
- * @type {number}
61
- */
62
- this.thickness = options.thickness || 1.5;
63
-
64
- /**
65
- * Polyline RGBA color.
66
- * @public
67
- * @type {Array<number>} - (exactly 4 entries)
68
- */
69
- this._defaultColor = htmlColorToFloat32Array(
70
- options.color || DEFAULT_COLOR,
71
- options.opacity
72
- ); // utils.createColorRGBA(options.color, new Vec4(1.0, 1.0, 1.0, 1.0));
73
-
74
- /**
75
- * Polyline visibility.
76
- * @public
77
- * @type {boolean}
78
- */
79
- this.visibility = options.visibility != undefined ? options.visibility : true;
80
-
81
- /**
82
- * Polyline geometry ring type identificator.
83
- * @protected
84
- * @type {Boolean}
85
- */
86
- this._closedLine = options.isClosed || false;
87
-
88
- /**
89
- * Polyline cartesian coordinates.
90
- * @private
91
- * @type {Array.<Vec3>}
92
- */
93
- this._path3v = [];
94
-
95
- this._pathLengths = [];
96
-
97
- /**
98
- * Polyline geodetic degrees coordiantes.
99
- * @private
100
- * @type {Array.<LonLat>}
101
- */
102
- this._pathLonLat = [];
103
-
104
- /**
105
- * Polyline geodetic mercator coordinates.
106
- * @private
107
- * @type {Array.<LonLat>}
108
- */
109
- this._pathLonLatMerc = [];
110
-
111
- this._pathColors = options.pathColors ? cloneArray(options.pathColors) : [];
112
-
113
- /**
114
- * Polyline geodetic extent.
115
- * @protected
116
- * @type {Extent}
117
- */
118
- this._extent = new Extent();
119
-
120
- this._verticesHigh = [];
121
- this._verticesLow = [];
122
- this._orders = [];
123
- this._indexes = [];
124
- this._colors = [];
125
-
126
- this._verticesHighBuffer = null;
127
- this._verticesLowBuffer = null;
128
- this._ordersBuffer = null;
129
- this._indexesBuffer = null;
130
- this._colorsBuffer = null;
131
-
132
- this._pickingColor = [0, 0, 0];
133
-
134
- this._renderNode = null;
135
-
136
- /**
137
- * Entity instance that holds this Polyline.
138
- * @private
139
- * @type {Entity}
140
- */
141
- this._entity = null;
142
-
143
- /**
144
- * Handler that stores and renders this Polyline object.
145
- * @private
146
- * @type {PolylineHandler}
147
- */
148
- this._handler = null;
149
- this._handlerIndex = -1;
150
-
151
- this._buffersUpdateCallbacks = [];
152
- this._buffersUpdateCallbacks[VERTICES_BUFFER] = this._createVerticesBuffer;
153
- this._buffersUpdateCallbacks[INDEX_BUFFER] = this._createIndexBuffer;
154
- this._buffersUpdateCallbacks[COLORS_BUFFER] = this._createColorsBuffer;
155
-
156
- this._changedBuffers = new Array(this._buffersUpdateCallbacks.length);
157
-
158
- // create path
159
- if (options.pathLonLat) {
160
- this.setPathLonLat(options.pathLonLat);
161
- } else if (options.path3v) {
162
- this.setPath3v(options.path3v);
163
- }
164
-
165
- this._refresh();
166
- }
167
-
168
- static get _staticCounter() {
169
- if (!this._counter && this._counter !== 0) {
170
- this._counter = 0;
171
- }
172
- return this._counter;
173
- }
174
-
175
- static set _staticCounter(n) {
176
- this._counter = n;
177
- }
178
-
179
- /**
180
- * Appends to the line array new cartesian coordinates line data.
181
- * @param {Array.<Array.<number>>} path3v - Line coordinates path array. [[0,0,0], [1,1,1],...]
182
- * @param {Boolean} isClosed - Identificator for the closed line data creation.
183
- * @param {Number[]} outVertices - Out vertices data array.
184
- * @param {Number[]} outOrders - Out vertices orders data array.
185
- * @param {Number[]} outIndexes - Out vertices indexes data array.
186
- * @param {Ellipsoid} [ellipsoid] - Ellipsoid to coordinates transformation.
187
- * @param {Array.<Array.<LonLat>>} [outTransformedPathLonLat] - Geodetic coordinates out array.
188
- * @param {Array.<Array.<LonLat>>} [outPath3v] - Cartesian coordinates out array.
189
- * @param {Array.<Array.<LonLat>>} [outTransformedPathMerc] - Mercator coordinates out array.
190
- * @param {Extent} [outExtent] - Geodetic line extent.
191
- * @param {Array} [outColors]
192
- * @static
193
- */
194
- static appendLineData3v(
195
- path3v,
196
- pathColors,
197
- defaultColor,
198
- isClosed,
199
- outVerticesHigh,
200
- outVerticesLow,
201
- outOrders,
202
- outIndexes,
203
- ellipsoid,
204
- outTransformedPathLonLat,
205
- outPath3v,
206
- outTransformedPathMerc,
207
- outExtent,
208
- outColors
209
- ) {
210
- var index = 0;
211
-
212
- var v_high = new Vec3(),
213
- v_low = new Vec3();
214
-
215
- if (outExtent) {
216
- outExtent.southWest.set(180.0, 90.0);
217
- outExtent.northEast.set(-180.0, -90.0);
218
- }
219
-
220
- if (outIndexes.length > 0) {
221
- index = outIndexes[outIndexes.length - 5] + 9;
222
- outIndexes.push(index, index);
223
- } else {
224
- outIndexes.push(0, 0);
225
- }
226
-
227
- for (var j = 0, len = path3v.length; j < len; j++) {
228
- var path = path3v[j],
229
- pathColors_j = pathColors[j];
230
-
231
- outTransformedPathLonLat[j] = [];
232
- outTransformedPathMerc[j] = [];
233
- outPath3v[j] = [];
234
-
235
- if (path.length === 0) {
236
- continue;
237
- }
238
-
239
- var startIndex = index;
240
-
241
- var last;
242
-
243
- if (isClosed) {
244
- last = path[path.length - 1];
245
- if (last instanceof Array) {
246
- last = new Vec3(last[0], last[1], last[2]);
247
- }
248
- } else {
249
- var p0 = path[0],
250
- p1 = path[1] || p0;
251
- if (p0 instanceof Array) {
252
- p0 = new Vec3(p0[0], p0[1], p0[2]);
253
- }
254
- if (p1 instanceof Array) {
255
- p1 = new Vec3(p1[0], p1[1], p1[2]);
256
- }
257
- last = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
258
- }
259
-
260
- let color = defaultColor;
261
-
262
- if (pathColors_j && pathColors_j[0]) {
263
- color = pathColors_j[0];
264
- }
265
-
266
- Vec3.doubleToTwoFloats(last, v_high, v_low);
267
- outVerticesHigh.push(
268
- v_high.x,
269
- v_high.y,
270
- v_high.z,
271
- v_high.x,
272
- v_high.y,
273
- v_high.z,
274
- v_high.x,
275
- v_high.y,
276
- v_high.z,
277
- v_high.x,
278
- v_high.y,
279
- v_high.z
280
- );
281
- outVerticesLow.push(
282
- v_low.x,
283
- v_low.y,
284
- v_low.z,
285
- v_low.x,
286
- v_low.y,
287
- v_low.z,
288
- v_low.x,
289
- v_low.y,
290
- v_low.z,
291
- v_low.x,
292
- v_low.y,
293
- v_low.z
294
- );
295
-
296
- let r = color[R],
297
- g = color[G],
298
- b = color[B],
299
- a = color[A] != undefined ? color[A] : 1.0;
300
-
301
- if (j > 0) {
302
- outColors.push(r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a);
303
- }
304
-
305
- outOrders.push(1, -1, 2, -2);
306
-
307
- for (let i = 0, len = path.length; i < len; i++) {
308
- var cur = path[i];
309
-
310
- if (cur instanceof Array) {
311
- cur = new Vec3(cur[0], cur[1], cur[2]);
312
- }
313
-
314
- outPath3v[j].push(cur);
315
-
316
- if (ellipsoid) {
317
- var lonLat = ellipsoid.cartesianToLonLat(cur);
318
- outTransformedPathLonLat[j].push(lonLat);
319
- outTransformedPathMerc[j].push(lonLat.forwardMercator());
320
-
321
- if (lonLat.lon < outExtent.southWest.lon) {
322
- outExtent.southWest.lon = lonLat.lon;
323
- }
324
- if (lonLat.lat < outExtent.southWest.lat) {
325
- outExtent.southWest.lat = lonLat.lat;
326
- }
327
- if (lonLat.lon > outExtent.northEast.lon) {
328
- outExtent.northEast.lon = lonLat.lon;
329
- }
330
- if (lonLat.lat > outExtent.northEast.lat) {
331
- outExtent.northEast.lat = lonLat.lat;
332
- }
333
- }
334
-
335
- if (pathColors_j && pathColors_j[i]) {
336
- color = pathColors_j[i];
337
- }
338
-
339
- r = color[R];
340
- g = color[G];
341
- b = color[B];
342
- a = color[A] != undefined ? color[A] : 1.0;
343
-
344
- Vec3.doubleToTwoFloats(cur, v_high, v_low);
345
- outVerticesHigh.push(
346
- v_high.x,
347
- v_high.y,
348
- v_high.z,
349
- v_high.x,
350
- v_high.y,
351
- v_high.z,
352
- v_high.x,
353
- v_high.y,
354
- v_high.z,
355
- v_high.x,
356
- v_high.y,
357
- v_high.z
358
- );
359
- outVerticesLow.push(
360
- v_low.x,
361
- v_low.y,
362
- v_low.z,
363
- v_low.x,
364
- v_low.y,
365
- v_low.z,
366
- v_low.x,
367
- v_low.y,
368
- v_low.z,
369
- v_low.x,
370
- v_low.y,
371
- v_low.z
372
- );
373
-
374
- outColors.push(r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a);
375
-
376
- outOrders.push(1, -1, 2, -2);
377
- outIndexes.push(index++, index++, index++, index++);
378
- }
379
-
380
- var first;
381
- if (isClosed) {
382
- first = path[0];
383
- if (first instanceof Array) {
384
- first = new Vec3(first[0], first[1], first[2]);
385
- }
386
- outIndexes.push(startIndex, startIndex + 1, startIndex + 1, startIndex + 1);
387
- } else {
388
- let p0 = path[path.length - 1],
389
- p1 = path[path.length - 2] || p0;
390
- if (p0 instanceof Array) {
391
- p0 = new Vec3(p0[0], p0[1], p0[2]);
392
- }
393
- if (p1 instanceof Array) {
394
- p1 = new Vec3(p1[0], p1[1], p1[2]);
395
- }
396
- first = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
397
- outIndexes.push(index - 1, index - 1, index - 1, index - 1);
398
- }
399
-
400
- if (pathColors_j && pathColors_j[path.length - 1]) {
401
- color = pathColors_j[path.length - 1];
402
- }
403
-
404
- r = color[R];
405
- g = color[G];
406
- b = color[B];
407
- a = color[A] != undefined ? color[A] : 1.0;
408
-
409
- Vec3.doubleToTwoFloats(first, v_high, v_low);
410
- outVerticesHigh.push(
411
- v_high.x,
412
- v_high.y,
413
- v_high.z,
414
- v_high.x,
415
- v_high.y,
416
- v_high.z,
417
- v_high.x,
418
- v_high.y,
419
- v_high.z,
420
- v_high.x,
421
- v_high.y,
422
- v_high.z
423
- );
424
- outVerticesLow.push(
425
- v_low.x,
426
- v_low.y,
427
- v_low.z,
428
- v_low.x,
429
- v_low.y,
430
- v_low.z,
431
- v_low.x,
432
- v_low.y,
433
- v_low.z,
434
- v_low.x,
435
- v_low.y,
436
- v_low.z
437
- );
438
-
439
- outColors.push(r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a);
440
-
441
- outOrders.push(1, -1, 2, -2);
442
-
443
- if (j < path3v.length - 1 && path3v[j + 1].length !== 0) {
444
- index += 8;
445
- outIndexes.push(index, index);
446
- }
447
- }
448
- }
449
-
450
- /**
451
- * Appends to the line new cartesian coordinates point data.
452
- * @param {Array.<Array.<number>>} path3v - Line coordinates path array. [[0,0,0], [1,1,1],...]
453
- * @param {Boolean} isClosed - Identificator for the closed line data creation.
454
- * @param {Number[]} outVertices - Out vertices data array.
455
- * @param {Number[]} outOrders - Out vertices orders data array.
456
- * @param {Number[]} outIndexes - Out vertices indexes data array.
457
- * @param {Ellipsoid} [ellipsoid] - Ellipsoid to coordinates transformation.
458
- * @param {Array.<Array.<LonLat>>} [outTransformedPathLonLat] - Geodetic coordinates out array.
459
- * @param {Array.<Array.<LonLat>>} [outPath3v] - Cartesian coordinates out array.
460
- * @param {Array.<Array.<LonLat>>} [outTransformedPathMerc] - Mercator coordinates out array.
461
- * @param {Extent} [outExtent] - Geodetic line extent.
462
- * @static
463
- */
464
- static appendPoint3v(
465
- path3v,
466
- point3v,
467
- pathColors,
468
- color,
469
- isClosed,
470
- outVerticesHigh,
471
- outVerticesLow,
472
- outColors,
473
- outOrders,
474
- outIndexes,
475
- ellipsoid,
476
- outTransformedPathLonLat,
477
- outTransformedPathMerc,
478
- outExtent
479
- ) {
480
- var v_high = new Vec3(),
481
- v_low = new Vec3();
482
-
483
- var ii = outIndexes.length - 4,
484
- index = outIndexes[ii - 1] + 1;
485
-
486
- if (path3v.length === 0) {
487
- path3v.push([]);
488
- if (!pathColors[0]) {
489
- pathColors[0] = [];
490
- }
491
- } else if (!pathColors[path3v.length - 1]) {
492
- pathColors[path3v.length - 1] = [];
493
- }
494
-
495
- var path = path3v[path3v.length - 1],
496
- len = path.length;
497
-
498
- path.push(point3v);
499
-
500
- let r = color[R],
501
- g = color[G],
502
- b = color[B],
503
- a = color[A] != undefined ? color[A] : 1.0,
504
- pathColors_last = pathColors[path3v.length - 1];
505
-
506
- if (pathColors_last[len]) {
507
- pathColors_last[len][R] = r;
508
- pathColors_last[len][G] = g;
509
- pathColors_last[len][B] = b;
510
- pathColors_last[len][A] = a;
511
- } else {
512
- pathColors_last.push(color);
513
- }
514
-
515
- if (len === 1) {
516
- var last;
517
- if (isClosed) {
518
- last = path[len - 1];
519
- if (last instanceof Array) {
520
- last = new Vec3(last[0], last[1], last[2]);
521
- }
522
- } else {
523
- var p0 = path[0],
524
- p1 = path[1] || p0;
525
- if (p0 instanceof Array) {
526
- p0 = new Vec3(p0[0], p0[1], p0[2]);
527
- }
528
- if (p1 instanceof Array) {
529
- p1 = new Vec3(p1[0], p1[1], p1[2]);
530
- }
531
- last = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
532
- }
533
-
534
- Vec3.doubleToTwoFloats(last, v_high, v_low);
535
-
536
- let vi = outVerticesHigh.length - 3 * 12;
537
-
538
- outVerticesHigh[vi] = v_high.x;
539
- outVerticesHigh[vi + 1] = v_high.y;
540
- outVerticesHigh[vi + 2] = v_high.z;
541
- outVerticesHigh[vi + 3] = v_high.x;
542
- outVerticesHigh[vi + 4] = v_high.y;
543
- outVerticesHigh[vi + 5] = v_high.z;
544
- outVerticesHigh[vi + 6] = v_high.x;
545
- outVerticesHigh[vi + 7] = v_high.y;
546
- outVerticesHigh[vi + 8] = v_high.z;
547
- outVerticesHigh[vi + 9] = v_high.x;
548
- outVerticesHigh[vi + 10] = v_high.y;
549
- outVerticesHigh[vi + 11] = v_high.z;
550
-
551
- outVerticesLow[vi] = v_low.x;
552
- outVerticesLow[vi + 1] = v_low.y;
553
- outVerticesLow[vi + 2] = v_low.z;
554
- outVerticesLow[vi + 3] = v_low.x;
555
- outVerticesLow[vi + 4] = v_low.y;
556
- outVerticesLow[vi + 5] = v_low.z;
557
- outVerticesLow[vi + 6] = v_low.x;
558
- outVerticesLow[vi + 7] = v_low.y;
559
- outVerticesLow[vi + 8] = v_low.z;
560
- outVerticesLow[vi + 9] = v_low.x;
561
- outVerticesLow[vi + 10] = v_low.y;
562
- outVerticesLow[vi + 11] = v_low.z;
563
- }
564
-
565
- var startIndex = index;
566
-
567
- if (ellipsoid) {
568
- if (outTransformedPathLonLat.length === 0) {
569
- outTransformedPathLonLat.push([]);
570
- }
571
-
572
- if (outTransformedPathMerc.length === 0) {
573
- outTransformedPathMerc.push([]);
574
- }
575
-
576
- var transformedPathLonLat =
577
- outTransformedPathLonLat[outTransformedPathLonLat.length - 1],
578
- transformedPathMerc = outTransformedPathMerc[outTransformedPathMerc.length - 1];
579
-
580
- let lonLat = ellipsoid.cartesianToLonLat(point3v);
581
- transformedPathLonLat.push(lonLat);
582
- transformedPathMerc.push(lonLat.forwardMercator());
583
-
584
- if (lonLat.lon < outExtent.southWest.lon) {
585
- outExtent.southWest.lon = lonLat.lon;
586
- }
587
- if (lonLat.lat < outExtent.southWest.lat) {
588
- outExtent.southWest.lat = lonLat.lat;
589
- }
590
- if (lonLat.lon > outExtent.northEast.lon) {
591
- outExtent.northEast.lon = lonLat.lon;
592
- }
593
- if (lonLat.lat > outExtent.northEast.lat) {
594
- outExtent.northEast.lat = lonLat.lat;
595
- }
596
- }
597
-
598
- Vec3.doubleToTwoFloats(point3v, v_high, v_low);
599
-
600
- let vi = outVerticesHigh.length - 12;
601
-
602
- outVerticesHigh[vi] = v_high.x;
603
- outVerticesHigh[vi + 1] = v_high.y;
604
- outVerticesHigh[vi + 2] = v_high.z;
605
- outVerticesHigh[vi + 3] = v_high.x;
606
- outVerticesHigh[vi + 4] = v_high.y;
607
- outVerticesHigh[vi + 5] = v_high.z;
608
- outVerticesHigh[vi + 6] = v_high.x;
609
- outVerticesHigh[vi + 7] = v_high.y;
610
- outVerticesHigh[vi + 8] = v_high.z;
611
- outVerticesHigh[vi + 9] = v_high.x;
612
- outVerticesHigh[vi + 10] = v_high.y;
613
- outVerticesHigh[vi + 11] = v_high.z;
614
-
615
- outVerticesLow[vi] = v_low.x;
616
- outVerticesLow[vi + 1] = v_low.y;
617
- outVerticesLow[vi + 2] = v_low.z;
618
- outVerticesLow[vi + 3] = v_low.x;
619
- outVerticesLow[vi + 4] = v_low.y;
620
- outVerticesLow[vi + 5] = v_low.z;
621
- outVerticesLow[vi + 6] = v_low.x;
622
- outVerticesLow[vi + 7] = v_low.y;
623
- outVerticesLow[vi + 8] = v_low.z;
624
- outVerticesLow[vi + 9] = v_low.x;
625
- outVerticesLow[vi + 10] = v_low.y;
626
- outVerticesLow[vi + 11] = v_low.z;
627
-
628
- let ci = outColors.length - 16;
629
-
630
- outColors[ci] = r;
631
- outColors[ci + 1] = g;
632
- outColors[ci + 2] = b;
633
- outColors[ci + 3] = a;
634
- outColors[ci + 4] = r;
635
- outColors[ci + 5] = g;
636
- outColors[ci + 6] = b;
637
- outColors[ci + 7] = a;
638
- outColors[ci + 8] = r;
639
- outColors[ci + 9] = g;
640
- outColors[ci + 10] = b;
641
- outColors[ci + 11] = a;
642
- outColors[ci + 12] = r;
643
- outColors[ci + 13] = g;
644
- outColors[ci + 14] = b;
645
- outColors[ci + 15] = a;
646
-
647
- outIndexes[ii] = index++;
648
- outIndexes[ii + 1] = index++;
649
- outIndexes[ii + 2] = index++;
650
- outIndexes[ii + 3] = index++;
651
-
652
- //
653
- // Close path
654
- //
655
- var first;
656
- if (isClosed) {
657
- first = path[0];
658
- outIndexes.push(startIndex, startIndex + 1, startIndex + 1, startIndex + 1);
659
- } else {
660
- let p0 = path[path.length - 1],
661
- p1 = path[path.length - 2] || p0;
662
-
663
- first = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
664
- outIndexes.push(index - 1, index - 1, index - 1, index - 1);
665
- }
666
-
667
- Vec3.doubleToTwoFloats(first, v_high, v_low);
668
- outVerticesHigh.push(
669
- v_high.x,
670
- v_high.y,
671
- v_high.z,
672
- v_high.x,
673
- v_high.y,
674
- v_high.z,
675
- v_high.x,
676
- v_high.y,
677
- v_high.z,
678
- v_high.x,
679
- v_high.y,
680
- v_high.z
681
- );
682
- outVerticesLow.push(
683
- v_low.x,
684
- v_low.y,
685
- v_low.z,
686
- v_low.x,
687
- v_low.y,
688
- v_low.z,
689
- v_low.x,
690
- v_low.y,
691
- v_low.z,
692
- v_low.x,
693
- v_low.y,
694
- v_low.z
695
- );
696
-
697
- outColors.push(r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a);
698
-
699
- outOrders.push(1, -1, 2, -2);
700
- }
701
-
702
- /**
703
- * Appends to the line array new geodetic coordinates line data.
704
- * @param {Array.<Array.<number>>} pathLonLat - Line geodetic coordinates path array. [[0,0,0], [1,1,1],...]
705
- * @param {Boolean} isClosed - Identificator for the closed line data creation.
706
- * @param {Number[]} outVertices - Out vertices data array.
707
- * @param {Number[]} outOrders - Out vertices orders data array.
708
- * @param {Number[]} outIndexes - Out indexes data array.
709
- * @param {Ellipsoid} ellipsoid - Ellipsoid to coordinates transformation.
710
- * @param {Array.<Array.<number>>} outTransformedPathCartesian - Cartesian coordinates out array. [[0,0,0], [1,1,1],...]
711
- * @param {Array.<Array.<LonLat>>} outPathLonLat - Geographic coordinates out array.
712
- * @param {Array.<Array.<LonLat>>} outTransformedPathMerc - Mercator coordinates out array.
713
- * @param {Extent} outExtent - Geodetic line extent.
714
- * @static
715
- */
716
- static appendLineDataLonLat(
717
- pathLonLat,
718
- pathColors,
719
- defaultColor,
720
- isClosed,
721
- outVerticesHigh,
722
- outVerticesLow,
723
- outOrders,
724
- outIndexes,
725
- ellipsoid,
726
- outTransformedPathCartesian,
727
- outPathLonLat,
728
- outTransformedPathMerc,
729
- outExtent,
730
- outColors
731
- ) {
732
- var index = 0;
733
-
734
- var v_high = new Vec3(),
735
- v_low = new Vec3();
736
-
737
- if (outExtent) {
738
- outExtent.southWest.set(180.0, 90.0);
739
- outExtent.northEast.set(-180.0, -90.0);
740
- }
741
-
742
- if (outIndexes.length > 0) {
743
- index = outIndexes[outIndexes.length - 5] + 9;
744
- outIndexes.push(index, index);
745
- } else {
746
- outIndexes.push(0, 0);
747
- }
748
-
749
- for (var j = 0, len = pathLonLat.length; j < len; j++) {
750
- var path = pathLonLat[j],
751
- pathColors_j = pathColors[j];
752
-
753
- outTransformedPathCartesian[j] = [];
754
- outTransformedPathMerc[j] = [];
755
- outPathLonLat[j] = [];
756
-
757
- if (path.length === 0) {
758
- continue;
759
- }
760
-
761
- var startIndex = index;
762
-
763
- var last;
764
-
765
- if (isClosed) {
766
- let pp = path[path.length - 1];
767
- if (pp instanceof Array) {
768
- last = ellipsoid.lonLatToCartesian(new LonLat(pp[0], pp[1], pp[2]));
769
- } else {
770
- last = ellipsoid.lonLatToCartesian(pp);
771
- }
772
- } else {
773
- let p0, p1;
774
- let pp = path[0];
775
- if (pp instanceof Array) {
776
- p0 = ellipsoid.lonLatToCartesian(new LonLat(pp[0], pp[1], pp[2]));
777
- } else {
778
- p0 = ellipsoid.lonLatToCartesian(pp);
779
- }
780
-
781
- pp = path[1];
782
-
783
- if (!pp) {
784
- pp = path[0];
785
- }
786
-
787
- if (pp instanceof Array) {
788
- p1 = ellipsoid.lonLatToCartesian(new LonLat(pp[0], pp[1], pp[2]));
789
- } else {
790
- p1 = ellipsoid.lonLatToCartesian(pp);
791
- }
792
-
793
- last = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
794
- }
795
-
796
- let color = defaultColor;
797
-
798
- if (pathColors_j && pathColors_j[0]) {
799
- color = pathColors_j[0];
800
- }
801
-
802
- Vec3.doubleToTwoFloats(last, v_high, v_low);
803
- outVerticesHigh.push(
804
- v_high.x,
805
- v_high.y,
806
- v_high.z,
807
- v_high.x,
808
- v_high.y,
809
- v_high.z,
810
- v_high.x,
811
- v_high.y,
812
- v_high.z,
813
- v_high.x,
814
- v_high.y,
815
- v_high.z
816
- );
817
- outVerticesLow.push(
818
- v_low.x,
819
- v_low.y,
820
- v_low.z,
821
- v_low.x,
822
- v_low.y,
823
- v_low.z,
824
- v_low.x,
825
- v_low.y,
826
- v_low.z,
827
- v_low.x,
828
- v_low.y,
829
- v_low.z
830
- );
831
-
832
- let r = color[R],
833
- g = color[G],
834
- b = color[B],
835
- a = color[A] != undefined ? color[A] : 1.0;
836
-
837
- if (j > 0) {
838
- outColors.push(r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a);
839
- }
840
-
841
- outOrders.push(1, -1, 2, -2);
842
-
843
- for (let i = 0, len = path.length; i < len; i++) {
844
- var cur = path[i];
845
-
846
- if (cur instanceof Array) {
847
- cur = new LonLat(cur[0], cur[1], cur[2]);
848
- }
849
-
850
- if (pathColors_j && pathColors_j[i]) {
851
- color = pathColors_j[i];
852
- }
853
-
854
- r = color[R];
855
- g = color[G];
856
- b = color[B];
857
- a = color[A] != undefined ? color[A] : 1.0;
858
-
859
- var cartesian = ellipsoid.lonLatToCartesian(cur);
860
- outTransformedPathCartesian[j].push(cartesian);
861
- outPathLonLat[j].push(cur);
862
- outTransformedPathMerc[j].push(cur.forwardMercator());
863
-
864
- Vec3.doubleToTwoFloats(cartesian, v_high, v_low);
865
- outVerticesHigh.push(
866
- v_high.x,
867
- v_high.y,
868
- v_high.z,
869
- v_high.x,
870
- v_high.y,
871
- v_high.z,
872
- v_high.x,
873
- v_high.y,
874
- v_high.z,
875
- v_high.x,
876
- v_high.y,
877
- v_high.z
878
- );
879
- outVerticesLow.push(
880
- v_low.x,
881
- v_low.y,
882
- v_low.z,
883
- v_low.x,
884
- v_low.y,
885
- v_low.z,
886
- v_low.x,
887
- v_low.y,
888
- v_low.z,
889
- v_low.x,
890
- v_low.y,
891
- v_low.z
892
- );
893
-
894
- outColors.push(r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a);
895
-
896
- outOrders.push(1, -1, 2, -2);
897
- outIndexes.push(index++, index++, index++, index++);
898
-
899
- if (cur.lon < outExtent.southWest.lon) {
900
- outExtent.southWest.lon = cur.lon;
901
- }
902
- if (cur.lat < outExtent.southWest.lat) {
903
- outExtent.southWest.lat = cur.lat;
904
- }
905
- if (cur.lon > outExtent.northEast.lon) {
906
- outExtent.northEast.lon = cur.lon;
907
- }
908
- if (cur.lat > outExtent.northEast.lat) {
909
- outExtent.northEast.lat = cur.lat;
910
- }
911
- }
912
-
913
- var first;
914
- if (isClosed) {
915
- let pp = path[0];
916
- if (pp instanceof Array) {
917
- first = ellipsoid.lonLatToCartesian(new LonLat(pp[0], pp[1], pp[2]));
918
- } else {
919
- first = ellipsoid.lonLatToCartesian(pp);
920
- }
921
- outIndexes.push(startIndex, startIndex + 1, startIndex + 1, startIndex + 1);
922
- } else {
923
- let p0, p1;
924
- let pp = path[path.length - 1];
925
- if (pp instanceof Array) {
926
- p0 = ellipsoid.lonLatToCartesian(new LonLat(pp[0], pp[1], pp[2]));
927
- } else {
928
- p0 = ellipsoid.lonLatToCartesian(pp);
929
- }
930
-
931
- pp = path[path.length - 2];
932
-
933
- if (!pp) {
934
- pp = path[0];
935
- }
936
-
937
- if (pp instanceof Array) {
938
- p1 = ellipsoid.lonLatToCartesian(new LonLat(pp[0], pp[1], pp[2]));
939
- } else {
940
- p1 = ellipsoid.lonLatToCartesian(pp);
941
- }
942
- first = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
943
- outIndexes.push(index - 1, index - 1, index - 1, index - 1);
944
- }
945
-
946
- if (pathColors_j && pathColors_j[path.length - 1]) {
947
- color = pathColors_j[path.length - 1];
948
- }
949
-
950
- r = color[R];
951
- g = color[G];
952
- b = color[B];
953
- a = color[A] != undefined ? color[A] : 1.0;
954
-
955
- Vec3.doubleToTwoFloats(first, v_high, v_low);
956
- outVerticesHigh.push(
957
- v_high.x,
958
- v_high.y,
959
- v_high.z,
960
- v_high.x,
961
- v_high.y,
962
- v_high.z,
963
- v_high.x,
964
- v_high.y,
965
- v_high.z,
966
- v_high.x,
967
- v_high.y,
968
- v_high.z
969
- );
970
- outVerticesLow.push(
971
- v_low.x,
972
- v_low.y,
973
- v_low.z,
974
- v_low.x,
975
- v_low.y,
976
- v_low.z,
977
- v_low.x,
978
- v_low.y,
979
- v_low.z,
980
- v_low.x,
981
- v_low.y,
982
- v_low.z
983
- );
984
-
985
- outColors.push(r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a);
986
-
987
- outOrders.push(1, -1, 2, -2);
988
-
989
- if (j < pathLonLat.length - 1 && pathLonLat[j + 1].length !== 0) {
990
- index += 8;
991
- outIndexes.push(index, index);
992
- }
993
- }
994
- }
995
-
996
- /**
997
- * Sets polyline path with cartesian coordinates.
998
- * @protected
999
- * @param {pg.math.Vector3[]} path3v - Cartesian coordinates.
1000
- */
1001
- _setEqualPath3v(path3v) {
1002
- var extent = this._extent;
1003
- extent.southWest.set(180, 90);
1004
- extent.northEast.set(-180, -90);
1005
-
1006
- var v_high = new Vec3(),
1007
- v_low = new Vec3();
1008
-
1009
- var vh = this._verticesHigh,
1010
- vl = this._verticesLow,
1011
- l = this._pathLonLat,
1012
- m = this._pathLonLatMerc,
1013
- k = 0;
1014
-
1015
- var ellipsoid = this._renderNode.ellipsoid;
1016
-
1017
- for (var j = 0; j < path3v.length; j++) {
1018
- var path = path3v[j];
1019
-
1020
- var last;
1021
- if (this._closedLine) {
1022
- last = path[path.length - 1];
1023
- } else {
1024
- last = new Vec3(
1025
- path[0].x + path[0].x - path[1].x,
1026
- path[0].y + path[0].y - path[1].y,
1027
- path[0].z + path[0].z - path[1].z
1028
- );
1029
- }
1030
-
1031
- Vec3.doubleToTwoFloats(last, v_high, v_low);
1032
-
1033
- vh[k] = v_high.x;
1034
- vl[k++] = v_low.x;
1035
- vh[k] = v_high.y;
1036
- vl[k++] = v_low.y;
1037
- vh[k] = v_high.z;
1038
- vl[k++] = v_low.z;
1039
- vh[k] = v_high.x;
1040
- vl[k++] = v_low.x;
1041
- vh[k] = v_high.y;
1042
- vl[k++] = v_low.y;
1043
- vh[k] = v_high.z;
1044
- vl[k++] = v_low.z;
1045
- vh[k] = v_high.x;
1046
- vl[k++] = v_low.x;
1047
- vh[k] = v_high.y;
1048
- vl[k++] = v_low.y;
1049
- vh[k] = v_high.z;
1050
- vl[k++] = v_low.z;
1051
- vh[k] = v_high.x;
1052
- vl[k++] = v_low.x;
1053
- vh[k] = v_high.y;
1054
- vl[k++] = v_low.y;
1055
- vh[k] = v_high.z;
1056
- vl[k++] = v_low.z;
1057
-
1058
- for (var i = 0; i < path.length; i++) {
1059
- var cur = path[i],
1060
- pji = this._path3v[j][i];
1061
-
1062
- pji.x = cur.x;
1063
- pji.y = cur.y;
1064
- pji.z = cur.z;
1065
-
1066
- if (ellipsoid) {
1067
- var lonLat = ellipsoid.cartesianToLonLat(cur);
1068
-
1069
- this._pathLonLat[j][i] = lonLat;
1070
-
1071
- l[j][i] = lonLat;
1072
- m[j][i] = lonLat.forwardMercator();
1073
-
1074
- if (lonLat.lon < extent.southWest.lon) {
1075
- extent.southWest.lon = lonLat.lon;
1076
- }
1077
- if (lonLat.lat < extent.southWest.lat) {
1078
- extent.southWest.lat = lonLat.lat;
1079
- }
1080
- if (lonLat.lon > extent.northEast.lon) {
1081
- extent.northEast.lon = lonLat.lon;
1082
- }
1083
- if (lonLat.lat > extent.northEast.lat) {
1084
- extent.northEast.lat = lonLat.lat;
1085
- }
1086
- }
1087
-
1088
- Vec3.doubleToTwoFloats(cur, v_high, v_low);
1089
-
1090
- vh[k] = v_high.x;
1091
- vl[k++] = v_low.x;
1092
- vh[k] = v_high.y;
1093
- vl[k++] = v_low.y;
1094
- vh[k] = v_high.z;
1095
- vl[k++] = v_low.z;
1096
- vh[k] = v_high.x;
1097
- vl[k++] = v_low.x;
1098
- vh[k] = v_high.y;
1099
- vl[k++] = v_low.y;
1100
- vh[k] = v_high.z;
1101
- vl[k++] = v_low.z;
1102
- vh[k] = v_high.x;
1103
- vl[k++] = v_low.x;
1104
- vh[k] = v_high.y;
1105
- vl[k++] = v_low.y;
1106
- vh[k] = v_high.z;
1107
- vl[k++] = v_low.z;
1108
- vh[k] = v_high.x;
1109
- vl[k++] = v_low.x;
1110
- vh[k] = v_high.y;
1111
- vl[k++] = v_low.y;
1112
- vh[k] = v_high.z;
1113
- vl[k++] = v_low.z;
1114
- }
1115
-
1116
- var first;
1117
- if (this._closedLine) {
1118
- first = path[0];
1119
- } else {
1120
- var l1 = path.length - 1;
1121
- first = new Vec3(
1122
- path[l1].x + path[l1].x - path[l1 - 1].x,
1123
- path[l1].y + path[l1].y - path[l1 - 1].y,
1124
- path[l1].z + path[l1].z - path[l1 - 1].z
1125
- );
1126
- }
1127
-
1128
- Vec3.doubleToTwoFloats(first, v_high, v_low);
1129
-
1130
- vh[k] = v_high.x;
1131
- vl[k++] = v_low.x;
1132
- vh[k] = v_high.y;
1133
- vl[k++] = v_low.y;
1134
- vh[k] = v_high.z;
1135
- vl[k++] = v_low.z;
1136
- vh[k] = v_high.x;
1137
- vl[k++] = v_low.x;
1138
- vh[k] = v_high.y;
1139
- vl[k++] = v_low.y;
1140
- vh[k] = v_high.z;
1141
- vl[k++] = v_low.z;
1142
- vh[k] = v_high.x;
1143
- vl[k++] = v_low.x;
1144
- vh[k] = v_high.y;
1145
- vl[k++] = v_low.y;
1146
- vh[k] = v_high.z;
1147
- vl[k++] = v_low.z;
1148
- vh[k] = v_high.x;
1149
- vl[k++] = v_low.x;
1150
- vh[k] = v_high.y;
1151
- vl[k++] = v_low.y;
1152
- vh[k] = v_high.z;
1153
- vl[k++] = v_low.z;
1154
- }
1155
- }
1156
-
1157
- /**
1158
- * Sets polyline with geodetic coordinates.
1159
- * @protected
1160
- * @param {LonLat[]} pathLonLat - Geodetic polyline path coordinates.
1161
- */
1162
- _setEqualPathLonLat(pathLonLat) {
1163
- var extent = this._extent;
1164
- extent.southWest.set(180.0, 90.0);
1165
- extent.northEast.set(-180.0, -90.0);
1166
-
1167
- var v_high = new Vec3(),
1168
- v_low = new Vec3();
1169
-
1170
- var vh = this._verticesHigh,
1171
- vl = this._verticesLow,
1172
- l = this._pathLonLat,
1173
- m = this._pathLonLatMerc,
1174
- c = this._path3v,
1175
- k = 0;
1176
-
1177
- var ellipsoid = this._renderNode.ellipsoid;
1178
-
1179
- for (var j = 0; j < pathLonLat.length; j++) {
1180
- var path = pathLonLat[j];
1181
-
1182
- var last;
1183
- if (this._closedLine) {
1184
- last = ellipsoid.lonLatToCartesian(path[path.length - 1]);
1185
- } else {
1186
- let p0 = ellipsoid.lonLatToCartesian(path[0]),
1187
- p1 = ellipsoid.lonLatToCartesian(path[1]);
1188
- last = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
1189
- }
1190
-
1191
- Vec3.doubleToTwoFloats(last, v_high, v_low);
1192
-
1193
- vh[k] = v_high.x;
1194
- vl[k++] = v_low.x;
1195
- vh[k] = v_high.y;
1196
- vl[k++] = v_low.y;
1197
- vh[k] = v_high.z;
1198
- vl[k++] = v_low.z;
1199
- vh[k] = v_high.x;
1200
- vl[k++] = v_low.x;
1201
- vh[k] = v_high.y;
1202
- vl[k++] = v_low.y;
1203
- vh[k] = v_high.z;
1204
- vl[k++] = v_low.z;
1205
- vh[k] = v_high.x;
1206
- vl[k++] = v_low.x;
1207
- vh[k] = v_high.y;
1208
- vl[k++] = v_low.y;
1209
- vh[k] = v_high.z;
1210
- vl[k++] = v_low.z;
1211
- vh[k] = v_high.x;
1212
- vl[k++] = v_low.x;
1213
- vh[k] = v_high.y;
1214
- vl[k++] = v_low.y;
1215
- vh[k] = v_high.z;
1216
- vl[k++] = v_low.z;
1217
-
1218
- for (var i = 0; i < path.length; i++) {
1219
- var cur = path[i];
1220
- var cartesian = ellipsoid.lonLatToCartesian(cur);
1221
- c[j][i] = cartesian;
1222
- m[j][i] = cur.forwardMercator();
1223
- l[j][i] = cur;
1224
-
1225
- Vec3.doubleToTwoFloats(cartesian, v_high, v_low);
1226
-
1227
- vh[k] = v_high.x;
1228
- vl[k++] = v_low.x;
1229
- vh[k] = v_high.y;
1230
- vl[k++] = v_low.y;
1231
- vh[k] = v_high.z;
1232
- vl[k++] = v_low.z;
1233
- vh[k] = v_high.x;
1234
- vl[k++] = v_low.x;
1235
- vh[k] = v_high.y;
1236
- vl[k++] = v_low.y;
1237
- vh[k] = v_high.z;
1238
- vl[k++] = v_low.z;
1239
- vh[k] = v_high.x;
1240
- vl[k++] = v_low.x;
1241
- vh[k] = v_high.y;
1242
- vl[k++] = v_low.y;
1243
- vh[k] = v_high.z;
1244
- vl[k++] = v_low.z;
1245
- vh[k] = v_high.x;
1246
- vl[k++] = v_low.x;
1247
- vh[k] = v_high.y;
1248
- vl[k++] = v_low.y;
1249
- vh[k] = v_high.z;
1250
- vl[k++] = v_low.z;
1251
-
1252
- if (cur.lon < extent.southWest.lon) {
1253
- extent.southWest.lon = cur.lon;
1254
- }
1255
- if (cur.lat < extent.southWest.lat) {
1256
- extent.southWest.lat = cur.lat;
1257
- }
1258
- if (cur.lon > extent.northEast.lon) {
1259
- extent.northEast.lon = cur.lon;
1260
- }
1261
- if (cur.lat > extent.northEast.lat) {
1262
- extent.northEast.lat = cur.lat;
1263
- }
1264
- }
1265
-
1266
- var first;
1267
- if (this._closedLine) {
1268
- first = ellipsoid.lonLatToCartesian(path[0]);
1269
- } else {
1270
- let p0 = ellipsoid.lonLatToCartesian(path[path.length - 1]),
1271
- p1 = ellipsoid.lonLatToCartesian(path[path.length - 2]);
1272
- first = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
1273
- }
1274
-
1275
- Vec3.doubleToTwoFloats(first, v_high, v_low);
1276
-
1277
- vh[k] = v_high.x;
1278
- vl[k++] = v_low.x;
1279
- vh[k] = v_high.y;
1280
- vl[k++] = v_low.y;
1281
- vh[k] = v_high.z;
1282
- vl[k++] = v_low.z;
1283
- vh[k] = v_high.x;
1284
- vl[k++] = v_low.x;
1285
- vh[k] = v_high.y;
1286
- vl[k++] = v_low.y;
1287
- vh[k] = v_high.z;
1288
- vl[k++] = v_low.z;
1289
- vh[k] = v_high.x;
1290
- vl[k++] = v_low.x;
1291
- vh[k] = v_high.y;
1292
- vl[k++] = v_low.y;
1293
- vh[k] = v_high.z;
1294
- vl[k++] = v_low.z;
1295
- vh[k] = v_high.x;
1296
- vl[k++] = v_low.x;
1297
- vh[k] = v_high.y;
1298
- vl[k++] = v_low.y;
1299
- vh[k] = v_high.z;
1300
- vl[k++] = v_low.z;
1301
- }
1302
- }
1303
-
1304
- setPointLonLat(lonlat, index, segmentIndex) {
1305
- if (this._renderNode && this._renderNode.ellipsoid) {
1306
- let l = this._pathLonLat,
1307
- m = this._pathLonLatMerc;
1308
-
1309
- l[segmentIndex][index] = lonlat;
1310
- m[segmentIndex][index] = lonlat.forwardMercator();
1311
-
1312
- //
1313
- // Apply new extent(TODO: think about optimization)
1314
- //
1315
- var extent = this._extent;
1316
- extent.southWest.set(180.0, 90.0);
1317
- extent.northEast.set(-180.0, -90.0);
1318
- for (var i = 0; i < l.length; i++) {
1319
- var pi = l[i];
1320
- for (var j = 0; j < pi.length; j++) {
1321
- var lon = pi[j].lon,
1322
- lat = pi[j].lat;
1323
- if (lon > extent.northEast.lon) {
1324
- extent.northEast.lon = lon;
1325
- }
1326
- if (lat > extent.northEast.lat) {
1327
- extent.northEast.lat = lat;
1328
- }
1329
- if (lon < extent.southWest.lon) {
1330
- extent.southWest.lon = lon;
1331
- }
1332
- if (lat < extent.southWest.lat) {
1333
- extent.southWest.lat = lat;
1334
- }
1335
- }
1336
- }
1337
-
1338
- this.setPoint3v(
1339
- this._renderNode.ellipsoid.lonLatToCartesian(lonlat),
1340
- index,
1341
- segmentIndex,
1342
- true
1343
- );
1344
- } else {
1345
- let path = this._pathLonLat[segmentIndex];
1346
- path[index].lon = lonlat.lon;
1347
- path[index].lat = lonlat.lat;
1348
- path[index].height = lonlat.height;
1349
- }
1350
- }
1351
-
1352
- setPoint3v(coordinates, index, segmentIndex, skipLonLat) {
1353
- segmentIndex = segmentIndex || 0;
1354
-
1355
- if (this._renderNode) {
1356
- var v_high = new Vec3(),
1357
- v_low = new Vec3();
1358
-
1359
- var vh = this._verticesHigh,
1360
- vl = this._verticesLow,
1361
- l = this._pathLonLat,
1362
- m = this._pathLonLatMerc,
1363
- k = 0,
1364
- kk = 0;
1365
-
1366
- //for (var i = 0; i < segmentIndex; i++) {
1367
- // kk += this._path3v[i].length * 12 + 24;
1368
- //}
1369
- kk = this._pathLengths[segmentIndex] * 12 + 24 * segmentIndex;
1370
-
1371
- let path = this._path3v[segmentIndex];
1372
-
1373
- path[index].x = coordinates.x;
1374
- path[index].y = coordinates.y;
1375
- path[index].z = coordinates.z;
1376
-
1377
- let _closedLine = this._closedLine || path.length === 1;
1378
-
1379
- if (index === 0 || index === 1) {
1380
- var last;
1381
- if (_closedLine) {
1382
- last = path[path.length - 1];
1383
- } else {
1384
- last = new Vec3(
1385
- path[0].x + path[0].x - path[1].x,
1386
- path[0].y + path[0].y - path[1].y,
1387
- path[0].z + path[0].z - path[1].z
1388
- );
1389
- }
1390
-
1391
- k = kk;
1392
-
1393
- Vec3.doubleToTwoFloats(last, v_high, v_low);
1394
-
1395
- vh[k] = v_high.x;
1396
- vh[k + 1] = v_high.y;
1397
- vh[k + 2] = v_high.z;
1398
- vh[k + 3] = v_high.x;
1399
- vh[k + 4] = v_high.y;
1400
- vh[k + 5] = v_high.z;
1401
- vh[k + 6] = v_high.x;
1402
- vh[k + 7] = v_high.y;
1403
- vh[k + 8] = v_high.z;
1404
- vh[k + 9] = v_high.x;
1405
- vh[k + 10] = v_high.y;
1406
- vh[k + 11] = v_high.z;
1407
-
1408
- vl[k] = v_low.x;
1409
- vl[k + 1] = v_low.y;
1410
- vl[k + 2] = v_low.z;
1411
- vl[k + 3] = v_low.x;
1412
- vl[k + 4] = v_low.y;
1413
- vl[k + 5] = v_low.z;
1414
- vl[k + 6] = v_low.x;
1415
- vl[k + 7] = v_low.y;
1416
- vl[k + 8] = v_low.z;
1417
- vl[k + 9] = v_low.x;
1418
- vl[k + 10] = v_low.y;
1419
- vl[k + 11] = v_low.z;
1420
- }
1421
-
1422
- if (!skipLonLat && this._renderNode.ellipsoid) {
1423
- var lonLat = this._renderNode.ellipsoid.cartesianToLonLat(coordinates);
1424
- l[segmentIndex][index] = lonLat;
1425
- m[segmentIndex][index] = lonLat.forwardMercator();
1426
-
1427
- //
1428
- // Apply new extent(TODO: think about optimization)
1429
- //
1430
- var extent = this._extent;
1431
- extent.southWest.set(180.0, 90.0);
1432
- extent.northEast.set(-180.0, -90.0);
1433
- for (let i = 0; i < l.length; i++) {
1434
- var pi = l[i];
1435
- for (var j = 0; j < pi.length; j++) {
1436
- var lon = pi[j].lon,
1437
- lat = pi[j].lat;
1438
- if (lon > extent.northEast.lon) {
1439
- extent.northEast.lon = lon;
1440
- }
1441
- if (lat > extent.northEast.lat) {
1442
- extent.northEast.lat = lat;
1443
- }
1444
- if (lon < extent.southWest.lon) {
1445
- extent.southWest.lon = lon;
1446
- }
1447
- if (lat < extent.southWest.lat) {
1448
- extent.southWest.lat = lat;
1449
- }
1450
- }
1451
- }
1452
- }
1453
-
1454
- k = kk + index * 12 + 12;
1455
-
1456
- Vec3.doubleToTwoFloats(coordinates, v_high, v_low);
1457
-
1458
- vh[k] = v_high.x;
1459
- vh[k + 1] = v_high.y;
1460
- vh[k + 2] = v_high.z;
1461
- vh[k + 3] = v_high.x;
1462
- vh[k + 4] = v_high.y;
1463
- vh[k + 5] = v_high.z;
1464
- vh[k + 6] = v_high.x;
1465
- vh[k + 7] = v_high.y;
1466
- vh[k + 8] = v_high.z;
1467
- vh[k + 9] = v_high.x;
1468
- vh[k + 10] = v_high.y;
1469
- vh[k + 11] = v_high.z;
1470
-
1471
- vl[k] = v_low.x;
1472
- vl[k + 1] = v_low.y;
1473
- vl[k + 2] = v_low.z;
1474
- vl[k + 3] = v_low.x;
1475
- vl[k + 4] = v_low.y;
1476
- vl[k + 5] = v_low.z;
1477
- vl[k + 6] = v_low.x;
1478
- vl[k + 7] = v_low.y;
1479
- vl[k + 8] = v_low.z;
1480
- vl[k + 9] = v_low.x;
1481
- vl[k + 10] = v_low.y;
1482
- vl[k + 11] = v_low.z;
1483
-
1484
- if (index === path.length - 1 || index === path.length - 2) {
1485
- var first;
1486
- if (_closedLine) {
1487
- first = path[0];
1488
- } else {
1489
- var l1 = path.length - 1;
1490
- first = new Vec3(
1491
- path[l1].x + path[l1].x - path[l1 - 1].x,
1492
- path[l1].y + path[l1].y - path[l1 - 1].y,
1493
- path[l1].z + path[l1].z - path[l1 - 1].z
1494
- );
1495
- }
1496
-
1497
- k = kk + path.length * 12 + 12;
1498
-
1499
- Vec3.doubleToTwoFloats(first, v_high, v_low);
1500
-
1501
- vh[k] = v_high.x;
1502
- vh[k + 1] = v_high.y;
1503
- vh[k + 2] = v_high.z;
1504
- vh[k + 3] = v_high.x;
1505
- vh[k + 4] = v_high.y;
1506
- vh[k + 5] = v_high.z;
1507
- vh[k + 6] = v_high.x;
1508
- vh[k + 7] = v_high.y;
1509
- vh[k + 8] = v_high.z;
1510
- vh[k + 9] = v_high.x;
1511
- vh[k + 10] = v_high.y;
1512
- vh[k + 11] = v_high.z;
1513
-
1514
- vl[k] = v_low.x;
1515
- vl[k + 1] = v_low.y;
1516
- vl[k + 2] = v_low.z;
1517
- vl[k + 3] = v_low.x;
1518
- vl[k + 4] = v_low.y;
1519
- vl[k + 5] = v_low.z;
1520
- vl[k + 6] = v_low.x;
1521
- vl[k + 7] = v_low.y;
1522
- vl[k + 8] = v_low.z;
1523
- vl[k + 9] = v_low.x;
1524
- vl[k + 10] = v_low.y;
1525
- vl[k + 11] = v_low.z;
1526
- }
1527
-
1528
- this._changedBuffers[VERTICES_BUFFER] = true;
1529
- } else {
1530
- let path = this._path3v[segmentIndex];
1531
- path[index].x = coordinates.x;
1532
- path[index].y = coordinates.y;
1533
- path[index].z = coordinates.z;
1534
- }
1535
- }
1536
-
1537
- _resizePathLengths(index = 0) {
1538
- this._pathLengths[0] = 0;
1539
- for (let i = index + 1, len = this._path3v.length; i <= len; i++) {
1540
- this._pathLengths[i] = this._pathLengths[i - 1] + this._path3v[i - 1].length;
1541
- }
1542
- }
1543
-
1544
- removeSegment(index) {
1545
- this._path3v.splice(index, 1);
1546
- this.setPath3v([].concat(this._path3v));
1547
- }
1548
-
1549
- removePoint(index, multiLineIndex = 0) {
1550
- this._path3v[multiLineIndex].splice(index, 1);
1551
- if (this._path3v[multiLineIndex].length === 0) {
1552
- this._path3v.splice(multiLineIndex, 1);
1553
- }
1554
- this.setPath3v([].concat(this._path3v));
1555
- }
1556
-
1557
- insertPoint3v(point3v, index = 0, color, multilineIndex = 0) {
1558
- let p = [].concat(this._path3v),
1559
- pp = p[multilineIndex];
1560
- if (pp) {
1561
- let c = [].concat(this._pathColors);
1562
-
1563
- pp.splice(index, 0, point3v);
1564
-
1565
- if (color) {
1566
- let cc = c[multilineIndex];
1567
- if (!cc) {
1568
- cc = new Array(pp.length);
1569
- }
1570
- cc.splice(index, 0, color);
1571
- }
1572
-
1573
- this.setPath3v(p, c);
1574
- } else {
1575
- this.addPoint3v(point3v, multilineIndex);
1576
- }
1577
- }
1578
-
1579
- /**
1580
- * Adds a new cartesian point in the end of the path in a last line segment.
1581
- * @public
1582
- * @param {Vec3} point3v - New coordinate.
1583
- */
1584
- appendPoint3v(point3v, color, skipEllipsoid) {
1585
- if (this._path3v.length === 0) {
1586
- this._pathColors.push([color || this._defaultColor]);
1587
- this.addPoint3v(point3v);
1588
- } else {
1589
- //
1590
- // Making typedArrays suitable for appendPoint function
1591
- //
1592
- this._verticesHigh = makeArray(this._verticesHigh);
1593
- this._verticesLow = makeArray(this._verticesLow);
1594
- this._colors = makeArray(this._colors);
1595
- this._orders = makeArray(this._orders);
1596
- this._indexes = makeArray(this._indexes);
1597
-
1598
- Polyline.appendPoint3v(
1599
- this._path3v,
1600
- point3v,
1601
- this._pathColors,
1602
- color || this._defaultColor,
1603
- this._closedLine,
1604
- this._verticesHigh,
1605
- this._verticesLow,
1606
- this._colors,
1607
- this._orders,
1608
- this._indexes,
1609
- !skipEllipsoid && this._renderNode.ellipsoid,
1610
- this._pathLonLat,
1611
- this._pathLonLatMerc,
1612
- this._extent
1613
- );
1614
-
1615
- this._pathLengths[this._path3v.length] += 1;
1616
-
1617
- this._changedBuffers[VERTICES_BUFFER] = true;
1618
- this._changedBuffers[COLORS_BUFFER] = true;
1619
- this._changedBuffers[INDEX_BUFFER] = true;
1620
- }
1621
- }
1622
-
1623
- /**
1624
- * Adds a new cartesian point in the end of the path.
1625
- * @public
1626
- * @param {Vec3} point3v - New coordinate.
1627
- * @param {number} [multiLineIndex=0] - Path part index, first by default.
1628
- */
1629
- addPoint3v(point3v, multiLineIndex = 0) {
1630
- //
1631
- // TODO: could be optimized
1632
- //
1633
- if (multiLineIndex >= this._path3v.length) {
1634
- this._path3v.push([]);
1635
- }
1636
- this._path3v[multiLineIndex].push(point3v);
1637
- this.setPath3v([].concat(this._path3v));
1638
- }
1639
-
1640
- /**
1641
- * Adds a new geodetic point in the end of the path.
1642
- * @public
1643
- * @param {LonLat} lonLat - New coordinate.
1644
- * @param {number} [multiLineIndex=0] - Path part index, first by default.
1645
- */
1646
- addPointLonLat(lonLat, multiLineIndex = 0) {
1647
- //
1648
- // TODO: could be optimized
1649
- //
1650
- if (multiLineIndex >= this._pathLonLat.length) {
1651
- this._pathLonLat.push([]);
1652
- }
1653
- this._pathLonLat[multiLineIndex].push(lonLat);
1654
- this.setPathLonLat([].concat(this._pathLonLat));
1655
- }
1656
-
1657
- /**
1658
- * Clear Polyline object data.
1659
- * @public
1660
- */
1661
- clear() {
1662
- this._clearData();
1663
- }
1664
-
1665
- setPointColor(color, index = 0, segmentIndex = 0) {
1666
- if (this._renderNode && index < this._path3v[segmentIndex].length) {
1667
- let colors = this._pathColors[segmentIndex];
1668
-
1669
- if (!colors) {
1670
- if (this._path3v[segmentIndex] && index < this._path3v[segmentIndex].length) {
1671
- this._pathColors[segmentIndex] = new Array(this._path3v[segmentIndex].length);
1672
- } else {
1673
- return;
1674
- }
1675
- }
1676
-
1677
- if (!colors[index]) {
1678
- colors[index] = [color[R], color[G], color[B], color[A] || 1.0];
1679
- } else {
1680
- colors[index][R] = color[R];
1681
- colors[index][G] = color[G];
1682
- colors[index][B] = color[B];
1683
- colors[index][A] = color[A] || 1.0;
1684
- }
1685
-
1686
- let c = this._colors;
1687
-
1688
- //optimized with this._pathLengths
1689
- //for (var i = 0; i < segmentIndex; i++) {
1690
- // kk += this._path3v[i].length * 16 + 32;
1691
- //}
1692
-
1693
- let k = index * 16 + this._pathLengths[segmentIndex] * 16 + 32 * segmentIndex;
1694
-
1695
- c[k] = c[k + 4] = c[k + 8] = c[k + 12] = color[R];
1696
- c[k + 1] = c[k + 5] = c[k + 9] = c[k + 13] = color[G];
1697
- c[k + 2] = c[k + 6] = c[k + 10] = c[k + 14] = color[B];
1698
- c[k + 3] = c[k + 7] = c[k + 11] = c[k + 15] = color[A] || 1.0;
1699
-
1700
- this._changedBuffers[COLORS_BUFFER] = true;
1701
- } else {
1702
- let pathColors = this._pathColors[segmentIndex];
1703
- pathColors[index] = color;
1704
- }
1705
- }
1706
-
1707
- /**
1708
- * Sets Polyline opacity.
1709
- * @public
1710
- * @param {number} opacity - Opacity.
1711
- */
1712
- setOpacity(opacity) {
1713
- this.color.w = opacity;
1714
- }
1715
-
1716
- /**
1717
- * Sets Polyline thickness in screen pixels.
1718
- * @public
1719
- * @param {number} thickness - Thickness.
1720
- */
1721
- setThickness(thickness) {
1722
- this.thickness = thickness;
1723
- }
1724
-
1725
- /**
1726
- * Returns thickness.
1727
- * @public
1728
- * @return {number} Thickness in screen pixels.
1729
- */
1730
- getThickness() {
1731
- return this.thickness;
1732
- }
1733
-
1734
- /**
1735
- * Sets visibility.
1736
- * @public
1737
- * @param {boolean} visibility - Polyline visibility.
1738
- */
1739
- setVisibility(visibility) {
1740
- this.visibility = visibility;
1741
- }
1742
-
1743
- /**
1744
- * Gets Polyline visibility.
1745
- * @public
1746
- * @return {boolean} Polyline visibility.
1747
- */
1748
- getVisibility() {
1749
- return this.visibility;
1750
- }
1751
-
1752
- /**
1753
- * Assign with render node.
1754
- * @public
1755
- * @param {RenderNode} renderNode -
1756
- */
1757
- setRenderNode(renderNode) {
1758
- if (renderNode) {
1759
- this._renderNode = renderNode;
1760
- if (this._pathLonLat.length) {
1761
- this._createDataLonLat([].concat(this._pathLonLat));
1762
- } else {
1763
- this._createData3v([].concat(this._path3v));
1764
- }
1765
- this._refresh();
1766
- this._update();
1767
- }
1768
- }
1769
-
1770
- /**
1771
- * @protected
1772
- */
1773
- _clearData() {
1774
- this._verticesHigh = null;
1775
- this._verticesLow = null;
1776
- this._orders = null;
1777
- this._indexes = null;
1778
- this._colors = null;
1779
-
1780
- this._verticesHigh = [];
1781
- this._verticesLow = [];
1782
- this._orders = [];
1783
- this._indexes = [];
1784
- this._colors = [];
1785
-
1786
- this._path3v.length = 0;
1787
- this._pathLonLat.length = 0;
1788
- this._pathLonLatMerc.length = 0;
1789
-
1790
- this._path3v = [];
1791
- this._pathLonLat = [];
1792
- this._pathLonLatMerc = [];
1793
- }
1794
-
1795
- _createData3v(path3v) {
1796
- this._clearData();
1797
- Polyline.appendLineData3v(
1798
- path3v,
1799
- this._pathColors,
1800
- this._defaultColor,
1801
- this._closedLine,
1802
- this._verticesHigh,
1803
- this._verticesLow,
1804
- this._orders,
1805
- this._indexes,
1806
- this._renderNode.ellipsoid,
1807
- this._pathLonLat,
1808
- this._path3v,
1809
- this._pathLonLatMerc,
1810
- this._extent,
1811
- this._colors
1812
- );
1813
- this._resizePathLengths(0);
1814
- }
1815
-
1816
- _createDataLonLat(pathLonlat) {
1817
- this._clearData();
1818
- Polyline.appendLineDataLonLat(
1819
- pathLonlat,
1820
- this._pathColors,
1821
- this._defaultColor,
1822
- this._closedLine,
1823
- this._verticesHigh,
1824
- this._verticesLow,
1825
- this._orders,
1826
- this._indexes,
1827
- this._renderNode.ellipsoid,
1828
- this._path3v,
1829
- this._pathLonLat,
1830
- this._pathLonLatMerc,
1831
- this._extent,
1832
- this._colors
1833
- );
1834
- this._resizePathLengths(0);
1835
- }
1836
-
1837
- /**
1838
- * Removes from an entity.
1839
- * @public
1840
- */
1841
- remove() {
1842
- this._entity = null;
1843
-
1844
- this._pathColors.length = 0;
1845
- this._pathColors = [];
1846
-
1847
- this._verticesHigh = null;
1848
- this._verticesLow = null;
1849
- this._orders = null;
1850
- this._indexes = null;
1851
- this._colors = null;
1852
-
1853
- this._verticesHigh = [];
1854
- this._verticesLow = [];
1855
- this._orders = [];
1856
- this._indexes = [];
1857
- this._colors = [];
1858
-
1859
- this._deleteBuffers();
1860
-
1861
- this._handler && this._handler.remove(this);
1862
- }
1863
-
1864
- setPickingColor3v(color) {
1865
- this._pickingColor[0] = color.x / 255.0;
1866
- this._pickingColor[1] = color.y / 255.0;
1867
- this._pickingColor[2] = color.z / 255.0;
1868
- }
1869
-
1870
- /**
1871
- * Returns polyline geodetic extent.
1872
- * @public
1873
- * @returns {Extent} - Geodetic extent
1874
- */
1875
- getExtent() {
1876
- return this._extent.clone();
1877
- }
1878
-
1879
- /**
1880
- * Returns path cartesian coordinates.
1881
- * @return {Array.<Vec3>} Polyline path.
1882
- */
1883
- getPath3v() {
1884
- return this._path3v;
1885
- }
1886
-
1887
- /**
1888
- * Returns geodetic path coordinates.
1889
- * @return {Array.<LonLat>} Polyline path.
1890
- */
1891
- getPathLonLat() {
1892
- return this._pathLonLat;
1893
- }
1894
-
1895
- getPathColors() {
1896
- return this._pathColors;
1897
- }
1898
-
1899
- setPathColors(pathColors) {
1900
- if (this._renderNode) {
1901
- // ...
1902
- }
1903
- }
1904
-
1905
- setColorHTML(htmlColor) {
1906
- this._defaultColor = htmlColorToFloat32Array(htmlColor);
1907
-
1908
- let color = htmlColorToRgba(htmlColor),
1909
- p = this._pathColors;
1910
-
1911
- for (let i = 0, len = p.length; i < len; i++) {
1912
- let s = p[i];
1913
- for (let j = 0, slen = s.length; j < slen; j++) {
1914
- s[j][0] = color.x;
1915
- s[j][1] = color.y;
1916
- s[j][2] = color.z;
1917
- s[j][3] = color.w;
1918
- }
1919
- }
1920
-
1921
- let c = this._colors;
1922
- for (let i = 0, len = c.length; i < len; i += 4) {
1923
- c[i] = color.x;
1924
- c[i + 1] = color.y;
1925
- c[i + 2] = color.z;
1926
- c[i + 3] = color.w;
1927
- }
1928
-
1929
- this._changedBuffers[COLORS_BUFFER] = true;
1930
- }
1931
-
1932
- /**
1933
- * Sets geodetic coordinates.
1934
- * @public
1935
- * @param {Array.<Array.<number>>} pathLonLat - Polyline path cartesian coordinates. (exactly 3 entries)
1936
- * @param {Boolean} [forceEqual=false] - Makes assigning faster for size equal coordinates array.
1937
- */
1938
- setPathLonLat(pathLonLat, forceEqual) {
1939
- if (this._renderNode && this._renderNode.ellipsoid) {
1940
- if (forceEqual) {
1941
- this._setEqualPathLonLat(pathLonLat);
1942
- this._changedBuffers[VERTICES_BUFFER] = true;
1943
- this._changedBuffers[COLORS_BUFFER] = true;
1944
- } else {
1945
- this._createDataLonLat(pathLonLat);
1946
- this._changedBuffers[VERTICES_BUFFER] = true;
1947
- this._changedBuffers[INDEX_BUFFER] = true;
1948
- this._changedBuffers[COLORS_BUFFER] = true;
1949
- }
1950
- } else {
1951
- this._pathLonLat = [].concat(pathLonLat);
1952
- }
1953
- }
1954
-
1955
- /**
1956
- * Sets Polyline cartesian coordinates.
1957
- * @public
1958
- * @param {Array.<Array.<number>>} path3v - Polyline path cartesian coordinates. (exactly 3 entries)
1959
- * @param {Boolean} [forceEqual=false] - Makes assigning faster for size equal coordinates array.
1960
- */
1961
- setPath3v(path3v, pathColors, forceEqual) {
1962
- if (pathColors) {
1963
- this._pathColors = [].concat(pathColors);
1964
- }
1965
-
1966
- if (this._renderNode) {
1967
- if (forceEqual) {
1968
- this._setEqualPath3v(path3v);
1969
- this._changedBuffers[VERTICES_BUFFER] = true;
1970
- this._changedBuffers[COLORS_BUFFER] = true;
1971
- } else {
1972
- this._createData3v(path3v);
1973
- this._changedBuffers[VERTICES_BUFFER] = true;
1974
- this._changedBuffers[INDEX_BUFFER] = true;
1975
- this._changedBuffers[COLORS_BUFFER] = true;
1976
- }
1977
- } else {
1978
- this._path3v = [].concat(path3v);
1979
- }
1980
- }
1981
-
1982
- draw() {
1983
- if (this.visibility && this._path3v.length) {
1984
- this._update();
1985
-
1986
- var rn = this._renderNode;
1987
- var r = rn.renderer;
1988
- var sh = r.handler.programs.polyline_screen;
1989
- var p = sh._program;
1990
- var gl = r.handler.gl,
1991
- sha = p.attributes,
1992
- shu = p.uniforms;
1993
-
1994
- sh.activate();
1995
-
1996
- gl.polygonOffset(
1997
- this._handler._entityCollection.polygonOffsetFactor,
1998
- this._handler._entityCollection.polygonOffsetUnits
1999
- );
2000
-
2001
- gl.enable(gl.BLEND);
2002
- gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
2003
- gl.blendFuncSeparate(
2004
- gl.SRC_ALPHA,
2005
- gl.ONE_MINUS_SRC_ALPHA,
2006
- gl.ONE,
2007
- gl.ONE_MINUS_SRC_ALPHA
2008
- );
2009
- gl.disable(gl.CULL_FACE);
2010
-
2011
- gl.uniformMatrix4fv(shu.proj, false, r.activeCamera.getProjectionMatrix());
2012
- gl.uniformMatrix4fv(shu.view, false, r.activeCamera.getViewMatrix());
2013
-
2014
- // gl.uniform4fv(shu.color, [this.color.x, this.color.y, this.color.z, this.color.w * this._handler._entityCollection._fadingOpacity]);
2015
-
2016
- gl.uniform3fv(shu.eyePositionHigh, r.activeCamera.eyeHigh);
2017
- gl.uniform3fv(shu.eyePositionLow, r.activeCamera.eyeLow);
2018
-
2019
- gl.uniform2fv(shu.uFloatParams, [
2020
- rn._planetRadius2 || 0.0,
2021
- r.activeCamera._tanViewAngle_hradOneByHeight
2022
- ]);
2023
- gl.uniform2fv(shu.viewport, [r.handler.canvas.width, r.handler.canvas.height]);
2024
- gl.uniform1f(shu.thickness, this.thickness * 0.5);
2025
- gl.uniform1f(shu.opacity, this._handler._entityCollection._fadingOpacity);
2026
-
2027
- gl.bindBuffer(gl.ARRAY_BUFFER, this._colorsBuffer);
2028
- gl.vertexAttribPointer(sha.color, this._colorsBuffer.itemSize, gl.FLOAT, false, 0, 0);
2029
-
2030
- var v = this._verticesHighBuffer;
2031
- gl.bindBuffer(gl.ARRAY_BUFFER, v);
2032
- gl.vertexAttribPointer(sha.prevHigh, v.itemSize, gl.FLOAT, false, 12, 0);
2033
- gl.vertexAttribPointer(sha.currentHigh, v.itemSize, gl.FLOAT, false, 12, 48);
2034
- gl.vertexAttribPointer(sha.nextHigh, v.itemSize, gl.FLOAT, false, 12, 96);
2035
-
2036
- v = this._verticesLowBuffer;
2037
- gl.bindBuffer(gl.ARRAY_BUFFER, v);
2038
- gl.vertexAttribPointer(sha.prevLow, v.itemSize, gl.FLOAT, false, 12, 0);
2039
- gl.vertexAttribPointer(sha.currentLow, v.itemSize, gl.FLOAT, false, 12, 48);
2040
- gl.vertexAttribPointer(sha.nextLow, v.itemSize, gl.FLOAT, false, 12, 96);
2041
-
2042
- gl.bindBuffer(gl.ARRAY_BUFFER, this._ordersBuffer);
2043
- gl.vertexAttribPointer(sha.order, this._ordersBuffer.itemSize, gl.FLOAT, false, 4, 0);
2044
-
2045
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexesBuffer);
2046
- gl.drawElements(gl.TRIANGLE_STRIP, this._indexesBuffer.numItems, gl.UNSIGNED_INT, 0);
2047
- }
2048
- }
2049
-
2050
- drawPicking() {
2051
- if (this.visibility && this._path3v.length) {
2052
- var rn = this._renderNode;
2053
- var r = rn.renderer;
2054
- var sh = r.handler.programs.polyline_picking;
2055
- var p = sh._program;
2056
- var gl = r.handler.gl,
2057
- sha = p.attributes,
2058
- shu = p.uniforms;
2059
-
2060
- sh.activate();
2061
-
2062
- gl.polygonOffset(
2063
- this._handler._entityCollection.polygonOffsetFactor,
2064
- this._handler._entityCollection.polygonOffsetUnits
2065
- );
2066
-
2067
- gl.enable(gl.BLEND);
2068
- gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
2069
- gl.blendFuncSeparate(
2070
- gl.SRC_ALPHA,
2071
- gl.ONE_MINUS_SRC_ALPHA,
2072
- gl.ONE,
2073
- gl.ONE_MINUS_SRC_ALPHA
2074
- );
2075
- gl.disable(gl.CULL_FACE);
2076
-
2077
- gl.uniformMatrix4fv(shu.proj, false, r.activeCamera.getProjectionMatrix());
2078
- gl.uniformMatrix4fv(shu.view, false, r.activeCamera.getViewMatrix());
2079
-
2080
- gl.uniform4fv(shu.color, [
2081
- this._pickingColor[0],
2082
- this._pickingColor[1],
2083
- this._pickingColor[2],
2084
- 1.0
2085
- ]);
2086
-
2087
- gl.uniform3fv(shu.eyePositionHigh, r.activeCamera.eyeHigh);
2088
- gl.uniform3fv(shu.eyePositionLow, r.activeCamera.eyeLow);
2089
-
2090
- gl.uniform2fv(shu.uFloatParams, [
2091
- rn._planetRadius2 || 0.0,
2092
- r.activeCamera._tanViewAngle_hradOneByHeight
2093
- ]);
2094
- gl.uniform2fv(shu.viewport, [r.handler.canvas.width, r.handler.canvas.height]);
2095
- gl.uniform1f(shu.thickness, this.thickness * 0.5);
2096
-
2097
- var v = this._verticesHighBuffer;
2098
- gl.bindBuffer(gl.ARRAY_BUFFER, v);
2099
- gl.vertexAttribPointer(sha.prevHigh, v.itemSize, gl.FLOAT, false, 12, 0);
2100
- gl.vertexAttribPointer(sha.currentHigh, v.itemSize, gl.FLOAT, false, 12, 48);
2101
- gl.vertexAttribPointer(sha.nextHigh, v.itemSize, gl.FLOAT, false, 12, 96);
2102
-
2103
- v = this._verticesLowBuffer;
2104
- gl.bindBuffer(gl.ARRAY_BUFFER, v);
2105
- gl.vertexAttribPointer(sha.prevLow, v.itemSize, gl.FLOAT, false, 12, 0);
2106
- gl.vertexAttribPointer(sha.currentLow, v.itemSize, gl.FLOAT, false, 12, 48);
2107
- gl.vertexAttribPointer(sha.nextLow, v.itemSize, gl.FLOAT, false, 12, 96);
2108
-
2109
- gl.bindBuffer(gl.ARRAY_BUFFER, this._ordersBuffer);
2110
- gl.vertexAttribPointer(sha.order, this._ordersBuffer.itemSize, gl.FLOAT, false, 4, 0);
2111
-
2112
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexesBuffer);
2113
- gl.drawElements(gl.TRIANGLE_STRIP, this._indexesBuffer.numItems, gl.UNSIGNED_INT, 0);
2114
- }
2115
- }
2116
-
2117
- /**
2118
- * Refresh buffers.
2119
- * @protected
2120
- */
2121
- _refresh() {
2122
- var i = this._changedBuffers.length;
2123
- while (i--) {
2124
- this._changedBuffers[i] = true;
2125
- }
2126
- }
2127
-
2128
- /**
2129
- * Updates render buffers.
2130
- * @protected
2131
- */
2132
- _update() {
2133
- if (this._renderNode) {
2134
- var i = this._changedBuffers.length;
2135
- while (i--) {
2136
- if (this._changedBuffers[i]) {
2137
- this._buffersUpdateCallbacks[i].call(this);
2138
- this._changedBuffers[i] = false;
2139
- }
2140
- }
2141
- }
2142
- }
2143
-
2144
- /**
2145
- * Clear GL buffers.
2146
- * @protected
2147
- */
2148
- _deleteBuffers() {
2149
- if (this._renderNode) {
2150
- var r = this._renderNode.renderer,
2151
- gl = r.handler.gl;
2152
-
2153
- gl.deleteBuffer(this._verticesHighBuffer);
2154
- gl.deleteBuffer(this._verticesLowBuffer);
2155
- gl.deleteBuffer(this._ordersBuffer);
2156
- gl.deleteBuffer(this._indexesBuffer);
2157
- gl.deleteBuffer(this._colorsBuffer);
2158
-
2159
- this._verticesHighBuffer = null;
2160
- this._verticesLowBuffer = null;
2161
- this._ordersBuffer = null;
2162
- this._indexesBuffer = null;
2163
- this._colorsBuffer = null;
2164
- }
2165
- }
2166
-
2167
- /**
2168
- * Creates gl main data buffer.
2169
- * @protected
2170
- */
2171
- _createVerticesBuffer() {
2172
- var h = this._renderNode.renderer.handler;
2173
-
2174
- let numItems = this._verticesHigh.length / 3;
2175
-
2176
- if (!this._verticesHighBuffer || this._verticesHighBuffer.numItems !== numItems) {
2177
- h.gl.deleteBuffer(this._verticesHighBuffer);
2178
- h.gl.deleteBuffer(this._verticesLowBuffer);
2179
- this._verticesHighBuffer = h.createStreamArrayBuffer(3, numItems);
2180
- this._verticesLowBuffer = h.createStreamArrayBuffer(3, numItems);
2181
- }
2182
-
2183
- this._verticesHigh = makeArrayTyped(this._verticesHigh);
2184
- this._verticesLow = makeArrayTyped(this._verticesLow);
2185
-
2186
- h.setStreamArrayBuffer(this._verticesHighBuffer, this._verticesHigh);
2187
- h.setStreamArrayBuffer(this._verticesLowBuffer, this._verticesLow);
2188
- }
2189
-
2190
- /**
2191
- * Creates gl index and order buffer.
2192
- * @protected
2193
- */
2194
- _createIndexBuffer() {
2195
- var h = this._renderNode.renderer.handler;
2196
- h.gl.deleteBuffer(this._ordersBuffer);
2197
- h.gl.deleteBuffer(this._indexesBuffer);
2198
-
2199
- this._orders = makeArrayTyped(this._orders);
2200
-
2201
- this._ordersBuffer = h.createArrayBuffer(this._orders, 1, this._orders.length / 2);
2202
-
2203
- this._indexes = makeArrayTyped(this._indexes, Uint32Array);
2204
-
2205
- this._indexesBuffer = h.createElementArrayBuffer(this._indexes, 1, this._indexes.length);
2206
- }
2207
-
2208
- _createColorsBuffer() {
2209
- var h = this._renderNode.renderer.handler;
2210
- h.gl.deleteBuffer(this._colorsBuffer);
2211
-
2212
- this._colors = makeArrayTyped(this._colors);
2213
-
2214
- this._colorsBuffer = h.createArrayBuffer(
2215
- new Float32Array(this._colors),
2216
- 4,
2217
- this._colors.length / 4
2218
- );
2219
- }
2220
- }
2221
-
2222
- export { Polyline };
1
+ /**
2
+ * @module og/entity/Polyline
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import {
8
+ makeArrayTyped,
9
+ makeArray,
10
+ htmlColorToFloat32Array,
11
+ htmlColorToRgba,
12
+ cloneArray
13
+ } from "../utils/shared.js";
14
+ import { Extent } from "../Extent.js";
15
+ import { LonLat } from "../LonLat.js";
16
+ import { Vec3 } from "../math/Vec3.js";
17
+
18
+ window.POLYLINE_DEPTH_OFFSET = 0.0;
19
+
20
+ const VERTICES_BUFFER = 0;
21
+ const INDEX_BUFFER = 1;
22
+ const COLORS_BUFFER = 2;
23
+
24
+ const DEFAULT_COLOR = "#0000FF";
25
+
26
+ const R = 0;
27
+ const G = 1;
28
+ const B = 2;
29
+ const A = 3;
30
+
31
+ /**
32
+ * Polyline object.
33
+ * @class
34
+ * @param {Object} [options] - Polyline options:
35
+ * @param {number} [options.thickness] - Thickness in screen pixels 1.5 is default.
36
+ * @param {Number} [options.altitude] - Relative to ground layers altitude value.
37
+ * @param {Vec4} [options.color] - RGBA color.
38
+ * @param {Boolean} [options.opacity] - Line opacity.
39
+ * @param {Boolean} [options.visibility] - Polyline visibility. True default.
40
+ * @param {Boolean} [options.isClosed] - Closed geometry type identificator.
41
+ * @param {Array.<Array.<number>>} [options.pathLonLat] - Polyline geodetic coordinates array. [[0,0,0], [1,1,1],...]
42
+ * @param {Array.<Array.<number>>} [options.path3v] - LinesString cartesian coordinates array. [[0,0,0], [1,1,1],...]
43
+ * @param {Array.<Array.<number>>} [options.pathColors] - Coordinates color. [[1,0,0,1], [0,1,0,1],...] for right and green colors.
44
+ */
45
+ class Polyline {
46
+ constructor(options) {
47
+ options = options || {};
48
+
49
+ /**
50
+ * Object unic identifier.
51
+ * @public
52
+ * @readonly
53
+ * @type {number}
54
+ */
55
+ this.id = Polyline._staticCounter++;
56
+
57
+ this.altitude = options.altitude || 0.0;
58
+
59
+ /**
60
+ * Polyline thickness in screen pixels.
61
+ * @public
62
+ * @type {number}
63
+ */
64
+ this.thickness = options.thickness || 1.5;
65
+
66
+ /**
67
+ * Polyline RGBA color.
68
+ * @public
69
+ * @type {Array<number>} - (exactly 4 entries)
70
+ */
71
+ this._defaultColor = htmlColorToFloat32Array(
72
+ options.color || DEFAULT_COLOR,
73
+ options.opacity
74
+ ); // utils.createColorRGBA(options.color, new Vec4(1.0, 1.0, 1.0, 1.0));
75
+
76
+ /**
77
+ * Polyline visibility.
78
+ * @public
79
+ * @type {boolean}
80
+ */
81
+ this.visibility = options.visibility != undefined ? options.visibility : true;
82
+
83
+ /**
84
+ * Polyline geometry ring type identificator.
85
+ * @protected
86
+ * @type {Boolean}
87
+ */
88
+ this._closedLine = options.isClosed || false;
89
+
90
+ /**
91
+ * Polyline cartesian coordinates.
92
+ * @private
93
+ * @type {Array.<Vec3>}
94
+ */
95
+ this._path3v = [];
96
+
97
+ this._pathLengths = [];
98
+
99
+ /**
100
+ * Polyline geodetic degrees coordiantes.
101
+ * @private
102
+ * @type {Array.<LonLat>}
103
+ */
104
+ this._pathLonLat = [];
105
+
106
+ /**
107
+ * Polyline geodetic mercator coordinates.
108
+ * @private
109
+ * @type {Array.<LonLat>}
110
+ */
111
+ this._pathLonLatMerc = [];
112
+
113
+ this._pathColors = options.pathColors ? cloneArray(options.pathColors) : [];
114
+
115
+ /**
116
+ * Polyline geodetic extent.
117
+ * @protected
118
+ * @type {Extent}
119
+ */
120
+ this._extent = new Extent();
121
+
122
+ this._verticesHigh = [];
123
+ this._verticesLow = [];
124
+ this._orders = [];
125
+ this._indexes = [];
126
+ this._colors = [];
127
+
128
+ this._verticesHighBuffer = null;
129
+ this._verticesLowBuffer = null;
130
+ this._ordersBuffer = null;
131
+ this._indexesBuffer = null;
132
+ this._colorsBuffer = null;
133
+
134
+ this._pickingColor = [0, 0, 0];
135
+
136
+ this._renderNode = null;
137
+
138
+ /**
139
+ * Entity instance that holds this Polyline.
140
+ * @private
141
+ * @type {Entity}
142
+ */
143
+ this._entity = null;
144
+
145
+ /**
146
+ * Handler that stores and renders this Polyline object.
147
+ * @private
148
+ * @type {PolylineHandler}
149
+ */
150
+ this._handler = null;
151
+ this._handlerIndex = -1;
152
+
153
+ this._buffersUpdateCallbacks = [];
154
+ this._buffersUpdateCallbacks[VERTICES_BUFFER] = this._createVerticesBuffer;
155
+ this._buffersUpdateCallbacks[INDEX_BUFFER] = this._createIndexBuffer;
156
+ this._buffersUpdateCallbacks[COLORS_BUFFER] = this._createColorsBuffer;
157
+
158
+ this._changedBuffers = new Array(this._buffersUpdateCallbacks.length);
159
+
160
+ // create path
161
+ if (options.pathLonLat) {
162
+ this.setPathLonLat(options.pathLonLat);
163
+ } else if (options.path3v) {
164
+ this.setPath3v(options.path3v);
165
+ }
166
+
167
+ this._refresh();
168
+ }
169
+
170
+ static get _staticCounter() {
171
+ if (!this._counter && this._counter !== 0) {
172
+ this._counter = 0;
173
+ }
174
+ return this._counter;
175
+ }
176
+
177
+ static set _staticCounter(n) {
178
+ this._counter = n;
179
+ }
180
+
181
+ /**
182
+ * Appends to the line array new cartesian coordinates line data.
183
+ * @param {Array.<Array.<number>>} path3v - Line coordinates path array. [[0,0,0], [1,1,1],...]
184
+ * @param {Boolean} isClosed - Identificator for the closed line data creation.
185
+ * @param {Number[]} outVertices - Out vertices data array.
186
+ * @param {Number[]} outOrders - Out vertices orders data array.
187
+ * @param {Number[]} outIndexes - Out vertices indexes data array.
188
+ * @param {Ellipsoid} [ellipsoid] - Ellipsoid to coordinates transformation.
189
+ * @param {Array.<Array.<LonLat>>} [outTransformedPathLonLat] - Geodetic coordinates out array.
190
+ * @param {Array.<Array.<LonLat>>} [outPath3v] - Cartesian coordinates out array.
191
+ * @param {Array.<Array.<LonLat>>} [outTransformedPathMerc] - Mercator coordinates out array.
192
+ * @param {Extent} [outExtent] - Geodetic line extent.
193
+ * @param {Array} [outColors]
194
+ * @static
195
+ */
196
+ static appendLineData3v(
197
+ path3v,
198
+ pathColors,
199
+ defaultColor,
200
+ isClosed,
201
+ outVerticesHigh,
202
+ outVerticesLow,
203
+ outOrders,
204
+ outIndexes,
205
+ ellipsoid,
206
+ outTransformedPathLonLat,
207
+ outPath3v,
208
+ outTransformedPathMerc,
209
+ outExtent,
210
+ outColors
211
+ ) {
212
+ var index = 0;
213
+
214
+ var v_high = new Vec3(),
215
+ v_low = new Vec3();
216
+
217
+ if (outExtent) {
218
+ outExtent.southWest.set(180.0, 90.0);
219
+ outExtent.northEast.set(-180.0, -90.0);
220
+ }
221
+
222
+ if (outIndexes.length > 0) {
223
+ index = outIndexes[outIndexes.length - 5] + 9;
224
+ outIndexes.push(index, index);
225
+ } else {
226
+ outIndexes.push(0, 0);
227
+ }
228
+
229
+ for (var j = 0, len = path3v.length; j < len; j++) {
230
+ var path = path3v[j],
231
+ pathColors_j = pathColors[j];
232
+
233
+ outTransformedPathLonLat[j] = [];
234
+ outTransformedPathMerc[j] = [];
235
+ outPath3v[j] = [];
236
+
237
+ if (path.length === 0) {
238
+ continue;
239
+ }
240
+
241
+ var startIndex = index;
242
+
243
+ var last;
244
+
245
+ if (isClosed) {
246
+ last = path[path.length - 1];
247
+ if (last instanceof Array) {
248
+ last = new Vec3(last[0], last[1], last[2]);
249
+ }
250
+ } else {
251
+ var p0 = path[0],
252
+ p1 = path[1] || p0;
253
+ if (p0 instanceof Array) {
254
+ p0 = new Vec3(p0[0], p0[1], p0[2]);
255
+ }
256
+ if (p1 instanceof Array) {
257
+ p1 = new Vec3(p1[0], p1[1], p1[2]);
258
+ }
259
+ last = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
260
+ }
261
+
262
+ let color = defaultColor;
263
+
264
+ if (pathColors_j && pathColors_j[0]) {
265
+ color = pathColors_j[0];
266
+ }
267
+
268
+ Vec3.doubleToTwoFloats(last, v_high, v_low);
269
+ outVerticesHigh.push(
270
+ v_high.x,
271
+ v_high.y,
272
+ v_high.z,
273
+ v_high.x,
274
+ v_high.y,
275
+ v_high.z,
276
+ v_high.x,
277
+ v_high.y,
278
+ v_high.z,
279
+ v_high.x,
280
+ v_high.y,
281
+ v_high.z
282
+ );
283
+ outVerticesLow.push(
284
+ v_low.x,
285
+ v_low.y,
286
+ v_low.z,
287
+ v_low.x,
288
+ v_low.y,
289
+ v_low.z,
290
+ v_low.x,
291
+ v_low.y,
292
+ v_low.z,
293
+ v_low.x,
294
+ v_low.y,
295
+ v_low.z
296
+ );
297
+
298
+ let r = color[R],
299
+ g = color[G],
300
+ b = color[B],
301
+ a = color[A] != undefined ? color[A] : 1.0;
302
+
303
+ if (j > 0) {
304
+ outColors.push(r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a);
305
+ }
306
+
307
+ outOrders.push(1, -1, 2, -2);
308
+
309
+ for (let i = 0, len = path.length; i < len; i++) {
310
+ var cur = path[i];
311
+
312
+ if (cur instanceof Array) {
313
+ cur = new Vec3(cur[0], cur[1], cur[2]);
314
+ }
315
+
316
+ outPath3v[j].push(cur);
317
+
318
+ if (ellipsoid) {
319
+ var lonLat = ellipsoid.cartesianToLonLat(cur);
320
+ outTransformedPathLonLat[j].push(lonLat);
321
+ outTransformedPathMerc[j].push(lonLat.forwardMercator());
322
+
323
+ if (lonLat.lon < outExtent.southWest.lon) {
324
+ outExtent.southWest.lon = lonLat.lon;
325
+ }
326
+ if (lonLat.lat < outExtent.southWest.lat) {
327
+ outExtent.southWest.lat = lonLat.lat;
328
+ }
329
+ if (lonLat.lon > outExtent.northEast.lon) {
330
+ outExtent.northEast.lon = lonLat.lon;
331
+ }
332
+ if (lonLat.lat > outExtent.northEast.lat) {
333
+ outExtent.northEast.lat = lonLat.lat;
334
+ }
335
+ }
336
+
337
+ if (pathColors_j && pathColors_j[i]) {
338
+ color = pathColors_j[i];
339
+ }
340
+
341
+ r = color[R];
342
+ g = color[G];
343
+ b = color[B];
344
+ a = color[A] != undefined ? color[A] : 1.0;
345
+
346
+ Vec3.doubleToTwoFloats(cur, v_high, v_low);
347
+ outVerticesHigh.push(
348
+ v_high.x,
349
+ v_high.y,
350
+ v_high.z,
351
+ v_high.x,
352
+ v_high.y,
353
+ v_high.z,
354
+ v_high.x,
355
+ v_high.y,
356
+ v_high.z,
357
+ v_high.x,
358
+ v_high.y,
359
+ v_high.z
360
+ );
361
+ outVerticesLow.push(
362
+ v_low.x,
363
+ v_low.y,
364
+ v_low.z,
365
+ v_low.x,
366
+ v_low.y,
367
+ v_low.z,
368
+ v_low.x,
369
+ v_low.y,
370
+ v_low.z,
371
+ v_low.x,
372
+ v_low.y,
373
+ v_low.z
374
+ );
375
+
376
+ outColors.push(r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a);
377
+
378
+ outOrders.push(1, -1, 2, -2);
379
+ outIndexes.push(index++, index++, index++, index++);
380
+ }
381
+
382
+ var first;
383
+ if (isClosed) {
384
+ first = path[0];
385
+ if (first instanceof Array) {
386
+ first = new Vec3(first[0], first[1], first[2]);
387
+ }
388
+ outIndexes.push(startIndex, startIndex + 1, startIndex + 1, startIndex + 1);
389
+ } else {
390
+ let p0 = path[path.length - 1],
391
+ p1 = path[path.length - 2] || p0;
392
+ if (p0 instanceof Array) {
393
+ p0 = new Vec3(p0[0], p0[1], p0[2]);
394
+ }
395
+ if (p1 instanceof Array) {
396
+ p1 = new Vec3(p1[0], p1[1], p1[2]);
397
+ }
398
+ first = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
399
+ outIndexes.push(index - 1, index - 1, index - 1, index - 1);
400
+ }
401
+
402
+ if (pathColors_j && pathColors_j[path.length - 1]) {
403
+ color = pathColors_j[path.length - 1];
404
+ }
405
+
406
+ r = color[R];
407
+ g = color[G];
408
+ b = color[B];
409
+ a = color[A] != undefined ? color[A] : 1.0;
410
+
411
+ Vec3.doubleToTwoFloats(first, v_high, v_low);
412
+ outVerticesHigh.push(
413
+ v_high.x,
414
+ v_high.y,
415
+ v_high.z,
416
+ v_high.x,
417
+ v_high.y,
418
+ v_high.z,
419
+ v_high.x,
420
+ v_high.y,
421
+ v_high.z,
422
+ v_high.x,
423
+ v_high.y,
424
+ v_high.z
425
+ );
426
+ outVerticesLow.push(
427
+ v_low.x,
428
+ v_low.y,
429
+ v_low.z,
430
+ v_low.x,
431
+ v_low.y,
432
+ v_low.z,
433
+ v_low.x,
434
+ v_low.y,
435
+ v_low.z,
436
+ v_low.x,
437
+ v_low.y,
438
+ v_low.z
439
+ );
440
+
441
+ outColors.push(r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a);
442
+
443
+ outOrders.push(1, -1, 2, -2);
444
+
445
+ if (j < path3v.length - 1 && path3v[j + 1].length !== 0) {
446
+ index += 8;
447
+ outIndexes.push(index, index);
448
+ }
449
+ }
450
+ }
451
+
452
+ /**
453
+ * Appends to the line new cartesian coordinates point data.
454
+ * @param {Array.<Array.<number>>} path3v - Line coordinates path array. [[0,0,0], [1,1,1],...]
455
+ * @param {Boolean} isClosed - Identificator for the closed line data creation.
456
+ * @param {Number[]} outVertices - Out vertices data array.
457
+ * @param {Number[]} outOrders - Out vertices orders data array.
458
+ * @param {Number[]} outIndexes - Out vertices indexes data array.
459
+ * @param {Ellipsoid} [ellipsoid] - Ellipsoid to coordinates transformation.
460
+ * @param {Array.<Array.<LonLat>>} [outTransformedPathLonLat] - Geodetic coordinates out array.
461
+ * @param {Array.<Array.<LonLat>>} [outPath3v] - Cartesian coordinates out array.
462
+ * @param {Array.<Array.<LonLat>>} [outTransformedPathMerc] - Mercator coordinates out array.
463
+ * @param {Extent} [outExtent] - Geodetic line extent.
464
+ * @static
465
+ */
466
+ static appendPoint3v(
467
+ path3v,
468
+ point3v,
469
+ pathColors,
470
+ color,
471
+ isClosed,
472
+ outVerticesHigh,
473
+ outVerticesLow,
474
+ outColors,
475
+ outOrders,
476
+ outIndexes,
477
+ ellipsoid,
478
+ outTransformedPathLonLat,
479
+ outTransformedPathMerc,
480
+ outExtent
481
+ ) {
482
+ var v_high = new Vec3(),
483
+ v_low = new Vec3();
484
+
485
+ var ii = outIndexes.length - 4,
486
+ index = outIndexes[ii - 1] + 1;
487
+
488
+ if (path3v.length === 0) {
489
+ path3v.push([]);
490
+ if (!pathColors[0]) {
491
+ pathColors[0] = [];
492
+ }
493
+ } else if (!pathColors[path3v.length - 1]) {
494
+ pathColors[path3v.length - 1] = [];
495
+ }
496
+
497
+ var path = path3v[path3v.length - 1],
498
+ len = path.length;
499
+
500
+ path.push(point3v);
501
+
502
+ let r = color[R],
503
+ g = color[G],
504
+ b = color[B],
505
+ a = color[A] != undefined ? color[A] : 1.0,
506
+ pathColors_last = pathColors[path3v.length - 1];
507
+
508
+ if (pathColors_last[len]) {
509
+ pathColors_last[len][R] = r;
510
+ pathColors_last[len][G] = g;
511
+ pathColors_last[len][B] = b;
512
+ pathColors_last[len][A] = a;
513
+ } else {
514
+ pathColors_last.push(color);
515
+ }
516
+
517
+ if (len === 1) {
518
+ var last;
519
+ if (isClosed) {
520
+ last = path[len - 1];
521
+ if (last instanceof Array) {
522
+ last = new Vec3(last[0], last[1], last[2]);
523
+ }
524
+ } else {
525
+ var p0 = path[0],
526
+ p1 = path[1] || p0;
527
+ if (p0 instanceof Array) {
528
+ p0 = new Vec3(p0[0], p0[1], p0[2]);
529
+ }
530
+ if (p1 instanceof Array) {
531
+ p1 = new Vec3(p1[0], p1[1], p1[2]);
532
+ }
533
+ last = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
534
+ }
535
+
536
+ Vec3.doubleToTwoFloats(last, v_high, v_low);
537
+
538
+ let vi = outVerticesHigh.length - 3 * 12;
539
+
540
+ outVerticesHigh[vi] = v_high.x;
541
+ outVerticesHigh[vi + 1] = v_high.y;
542
+ outVerticesHigh[vi + 2] = v_high.z;
543
+ outVerticesHigh[vi + 3] = v_high.x;
544
+ outVerticesHigh[vi + 4] = v_high.y;
545
+ outVerticesHigh[vi + 5] = v_high.z;
546
+ outVerticesHigh[vi + 6] = v_high.x;
547
+ outVerticesHigh[vi + 7] = v_high.y;
548
+ outVerticesHigh[vi + 8] = v_high.z;
549
+ outVerticesHigh[vi + 9] = v_high.x;
550
+ outVerticesHigh[vi + 10] = v_high.y;
551
+ outVerticesHigh[vi + 11] = v_high.z;
552
+
553
+ outVerticesLow[vi] = v_low.x;
554
+ outVerticesLow[vi + 1] = v_low.y;
555
+ outVerticesLow[vi + 2] = v_low.z;
556
+ outVerticesLow[vi + 3] = v_low.x;
557
+ outVerticesLow[vi + 4] = v_low.y;
558
+ outVerticesLow[vi + 5] = v_low.z;
559
+ outVerticesLow[vi + 6] = v_low.x;
560
+ outVerticesLow[vi + 7] = v_low.y;
561
+ outVerticesLow[vi + 8] = v_low.z;
562
+ outVerticesLow[vi + 9] = v_low.x;
563
+ outVerticesLow[vi + 10] = v_low.y;
564
+ outVerticesLow[vi + 11] = v_low.z;
565
+ }
566
+
567
+ var startIndex = index;
568
+
569
+ if (ellipsoid) {
570
+ if (outTransformedPathLonLat.length === 0) {
571
+ outTransformedPathLonLat.push([]);
572
+ }
573
+
574
+ if (outTransformedPathMerc.length === 0) {
575
+ outTransformedPathMerc.push([]);
576
+ }
577
+
578
+ var transformedPathLonLat =
579
+ outTransformedPathLonLat[outTransformedPathLonLat.length - 1],
580
+ transformedPathMerc = outTransformedPathMerc[outTransformedPathMerc.length - 1];
581
+
582
+ let lonLat = ellipsoid.cartesianToLonLat(point3v);
583
+ transformedPathLonLat.push(lonLat);
584
+ transformedPathMerc.push(lonLat.forwardMercator());
585
+
586
+ if (lonLat.lon < outExtent.southWest.lon) {
587
+ outExtent.southWest.lon = lonLat.lon;
588
+ }
589
+ if (lonLat.lat < outExtent.southWest.lat) {
590
+ outExtent.southWest.lat = lonLat.lat;
591
+ }
592
+ if (lonLat.lon > outExtent.northEast.lon) {
593
+ outExtent.northEast.lon = lonLat.lon;
594
+ }
595
+ if (lonLat.lat > outExtent.northEast.lat) {
596
+ outExtent.northEast.lat = lonLat.lat;
597
+ }
598
+ }
599
+
600
+ Vec3.doubleToTwoFloats(point3v, v_high, v_low);
601
+
602
+ let vi = outVerticesHigh.length - 12;
603
+
604
+ outVerticesHigh[vi] = v_high.x;
605
+ outVerticesHigh[vi + 1] = v_high.y;
606
+ outVerticesHigh[vi + 2] = v_high.z;
607
+ outVerticesHigh[vi + 3] = v_high.x;
608
+ outVerticesHigh[vi + 4] = v_high.y;
609
+ outVerticesHigh[vi + 5] = v_high.z;
610
+ outVerticesHigh[vi + 6] = v_high.x;
611
+ outVerticesHigh[vi + 7] = v_high.y;
612
+ outVerticesHigh[vi + 8] = v_high.z;
613
+ outVerticesHigh[vi + 9] = v_high.x;
614
+ outVerticesHigh[vi + 10] = v_high.y;
615
+ outVerticesHigh[vi + 11] = v_high.z;
616
+
617
+ outVerticesLow[vi] = v_low.x;
618
+ outVerticesLow[vi + 1] = v_low.y;
619
+ outVerticesLow[vi + 2] = v_low.z;
620
+ outVerticesLow[vi + 3] = v_low.x;
621
+ outVerticesLow[vi + 4] = v_low.y;
622
+ outVerticesLow[vi + 5] = v_low.z;
623
+ outVerticesLow[vi + 6] = v_low.x;
624
+ outVerticesLow[vi + 7] = v_low.y;
625
+ outVerticesLow[vi + 8] = v_low.z;
626
+ outVerticesLow[vi + 9] = v_low.x;
627
+ outVerticesLow[vi + 10] = v_low.y;
628
+ outVerticesLow[vi + 11] = v_low.z;
629
+
630
+ let ci = outColors.length - 16;
631
+
632
+ outColors[ci] = r;
633
+ outColors[ci + 1] = g;
634
+ outColors[ci + 2] = b;
635
+ outColors[ci + 3] = a;
636
+ outColors[ci + 4] = r;
637
+ outColors[ci + 5] = g;
638
+ outColors[ci + 6] = b;
639
+ outColors[ci + 7] = a;
640
+ outColors[ci + 8] = r;
641
+ outColors[ci + 9] = g;
642
+ outColors[ci + 10] = b;
643
+ outColors[ci + 11] = a;
644
+ outColors[ci + 12] = r;
645
+ outColors[ci + 13] = g;
646
+ outColors[ci + 14] = b;
647
+ outColors[ci + 15] = a;
648
+
649
+ outIndexes[ii] = index++;
650
+ outIndexes[ii + 1] = index++;
651
+ outIndexes[ii + 2] = index++;
652
+ outIndexes[ii + 3] = index++;
653
+
654
+ //
655
+ // Close path
656
+ //
657
+ var first;
658
+ if (isClosed) {
659
+ first = path[0];
660
+ outIndexes.push(startIndex, startIndex + 1, startIndex + 1, startIndex + 1);
661
+ } else {
662
+ let p0 = path[path.length - 1],
663
+ p1 = path[path.length - 2] || p0;
664
+
665
+ first = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
666
+ outIndexes.push(index - 1, index - 1, index - 1, index - 1);
667
+ }
668
+
669
+ Vec3.doubleToTwoFloats(first, v_high, v_low);
670
+ outVerticesHigh.push(
671
+ v_high.x,
672
+ v_high.y,
673
+ v_high.z,
674
+ v_high.x,
675
+ v_high.y,
676
+ v_high.z,
677
+ v_high.x,
678
+ v_high.y,
679
+ v_high.z,
680
+ v_high.x,
681
+ v_high.y,
682
+ v_high.z
683
+ );
684
+ outVerticesLow.push(
685
+ v_low.x,
686
+ v_low.y,
687
+ v_low.z,
688
+ v_low.x,
689
+ v_low.y,
690
+ v_low.z,
691
+ v_low.x,
692
+ v_low.y,
693
+ v_low.z,
694
+ v_low.x,
695
+ v_low.y,
696
+ v_low.z
697
+ );
698
+
699
+ outColors.push(r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a);
700
+
701
+ outOrders.push(1, -1, 2, -2);
702
+ }
703
+
704
+ /**
705
+ * Appends to the line array new geodetic coordinates line data.
706
+ * @param {Array.<Array.<number>>} pathLonLat - Line geodetic coordinates path array. [[0,0,0], [1,1,1],...]
707
+ * @param {Boolean} isClosed - Identificator for the closed line data creation.
708
+ * @param {Number[]} outVertices - Out vertices data array.
709
+ * @param {Number[]} outOrders - Out vertices orders data array.
710
+ * @param {Number[]} outIndexes - Out indexes data array.
711
+ * @param {Ellipsoid} ellipsoid - Ellipsoid to coordinates transformation.
712
+ * @param {Array.<Array.<number>>} outTransformedPathCartesian - Cartesian coordinates out array. [[0,0,0], [1,1,1],...]
713
+ * @param {Array.<Array.<LonLat>>} outPathLonLat - Geographic coordinates out array.
714
+ * @param {Array.<Array.<LonLat>>} outTransformedPathMerc - Mercator coordinates out array.
715
+ * @param {Extent} outExtent - Geodetic line extent.
716
+ * @static
717
+ */
718
+ static appendLineDataLonLat(
719
+ pathLonLat,
720
+ pathColors,
721
+ defaultColor,
722
+ isClosed,
723
+ outVerticesHigh,
724
+ outVerticesLow,
725
+ outOrders,
726
+ outIndexes,
727
+ ellipsoid,
728
+ outTransformedPathCartesian,
729
+ outPathLonLat,
730
+ outTransformedPathMerc,
731
+ outExtent,
732
+ outColors
733
+ ) {
734
+ var index = 0;
735
+
736
+ var v_high = new Vec3(),
737
+ v_low = new Vec3();
738
+
739
+ if (outExtent) {
740
+ outExtent.southWest.set(180.0, 90.0);
741
+ outExtent.northEast.set(-180.0, -90.0);
742
+ }
743
+
744
+ if (outIndexes.length > 0) {
745
+ index = outIndexes[outIndexes.length - 5] + 9;
746
+ outIndexes.push(index, index);
747
+ } else {
748
+ outIndexes.push(0, 0);
749
+ }
750
+
751
+ for (var j = 0, len = pathLonLat.length; j < len; j++) {
752
+ var path = pathLonLat[j],
753
+ pathColors_j = pathColors[j];
754
+
755
+ outTransformedPathCartesian[j] = [];
756
+ outTransformedPathMerc[j] = [];
757
+ outPathLonLat[j] = [];
758
+
759
+ if (path.length === 0) {
760
+ continue;
761
+ }
762
+
763
+ var startIndex = index;
764
+
765
+ var last;
766
+
767
+ if (isClosed) {
768
+ let pp = path[path.length - 1];
769
+ if (pp instanceof Array) {
770
+ last = ellipsoid.lonLatToCartesian(new LonLat(pp[0], pp[1], pp[2]));
771
+ } else {
772
+ last = ellipsoid.lonLatToCartesian(pp);
773
+ }
774
+ } else {
775
+ let p0, p1;
776
+ let pp = path[0];
777
+ if (pp instanceof Array) {
778
+ p0 = ellipsoid.lonLatToCartesian(new LonLat(pp[0], pp[1], pp[2]));
779
+ } else {
780
+ p0 = ellipsoid.lonLatToCartesian(pp);
781
+ }
782
+
783
+ pp = path[1];
784
+
785
+ if (!pp) {
786
+ pp = path[0];
787
+ }
788
+
789
+ if (pp instanceof Array) {
790
+ p1 = ellipsoid.lonLatToCartesian(new LonLat(pp[0], pp[1], pp[2]));
791
+ } else {
792
+ p1 = ellipsoid.lonLatToCartesian(pp);
793
+ }
794
+
795
+ last = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
796
+ }
797
+
798
+ let color = defaultColor;
799
+
800
+ if (pathColors_j && pathColors_j[0]) {
801
+ color = pathColors_j[0];
802
+ }
803
+
804
+ Vec3.doubleToTwoFloats(last, v_high, v_low);
805
+ outVerticesHigh.push(
806
+ v_high.x,
807
+ v_high.y,
808
+ v_high.z,
809
+ v_high.x,
810
+ v_high.y,
811
+ v_high.z,
812
+ v_high.x,
813
+ v_high.y,
814
+ v_high.z,
815
+ v_high.x,
816
+ v_high.y,
817
+ v_high.z
818
+ );
819
+ outVerticesLow.push(
820
+ v_low.x,
821
+ v_low.y,
822
+ v_low.z,
823
+ v_low.x,
824
+ v_low.y,
825
+ v_low.z,
826
+ v_low.x,
827
+ v_low.y,
828
+ v_low.z,
829
+ v_low.x,
830
+ v_low.y,
831
+ v_low.z
832
+ );
833
+
834
+ let r = color[R],
835
+ g = color[G],
836
+ b = color[B],
837
+ a = color[A] != undefined ? color[A] : 1.0;
838
+
839
+ if (j > 0) {
840
+ outColors.push(r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a);
841
+ }
842
+
843
+ outOrders.push(1, -1, 2, -2);
844
+
845
+ for (let i = 0, len = path.length; i < len; i++) {
846
+ var cur = path[i];
847
+
848
+ if (cur instanceof Array) {
849
+ cur = new LonLat(cur[0], cur[1], cur[2]);
850
+ }
851
+
852
+ if (pathColors_j && pathColors_j[i]) {
853
+ color = pathColors_j[i];
854
+ }
855
+
856
+ r = color[R];
857
+ g = color[G];
858
+ b = color[B];
859
+ a = color[A] != undefined ? color[A] : 1.0;
860
+
861
+ var cartesian = ellipsoid.lonLatToCartesian(cur);
862
+ outTransformedPathCartesian[j].push(cartesian);
863
+ outPathLonLat[j].push(cur);
864
+ outTransformedPathMerc[j].push(cur.forwardMercator());
865
+
866
+ Vec3.doubleToTwoFloats(cartesian, v_high, v_low);
867
+ outVerticesHigh.push(
868
+ v_high.x,
869
+ v_high.y,
870
+ v_high.z,
871
+ v_high.x,
872
+ v_high.y,
873
+ v_high.z,
874
+ v_high.x,
875
+ v_high.y,
876
+ v_high.z,
877
+ v_high.x,
878
+ v_high.y,
879
+ v_high.z
880
+ );
881
+ outVerticesLow.push(
882
+ v_low.x,
883
+ v_low.y,
884
+ v_low.z,
885
+ v_low.x,
886
+ v_low.y,
887
+ v_low.z,
888
+ v_low.x,
889
+ v_low.y,
890
+ v_low.z,
891
+ v_low.x,
892
+ v_low.y,
893
+ v_low.z
894
+ );
895
+
896
+ outColors.push(r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a);
897
+
898
+ outOrders.push(1, -1, 2, -2);
899
+ outIndexes.push(index++, index++, index++, index++);
900
+
901
+ if (cur.lon < outExtent.southWest.lon) {
902
+ outExtent.southWest.lon = cur.lon;
903
+ }
904
+ if (cur.lat < outExtent.southWest.lat) {
905
+ outExtent.southWest.lat = cur.lat;
906
+ }
907
+ if (cur.lon > outExtent.northEast.lon) {
908
+ outExtent.northEast.lon = cur.lon;
909
+ }
910
+ if (cur.lat > outExtent.northEast.lat) {
911
+ outExtent.northEast.lat = cur.lat;
912
+ }
913
+ }
914
+
915
+ var first;
916
+ if (isClosed) {
917
+ let pp = path[0];
918
+ if (pp instanceof Array) {
919
+ first = ellipsoid.lonLatToCartesian(new LonLat(pp[0], pp[1], pp[2]));
920
+ } else {
921
+ first = ellipsoid.lonLatToCartesian(pp);
922
+ }
923
+ outIndexes.push(startIndex, startIndex + 1, startIndex + 1, startIndex + 1);
924
+ } else {
925
+ let p0, p1;
926
+ let pp = path[path.length - 1];
927
+ if (pp instanceof Array) {
928
+ p0 = ellipsoid.lonLatToCartesian(new LonLat(pp[0], pp[1], pp[2]));
929
+ } else {
930
+ p0 = ellipsoid.lonLatToCartesian(pp);
931
+ }
932
+
933
+ pp = path[path.length - 2];
934
+
935
+ if (!pp) {
936
+ pp = path[0];
937
+ }
938
+
939
+ if (pp instanceof Array) {
940
+ p1 = ellipsoid.lonLatToCartesian(new LonLat(pp[0], pp[1], pp[2]));
941
+ } else {
942
+ p1 = ellipsoid.lonLatToCartesian(pp);
943
+ }
944
+ first = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
945
+ outIndexes.push(index - 1, index - 1, index - 1, index - 1);
946
+ }
947
+
948
+ if (pathColors_j && pathColors_j[path.length - 1]) {
949
+ color = pathColors_j[path.length - 1];
950
+ }
951
+
952
+ r = color[R];
953
+ g = color[G];
954
+ b = color[B];
955
+ a = color[A] != undefined ? color[A] : 1.0;
956
+
957
+ Vec3.doubleToTwoFloats(first, v_high, v_low);
958
+ outVerticesHigh.push(
959
+ v_high.x,
960
+ v_high.y,
961
+ v_high.z,
962
+ v_high.x,
963
+ v_high.y,
964
+ v_high.z,
965
+ v_high.x,
966
+ v_high.y,
967
+ v_high.z,
968
+ v_high.x,
969
+ v_high.y,
970
+ v_high.z
971
+ );
972
+ outVerticesLow.push(
973
+ v_low.x,
974
+ v_low.y,
975
+ v_low.z,
976
+ v_low.x,
977
+ v_low.y,
978
+ v_low.z,
979
+ v_low.x,
980
+ v_low.y,
981
+ v_low.z,
982
+ v_low.x,
983
+ v_low.y,
984
+ v_low.z
985
+ );
986
+
987
+ outColors.push(r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a);
988
+
989
+ outOrders.push(1, -1, 2, -2);
990
+
991
+ if (j < pathLonLat.length - 1 && pathLonLat[j + 1].length !== 0) {
992
+ index += 8;
993
+ outIndexes.push(index, index);
994
+ }
995
+ }
996
+ }
997
+
998
+ /**
999
+ * Sets polyline path with cartesian coordinates.
1000
+ * @protected
1001
+ * @param {pg.math.Vector3[]} path3v - Cartesian coordinates.
1002
+ */
1003
+ _setEqualPath3v(path3v) {
1004
+ var extent = this._extent;
1005
+ extent.southWest.set(180, 90);
1006
+ extent.northEast.set(-180, -90);
1007
+
1008
+ var v_high = new Vec3(),
1009
+ v_low = new Vec3();
1010
+
1011
+ var vh = this._verticesHigh,
1012
+ vl = this._verticesLow,
1013
+ l = this._pathLonLat,
1014
+ m = this._pathLonLatMerc,
1015
+ k = 0;
1016
+
1017
+ var ellipsoid = this._renderNode.ellipsoid;
1018
+
1019
+ for (var j = 0; j < path3v.length; j++) {
1020
+ var path = path3v[j];
1021
+
1022
+ var last;
1023
+ if (this._closedLine) {
1024
+ last = path[path.length - 1];
1025
+ } else {
1026
+ last = new Vec3(
1027
+ path[0].x + path[0].x - path[1].x,
1028
+ path[0].y + path[0].y - path[1].y,
1029
+ path[0].z + path[0].z - path[1].z
1030
+ );
1031
+ }
1032
+
1033
+ Vec3.doubleToTwoFloats(last, v_high, v_low);
1034
+
1035
+ vh[k] = v_high.x;
1036
+ vl[k++] = v_low.x;
1037
+ vh[k] = v_high.y;
1038
+ vl[k++] = v_low.y;
1039
+ vh[k] = v_high.z;
1040
+ vl[k++] = v_low.z;
1041
+ vh[k] = v_high.x;
1042
+ vl[k++] = v_low.x;
1043
+ vh[k] = v_high.y;
1044
+ vl[k++] = v_low.y;
1045
+ vh[k] = v_high.z;
1046
+ vl[k++] = v_low.z;
1047
+ vh[k] = v_high.x;
1048
+ vl[k++] = v_low.x;
1049
+ vh[k] = v_high.y;
1050
+ vl[k++] = v_low.y;
1051
+ vh[k] = v_high.z;
1052
+ vl[k++] = v_low.z;
1053
+ vh[k] = v_high.x;
1054
+ vl[k++] = v_low.x;
1055
+ vh[k] = v_high.y;
1056
+ vl[k++] = v_low.y;
1057
+ vh[k] = v_high.z;
1058
+ vl[k++] = v_low.z;
1059
+
1060
+ for (var i = 0; i < path.length; i++) {
1061
+ var cur = path[i],
1062
+ pji = this._path3v[j][i];
1063
+
1064
+ pji.x = cur.x;
1065
+ pji.y = cur.y;
1066
+ pji.z = cur.z;
1067
+
1068
+ if (ellipsoid) {
1069
+ var lonLat = ellipsoid.cartesianToLonLat(cur);
1070
+
1071
+ this._pathLonLat[j][i] = lonLat;
1072
+
1073
+ l[j][i] = lonLat;
1074
+ m[j][i] = lonLat.forwardMercator();
1075
+
1076
+ if (lonLat.lon < extent.southWest.lon) {
1077
+ extent.southWest.lon = lonLat.lon;
1078
+ }
1079
+ if (lonLat.lat < extent.southWest.lat) {
1080
+ extent.southWest.lat = lonLat.lat;
1081
+ }
1082
+ if (lonLat.lon > extent.northEast.lon) {
1083
+ extent.northEast.lon = lonLat.lon;
1084
+ }
1085
+ if (lonLat.lat > extent.northEast.lat) {
1086
+ extent.northEast.lat = lonLat.lat;
1087
+ }
1088
+ }
1089
+
1090
+ Vec3.doubleToTwoFloats(cur, v_high, v_low);
1091
+
1092
+ vh[k] = v_high.x;
1093
+ vl[k++] = v_low.x;
1094
+ vh[k] = v_high.y;
1095
+ vl[k++] = v_low.y;
1096
+ vh[k] = v_high.z;
1097
+ vl[k++] = v_low.z;
1098
+ vh[k] = v_high.x;
1099
+ vl[k++] = v_low.x;
1100
+ vh[k] = v_high.y;
1101
+ vl[k++] = v_low.y;
1102
+ vh[k] = v_high.z;
1103
+ vl[k++] = v_low.z;
1104
+ vh[k] = v_high.x;
1105
+ vl[k++] = v_low.x;
1106
+ vh[k] = v_high.y;
1107
+ vl[k++] = v_low.y;
1108
+ vh[k] = v_high.z;
1109
+ vl[k++] = v_low.z;
1110
+ vh[k] = v_high.x;
1111
+ vl[k++] = v_low.x;
1112
+ vh[k] = v_high.y;
1113
+ vl[k++] = v_low.y;
1114
+ vh[k] = v_high.z;
1115
+ vl[k++] = v_low.z;
1116
+ }
1117
+
1118
+ var first;
1119
+ if (this._closedLine) {
1120
+ first = path[0];
1121
+ } else {
1122
+ var l1 = path.length - 1;
1123
+ first = new Vec3(
1124
+ path[l1].x + path[l1].x - path[l1 - 1].x,
1125
+ path[l1].y + path[l1].y - path[l1 - 1].y,
1126
+ path[l1].z + path[l1].z - path[l1 - 1].z
1127
+ );
1128
+ }
1129
+
1130
+ Vec3.doubleToTwoFloats(first, v_high, v_low);
1131
+
1132
+ vh[k] = v_high.x;
1133
+ vl[k++] = v_low.x;
1134
+ vh[k] = v_high.y;
1135
+ vl[k++] = v_low.y;
1136
+ vh[k] = v_high.z;
1137
+ vl[k++] = v_low.z;
1138
+ vh[k] = v_high.x;
1139
+ vl[k++] = v_low.x;
1140
+ vh[k] = v_high.y;
1141
+ vl[k++] = v_low.y;
1142
+ vh[k] = v_high.z;
1143
+ vl[k++] = v_low.z;
1144
+ vh[k] = v_high.x;
1145
+ vl[k++] = v_low.x;
1146
+ vh[k] = v_high.y;
1147
+ vl[k++] = v_low.y;
1148
+ vh[k] = v_high.z;
1149
+ vl[k++] = v_low.z;
1150
+ vh[k] = v_high.x;
1151
+ vl[k++] = v_low.x;
1152
+ vh[k] = v_high.y;
1153
+ vl[k++] = v_low.y;
1154
+ vh[k] = v_high.z;
1155
+ vl[k++] = v_low.z;
1156
+ }
1157
+ }
1158
+
1159
+ /**
1160
+ * Sets polyline with geodetic coordinates.
1161
+ * @protected
1162
+ * @param {LonLat[]} pathLonLat - Geodetic polyline path coordinates.
1163
+ */
1164
+ _setEqualPathLonLat(pathLonLat) {
1165
+ var extent = this._extent;
1166
+ extent.southWest.set(180.0, 90.0);
1167
+ extent.northEast.set(-180.0, -90.0);
1168
+
1169
+ var v_high = new Vec3(),
1170
+ v_low = new Vec3();
1171
+
1172
+ var vh = this._verticesHigh,
1173
+ vl = this._verticesLow,
1174
+ l = this._pathLonLat,
1175
+ m = this._pathLonLatMerc,
1176
+ c = this._path3v,
1177
+ k = 0;
1178
+
1179
+ var ellipsoid = this._renderNode.ellipsoid;
1180
+
1181
+ for (var j = 0; j < pathLonLat.length; j++) {
1182
+ var path = pathLonLat[j];
1183
+
1184
+ var last;
1185
+ if (this._closedLine) {
1186
+ last = ellipsoid.lonLatToCartesian(path[path.length - 1]);
1187
+ } else {
1188
+ let p0 = ellipsoid.lonLatToCartesian(path[0]),
1189
+ p1 = ellipsoid.lonLatToCartesian(path[1]);
1190
+ last = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
1191
+ }
1192
+
1193
+ Vec3.doubleToTwoFloats(last, v_high, v_low);
1194
+
1195
+ vh[k] = v_high.x;
1196
+ vl[k++] = v_low.x;
1197
+ vh[k] = v_high.y;
1198
+ vl[k++] = v_low.y;
1199
+ vh[k] = v_high.z;
1200
+ vl[k++] = v_low.z;
1201
+ vh[k] = v_high.x;
1202
+ vl[k++] = v_low.x;
1203
+ vh[k] = v_high.y;
1204
+ vl[k++] = v_low.y;
1205
+ vh[k] = v_high.z;
1206
+ vl[k++] = v_low.z;
1207
+ vh[k] = v_high.x;
1208
+ vl[k++] = v_low.x;
1209
+ vh[k] = v_high.y;
1210
+ vl[k++] = v_low.y;
1211
+ vh[k] = v_high.z;
1212
+ vl[k++] = v_low.z;
1213
+ vh[k] = v_high.x;
1214
+ vl[k++] = v_low.x;
1215
+ vh[k] = v_high.y;
1216
+ vl[k++] = v_low.y;
1217
+ vh[k] = v_high.z;
1218
+ vl[k++] = v_low.z;
1219
+
1220
+ for (var i = 0; i < path.length; i++) {
1221
+ var cur = path[i];
1222
+ var cartesian = ellipsoid.lonLatToCartesian(cur);
1223
+ c[j][i] = cartesian;
1224
+ m[j][i] = cur.forwardMercator();
1225
+ l[j][i] = cur;
1226
+
1227
+ Vec3.doubleToTwoFloats(cartesian, v_high, v_low);
1228
+
1229
+ vh[k] = v_high.x;
1230
+ vl[k++] = v_low.x;
1231
+ vh[k] = v_high.y;
1232
+ vl[k++] = v_low.y;
1233
+ vh[k] = v_high.z;
1234
+ vl[k++] = v_low.z;
1235
+ vh[k] = v_high.x;
1236
+ vl[k++] = v_low.x;
1237
+ vh[k] = v_high.y;
1238
+ vl[k++] = v_low.y;
1239
+ vh[k] = v_high.z;
1240
+ vl[k++] = v_low.z;
1241
+ vh[k] = v_high.x;
1242
+ vl[k++] = v_low.x;
1243
+ vh[k] = v_high.y;
1244
+ vl[k++] = v_low.y;
1245
+ vh[k] = v_high.z;
1246
+ vl[k++] = v_low.z;
1247
+ vh[k] = v_high.x;
1248
+ vl[k++] = v_low.x;
1249
+ vh[k] = v_high.y;
1250
+ vl[k++] = v_low.y;
1251
+ vh[k] = v_high.z;
1252
+ vl[k++] = v_low.z;
1253
+
1254
+ if (cur.lon < extent.southWest.lon) {
1255
+ extent.southWest.lon = cur.lon;
1256
+ }
1257
+ if (cur.lat < extent.southWest.lat) {
1258
+ extent.southWest.lat = cur.lat;
1259
+ }
1260
+ if (cur.lon > extent.northEast.lon) {
1261
+ extent.northEast.lon = cur.lon;
1262
+ }
1263
+ if (cur.lat > extent.northEast.lat) {
1264
+ extent.northEast.lat = cur.lat;
1265
+ }
1266
+ }
1267
+
1268
+ var first;
1269
+ if (this._closedLine) {
1270
+ first = ellipsoid.lonLatToCartesian(path[0]);
1271
+ } else {
1272
+ let p0 = ellipsoid.lonLatToCartesian(path[path.length - 1]),
1273
+ p1 = ellipsoid.lonLatToCartesian(path[path.length - 2]);
1274
+ first = new Vec3(p0.x + p0.x - p1.x, p0.y + p0.y - p1.y, p0.z + p0.z - p1.z);
1275
+ }
1276
+
1277
+ Vec3.doubleToTwoFloats(first, v_high, v_low);
1278
+
1279
+ vh[k] = v_high.x;
1280
+ vl[k++] = v_low.x;
1281
+ vh[k] = v_high.y;
1282
+ vl[k++] = v_low.y;
1283
+ vh[k] = v_high.z;
1284
+ vl[k++] = v_low.z;
1285
+ vh[k] = v_high.x;
1286
+ vl[k++] = v_low.x;
1287
+ vh[k] = v_high.y;
1288
+ vl[k++] = v_low.y;
1289
+ vh[k] = v_high.z;
1290
+ vl[k++] = v_low.z;
1291
+ vh[k] = v_high.x;
1292
+ vl[k++] = v_low.x;
1293
+ vh[k] = v_high.y;
1294
+ vl[k++] = v_low.y;
1295
+ vh[k] = v_high.z;
1296
+ vl[k++] = v_low.z;
1297
+ vh[k] = v_high.x;
1298
+ vl[k++] = v_low.x;
1299
+ vh[k] = v_high.y;
1300
+ vl[k++] = v_low.y;
1301
+ vh[k] = v_high.z;
1302
+ vl[k++] = v_low.z;
1303
+ }
1304
+ }
1305
+
1306
+ setPointLonLat(lonlat, index, segmentIndex) {
1307
+ if (this._renderNode && this._renderNode.ellipsoid) {
1308
+ let l = this._pathLonLat,
1309
+ m = this._pathLonLatMerc;
1310
+
1311
+ l[segmentIndex][index] = lonlat;
1312
+ m[segmentIndex][index] = lonlat.forwardMercator();
1313
+
1314
+ //
1315
+ // Apply new extent(TODO: think about optimization)
1316
+ //
1317
+ var extent = this._extent;
1318
+ extent.southWest.set(180.0, 90.0);
1319
+ extent.northEast.set(-180.0, -90.0);
1320
+ for (var i = 0; i < l.length; i++) {
1321
+ var pi = l[i];
1322
+ for (var j = 0; j < pi.length; j++) {
1323
+ var lon = pi[j].lon,
1324
+ lat = pi[j].lat;
1325
+ if (lon > extent.northEast.lon) {
1326
+ extent.northEast.lon = lon;
1327
+ }
1328
+ if (lat > extent.northEast.lat) {
1329
+ extent.northEast.lat = lat;
1330
+ }
1331
+ if (lon < extent.southWest.lon) {
1332
+ extent.southWest.lon = lon;
1333
+ }
1334
+ if (lat < extent.southWest.lat) {
1335
+ extent.southWest.lat = lat;
1336
+ }
1337
+ }
1338
+ }
1339
+
1340
+ this.setPoint3v(
1341
+ this._renderNode.ellipsoid.lonLatToCartesian(lonlat),
1342
+ index,
1343
+ segmentIndex,
1344
+ true
1345
+ );
1346
+ } else {
1347
+ let path = this._pathLonLat[segmentIndex];
1348
+ path[index].lon = lonlat.lon;
1349
+ path[index].lat = lonlat.lat;
1350
+ path[index].height = lonlat.height;
1351
+ }
1352
+ }
1353
+
1354
+ setPoint3v(coordinates, index = 0, segmentIndex = 0, skipLonLat = false) {
1355
+
1356
+ if (this._renderNode) {
1357
+ var v_high = new Vec3(),
1358
+ v_low = new Vec3();
1359
+
1360
+ var vh = this._verticesHigh,
1361
+ vl = this._verticesLow,
1362
+ l = this._pathLonLat,
1363
+ m = this._pathLonLatMerc,
1364
+ k = 0,
1365
+ kk = 0;
1366
+
1367
+ //for (var i = 0; i < segmentIndex; i++) {
1368
+ // kk += this._path3v[i].length * 12 + 24;
1369
+ //}
1370
+ kk = this._pathLengths[segmentIndex] * 12 + 24 * segmentIndex;
1371
+
1372
+ let path = this._path3v[segmentIndex];
1373
+
1374
+ path[index].x = coordinates.x;
1375
+ path[index].y = coordinates.y;
1376
+ path[index].z = coordinates.z;
1377
+
1378
+ let _closedLine = this._closedLine || path.length === 1;
1379
+
1380
+ if (index === 0 || index === 1) {
1381
+ var last;
1382
+ if (_closedLine) {
1383
+ last = path[path.length - 1];
1384
+ } else {
1385
+ last = new Vec3(
1386
+ path[0].x + path[0].x - path[1].x,
1387
+ path[0].y + path[0].y - path[1].y,
1388
+ path[0].z + path[0].z - path[1].z
1389
+ );
1390
+ }
1391
+
1392
+ k = kk;
1393
+
1394
+ Vec3.doubleToTwoFloats(last, v_high, v_low);
1395
+
1396
+ vh[k] = v_high.x;
1397
+ vh[k + 1] = v_high.y;
1398
+ vh[k + 2] = v_high.z;
1399
+ vh[k + 3] = v_high.x;
1400
+ vh[k + 4] = v_high.y;
1401
+ vh[k + 5] = v_high.z;
1402
+ vh[k + 6] = v_high.x;
1403
+ vh[k + 7] = v_high.y;
1404
+ vh[k + 8] = v_high.z;
1405
+ vh[k + 9] = v_high.x;
1406
+ vh[k + 10] = v_high.y;
1407
+ vh[k + 11] = v_high.z;
1408
+
1409
+ vl[k] = v_low.x;
1410
+ vl[k + 1] = v_low.y;
1411
+ vl[k + 2] = v_low.z;
1412
+ vl[k + 3] = v_low.x;
1413
+ vl[k + 4] = v_low.y;
1414
+ vl[k + 5] = v_low.z;
1415
+ vl[k + 6] = v_low.x;
1416
+ vl[k + 7] = v_low.y;
1417
+ vl[k + 8] = v_low.z;
1418
+ vl[k + 9] = v_low.x;
1419
+ vl[k + 10] = v_low.y;
1420
+ vl[k + 11] = v_low.z;
1421
+ }
1422
+
1423
+ if (!skipLonLat && this._renderNode.ellipsoid) {
1424
+ var lonLat = this._renderNode.ellipsoid.cartesianToLonLat(coordinates);
1425
+ l[segmentIndex][index] = lonLat;
1426
+ m[segmentIndex][index] = lonLat.forwardMercator();
1427
+
1428
+ //
1429
+ // Apply new extent(TODO: think about optimization)
1430
+ //
1431
+ var extent = this._extent;
1432
+ extent.southWest.set(180.0, 90.0);
1433
+ extent.northEast.set(-180.0, -90.0);
1434
+ for (let i = 0; i < l.length; i++) {
1435
+ var pi = l[i];
1436
+ for (var j = 0; j < pi.length; j++) {
1437
+ var lon = pi[j].lon,
1438
+ lat = pi[j].lat;
1439
+ if (lon > extent.northEast.lon) {
1440
+ extent.northEast.lon = lon;
1441
+ }
1442
+ if (lat > extent.northEast.lat) {
1443
+ extent.northEast.lat = lat;
1444
+ }
1445
+ if (lon < extent.southWest.lon) {
1446
+ extent.southWest.lon = lon;
1447
+ }
1448
+ if (lat < extent.southWest.lat) {
1449
+ extent.southWest.lat = lat;
1450
+ }
1451
+ }
1452
+ }
1453
+ }
1454
+
1455
+ k = kk + index * 12 + 12;
1456
+
1457
+ Vec3.doubleToTwoFloats(coordinates, v_high, v_low);
1458
+
1459
+ vh[k] = v_high.x;
1460
+ vh[k + 1] = v_high.y;
1461
+ vh[k + 2] = v_high.z;
1462
+ vh[k + 3] = v_high.x;
1463
+ vh[k + 4] = v_high.y;
1464
+ vh[k + 5] = v_high.z;
1465
+ vh[k + 6] = v_high.x;
1466
+ vh[k + 7] = v_high.y;
1467
+ vh[k + 8] = v_high.z;
1468
+ vh[k + 9] = v_high.x;
1469
+ vh[k + 10] = v_high.y;
1470
+ vh[k + 11] = v_high.z;
1471
+
1472
+ vl[k] = v_low.x;
1473
+ vl[k + 1] = v_low.y;
1474
+ vl[k + 2] = v_low.z;
1475
+ vl[k + 3] = v_low.x;
1476
+ vl[k + 4] = v_low.y;
1477
+ vl[k + 5] = v_low.z;
1478
+ vl[k + 6] = v_low.x;
1479
+ vl[k + 7] = v_low.y;
1480
+ vl[k + 8] = v_low.z;
1481
+ vl[k + 9] = v_low.x;
1482
+ vl[k + 10] = v_low.y;
1483
+ vl[k + 11] = v_low.z;
1484
+
1485
+ if (index === path.length - 1 || index === path.length - 2) {
1486
+ var first;
1487
+ if (_closedLine) {
1488
+ first = path[0];
1489
+ } else {
1490
+ var l1 = path.length - 1;
1491
+ first = new Vec3(
1492
+ path[l1].x + path[l1].x - path[l1 - 1].x,
1493
+ path[l1].y + path[l1].y - path[l1 - 1].y,
1494
+ path[l1].z + path[l1].z - path[l1 - 1].z
1495
+ );
1496
+ }
1497
+
1498
+ k = kk + path.length * 12 + 12;
1499
+
1500
+ Vec3.doubleToTwoFloats(first, v_high, v_low);
1501
+
1502
+ vh[k] = v_high.x;
1503
+ vh[k + 1] = v_high.y;
1504
+ vh[k + 2] = v_high.z;
1505
+ vh[k + 3] = v_high.x;
1506
+ vh[k + 4] = v_high.y;
1507
+ vh[k + 5] = v_high.z;
1508
+ vh[k + 6] = v_high.x;
1509
+ vh[k + 7] = v_high.y;
1510
+ vh[k + 8] = v_high.z;
1511
+ vh[k + 9] = v_high.x;
1512
+ vh[k + 10] = v_high.y;
1513
+ vh[k + 11] = v_high.z;
1514
+
1515
+ vl[k] = v_low.x;
1516
+ vl[k + 1] = v_low.y;
1517
+ vl[k + 2] = v_low.z;
1518
+ vl[k + 3] = v_low.x;
1519
+ vl[k + 4] = v_low.y;
1520
+ vl[k + 5] = v_low.z;
1521
+ vl[k + 6] = v_low.x;
1522
+ vl[k + 7] = v_low.y;
1523
+ vl[k + 8] = v_low.z;
1524
+ vl[k + 9] = v_low.x;
1525
+ vl[k + 10] = v_low.y;
1526
+ vl[k + 11] = v_low.z;
1527
+ }
1528
+
1529
+ this._changedBuffers[VERTICES_BUFFER] = true;
1530
+ } else {
1531
+ let path = this._path3v[segmentIndex];
1532
+ path[index].x = coordinates.x;
1533
+ path[index].y = coordinates.y;
1534
+ path[index].z = coordinates.z;
1535
+ }
1536
+ }
1537
+
1538
+ _resizePathLengths(index = 0) {
1539
+ this._pathLengths[0] = 0;
1540
+ for (let i = index + 1, len = this._path3v.length; i <= len; i++) {
1541
+ this._pathLengths[i] = this._pathLengths[i - 1] + this._path3v[i - 1].length;
1542
+ }
1543
+ }
1544
+
1545
+ removeSegment(index) {
1546
+ this._path3v.splice(index, 1);
1547
+ this.setPath3v([].concat(this._path3v));
1548
+ }
1549
+
1550
+ removePoint(index, multiLineIndex = 0) {
1551
+ this._path3v[multiLineIndex].splice(index, 1);
1552
+ if (this._path3v[multiLineIndex].length === 0) {
1553
+ this._path3v.splice(multiLineIndex, 1);
1554
+ }
1555
+ this.setPath3v([].concat(this._path3v));
1556
+ }
1557
+
1558
+ insertPoint3v(point3v, index = 0, color, multilineIndex = 0) {
1559
+ let p = [].concat(this._path3v),
1560
+ pp = p[multilineIndex];
1561
+ if (pp) {
1562
+ let c = [].concat(this._pathColors);
1563
+
1564
+ pp.splice(index, 0, point3v);
1565
+
1566
+ if (color) {
1567
+ let cc = c[multilineIndex];
1568
+ if (!cc) {
1569
+ cc = new Array(pp.length);
1570
+ }
1571
+ cc.splice(index, 0, color);
1572
+ }
1573
+
1574
+ this.setPath3v(p, c);
1575
+ } else {
1576
+ this.addPoint3v(point3v, multilineIndex);
1577
+ }
1578
+ }
1579
+
1580
+ /**
1581
+ * Adds a new cartesian point in the end of the path in a last line segment.
1582
+ * @public
1583
+ * @param {Vec3} point3v - New coordinate.
1584
+ */
1585
+ appendPoint3v(point3v, color, skipEllipsoid) {
1586
+ if (this._path3v.length === 0) {
1587
+ this._pathColors.push([color || this._defaultColor]);
1588
+ this.addPoint3v(point3v);
1589
+ } else {
1590
+ //
1591
+ // Making typedArrays suitable for appendPoint function
1592
+ //
1593
+ this._verticesHigh = makeArray(this._verticesHigh);
1594
+ this._verticesLow = makeArray(this._verticesLow);
1595
+ this._colors = makeArray(this._colors);
1596
+ this._orders = makeArray(this._orders);
1597
+ this._indexes = makeArray(this._indexes);
1598
+
1599
+ Polyline.appendPoint3v(
1600
+ this._path3v,
1601
+ point3v,
1602
+ this._pathColors,
1603
+ color || this._defaultColor,
1604
+ this._closedLine,
1605
+ this._verticesHigh,
1606
+ this._verticesLow,
1607
+ this._colors,
1608
+ this._orders,
1609
+ this._indexes,
1610
+ !skipEllipsoid && this._renderNode.ellipsoid,
1611
+ this._pathLonLat,
1612
+ this._pathLonLatMerc,
1613
+ this._extent
1614
+ );
1615
+
1616
+ this._pathLengths[this._path3v.length] += 1;
1617
+
1618
+ this._changedBuffers[VERTICES_BUFFER] = true;
1619
+ this._changedBuffers[COLORS_BUFFER] = true;
1620
+ this._changedBuffers[INDEX_BUFFER] = true;
1621
+ }
1622
+ }
1623
+
1624
+ /**
1625
+ * Adds a new cartesian point in the end of the path.
1626
+ * @public
1627
+ * @param {Vec3} point3v - New coordinate.
1628
+ * @param {number} [multiLineIndex=0] - Path part index, first by default.
1629
+ */
1630
+ addPoint3v(point3v, multiLineIndex = 0) {
1631
+ //
1632
+ // TODO: could be optimized
1633
+ //
1634
+ if (multiLineIndex >= this._path3v.length) {
1635
+ this._path3v.push([]);
1636
+ }
1637
+ this._path3v[multiLineIndex].push(point3v);
1638
+ this.setPath3v([].concat(this._path3v));
1639
+ }
1640
+
1641
+ /**
1642
+ * Adds a new geodetic point in the end of the path.
1643
+ * @public
1644
+ * @param {LonLat} lonLat - New coordinate.
1645
+ * @param {number} [multiLineIndex=0] - Path part index, first by default.
1646
+ */
1647
+ addPointLonLat(lonLat, multiLineIndex = 0) {
1648
+ //
1649
+ // TODO: could be optimized
1650
+ //
1651
+ if (multiLineIndex >= this._pathLonLat.length) {
1652
+ this._pathLonLat.push([]);
1653
+ }
1654
+ this._pathLonLat[multiLineIndex].push(lonLat);
1655
+ this.setPathLonLat([].concat(this._pathLonLat));
1656
+ }
1657
+
1658
+ /**
1659
+ * Clear Polyline object data.
1660
+ * @public
1661
+ */
1662
+ clear() {
1663
+ this._clearData();
1664
+ }
1665
+
1666
+ setPointColor(color, index = 0, segmentIndex = 0) {
1667
+ if (this._renderNode && index < this._path3v[segmentIndex].length) {
1668
+ let colors = this._pathColors[segmentIndex];
1669
+
1670
+ if (!colors) {
1671
+ if (this._path3v[segmentIndex] && index < this._path3v[segmentIndex].length) {
1672
+ this._pathColors[segmentIndex] = new Array(this._path3v[segmentIndex].length);
1673
+ } else {
1674
+ return;
1675
+ }
1676
+ }
1677
+
1678
+ if (!colors[index]) {
1679
+ colors[index] = [color[R], color[G], color[B], color[A] || 1.0];
1680
+ } else {
1681
+ colors[index][R] = color[R];
1682
+ colors[index][G] = color[G];
1683
+ colors[index][B] = color[B];
1684
+ colors[index][A] = color[A] || 1.0;
1685
+ }
1686
+
1687
+ let c = this._colors;
1688
+
1689
+ //optimized with this._pathLengths
1690
+ //for (var i = 0; i < segmentIndex; i++) {
1691
+ // kk += this._path3v[i].length * 16 + 32;
1692
+ //}
1693
+
1694
+ let k = index * 16 + this._pathLengths[segmentIndex] * 16 + 32 * segmentIndex;
1695
+
1696
+ c[k] = c[k + 4] = c[k + 8] = c[k + 12] = color[R];
1697
+ c[k + 1] = c[k + 5] = c[k + 9] = c[k + 13] = color[G];
1698
+ c[k + 2] = c[k + 6] = c[k + 10] = c[k + 14] = color[B];
1699
+ c[k + 3] = c[k + 7] = c[k + 11] = c[k + 15] = color[A] || 1.0;
1700
+
1701
+ this._changedBuffers[COLORS_BUFFER] = true;
1702
+ } else {
1703
+ let pathColors = this._pathColors[segmentIndex];
1704
+ pathColors[index] = color;
1705
+ }
1706
+ }
1707
+
1708
+ /**
1709
+ * Sets Polyline opacity.
1710
+ * @public
1711
+ * @param {number} opacity - Opacity.
1712
+ */
1713
+ setOpacity(opacity) {
1714
+ this.color.w = opacity;
1715
+ }
1716
+
1717
+ /**
1718
+ * Sets Polyline thickness in screen pixels.
1719
+ * @public
1720
+ * @param {number} thickness - Thickness.
1721
+ */
1722
+ setThickness(thickness) {
1723
+ this.thickness = thickness;
1724
+ }
1725
+
1726
+ /**
1727
+ * Returns thickness.
1728
+ * @public
1729
+ * @return {number} Thickness in screen pixels.
1730
+ */
1731
+ getThickness() {
1732
+ return this.thickness;
1733
+ }
1734
+
1735
+ /**
1736
+ * Sets visibility.
1737
+ * @public
1738
+ * @param {boolean} visibility - Polyline visibility.
1739
+ */
1740
+ setVisibility(visibility) {
1741
+ this.visibility = visibility;
1742
+ }
1743
+
1744
+ /**
1745
+ * Gets Polyline visibility.
1746
+ * @public
1747
+ * @return {boolean} Polyline visibility.
1748
+ */
1749
+ getVisibility() {
1750
+ return this.visibility;
1751
+ }
1752
+
1753
+ /**
1754
+ * Assign with render node.
1755
+ * @public
1756
+ * @param {RenderNode} renderNode -
1757
+ */
1758
+ setRenderNode(renderNode) {
1759
+ if (renderNode) {
1760
+ this._renderNode = renderNode;
1761
+ if (this._pathLonLat.length) {
1762
+ this._createDataLonLat([].concat(this._pathLonLat));
1763
+ } else {
1764
+ this._createData3v([].concat(this._path3v));
1765
+ }
1766
+ this._refresh();
1767
+ this._update();
1768
+ }
1769
+ }
1770
+
1771
+ /**
1772
+ * @protected
1773
+ */
1774
+ _clearData() {
1775
+ this._verticesHigh = null;
1776
+ this._verticesLow = null;
1777
+ this._orders = null;
1778
+ this._indexes = null;
1779
+ this._colors = null;
1780
+
1781
+ this._verticesHigh = [];
1782
+ this._verticesLow = [];
1783
+ this._orders = [];
1784
+ this._indexes = [];
1785
+ this._colors = [];
1786
+
1787
+ this._path3v.length = 0;
1788
+ this._pathLonLat.length = 0;
1789
+ this._pathLonLatMerc.length = 0;
1790
+
1791
+ this._path3v = [];
1792
+ this._pathLonLat = [];
1793
+ this._pathLonLatMerc = [];
1794
+ }
1795
+
1796
+ _createData3v(path3v) {
1797
+ this._clearData();
1798
+ Polyline.appendLineData3v(
1799
+ path3v,
1800
+ this._pathColors,
1801
+ this._defaultColor,
1802
+ this._closedLine,
1803
+ this._verticesHigh,
1804
+ this._verticesLow,
1805
+ this._orders,
1806
+ this._indexes,
1807
+ this._renderNode.ellipsoid,
1808
+ this._pathLonLat,
1809
+ this._path3v,
1810
+ this._pathLonLatMerc,
1811
+ this._extent,
1812
+ this._colors
1813
+ );
1814
+ this._resizePathLengths(0);
1815
+ }
1816
+
1817
+ _createDataLonLat(pathLonlat) {
1818
+ this._clearData();
1819
+ Polyline.appendLineDataLonLat(
1820
+ pathLonlat,
1821
+ this._pathColors,
1822
+ this._defaultColor,
1823
+ this._closedLine,
1824
+ this._verticesHigh,
1825
+ this._verticesLow,
1826
+ this._orders,
1827
+ this._indexes,
1828
+ this._renderNode.ellipsoid,
1829
+ this._path3v,
1830
+ this._pathLonLat,
1831
+ this._pathLonLatMerc,
1832
+ this._extent,
1833
+ this._colors
1834
+ );
1835
+ this._resizePathLengths(0);
1836
+ }
1837
+
1838
+ /**
1839
+ * Removes from an entity.
1840
+ * @public
1841
+ */
1842
+ remove() {
1843
+ this._entity = null;
1844
+
1845
+ this._pathColors.length = 0;
1846
+ this._pathColors = [];
1847
+
1848
+ this._verticesHigh = null;
1849
+ this._verticesLow = null;
1850
+ this._orders = null;
1851
+ this._indexes = null;
1852
+ this._colors = null;
1853
+
1854
+ this._verticesHigh = [];
1855
+ this._verticesLow = [];
1856
+ this._orders = [];
1857
+ this._indexes = [];
1858
+ this._colors = [];
1859
+
1860
+ this._deleteBuffers();
1861
+
1862
+ this._handler && this._handler.remove(this);
1863
+ }
1864
+
1865
+ setPickingColor3v(color) {
1866
+ this._pickingColor[0] = color.x / 255.0;
1867
+ this._pickingColor[1] = color.y / 255.0;
1868
+ this._pickingColor[2] = color.z / 255.0;
1869
+ }
1870
+
1871
+ /**
1872
+ * Returns polyline geodetic extent.
1873
+ * @public
1874
+ * @returns {Extent} - Geodetic extent
1875
+ */
1876
+ getExtent() {
1877
+ return this._extent.clone();
1878
+ }
1879
+
1880
+ /**
1881
+ * Returns path cartesian coordinates.
1882
+ * @return {Array.<Vec3>} Polyline path.
1883
+ */
1884
+ getPath3v() {
1885
+ return this._path3v;
1886
+ }
1887
+
1888
+ /**
1889
+ * Returns geodetic path coordinates.
1890
+ * @return {Array.<LonLat>} Polyline path.
1891
+ */
1892
+ getPathLonLat() {
1893
+ return this._pathLonLat;
1894
+ }
1895
+
1896
+ getPathColors() {
1897
+ return this._pathColors;
1898
+ }
1899
+
1900
+ setPathColors(pathColors) {
1901
+ if (this._renderNode) {
1902
+ // ...
1903
+ }
1904
+ }
1905
+
1906
+ setColorHTML(htmlColor) {
1907
+ this._defaultColor = htmlColorToFloat32Array(htmlColor);
1908
+
1909
+ let color = htmlColorToRgba(htmlColor),
1910
+ p = this._pathColors;
1911
+
1912
+ for (let i = 0, len = p.length; i < len; i++) {
1913
+ let s = p[i];
1914
+ for (let j = 0, slen = s.length; j < slen; j++) {
1915
+ s[j][0] = color.x;
1916
+ s[j][1] = color.y;
1917
+ s[j][2] = color.z;
1918
+ s[j][3] = color.w;
1919
+ }
1920
+ }
1921
+
1922
+ let c = this._colors;
1923
+ for (let i = 0, len = c.length; i < len; i += 4) {
1924
+ c[i] = color.x;
1925
+ c[i + 1] = color.y;
1926
+ c[i + 2] = color.z;
1927
+ c[i + 3] = color.w;
1928
+ }
1929
+
1930
+ this._changedBuffers[COLORS_BUFFER] = true;
1931
+ }
1932
+
1933
+ /**
1934
+ * Sets geodetic coordinates.
1935
+ * @public
1936
+ * @param {Array.<Array.<number>>} pathLonLat - Polyline path cartesian coordinates. (exactly 3 entries)
1937
+ * @param {Boolean} [forceEqual=false] - Makes assigning faster for size equal coordinates array.
1938
+ */
1939
+ setPathLonLat(pathLonLat, forceEqual) {
1940
+ if (this._renderNode && this._renderNode.ellipsoid) {
1941
+ if (forceEqual) {
1942
+ this._setEqualPathLonLat(pathLonLat);
1943
+ this._changedBuffers[VERTICES_BUFFER] = true;
1944
+ this._changedBuffers[COLORS_BUFFER] = true;
1945
+ } else {
1946
+ this._createDataLonLat(pathLonLat);
1947
+ this._changedBuffers[VERTICES_BUFFER] = true;
1948
+ this._changedBuffers[INDEX_BUFFER] = true;
1949
+ this._changedBuffers[COLORS_BUFFER] = true;
1950
+ }
1951
+ } else {
1952
+ this._pathLonLat = [].concat(pathLonLat);
1953
+ }
1954
+ }
1955
+
1956
+ /**
1957
+ * Sets Polyline cartesian coordinates.
1958
+ * @public
1959
+ * @param {Array.<Array.<number>>} path3v - Polyline path cartesian coordinates. (exactly 3 entries)
1960
+ * @param {Boolean} [forceEqual=false] - Makes assigning faster for size equal coordinates array.
1961
+ */
1962
+ setPath3v(path3v, pathColors, forceEqual) {
1963
+ if (pathColors) {
1964
+ this._pathColors = [].concat(pathColors);
1965
+ }
1966
+
1967
+ if (this._renderNode) {
1968
+ if (forceEqual) {
1969
+ this._setEqualPath3v(path3v);
1970
+ this._changedBuffers[VERTICES_BUFFER] = true;
1971
+ this._changedBuffers[COLORS_BUFFER] = true;
1972
+ } else {
1973
+ this._createData3v(path3v);
1974
+ this._changedBuffers[VERTICES_BUFFER] = true;
1975
+ this._changedBuffers[INDEX_BUFFER] = true;
1976
+ this._changedBuffers[COLORS_BUFFER] = true;
1977
+ }
1978
+ } else {
1979
+ this._path3v = [].concat(path3v);
1980
+ }
1981
+ }
1982
+
1983
+ draw() {
1984
+ if (this.visibility && this._path3v.length) {
1985
+ this._update();
1986
+
1987
+ var rn = this._renderNode;
1988
+ var r = rn.renderer;
1989
+ var sh = r.handler.programs.polyline_screen;
1990
+ var p = sh._program;
1991
+ var gl = r.handler.gl,
1992
+ sha = p.attributes,
1993
+ shu = p.uniforms,
1994
+ ec = this._handler._entityCollection;
1995
+
1996
+ sh.activate();
1997
+
1998
+ gl.enable(gl.BLEND);
1999
+ gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
2000
+ gl.blendFuncSeparate(
2001
+ gl.SRC_ALPHA,
2002
+ gl.ONE_MINUS_SRC_ALPHA,
2003
+ gl.ONE,
2004
+ gl.ONE_MINUS_SRC_ALPHA
2005
+ );
2006
+ gl.disable(gl.CULL_FACE);
2007
+
2008
+ gl.uniform1f(shu.depthOffset, ec.polygonOffsetUnits + window.POLYLINE_DEPTH_OFFSET);
2009
+
2010
+ gl.uniformMatrix4fv(shu.proj, false, r.activeCamera.getProjectionMatrix());
2011
+ gl.uniformMatrix4fv(shu.view, false, r.activeCamera.getViewMatrix());
2012
+
2013
+ // gl.uniform4fv(shu.color, [this.color.x, this.color.y, this.color.z, this.color.w * this._handler._entityCollection._fadingOpacity]);
2014
+
2015
+ gl.uniform3fv(shu.eyePositionHigh, r.activeCamera.eyeHigh);
2016
+ gl.uniform3fv(shu.eyePositionLow, r.activeCamera.eyeLow);
2017
+
2018
+ gl.uniform2fv(shu.uFloatParams, [
2019
+ rn._planetRadius2 || 0.0,
2020
+ r.activeCamera._tanViewAngle_hradOneByHeight
2021
+ ]);
2022
+ gl.uniform2fv(shu.viewport, [r.handler.canvas.width, r.handler.canvas.height]);
2023
+ gl.uniform1f(shu.thickness, this.thickness * 0.5);
2024
+ gl.uniform1f(shu.opacity, ec._fadingOpacity);
2025
+
2026
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._colorsBuffer);
2027
+ gl.vertexAttribPointer(sha.color, this._colorsBuffer.itemSize, gl.FLOAT, false, 0, 0);
2028
+
2029
+ var v = this._verticesHighBuffer;
2030
+ gl.bindBuffer(gl.ARRAY_BUFFER, v);
2031
+ gl.vertexAttribPointer(sha.prevHigh, v.itemSize, gl.FLOAT, false, 12, 0);
2032
+ gl.vertexAttribPointer(sha.currentHigh, v.itemSize, gl.FLOAT, false, 12, 48);
2033
+ gl.vertexAttribPointer(sha.nextHigh, v.itemSize, gl.FLOAT, false, 12, 96);
2034
+
2035
+ v = this._verticesLowBuffer;
2036
+ gl.bindBuffer(gl.ARRAY_BUFFER, v);
2037
+ gl.vertexAttribPointer(sha.prevLow, v.itemSize, gl.FLOAT, false, 12, 0);
2038
+ gl.vertexAttribPointer(sha.currentLow, v.itemSize, gl.FLOAT, false, 12, 48);
2039
+ gl.vertexAttribPointer(sha.nextLow, v.itemSize, gl.FLOAT, false, 12, 96);
2040
+
2041
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._ordersBuffer);
2042
+ gl.vertexAttribPointer(sha.order, this._ordersBuffer.itemSize, gl.FLOAT, false, 4, 0);
2043
+
2044
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexesBuffer);
2045
+ gl.drawElements(gl.TRIANGLE_STRIP, this._indexesBuffer.numItems, gl.UNSIGNED_INT, 0);
2046
+ }
2047
+ }
2048
+
2049
+ drawPicking() {
2050
+ if (this.visibility && this._path3v.length) {
2051
+ var rn = this._renderNode;
2052
+ var r = rn.renderer;
2053
+ var sh = r.handler.programs.polyline_picking;
2054
+ var p = sh._program;
2055
+ var gl = r.handler.gl,
2056
+ sha = p.attributes,
2057
+ shu = p.uniforms;
2058
+
2059
+ sh.activate();
2060
+
2061
+ gl.enable(gl.BLEND);
2062
+ gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
2063
+ gl.blendFuncSeparate(
2064
+ gl.SRC_ALPHA,
2065
+ gl.ONE_MINUS_SRC_ALPHA,
2066
+ gl.ONE,
2067
+ gl.ONE_MINUS_SRC_ALPHA
2068
+ );
2069
+ gl.disable(gl.CULL_FACE);
2070
+
2071
+ gl.uniform1f(shu.depthOffset, this._handler._entityCollection.polygonOffsetUnits + window.POLYLINE_DEPTH_OFFSET);
2072
+
2073
+ gl.uniformMatrix4fv(shu.proj, false, r.activeCamera.getProjectionMatrix());
2074
+ gl.uniformMatrix4fv(shu.view, false, r.activeCamera.getViewMatrix());
2075
+
2076
+ gl.uniform4fv(shu.color, [
2077
+ this._pickingColor[0],
2078
+ this._pickingColor[1],
2079
+ this._pickingColor[2],
2080
+ 1.0
2081
+ ]);
2082
+
2083
+ gl.uniform3fv(shu.eyePositionHigh, r.activeCamera.eyeHigh);
2084
+ gl.uniform3fv(shu.eyePositionLow, r.activeCamera.eyeLow);
2085
+
2086
+ gl.uniform2fv(shu.uFloatParams, [
2087
+ rn._planetRadius2 || 0.0,
2088
+ r.activeCamera._tanViewAngle_hradOneByHeight
2089
+ ]);
2090
+ gl.uniform2fv(shu.viewport, [r.handler.canvas.width, r.handler.canvas.height]);
2091
+ gl.uniform1f(shu.thickness, this.thickness * 0.5);
2092
+
2093
+ var v = this._verticesHighBuffer;
2094
+ gl.bindBuffer(gl.ARRAY_BUFFER, v);
2095
+ gl.vertexAttribPointer(sha.prevHigh, v.itemSize, gl.FLOAT, false, 12, 0);
2096
+ gl.vertexAttribPointer(sha.currentHigh, v.itemSize, gl.FLOAT, false, 12, 48);
2097
+ gl.vertexAttribPointer(sha.nextHigh, v.itemSize, gl.FLOAT, false, 12, 96);
2098
+
2099
+ v = this._verticesLowBuffer;
2100
+ gl.bindBuffer(gl.ARRAY_BUFFER, v);
2101
+ gl.vertexAttribPointer(sha.prevLow, v.itemSize, gl.FLOAT, false, 12, 0);
2102
+ gl.vertexAttribPointer(sha.currentLow, v.itemSize, gl.FLOAT, false, 12, 48);
2103
+ gl.vertexAttribPointer(sha.nextLow, v.itemSize, gl.FLOAT, false, 12, 96);
2104
+
2105
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._ordersBuffer);
2106
+ gl.vertexAttribPointer(sha.order, this._ordersBuffer.itemSize, gl.FLOAT, false, 4, 0);
2107
+
2108
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexesBuffer);
2109
+ gl.drawElements(gl.TRIANGLE_STRIP, this._indexesBuffer.numItems, gl.UNSIGNED_INT, 0);
2110
+ }
2111
+ }
2112
+
2113
+ /**
2114
+ * Refresh buffers.
2115
+ * @protected
2116
+ */
2117
+ _refresh() {
2118
+ var i = this._changedBuffers.length;
2119
+ while (i--) {
2120
+ this._changedBuffers[i] = true;
2121
+ }
2122
+ }
2123
+
2124
+ /**
2125
+ * Updates render buffers.
2126
+ * @protected
2127
+ */
2128
+ _update() {
2129
+ if (this._renderNode) {
2130
+ var i = this._changedBuffers.length;
2131
+ while (i--) {
2132
+ if (this._changedBuffers[i]) {
2133
+ this._buffersUpdateCallbacks[i].call(this);
2134
+ this._changedBuffers[i] = false;
2135
+ }
2136
+ }
2137
+ }
2138
+ }
2139
+
2140
+ /**
2141
+ * Clear GL buffers.
2142
+ * @protected
2143
+ */
2144
+ _deleteBuffers() {
2145
+ if (this._renderNode) {
2146
+ var r = this._renderNode.renderer,
2147
+ gl = r.handler.gl;
2148
+
2149
+ gl.deleteBuffer(this._verticesHighBuffer);
2150
+ gl.deleteBuffer(this._verticesLowBuffer);
2151
+ gl.deleteBuffer(this._ordersBuffer);
2152
+ gl.deleteBuffer(this._indexesBuffer);
2153
+ gl.deleteBuffer(this._colorsBuffer);
2154
+
2155
+ this._verticesHighBuffer = null;
2156
+ this._verticesLowBuffer = null;
2157
+ this._ordersBuffer = null;
2158
+ this._indexesBuffer = null;
2159
+ this._colorsBuffer = null;
2160
+ }
2161
+ }
2162
+
2163
+ /**
2164
+ * Creates gl main data buffer.
2165
+ * @protected
2166
+ */
2167
+ _createVerticesBuffer() {
2168
+ var h = this._renderNode.renderer.handler;
2169
+
2170
+ let numItems = this._verticesHigh.length / 3;
2171
+
2172
+ if (!this._verticesHighBuffer || this._verticesHighBuffer.numItems !== numItems) {
2173
+ h.gl.deleteBuffer(this._verticesHighBuffer);
2174
+ h.gl.deleteBuffer(this._verticesLowBuffer);
2175
+ this._verticesHighBuffer = h.createStreamArrayBuffer(3, numItems);
2176
+ this._verticesLowBuffer = h.createStreamArrayBuffer(3, numItems);
2177
+ }
2178
+
2179
+ this._verticesHigh = makeArrayTyped(this._verticesHigh);
2180
+ this._verticesLow = makeArrayTyped(this._verticesLow);
2181
+
2182
+ h.setStreamArrayBuffer(this._verticesHighBuffer, this._verticesHigh);
2183
+ h.setStreamArrayBuffer(this._verticesLowBuffer, this._verticesLow);
2184
+ }
2185
+
2186
+ /**
2187
+ * Creates gl index and order buffer.
2188
+ * @protected
2189
+ */
2190
+ _createIndexBuffer() {
2191
+ var h = this._renderNode.renderer.handler;
2192
+ h.gl.deleteBuffer(this._ordersBuffer);
2193
+ h.gl.deleteBuffer(this._indexesBuffer);
2194
+
2195
+ this._orders = makeArrayTyped(this._orders);
2196
+
2197
+ this._ordersBuffer = h.createArrayBuffer(this._orders, 1, this._orders.length / 2);
2198
+
2199
+ this._indexes = makeArrayTyped(this._indexes, Uint32Array);
2200
+
2201
+ this._indexesBuffer = h.createElementArrayBuffer(this._indexes, 1, this._indexes.length);
2202
+ }
2203
+
2204
+ _createColorsBuffer() {
2205
+ var h = this._renderNode.renderer.handler;
2206
+ h.gl.deleteBuffer(this._colorsBuffer);
2207
+
2208
+ this._colors = makeArrayTyped(this._colors);
2209
+
2210
+ this._colorsBuffer = h.createArrayBuffer(
2211
+ new Float32Array(this._colors),
2212
+ 4,
2213
+ this._colors.length / 4
2214
+ );
2215
+ }
2216
+ }
2217
+
2218
+ export { Polyline };