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

47 views
Skip to first unread message

B

unread,
Mar 28, 2018, 2:12:25 PM3/28/18
to cesium-dev
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
};

var kmlDocument = new DOMParser().parseFromString(
    '<?xml version="1.0" encoding="UTF-8"?>' +
'<Document>' +
'<name>Sundial Collection.kmz</name>' +
'<Style id="sn_sunny_copy68">' +
'<IconStyle>' +
'<scale>1.2</scale>' +
'<Icon>' +
'</Icon>' +
'<hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>' +
'</IconStyle>' +
'<LabelStyle>' +
'<color>ff00aaff</color>' +
'</LabelStyle>' +
'</Style>' +
'<Folder>' +
'<name>Sundial Collection</name>' +
'<open>1</open>' +
'<LookAt>' +
'<longitude>-56.6884384968692</longitude>' +
'<latitude>47.91963617483238</latitude>' +
'<altitude>0</altitude>' +
'<range>9958750.824018393</range>' +
'<tilt>1.303827428939919e-015</tilt>' +
'<heading>-16.31426621668193</heading>' +
'</LookAt>' +
'<Style>' +
'<ListStyle>' +
'<listItemType>check</listItemType>' +
'<bgColor>00ffffff</bgColor>' +
'</ListStyle>' +
'</Style>' +
'<Folder>' +
'<name>High Resolution</name>' +
'<Placemark>' +
'<name>Sundial with light conductors - Paris, Les Halles</name>' +
'<description><![CDATA[<p><img' + 'src="http://www.home.uni-osnabrueck.de/ahaenel/sonnuhr/paris1.jpg"></p>' +

'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

'<LookAt>' +
'<longitude>2.344185113917775</longitude>' +
'<latitude>48.86294270160059</latitude>' +
'<altitude>0</altitude>' +
'<range>39.52787486507292</range>' +
'<tilt>0</tilt>' +
'<heading>-0.003533584730563007</heading>' +
'</LookAt>' +
'<styleUrl>#sn_sunny_copy68</styleUrl>' +
'<Point>' +
'<coordinates>2.344143312335305,48.86302323987447,0</coordinates>' +
'</Point>' +
'</Placemark>' +
'</Folder>' +
'</Folder>' +
'</Document>' +
'</kml>', "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!

Gabby Getz

unread,
Mar 29, 2018, 5:37:34 PM3/29/18
to cesium-dev
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
Reply all
Reply to author
Forward
0 new messages