/
GroundGeometryUpdater.js
232 lines (208 loc) · 6.25 KB
/
GroundGeometryUpdater.js
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import Check from "../Core/Check.js";
import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import GeometryOffsetAttribute from "../Core/GeometryOffsetAttribute.js";
import oneTimeWarning from "../Core/oneTimeWarning.js";
import GroundPrimitive from "../Scene/GroundPrimitive.js";
import HeightReference from "../Scene/HeightReference.js";
import CallbackProperty from "./CallbackProperty.js";
import ConstantProperty from "./ConstantProperty.js";
import GeometryUpdater from "./GeometryUpdater.js";
import TerrainOffsetProperty from "./TerrainOffsetProperty.js";
var defaultZIndex = new ConstantProperty(0);
/**
* An abstract class for updating ground geometry entities.
* @constructor
* @alias GroundGeometryUpdater
* @param {Object} options An object with the following properties:
* @param {Entity} options.entity The entity containing the geometry to be visualized.
* @param {Scene} options.scene The scene where visualization is taking place.
* @param {Object} options.geometryOptions Options for the geometry
* @param {String} options.geometryPropertyName The geometry property name
* @param {String[]} options.observedPropertyNames The entity properties this geometry cares about
*/
function GroundGeometryUpdater(options) {
GeometryUpdater.call(this, options);
this._zIndex = 0;
this._terrainOffsetProperty = undefined;
}
if (defined(Object.create)) {
GroundGeometryUpdater.prototype = Object.create(GeometryUpdater.prototype);
GroundGeometryUpdater.prototype.constructor = GroundGeometryUpdater;
}
Object.defineProperties(GroundGeometryUpdater.prototype, {
/**
* Gets the zindex
* @type {Number}
* @memberof GroundGeometryUpdater.prototype
* @readonly
*/
zIndex: {
get: function () {
return this._zIndex;
},
},
/**
* Gets the terrain offset property
* @type {TerrainOffsetProperty}
* @memberof GroundGeometryUpdater.prototype
* @readonly
* @private
*/
terrainOffsetProperty: {
get: function () {
return this._terrainOffsetProperty;
},
},
});
GroundGeometryUpdater.prototype._isOnTerrain = function (entity, geometry) {
return (
this._fillEnabled &&
!defined(geometry.height) &&
!defined(geometry.extrudedHeight) &&
GroundPrimitive.isSupported(this._scene)
);
};
GroundGeometryUpdater.prototype._getIsClosed = function (options) {
var height = options.height;
var extrudedHeight = options.extrudedHeight;
return height === 0 || (defined(extrudedHeight) && extrudedHeight !== height);
};
GroundGeometryUpdater.prototype._computeCenter =
DeveloperError.throwInstantiationError;
GroundGeometryUpdater.prototype._onEntityPropertyChanged = function (
entity,
propertyName,
newValue,
oldValue
) {
GeometryUpdater.prototype._onEntityPropertyChanged.call(
this,
entity,
propertyName,
newValue,
oldValue
);
if (this._observedPropertyNames.indexOf(propertyName) === -1) {
return;
}
var geometry = this._entity[this._geometryPropertyName];
if (!defined(geometry)) {
return;
}
if (
defined(geometry.zIndex) &&
(defined(geometry.height) || defined(geometry.extrudedHeight))
) {
oneTimeWarning(oneTimeWarning.geometryZIndex);
}
this._zIndex = defaultValue(geometry.zIndex, defaultZIndex);
if (defined(this._terrainOffsetProperty)) {
this._terrainOffsetProperty.destroy();
this._terrainOffsetProperty = undefined;
}
var heightReferenceProperty = geometry.heightReference;
var extrudedHeightReferenceProperty = geometry.extrudedHeightReference;
if (
defined(heightReferenceProperty) ||
defined(extrudedHeightReferenceProperty)
) {
var centerPosition = new CallbackProperty(
this._computeCenter.bind(this),
!this._dynamic
);
this._terrainOffsetProperty = new TerrainOffsetProperty(
this._scene,
centerPosition,
heightReferenceProperty,
extrudedHeightReferenceProperty
);
}
};
/**
* Destroys and resources used by the object. Once an object is destroyed, it should not be used.
*
* @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
*/
GroundGeometryUpdater.prototype.destroy = function () {
if (defined(this._terrainOffsetProperty)) {
this._terrainOffsetProperty.destroy();
this._terrainOffsetProperty = undefined;
}
GeometryUpdater.prototype.destroy.call(this);
};
/**
* @private
*/
GroundGeometryUpdater.getGeometryHeight = function (height, heightReference) {
//>>includeStart('debug', pragmas.debug);
Check.defined("heightReference", heightReference);
//>>includeEnd('debug');
if (!defined(height)) {
if (heightReference !== HeightReference.NONE) {
oneTimeWarning(oneTimeWarning.geometryHeightReference);
}
return;
}
if (heightReference !== HeightReference.CLAMP_TO_GROUND) {
return height;
}
return 0.0;
};
/**
* @private
*/
GroundGeometryUpdater.getGeometryExtrudedHeight = function (
extrudedHeight,
extrudedHeightReference
) {
//>>includeStart('debug', pragmas.debug);
Check.defined("extrudedHeightReference", extrudedHeightReference);
//>>includeEnd('debug');
if (!defined(extrudedHeight)) {
if (extrudedHeightReference !== HeightReference.NONE) {
oneTimeWarning(oneTimeWarning.geometryExtrudedHeightReference);
}
return;
}
if (extrudedHeightReference !== HeightReference.CLAMP_TO_GROUND) {
return extrudedHeight;
}
return GroundGeometryUpdater.CLAMP_TO_GROUND;
};
/**
* @private
*/
GroundGeometryUpdater.CLAMP_TO_GROUND = "clamp";
/**
* @private
*/
GroundGeometryUpdater.computeGeometryOffsetAttribute = function (
height,
heightReference,
extrudedHeight,
extrudedHeightReference
) {
if (!defined(height) || !defined(heightReference)) {
heightReference = HeightReference.NONE;
}
if (!defined(extrudedHeight) || !defined(extrudedHeightReference)) {
extrudedHeightReference = HeightReference.NONE;
}
var n = 0;
if (heightReference !== HeightReference.NONE) {
n++;
}
if (extrudedHeightReference === HeightReference.RELATIVE_TO_GROUND) {
n++;
}
if (n === 2) {
return GeometryOffsetAttribute.ALL;
}
if (n === 1) {
return GeometryOffsetAttribute.TOP;
}
return undefined;
};
export default GroundGeometryUpdater;