KML with anchor tags without href attribute fail to load in Cesium 1.42.1

1. A concise explanation of the problem you’re experiencing.

Cesium chokes on KMLs with anchor tags that dont have a href attribute.

The sandcastle writes this message to the console:

TypeError: Unable to get property ‘url’ of undefined or null reference
TypeError: Unable to get property ‘url’ of undefined or null reference

I think this was introduced in this commit:

In this case, resolveHref is returning undefined instead of a Resource. The code is failing because resource is an undefined reference.

  • var uri = resolveHref(value, proxy, sourceUri, query);
  • element.setAttribute(attributeName, uri);
  • var resource = resolveHref(value, sourceResource);
  • element.setAttribute(attributeName, resource.url);

``

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

Please paste the code block into a Sandcastle.The Share button seems to be having issues.

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var options = {

camera : viewer.scene.camera,

canvas : viewer.scene.canvas

};

//sample KML portion of http://dev.openlayers.org/examples/kml/sundials.kml

var kmlDocument = new DOMParser().parseFromString(

‘<?xml version="1.0" encoding="UTF-8"?>’ +

‘’ +

‘’ +

‘Sundial Collection.kmz’ +

‘’ +

‘’ +

‘1.2’ +

‘’ +

http://maps.google.com/mapfiles/kml/shapes/sunny.png’ +

‘’ +

‘’ +

‘’ +

‘’ +

‘ff00aaff’ +

‘’ +

‘’ +

‘’ +

‘Sundial Collection’ +

‘1’ +

‘’ +

‘-56.6884384968692’ +

‘47.91963617483238’ +

‘0’ +

‘9958750.824018393’ +

‘1.303827428939919e-015’ +

‘-16.31426621668193’ +

‘’ +

‘’ +

‘’ +

‘check’ +

‘00ffffff’ +

‘’ +

‘’ +

‘’ +

‘High Resolution’ +

‘’ +

‘Sundial with light conductors - Paris, Les Halles’ +

‘<![CDATA[

<img’ + ‘src=“http://www.home.uni-osnabrueck.de/ahaenel/sonnuhr/paris1.jpg”>

’ +

‘The sunlight falls on one of the three windows in the column (east, south, west) and over light’ + ‘conductors on the wall is indicated.’ +

’ +

‘The clock shows 16,40 o’clock.’ +

’ +

// This is the line of interest

Quelle:http://www.home.uni-osnabrueck.de/ahaenel/sonnuhr/paris_halles.htm’ +

http://perso.orange.fr/cadrans.solaires/cadrans/cadran-halles-paris.html]]>’ +

‘’ +

‘2.344185113917775’ +

‘48.86294270160059’ +

‘0’ +

‘39.52787486507292’ +

‘0’ +

‘-0.003533584730563007’ +

‘’ +

#sn_sunny_copy68’ +

‘’ +

‘2.344143312335305,48.86302323987447,0’ +

‘’ +

‘’ +

‘’ +

‘’ +

‘’ +

‘’, “application/xml”);

//Load the KML object and move camera to point to it.

viewer.flyTo(

viewer.dataSources.add(

Cesium.KmlDataSource.load(kmlDocument, options)

)

);

``

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

I want to load this KML in Cesium. It is a portion of http://dev.openlayers.org/examples/kml/sundials.kml

4. The Cesium version you’re using, your operating system and browser.

Browser: Edge.

OS: Windows 10.

Cesium Version:

** In 1.41, none of the Bing Maps layers load for me. Not quite sure what’s going on here.

It loads in Google Earth.

Thanks for all your help!

Hi B,

Look like the failure is on this line: https://github.com/AnalyticalGraphicsInc/cesium/commit/b68a1e87dfc44db6363d346fcaef6f10acacf6c0#diff-0aabbb637a10ce9c28e4d24c9f73a99eL542

If there is no href property on the tag, the function returns undefined, but it should be returning a new Resource, but with an undefined url.

Sounds like a straightforward fix, would you be interested in contributing it? Community contributions are always encouraged!

Thanks,

Gabby