@openglobus/og 0.13.10 → 0.14.1

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 (83) hide show
  1. package/README.md +1 -4
  2. package/css/og.css +1 -1
  3. package/dist/@openglobus/og.css +1 -1
  4. package/dist/@openglobus/og.esm.js +2 -2
  5. package/dist/@openglobus/og.esm.js.map +1 -1
  6. package/dist/@openglobus/og.umd.js +2 -2
  7. package/dist/@openglobus/og.umd.js.map +1 -1
  8. package/package.json +2 -2
  9. package/src/og/Globe.js +14 -4
  10. package/src/og/camera/Camera.js +7 -7
  11. package/src/og/camera/PlanetCamera.js +1 -1
  12. package/src/og/control/LayerSwitcher.js +48 -31
  13. package/src/og/control/MouseNavigation.js +2 -2
  14. package/src/og/control/ScaleControl.js +30 -10
  15. package/src/og/control/SimpleSkyBackground.js +184 -0
  16. package/src/og/control/Sun.js +3 -2
  17. package/src/og/ellipsoid/Ellipsoid.js +119 -92
  18. package/src/og/ellipsoid/wgs84.js +13 -13
  19. package/src/og/entity/Entity.js +3 -3
  20. package/src/og/entity/GeometryHandler.js +1341 -1337
  21. package/src/og/entity/LabelHandler.js +1 -4
  22. package/src/og/entity/LabelWorker.js +10 -13
  23. package/src/og/entity/Polyline.js +0 -16
  24. package/src/og/entity/Ray.js +0 -10
  25. package/src/og/entity/RayHandler.js +3 -44
  26. package/src/og/entity/Strip.js +1 -6
  27. package/src/og/index.js +106 -95
  28. package/src/og/layer/GeoVideo.js +1 -0
  29. package/src/og/layer/Layer.js +62 -3
  30. package/src/og/layer/XYZ.js +4 -3
  31. package/src/og/math/Line3.js +140 -139
  32. package/src/og/math/Plane.js +118 -117
  33. package/src/og/math/Ray.js +242 -239
  34. package/src/og/math/Vec3.js +56 -37
  35. package/src/og/math/Vec4.js +3 -4
  36. package/src/og/math.js +21 -21
  37. package/src/og/quadTree/EarthQuadTreeStrategy.js +29 -0
  38. package/src/og/quadTree/MarsQuadTreeStrategy.js +27 -0
  39. package/src/og/quadTree/Node.js +55 -218
  40. package/src/og/quadTree/QuadTreeStrategy.js +93 -0
  41. package/src/og/quadTree/Wgs84QuadTreeStrategy.js +26 -0
  42. package/src/og/renderer/Renderer.js +13 -12
  43. package/src/og/renderer/RendererEvents.js +1065 -1065
  44. package/src/og/scene/Planet.js +84 -273
  45. package/src/og/segment/Segment.js +18 -25
  46. package/src/og/segment/SegmentLonLat.js +34 -31
  47. package/src/og/segment/SegmentLonLatWgs84.js +41 -0
  48. package/src/og/shaders/ray.js +13 -6
  49. package/src/og/shaders/toneMapping.js +5 -5
  50. package/src/og/terrain/GlobusTerrain.js +3 -2
  51. package/src/og/terrain/MapboxTerrain.js +231 -52
  52. package/src/og/utils/quadTreeType.js +11 -0
  53. package/src/og/utils/shared.js +942 -942
  54. package/src/og/webgl/Handler.js +22 -9
  55. package/types/Globe.d.ts +7 -0
  56. package/types/camera/Camera.d.ts +3 -3
  57. package/types/camera/PlanetCamera.d.ts +1 -1
  58. package/types/control/LayerSwitcher.d.ts +1 -1
  59. package/types/control/ScaleControl.d.ts +2 -1
  60. package/types/control/SimpleSkyBackground.d.ts +11 -0
  61. package/types/control/Sun.d.ts +2 -1
  62. package/types/ellipsoid/Ellipsoid.d.ts +3 -2
  63. package/types/entity/LabelWorker.d.ts +1 -1
  64. package/types/entity/Ray.d.ts +0 -3
  65. package/types/entity/RayHandler.d.ts +0 -4
  66. package/types/index.d.ts +6 -1
  67. package/types/layer/Layer.d.ts +8 -0
  68. package/types/math/Vec3.d.ts +19 -16
  69. package/types/math/Vec4.d.ts +2 -3
  70. package/types/math.d.ts +20 -20
  71. package/types/quadTree/EarthQuadTreeStrategy.d.ts +3 -0
  72. package/types/quadTree/MarsQuadTreeStrategy.d.ts +3 -0
  73. package/types/quadTree/Node.d.ts +0 -1
  74. package/types/quadTree/QuadTreeStrategy.d.ts +21 -0
  75. package/types/quadTree/Wgs84QuadTreeStrategy.d.ts +3 -0
  76. package/types/renderer/Renderer.d.ts +1 -1
  77. package/types/scene/Planet.d.ts +6 -24
  78. package/types/segment/Segment.d.ts +4 -4
  79. package/types/segment/SegmentLonLat.d.ts +6 -2
  80. package/types/segment/SegmentLonLatWgs84.d.ts +4 -0
  81. package/types/terrain/MapboxTerrain.d.ts +2 -1
  82. package/types/utils/quadTreeType.d.ts +8 -0
  83. package/types/webgl/Handler.d.ts +4 -1
