-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathBufferPolylineCollection.js
More file actions
132 lines (115 loc) · 4 KB
/
BufferPolylineCollection.js
File metadata and controls
132 lines (115 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// @ts-check
import defined from "../Core/defined.js";
import BufferPrimitiveCollection from "./BufferPrimitiveCollection.js";
import BufferPolyline from "./BufferPolyline.js";
import renderPolylines from "./renderBufferPolylineCollection.js";
/** @import { TypedArray } from "../Core/globalTypes.js"; */
/** @import Color from "../Core/Color.js"; */
/** @import Matrix4 from "../Core/Matrix4.js"; */
/** @import FrameState from "./FrameState.js" */
/**
* @typedef {object} BufferPolylineOptions
* @property {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] Transforms geometry from model to world coordinates.
* @property {boolean} [show=true]
* @property {Color} [color=Color.WHITE]
* @property {TypedArray} [positions]
* @property {number} [width=1]
* @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
*/
/**
* Collection of polylines held in ArrayBuffer storage for performance and memory optimization.
*
* <p>Default buffer memory allocation is arbitrary, and collections cannot be resized,
* so specific per-buffer capacities should be provided in the collection
* constructor when available.</p>
*
* @example
* const collection = new BufferPolylineCollection({
* primitiveCountMax: 1024,
* vertexCountMax: 4096,
* });
*
* const polyline = new BufferPolyline();
*
* // Create a new polyline, temporarily bound to 'polyline' local variable.
* collection.add({
* positions: new Float64Array([ ... ]),
* color: Color.WHITE,
* }, polyline);
*
* // Iterate over all polylines in collection, temporarily binding 'polyline'
* // local variable to each, and updating polyline color.
* for (let i = 0; i < collection.primitiveCount; i++) {
* collection.get(i, polyline);
* polyline.setColor(Color.RED);
* }
*
* @see BufferPolyline
* @see BufferPrimitiveCollection
* @extends BufferPrimitiveCollection<BufferPolyline>
* @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
*/
class BufferPolylineCollection extends BufferPrimitiveCollection {
_getCollectionClass() {
return BufferPolylineCollection;
}
_getPrimitiveClass() {
return BufferPolyline;
}
/////////////////////////////////////////////////////////////////////////////
// COLLECTION LIFECYCLE
/**
* @param {BufferPolylineCollection} collection
* @returns {BufferPolylineCollection}
* @override
* @ignore
*/
static _cloneEmpty(collection) {
return new BufferPolylineCollection({
primitiveCountMax: collection.primitiveCountMax,
vertexCountMax: collection.vertexCountMax,
});
}
/////////////////////////////////////////////////////////////////////////////
// PRIMITIVE LIFECYCLE
/**
* Adds a new polyline to the collection, with the specified options. A
* {@link BufferPolyline} instance is linked to the new polyline, using
* the 'result' argument if given, or a new instance if not. For repeated
* calls, prefer to reuse a single BufferPolyline instance rather than
* allocating a new instance on each call.
*
* @param {BufferPolylineOptions} options
* @param {BufferPolyline} result
* @returns {BufferPolyline}
* @override
*/
add(options, result = new BufferPolyline()) {
super.add(options, result);
const vertexOffset = this._positionCount;
result._setUint32(BufferPolyline.Layout.POSITION_OFFSET_U32, vertexOffset);
result._setUint32(BufferPolyline.Layout.POSITION_COUNT_U32, 0);
result.width = options.width ?? 1;
if (defined(options.positions)) {
result.setPositions(options.positions);
}
return result;
}
/////////////////////////////////////////////////////////////////////////////
// RENDER
/**
* @param {FrameState} frameState
* @ignore
*/
update(frameState) {
super.update(frameState);
if (this.show) {
this._renderContext = renderPolylines(
this,
frameState,
this._renderContext,
);
}
}
}
export default BufferPolylineCollection;