Skip to content

Commit

Permalink
Merge branch 'master' into invert-classification
Browse files Browse the repository at this point in the history
  • Loading branch information
bagnell committed Oct 18, 2017
2 parents 87289df + 9b912da commit c4e886f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Change Log
==========
### 1.39 - 2017-11-01

* Added function that inserts missing namespace declarations into KML files. [#5860](https://github.com/AnalyticalGraphicsInc/cesium/pull/5860)
* Added support for the layer.json `parentUrl` property in `CesiumTerrainProvider` to allow for compositing of tilesets.
* Fixed a bug that caused KML ground overlays to appear distorted when rotation was applied. [#5914](https://github.com/AnalyticalGraphicsInc/cesium/issues/5914)
* Adds `invertClassification` and `invertClassificationColor` to `Scene`. When `invertClassification` is `true`, any 3D Tiles geometry that is not classified by a `ClassificationPrimitive` or `GroundPrimitive` will have its color multiplied by `invertClassificationColor`. [#5836](https://github.com/AnalyticalGraphicsInc/cesium/pull/5836)
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
* [Logilab](https://www.logilab.fr/)
* [Florent Cayré](https://github.com/fcayre/)
* [Novetta](http://www.novetta.com/)
* [Natanael Rivera](https://github.com/nrivera-Novetta/)
* [Justin Burr](https://github.com/jburr-nc/)

## [Individual CLA](Documentation/Contributors/CLAs/individual-cla-agi-v1.0.txt)
Expand Down
30 changes: 30 additions & 0 deletions Source/DataSources/KmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,33 @@ define([
return deferred.promise;
}

function insertNamespaces(text) {
var namespaceMap = {
xsi : 'http://www.w3.org/2001/XMLSchema-instance'
};
var firstPart, lastPart, reg, declaration;

for (var key in namespaceMap) {
if (namespaceMap.hasOwnProperty(key)) {
reg = RegExp('[< ]' + key + ':');
declaration = 'xmlns:' + key + '=';
if (reg.test(text) && text.indexOf(declaration) === -1) {
if (!defined(firstPart)) {
firstPart = text.substr(0, text.indexOf('<kml') + 4);
lastPart = text.substr(firstPart.length);
}
firstPart += ' ' + declaration + '"' + namespaceMap[key] + '"';
}
}
}

if (defined(firstPart)) {
text = firstPart + lastPart;
}

return text;
}

function loadXmlFromZip(reader, entry, uriResolver, deferred) {
entry.getData(new zip.TextWriter(), function(text) {
uriResolver.kml = parser.parseFromString(text, 'application/xml');
Expand Down Expand Up @@ -2324,6 +2351,9 @@ define([
//There's no official way to validate if a parse was successful.
//The following check detects the error on various browsers.

//Insert missing namespaces
text = insertNamespaces(text);

//IE raises an exception
var kml;
var error;
Expand Down
18 changes: 18 additions & 0 deletions Specs/Data/KML/undeclaredNamespaces.kml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd http://www.google.com/kml/ext/2.2 http://code.google.com/apis/kml/schema/kml22gx.xsd">
<Placemark>
<Style>
<IconStyle>
<Icon>
<href>image.png</href>
</Icon>
</IconStyle>
</Style>
<description><![CDATA[image.png <a href="./image.png">image.png</a><img src="image.png"/>]]></description>
<Point>
<coordinates>1,2,3</coordinates>
</Point>
</Placemark>
</Document>
</kml>
8 changes: 8 additions & 0 deletions Specs/DataSources/KmlDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ defineSuite([
});
});

it('load inserts missing namespace declaration', function() {
var dataSource = new KmlDataSource(options);
return dataSource.load('Data/KML/undeclaredNamespaces.kml').then(function(source) {
expect(source).toBe(dataSource);
expect(source.entities.values.length).toEqual(1);
});
});

it('load rejects nonexistent URL', function() {
return KmlDataSource.load('test.invalid', options).otherwise(function(e) {
expect(e).toBeInstanceOf(RequestErrorEvent);
Expand Down

0 comments on commit c4e886f

Please sign in to comment.