I have created a Cesium webpage that allows the user to select a kml file to display. I have it all working fine but when I change data in a kml file that was previously loaded I still see the old data not the new after I try to reload it. Here is my code:
viewer.dataSources.removeAll();
viewer.scene.primitives.removeAll();
var dataSource1 = new Cesium.KmlDataSource();
dataSource1.load(strFile);
viewer.dataSources.add(dataSource1);
I have added the primitives.removeAll statement and tweaked the load statements to avoid promises but so far nothing seems to force a refresh of the data file.
What do I need to do to get Cesium to "throw away" the previous data and reload the data file that has been updated?
I’m not sure what you mean about “avoiding” promises. Promises can’t be avoided. Don’t call viewer.scene.primitives.removeAll(); (we actually have a bug on this), but other than that your code is correct without the call. Can you provide a more complete example of what you’re doing? I can’t reproduce the problem. For example, paste the below into Sandcastle, it toggles between two different files every time you hit the button.
var viewer = new Cesium.Viewer(‘cesiumContainer’);
var files = [’…/…/SampleData/kml/facilities/facilities.kml’,
'../../SampleData/kml/gdpPerCapita2008.kmz'];
var count = 0;
Sandcastle.addDefaultToolbarButton(‘Switch files’, function() {
viewer.dataSources.removeAll();
var dataSource1 = new Cesium.KmlDataSource();
dataSource1.load(files[count++%2]);
viewer.dataSources.add(dataSource1);
});
I have been doing research on this issue and someone suggested the way I have the add datasource and the person who posted it said that it would be a better way of doing it (I read it as "avoid" a promise maybe a better word is "ignore").
Moving back to the real issue. I have a file "mydata.kml" that I do my add datasource with and I see the data - let's say the balloon pops up with a value of 100 when I click on an item. I then go into the mydata.kml file on my server and change the value to 120 on that item. I invoke the code again to load the mydata.kml file but the value is still 100, not 120. I read somewhere the primitive holds the data so that is why I added its removeAll.
What do I need to do so that the cache, buffer, primitive or whatever is holding the data is cleared out each time and the file is forced to load its updated data?
I just realized that you said you are actually modifying a file on the server? That could be your problem. Depending on how your server is configured, the browser is most likely just caching the result and when you “reload” the file you’re actually loading the old version and not the changed version. There’s a good chance your code is fine and it’s a server configuration issue.