Skip to content

Commit

Permalink
Merge pull request #2945 from AnalyticalGraphicsInc/kml-non-feature-c…
Browse files Browse the repository at this point in the history
…hildren

Don't assume the first element of the KML node is the root feature
  • Loading branch information
pjcozzi committed Aug 18, 2015
2 parents bf9df35 + a494d60 commit acd9d33
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Change Log
* Deprecated
*
* Fix issue where extruded `PolygonGeometry` was always extruding to the ellipsoid surface instead of specified height.
* Fix an issue where non-feature nodes prevented KML documents from loading. [#2945](https://github.com/AnalyticalGraphicsInc/cesium/pull/2945).

### 1.12 - 2015-08-03

Expand Down
9 changes: 8 additions & 1 deletion Source/DataSources/KmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,14 @@ define([
return when.all(processStyles(dataSource, kml, styleCollection, sourceUri, false, uriResolver), function() {
var element = kml.documentElement;
if (element.localName === 'kml') {
element = element.firstElementChild;
var childNodes = element.childNodes;
for (var i = 0; i < childNodes.length; i++) {
var tmp = childNodes[i];
if (defined(featureTypes[tmp.localName])) {
element = tmp;
break;
}
}
}
processFeatureNode(dataSource, element, undefined, entityCollection, styleCollection, sourceUri, uriResolver);

Expand Down
18 changes: 18 additions & 0 deletions Specs/DataSources/KmlDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2833,4 +2833,22 @@ defineSuite([
expect(entity.polygon.perPositionHeight.getValue()).toEqual(true);
});
});

it('Properly finds the root feature node when it is not the first child of the KML node', function() {
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
<kml xmlns="http://www.opengis.net/kml/2.2">\
<NetworkLinkControl>\
</NetworkLinkControl>\
<Placemark>\
<name>bob</name>\
</Placemark>\
</kml>';

return KmlDataSource.load(parser.parseFromString(kml, "text/xml")).then(function(dataSource) {
var entity = dataSource.entities.values[0];
expect(entity.name).toBe('bob');
expect(entity.label).toBeDefined();
expect(entity.label.text.getValue()).toBe('bob');
});
});
});

0 comments on commit acd9d33

Please sign in to comment.