/
CustomDataSource.js
172 lines (168 loc) · 4.96 KB
/
CustomDataSource.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
define([
'../Core/defined',
'../Core/defineProperties',
'../Core/DeveloperError',
'../Core/Event',
'./DataSource',
'./EntityCluster',
'./EntityCollection'
], function(
defined,
defineProperties,
DeveloperError,
Event,
DataSource,
EntityCluster,
EntityCollection) {
'use strict';
/**
* A {@link DataSource} implementation which can be used to manually manage a group of entities.
*
* @alias CustomDataSource
* @constructor
*
* @param {String} [name] A human-readable name for this instance.
*
* @example
* var dataSource = new Cesium.CustomDataSource('myData');
*
* var entity = dataSource.entities.add({
* position : Cesium.Cartesian3.fromDegrees(1, 2, 0),
* billboard : {
* image : 'image.png'
* }
* });
*
* viewer.dataSources.add(dataSource);
*/
function CustomDataSource(name) {
this._name = name;
this._clock = undefined;
this._changed = new Event();
this._error = new Event();
this._isLoading = false;
this._loading = new Event();
this._entityCollection = new EntityCollection(this);
this._entityCluster = new EntityCluster();
}
defineProperties(CustomDataSource.prototype, {
/**
* Gets or sets a human-readable name for this instance.
* @memberof CustomDataSource.prototype
* @type {String}
*/
name : {
get : function() {
return this._name;
},
set : function(value) {
if (this._name !== value) {
this._name = value;
this._changed.raiseEvent(this);
}
}
},
/**
* Gets or sets the clock for this instance.
* @memberof CustomDataSource.prototype
* @type {DataSourceClock}
*/
clock : {
get : function() {
return this._clock;
},
set : function(value) {
if (this._clock !== value) {
this._clock = value;
this._changed.raiseEvent(this);
}
}
},
/**
* Gets the collection of {@link Entity} instances.
* @memberof CustomDataSource.prototype
* @type {EntityCollection}
*/
entities : {
get : function() {
return this._entityCollection;
}
},
/**
* Gets or sets whether the data source is currently loading data.
* @memberof CustomDataSource.prototype
* @type {Boolean}
*/
isLoading : {
get : function() {
return this._isLoading;
},
set : function(value) {
DataSource.setLoading(this, value);
}
},
/**
* Gets an event that will be raised when the underlying data changes.
* @memberof CustomDataSource.prototype
* @type {Event}
*/
changedEvent : {
get : function() {
return this._changed;
}
},
/**
* Gets an event that will be raised if an error is encountered during processing.
* @memberof CustomDataSource.prototype
* @type {Event}
*/
errorEvent : {
get : function() {
return this._error;
}
},
/**
* Gets an event that will be raised when the data source either starts or stops loading.
* @memberof CustomDataSource.prototype
* @type {Event}
*/
loadingEvent : {
get : function() {
return this._loading;
}
},
/**
* Gets whether or not this data source should be displayed.
* @memberof CustomDataSource.prototype
* @type {Boolean}
*/
show : {
get : function() {
return this._entityCollection.show;
},
set : function(value) {
this._entityCollection.show = value;
}
},
/**
* Gets or sets the clustering options for this data source. This object can be shared between multiple data sources.
*
* @memberof CustomDataSource.prototype
* @type {EntityCluster}
*/
clustering : {
get : function() {
return this._entityCluster;
},
set : function(value) {
//>>includeStart('debug', pragmas.debug);
if (!defined(value)) {
throw new DeveloperError('value must be defined.');
}
//>>includeEnd('debug');
this._entityCluster = value;
}
}
});
return CustomDataSource;
});