Skip to content

Commit

Permalink
Thread query through more functions. Update processStyles parameter c…
Browse files Browse the repository at this point in the history
…all. Add unit test
  • Loading branch information
ottaviohartman committed Jun 7, 2017
1 parent f931286 commit 8c6028c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 28 deletions.
3 changes: 1 addition & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Change Log
* 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)
* 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)
* `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)

### 1.34 - 2017-06-01

Expand Down
54 changes: 28 additions & 26 deletions Source/DataSources/KmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,12 @@ define([
}
}
}
if (!hrefResolved && defined(sourceUri)) {
href = getAbsoluteUri(href, getAbsoluteUri(sourceUri));
if (!hrefResolved) {
if (defined(sourceUri)) {
href = getAbsoluteUri(href, getAbsoluteUri(sourceUri));
}
href = proxyUrl(href, proxy, query);
}
href = proxyUrl(href, proxy, query);
return href;
}

Expand Down Expand Up @@ -678,13 +680,13 @@ define([
return href;
}

function processBillboardIcon(dataSource, node, targetEntity, sourceUri, uriResolver) {
function processBillboardIcon(dataSource, node, targetEntity, sourceUri, uriResolver, query) {
var scale = queryNumericValue(node, 'scale', namespaces.kml);
var heading = queryNumericValue(node, 'heading', namespaces.kml);
var color = queryColorValue(node, 'color', namespaces.kml);

var iconNode = queryFirstNode(node, 'Icon', namespaces.kml);
var icon = getIconHref(iconNode, dataSource, sourceUri, uriResolver, false);
var icon = getIconHref(iconNode, dataSource, sourceUri, uriResolver, false, query);
var x = queryNumericValue(iconNode, 'x', namespaces.gx);
var y = queryNumericValue(iconNode, 'y', namespaces.gx);
var w = queryNumericValue(iconNode, 'w', namespaces.gx);
Expand Down Expand Up @@ -753,11 +755,11 @@ define([
}
}

function applyStyle(dataSource, styleNode, targetEntity, sourceUri, uriResolver) {
function applyStyle(dataSource, styleNode, targetEntity, sourceUri, uriResolver, query) {
for (var i = 0, len = styleNode.childNodes.length; i < len; i++) {
var node = styleNode.childNodes.item(i);
if (node.localName === 'IconStyle') {
processBillboardIcon(dataSource, node, targetEntity, sourceUri, uriResolver);
processBillboardIcon(dataSource, node, targetEntity, sourceUri, uriResolver, query);
} else if (node.localName === 'LabelStyle') {
var label = targetEntity.label;
if (!defined(label)) {
Expand Down Expand Up @@ -819,7 +821,7 @@ define([
}

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

Expand All @@ -837,7 +839,7 @@ define([
if (styleIndex !== -1) {
var inlineStyleNode = childNodes[styleIndex];
if (inlineStyleNode.localName === 'Style') {
applyStyle(dataSource, inlineStyleNode, result, sourceUri, uriResolver);
applyStyle(dataSource, inlineStyleNode, result, sourceUri, uriResolver, query);
} else { // StyleMap
var pairs = queryChildNodes(inlineStyleNode, 'Pair', namespaces.kml);
for (var p = 0; p < pairs.length; p++) {
Expand All @@ -855,7 +857,7 @@ define([
}
} else {
var node = queryFirstNode(pair, 'Style', namespaces.kml);
applyStyle(dataSource, node, result, sourceUri, uriResolver);
applyStyle(dataSource, node, result, sourceUri, uriResolver, query);
}
} else {
console.log('KML - Unsupported StyleMap key: ' + key);
Expand Down Expand Up @@ -922,7 +924,7 @@ define([
id : id
});
styleCollection.add(styleEntity);
applyStyle(dataSource, node, styleEntity, sourceUri, uriResolver);
applyStyle(dataSource, node, styleEntity, sourceUri, uriResolver, query);
}
}
}
Expand Down Expand Up @@ -963,7 +965,7 @@ define([
}
} else {
node = queryFirstNode(pair, 'Style', namespaces.kml);
applyStyle(dataSource, node, styleEntity, sourceUri, uriResolver);
applyStyle(dataSource, node, styleEntity, sourceUri, uriResolver, query);
}
}
} else {
Expand Down Expand Up @@ -1552,10 +1554,10 @@ define([
entity.description = tmp;
}

function processFeature(dataSource, parent, featureNode, entityCollection, styleCollection, sourceUri, uriResolver, promises, context) {
function processFeature(dataSource, parent, featureNode, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query) {
var entity = createEntity(featureNode, entityCollection, context);
var kmlData = entity.kml;
var styleEntity = computeFinalStyle(entity, dataSource, featureNode, styleCollection, sourceUri, uriResolver);
var styleEntity = computeFinalStyle(entity, dataSource, featureNode, styleCollection, sourceUri, uriResolver, query);

var name = queryStringValue(featureNode, 'name', namespaces.kml);
entity.name = name;
Expand Down Expand Up @@ -1630,7 +1632,7 @@ define([
Model : processUnsupportedGeometry
};

function processDocument(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context) {
function processDocument(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query) {
var featureTypeNames = Object.keys(featureTypes);
var featureTypeNamesLength = featureTypeNames.length;

Expand All @@ -1644,19 +1646,19 @@ define([
var child = childNodes[q];
if (child.localName === featureName &&
((namespaces.kml.indexOf(child.namespaceURI) !== -1) || (namespaces.gx.indexOf(child.namespaceURI) !== -1))) {
processFeatureNode(dataSource, parent, child, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
processFeatureNode(dataSource, parent, child, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query);
}
}
}
}

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

function processPlacemark(dataSource, parent, placemark, entityCollection, styleCollection, sourceUri, uriResolver, promises, context) {
var r = processFeature(dataSource, parent, placemark, entityCollection, styleCollection, sourceUri, uriResolver, promises, context);
function processPlacemark(dataSource, parent, placemark, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query) {
var r = processFeature(dataSource, parent, placemark, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query);
var entity = r.entity;
var styleEntity = r.styleEntity;

Expand All @@ -1679,8 +1681,8 @@ define([
}
}

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

var geometry;
Expand Down Expand Up @@ -1725,7 +1727,7 @@ define([
}

var iconNode = queryFirstNode(groundOverlay, 'Icon', namespaces.kml);
var href = getIconHref(iconNode, dataSource, sourceUri, uriResolver, true);
var href = getIconHref(iconNode, dataSource, sourceUri, uriResolver, true, query);
if (defined(href)) {
if (isLatLonQuad) {
console.log('KML - gx:LatLonQuad Icon does not support texture projection.');
Expand Down Expand Up @@ -1938,7 +1940,7 @@ define([
}

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 r = processFeature(dataSource, parent, node, entityCollection, styleCollection, sourceUri, uriResolver, promises, context, query);
var networkEntity = r.entity;

var link = queryFirstNode(node, 'Link', namespaces.kml);
Expand Down Expand Up @@ -2110,7 +2112,7 @@ define([
}

var styleCollection = new EntityCollection(dataSource);
return when.all(processStyles(dataSource, kml, styleCollection, sourceUri, false, uriResolver, context)).then(function() {
return when.all(processStyles(dataSource, kml, styleCollection, sourceUri, false, uriResolver, query)).then(function() {
var element = kml.documentElement;
if (element.localName === 'kml') {
var childNodes = element.childNodes;
Expand Down
26 changes: 26 additions & 0 deletions Specs/DataSources/KmlDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,32 @@ defineSuite([
});
});

it('IconStyle: Sets billboard image with query', function() {
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
<Placemark>\
<Style>\
<IconStyle>\
<Icon>\
<href>image.png</href>\
</Icon>\
</IconStyle>\
</Style>\
</Placemark>';
debugger;
return KmlDataSource.load(parser.parseFromString(kml, "text/xml"), {
camera : options.camera,
canvas : options.canvas,
sourceUri : 'http://test.invalid',
query : {
"test": true
}
}).then(function(dataSource) {
var entities = dataSource.entities.values;
var billboard = entities[0].billboard;
expect(billboard.image.getValue()).toEqual('http://test.invalid/image.png?test=true');
});
});

it('IconStyle: Sets billboard image with subregion', function() {
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
<Placemark xmlns="http://www.opengis.net/kml/2.2"\
Expand Down

0 comments on commit 8c6028c

Please sign in to comment.