Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options.query to KMLDataSource #5434

Merged
merged 5 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Change Log
* Reduced the amount of Sun bloom post-process effect near the horizon. [#5381](https://github.com/AnalyticalGraphicsInc/cesium/issues/5381)
* Added Sandcastle demo for ArcticDEM data. [#5224](https://github.com/AnalyticalGraphicsInc/cesium/issues/5224)
* `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)
* `KmlDataSource` load functions now take an optional `query` object. which will append query parameters to all network requests. [#5434](https://github.com/AnalyticalGraphicsInc/cesium/pull/5434)

### 1.34 - 2017-06-01

Expand Down
48 changes: 28 additions & 20 deletions Source/DataSources/KmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ define([
'../Core/loadXML',
'../Core/Math',
'../Core/NearFarScalar',
'../Core/objectToQuery',
'../Core/PinBuilder',
'../Core/PolygonHierarchy',
'../Core/Rectangle',
Expand Down Expand Up @@ -84,6 +85,7 @@ define([
loadXML,
CesiumMath,
NearFarScalar,
objectToQuery,
PinBuilder,
PolygonHierarchy,
Rectangle,
Expand Down Expand Up @@ -272,22 +274,25 @@ define([
}
}

function applyBasePath(div, elementType, attributeName, proxy, sourceUri) {
function applyBasePath(div, elementType, attributeName, proxy, sourceUri, query) {
var elements = div.querySelectorAll(elementType);
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
var value = element.getAttribute(attributeName);
var uri = resolveHref(value, proxy, sourceUri);
var uri = resolveHref(value, proxy, sourceUri, query);
element.setAttribute(attributeName, uri);
}
}

function proxyUrl(url, proxy) {
function proxyUrl(url, proxy, query) {
if (defined(proxy)) {
if (new Uri(url).isAbsolute()) {
url = proxy.getURL(url);
}
}
if (defined(query)) {
url = joinUrls(url, '?' + query, false);
}
return url;
}

Expand Down Expand Up @@ -467,7 +472,7 @@ define([
return undefined;
}

function resolveHref(href, proxy, sourceUri, uriResolver) {
function resolveHref(href, proxy, sourceUri, uriResolver, query) {
if (!defined(href)) {
return undefined;
}
Expand All @@ -489,8 +494,8 @@ define([
}
if (!hrefResolved && defined(sourceUri)) {
href = getAbsoluteUri(href, getAbsoluteUri(sourceUri));
href = proxyUrl(href, proxy);
}
href = proxyUrl(href, proxy, query);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be inside of an if (!hrefResolved) block, so adjust the original logic to handle that. Basically, if hrefResolved is true at this point, it means that the item is a data or blob uri, which means we can't/shouldn't append query parameters to it.

return href;
}

Expand Down Expand Up @@ -630,7 +635,7 @@ define([
return label;
}

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

href = resolveHref(href, dataSource._proxy, sourceUri, uriResolver);
href = resolveHref(href, dataSource._proxy, sourceUri, uriResolver, query);

if (canRefresh) {
var refreshMode = queryStringValue(iconNode, 'refreshMode', namespaces.kml);
Expand Down Expand Up @@ -885,8 +890,8 @@ define([
}

//Asynchronously processes an external style file.
function processExternalStyles(dataSource, uri, styleCollection) {
return loadXML(proxyUrl(uri, dataSource._proxy)).then(function(styleKml) {
function processExternalStyles(dataSource, uri, styleCollection, query) {
return loadXML(proxyUrl(uri, dataSource._proxy, query)).then(function(styleKml) {
return processStyles(dataSource, styleKml, styleCollection, uri, true);
});
}
Expand All @@ -895,7 +900,7 @@ define([
//their id into the provided styleCollection.
//Returns an array of promises that will resolve when
//each style is loaded.
function processStyles(dataSource, kml, styleCollection, sourceUri, isExternal, uriResolver) {
function processStyles(dataSource, kml, styleCollection, sourceUri, isExternal, uriResolver, query) {
var i;
var id;
var styleEntity;
Expand Down Expand Up @@ -987,7 +992,7 @@ define([
if (defined(sourceUri)) {
uri = getAbsoluteUri(uri, getAbsoluteUri(sourceUri));
}
promises.push(processExternalStyles(dataSource, uri, styleCollection, sourceUri));
promises.push(processExternalStyles(dataSource, uri, styleCollection, query));
}
}
}
Expand Down Expand Up @@ -1932,7 +1937,7 @@ define([
return queryString;
}

function processNetworkLink(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context) {
function processNetworkLink(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query) {
var r = processFeature(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
var networkEntity = r.entity;

Expand All @@ -1945,7 +1950,7 @@ define([
var href = queryStringValue(link, 'href', namespaces.kml);
if (defined(href)) {
var newSourceUri = href;
href = resolveHref(href, undefined, sourceUri, uriResolver);
href = resolveHref(href, undefined, sourceUri, uriResolver, query);
var linkUrl;

// We need to pass in the original path if resolveHref returns a data uri because the network link
Expand Down Expand Up @@ -2079,16 +2084,16 @@ define([
Tour : processUnsupportedFeature
};

function processFeatureNode(dataSource, node, parent, entityCollection, styleCollection, sourceUri, uriResolver, promises, context) {
function processFeatureNode(dataSource, node, parent, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query) {
var featureProcessor = featureTypes[node.localName];
if (defined(featureProcessor)) {
featureProcessor(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
featureProcessor(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query);
} else {
processUnsupportedFeature(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
}
}

function loadKml(dataSource, entityCollection, kml, sourceUri, uriResolver, context) {
function loadKml(dataSource, entityCollection, kml, sourceUri, uriResolver, context, query) {
entityCollection.removeAll();

var promises = [];
Expand Down Expand Up @@ -2118,7 +2123,7 @@ define([
}
}
entityCollection.suspendEvents();
processFeatureNode(dataSource, element, undefined, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
processFeatureNode(dataSource, element, undefined, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query);
entityCollection.resumeEvents();

return when.all(promises).then(function() {
Expand Down Expand Up @@ -2187,10 +2192,11 @@ define([
var sourceUri = options.sourceUri;
var uriResolver = options.uriResolver;
var context = options.context;
var query = defined(options.query) ? objectToQuery(options.query) : undefined;

var promise = data;
if (typeof data === 'string') {
promise = loadBlob(proxyUrl(data, dataSource._proxy));
promise = loadBlob(proxyUrl(data, dataSource._proxy, query));
sourceUri = defaultValue(sourceUri, data);
}

Expand Down Expand Up @@ -2228,11 +2234,11 @@ define([
//Return the error
throw new RuntimeError(msg);
}
return loadKml(dataSource, entityCollection, kml, sourceUri, uriResolver, context);
return loadKml(dataSource, entityCollection, kml, sourceUri, uriResolver, context, query);
});
});
} else {
return loadKml(dataSource, entityCollection, dataToLoad, sourceUri, uriResolver, context);
return loadKml(dataSource, entityCollection, dataToLoad, sourceUri, uriResolver, context, query);
}
})
.otherwise(function(error) {
Expand Down Expand Up @@ -2327,6 +2333,7 @@ define([
* @param {DefaultProxy} [options.proxy] A proxy to be used for loading external data.
* @param {String} [options.sourceUri] Overrides the url to use for resolving relative links and other KML network features.
* @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.
* @param {Object} [options.query] Key-value pairs which are appended to all URIs in the CZML.
*
* @returns {Promise.<KmlDataSource>} A promise that will resolve to a new KmlDataSource instance once the KML is loaded.
*/
Expand Down Expand Up @@ -2473,6 +2480,7 @@ define([
* @param {Number} [options.sourceUri] Overrides the url to use for resolving relative links and other KML network features.
* @returns {Promise.<KmlDataSource>} A promise that will resolve to this instances once the KML is loaded.
* @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.
* @param {Object} [options.query] Key-value pairs which are appended to all URIs in the CZML.
*/
KmlDataSource.prototype.load = function(data, options) {
//>>includeStart('debug', pragmas.debug);
Expand Down
Loading