Unload Datasource

Hello Gabby,

How can we unload the KML or CZML datasource??

If we use, viewer.dataSources.remove(*datasource name*);
Still it is not removing the datasource layer.

Please help with other solution.

Regards,
Shubham M

Hi!

I can’t seem to replicate this problem. Do you have a code example? In the meantime, the following may be why it’s not removing.

If your code looks something like, it wouldn’t work because the added ds is actually no longer the same reference as the old ds:

var ds = Cesium.CzmlDataSource.load(czml);
viewer.dataSources.add(ds); // the added ds is NOT referentially the same as ds

console.log(viewer.dataSources.contains(ds)); // would output FALSE

viewer.dataSources.remove(ds);// removes nothing, because ds isn’t even in viewer.dataSources!

``

The following code correctly references and removes the datasource:

var ds;

viewer.dataSources.add(Cesium.CzmlDataSource.load(insert your czml/kml)).then(function(datasource) {

ds = datasource; // the add function returns the correct reference to the loaded datasource

});

console.log(viewer.dataSources.contains(ds)); // would output TRUE

viewer.dataSources.remove(ds); // datasource is removed

``

Hope this helps!

Thanks alot. Working fine.
Thank You

Regards,

Shubham Mahale

Hello Jane!!

Above code suggested from you is working fine.

But can we do this task in another way.??

For eg : In above case, on every time we are loading the layer and unloading the layer. Again, loading the layer and unloading the layer,

but can we just give visibility to layer i.e, on/off the layer instead of unloading the layer???

Please suggest can we do this

Regards,

Shubham M

Hi! I’m glad to hear it’s working c:

Have you checked out the show attribute of Datasource? Try doing something like:

ds.show = false;

``

to make it invisible and

ds.show = true;

``

to make it visible.

Hello Jane!!

Can you help me in below code.

How can we remove the datasource after loading Geojson datasource??

var promiseenemy = Cesium.GeoJsonDataSource.load(’…/…/TestDemo/cesiumLayers/sampledata/nextgen/Abc.geojson’);

promiseenemy.then(function(dataSource) {

viewer.dataSources.add(dataSource);

//dataSource.clustering.enabled = true;

var entities = dataSource.entities.values;

for (var i = 0; i < entities.length; i++) {

attachSym(entities[i]); //here i am invoking some method

}

});

Please guide.

Thanks in advance

Regards,

Shubham M

Hi! To show/hide the datasource (if this is what you would rather have), the following should work:

promiseenemy.then(function(dataSource) {
viewer.dataSources.add(dataSource);
//dataSource.clustering.enabled = true;

// to hide the dataSource, do the following:
dataSource.show = false;

// to show the dataSource, do the following:
dataSource.show = true;

// ... your other code ... //

});

``