Skip to content

Commit c2bb133

Browse files
Add options.query to CZML in order to append tokens to URL/URI
1 parent 04396a9 commit c2bb133

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

Source/DataSources/CzmlDataSource.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ define([
2121
'../Core/HermitePolynomialApproximation',
2222
'../Core/isArray',
2323
'../Core/Iso8601',
24+
'../Core/joinUrls',
2425
'../Core/JulianDate',
2526
'../Core/LagrangePolynomialApproximation',
2627
'../Core/LinearApproximation',
2728
'../Core/loadJson',
2829
'../Core/Math',
2930
'../Core/NearFarScalar',
31+
'../Core/objectToQuery',
3032
'../Core/Quaternion',
3133
'../Core/Rectangle',
3234
'../Core/ReferenceFrame',
@@ -107,12 +109,14 @@ define([
107109
HermitePolynomialApproximation,
108110
isArray,
109111
Iso8601,
112+
joinUrls,
110113
JulianDate,
111114
LagrangePolynomialApproximation,
112115
LinearApproximation,
113116
loadJson,
114117
CesiumMath,
115118
NearFarScalar,
119+
objectToQuery,
116120
Quaternion,
117121
Rectangle,
118122
ReferenceFrame,
@@ -217,7 +221,16 @@ define([
217221
function unwrapUriInterval(czmlInterval, sourceUri) {
218222
var result = defaultValue(czmlInterval.uri, czmlInterval);
219223
if (defined(sourceUri)) {
220-
result = getAbsoluteUri(result, getAbsoluteUri(sourceUri));
224+
var uriComponents = sourceUri.split('?');
225+
var sourceUriPath = uriComponents[0];
226+
var query = uriComponents[1];
227+
result = getAbsoluteUri(result, getAbsoluteUri(sourceUriPath));
228+
229+
if (defined(query)) {
230+
// Add back the question mark and append to the result
231+
query = '?' + query;
232+
result = joinUrls(result, query, false);
233+
}
221234
}
222235
return result;
223236
}
@@ -1892,9 +1905,18 @@ define([
18921905

18931906
var promise = czml;
18941907
var sourceUri = options.sourceUri;
1908+
var query = options.query;
1909+
var queryBlob = defined(query) ? '?' + objectToQuery(query) : '';
1910+
1911+
// If the czml is a URL
18951912
if (typeof czml === 'string') {
1896-
promise = loadJson(czml);
18971913
sourceUri = defaultValue(sourceUri, czml);
1914+
czml = joinUrls(czml, queryBlob, false);
1915+
promise = loadJson(czml);
1916+
}
1917+
1918+
if (defined(sourceUri)) {
1919+
sourceUri = joinUrls(sourceUri, queryBlob, false);
18981920
}
18991921

19001922
DataSource.setLoading(dataSource, true);
@@ -1973,6 +1995,7 @@ define([
19731995
* @param {String|Object} czml A url or CZML object to be processed.
19741996
* @param {Object} [options] An object with the following properties:
19751997
* @param {String} [options.sourceUri] Overrides the url to use for resolving relative links.
1998+
* @param {Object} [options.query] Key-value pairs which are appended to all URIs in the CZML.
19761999
* @returns {Promise.<CzmlDataSource>} A promise that resolves to the new instance once the data is processed.
19772000
*/
19782001
CzmlDataSource.load = function(czml, options) {

Specs/DataSources/CzmlDataSourceSpec.js

+51-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ defineSuite([
1515
'Core/Iso8601',
1616
'Core/JulianDate',
1717
'Core/loadJson',
18+
'Core/loadWithXhr',
1819
'Core/Math',
1920
'Core/NearFarScalar',
2021
'Core/Quaternion',
@@ -51,6 +52,7 @@ defineSuite([
5152
Iso8601,
5253
JulianDate,
5354
loadJson,
55+
loadWithXhr,
5456
CesiumMath,
5557
NearFarScalar,
5658
Quaternion,
@@ -258,13 +260,13 @@ defineSuite([
258260

259261
it('process loads expected data', function() {
260262
var dataSource = new CzmlDataSource();
261-
dataSource.process(simple, simpleUrl);
263+
dataSource.process(simple);
262264
expect(dataSource.entities.values.length).toEqual(10);
263265
});
264266

265267
it('process loads data on top of existing', function() {
266268
var dataSource = new CzmlDataSource();
267-
dataSource.process(simple, simpleUrl);
269+
dataSource.process(simple);
268270
expect(dataSource.entities.values.length === 10);
269271

270272
dataSource.process(vehicle, vehicleUrl);
@@ -273,7 +275,7 @@ defineSuite([
273275

274276
it('load replaces data', function() {
275277
var dataSource = new CzmlDataSource();
276-
dataSource.process(simple, simpleUrl);
278+
dataSource.process(simple);
277279
expect(dataSource.entities.values.length).toEqual(10);
278280

279281
dataSource.load(vehicle, vehicleUrl);
@@ -554,6 +556,52 @@ defineSuite([
554556
expect(imageProperty.getValue(JulianDate.fromIso8601('2013-01-01T01:00:00Z'))).toEqual(source + 'image2.png');
555557
});
556558

559+
it('appends query to all uri', function() {
560+
var source = 'http://some.url.invalid/';
561+
var packet = {
562+
billboard : {
563+
image : [{
564+
interval : '2013-01-01T00:00:00Z/2013-01-01T01:00:00Z',
565+
uri : 'image.png'
566+
}, {
567+
interval : '2013-01-01T01:00:00Z/2013-01-01T02:00:00Z',
568+
uri : 'image2.png'
569+
}]
570+
}
571+
};
572+
573+
var dataSource = new CzmlDataSource();
574+
dataSource.load(makePacket(packet), {
575+
sourceUri : source,
576+
query : {
577+
token : 34570,
578+
password : "Passw0rd"
579+
}
580+
});
581+
var entity = dataSource.entities.values[0];
582+
var imageProperty = entity.billboard.image;
583+
expect(imageProperty.getValue(JulianDate.fromIso8601('2013-01-01T00:00:00Z'))).toEqual(source + 'image.png' + '?token=34570&password=Passw0rd');
584+
expect(imageProperty.getValue(JulianDate.fromIso8601('2013-01-01T01:00:00Z'))).toEqual(source + 'image2.png' + '?token=34570&password=Passw0rd');
585+
});
586+
587+
it('appends query tokens to source URL', function() {
588+
var dataSource = new CzmlDataSource();
589+
var requestNetworkLink = when.defer();
590+
591+
spyOn(loadWithXhr, 'load').and.callFake(function(url, responseType, method, data, headers, deferred, overrideMimeType) {
592+
requestNetworkLink.resolve(url);
593+
deferred.reject();
594+
});
595+
596+
dataSource.process(simpleUrl, { query : {
597+
"token" : 30203,
598+
"pass" : "passw0rd"
599+
}});
600+
return requestNetworkLink.promise.then(function(url) {
601+
expect(url).toEqual(simpleUrl + '?token=30203&pass=passw0rd');
602+
});
603+
});
604+
557605
it('CZML adds data for constrained billboard.', function() {
558606
var billboardPacket = {
559607
billboard : {

0 commit comments

Comments
 (0)