CzmlDataSource need to be removed before add new data.

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\(\{ &nbsp;&nbsp;url: &quot;ajax/admin\_ajax\.php&quot;, &nbsp;&nbsp;type: &quot;POST&quot;, &nbsp;&nbsp;cache: false, &nbsp;&nbsp;data: \{ &nbsp;&nbsp;&nbsp;&nbsp;tracker\_req: &quot;yes&quot;, &nbsp;&nbsp;\}, &nbsp;&nbsp;dataType: &#39;text&#39;, &nbsp;&nbsp;success: function \(result\) &nbsp;&nbsp;\{ &nbsp;&nbsp;&nbsp;&nbsp;var result\_json = .parseJSON(result);
      var json = ;
    \.each\(result\_json\[&quot;live\_flights&quot;\], function\( index, value \) \{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;json = value; &nbsp;&nbsp;&nbsp;&nbsp;\}\); &nbsp;&nbsp;&nbsp;&nbsp;//console\.table\(json\); &nbsp;&nbsp;&nbsp;&nbsp;var json\_empty = \[\]; &nbsp;&nbsp;&nbsp;&nbsp;("#count_total_flights").html(result_json["live_flights_count"]);
    $("#logged_in_operator").html(operator_icao_code);

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

Thanks

Hello,

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

viewer.dataSources.removeAll();

``

Best,

Hannah