Change color of polygon from KML

I have a project that I’ve converted from Google Earth to Cesium. I have the following problem and can’t seem to find an answer.
This project loads a dynamically generated KML file so I don’t have control over the colors.
I can get to the following polygon and I have a function to show or hide the polygon but I can not change it’s color.

Works:
outagesLayer.entities.getById(‘GPSJammingInterferenceId’).show = false/true; //depending on check box in the html.

Does not work:
outagesLayer.entities.getById(‘GPSJammingInterferenceId’).polygon.material = Cesium.Color.RED.withAlpha(0.5);

I’ve tried creating a material and then setting the material of this object but it doesn’t change. Is this possible?

Thanks,

-Gerry

Hi Gerry,

I believe the code you posted should work, so it might be a bug. Could you put together an example to reproduce this in Sandcastle: http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html

By the way, what kind of project are you working on?

Best,

Hannah

This example worked for me:

var kml = ’<?xml version="1.0" encoding="UTF-8"?>


Polygon.kml
0

hollow box




-122.366278,37.818844,30
-122.365248,37.819267,30
-122.365640,37.819861,30
-122.366669,37.819429,30
-122.366278,37.818844,30






';
var viewer = new Cesium.Viewer(‘cesiumContainer’);
var parser = new DOMParser();
var promise = Cesium.KmlDataSource.load(parser.parseFromString(kml, “text/xml”), {
camera: viewer.scene.camera,
canvas: viewer.scene.canvas
});
promise.then(function(ds) {
viewer.dataSources.add(ds);
ds.entities.getById(‘test’).polygon.material = Cesium.Color.RED;
viewer.zoomTo(ds.entities);
});

``

Best,

Hannah