CZML remove polygon is not working

I need to remove previoud polygon and add a new polygon to map.
Data is updating but, it is not getting earsed from map.

I have created one cesium sandcastle link(cesium sandcastle).

I have a requirement to get the data from API and update the polygon on map in a loop(but it always erase the previous polygon).

Please check and help to fix this.

Your code appears to be removing the polygon CZML when adding the new circles, is that correct?

viewer.dataSources.remove(polygon_czml);

This may be easier to do through the Entity API, where you can just add the new entities as needed. Otherwise if you’re using CZML, make sure to use process instead of load so you don’t clear any previously added objects:

https://cesium.com/docs/cesiumjs-ref-doc/CzmlDataSource.html#process

Thank you omar for the reply.
I got it working with process and callback of datasource.

Example:

czmlSource.process(czml).then(function(dataSource) {
var _sources = dataSource;
if(_sources.name == “CZML Geometries”){
map.dataSources.remove(map.dataSources.get(0), true);
}
});

1 Like