# Removing individual dataSources does not update viewer

**URL:** <https://community.cesium.com/t/removing-individual-datasources-does-not-update-viewer/1637>\
**Category:** CesiumJS\
**Created:** [November 2, 2014, 3:58pm UTC](https://community.cesium.com/t/removing-individual-datasources-does-not-update-viewer/1637 "2014-11-02T15:58:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bart](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@Bart](https://community.cesium.com/u/Bart)\
**Post date:** [November 2, 2014, 3:58pm UTC](https://community.cesium.com/t/removing-individual-datasources-does-not-update-viewer/1637/1 "2014-11-02T15:58:02Z")

</div>

I’m loading a small number (~4) of GeoJson dataSources, each with a small number (~2) of features. When I remove a single dataSource, the dataSource’s features are still visible in the viewer. The viewer’s dataSources collection contains the correct number of remaining dataSources. Only when I call viewer.resize() or when all of the dataSources have been removed does the viewer update properly, showing no features. This happens whether or not I set the destroy parameter to true:

viewer.dataSources.remove(datasource);  
viewer.dataSources.remove(datasource, true);  
//nothing changes in the viewer until the last dataSource has been removed

viewer.resize(); //this causes the viewer to update correctly

viewer.dataSources.removeAll(); //this works as expected and as in Sandcastle

``

When I call viewer.resize() after removing a single dataSource, it is removed from the viewer. Am I missing something, or is this the intended behavior?

Bart

---

<div class="post-metadata">

**Author:** ![Scott\_Hunter](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/scott_hunter/32/2006_2.png) [@Scott\_Hunter](https://community.cesium.com/u/Scott_Hunter)\
**Post date:** [November 4, 2014, 9:10pm UTC](https://community.cesium.com/t/removing-individual-datasources-does-not-update-viewer/1637/2 "2014-11-04T21:10:44Z")

</div>

Can you provide code that reproduces the problem? I made a quick test case and it seems to be working correctly.

I downloaded a few geojson files from [https://github.com/johan/world.geo.json/tree/master/countries/USA](https://github.com/johan/world.geo.json/tree/master/countries/USA) and tested with this sandcastle:

//Create the viewer

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var wi = Cesium.GeoJsonDataSource.fromUrl(’…/…/SampleData/WI.geo.json’);

var wv = Cesium.GeoJsonDataSource.fromUrl(’…/…/SampleData/WV.geo.json’);

var wy = Cesium.GeoJsonDataSource.fromUrl(’…/…/SampleData/WY.geo.json’);

Sandcastle.addToolbarButton(‘add wi’, function() {

viewer.dataSources.add(wi);

});

Sandcastle.addToolbarButton(‘add wv’, function() {

viewer.dataSources.add(wv);

});

Sandcastle.addToolbarButton(‘add wy’, function() {

viewer.dataSources.add(wy);

});

Sandcastle.addToolbarButton(‘remove wi’, function() {

viewer.dataSources.remove(wi);

});

Sandcastle.addToolbarButton(‘remove wv’, function() {

viewer.dataSources.remove(wv);

});

Sandcastle.addToolbarButton(‘remove wy’, function() {

viewer.dataSources.remove(wy);

});

---

<div class="post-metadata">

**Author:** ![gov\_inda](https://avatars.discourse-cdn.com/v4/letter/g/5e9695/32.png) [@gov\_inda](https://community.cesium.com/u/gov_inda)\
**Post date:** [March 18, 2015, 9:14am UTC](https://community.cesium.com/t/removing-individual-datasources-does-not-update-viewer/1637/3 "2015-03-18T09:14:08Z")

</div>

I have the same issue on cesium 1.7.1, using the viewer not in sandcastle

var data = Cesium.GeoJsonDataSource.load(‘data/mun.topojson’);

viewer.dataSources.add(data);

if(flag){

> [//viewer.dataSources.removeAll](https://viewer.dataSources.removeAll)(); //works  
> viewer.dataSources.remove(data); //does not work  
> }  
> else

---

<div class="post-metadata">

**Author:** ![Matt\_Amato](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/matt_amato/32/1993_2.png) [@Matt\_Amato](https://community.cesium.com/u/Matt_Amato)\
**Post date:** [March 18, 2015, 3:22pm UTC](https://community.cesium.com/t/removing-individual-datasources-does-not-update-viewer/1637/4 "2015-03-18T15:22:57Z")

</div>

data is not what you think it is. It’s a Promise and not a KmlDataSource.

See my response in this thread for example code and details: [https://groups.google.com/d/msg/cesium-dev/Bf9MwBgJN8w/5WfUFprBqSgJ](https://groups.google.com/d/msg/cesium-dev/Bf9MwBgJN8w/5WfUFprBqSgJ)

---

<div class="post-metadata">

**Author:** ![carlo.nnn](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@carlo.nnn](https://community.cesium.com/u/carlo.nnn)\
**Post date:** [March 24, 2015, 4:02pm UTC](https://community.cesium.com/t/removing-individual-datasources-does-not-update-viewer/1637/5 "2015-03-24T16:02:40Z")

</div>

thank you, it works.
