/
Entity.js
347 lines (331 loc) · 11.9 KB
/
Entity.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/*global define*/
define([
'../Core/createGuid',
'../Core/defaultValue',
'../Core/defined',
'../Core/defineProperties',
'../Core/DeveloperError',
'../Core/Event',
'./createPropertyDescriptor'
], function(
createGuid,
defaultValue,
defined,
defineProperties,
DeveloperError,
Event,
createPropertyDescriptor) {
"use strict";
/**
* Entity instances are the primary data store for processed data.
* They are used primarily by the visualizers to create and maintain graphic
* primitives that represent the Entity's properties at a specific time.
* @alias Entity
* @constructor
*
* @param {String} [id] A unique identifier for this object. If no id is provided, a GUID is generated.
*
* @see Property
* @see EntityCollection
*/
var Entity = function(id) {
if (!defined(id)) {
id = createGuid();
}
this._availability = undefined;
this._id = id;
this._definitionChanged = new Event();
this._name = undefined;
this._parent = undefined;
this._propertyNames = ['billboard', 'description', 'ellipse', 'ellipsoid', 'label', 'model', //
'orientation', 'path', 'point', 'polygon', 'polyline', 'position', //
'rectangle', 'viewFrom', 'wall'];
this._billboard = undefined;
this._billboardSubscription = undefined;
this._description = undefined;
this._descriptionSubscription = undefined;
this._ellipse = undefined;
this._ellipseSubscription = undefined;
this._ellipsoid = undefined;
this._ellipsoidSubscription = undefined;
this._label = undefined;
this._labelSubscription = undefined;
this._model = undefined;
this._modelSubscription = undefined;
this._orientation = undefined;
this._orientationSubscription = undefined;
this._path = undefined;
this._pathSubscription = undefined;
this._point = undefined;
this._pointSubscription = undefined;
this._polygon = undefined;
this._polygonSubscription = undefined;
this._polyline = undefined;
this._polylineSubscription = undefined;
this._position = undefined;
this._positionSubscription = undefined;
this._rectangle = undefined;
this._rectangleSubscription = undefined;
this._viewFrom = undefined;
this._viewFromSubscription = undefined;
this._wall = undefined;
this._wallSubscription = undefined;
};
defineProperties(Entity.prototype, {
/**
* The availability, if any, associated with this object.
* If availability is undefined, it is assumed that this object's
* other properties will return valid data for any provided time.
* If availability exists, the objects other properties will only
* provide valid data if queried within the given interval.
* @memberof Entity.prototype
* @type {TimeIntervalCollection}
*/
availability : createPropertyDescriptor('availability'),
/**
* Gets the unique ID associated with this object.
* @memberof Entity.prototype
* @type {String}
*/
id : {
get : function() {
return this._id;
}
},
/**
* Gets the event that is raised whenever a new property is assigned.
* @memberof Entity.prototype
*
* @type {Event}
* @readonly
*/
definitionChanged : {
get : function() {
return this._definitionChanged;
}
},
/**
* Gets or sets the name of the object. The name is intended for end-user
* consumption and does not need to be unique.
* @memberof Entity.prototype
* @type {String}
*/
name : {
configurable : false,
get : function() {
return this._name;
},
set : function(value) {
var oldValue = this._name;
if (oldValue !== value) {
this._name = value;
this._definitionChanged.raiseEvent(this, 'name', value, oldValue);
}
}
},
/**
* Gets or sets the parent object.
* @memberof Entity.prototype
* @type {Entity}
*/
parent : createPropertyDescriptor('parent'),
/**
* Gets the names of all properties registed on this instance.
* @memberof Entity.prototype
* @type {Event}
*/
propertyNames : {
get : function() {
return this._propertyNames;
}
},
/**
* Gets or sets the billboard.
* @memberof Entity.prototype
* @type {BillboardGraphics}
*/
billboard : createPropertyDescriptor('billboard'),
/**
* Gets or sets the description.
* @memberof Entity.prototype
* @type {Property}
*/
description : createPropertyDescriptor('description'),
/**
* Gets or sets the ellipse.
* @memberof Entity.prototype
* @type {EllipseGraphics}
*/
ellipse : createPropertyDescriptor('ellipse'),
/**
* Gets or sets the ellipsoid.
* @memberof Entity.prototype
* @type {EllipsoidGraphics}
*/
ellipsoid : createPropertyDescriptor('ellipsoid'),
/**
* Gets or sets the label.
* @memberof Entity.prototype
* @type {LabelGraphics}
*/
label : createPropertyDescriptor('label'),
/**
* Gets or sets the model.
* @memberof Entity.prototype
* @type {LabelGraphics}
*/
model : createPropertyDescriptor('model'),
/**
* Gets or sets the orientation.
* @memberof Entity.prototype
* @type {Property}
*/
orientation : createPropertyDescriptor('orientation'),
/**
* Gets or sets the path.
* @memberof Entity.prototype
* @type {PathGraphics}
*/
path : createPropertyDescriptor('path'),
/**
* Gets or sets the point graphic.
* @memberof Entity.prototype
* @type {PointGraphics}
*/
point : createPropertyDescriptor('point'),
/**
* Gets or sets the polygon.
* @memberof Entity.prototype
* @type {PolygonGraphics}
*/
polygon : createPropertyDescriptor('polygon'),
/**
* Gets or sets the polyline.
* @memberof Entity.prototype
* @type {PolylineGraphics}
*/
polyline : createPropertyDescriptor('polyline'),
/**
* Gets or sets the position.
* @memberof Entity.prototype
* @type {PositionProperty}
*/
position : createPropertyDescriptor('position'),
/**
* Gets or sets the rectangle.
* @memberof Entity.prototype
* @type {RectangleGraphics}
*/
rectangle : createPropertyDescriptor('rectangle'),
/**
* Gets or sets the suggested initial offset for viewing this object
* with the camera. The offset is defined in the east-north-up reference frame.
* @memberof Entity.prototype
* @type {Cartesian3}
*/
viewFrom : createPropertyDescriptor('viewFrom'),
/**
* Gets or sets the wall.
* @memberof Entity.prototype
* @type {WallGraphics}
*/
wall : createPropertyDescriptor('wall')
});
/**
* Given a time, returns true if this object should have data during that time.
*
* @param {JulianDate} time The time to check availability for.
* @returns true if the object should have data during the provided time, false otherwise.
*/
Entity.prototype.isAvailable = function(time) {
//>>includeStart('debug', pragmas.debug);
if (!defined(time)) {
throw new DeveloperError('time is required.');
}
//>>includeEnd('debug');
var availability = this._availability;
return !defined(availability) || availability.contains(time);
};
/**
* Adds a property to this object. Once a property is added, it can be
* observed with {@link Entity#definitionChanged} and composited
* with {@link CompositeEntityCollection}
*
* @param {String} propertyName The name of the property to add.
*
* @exception {DeveloperError} "propertyName" is a reserved property name.
* @exception {DeveloperError} "propertyName" is already a registered property.
*/
Entity.prototype.addProperty = function(propertyName) {
var propertyNames = this._propertyNames;
//>>includeStart('debug', pragmas.debug);
if (!defined(propertyName)) {
throw new DeveloperError('propertyName is required.');
}
if (propertyNames.indexOf(propertyName) !== -1) {
throw new DeveloperError(propertyName + ' is already a registered property.');
}
if (propertyName in this) {
throw new DeveloperError(propertyName + ' is a reserved property name.');
}
//>>includeEnd('debug');
propertyNames.push(propertyName);
Object.defineProperty(this, propertyName, createPropertyDescriptor(propertyName, true));
};
/**
* Removed a property previously added with addProperty.
*
* @param {String} propertyName The name of the property to remove.
*
* @exception {DeveloperError} "propertyName" is a reserved property name.
* @exception {DeveloperError} "propertyName" is not a registered property.
*/
Entity.prototype.removeProperty = function(propertyName) {
var propertyNames = this._propertyNames;
//>>includeStart('debug', pragmas.debug);
if (!defined(propertyName)) {
throw new DeveloperError('propertyName is required.');
}
if (propertyNames.indexOf(propertyName) === -1) {
throw new DeveloperError(propertyName + ' is not a registered property.');
}
//>>includeEnd('debug');
this._propertyNames.push(propertyName);
delete this[propertyName];
};
/**
* Assigns each unassigned property on this object to the value
* of the same property on the provided source object.
*
* @param {Entity} source The object to be merged into this object.
*/
Entity.prototype.merge = function(source) {
//>>includeStart('debug', pragmas.debug);
if (!defined(source)) {
throw new DeveloperError('source is required.');
}
//>>includeEnd('debug');
//Name and availability are not Property objects and are currently handled differently.
this.name = defaultValue(this.name, source.name);
this.availability = defaultValue(source.availability, this.availability);
var propertyNames = this._propertyNames;
var propertyNamesLength = propertyNames.length;
for (var i = 0; i < propertyNamesLength; i++) {
var name = propertyNames[i];
var targetProperty = this[name];
var sourceProperty = source[name];
if (defined(sourceProperty)) {
if (defined(targetProperty)) {
if (defined(targetProperty.merge)) {
targetProperty.merge(sourceProperty);
}
} else if (defined(sourceProperty.merge) && defined(sourceProperty.clone)) {
this[name] = sourceProperty.clone();
} else {
this[name] = sourceProperty;
}
}
}
};
return Entity;
});