@@ -1,1337 +1,1341 @@
1
- /**
2
- * @module og/entity/GeometryHandler
3
- */
4
-
5
- "use strict";
6
-
7
- import * as mercator from "../mercator.js";
8
- import * as quadTree from "../quadTree/quadTree.js";
9
- import { earcut, flatten } from "../utils/earcut.js";
10
- import { GeometryType } from "./Geometry.js";
11
- import { Vec2 } from "../math/Vec2.js";
12
- import { doubleToTwoFloatsV2 } from "../math/coder.js";
13
-
14
- const POLYVERTICES_BUFFER = 0;
15
- const POLYINDEXES_BUFFER = 1;
16
- const POLYCOLORS_BUFFER = 2;
17
- const LINEVERTICES_BUFFER = 3;
18
- const LINEINDEXES_BUFFER = 4;
19
- const LINEORDERS_BUFFER = 5;
20
- const LINECOLORS_BUFFER = 6;
21
- const LINETHICKNESS_BUFFER = 7;
22
- const LINESTROKES_BUFFER = 8;
23
- const LINESTROKECOLORS_BUFFER = 9;
24
- const POLYPICKINGCOLORS_BUFFER = 10;
25
- const LINEPICKINGCOLORS_BUFFER = 11;
26
-
27
- function doubleToTwoFloats(v, high, low) {
28
- let x = v[0],
29
- y = v[1];
30
-
31
- if (x >= 0.0) {
32
- let doubleHigh = Math.floor(x / 65536.0) * 65536.0;
33
- high.x = Math.fround(doubleHigh);
34
- low.x = Math.fround(x - doubleHigh);
35
- } else {
36
- let doubleHigh = Math.floor(-x / 65536.0) * 65536.0;
37
- high.x = Math.fround(-doubleHigh);
38
- low.x = Math.fround(x + doubleHigh);
39
- }
40
-
41
- if (y >= 0.0) {
42
- let doubleHigh = Math.floor(y / 65536.0) * 65536.0;
43
- high.y = Math.fround(doubleHigh);
44
- low.y = Math.fround(y - doubleHigh);
45
- } else {
46
- let doubleHigh = Math.floor(-y / 65536.0) * 65536.0;
47
- high.y = Math.fround(-doubleHigh);
48
- low.y = Math.fround(y + doubleHigh);
49
- }
50
- }
51
-
52
- let tempHigh = new Vec2(),
53
- tempLow = new Vec2(),
54
- tempHighLow = new Vec2();
55
-
56
- class GeometryHandler {
57
- constructor(layer) {
58
- this.__staticId = GeometryHandler._staticCounter++;
59
-
60
- this._layer = layer;
61
-
62
- this._handler = null;
63
-
64
- this._geometries = [];
65
-
66
- this._updatedGeometryArr = [];
67
- this._updatedGeometry = {};
68
-
69
- this._removeGeometryExtentArr = [];
70
- this._removeGeometryExtents = {};
71
-
72
- // Polygon arrays
73
- this._polyVerticesHighMerc = [];
74
- this._polyVerticesLowMerc = [];
75
- this._polyColors = [];
76
- this._polyPickingColors = [];
77
- this._polyIndexes = [];
78
-
79
- // Line arrays
80
- this._lineVerticesHighMerc = [];
81
- this._lineVerticesLowMerc = [];
82
- this._lineOrders = [];
83
- this._lineIndexes = [];
84
- this._lineColors = [];
85
- this._linePickingColors = [];
86
- this._lineThickness = [];
87
- this._lineStrokes = [];
88
- this._lineStrokeColors = [];
89
-
90
- // Buffers
91
- this._polyVerticesHighBufferMerc = null;
92
- this._polyVerticesLowBufferMerc = null;
93
- this._polyColorsBuffer = null;
94
- this._polyPickingColorsBuffer = null;
95
- this._polyIndexesBuffer = null;
96
-
97
- this._lineVerticesHighBufferMerc = null;
98
- this._lineVerticesLowBufferMerc = null;
99
- this._lineColorsBuffer = null;
100
- this._linePickingColorsBuffer = null;
101
- this._lineThicknessBuffer = null;
102
- this._lineStrokesBuffer = null;
103
- this._lineStrokeColorsBuffer = null;
104
- this._lineOrdersBuffer = null;
105
- this._lineIndexesBuffer = null;
106
-
107
- this._buffersUpdateCallbacks = [];
108
- this._buffersUpdateCallbacks[POLYVERTICES_BUFFER] = this.createPolyVerticesBuffer;
109
- this._buffersUpdateCallbacks[POLYINDEXES_BUFFER] = this.createPolyIndexesBuffer;
110
- this._buffersUpdateCallbacks[POLYCOLORS_BUFFER] = this.createPolyColorsBuffer;
111
- this._buffersUpdateCallbacks[LINEVERTICES_BUFFER] = this.createLineVerticesBuffer;
112
- this._buffersUpdateCallbacks[LINEINDEXES_BUFFER] = this.createLineIndexesBuffer;
113
- this._buffersUpdateCallbacks[LINEORDERS_BUFFER] = this.createLineOrdersBuffer;
114
- this._buffersUpdateCallbacks[LINECOLORS_BUFFER] = this.createLineColorsBuffer;
115
- this._buffersUpdateCallbacks[LINETHICKNESS_BUFFER] = this.createLineThicknessBuffer;
116
- this._buffersUpdateCallbacks[LINESTROKES_BUFFER] = this.createLineStrokesBuffer;
117
- this._buffersUpdateCallbacks[LINESTROKECOLORS_BUFFER] = this.createLineStrokeColorsBuffer;
118
- this._buffersUpdateCallbacks[POLYPICKINGCOLORS_BUFFER] = this.createPolyPickingColorsBuffer;
119
- this._buffersUpdateCallbacks[LINEPICKINGCOLORS_BUFFER] = this.createLinePickingColorsBuffer;
120
-
121
- this._changedBuffers = new Array(this._buffersUpdateCallbacks.length);
122
- }
123
-
124
- static get _staticCounter() {
125
- if (!this._counter && this._counter !== 0) {
126
- this._counter = 0;
127
- }
128
- return this._counter;
129
- }
130
-
131
- static set _staticCounter(n) {
132
- this._counter = n;
133
- }
134
-
135
- static appendLineData(
136
- pathArr,
137
- isClosed,
138
- color,
139
- pickingColor,
140
- thickness,
141
- strokeColor,
142
- strokeSize,
143
- outVerticesHigh,
144
- outVerticesLow,
145
- outOrders,
146
- outIndexes,
147
- outColors,
148
- outPickingColors,
149
- outThickness,
150
- outStrokeColors,
151
- outStrokes,
152
- outVerticesHigh2,
153
- outVerticesLow2
154
- ) {
155
- var index = 0;
156
-
157
- if (outIndexes.length > 0) {
158
- index = outIndexes[outIndexes.length - 5] + 9;
159
- outIndexes.push(index, index);
160
- } else {
161
- outIndexes.push(0, 0);
162
- }
163
-
164
- var t = thickness,
165
- c = [color.x, color.y, color.z, color.w],
166
- s = strokeSize,
167
- sc = [strokeColor.x, strokeColor.y, strokeColor.z, strokeColor.w],
168
- p = [pickingColor.x, pickingColor.y, pickingColor.z, 1.0];
169
-
170
- for (var j = 0; j < pathArr.length; j++) {
171
- var path = pathArr[j];
172
-
173
- if (path.length === 0) {
174
- continue;
175
- }
176
-
177
- var startIndex = index;
178
- var last;
179
- if (isClosed) {
180
- last = path[path.length - 1];
181
- } else {
182
- let p0 = path[0],
183
- p1 = path[1];
184
-
185
- if (!p1) {
186
- p1 = p0;
187
- }
188
-
189
- last = [p0[0] + p0[0] - p1[0], p0[1] + p0[1] - p1[1]];
190
- }
191
-
192
- doubleToTwoFloats(last, tempHigh, tempLow);
193
-
194
- outVerticesHigh.push(
195
- tempHigh.x,
196
- tempHigh.y,
197
- tempHigh.x,
198
- tempHigh.y,
199
- tempHigh.x,
200
- tempHigh.y,
201
- tempHigh.x,
202
- tempHigh.y
203
- );
204
- outVerticesLow.push(
205
- tempLow.x,
206
- tempLow.y,
207
- tempLow.x,
208
- tempLow.y,
209
- tempLow.x,
210
- tempLow.y,
211
- tempLow.x,
212
- tempLow.y
213
- );
214
-
215
- outVerticesHigh2.push(
216
- tempHigh.x,
217
- tempHigh.y,
218
- tempHigh.x,
219
- tempHigh.y,
220
- tempHigh.x,
221
- tempHigh.y,
222
- tempHigh.x,
223
- tempHigh.y
224
- );
225
- outVerticesLow2.push(
226
- tempLow.x,
227
- tempLow.y,
228
- tempLow.x,
229
- tempLow.y,
230
- tempLow.x,
231
- tempLow.y,
232
- tempLow.x,
233
- tempLow.y
234
- );
235
-
236
- outOrders.push(1, -1, 2, -2);
237
-
238
- outThickness.push(t, t, t, t);
239
- outStrokes.push(s, s, s, s);
240
- outColors.push(
241
- c[0],
242
- c[1],
243
- c[2],
244
- c[3],
245
- c[0],
246
- c[1],
247
- c[2],
248
- c[3],
249
- c[0],
250
- c[1],
251
- c[2],
252
- c[3],
253
- c[0],
254
- c[1],
255
- c[2],
256
- c[3]
257
- );
258
- outStrokeColors.push(
259
- sc[0],
260
- sc[1],
261
- sc[2],
262
- sc[3],
263
- sc[0],
264
- sc[1],
265
- sc[2],
266
- sc[3],
267
- sc[0],
268
- sc[1],
269
- sc[2],
270
- sc[3],
271
- sc[0],
272
- sc[1],
273
- sc[2],
274
- sc[3]
275
- );
276
- outPickingColors.push(
277
- p[0],
278
- p[1],
279
- p[2],
280
- p[3],
281
- p[0],
282
- p[1],
283
- p[2],
284
- p[3],
285
- p[0],
286
- p[1],
287
- p[2],
288
- p[3],
289
- p[0],
290
- p[1],
291
- p[2],
292
- p[3]
293
- );
294
-
295
- for (var i = 0; i < path.length; i++) {
296
- var cur = path[i];
297
-
298
- doubleToTwoFloats(cur, tempHigh, tempLow);
299
-
300
- outVerticesHigh.push(
301
- tempHigh.x,
302
- tempHigh.y,
303
- tempHigh.x,
304
- tempHigh.y,
305
- tempHigh.x,
306
- tempHigh.y,
307
- tempHigh.x,
308
- tempHigh.y
309
- );
310
- outVerticesLow.push(
311
- tempLow.x,
312
- tempLow.y,
313
- tempLow.x,
314
- tempLow.y,
315
- tempLow.x,
316
- tempLow.y,
317
- tempLow.x,
318
- tempLow.y
319
- );
320
-
321
- outVerticesHigh2.push(
322
- tempHigh.x,
323
- tempHigh.y,
324
- tempHigh.x,
325
- tempHigh.y,
326
- tempHigh.x,
327
- tempHigh.y,
328
- tempHigh.x,
329
- tempHigh.y
330
- );
331
- outVerticesLow2.push(
332
- tempLow.x,
333
- tempLow.y,
334
- tempLow.x,
335
- tempLow.y,
336
- tempLow.x,
337
- tempLow.y,
338
- tempLow.x,
339
- tempLow.y
340
- );
341
-
342
- outOrders.push(1, -1, 2, -2);
343
- outThickness.push(t, t, t, t);
344
- outStrokes.push(s, s, s, s);
345
- outColors.push(
346
- c[0],
347
- c[1],
348
- c[2],
349
- c[3],
350
- c[0],
351
- c[1],
352
- c[2],
353
- c[3],
354
- c[0],
355
- c[1],
356
- c[2],
357
- c[3],
358
- c[0],
359
- c[1],
360
- c[2],
361
- c[3]
362
- );
363
- outStrokeColors.push(
364
- sc[0],
365
- sc[1],
366
- sc[2],
367
- sc[3],
368
- sc[0],
369
- sc[1],
370
- sc[2],
371
- sc[3],
372
- sc[0],
373
- sc[1],
374
- sc[2],
375
- sc[3],
376
- sc[0],
377
- sc[1],
378
- sc[2],
379
- sc[3]
380
- );
381
- outPickingColors.push(
382
- p[0],
383
- p[1],
384
- p[2],
385
- p[3],
386
- p[0],
387
- p[1],
388
- p[2],
389
- p[3],
390
- p[0],
391
- p[1],
392
- p[2],
393
- p[3],
394
- p[0],
395
- p[1],
396
- p[2],
397
- p[3]
398
- );
399
- outIndexes.push(index++, index++, index++, index++);
400
- }
401
-
402
- var first;
403
- if (isClosed) {
404
- first = path[0];
405
- outIndexes.push(startIndex, startIndex + 1, startIndex + 1, startIndex + 1);
406
- } else {
407
- let p0 = path[path.length - 1],
408
- p1 = path[path.length - 2];
409
-
410
- if (!p1) {
411
- p1 = p0;
412
- }
413
-
414
- first = [p0[0] + p0[0] - p1[0], p0[1] + p0[1] - p1[1]];
415
- outIndexes.push(index - 1, index - 1, index - 1, index - 1);
416
- }
417
-
418
- doubleToTwoFloats(first, tempHigh, tempLow);
419
-
420
- outVerticesHigh.push(
421
- tempHigh.x,
422
- tempHigh.y,
423
- tempHigh.x,
424
- tempHigh.y,
425
- tempHigh.x,
426
- tempHigh.y,
427
- tempHigh.x,
428
- tempHigh.y
429
- );
430
- outVerticesLow.push(
431
- tempLow.x,
432
- tempLow.y,
433
- tempLow.x,
434
- tempLow.y,
435
- tempLow.x,
436
- tempLow.y,
437
- tempLow.x,
438
- tempLow.y
439
- );
440
-
441
- outVerticesHigh2.push(
442
- tempHigh.x,
443
- tempHigh.y,
444
- tempHigh.x,
445
- tempHigh.y,
446
- tempHigh.x,
447
- tempHigh.y,
448
- tempHigh.x,
449
- tempHigh.y
450
- );
451
- outVerticesLow2.push(
452
- tempLow.x,
453
- tempLow.y,
454
- tempLow.x,
455
- tempLow.y,
456
- tempLow.x,
457
- tempLow.y,
458
- tempLow.x,
459
- tempLow.y
460
- );
461
-
462
- outOrders.push(1, -1, 2, -2);
463
- outThickness.push(t, t, t, t);
464
- outStrokes.push(s, s, s, s);
465
- outColors.push(
466
- c[0],
467
- c[1],
468
- c[2],
469
- c[3],
470
- c[0],
471
- c[1],
472
- c[2],
473
- c[3],
474
- c[0],
475
- c[1],
476
- c[2],
477
- c[3],
478
- c[0],
479
- c[1],
480
- c[2],
481
- c[3]
482
- );
483
- outStrokeColors.push(
484
- sc[0],
485
- sc[1],
486
- sc[2],
487
- sc[3],
488
- sc[0],
489
- sc[1],
490
- sc[2],
491
- sc[3],
492
- sc[0],
493
- sc[1],
494
- sc[2],
495
- sc[3],
496
- sc[0],
497
- sc[1],
498
- sc[2],
499
- sc[3]
500
- );
501
- outPickingColors.push(
502
- p[0],
503
- p[1],
504
- p[2],
505
- p[3],
506
- p[0],
507
- p[1],
508
- p[2],
509
- p[3],
510
- p[0],
511
- p[1],
512
- p[2],
513
- p[3],
514
- p[0],
515
- p[1],
516
- p[2],
517
- p[3]
518
- );
519
-
520
- if (j < pathArr.length - 1) {
521
- index += 8;
522
- outIndexes.push(index, index);
523
- }
524
- }
525
- }
526
-
527
- assignHandler(handler) {
528
- this._handler = handler;
529
- this.refresh();
530
- }
531
-
532
- /**
533
- * @public
534
- * @param {Geometry} geometry - Geometry object.
535
- */
536
- add(geometry) {
537
- //
538
- // Triangulates polygon and sets geometry data.
539
- if (geometry._handlerIndex === -1) {
540
- geometry._handler = this;
541
- geometry._handlerIndex = this._geometries.length;
542
- this._geometries.push(geometry);
543
-
544
- let pickingColor = geometry._entity._pickingColor.scaleTo(1 / 255);
545
-
546
- geometry._polyVerticesHighMerc = [];
547
- geometry._polyVerticesLowMerc = [];
548
- geometry._lineVerticesHighMerc = [];
549
- geometry._lineVerticesLowMerc = [];
550
-
551
- if (geometry._type === GeometryType.POLYGON) {
552
- let coordinates = geometry._coordinates;
553
- let ci = [];
554
- for (let j = 0; j < coordinates.length; j++) {
555
- ci[j] = [];
556
- for (var k = 0; k < coordinates[j].length; k++) {
557
- ci[j][k] = [
558
- mercator.forward_lon(coordinates[j][k][0]),
559
- mercator.forward_lat(coordinates[j][k][1])
560
- ];
561
- }
562
- }
563
-
564
- let data = flatten(ci);
565
- let indexes = earcut(data.vertices, data.holes, 2);
566
-
567
- geometry._polyVerticesHandlerIndex = this._polyVerticesHighMerc.length;
568
- geometry._polyIndexesHandlerIndex = this._polyIndexes.length;
569
-
570
- for (let i = 0; i < indexes.length; i++) {
571
- this._polyIndexes.push(indexes[i] + geometry._polyVerticesHandlerIndex * 0.5);
572
- }
573
-
574
- var color = geometry._style.fillColor;
575
-
576
- let verticesHigh = [],
577
- verticesLow = [];
578
-
579
- for (let i = 0; i < data.vertices.length * 0.5; i++) {
580
- this._polyColors.push(color.x, color.y, color.z, color.w);
581
- this._polyPickingColors.push(
582
- pickingColor.x,
583
- pickingColor.y,
584
- pickingColor.z,
585
- 1.0
586
- );
587
- }
588
-
589
- for (let i = 0; i < data.vertices.length; i++) {
590
- doubleToTwoFloatsV2(data.vertices[i], tempHighLow);
591
- verticesHigh[i] = tempHighLow.x;
592
- verticesLow[i] = tempHighLow.y;
593
- }
594
-
595
- geometry._polyVerticesHighMerc = verticesHigh;
596
- geometry._polyVerticesLowMerc = verticesLow;
597
-
598
- this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc, verticesHigh);
599
- this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc, verticesLow);
600
-
601
- geometry._polyVerticesLength = data.vertices.length;
602
- geometry._polyIndexesLength = indexes.length;
603
-
604
- // Creates polygon stroke data
605
- geometry._lineVerticesHandlerIndex = this._lineVerticesHighMerc.length;
606
- geometry._lineOrdersHandlerIndex = this._lineOrders.length;
607
- geometry._lineIndexesHandlerIndex = this._lineIndexes.length;
608
- geometry._lineColorsHandlerIndex = this._lineColors.length;
609
- geometry._lineThicknessHandlerIndex = this._lineThickness.length;
610
-
611
- GeometryHandler.appendLineData(
612
- ci,
613
- true,
614
- geometry._style.lineColor,
615
- pickingColor,
616
- geometry._style.lineWidth,
617
- geometry._style.strokeColor,
618
- geometry._style.strokeWidth,
619
- this._lineVerticesHighMerc,
620
- this._lineVerticesLowMerc,
621
- this._lineOrders,
622
- this._lineIndexes,
623
- this._lineColors,
624
- this._linePickingColors,
625
- this._lineThickness,
626
- this._lineStrokeColors,
627
- this._lineStrokes,
628
- geometry._lineVerticesHighMerc,
629
- geometry._lineVerticesLowMerc
630
- );
631
-
632
- geometry._lineVerticesLength =
633
- this._lineVerticesHighMerc.length - geometry._lineVerticesHandlerIndex;
634
- geometry._lineOrdersLength =
635
- this._lineOrders.length - geometry._lineOrdersHandlerIndex;
636
- geometry._lineIndexesLength =
637
- this._lineIndexes.length - geometry._lineIndexesHandlerIndex;
638
- geometry._lineColorsLength =
639
- this._lineColors.length - geometry._lineColorsHandlerIndex;
640
- geometry._lineThicknessLength =
641
- this._lineThickness.length - geometry._lineThicknessHandlerIndex;
642
- } else if (geometry._type === GeometryType.MULTIPOLYGON) {
643
- let coordinates = geometry._coordinates;
644
- let vertices = [],
645
- indexes = [];
646
-
647
- // Creates polygon stroke data
648
- geometry._lineVerticesHandlerIndex = this._lineVerticesHighMerc.length;
649
- geometry._lineOrdersHandlerIndex = this._lineOrders.length;
650
- geometry._lineIndexesHandlerIndex = this._lineIndexes.length;
651
- geometry._lineColorsHandlerIndex = this._lineColors.length;
652
- geometry._lineThicknessHandlerIndex = this._lineThickness.length;
653
-
654
- for (var i = 0; i < coordinates.length; i++) {
655
- let cci = coordinates[i];
656
- let ci = [];
657
- for (let j = 0; j < cci.length; j++) {
658
- ci[j] = [];
659
- for (let k = 0; k < coordinates[i][j].length; k++) {
660
- ci[j][k] = [
661
- mercator.forward_lon(cci[j][k][0]),
662
- mercator.forward_lat(cci[j][k][1])
663
- ];
664
- }
665
- }
666
- let data = flatten(ci);
667
- let dataIndexes = earcut(data.vertices, data.holes, 2);
668
-
669
- for (let j = 0; j < dataIndexes.length; j++) {
670
- indexes.push(dataIndexes[j] + vertices.length * 0.5);
671
- }
672
-
673
- vertices.push.apply(vertices, data.vertices);
674
-
675
- GeometryHandler.appendLineData(
676
- ci,
677
- true,
678
- geometry._style.lineColor,
679
- pickingColor,
680
- geometry._style.lineWidth,
681
- geometry._style.strokeColor,
682
- geometry._style.strokeWidth,
683
- this._lineVerticesHighMerc,
684
- this._lineVerticesLowMerc,
685
- this._lineOrders,
686
- this._lineIndexes,
687
- this._lineColors,
688
- this._linePickingColors,
689
- this._lineThickness,
690
- this._lineStrokeColors,
691
- this._lineStrokes,
692
- geometry._lineVerticesHighMerc,
693
- geometry._lineVerticesLowMerc
694
- );
695
- }
696
-
697
- geometry._polyVerticesHandlerIndex = this._polyVerticesHighMerc.length;
698
- geometry._polyIndexesHandlerIndex = this._polyIndexes.length;
699
-
700
- for (let i = 0; i < indexes.length; i++) {
701
- this._polyIndexes.push(indexes[i] + geometry._polyVerticesHandlerIndex * 0.5);
702
- }
703
-
704
- let color = geometry._style.fillColor;
705
-
706
- let verticesHigh = [],
707
- verticesLow = [];
708
-
709
- for (let i = 0; i < vertices.length * 0.5; i++) {
710
- this._polyColors.push(color.x, color.y, color.z, color.w);
711
- this._polyPickingColors.push(
712
- pickingColor.x,
713
- pickingColor.y,
714
- pickingColor.z,
715
- 1.0
716
- );
717
- }
718
-
719
- for (let i = 0; i < vertices.length; i++) {
720
- doubleToTwoFloatsV2(vertices[i], tempHighLow);
721
- verticesHigh[i] = tempHighLow.x;
722
- verticesLow[i] = tempHighLow.y;
723
- }
724
-
725
- geometry._polyVerticesHighMerc = verticesHigh;
726
- geometry._polyVerticesLowMerc = verticesLow;
727
-
728
- this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc, verticesHigh);
729
- this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc, verticesLow);
730
-
731
- geometry._polyVerticesLength = vertices.length;
732
- geometry._polyIndexesLength = indexes.length;
733
-
734
- geometry._lineVerticesLength =
735
- this._lineVerticesHighMerc.length - geometry._lineVerticesHandlerIndex;
736
- geometry._lineOrdersLength =
737
- this._lineOrders.length - geometry._lineOrdersHandlerIndex;
738
- geometry._lineIndexesLength =
739
- this._lineIndexes.length - geometry._lineIndexesHandlerIndex;
740
- geometry._lineColorsLength =
741
- this._lineColors.length - geometry._lineColorsHandlerIndex;
742
- geometry._lineThicknessLength =
743
- this._lineThickness.length - geometry._lineThicknessHandlerIndex;
744
- } else if (geometry._type === GeometryType.LINESTRING) {
745
- let coordinates = geometry._coordinates;
746
- let ci = new Array(coordinates.length);
747
- for (let j = 0; j < coordinates.length; j++) {
748
- ci[j] = [
749
- mercator.forward_lon(coordinates[j][0]),
750
- mercator.forward_lat(coordinates[j][1])
751
- ];
752
- }
753
-
754
- // Creates polygon stroke data
755
- geometry._lineVerticesHandlerIndex = this._lineVerticesHighMerc.length;
756
- geometry._lineOrdersHandlerIndex = this._lineOrders.length;
757
- geometry._lineIndexesHandlerIndex = this._lineIndexes.length;
758
- geometry._lineColorsHandlerIndex = this._lineColors.length;
759
- geometry._lineThicknessHandlerIndex = this._lineThickness.length;
760
-
761
- GeometryHandler.appendLineData(
762
- [ci],
763
- false,
764
- geometry._style.lineColor,
765
- pickingColor,
766
- geometry._style.lineWidth,
767
- geometry._style.strokeColor,
768
- geometry._style.strokeWidth,
769
- this._lineVerticesHighMerc,
770
- this._lineVerticesLowMerc,
771
- this._lineOrders,
772
- this._lineIndexes,
773
- this._lineColors,
774
- this._linePickingColors,
775
- this._lineThickness,
776
- this._lineStrokeColors,
777
- this._lineStrokes,
778
- geometry._lineVerticesHighMerc,
779
- geometry._lineVerticesLowMerc
780
- );
781
-
782
- geometry._lineVerticesLength =
783
- this._lineVerticesHighMerc.length - geometry._lineVerticesHandlerIndex;
784
- geometry._lineOrdersLength =
785
- this._lineOrders.length - geometry._lineOrdersHandlerIndex;
786
- geometry._lineIndexesLength =
787
- this._lineIndexes.length - geometry._lineIndexesHandlerIndex;
788
- geometry._lineColorsLength =
789
- this._lineColors.length - geometry._lineColorsHandlerIndex;
790
- geometry._lineThicknessLength =
791
- this._lineThickness.length - geometry._lineThicknessHandlerIndex;
792
- } else if (geometry._type === GeometryType.MULTILINESTRING) {
793
- let coordinates = geometry._coordinates;
794
- let ci = [];
795
- for (let j = 0; j < coordinates.length; j++) {
796
- ci[j] = [];
797
- for (let k = 0; k < coordinates[j].length; k++) {
798
- ci[j][k] = [
799
- mercator.forward_lon(coordinates[j][k][0]),
800
- mercator.forward_lat(coordinates[j][k][1])
801
- ];
802
- }
803
- }
804
-
805
- // Creates polygon stroke data
806
- geometry._lineVerticesHandlerIndex = this._lineVerticesHighMerc.length;
807
- geometry._lineOrdersHandlerIndex = this._lineOrders.length;
808
- geometry._lineIndexesHandlerIndex = this._lineIndexes.length;
809
- geometry._lineColorsHandlerIndex = this._lineColors.length;
810
- geometry._lineThicknessHandlerIndex = this._lineThickness.length;
811
-
812
- GeometryHandler.appendLineData(
813
- ci,
814
- false,
815
- geometry._style.lineColor,
816
- pickingColor,
817
- geometry._style.lineWidth,
818
- geometry._style.strokeColor,
819
- geometry._style.strokeWidth,
820
- this._lineVerticesHighMerc,
821
- this._lineVerticesLowMerc,
822
- this._lineOrders,
823
- this._lineIndexes,
824
- this._lineColors,
825
- this._linePickingColors,
826
- this._lineThickness,
827
- this._lineStrokeColors,
828
- this._lineStrokes,
829
- geometry._lineVerticesHighMerc,
830
- geometry._lineVerticesLowMerc
831
- );
832
-
833
- geometry._lineVerticesLength =
834
- this._lineVerticesHighMerc.length - geometry._lineVerticesHandlerIndex;
835
- geometry._lineOrdersLength =
836
- this._lineOrders.length - geometry._lineOrdersHandlerIndex;
837
- geometry._lineIndexesLength =
838
- this._lineIndexes.length - geometry._lineIndexesHandlerIndex;
839
- geometry._lineColorsLength =
840
- this._lineColors.length - geometry._lineColorsHandlerIndex;
841
- geometry._lineThicknessLength =
842
- this._lineThickness.length - geometry._lineThicknessHandlerIndex;
843
- }
844
-
845
- // Refresh visibility
846
- this.setGeometryVisibility(geometry);
847
-
848
- !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
849
- this._updatedGeometry[geometry._id] = true;
850
- this.refresh();
851
- }
852
- }
853
-
854
- remove(geometry) {
855
- var index = geometry._handlerIndex;
856
- if (index !== -1) {
857
- this._geometries.splice(index, 1);
858
-
859
- // polygon
860
- // this._polyVerticesLonLat.splice(geometry._polyVerticesHandlerIndex, geometry._polyVerticesLength);
861
- this._polyVerticesHighMerc.splice(
862
- geometry._polyVerticesHandlerIndex,
863
- geometry._polyVerticesLength
864
- );
865
- this._polyVerticesLowMerc.splice(
866
- geometry._polyVerticesHandlerIndex,
867
- geometry._polyVerticesLength
868
- );
869
-
870
- this._polyColors.splice(
871
- geometry._polyVerticesHandlerIndex * 2,
872
- geometry._polyVerticesLength * 2
873
- );
874
- this._polyPickingColors.splice(
875
- geometry._polyVerticesHandlerIndex * 2,
876
- geometry._polyVerticesLength * 2
877
- );
878
- this._polyIndexes.splice(
879
- geometry._polyIndexesHandlerIndex,
880
- geometry._polyIndexesLength
881
- );
882
- var di = geometry._polyVerticesLength * 0.5;
883
- for (var i = geometry._polyIndexesHandlerIndex; i < this._polyIndexes.length; i++) {
884
- this._polyIndexes[i] -= di;
885
- }
886
-
887
- // line
888
- // this._lineVerticesLonLat.splice(geometry._lineVerticesHandlerIndex, geometry._lineVerticesLength);
889
- this._lineVerticesHighMerc.splice(
890
- geometry._lineVerticesHandlerIndex,
891
- geometry._lineVerticesLength
892
- );
893
- this._lineVerticesLowMerc.splice(
894
- geometry._lineVerticesHandlerIndex,
895
- geometry._lineVerticesLength
896
- );
897
- this._lineOrders.splice(geometry._lineOrdersHandlerIndex, geometry._lineOrdersLength);
898
- this._lineColors.splice(geometry._lineColorsHandlerIndex, geometry._lineColorsLength);
899
- this._linePickingColors.splice(
900
- geometry._lineColorsHandlerIndex,
901
- geometry._lineColorsLength
902
- );
903
- this._lineStrokeColors.splice(
904
- geometry._lineColorsHandlerIndex,
905
- geometry._lineColorsLength
906
- );
907
- this._lineThickness.splice(
908
- geometry._lineThicknessHandlerIndex,
909
- geometry._lineThicknessLength
910
- );
911
- this._lineStrokes.splice(
912
- geometry._lineThicknessHandlerIndex,
913
- geometry._lineThicknessLength
914
- );
915
- this._lineIndexes.splice(
916
- geometry._lineIndexesHandlerIndex,
917
- geometry._lineIndexesLength
918
- );
919
- di = geometry._lineVerticesLength * 0.5;
920
- for (let i = geometry._lineIndexesHandlerIndex; i < this._lineIndexes.length; i++) {
921
- this._lineIndexes[i] -= di;
922
- }
923
-
924
- // reindex
925
- var g = this._geometries;
926
- for (let i = index; i < g.length; i++) {
927
- var gi = g[i];
928
- gi._handlerIndex = i;
929
- gi._polyVerticesHandlerIndex -= geometry._polyVerticesLength;
930
- gi._polyIndexesHandlerIndex -= geometry._polyIndexesLength;
931
-
932
- gi._lineVerticesHandlerIndex -= geometry._lineVerticesLength;
933
- gi._lineOrdersHandlerIndex -= geometry._lineOrdersLength;
934
- gi._lineColorsHandlerIndex -= geometry._lineColorsLength;
935
- gi._lineThicknessHandlerIndex -= geometry._lineThicknessLength;
936
- gi._lineIndexesHandlerIndex -= geometry._lineIndexesLength;
937
- }
938
-
939
- geometry._pickingReady = false;
940
-
941
- geometry._handler = null;
942
- geometry._handlerIndex = -1;
943
-
944
- geometry._polyVerticesHighMerc = [];
945
- geometry._polyVerticesLowMerc = [];
946
- geometry._polyVerticesLength = -1;
947
- geometry._polyIndexesLength = -1;
948
- geometry._polyVerticesHandlerIndex = -1;
949
- geometry._polyIndexesHandlerIndex = -1;
950
-
951
- geometry._lineVerticesHighMerc = [];
952
- geometry._lineVerticesLowMerc = [];
953
- geometry._lineVerticesLength = -1;
954
- geometry._lineOrdersLength = -1;
955
- geometry._lineIndexesLength = -1;
956
- geometry._lineColorsLength = -1;
957
- geometry._lineThicknessLength = -1;
958
- geometry._lineVerticesHandlerIndex = -1;
959
- geometry._lineOrdersHandlerIndex = -1;
960
- geometry._lineIndexesHandlerIndex = -1;
961
- geometry._lineThicknessHandlerIndex = -1;
962
- geometry._lineColorsHandlerIndex = -1;
963
-
964
- !this._removeGeometryExtents[geometry._id] &&
965
- this._removeGeometryExtentArr.push(geometry.getExtent());
966
- this._removeGeometryExtents[geometry._id] = true;
967
-
968
- this.refresh();
969
- }
970
- }
971
-
972
- _refreshRecursevely(geometry, treeNode) {
973
- if (treeNode.ready) {
974
- var lid = this._layer._id;
975
- for (var i = 0; i < treeNode.nodes.length; i++) {
976
- var ni = treeNode.nodes[i];
977
- if (geometry._extent.overlaps(ni.segment.getExtentLonLat())) {
978
- this._refreshRecursevely(geometry, ni);
979
- var m = ni.segment.materials[lid];
980
- if (m && m.isReady) {
981
- if (m.segment.node.getState() !== quadTree.RENDERING) {
982
- m.layer.clearMaterial(m);
983
- } else {
984
- m.pickingReady = m.pickingReady && geometry._pickingReady;
985
- m.isReady = false;
986
- m._updateTexture = m.texture;
987
- m._updatePickingMask = m.pickingMask;
988
- }
989
- geometry._pickingReady = true;
990
- }
991
- }
992
- }
993
- }
994
- }
995
-
996
- _refreshRecursevelyExt(extent, treeNode) {
997
- if (treeNode.ready) {
998
- var lid = this._layer._id;
999
- for (var i = 0; i < treeNode.nodes.length; i++) {
1000
- var ni = treeNode.nodes[i];
1001
- if (extent.overlaps(ni.segment.getExtentLonLat())) {
1002
- this._refreshRecursevelyExt(extent, ni);
1003
- var m = ni.segment.materials[lid];
1004
- if (m && m.isReady) {
1005
- m.layer.clearMaterial(m);
1006
- // m.pickingReady = false;
1007
- // m.isReady = false;
1008
- // m._updateTexture = m.texture;
1009
- // m._updatePickingMask = m.pickingMask;
1010
- }
1011
- }
1012
- }
1013
- }
1014
- }
1015
-
1016
- _refreshPlanetNode(treeNode) {
1017
- var i = 0;
1018
-
1019
- var e = this._removeGeometryExtentArr;
1020
- for (i = 0; i < e.length; i++) {
1021
- this._refreshRecursevelyExt(e[i], treeNode);
1022
- }
1023
-
1024
- var g = this._updatedGeometryArr;
1025
- for (i = 0; i < g.length; i++) {
1026
- this._refreshRecursevely(g[i], treeNode);
1027
- }
1028
- }
1029
-
1030
- _updatePlanet() {
1031
- var p = this._layer._planet;
1032
- if (p) {
1033
- this._refreshPlanetNode(p._quadTree);
1034
- this._refreshPlanetNode(p._quadTreeNorth);
1035
- this._refreshPlanetNode(p._quadTreeSouth);
1036
- }
1037
- this._updatedGeometryArr.length = 0;
1038
- this._updatedGeometryArr = [];
1039
- this._updatedGeometry = {};
1040
-
1041
- this._removeGeometryExtentArr.length = 0;
1042
- this._removeGeometryExtentArr = [];
1043
- this._removeGeometryExtents = {};
1044
- }
1045
-
1046
- refresh() {
1047
- var i = this._changedBuffers.length;
1048
- while (i--) {
1049
- this._changedBuffers[i] = true;
1050
- }
1051
- }
1052
-
1053
- update() {
1054
- if (this._handler) {
1055
- var needUpdate = false;
1056
- var i = this._changedBuffers.length;
1057
- while (i--) {
1058
- if (this._changedBuffers[i]) {
1059
- needUpdate = true;
1060
- this._buffersUpdateCallbacks[i].call(this);
1061
- this._changedBuffers[i] = false;
1062
- }
1063
- }
1064
- needUpdate && this._updatePlanet();
1065
- }
1066
- }
1067
-
1068
- setGeometryVisibility(geometry) {
1069
- var v = geometry._visibility ? 1.0 : 0.0;
1070
-
1071
- var a = this._polyVerticesHighMerc,
1072
- b = this._polyVerticesLowMerc;
1073
-
1074
- var l = geometry._polyVerticesLength;
1075
- var ind = geometry._polyVerticesHandlerIndex;
1076
- for (var i = 0; i < l; i++) {
1077
- a[ind + i] = geometry._polyVerticesHighMerc[i] * v;
1078
- b[ind + i] = geometry._polyVerticesLowMerc[i] * v;
1079
- }
1080
-
1081
- a = this._lineVerticesHighMerc;
1082
- b = this._lineVerticesLowMerc;
1083
- l = geometry._lineVerticesLength;
1084
- ind = geometry._lineVerticesHandlerIndex;
1085
- for (i = 0; i < l; i++) {
1086
- a[ind + i] = geometry._lineVerticesHighMerc[i] * v;
1087
- b[ind + i] = geometry._lineVerticesLowMerc[i] * v;
1088
- }
1089
-
1090
- this._changedBuffers[POLYVERTICES_BUFFER] = true;
1091
- this._changedBuffers[LINEVERTICES_BUFFER] = true;
1092
-
1093
- !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
1094
- this._updatedGeometry[geometry._id] = true;
1095
- }
1096
-
1097
- setPolyColorArr(geometry, color) {
1098
- var index = geometry._polyVerticesHandlerIndex * 2, // ... / 2 * 4
1099
- size = index + geometry._polyVerticesLength * 2; // ... / 2 * 4
1100
- var a = this._polyColors;
1101
- for (var i = index; i < size; i += 4) {
1102
- a[i] = color.x;
1103
- a[i + 1] = color.y;
1104
- a[i + 2] = color.z;
1105
- a[i + 3] = color.w;
1106
- }
1107
- this._changedBuffers[POLYCOLORS_BUFFER] = true;
1108
- !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
1109
- this._updatedGeometry[geometry._id] = true;
1110
- }
1111
-
1112
- setLineStrokeColorArr(geometry, color) {
1113
- var index = geometry._lineColorsHandlerIndex,
1114
- size = index + geometry._lineColorsLength;
1115
- var a = this._lineStrokeColors;
1116
- for (var i = index; i < size; i += 4) {
1117
- a[i] = color.x;
1118
- a[i + 1] = color.y;
1119
- a[i + 2] = color.z;
1120
- a[i + 3] = color.w;
1121
- }
1122
- this._changedBuffers[LINESTROKECOLORS_BUFFER] = true;
1123
- !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
1124
- this._updatedGeometry[geometry._id] = true;
1125
- }
1126
-
1127
- setLineColorArr(geometry, color) {
1128
- var index = geometry._lineColorsHandlerIndex,
1129
- size = index + geometry._lineColorsLength;
1130
- var a = this._lineColors;
1131
- for (var i = index; i < size; i += 4) {
1132
- a[i] = color.x;
1133
- a[i + 1] = color.y;
1134
- a[i + 2] = color.z;
1135
- a[i + 3] = color.w;
1136
- }
1137
- this._changedBuffers[LINECOLORS_BUFFER] = true;
1138
- !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
1139
- this._updatedGeometry[geometry._id] = true;
1140
- }
1141
-
1142
- setLineStrokeArr(geometry, width) {
1143
- var index = geometry._lineStrokesHandlerIndex,
1144
- size = index + geometry._lineStrokesLength;
1145
- var a = this._lineStrokes;
1146
- for (var i = index; i < size; i++) {
1147
- a[i] = width;
1148
- }
1149
- this._changedBuffers[LINESTROKES_BUFFER] = true;
1150
- !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
1151
- this._updatedGeometry[geometry._id] = true;
1152
- }
1153
-
1154
- setLineThicknessArr(geometry, width) {
1155
- var index = geometry._lineThicknessHandlerIndex,
1156
- size = index + geometry._lineThicknessLength;
1157
- var a = this._lineThickness;
1158
- for (var i = index; i < size; i++) {
1159
- a[i] = width;
1160
- }
1161
- this._changedBuffers[LINETHICKNESS_BUFFER] = true;
1162
- !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
1163
- this._updatedGeometry[geometry._id] = true;
1164
- }
1165
-
1166
- bringToFront(geometry) {
1167
- var polyIndexes = this._polyIndexes.splice(
1168
- geometry._polyIndexesHandlerIndex,
1169
- geometry._polyIndexesLength
1170
- );
1171
- var lineIndexes = this._lineIndexes.splice(
1172
- geometry._lineIndexesHandlerIndex,
1173
- geometry._lineIndexesLength
1174
- );
1175
-
1176
- this._geometries.splice(geometry._handlerIndex, 1);
1177
-
1178
- var g = this._geometries;
1179
- for (var i = geometry._handlerIndex; i < g.length; i++) {
1180
- var gi = g[i];
1181
- gi._handlerIndex = i;
1182
- gi._polyIndexesHandlerIndex -= geometry._polyIndexesLength;
1183
- gi._lineIndexesHandlerIndex -= geometry._lineIndexesLength;
1184
- }
1185
-
1186
- geometry._polyIndexesHandlerIndex = this._polyIndexes.length;
1187
- geometry._lineIndexesHandlerIndex = this._lineIndexes.length;
1188
-
1189
- geometry._handlerIndex = this._geometries.length;
1190
- this._geometries.push(geometry);
1191
-
1192
- this._polyIndexes.push.apply(this._polyIndexes, polyIndexes);
1193
- this._lineIndexes.push.apply(this._lineIndexes, lineIndexes);
1194
-
1195
- this._changedBuffers[POLYINDEXES_BUFFER] = true;
1196
- this._changedBuffers[LINEINDEXES_BUFFER] = true;
1197
-
1198
- !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
1199
- this._updatedGeometry[geometry._id] = true;
1200
- }
1201
-
1202
- createPolyVerticesBuffer() {
1203
- var h = this._handler;
1204
- h.gl.deleteBuffer(this._polyVerticesHighBufferMerc);
1205
- this._polyVerticesHighBufferMerc = h.createArrayBuffer(
1206
- new Float32Array(this._polyVerticesHighMerc),
1207
- 2,
1208
- this._polyVerticesHighMerc.length / 2
1209
- );
1210
-
1211
- h.gl.deleteBuffer(this._polyVerticesLowBufferMerc);
1212
- this._polyVerticesLowBufferMerc = h.createArrayBuffer(
1213
- new Float32Array(this._polyVerticesLowMerc),
1214
- 2,
1215
- this._polyVerticesLowMerc.length / 2
1216
- );
1217
- }
1218
-
1219
- createPolyIndexesBuffer() {
1220
- var h = this._handler;
1221
- h.gl.deleteBuffer(this._polyIndexesBuffer);
1222
- this._polyIndexesBuffer = h.createElementArrayBuffer(
1223
- new Uint32Array(this._polyIndexes),
1224
- 1,
1225
- this._polyIndexes.length
1226
- );
1227
- }
1228
-
1229
- createPolyColorsBuffer() {
1230
- var h = this._handler;
1231
- h.gl.deleteBuffer(this._polyColorsBuffer);
1232
- this._polyColorsBuffer = h.createArrayBuffer(
1233
- new Float32Array(this._polyColors),
1234
- 4,
1235
- this._polyColors.length / 4
1236
- );
1237
- }
1238
-
1239
- createPolyPickingColorsBuffer() {
1240
- var h = this._handler;
1241
- h.gl.deleteBuffer(this._polyPickingColorsBuffer);
1242
- this._polyPickingColorsBuffer = h.createArrayBuffer(
1243
- new Float32Array(this._polyPickingColors),
1244
- 4,
1245
- this._polyPickingColors.length / 4
1246
- );
1247
- }
1248
-
1249
- createLineVerticesBuffer() {
1250
- var h = this._handler;
1251
- h.gl.deleteBuffer(this._lineVerticesHighBufferMerc);
1252
- this._lineVerticesHighBufferMerc = h.createArrayBuffer(
1253
- new Float32Array(this._lineVerticesHighMerc),
1254
- 2,
1255
- this._lineVerticesHighMerc.length / 2
1256
- );
1257
-
1258
- h.gl.deleteBuffer(this._lineVerticesLowBufferMerc);
1259
- this._lineVerticesLowBufferMerc = h.createArrayBuffer(
1260
- new Float32Array(this._lineVerticesLowMerc),
1261
- 2,
1262
- this._lineVerticesLowMerc.length / 2
1263
- );
1264
- }
1265
-
1266
- createLineIndexesBuffer() {
1267
- var h = this._handler;
1268
- h.gl.deleteBuffer(this._lineIndexesBuffer);
1269
- this._lineIndexesBuffer = h.createElementArrayBuffer(
1270
- new Uint32Array(this._lineIndexes),
1271
- 1,
1272
- this._lineIndexes.length
1273
- );
1274
- }
1275
-
1276
- createLineOrdersBuffer() {
1277
- var h = this._handler;
1278
- h.gl.deleteBuffer(this._lineOrdersBuffer);
1279
- this._lineOrdersBuffer = h.createArrayBuffer(
1280
- new Float32Array(this._lineOrders),
1281
- 1,
1282
- this._lineOrders.length / 2
1283
- );
1284
- }
1285
-
1286
- createLineColorsBuffer() {
1287
- var h = this._handler;
1288
- h.gl.deleteBuffer(this._lineColorsBuffer);
1289
- this._lineColorsBuffer = h.createArrayBuffer(
1290
- new Float32Array(this._lineColors),
1291
- 4,
1292
- this._lineColors.length / 4
1293
- );
1294
- }
1295
-
1296
- createLinePickingColorsBuffer() {
1297
- var h = this._handler;
1298
- h.gl.deleteBuffer(this._linePickingColorsBuffer);
1299
- this._linePickingColorsBuffer = h.createArrayBuffer(
1300
- new Float32Array(this._linePickingColors),
1301
- 4,
1302
- this._linePickingColors.length / 4
1303
- );
1304
- }
1305
-
1306
- createLineThicknessBuffer() {
1307
- var h = this._handler;
1308
- h.gl.deleteBuffer(this._lineThicknessBuffer);
1309
- this._lineThicknessBuffer = h.createArrayBuffer(
1310
- new Float32Array(this._lineThickness),
1311
- 1,
1312
- this._lineThickness.length
1313
- );
1314
- }
1315
-
1316
- createLineStrokesBuffer() {
1317
- var h = this._handler;
1318
- h.gl.deleteBuffer(this._lineStrokesBuffer);
1319
- this._lineStrokesBuffer = h.createArrayBuffer(
1320
- new Float32Array(this._lineStrokes),
1321
- 1,
1322
- this._lineStrokes.length
1323
- );
1324
- }
1325
-
1326
- createLineStrokeColorsBuffer() {
1327
- var h = this._handler;
1328
- h.gl.deleteBuffer(this._lineStrokeColorsBuffer);
1329
- this._lineStrokeColorsBuffer = h.createArrayBuffer(
1330
- new Float32Array(this._lineStrokeColors),
1331
- 4,
1332
- this._lineStrokeColors.length / 4
1333
- );
1334
- }
1335
- }
1336
-
1337
- export { GeometryHandler };
1
+ /**
2
+ * @module og/entity/GeometryHandler
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import * as mercator from "../mercator.js";
8
+ import * as quadTree from "../quadTree/quadTree.js";
9
+ import { earcut, flatten } from "../utils/earcut.js";
10
+ import { GeometryType } from "./Geometry.js";
11
+ import { Vec2 } from "../math/Vec2.js";
12
+ import { doubleToTwoFloatsV2 } from "../math/coder.js";
13
+
14
+ const POLYVERTICES_BUFFER = 0;
15
+ const POLYINDEXES_BUFFER = 1;
16
+ const POLYCOLORS_BUFFER = 2;
17
+ const LINEVERTICES_BUFFER = 3;
18
+ const LINEINDEXES_BUFFER = 4;
19
+ const LINEORDERS_BUFFER = 5;
20
+ const LINECOLORS_BUFFER = 6;
21
+ const LINETHICKNESS_BUFFER = 7;
22
+ const LINESTROKES_BUFFER = 8;
23
+ const LINESTROKECOLORS_BUFFER = 9;
24
+ const POLYPICKINGCOLORS_BUFFER = 10;
25
+ const LINEPICKINGCOLORS_BUFFER = 11;
26
+
27
+ function doubleToTwoFloats(v, high, low) {
28
+ let x = v[0],
29
+ y = v[1];
30
+
31
+ if (x >= 0.0) {
32
+ let doubleHigh = Math.floor(x / 65536.0) * 65536.0;
33
+ high.x = Math.fround(doubleHigh);
34
+ low.x = Math.fround(x - doubleHigh);
35
+ } else {
36
+ let doubleHigh = Math.floor(-x / 65536.0) * 65536.0;
37
+ high.x = Math.fround(-doubleHigh);
38
+ low.x = Math.fround(x + doubleHigh);
39
+ }
40
+
41
+ if (y >= 0.0) {
42
+ let doubleHigh = Math.floor(y / 65536.0) * 65536.0;
43
+ high.y = Math.fround(doubleHigh);
44
+ low.y = Math.fround(y - doubleHigh);
45
+ } else {
46
+ let doubleHigh = Math.floor(-y / 65536.0) * 65536.0;
47
+ high.y = Math.fround(-doubleHigh);
48
+ low.y = Math.fround(y + doubleHigh);
49
+ }
50
+ }
51
+
52
+ let tempHigh = new Vec2(),
53
+ tempLow = new Vec2(),
54
+ tempHighLow = new Vec2();
55
+
56
+ class GeometryHandler {
57
+ constructor(layer) {
58
+ this.__staticId = GeometryHandler._staticCounter++;
59
+
60
+ this._layer = layer;
61
+
62
+ this._handler = null;
63
+
64
+ this._geometries = [];
65
+
66
+ this._updatedGeometryArr = [];
67
+ this._updatedGeometry = {};
68
+
69
+ this._removeGeometryExtentArr = [];
70
+ this._removeGeometryExtents = {};
71
+
72
+ // Polygon arrays
73
+ this._polyVerticesHighMerc = [];
74
+ this._polyVerticesLowMerc = [];
75
+ this._polyColors = [];
76
+ this._polyPickingColors = [];
77
+ this._polyIndexes = [];
78
+
79
+ // Line arrays
80
+ this._lineVerticesHighMerc = [];
81
+ this._lineVerticesLowMerc = [];
82
+ this._lineOrders = [];
83
+ this._lineIndexes = [];
84
+ this._lineColors = [];
85
+ this._linePickingColors = [];
86
+ this._lineThickness = [];
87
+ this._lineStrokes = [];
88
+ this._lineStrokeColors = [];
89
+
90
+ // Buffers
91
+ this._polyVerticesHighBufferMerc = null;
92
+ this._polyVerticesLowBufferMerc = null;
93
+ this._polyColorsBuffer = null;
94
+ this._polyPickingColorsBuffer = null;
95
+ this._polyIndexesBuffer = null;
96
+
97
+ this._lineVerticesHighBufferMerc = null;
98
+ this._lineVerticesLowBufferMerc = null;
99
+ this._lineColorsBuffer = null;
100
+ this._linePickingColorsBuffer = null;
101
+ this._lineThicknessBuffer = null;
102
+ this._lineStrokesBuffer = null;
103
+ this._lineStrokeColorsBuffer = null;
104
+ this._lineOrdersBuffer = null;
105
+ this._lineIndexesBuffer = null;
106
+
107
+ this._buffersUpdateCallbacks = [];
108
+ this._buffersUpdateCallbacks[POLYVERTICES_BUFFER] = this.createPolyVerticesBuffer;
109
+ this._buffersUpdateCallbacks[POLYINDEXES_BUFFER] = this.createPolyIndexesBuffer;
110
+ this._buffersUpdateCallbacks[POLYCOLORS_BUFFER] = this.createPolyColorsBuffer;
111
+ this._buffersUpdateCallbacks[LINEVERTICES_BUFFER] = this.createLineVerticesBuffer;
112
+ this._buffersUpdateCallbacks[LINEINDEXES_BUFFER] = this.createLineIndexesBuffer;
113
+ this._buffersUpdateCallbacks[LINEORDERS_BUFFER] = this.createLineOrdersBuffer;
114
+ this._buffersUpdateCallbacks[LINECOLORS_BUFFER] = this.createLineColorsBuffer;
115
+ this._buffersUpdateCallbacks[LINETHICKNESS_BUFFER] = this.createLineThicknessBuffer;
116
+ this._buffersUpdateCallbacks[LINESTROKES_BUFFER] = this.createLineStrokesBuffer;
117
+ this._buffersUpdateCallbacks[LINESTROKECOLORS_BUFFER] = this.createLineStrokeColorsBuffer;
118
+ this._buffersUpdateCallbacks[POLYPICKINGCOLORS_BUFFER] = this.createPolyPickingColorsBuffer;
119
+ this._buffersUpdateCallbacks[LINEPICKINGCOLORS_BUFFER] = this.createLinePickingColorsBuffer;
120
+
121
+ this._changedBuffers = new Array(this._buffersUpdateCallbacks.length);
122
+ }
123
+
124
+ static get _staticCounter() {
125
+ if (!this._counter && this._counter !== 0) {
126
+ this._counter = 0;
127
+ }
128
+ return this._counter;
129
+ }
130
+
131
+ static set _staticCounter(n) {
132
+ this._counter = n;
133
+ }
134
+
135
+ static appendLineData(
136
+ pathArr,
137
+ isClosed,
138
+ color,
139
+ pickingColor,
140
+ thickness,
141
+ strokeColor,
142
+ strokeSize,
143
+ outVerticesHigh,
144
+ outVerticesLow,
145
+ outOrders,
146
+ outIndexes,
147
+ outColors,
148
+ outPickingColors,
149
+ outThickness,
150
+ outStrokeColors,
151
+ outStrokes,
152
+ outVerticesHigh2,
153
+ outVerticesLow2
154
+ ) {
155
+ var index = 0;
156
+
157
+ if (outIndexes.length > 0) {
158
+ index = outIndexes[outIndexes.length - 5] + 9;
159
+ outIndexes.push(index, index);
160
+ } else {
161
+ outIndexes.push(0, 0);
162
+ }
163
+
164
+ var t = thickness,
165
+ c = [color.x, color.y, color.z, color.w],
166
+ s = strokeSize,
167
+ sc = [strokeColor.x, strokeColor.y, strokeColor.z, strokeColor.w],
168
+ p = [pickingColor.x, pickingColor.y, pickingColor.z, 1.0];
169
+
170
+ for (var j = 0; j < pathArr.length; j++) {
171
+ var path = pathArr[j];
172
+
173
+ if (path.length === 0) {
174
+ continue;
175
+ }
176
+
177
+ var startIndex = index;
178
+ var last;
179
+ if (isClosed) {
180
+ last = path[path.length - 1];
181
+ } else {
182
+ let p0 = path[0],
183
+ p1 = path[1];
184
+
185
+ if (!p1) {
186
+ p1 = p0;
187
+ }
188
+
189
+ last = [p0[0] + p0[0] - p1[0], p0[1] + p0[1] - p1[1]];
190
+ }
191
+
192
+ doubleToTwoFloats(last, tempHigh, tempLow);
193
+
194
+ outVerticesHigh.push(
195
+ tempHigh.x,
196
+ tempHigh.y,
197
+ tempHigh.x,
198
+ tempHigh.y,
199
+ tempHigh.x,
200
+ tempHigh.y,
201
+ tempHigh.x,
202
+ tempHigh.y
203
+ );
204
+ outVerticesLow.push(
205
+ tempLow.x,
206
+ tempLow.y,
207
+ tempLow.x,
208
+ tempLow.y,
209
+ tempLow.x,
210
+ tempLow.y,
211
+ tempLow.x,
212
+ tempLow.y
213
+ );
214
+
215
+ outVerticesHigh2.push(
216
+ tempHigh.x,
217
+ tempHigh.y,
218
+ tempHigh.x,
219
+ tempHigh.y,
220
+ tempHigh.x,
221
+ tempHigh.y,
222
+ tempHigh.x,
223
+ tempHigh.y
224
+ );
225
+ outVerticesLow2.push(
226
+ tempLow.x,
227
+ tempLow.y,
228
+ tempLow.x,
229
+ tempLow.y,
230
+ tempLow.x,
231
+ tempLow.y,
232
+ tempLow.x,
233
+ tempLow.y
234
+ );
235
+
236
+ outOrders.push(1, -1, 2, -2);
237
+
238
+ outThickness.push(t, t, t, t);
239
+ outStrokes.push(s, s, s, s);
240
+ outColors.push(
241
+ c[0],
242
+ c[1],
243
+ c[2],
244
+ c[3],
245
+ c[0],
246
+ c[1],
247
+ c[2],
248
+ c[3],
249
+ c[0],
250
+ c[1],
251
+ c[2],
252
+ c[3],
253
+ c[0],
254
+ c[1],
255
+ c[2],
256
+ c[3]
257
+ );
258
+ outStrokeColors.push(
259
+ sc[0],
260
+ sc[1],
261
+ sc[2],
262
+ sc[3],
263
+ sc[0],
264
+ sc[1],
265
+ sc[2],
266
+ sc[3],
267
+ sc[0],
268
+ sc[1],
269
+ sc[2],
270
+ sc[3],
271
+ sc[0],
272
+ sc[1],
273
+ sc[2],
274
+ sc[3]
275
+ );
276
+ outPickingColors.push(
277
+ p[0],
278
+ p[1],
279
+ p[2],
280
+ p[3],
281
+ p[0],
282
+ p[1],
283
+ p[2],
284
+ p[3],
285
+ p[0],
286
+ p[1],
287
+ p[2],
288
+ p[3],
289
+ p[0],
290
+ p[1],
291
+ p[2],
292
+ p[3]
293
+ );
294
+
295
+ for (var i = 0; i < path.length; i++) {
296
+ var cur = path[i];
297
+
298
+ doubleToTwoFloats(cur, tempHigh, tempLow);
299
+
300
+ outVerticesHigh.push(
301
+ tempHigh.x,
302
+ tempHigh.y,
303
+ tempHigh.x,
304
+ tempHigh.y,
305
+ tempHigh.x,
306
+ tempHigh.y,
307
+ tempHigh.x,
308
+ tempHigh.y
309
+ );
310
+ outVerticesLow.push(
311
+ tempLow.x,
312
+ tempLow.y,
313
+ tempLow.x,
314
+ tempLow.y,
315
+ tempLow.x,
316
+ tempLow.y,
317
+ tempLow.x,
318
+ tempLow.y
319
+ );
320
+
321
+ outVerticesHigh2.push(
322
+ tempHigh.x,
323
+ tempHigh.y,
324
+ tempHigh.x,
325
+ tempHigh.y,
326
+ tempHigh.x,
327
+ tempHigh.y,
328
+ tempHigh.x,
329
+ tempHigh.y
330
+ );
331
+ outVerticesLow2.push(
332
+ tempLow.x,
333
+ tempLow.y,
334
+ tempLow.x,
335
+ tempLow.y,
336
+ tempLow.x,
337
+ tempLow.y,
338
+ tempLow.x,
339
+ tempLow.y
340
+ );
341
+
342
+ outOrders.push(1, -1, 2, -2);
343
+ outThickness.push(t, t, t, t);
344
+ outStrokes.push(s, s, s, s);
345
+ outColors.push(
346
+ c[0],
347
+ c[1],
348
+ c[2],
349
+ c[3],
350
+ c[0],
351
+ c[1],
352
+ c[2],
353
+ c[3],
354
+ c[0],
355
+ c[1],
356
+ c[2],
357
+ c[3],
358
+ c[0],
359
+ c[1],
360
+ c[2],
361
+ c[3]
362
+ );
363
+ outStrokeColors.push(
364
+ sc[0],
365
+ sc[1],
366
+ sc[2],
367
+ sc[3],
368
+ sc[0],
369
+ sc[1],
370
+ sc[2],
371
+ sc[3],
372
+ sc[0],
373
+ sc[1],
374
+ sc[2],
375
+ sc[3],
376
+ sc[0],
377
+ sc[1],
378
+ sc[2],
379
+ sc[3]
380
+ );
381
+ outPickingColors.push(
382
+ p[0],
383
+ p[1],
384
+ p[2],
385
+ p[3],
386
+ p[0],
387
+ p[1],
388
+ p[2],
389
+ p[3],
390
+ p[0],
391
+ p[1],
392
+ p[2],
393
+ p[3],
394
+ p[0],
395
+ p[1],
396
+ p[2],
397
+ p[3]
398
+ );
399
+ outIndexes.push(index++, index++, index++, index++);
400
+ }
401
+
402
+ var first;
403
+ if (isClosed) {
404
+ first = path[0];
405
+ outIndexes.push(startIndex, startIndex + 1, startIndex + 1, startIndex + 1);
406
+ } else {
407
+ let p0 = path[path.length - 1],
408
+ p1 = path[path.length - 2];
409
+
410
+ if (!p1) {
411
+ p1 = p0;
412
+ }
413
+
414
+ first = [p0[0] + p0[0] - p1[0], p0[1] + p0[1] - p1[1]];
415
+ outIndexes.push(index - 1, index - 1, index - 1, index - 1);
416
+ }
417
+
418
+ doubleToTwoFloats(first, tempHigh, tempLow);
419
+
420
+ outVerticesHigh.push(
421
+ tempHigh.x,
422
+ tempHigh.y,
423
+ tempHigh.x,
424
+ tempHigh.y,
425
+ tempHigh.x,
426
+ tempHigh.y,
427
+ tempHigh.x,
428
+ tempHigh.y
429
+ );
430
+ outVerticesLow.push(
431
+ tempLow.x,
432
+ tempLow.y,
433
+ tempLow.x,
434
+ tempLow.y,
435
+ tempLow.x,
436
+ tempLow.y,
437
+ tempLow.x,
438
+ tempLow.y
439
+ );
440
+
441
+ outVerticesHigh2.push(
442
+ tempHigh.x,
443
+ tempHigh.y,
444
+ tempHigh.x,
445
+ tempHigh.y,
446
+ tempHigh.x,
447
+ tempHigh.y,
448
+ tempHigh.x,
449
+ tempHigh.y
450
+ );
451
+ outVerticesLow2.push(
452
+ tempLow.x,
453
+ tempLow.y,
454
+ tempLow.x,
455
+ tempLow.y,
456
+ tempLow.x,
457
+ tempLow.y,
458
+ tempLow.x,
459
+ tempLow.y
460
+ );
461
+
462
+ outOrders.push(1, -1, 2, -2);
463
+ outThickness.push(t, t, t, t);
464
+ outStrokes.push(s, s, s, s);
465
+ outColors.push(
466
+ c[0],
467
+ c[1],
468
+ c[2],
469
+ c[3],
470
+ c[0],
471
+ c[1],
472
+ c[2],
473
+ c[3],
474
+ c[0],
475
+ c[1],
476
+ c[2],
477
+ c[3],
478
+ c[0],
479
+ c[1],
480
+ c[2],
481
+ c[3]
482
+ );
483
+ outStrokeColors.push(
484
+ sc[0],
485
+ sc[1],
486
+ sc[2],
487
+ sc[3],
488
+ sc[0],
489
+ sc[1],
490
+ sc[2],
491
+ sc[3],
492
+ sc[0],
493
+ sc[1],
494
+ sc[2],
495
+ sc[3],
496
+ sc[0],
497
+ sc[1],
498
+ sc[2],
499
+ sc[3]
500
+ );
501
+ outPickingColors.push(
502
+ p[0],
503
+ p[1],
504
+ p[2],
505
+ p[3],
506
+ p[0],
507
+ p[1],
508
+ p[2],
509
+ p[3],
510
+ p[0],
511
+ p[1],
512
+ p[2],
513
+ p[3],
514
+ p[0],
515
+ p[1],
516
+ p[2],
517
+ p[3]
518
+ );
519
+
520
+ if (j < pathArr.length - 1) {
521
+ index += 8;
522
+ outIndexes.push(index, index);
523
+ }
524
+ }
525
+ }
526
+
527
+ assignHandler(handler) {
528
+ this._handler = handler;
529
+ this.refresh();
530
+ }
531
+
532
+ /**
533
+ * @public
534
+ * @param {Geometry} geometry - Geometry object.
535
+ */
536
+ add(geometry) {
537
+ //
538
+ // Triangulates polygon and sets geometry data.
539
+ if (geometry._handlerIndex === -1) {
540
+ geometry._handler = this;
541
+ geometry._handlerIndex = this._geometries.length;
542
+
543
+ this._geometries.push(geometry);
544
+
545
+ let pickingColor = geometry._entity._pickingColor.scaleTo(1 / 255);
546
+
547
+ geometry._polyVerticesHighMerc = [];
548
+ geometry._polyVerticesLowMerc = [];
549
+ geometry._lineVerticesHighMerc = [];
550
+ geometry._lineVerticesLowMerc = [];
551
+
552
+ if (geometry._coordinates[0].length) {
553
+ if (geometry._type === GeometryType.POLYGON) {
554
+ let coordinates = geometry._coordinates;
555
+ let ci = [];
556
+ for (let j = 0; j < coordinates.length; j++) {
557
+ ci[j] = [];
558
+ for (var k = 0; k < coordinates[j].length; k++) {
559
+ ci[j][k] = [
560
+ mercator.forward_lon(coordinates[j][k][0]),
561
+ mercator.forward_lat(coordinates[j][k][1])
562
+ ];
563
+ }
564
+ }
565
+
566
+ let data = flatten(ci);
567
+ let indexes = earcut(data.vertices, data.holes, 2);
568
+
569
+ geometry._polyVerticesHandlerIndex = this._polyVerticesHighMerc.length;
570
+ geometry._polyIndexesHandlerIndex = this._polyIndexes.length;
571
+
572
+ for (let i = 0; i < indexes.length; i++) {
573
+ this._polyIndexes.push(indexes[i] + geometry._polyVerticesHandlerIndex * 0.5);
574
+ }
575
+
576
+ var color = geometry._style.fillColor;
577
+
578
+ let verticesHigh = [],
579
+ verticesLow = [];
580
+
581
+ for (let i = 0; i < data.vertices.length * 0.5; i++) {
582
+ this._polyColors.push(color.x, color.y, color.z, color.w);
583
+ this._polyPickingColors.push(
584
+ pickingColor.x,
585
+ pickingColor.y,
586
+ pickingColor.z,
587
+ 1.0
588
+ );
589
+ }
590
+
591
+ for (let i = 0; i < data.vertices.length; i++) {
592
+ doubleToTwoFloatsV2(data.vertices[i], tempHighLow);
593
+ verticesHigh[i] = tempHighLow.x;
594
+ verticesLow[i] = tempHighLow.y;
595
+ }
596
+
597
+ geometry._polyVerticesHighMerc = verticesHigh;
598
+ geometry._polyVerticesLowMerc = verticesLow;
599
+
600
+ this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc, verticesHigh);
601
+ this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc, verticesLow);
602
+
603
+ geometry._polyVerticesLength = data.vertices.length;
604
+ geometry._polyIndexesLength = indexes.length;
605
+
606
+ // Creates polygon stroke data
607
+ geometry._lineVerticesHandlerIndex = this._lineVerticesHighMerc.length;
608
+ geometry._lineOrdersHandlerIndex = this._lineOrders.length;
609
+ geometry._lineIndexesHandlerIndex = this._lineIndexes.length;
610
+ geometry._lineColorsHandlerIndex = this._lineColors.length;
611
+ geometry._lineThicknessHandlerIndex = this._lineThickness.length;
612
+
613
+ GeometryHandler.appendLineData(
614
+ ci,
615
+ true,
616
+ geometry._style.lineColor,
617
+ pickingColor,
618
+ geometry._style.lineWidth,
619
+ geometry._style.strokeColor,
620
+ geometry._style.strokeWidth,
621
+ this._lineVerticesHighMerc,
622
+ this._lineVerticesLowMerc,
623
+ this._lineOrders,
624
+ this._lineIndexes,
625
+ this._lineColors,
626
+ this._linePickingColors,
627
+ this._lineThickness,
628
+ this._lineStrokeColors,
629
+ this._lineStrokes,
630
+ geometry._lineVerticesHighMerc,
631
+ geometry._lineVerticesLowMerc
632
+ );
633
+
634
+ geometry._lineVerticesLength =
635
+ this._lineVerticesHighMerc.length - geometry._lineVerticesHandlerIndex;
636
+ geometry._lineOrdersLength =
637
+ this._lineOrders.length - geometry._lineOrdersHandlerIndex;
638
+ geometry._lineIndexesLength =
639
+ this._lineIndexes.length - geometry._lineIndexesHandlerIndex;
640
+ geometry._lineColorsLength =
641
+ this._lineColors.length - geometry._lineColorsHandlerIndex;
642
+ geometry._lineThicknessLength =
643
+ this._lineThickness.length - geometry._lineThicknessHandlerIndex;
644
+
645
+ } else if (geometry._type === GeometryType.MULTIPOLYGON) {
646
+ let coordinates = geometry._coordinates;
647
+ let vertices = [],
648
+ indexes = [];
649
+
650
+ // Creates polygon stroke data
651
+ geometry._lineVerticesHandlerIndex = this._lineVerticesHighMerc.length;
652
+ geometry._lineOrdersHandlerIndex = this._lineOrders.length;
653
+ geometry._lineIndexesHandlerIndex = this._lineIndexes.length;
654
+ geometry._lineColorsHandlerIndex = this._lineColors.length;
655
+ geometry._lineThicknessHandlerIndex = this._lineThickness.length;
656
+
657
+ for (var i = 0; i < coordinates.length; i++) {
658
+ let cci = coordinates[i];
659
+ let ci = [];
660
+ for (let j = 0; j < cci.length; j++) {
661
+ ci[j] = [];
662
+ for (let k = 0; k < coordinates[i][j].length; k++) {
663
+ ci[j][k] = [
664
+ mercator.forward_lon(cci[j][k][0]),
665
+ mercator.forward_lat(cci[j][k][1])
666
+ ];
667
+ }
668
+ }
669
+ let data = flatten(ci);
670
+ let dataIndexes = earcut(data.vertices, data.holes, 2);
671
+
672
+ for (let j = 0; j < dataIndexes.length; j++) {
673
+ indexes.push(dataIndexes[j] + vertices.length * 0.5);
674
+ }
675
+
676
+ vertices.push.apply(vertices, data.vertices);
677
+
678
+ GeometryHandler.appendLineData(
679
+ ci,
680
+ true,
681
+ geometry._style.lineColor,
682
+ pickingColor,
683
+ geometry._style.lineWidth,
684
+ geometry._style.strokeColor,
685
+ geometry._style.strokeWidth,
686
+ this._lineVerticesHighMerc,
687
+ this._lineVerticesLowMerc,
688
+ this._lineOrders,
689
+ this._lineIndexes,
690
+ this._lineColors,
691
+ this._linePickingColors,
692
+ this._lineThickness,
693
+ this._lineStrokeColors,
694
+ this._lineStrokes,
695
+ geometry._lineVerticesHighMerc,
696
+ geometry._lineVerticesLowMerc
697
+ );
698
+ }
699
+
700
+ geometry._polyVerticesHandlerIndex = this._polyVerticesHighMerc.length;
701
+ geometry._polyIndexesHandlerIndex = this._polyIndexes.length;
702
+
703
+ for (let i = 0; i < indexes.length; i++) {
704
+ this._polyIndexes.push(indexes[i] + geometry._polyVerticesHandlerIndex * 0.5);
705
+ }
706
+
707
+ let color = geometry._style.fillColor;
708
+
709
+ let verticesHigh = [],
710
+ verticesLow = [];
711
+
712
+ for (let i = 0; i < vertices.length * 0.5; i++) {
713
+ this._polyColors.push(color.x, color.y, color.z, color.w);
714
+ this._polyPickingColors.push(
715
+ pickingColor.x,
716
+ pickingColor.y,
717
+ pickingColor.z,
718
+ 1.0
719
+ );
720
+ }
721
+
722
+ for (let i = 0; i < vertices.length; i++) {
723
+ doubleToTwoFloatsV2(vertices[i], tempHighLow);
724
+ verticesHigh[i] = tempHighLow.x;
725
+ verticesLow[i] = tempHighLow.y;
726
+ }
727
+
728
+ geometry._polyVerticesHighMerc = verticesHigh;
729
+ geometry._polyVerticesLowMerc = verticesLow;
730
+
731
+ this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc, verticesHigh);
732
+ this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc, verticesLow);
733
+
734
+ geometry._polyVerticesLength = vertices.length;
735
+ geometry._polyIndexesLength = indexes.length;
736
+
737
+ geometry._lineVerticesLength =
738
+ this._lineVerticesHighMerc.length - geometry._lineVerticesHandlerIndex;
739
+ geometry._lineOrdersLength =
740
+ this._lineOrders.length - geometry._lineOrdersHandlerIndex;
741
+ geometry._lineIndexesLength =
742
+ this._lineIndexes.length - geometry._lineIndexesHandlerIndex;
743
+ geometry._lineColorsLength =
744
+ this._lineColors.length - geometry._lineColorsHandlerIndex;
745
+ geometry._lineThicknessLength =
746
+ this._lineThickness.length - geometry._lineThicknessHandlerIndex;
747
+ } else if (geometry._type === GeometryType.LINESTRING) {
748
+ let coordinates = geometry._coordinates;
749
+ let ci = new Array(coordinates.length);
750
+ for (let j = 0; j < coordinates.length; j++) {
751
+ ci[j] = [
752
+ mercator.forward_lon(coordinates[j][0]),
753
+ mercator.forward_lat(coordinates[j][1])
754
+ ];
755
+ }
756
+
757
+ // Creates polygon stroke data
758
+ geometry._lineVerticesHandlerIndex = this._lineVerticesHighMerc.length;
759
+ geometry._lineOrdersHandlerIndex = this._lineOrders.length;
760
+ geometry._lineIndexesHandlerIndex = this._lineIndexes.length;
761
+ geometry._lineColorsHandlerIndex = this._lineColors.length;
762
+ geometry._lineThicknessHandlerIndex = this._lineThickness.length;
763
+
764
+ GeometryHandler.appendLineData(
765
+ [ci],
766
+ false,
767
+ geometry._style.lineColor,
768
+ pickingColor,
769
+ geometry._style.lineWidth,
770
+ geometry._style.strokeColor,
771
+ geometry._style.strokeWidth,
772
+ this._lineVerticesHighMerc,
773
+ this._lineVerticesLowMerc,
774
+ this._lineOrders,
775
+ this._lineIndexes,
776
+ this._lineColors,
777
+ this._linePickingColors,
778
+ this._lineThickness,
779
+ this._lineStrokeColors,
780
+ this._lineStrokes,
781
+ geometry._lineVerticesHighMerc,
782
+ geometry._lineVerticesLowMerc
783
+ );
784
+
785
+ geometry._lineVerticesLength =
786
+ this._lineVerticesHighMerc.length - geometry._lineVerticesHandlerIndex;
787
+ geometry._lineOrdersLength =
788
+ this._lineOrders.length - geometry._lineOrdersHandlerIndex;
789
+ geometry._lineIndexesLength =
790
+ this._lineIndexes.length - geometry._lineIndexesHandlerIndex;
791
+ geometry._lineColorsLength =
792
+ this._lineColors.length - geometry._lineColorsHandlerIndex;
793
+ geometry._lineThicknessLength =
794
+ this._lineThickness.length - geometry._lineThicknessHandlerIndex;
795
+ } else if (geometry._type === GeometryType.MULTILINESTRING) {
796
+ let coordinates = geometry._coordinates;
797
+ let ci = [];
798
+ for (let j = 0; j < coordinates.length; j++) {
799
+ ci[j] = [];
800
+ for (let k = 0; k < coordinates[j].length; k++) {
801
+ ci[j][k] = [
802
+ mercator.forward_lon(coordinates[j][k][0]),
803
+ mercator.forward_lat(coordinates[j][k][1])
804
+ ];
805
+ }
806
+ }
807
+
808
+ // Creates polygon stroke data
809
+ geometry._lineVerticesHandlerIndex = this._lineVerticesHighMerc.length;
810
+ geometry._lineOrdersHandlerIndex = this._lineOrders.length;
811
+ geometry._lineIndexesHandlerIndex = this._lineIndexes.length;
812
+ geometry._lineColorsHandlerIndex = this._lineColors.length;
813
+ geometry._lineThicknessHandlerIndex = this._lineThickness.length;
814
+
815
+ GeometryHandler.appendLineData(
816
+ ci,
817
+ false,
818
+ geometry._style.lineColor,
819
+ pickingColor,
820
+ geometry._style.lineWidth,
821
+ geometry._style.strokeColor,
822
+ geometry._style.strokeWidth,
823
+ this._lineVerticesHighMerc,
824
+ this._lineVerticesLowMerc,
825
+ this._lineOrders,
826
+ this._lineIndexes,
827
+ this._lineColors,
828
+ this._linePickingColors,
829
+ this._lineThickness,
830
+ this._lineStrokeColors,
831
+ this._lineStrokes,
832
+ geometry._lineVerticesHighMerc,
833
+ geometry._lineVerticesLowMerc
834
+ );
835
+
836
+ geometry._lineVerticesLength =
837
+ this._lineVerticesHighMerc.length - geometry._lineVerticesHandlerIndex;
838
+ geometry._lineOrdersLength =
839
+ this._lineOrders.length - geometry._lineOrdersHandlerIndex;
840
+ geometry._lineIndexesLength =
841
+ this._lineIndexes.length - geometry._lineIndexesHandlerIndex;
842
+ geometry._lineColorsLength =
843
+ this._lineColors.length - geometry._lineColorsHandlerIndex;
844
+ geometry._lineThicknessLength =
845
+ this._lineThickness.length - geometry._lineThicknessHandlerIndex;
846
+ }
847
+ }
848
+
849
+ // Refresh visibility
850
+ this.setGeometryVisibility(geometry);
851
+
852
+ !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
853
+ this._updatedGeometry[geometry._id] = true;
854
+ this.refresh();
855
+ }
856
+ }
857
+
858
+ remove(geometry) {
859
+ var index = geometry._handlerIndex;
860
+ if (index !== -1) {
861
+ this._geometries.splice(index, 1);
862
+
863
+ // polygon
864
+ // this._polyVerticesLonLat.splice(geometry._polyVerticesHandlerIndex, geometry._polyVerticesLength);
865
+ this._polyVerticesHighMerc.splice(
866
+ geometry._polyVerticesHandlerIndex,
867
+ geometry._polyVerticesLength
868
+ );
869
+ this._polyVerticesLowMerc.splice(
870
+ geometry._polyVerticesHandlerIndex,
871
+ geometry._polyVerticesLength
872
+ );
873
+
874
+ this._polyColors.splice(
875
+ geometry._polyVerticesHandlerIndex * 2,
876
+ geometry._polyVerticesLength * 2
877
+ );
878
+ this._polyPickingColors.splice(
879
+ geometry._polyVerticesHandlerIndex * 2,
880
+ geometry._polyVerticesLength * 2
881
+ );
882
+ this._polyIndexes.splice(
883
+ geometry._polyIndexesHandlerIndex,
884
+ geometry._polyIndexesLength
885
+ );
886
+ var di = geometry._polyVerticesLength * 0.5;
887
+ for (var i = geometry._polyIndexesHandlerIndex; i < this._polyIndexes.length; i++) {
888
+ this._polyIndexes[i] -= di;
889
+ }
890
+
891
+ // line
892
+ // this._lineVerticesLonLat.splice(geometry._lineVerticesHandlerIndex, geometry._lineVerticesLength);
893
+ this._lineVerticesHighMerc.splice(
894
+ geometry._lineVerticesHandlerIndex,
895
+ geometry._lineVerticesLength
896
+ );
897
+ this._lineVerticesLowMerc.splice(
898
+ geometry._lineVerticesHandlerIndex,
899
+ geometry._lineVerticesLength
900
+ );
901
+ this._lineOrders.splice(geometry._lineOrdersHandlerIndex, geometry._lineOrdersLength);
902
+ this._lineColors.splice(geometry._lineColorsHandlerIndex, geometry._lineColorsLength);
903
+ this._linePickingColors.splice(
904
+ geometry._lineColorsHandlerIndex,
905
+ geometry._lineColorsLength
906
+ );
907
+ this._lineStrokeColors.splice(
908
+ geometry._lineColorsHandlerIndex,
909
+ geometry._lineColorsLength
910
+ );
911
+ this._lineThickness.splice(
912
+ geometry._lineThicknessHandlerIndex,
913
+ geometry._lineThicknessLength
914
+ );
915
+ this._lineStrokes.splice(
916
+ geometry._lineThicknessHandlerIndex,
917
+ geometry._lineThicknessLength
918
+ );
919
+ this._lineIndexes.splice(
920
+ geometry._lineIndexesHandlerIndex,
921
+ geometry._lineIndexesLength
922
+ );
923
+ di = geometry._lineVerticesLength * 0.5;
924
+ for (let i = geometry._lineIndexesHandlerIndex; i < this._lineIndexes.length; i++) {
925
+ this._lineIndexes[i] -= di;
926
+ }
927
+
928
+ // reindex
929
+ var g = this._geometries;
930
+ for (let i = index; i < g.length; i++) {
931
+ var gi = g[i];
932
+ gi._handlerIndex = i;
933
+ gi._polyVerticesHandlerIndex -= geometry._polyVerticesLength;
934
+ gi._polyIndexesHandlerIndex -= geometry._polyIndexesLength;
935
+
936
+ gi._lineVerticesHandlerIndex -= geometry._lineVerticesLength;
937
+ gi._lineOrdersHandlerIndex -= geometry._lineOrdersLength;
938
+ gi._lineColorsHandlerIndex -= geometry._lineColorsLength;
939
+ gi._lineThicknessHandlerIndex -= geometry._lineThicknessLength;
940
+ gi._lineIndexesHandlerIndex -= geometry._lineIndexesLength;
941
+ }
942
+
943
+ geometry._pickingReady = false;
944
+
945
+ geometry._handler = null;
946
+ geometry._handlerIndex = -1;
947
+
948
+ geometry._polyVerticesHighMerc = [];
949
+ geometry._polyVerticesLowMerc = [];
950
+ geometry._polyVerticesLength = -1;
951
+ geometry._polyIndexesLength = -1;
952
+ geometry._polyVerticesHandlerIndex = -1;
953
+ geometry._polyIndexesHandlerIndex = -1;
954
+
955
+ geometry._lineVerticesHighMerc = [];
956
+ geometry._lineVerticesLowMerc = [];
957
+ geometry._lineVerticesLength = -1;
958
+ geometry._lineOrdersLength = -1;
959
+ geometry._lineIndexesLength = -1;
960
+ geometry._lineColorsLength = -1;
961
+ geometry._lineThicknessLength = -1;
962
+ geometry._lineVerticesHandlerIndex = -1;
963
+ geometry._lineOrdersHandlerIndex = -1;
964
+ geometry._lineIndexesHandlerIndex = -1;
965
+ geometry._lineThicknessHandlerIndex = -1;
966
+ geometry._lineColorsHandlerIndex = -1;
967
+
968
+ !this._removeGeometryExtents[geometry._id] &&
969
+ this._removeGeometryExtentArr.push(geometry.getExtent());
970
+ this._removeGeometryExtents[geometry._id] = true;
971
+
972
+ this.refresh();
973
+ }
974
+ }
975
+
976
+ _refreshRecursevely(geometry, treeNode) {
977
+ if (treeNode.ready) {
978
+ var lid = this._layer._id;
979
+ for (var i = 0; i < treeNode.nodes.length; i++) {
980
+ var ni = treeNode.nodes[i];
981
+ if (geometry._extent.overlaps(ni.segment.getExtentLonLat())) {
982
+ this._refreshRecursevely(geometry, ni);
983
+ var m = ni.segment.materials[lid];
984
+ if (m && m.isReady) {
985
+ if (m.segment.node.getState() !== quadTree.RENDERING) {
986
+ m.layer.clearMaterial(m);
987
+ } else {
988
+ m.pickingReady = m.pickingReady && geometry._pickingReady;
989
+ m.isReady = false;
990
+ m._updateTexture = m.texture;
991
+ m._updatePickingMask = m.pickingMask;
992
+ }
993
+ geometry._pickingReady = true;
994
+ }
995
+ }
996
+ }
997
+ }
998
+ }
999
+
1000
+ _refreshRecursevelyExt(extent, treeNode) {
1001
+ if (treeNode.ready) {
1002
+ var lid = this._layer._id;
1003
+ for (var i = 0; i < treeNode.nodes.length; i++) {
1004
+ var ni = treeNode.nodes[i];
1005
+ if (extent.overlaps(ni.segment.getExtentLonLat())) {
1006
+ this._refreshRecursevelyExt(extent, ni);
1007
+ var m = ni.segment.materials[lid];
1008
+ if (m && m.isReady) {
1009
+ m.layer.clearMaterial(m);
1010
+ // m.pickingReady = false;
1011
+ // m.isReady = false;
1012
+ // m._updateTexture = m.texture;
1013
+ // m._updatePickingMask = m.pickingMask;
1014
+ }
1015
+ }
1016
+ }
1017
+ }
1018
+ }
1019
+
1020
+ _refreshPlanetNode(treeNode) {
1021
+ var i = 0;
1022
+
1023
+ var e = this._removeGeometryExtentArr;
1024
+ for (i = 0; i < e.length; i++) {
1025
+ this._refreshRecursevelyExt(e[i], treeNode);
1026
+ }
1027
+
1028
+ var g = this._updatedGeometryArr;
1029
+ for (i = 0; i < g.length; i++) {
1030
+ this._refreshRecursevely(g[i], treeNode);
1031
+ }
1032
+ }
1033
+
1034
+ _updatePlanet() {
1035
+ var p = this._layer._planet;
1036
+ if (p) {
1037
+ p.quadTreeStrategy.quadTreeList.forEach(quadTree => {
1038
+ this._refreshPlanetNode(quadTree);
1039
+ });
1040
+ }
1041
+ this._updatedGeometryArr.length = 0;
1042
+ this._updatedGeometryArr = [];
1043
+ this._updatedGeometry = {};
1044
+
1045
+ this._removeGeometryExtentArr.length = 0;
1046
+ this._removeGeometryExtentArr = [];
1047
+ this._removeGeometryExtents = {};
1048
+ }
1049
+
1050
+ refresh() {
1051
+ var i = this._changedBuffers.length;
1052
+ while (i--) {
1053
+ this._changedBuffers[i] = true;
1054
+ }
1055
+ }
1056
+
1057
+ update() {
1058
+ if (this._handler) {
1059
+ var needUpdate = false;
1060
+ var i = this._changedBuffers.length;
1061
+ while (i--) {
1062
+ if (this._changedBuffers[i]) {
1063
+ needUpdate = true;
1064
+ this._buffersUpdateCallbacks[i].call(this);
1065
+ this._changedBuffers[i] = false;
1066
+ }
1067
+ }
1068
+ needUpdate && this._updatePlanet();
1069
+ }
1070
+ }
1071
+
1072
+ setGeometryVisibility(geometry) {
1073
+ var v = geometry._visibility ? 1.0 : 0.0;
1074
+
1075
+ var a = this._polyVerticesHighMerc,
1076
+ b = this._polyVerticesLowMerc;
1077
+
1078
+ var l = geometry._polyVerticesLength;
1079
+ var ind = geometry._polyVerticesHandlerIndex;
1080
+ for (var i = 0; i < l; i++) {
1081
+ a[ind + i] = geometry._polyVerticesHighMerc[i] * v;
1082
+ b[ind + i] = geometry._polyVerticesLowMerc[i] * v;
1083
+ }
1084
+
1085
+ a = this._lineVerticesHighMerc;
1086
+ b = this._lineVerticesLowMerc;
1087
+ l = geometry._lineVerticesLength;
1088
+ ind = geometry._lineVerticesHandlerIndex;
1089
+ for (i = 0; i < l; i++) {
1090
+ a[ind + i] = geometry._lineVerticesHighMerc[i] * v;
1091
+ b[ind + i] = geometry._lineVerticesLowMerc[i] * v;
1092
+ }
1093
+
1094
+ this._changedBuffers[POLYVERTICES_BUFFER] = true;
1095
+ this._changedBuffers[LINEVERTICES_BUFFER] = true;
1096
+
1097
+ !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
1098
+ this._updatedGeometry[geometry._id] = true;
1099
+ }
1100
+
1101
+ setPolyColorArr(geometry, color) {
1102
+ var index = geometry._polyVerticesHandlerIndex * 2, // ... / 2 * 4
1103
+ size = index + geometry._polyVerticesLength * 2; // ... / 2 * 4
1104
+ var a = this._polyColors;
1105
+ for (var i = index; i < size; i += 4) {
1106
+ a[i] = color.x;
1107
+ a[i + 1] = color.y;
1108
+ a[i + 2] = color.z;
1109
+ a[i + 3] = color.w;
1110
+ }
1111
+ this._changedBuffers[POLYCOLORS_BUFFER] = true;
1112
+ !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
1113
+ this._updatedGeometry[geometry._id] = true;
1114
+ }
1115
+
1116
+ setLineStrokeColorArr(geometry, color) {
1117
+ var index = geometry._lineColorsHandlerIndex,
1118
+ size = index + geometry._lineColorsLength;
1119
+ var a = this._lineStrokeColors;
1120
+ for (var i = index; i < size; i += 4) {
1121
+ a[i] = color.x;
1122
+ a[i + 1] = color.y;
1123
+ a[i + 2] = color.z;
1124
+ a[i + 3] = color.w;
1125
+ }
1126
+ this._changedBuffers[LINESTROKECOLORS_BUFFER] = true;
1127
+ !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
1128
+ this._updatedGeometry[geometry._id] = true;
1129
+ }
1130
+
1131
+ setLineColorArr(geometry, color) {
1132
+ var index = geometry._lineColorsHandlerIndex,
1133
+ size = index + geometry._lineColorsLength;
1134
+ var a = this._lineColors;
1135
+ for (var i = index; i < size; i += 4) {
1136
+ a[i] = color.x;
1137
+ a[i + 1] = color.y;
1138
+ a[i + 2] = color.z;
1139
+ a[i + 3] = color.w;
1140
+ }
1141
+ this._changedBuffers[LINECOLORS_BUFFER] = true;
1142
+ !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
1143
+ this._updatedGeometry[geometry._id] = true;
1144
+ }
1145
+
1146
+ setLineStrokeArr(geometry, width) {
1147
+ var index = geometry._lineStrokesHandlerIndex,
1148
+ size = index + geometry._lineStrokesLength;
1149
+ var a = this._lineStrokes;
1150
+ for (var i = index; i < size; i++) {
1151
+ a[i] = width;
1152
+ }
1153
+ this._changedBuffers[LINESTROKES_BUFFER] = true;
1154
+ !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
1155
+ this._updatedGeometry[geometry._id] = true;
1156
+ }
1157
+
1158
+ setLineThicknessArr(geometry, width) {
1159
+ var index = geometry._lineThicknessHandlerIndex,
1160
+ size = index + geometry._lineThicknessLength;
1161
+ var a = this._lineThickness;
1162
+ for (var i = index; i < size; i++) {
1163
+ a[i] = width;
1164
+ }
1165
+ this._changedBuffers[LINETHICKNESS_BUFFER] = true;
1166
+ !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
1167
+ this._updatedGeometry[geometry._id] = true;
1168
+ }
1169
+
1170
+ bringToFront(geometry) {
1171
+ var polyIndexes = this._polyIndexes.splice(
1172
+ geometry._polyIndexesHandlerIndex,
1173
+ geometry._polyIndexesLength
1174
+ );
1175
+ var lineIndexes = this._lineIndexes.splice(
1176
+ geometry._lineIndexesHandlerIndex,
1177
+ geometry._lineIndexesLength
1178
+ );
1179
+
1180
+ this._geometries.splice(geometry._handlerIndex, 1);
1181
+
1182
+ var g = this._geometries;
1183
+ for (var i = geometry._handlerIndex; i < g.length; i++) {
1184
+ var gi = g[i];
1185
+ gi._handlerIndex = i;
1186
+ gi._polyIndexesHandlerIndex -= geometry._polyIndexesLength;
1187
+ gi._lineIndexesHandlerIndex -= geometry._lineIndexesLength;
1188
+ }
1189
+
1190
+ geometry._polyIndexesHandlerIndex = this._polyIndexes.length;
1191
+ geometry._lineIndexesHandlerIndex = this._lineIndexes.length;
1192
+
1193
+ geometry._handlerIndex = this._geometries.length;
1194
+ this._geometries.push(geometry);
1195
+
1196
+ this._polyIndexes.push.apply(this._polyIndexes, polyIndexes);
1197
+ this._lineIndexes.push.apply(this._lineIndexes, lineIndexes);
1198
+
1199
+ this._changedBuffers[POLYINDEXES_BUFFER] = true;
1200
+ this._changedBuffers[LINEINDEXES_BUFFER] = true;
1201
+
1202
+ !this._updatedGeometry[geometry._id] && this._updatedGeometryArr.push(geometry);
1203
+ this._updatedGeometry[geometry._id] = true;
1204
+ }
1205
+
1206
+ createPolyVerticesBuffer() {
1207
+ var h = this._handler;
1208
+ h.gl.deleteBuffer(this._polyVerticesHighBufferMerc);
1209
+ this._polyVerticesHighBufferMerc = h.createArrayBuffer(
1210
+ new Float32Array(this._polyVerticesHighMerc),
1211
+ 2,
1212
+ this._polyVerticesHighMerc.length / 2
1213
+ );
1214
+
1215
+ h.gl.deleteBuffer(this._polyVerticesLowBufferMerc);
1216
+ this._polyVerticesLowBufferMerc = h.createArrayBuffer(
1217
+ new Float32Array(this._polyVerticesLowMerc),
1218
+ 2,
1219
+ this._polyVerticesLowMerc.length / 2
1220
+ );
1221
+ }
1222
+
1223
+ createPolyIndexesBuffer() {
1224
+ var h = this._handler;
1225
+ h.gl.deleteBuffer(this._polyIndexesBuffer);
1226
+ this._polyIndexesBuffer = h.createElementArrayBuffer(
1227
+ new Uint32Array(this._polyIndexes),
1228
+ 1,
1229
+ this._polyIndexes.length
1230
+ );
1231
+ }
1232
+
1233
+ createPolyColorsBuffer() {
1234
+ var h = this._handler;
1235
+ h.gl.deleteBuffer(this._polyColorsBuffer);
1236
+ this._polyColorsBuffer = h.createArrayBuffer(
1237
+ new Float32Array(this._polyColors),
1238
+ 4,
1239
+ this._polyColors.length / 4
1240
+ );
1241
+ }
1242
+
1243
+ createPolyPickingColorsBuffer() {
1244
+ var h = this._handler;
1245
+ h.gl.deleteBuffer(this._polyPickingColorsBuffer);
1246
+ this._polyPickingColorsBuffer = h.createArrayBuffer(
1247
+ new Float32Array(this._polyPickingColors),
1248
+ 4,
1249
+ this._polyPickingColors.length / 4
1250
+ );
1251
+ }
1252
+
1253
+ createLineVerticesBuffer() {
1254
+ var h = this._handler;
1255
+ h.gl.deleteBuffer(this._lineVerticesHighBufferMerc);
1256
+ this._lineVerticesHighBufferMerc = h.createArrayBuffer(
1257
+ new Float32Array(this._lineVerticesHighMerc),
1258
+ 2,
1259
+ this._lineVerticesHighMerc.length / 2
1260
+ );
1261
+
1262
+ h.gl.deleteBuffer(this._lineVerticesLowBufferMerc);
1263
+ this._lineVerticesLowBufferMerc = h.createArrayBuffer(
1264
+ new Float32Array(this._lineVerticesLowMerc),
1265
+ 2,
1266
+ this._lineVerticesLowMerc.length / 2
1267
+ );
1268
+ }
1269
+
1270
+ createLineIndexesBuffer() {
1271
+ var h = this._handler;
1272
+ h.gl.deleteBuffer(this._lineIndexesBuffer);
1273
+ this._lineIndexesBuffer = h.createElementArrayBuffer(
1274
+ new Uint32Array(this._lineIndexes),
1275
+ 1,
1276
+ this._lineIndexes.length
1277
+ );
1278
+ }
1279
+
1280
+ createLineOrdersBuffer() {
1281
+ var h = this._handler;
1282
+ h.gl.deleteBuffer(this._lineOrdersBuffer);
1283
+ this._lineOrdersBuffer = h.createArrayBuffer(
1284
+ new Float32Array(this._lineOrders),
1285
+ 1,
1286
+ this._lineOrders.length / 2
1287
+ );
1288
+ }
1289
+
1290
+ createLineColorsBuffer() {
1291
+ var h = this._handler;
1292
+ h.gl.deleteBuffer(this._lineColorsBuffer);
1293
+ this._lineColorsBuffer = h.createArrayBuffer(
1294
+ new Float32Array(this._lineColors),
1295
+ 4,
1296
+ this._lineColors.length / 4
1297
+ );
1298
+ }
1299
+
1300
+ createLinePickingColorsBuffer() {
1301
+ var h = this._handler;
1302
+ h.gl.deleteBuffer(this._linePickingColorsBuffer);
1303
+ this._linePickingColorsBuffer = h.createArrayBuffer(
1304
+ new Float32Array(this._linePickingColors),
1305
+ 4,
1306
+ this._linePickingColors.length / 4
1307
+ );
1308
+ }
1309
+
1310
+ createLineThicknessBuffer() {
1311
+ var h = this._handler;
1312
+ h.gl.deleteBuffer(this._lineThicknessBuffer);
1313
+ this._lineThicknessBuffer = h.createArrayBuffer(
1314
+ new Float32Array(this._lineThickness),
1315
+ 1,
1316
+ this._lineThickness.length
1317
+ );
1318
+ }
1319
+
1320
+ createLineStrokesBuffer() {
1321
+ var h = this._handler;
1322
+ h.gl.deleteBuffer(this._lineStrokesBuffer);
1323
+ this._lineStrokesBuffer = h.createArrayBuffer(
1324
+ new Float32Array(this._lineStrokes),
1325
+ 1,
1326
+ this._lineStrokes.length
1327
+ );
1328
+ }
1329
+
1330
+ createLineStrokeColorsBuffer() {
1331
+ var h = this._handler;
1332
+ h.gl.deleteBuffer(this._lineStrokeColorsBuffer);
1333
+ this._lineStrokeColorsBuffer = h.createArrayBuffer(
1334
+ new Float32Array(this._lineStrokeColors),
1335
+ 4,
1336
+ this._lineStrokeColors.length / 4
1337
+ );
1338
+ }
1339
+ }
1340
+
1341
+ export { GeometryHandler };