KmlDataResource

Hi, I need to get a layer handler of the image in the KML file after I loaded the KML file into KmlDataResource. I need the layer so I can set the opacity of that image after the image was added to Cesium viewer. Does anyone know how? Thanks a lot

Here is the code:

viewer = new Cesium.Viewer(‘cesiumContainer’);
kmlDataSource = new Cesium.KmlDataSource();
kmlDataSource.loadUrl(‘myKMLFile’);
viewer.dataSources.add(kmlDataSource);

var entities = kmlDataSource.entities.entities;
var entity = entities[0];
var rectangle = entity.rectangle;
var material = rectangle.material;
var image = material.image;

How do I do this:

image.alpha = Cesium.defaultValue(0.2, 0.2);

Thanks,

Unfortunately, it looks like there is currently no way to do this.I wrote up an issue so we don’t forget about it: https://github.com/AnalyticalGraphicsInc/cesium/issues/2484

Thanks Matthew.

I have another question.

As you know, after we load a KML file, we have a rectangle.material.image for the icon from that KML file. Is there any way we can create an ImageryProvider with that rectangle.material or that rectangle.material.image. Currently, we have to create an ImageryProvider with a URL only.

Thanks,

You can get the url and rectangle of the KML rectangle and construct a SingleTileProvider from that.

Something like this:

var url = rectangle.material.image.getValue();
var rectangle = rectangle.coordinates.getValue();

var provider = new Cesium.SingleTileImageryProvider({ url:url, rectangle:rectangle });

Hi Matthew,

These codes worked fine for the old version, but after I downloaded the version 1.8, it failed. Here are my source codes and urls:

kmlDataSource.load(kml).then(function(dataSource)
{
  var entities = dataSource.entities.values;
  var length = entities.length;
  var entity = entities[0];
  var rectangle = entity.rectangle;
  var url = rectangle.material.image.getValue();
  rectangle = rectangle.coordinates.getValue();
  var opacity = 1.0;
  var child = addAdditionalLayerOption(
          'Test',
          new Cesium.SingleTileImageryProvider({
              url : url,
              rectangle : rectangle
         }),
         opacity,
         true);
});

}

http://mwsci.jpl.nasa.gov/cesium-kml/Apps/kmlTest.html – The old version worked fine:

and

http://mwsci.jpl.nasa.gov/cesium-1.8/Apps/kmlTest.html – The new version 1.8 got the following error:

An error occurred while rendering. Rendering has stopped.

TypeError: t is undefined
l.intersection@http://mwsci.jpl.nasa.gov/cesium-1.8/Build/Cesium/Cesium.js:417:28988
N.prototype._createTileImagerySkeletons@http://mwsci.jpl.nasa.gov/cesium-1.8/Build/Cesium/Cesium.js:452:23606
M.processStateMachine@http://mwsci.jpl.nasa.gov/cesium-1.8/Build/Cesium/Cesium.js:452:15115
N.prototype.loadTile@http://mwsci.jpl.nasa.gov/cesium-1.8/Build/Cesium/Cesium.js:453:6024
_@http://mwsci.jpl.nasa.gov/cesium-1.8/Build/Cesium/Cesium.js:453:18469
w.prototype.update@http://mwsci.jpl.nasa.gov/cesium-1.8/Build/Cesium/Cesium.js:453:20030
K.prototype.update@http://mwsci.jpl.nasa.gov/cesium-1.8/Build/Cesium/Cesium.js:453:31644
ct@http://mwsci.jpl.nasa.gov/cesium-1.8/Build/Cesium/Cesium.js:457:2238
dt@http://mwsci.jpl.nasa.gov/cesium-1.8/Build/Cesium/Cesium.js:457:2692
vt.prototype.render@http://mwsci.jpl.nasa.gov/cesium-1.8/Build/Cesium/Cesium.js:457:8493
P.prototype.render@http://mwsci.jpl.nasa.gov/cesium-1.8/Build/Cesium/Cesium.js:462:15618
t@http://mwsci.jpl.nasa.gov/cesium-1.8/Build/Cesium/Cesium.js:462:2643

I have looked up the code and I found that the new version 1,8 has added the Mine type to the kmlDataResource and didn’t have the KmlDataResource.loadUrl()l function any longer, but I did use the KmlDataResource.load() instead. It still had error. Do you have any ideas.

Thanks,
–Quoc

TC-8, Matthew Amato wrote:

I wrote up this issue to address this: https://github.com/AnalyticalGraphicsInc/cesium/issues/2624 It’s an easy fix and should be available in 1.9 (May 1st).

Thanks Matthew,