/
ReferenceProperty.js
157 lines (145 loc) · 7.04 KB
/
ReferenceProperty.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
/*global define*/
define([
'../Core/defaultValue',
'../Core/DeveloperError'
], function(
defaultValue,
DeveloperError) {
"use strict";
function resolve(referenceProperty) {
var targetProperty = referenceProperty._targetProperty;
if (typeof targetProperty === 'undefined') {
var resolveBuffer = defaultValue(referenceProperty._dynamicObjectCollection.compositeCollection, referenceProperty._dynamicObjectCollection);
var targetObject = resolveBuffer.getObject(referenceProperty._targetObjectId);
if (typeof targetObject !== 'undefined') {
targetProperty = targetObject[referenceProperty._targetPropertyName];
referenceProperty._targetProperty = targetProperty;
referenceProperty._targetObject = targetObject;
}
}
return targetProperty;
}
/**
* A dynamic property which transparently links to another property, which may
* or may not exist yet. It is up to the caller to know which kind of property
* is being linked to.
*
* @alias ReferenceProperty
* @constructor
*
* @param {DynamicObjectCollection} dynamicObjectCollection The object collection which will be used to resolve the reference.
* @param {String} targetObjectId The id of the object which is being referenced.
* @param {String} targetPropertyName The name of the property on the target object which we will use.
*
* @exception {DeveloperError} dynamicObjectCollection is required.
* @exception {DeveloperError} targetObjectId is required.
* @exception {DeveloperError} targetPropertyName is required.
*
* @see ReferenceProperty#fromString
* @see DynamicProperty
* @see DynamicPositionProperty
* @see DynamicDirectionsProperty
* @see DynamicVertexPositionsProperty
* @see DynamicObjectCollection
* @see CompositeDynamicObjectCollection
*/
var ReferenceProperty = function(dynamicObjectCollection, targetObjectId, targetPropertyName) {
if (typeof dynamicObjectCollection === 'undefined') {
throw new DeveloperError('dynamicObjectCollection is required.');
}
if (typeof targetObjectId === 'undefined') {
throw new DeveloperError('targetObjectId is required.');
}
if (typeof targetPropertyName === 'undefined') {
throw new DeveloperError('targetPropertyName is required.');
}
this._targetProperty = undefined;
this._dynamicObjectCollection = dynamicObjectCollection;
this._targetObjectId = targetObjectId;
this._targetObject = undefined;
this._targetPropertyName = targetPropertyName;
};
/**
* Creates a new reference property given the dynamic object collection that will
* be used to resolve it and a string indicating the target object id and property,
* delineated by a period.
*
* @param {DynamicObject} dynamicObjectCollection
* @param referenceString
*
* @exception {DeveloperError} dynamicObjectCollection is required.
* @exception {DeveloperError} referenceString is required.
* @exception {DeveloperError} referenceString must contain a single . delineating the target object ID and property name.
*
* @see ReferenceProperty#fromString
* @see DynamicProperty
* @see DynamicPositionProperty
* @see DynamicDirectionsProperty
* @see DynamicVertexPositionsProperty
* @see DynamicObjectCollection
* @see CompositeDynamicObjectCollection
*
* @returns A new instance of ReferenceProperty.
*/
ReferenceProperty.fromString = function(dynamicObjectCollection, referenceString) {
if (typeof dynamicObjectCollection === 'undefined') {
throw new DeveloperError('dynamicObjectCollection is required.');
}
if (typeof referenceString === 'undefined') {
throw new DeveloperError('referenceString is required.');
}
var parts = referenceString.split('.');
if (parts.length !== 2) {
throw new DeveloperError('referenceString must contain a single . delineating the target object ID and property name.');
}
return new ReferenceProperty(dynamicObjectCollection, parts[0], parts[1]);
};
/**
* Retrieves the value of the property at the specified time.
*
* @param time The time to evaluate the property.
* @param [result] The object to store the result in, if undefined a new instance will be created.
* @returns The result parameter or a new instance if the parameter was omitted.
*/
ReferenceProperty.prototype.getValue = function(time, result) {
var targetProperty = resolve(this);
return typeof targetProperty !== 'undefined' && this._targetObject.isAvailable(time) ? targetProperty.getValue(time, result) : undefined;
};
/**
* Retrieves the Cartographic value or values of the property at the specified time if the linked property
* is a DynamicPositionProperty or DynamicVertexPositionsProperty.
*
* @param time The time to evaluate the property.
* @param [result] The object to store the result in, if undefined a new instance will be created.
* @returns The result parameter or a new instance if the parameter was omitted.
*/
ReferenceProperty.prototype.getValueCartographic = function(time, result) {
var targetProperty = resolve(this);
return typeof targetProperty !== 'undefined' && this._targetObject.isAvailable(time) ? targetProperty.getValueCartographic(time, result) : undefined;
};
/**
* Retrieves the Cartesian value or values of the property at the specified time if the linked property
* is a DynamicPositionProperty, DynamicVertexPositionsProperty, or DynamicDirectionsProperty.
*
* @param time The time to evaluate the property.
* @param [result] The object to store the result in, if undefined a new instance will be created.
* @returns The result parameter or a new instance if the parameter was omitted.
*/
ReferenceProperty.prototype.getValueCartesian = function(time, result) {
var targetProperty = resolve(this);
return typeof targetProperty !== 'undefined' && this._targetObject.isAvailable(time) ? targetProperty.getValueCartesian(time, result) : undefined;
};
/**
* Retrieves the Spherical value or values of the property at the specified time if the linked property
* is a DynamicDirectionsProperty.
*
* @param time The time to evaluate the property.
* @param [result] The object to store the result in, if undefined a new instance will be created.
* @returns The result parameter or a new instance if the parameter was omitted.
*/
ReferenceProperty.prototype.getValueSpherical = function(time, result) {
var targetProperty = resolve(this);
return typeof targetProperty !== 'undefined' && this._targetObject.isAvailable(time) ? targetProperty.getValueSpherical(time, result) : undefined;
};
return ReferenceProperty;
});