From 64106b3e23a52fda1428ab4921e0577ce31a5e6e Mon Sep 17 00:00:00 2001 From: JeremyMarzano-ISPA Date: Thu, 9 Nov 2017 10:03:20 -0500 Subject: [PATCH 01/11] Added a function to remove duplicate namespaces in the KML file --- Source/DataSources/KmlDataSource.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Source/DataSources/KmlDataSource.js b/Source/DataSources/KmlDataSource.js index 9f8388e3a223..52cefd89ce41 100644 --- a/Source/DataSources/KmlDataSource.js +++ b/Source/DataSources/KmlDataSource.js @@ -282,6 +282,26 @@ define([ return text; } + function removeDuplicateNamespaces(text) { + var index = text.indexOf("xmlns:"); + var endDeclaration = text.indexOf(">", index); + var namespace, startIndex, endIndex; + + while ((index !== -1) && (index < endDeclaration)) { + namespace = text.slice(index, text.indexOf("\"", index)); + startIndex = index; + index = text.indexOf(namespace, index + 1); + if (index !== -1) { + endIndex = text.indexOf("\"", (text.indexOf("\"", index) + 1)); + text = text.slice(0, index -1) + text.slice(endIndex + 1, text.length); + } + index = text.indexOf("xmlns:", startIndex + 1); + } + + return text; + } + + function loadXmlFromZip(reader, entry, uriResolver, deferred) { entry.getData(new zip.TextWriter(), function(text) { uriResolver.kml = parser.parseFromString(text, 'application/xml'); @@ -2368,6 +2388,9 @@ define([ //Insert missing namespaces text = insertNamespaces(text); + //Remove Duplicate Namespaces + text = removeDuplicateNamespaces(text); + //IE raises an exception var kml; var error; From 7bb806ca1e5c8271dbb67393031f6cd040be4950 Mon Sep 17 00:00:00 2001 From: JeremyMarzano-ISPA Date: Thu, 9 Nov 2017 11:11:57 -0500 Subject: [PATCH 02/11] Added Unit test and listed the changes and contributor --- CHANGES.md | 1 + CONTRIBUTORS.md | 1 + Specs/Data/KML/duplicateNamespace.kml | 18 +++++++++ Specs/DataSources/KmlDataSourceSpec.js | 53 ++++---------------------- 4 files changed, 28 insertions(+), 45 deletions(-) create mode 100644 Specs/Data/KML/duplicateNamespace.kml diff --git a/CHANGES.md b/CHANGES.md index fa2be9350acc..222bd4a3f846 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ Change Log ### 1.40 - 2017-12-01 * Added ability to support touch event in Imagery Layers Split demo application. [#5948](https://github.com/AnalyticalGraphicsInc/cesium/pull/5948) +* Added function that removes duplicate namespace declarations while loading a KML. [#] () ### 1.39 - 2017-11-01 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index eabe0c63e09f..0832fa8725ea 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -99,6 +99,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu * [Joshua Bernstein](https://github.com/jbernstein/) * [Natanael Rivera](https://github.com/nrivera-Novetta/) * [Justin Burr](https://github.com/jburr-nc/) + * [Jeremy Marzano] (https://github.com/JeremyMarzano-ISPA/) ## [Individual CLA](Documentation/Contributors/CLAs/individual-cla-agi-v1.0.txt) * [Victor Berchet](https://github.com/vicb) diff --git a/Specs/Data/KML/duplicateNamespace.kml b/Specs/Data/KML/duplicateNamespace.kml new file mode 100644 index 000000000000..ca8107d5a335 --- /dev/null +++ b/Specs/Data/KML/duplicateNamespace.kml @@ -0,0 +1,18 @@ + + + + + + image.png]]> + + 1,2,3 + + + + \ No newline at end of file diff --git a/Specs/DataSources/KmlDataSourceSpec.js b/Specs/DataSources/KmlDataSourceSpec.js index d5daecf6fdb3..7f3f2d63f25e 100644 --- a/Specs/DataSources/KmlDataSourceSpec.js +++ b/Specs/DataSources/KmlDataSourceSpec.js @@ -244,20 +244,20 @@ 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); }); }); + it('load deletes duplicate namespace declaration', function() { + var datasource = new KmlDataSource(options); + return datasource.load('Data/KML/duplicateNamespace.kml').then(function(source) { + expect(source).toBe(datasource); + expect(source.entities.values.length).toEqual(1); + }); + }); + it('load rejects loading non-KML URL', function() { return KmlDataSource.load('Data/Images/Blue.png', options).otherwise(function(e) { expect(e).toBeInstanceOf(RuntimeError); @@ -271,42 +271,6 @@ defineSuite([ }); }); - it('if load contains tag with no image included, no image is added', function() { - var dataSource = new KmlDataSource(options); - return loadBlob('Data/KML/simpleNoIcon.kml').then(function(blob) { - return dataSource.load(blob); - }).then(function(source) { - expect(source.entities); - expect(source.entities.values.length).toEqual(1); - expect(source.entities._entities._array.length).toEqual(1); - expect(source.entities._entities._array[0]._billboard._image).toBeUndefined(); - }); - }); - - it('if load does not contain icon