Skip to content

Commit 94ecd9d

Browse files
authored
Merge pull request #5434 from omh1280/kml_query
Add `options.query` to KMLDataSource
2 parents 4d3cd8e + acfaa9f commit 94ecd9d

File tree

3 files changed

+283
-46
lines changed

3 files changed

+283
-46
lines changed

CHANGES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Change Log
99
* Fixed a bug where picking clusters would return undefined instead of a list of the clustered entities. [#5286](https://github.com/AnalyticalGraphicsInc/cesium/issues/5286)
1010
* Reduced the amount of Sun bloom post-process effect near the horizon. [#5381](https://github.com/AnalyticalGraphicsInc/cesium/issues/5381)
1111
* Added Sandcastle demo for ArcticDEM data. [#5224](https://github.com/AnalyticalGraphicsInc/cesium/issues/5224)
12+
* `CzmlDataSource` and `KmlDataSource` load functions now take an optional `query` object, which will append query parameters to all network requests. [#5419](https://github.com/AnalyticalGraphicsInc/cesium/pull/5419), [#5434](https://github.com/AnalyticalGraphicsInc/cesium/pull/5434)
1213
* Fixed geocoder bug so geocoder can accurately handle NSEW inputs [#5407] (https://github.com/AnalyticalGraphicsInc/cesium/pull/5407)
13-
* `CzmlDataSource` load functions now take an optional `query` object, which will append query parameters to all network requests. [#5419](https://github.com/AnalyticalGraphicsInc/cesium/pull/5419)
1414

1515
### 1.34 - 2017-06-01
1616

Source/DataSources/KmlDataSource.js

+55-45
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ define([
2525
'../Core/loadXML',
2626
'../Core/Math',
2727
'../Core/NearFarScalar',
28+
'../Core/objectToQuery',
2829
'../Core/PinBuilder',
2930
'../Core/PolygonHierarchy',
3031
'../Core/Rectangle',
@@ -84,6 +85,7 @@ define([
8485
loadXML,
8586
CesiumMath,
8687
NearFarScalar,
88+
objectToQuery,
8789
PinBuilder,
8890
PolygonHierarchy,
8991
Rectangle,
@@ -272,22 +274,25 @@ define([
272274
}
273275
}
274276

275-
function applyBasePath(div, elementType, attributeName, proxy, sourceUri) {
277+
function applyBasePath(div, elementType, attributeName, proxy, sourceUri, query) {
276278
var elements = div.querySelectorAll(elementType);
277279
for (var i = 0; i < elements.length; i++) {
278280
var element = elements[i];
279281
var value = element.getAttribute(attributeName);
280-
var uri = resolveHref(value, proxy, sourceUri);
282+
var uri = resolveHref(value, proxy, sourceUri, query);
281283
element.setAttribute(attributeName, uri);
282284
}
283285
}
284286

285-
function proxyUrl(url, proxy) {
287+
function proxyUrl(url, proxy, query) {
286288
if (defined(proxy)) {
287289
if (new Uri(url).isAbsolute()) {
288290
url = proxy.getURL(url);
289291
}
290292
}
293+
if (defined(query)) {
294+
url = joinUrls(url, '?' + query, false);
295+
}
291296
return url;
292297
}
293298

@@ -467,7 +472,7 @@ define([
467472
return undefined;
468473
}
469474

470-
function resolveHref(href, proxy, sourceUri, uriResolver) {
475+
function resolveHref(href, proxy, sourceUri, uriResolver, query) {
471476
if (!defined(href)) {
472477
return undefined;
473478
}
@@ -487,9 +492,11 @@ define([
487492
}
488493
}
489494
}
490-
if (!hrefResolved && defined(sourceUri)) {
491-
href = getAbsoluteUri(href, getAbsoluteUri(sourceUri));
492-
href = proxyUrl(href, proxy);
495+
if (!hrefResolved) {
496+
if (defined(sourceUri)) {
497+
href = getAbsoluteUri(href, getAbsoluteUri(sourceUri));
498+
}
499+
href = proxyUrl(href, proxy, query);
493500
}
494501
return href;
495502
}
@@ -630,7 +637,7 @@ define([
630637
return label;
631638
}
632639

633-
function getIconHref(iconNode, dataSource, sourceUri, uriResolver, canRefresh) {
640+
function getIconHref(iconNode, dataSource, sourceUri, uriResolver, canRefresh, query) {
634641
var href = queryStringValue(iconNode, 'href', namespaces.kml);
635642
if (!defined(href) || (href.length === 0)) {
636643
return undefined;
@@ -649,7 +656,7 @@ define([
649656
href = 'https://maps.google.com/mapfiles/kml/pal' + palette + '/icon' + iconNum + '.png';
650657
}
651658

652-
href = resolveHref(href, dataSource._proxy, sourceUri, uriResolver);
659+
href = resolveHref(href, dataSource._proxy, sourceUri, uriResolver, query);
653660

654661
if (canRefresh) {
655662
var refreshMode = queryStringValue(iconNode, 'refreshMode', namespaces.kml);
@@ -673,13 +680,13 @@ define([
673680
return href;
674681
}
675682

676-
function processBillboardIcon(dataSource, node, targetEntity, sourceUri, uriResolver) {
683+
function processBillboardIcon(dataSource, node, targetEntity, sourceUri, uriResolver, query) {
677684
var scale = queryNumericValue(node, 'scale', namespaces.kml);
678685
var heading = queryNumericValue(node, 'heading', namespaces.kml);
679686
var color = queryColorValue(node, 'color', namespaces.kml);
680687

681688
var iconNode = queryFirstNode(node, 'Icon', namespaces.kml);
682-
var icon = getIconHref(iconNode, dataSource, sourceUri, uriResolver, false);
689+
var icon = getIconHref(iconNode, dataSource, sourceUri, uriResolver, false, query);
683690
var x = queryNumericValue(iconNode, 'x', namespaces.gx);
684691
var y = queryNumericValue(iconNode, 'y', namespaces.gx);
685692
var w = queryNumericValue(iconNode, 'w', namespaces.gx);
@@ -748,11 +755,11 @@ define([
748755
}
749756
}
750757

751-
function applyStyle(dataSource, styleNode, targetEntity, sourceUri, uriResolver) {
758+
function applyStyle(dataSource, styleNode, targetEntity, sourceUri, uriResolver, query) {
752759
for (var i = 0, len = styleNode.childNodes.length; i < len; i++) {
753760
var node = styleNode.childNodes.item(i);
754761
if (node.localName === 'IconStyle') {
755-
processBillboardIcon(dataSource, node, targetEntity, sourceUri, uriResolver);
762+
processBillboardIcon(dataSource, node, targetEntity, sourceUri, uriResolver, query);
756763
} else if (node.localName === 'LabelStyle') {
757764
var label = targetEntity.label;
758765
if (!defined(label)) {
@@ -814,7 +821,7 @@ define([
814821
}
815822

816823
//Processes and merges any inline styles for the provided node into the provided entity.
817-
function computeFinalStyle(entity, dataSource, placeMark, styleCollection, sourceUri, uriResolver) {
824+
function computeFinalStyle(entity, dataSource, placeMark, styleCollection, sourceUri, uriResolver, query) {
818825
var result = new Entity();
819826
var styleEntity;
820827

@@ -832,7 +839,7 @@ define([
832839
if (styleIndex !== -1) {
833840
var inlineStyleNode = childNodes[styleIndex];
834841
if (inlineStyleNode.localName === 'Style') {
835-
applyStyle(dataSource, inlineStyleNode, result, sourceUri, uriResolver);
842+
applyStyle(dataSource, inlineStyleNode, result, sourceUri, uriResolver, query);
836843
} else { // StyleMap
837844
var pairs = queryChildNodes(inlineStyleNode, 'Pair', namespaces.kml);
838845
for (var p = 0; p < pairs.length; p++) {
@@ -850,7 +857,7 @@ define([
850857
}
851858
} else {
852859
var node = queryFirstNode(pair, 'Style', namespaces.kml);
853-
applyStyle(dataSource, node, result, sourceUri, uriResolver);
860+
applyStyle(dataSource, node, result, sourceUri, uriResolver, query);
854861
}
855862
} else {
856863
console.log('KML - Unsupported StyleMap key: ' + key);
@@ -885,8 +892,8 @@ define([
885892
}
886893

887894
//Asynchronously processes an external style file.
888-
function processExternalStyles(dataSource, uri, styleCollection) {
889-
return loadXML(proxyUrl(uri, dataSource._proxy)).then(function(styleKml) {
895+
function processExternalStyles(dataSource, uri, styleCollection, query) {
896+
return loadXML(proxyUrl(uri, dataSource._proxy, query)).then(function(styleKml) {
890897
return processStyles(dataSource, styleKml, styleCollection, uri, true);
891898
});
892899
}
@@ -895,7 +902,7 @@ define([
895902
//their id into the provided styleCollection.
896903
//Returns an array of promises that will resolve when
897904
//each style is loaded.
898-
function processStyles(dataSource, kml, styleCollection, sourceUri, isExternal, uriResolver) {
905+
function processStyles(dataSource, kml, styleCollection, sourceUri, isExternal, uriResolver, query) {
899906
var i;
900907
var id;
901908
var styleEntity;
@@ -917,7 +924,7 @@ define([
917924
id : id
918925
});
919926
styleCollection.add(styleEntity);
920-
applyStyle(dataSource, node, styleEntity, sourceUri, uriResolver);
927+
applyStyle(dataSource, node, styleEntity, sourceUri, uriResolver, query);
921928
}
922929
}
923930
}
@@ -958,7 +965,7 @@ define([
958965
}
959966
} else {
960967
node = queryFirstNode(pair, 'Style', namespaces.kml);
961-
applyStyle(dataSource, node, styleEntity, sourceUri, uriResolver);
968+
applyStyle(dataSource, node, styleEntity, sourceUri, uriResolver, query);
962969
}
963970
}
964971
} else {
@@ -987,7 +994,7 @@ define([
987994
if (defined(sourceUri)) {
988995
uri = getAbsoluteUri(uri, getAbsoluteUri(sourceUri));
989996
}
990-
promises.push(processExternalStyles(dataSource, uri, styleCollection, sourceUri));
997+
promises.push(processExternalStyles(dataSource, uri, styleCollection, query));
991998
}
992999
}
9931000
}
@@ -1547,10 +1554,10 @@ define([
15471554
entity.description = tmp;
15481555
}
15491556

1550-
function processFeature(dataSource, parent, featureNode, entityCollection, styleCollection, sourceUri, uriResolver, promises, context) {
1557+
function processFeature(dataSource, parent, featureNode, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query) {
15511558
var entity = createEntity(featureNode, entityCollection, context);
15521559
var kmlData = entity.kml;
1553-
var styleEntity = computeFinalStyle(entity, dataSource, featureNode, styleCollection, sourceUri, uriResolver);
1560+
var styleEntity = computeFinalStyle(entity, dataSource, featureNode, styleCollection, sourceUri, uriResolver, query);
15541561

15551562
var name = queryStringValue(featureNode, 'name', namespaces.kml);
15561563
entity.name = name;
@@ -1625,7 +1632,7 @@ define([
16251632
Model : processUnsupportedGeometry
16261633
};
16271634

1628-
function processDocument(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context) {
1635+
function processDocument(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query) {
16291636
var featureTypeNames = Object.keys(featureTypes);
16301637
var featureTypeNamesLength = featureTypeNames.length;
16311638

@@ -1639,19 +1646,19 @@ define([
16391646
var child = childNodes[q];
16401647
if (child.localName === featureName &&
16411648
((namespaces.kml.indexOf(child.namespaceURI) !== -1) || (namespaces.gx.indexOf(child.namespaceURI) !== -1))) {
1642-
processFeatureNode(dataSource, parent, child, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
1649+
processFeatureNode(dataSource, parent, child, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query);
16431650
}
16441651
}
16451652
}
16461653
}
16471654

1648-
function processFolder(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context) {
1649-
var r = processFeature(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
1650-
processDocument(dataSource, r.entity, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
1655+
function processFolder(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query) {
1656+
var r = processFeature(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query);
1657+
processDocument(dataSource, r.entity, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query);
16511658
}
16521659

1653-
function processPlacemark(dataSource, parent, placemark, entityCollection, styleCollection, sourceUri, uriResolver, promises, context) {
1654-
var r = processFeature(dataSource, parent, placemark, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
1660+
function processPlacemark(dataSource, parent, placemark, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query) {
1661+
var r = processFeature(dataSource, parent, placemark, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query);
16551662
var entity = r.entity;
16561663
var styleEntity = r.styleEntity;
16571664

@@ -1674,8 +1681,8 @@ define([
16741681
}
16751682
}
16761683

1677-
function processGroundOverlay(dataSource, parent, groundOverlay, entityCollection, styleCollection, sourceUri, uriResolver, promises, context) {
1678-
var r = processFeature(dataSource, parent, groundOverlay, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
1684+
function processGroundOverlay(dataSource, parent, groundOverlay, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query) {
1685+
var r = processFeature(dataSource, parent, groundOverlay, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query);
16791686
var entity = r.entity;
16801687

16811688
var geometry;
@@ -1720,7 +1727,7 @@ define([
17201727
}
17211728

17221729
var iconNode = queryFirstNode(groundOverlay, 'Icon', namespaces.kml);
1723-
var href = getIconHref(iconNode, dataSource, sourceUri, uriResolver, true);
1730+
var href = getIconHref(iconNode, dataSource, sourceUri, uriResolver, true, query);
17241731
if (defined(href)) {
17251732
if (isLatLonQuad) {
17261733
console.log('KML - gx:LatLonQuad Icon does not support texture projection.');
@@ -1932,8 +1939,8 @@ define([
19321939
return queryString;
19331940
}
19341941

1935-
function processNetworkLink(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context) {
1936-
var r = processFeature(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
1942+
function processNetworkLink(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query) {
1943+
var r = processFeature(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query);
19371944
var networkEntity = r.entity;
19381945

19391946
var link = queryFirstNode(node, 'Link', namespaces.kml);
@@ -1945,7 +1952,7 @@ define([
19451952
var href = queryStringValue(link, 'href', namespaces.kml);
19461953
if (defined(href)) {
19471954
var newSourceUri = href;
1948-
href = resolveHref(href, undefined, sourceUri, uriResolver);
1955+
href = resolveHref(href, undefined, sourceUri, uriResolver, query);
19491956
var linkUrl;
19501957

19511958
// We need to pass in the original path if resolveHref returns a data uri because the network link
@@ -2079,16 +2086,16 @@ define([
20792086
Tour : processUnsupportedFeature
20802087
};
20812088

2082-
function processFeatureNode(dataSource, node, parent, entityCollection, styleCollection, sourceUri, uriResolver, promises, context) {
2089+
function processFeatureNode(dataSource, node, parent, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query) {
20832090
var featureProcessor = featureTypes[node.localName];
20842091
if (defined(featureProcessor)) {
2085-
featureProcessor(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
2092+
featureProcessor(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query);
20862093
} else {
20872094
processUnsupportedFeature(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
20882095
}
20892096
}
20902097

2091-
function loadKml(dataSource, entityCollection, kml, sourceUri, uriResolver, context) {
2098+
function loadKml(dataSource, entityCollection, kml, sourceUri, uriResolver, context, query) {
20922099
entityCollection.removeAll();
20932100

20942101
var promises = [];
@@ -2105,7 +2112,7 @@ define([
21052112
}
21062113

21072114
var styleCollection = new EntityCollection(dataSource);
2108-
return when.all(processStyles(dataSource, kml, styleCollection, sourceUri, false, uriResolver, context)).then(function() {
2115+
return when.all(processStyles(dataSource, kml, styleCollection, sourceUri, false, uriResolver, query)).then(function() {
21092116
var element = kml.documentElement;
21102117
if (element.localName === 'kml') {
21112118
var childNodes = element.childNodes;
@@ -2118,7 +2125,7 @@ define([
21182125
}
21192126
}
21202127
entityCollection.suspendEvents();
2121-
processFeatureNode(dataSource, element, undefined, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
2128+
processFeatureNode(dataSource, element, undefined, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query);
21222129
entityCollection.resumeEvents();
21232130

21242131
return when.all(promises).then(function() {
@@ -2187,10 +2194,11 @@ define([
21872194
var sourceUri = options.sourceUri;
21882195
var uriResolver = options.uriResolver;
21892196
var context = options.context;
2197+
var query = defined(options.query) ? objectToQuery(options.query) : undefined;
21902198

21912199
var promise = data;
21922200
if (typeof data === 'string') {
2193-
promise = loadBlob(proxyUrl(data, dataSource._proxy));
2201+
promise = loadBlob(proxyUrl(data, dataSource._proxy, query));
21942202
sourceUri = defaultValue(sourceUri, data);
21952203
}
21962204

@@ -2228,11 +2236,11 @@ define([
22282236
//Return the error
22292237
throw new RuntimeError(msg);
22302238
}
2231-
return loadKml(dataSource, entityCollection, kml, sourceUri, uriResolver, context);
2239+
return loadKml(dataSource, entityCollection, kml, sourceUri, uriResolver, context, query);
22322240
});
22332241
});
22342242
} else {
2235-
return loadKml(dataSource, entityCollection, dataToLoad, sourceUri, uriResolver, context);
2243+
return loadKml(dataSource, entityCollection, dataToLoad, sourceUri, uriResolver, context, query);
22362244
}
22372245
})
22382246
.otherwise(function(error) {
@@ -2327,6 +2335,7 @@ define([
23272335
* @param {DefaultProxy} [options.proxy] A proxy to be used for loading external data.
23282336
* @param {String} [options.sourceUri] Overrides the url to use for resolving relative links and other KML network features.
23292337
* @param {Boolean} [options.clampToGround=false] true if we want the geometry features (Polygons, LineStrings and LinearRings) clamped to the ground. If true, lines will use corridors so use Entity.corridor instead of Entity.polyline.
2338+
* @param {Object} [options.query] Key-value pairs which are appended to all URIs in the CZML.
23302339
*
23312340
* @returns {Promise.<KmlDataSource>} A promise that will resolve to a new KmlDataSource instance once the KML is loaded.
23322341
*/
@@ -2473,6 +2482,7 @@ define([
24732482
* @param {Number} [options.sourceUri] Overrides the url to use for resolving relative links and other KML network features.
24742483
* @returns {Promise.<KmlDataSource>} A promise that will resolve to this instances once the KML is loaded.
24752484
* @param {Boolean} [options.clampToGround=false] true if we want the geometry features (Polygons, LineStrings and LinearRings) clamped to the ground. If true, lines will use corridors so use Entity.corridor instead of Entity.polyline.
2485+
* @param {Object} [options.query] Key-value pairs which are appended to all URIs in the CZML.
24762486
*/
24772487
KmlDataSource.prototype.load = function(data, options) {
24782488
//>>includeStart('debug', pragmas.debug);

0 commit comments

Comments
 (0)