diff --git a/CHANGES.md b/CHANGES.md index 7848cdd3fb3e..e1bde72eb300 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ Change Log * Fixed translucency bug for certain material types [#5335](https://github.com/AnalyticalGraphicsInc/cesium/pull/5335) * Fix picking polylines that use a depth fail appearance. [#5337](https://github.com/AnalyticalGraphicsInc/cesium/pull/5337) * Fixed a crash when morphing from Columbus view to 3D. [#5311](https://github.com/AnalyticalGraphicsInc/cesium/issues/5311) +* Fixed a bug which prevented KML descriptions with relative paths from loading. [#5352](https://github.com/AnalyticalGraphicsInc/cesium/pull/5352) * Updated documentation for Quaternion.fromHeadingPitchRoll [#5264](https://github.com/AnalyticalGraphicsInc/cesium/issues/5264) ### 1.33 - 2017-05-01 diff --git a/Source/DataSources/KmlDataSource.js b/Source/DataSources/KmlDataSource.js index 0807ee87b7bd..87f00c7f7a35 100644 --- a/Source/DataSources/KmlDataSource.js +++ b/Source/DataSources/KmlDataSource.js @@ -253,7 +253,7 @@ define([ }); } - function replaceAttributes(div, elementType, attributeName, uriResolver) { + function embedDataUris(div, elementType, attributeName, uriResolver) { var keys = uriResolver.keys; var baseUri = new Uri('.'); var elements = div.querySelectorAll(elementType); @@ -272,6 +272,16 @@ define([ } } + function applyBasePath(div, elementType, attributeName, proxy, sourceUri) { + 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); + element.setAttribute(attributeName, uri); + } + } + function proxyUrl(url, proxy) { if (defined(proxy)) { if (new Uri(url).isAbsolute()) { @@ -1431,7 +1441,7 @@ define([ var scratchDiv = document.createElement('div'); - function processDescription(node, entity, styleEntity, uriResolver) { + function processDescription(node, entity, styleEntity, uriResolver, proxy, sourceUri) { var i; var key; var keys; @@ -1516,10 +1526,14 @@ define([ //Rewrite any KMZ embedded urls if (defined(uriResolver) && uriResolver.keys.length > 1) { - replaceAttributes(scratchDiv, 'a', 'href', uriResolver); - replaceAttributes(scratchDiv, 'img', 'src', uriResolver); + embedDataUris(scratchDiv, 'a', 'href', uriResolver); + embedDataUris(scratchDiv, 'img', 'src', uriResolver); } + //Make relative urls absolute using the sourceUri + applyBasePath(scratchDiv, 'a', 'href', proxy, sourceUri); + applyBasePath(scratchDiv, 'img', 'src', proxy, sourceUri); + var tmp = '
\ + \ + ]]>\ + '; + + return KmlDataSource.load(parser.parseFromString(kml, "text/xml"), { + camera : options.camera, + canvas : options.canvas, + sourceUri : 'http://test.invalid' + }).then(function(dataSource) { + var entity = dataSource.entities.values[0]; + + var element = document.createElement('div'); + element.innerHTML = entity.description.getValue(); + + var a = element.firstChild.firstChild; + expect(a.localName).toEqual('img'); + expect(a.getAttribute('src')).toEqual('http://test.invalid/foo/bar.png'); + }); + }); + it('BalloonStyle: description retargets existing links to _blank', function() { var kml = '\ \