-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
DynamicPath.js
229 lines (211 loc) · 8.64 KB
/
DynamicPath.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
/*global define*/
define([
'../Core/TimeInterval',
'../Core/defaultValue',
'./CzmlBoolean',
'./CzmlNumber',
'./CzmlColor',
'./DynamicProperty'],
function(
TimeInterval,
defaultValue,
CzmlBoolean,
CzmlNumber,
CzmlColor,
DynamicProperty) {
"use strict";
/**
* Represents a time-dynamic path, typically used in conjunction with DynamicPathVisualizer and
* DynamicObjectCollection to visualize CZML.
*
* @alias DynamicPath
* @constructor
*
* @see DynamicObject
* @see DynamicProperty
* @see DynamicObjectCollection
* @see DynamicPathVisualizer
* @see VisualizerCollection
* @see Polyline
* @see CzmlDefaults
*/
var DynamicPath = function() {
/**
* A DynamicProperty of type CzmlColor which determines the line's color.
* @type DynamicProperty
*/
this.color = undefined;
/**
* A DynamicProperty of type CzmlColor which determines the line's outline color.
* @type DynamicProperty
*/
this.outlineColor = undefined;
/**
* A DynamicProperty of type CzmlNumber which determines the line's outline width.
* @type DynamicProperty
*/
this.outlineWidth = undefined;
/**
* A DynamicProperty of type CzmlBoolean which determines the lines's visibility.
* @type DynamicProperty
*/
this.show = undefined;
/**
* A DynamicProperty of type CzmlNumber which determines the line's width.
* @type DynamicProperty
*/
this.width = undefined;
/**
* A DynamicProperty of type CzmlNumber which determines the maximum step size, in seconds, to take when sampling the position.
* @type DynamicProperty
*/
this.resolution = undefined;
/**
* A DynamicProperty of type CzmlNumber which determines the number of seconds in front of the object to show.
* @type DynamicProperty
*/
this.leadTime = undefined;
/**
* A DynamicProperty of type CzmlNumber which determines the the number of seconds behind the object to show.
* @type DynamicProperty
*/
this.trailTime = undefined;
};
/**
* Processes a single CZML packet and merges its data into the provided DynamicObject's path.
* If the DynamicObject does not have a path, one is created. This method is not
* normally called directly, but is part of the array of CZML processing functions that is
* passed into the DynamicObjectCollection constructor.
*
* @param {DynamicObject} dynamicObject The DynamicObject which will contain the path data.
* @param {Object} packet The CZML packet to process.
* @returns {Boolean} true if any new properties were created while processing the packet, false otherwise.
*
* @see DynamicObject
* @see DynamicProperty
* @see DynamicObjectCollection
* @see CzmlDefaults#updaters
*/
DynamicPath.processCzmlPacket = function(dynamicObject, packet) {
var pathData = packet.path;
if (typeof pathData === 'undefined') {
return false;
}
var pathUpdated = false;
var path = dynamicObject.path;
pathUpdated = typeof path === 'undefined';
if (pathUpdated) {
dynamicObject.path = path = new DynamicPath();
}
var interval = pathData.interval;
if (typeof interval !== 'undefined') {
interval = TimeInterval.fromIso8601(interval);
}
if (typeof pathData.color !== 'undefined') {
var color = path.color;
if (typeof color === 'undefined') {
path.color = color = new DynamicProperty(CzmlColor);
pathUpdated = true;
}
color.processCzmlIntervals(pathData.color, interval);
}
if (typeof pathData.width !== 'undefined') {
var width = path.width;
if (typeof width === 'undefined') {
path.width = width = new DynamicProperty(CzmlNumber);
pathUpdated = true;
}
width.processCzmlIntervals(pathData.width, interval);
}
if (typeof pathData.resolution !== 'undefined') {
var resolution = path.resolution;
if (typeof resolution === 'undefined') {
path.resolution = resolution = new DynamicProperty(CzmlNumber);
pathUpdated = true;
}
resolution.processCzmlIntervals(pathData.resolution, interval);
}
if (typeof pathData.outlineColor !== 'undefined') {
var outlineColor = path.outlineColor;
if (typeof outlineColor === 'undefined') {
path.outlineColor = outlineColor = new DynamicProperty(CzmlColor);
pathUpdated = true;
}
outlineColor.processCzmlIntervals(pathData.outlineColor, interval);
}
if (typeof pathData.outlineWidth !== 'undefined') {
var outlineWidth = path.outlineWidth;
if (typeof outlineWidth === 'undefined') {
path.outlineWidth = outlineWidth = new DynamicProperty(CzmlNumber);
pathUpdated = true;
}
outlineWidth.processCzmlIntervals(pathData.outlineWidth, interval);
}
if (typeof pathData.show !== 'undefined') {
var show = path.show;
if (typeof show === 'undefined') {
path.show = show = new DynamicProperty(CzmlBoolean);
pathUpdated = true;
}
show.processCzmlIntervals(pathData.show, interval);
}
if (typeof pathData.leadTime !== 'undefined') {
var leadTime = path.leadTime;
if (typeof leadTime === 'undefined') {
path.leadTime = leadTime = new DynamicProperty(CzmlNumber);
pathUpdated = true;
}
leadTime.processCzmlIntervals(pathData.leadTime, interval);
}
if (typeof pathData.trailTime !== 'undefined') {
var trailTime = path.trailTime;
if (typeof trailTime === 'undefined') {
path.trailTime = trailTime = new DynamicProperty(CzmlNumber);
pathUpdated = true;
}
trailTime.processCzmlIntervals(pathData.trailTime, interval);
}
return pathUpdated;
};
/**
* Given two DynamicObjects, takes the path properties from the second
* and assigns them to the first, assuming such a property did not already exist.
* This method is not normally called directly, but is part of the array of CZML processing
* functions that is passed into the CompositeDynamicObjectCollection constructor.
*
* @param {DynamicObject} targetObject The DynamicObject which will have properties merged onto it.
* @param {DynamicObject} objectToMerge The DynamicObject containing properties to be merged.
*
* @see CzmlDefaults
*/
DynamicPath.mergeProperties = function(targetObject, objectToMerge) {
var pathToMerge = objectToMerge.path;
if (typeof pathToMerge !== 'undefined') {
var targetpath = targetObject.path;
if (typeof targetpath === 'undefined') {
targetObject.path = targetpath = new DynamicPath();
}
targetpath.color = defaultValue(targetpath.color, pathToMerge.color);
targetpath.width = defaultValue(targetpath.width, pathToMerge.width);
targetpath.resolution = defaultValue(targetpath.resolution, pathToMerge.resolution);
targetpath.outlineColor = defaultValue(targetpath.outlineColor, pathToMerge.outlineColor);
targetpath.outlineWidth = defaultValue(targetpath.outlineWidth, pathToMerge.outlineWidth);
targetpath.show = defaultValue(targetpath.show, pathToMerge.show);
targetpath.leadTime = defaultValue(targetpath.leadTime, pathToMerge.leadTime);
targetpath.trailTime = defaultValue(targetpath.trailTime, pathToMerge.trailTime);
}
};
/**
* Given a DynamicObject, undefines the path associated with it.
* This method is not normally called directly, but is part of the array of CZML processing
* functions that is passed into the CompositeDynamicObjectCollection constructor.
*
* @param {DynamicObject} dynamicObject The DynamicObject to remove the path from.
*
* @see CzmlDefaults
*/
DynamicPath.undefineProperties = function(dynamicObject) {
dynamicObject.path = undefined;
};
return DynamicPath;
});