CzmlDataSource need to be removed before add new data.

108 views
Skip to first unread message

lgsof...@gmail.com

unread,
Apr 21, 2016, 6:11:29 PM4/21/16
to cesium-dev
Hi
Hannah,

I have to update CzmlDataSource but before that i want to remove old one on every ajax call it load new data.

How can i remove old data and load new one.

This works - viewer.dataSources.add(Cesium.CzmlDataSource.load(json));

but it also keep adding on top of that. It does not remove old CzmlDataSource.

I tried few things

viewer.entities.removeAll();

//viewer.dataSources.remove(Cesium.CzmlDataSource.load(json));

for (var i = 0; i < viewer.dataSources.length; ++i) {
var dataSource = viewer.dataSources[i];
//if (dataSource.name === "simple") {
viewer.dataSources.remove(dataSource);
// break;
// }
}

Non of them are working....


Here is my Ajax call back code -

$.ajax({
url: "ajax/admin_ajax.php",
type: "POST",
cache: false,
data: {
tracker_req: "yes",
},
dataType: 'text',
success: function (result)
{
var result_json = $.parseJSON(result);
var json = [];
$.each(result_json["live_flights"], function( index, value ) {
json = value;
});
//console.table(json);
var json_empty = [];
$("#count_total_flights").html(result_json["live_flights_count"]);
$("#logged_in_operator").html(operator_icao_code);

viewer.dataSources.add(Cesium.CzmlDataSource.load(json));
}
});


Thanks

Hannah Pinkos

unread,
Apr 22, 2016, 9:46:08 AM4/22/16
to cesium-dev, lgsof...@gmail.com
Hello,

You need to remove the dataSource from viewer.dataSources.  This should do this trick:

viewer.dataSources.removeAll();

Best,

Hannah
Reply all
Reply to author
Forward
0 new messages