# Removing specified customDataSource

**URL:** <https://community.cesium.com/t/removing-specified-customdatasource/16726>\
**Category:** CesiumJS\
**Created:** [January 3, 2022, 10:17am UTC](https://community.cesium.com/t/removing-specified-customdatasource/16726 "2022-01-03T10:17:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahyar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/ahyar/32/6472_2.png) [@Ahyar](https://community.cesium.com/u/Ahyar)\
**Post date:** [January 3, 2022, 10:17am UTC](https://community.cesium.com/t/removing-specified-customdatasource/16726/1 "2022-01-03T10:17:18Z")

</div>

how to remove a customDataSource? for example i have two dataSources, like this below.

```auto
var dataSource1 = new Cesium.CustomDataSource('myData1');
var dataSource2 = new Cesium.CustomDataSource('myData2');

var entity1 = dataSource1.entities.add({
   position : Cesium.Cartesian3.fromDegrees(1, 2, 0),
   billboard : {
       image : 'image1.png'
   }
});

var entity2 = dataSource2.entities.add({
   position : Cesium.Cartesian3.fromDegrees(1, 2, 0),
   billboard : {
       image : 'image2.png'
   }
});

viewer.dataSources.add(dataSource1);
viewer.dataSources.add(dataSource2);

```

what should i do to remove only the dataSource2 ?

---

<div class="post-metadata">

**Author:** ![sam.rothstein](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sam.rothstein/32/6584_2.png) [@sam.rothstein](https://community.cesium.com/u/sam.rothstein)\
**Post date:** [January 3, 2022, 6:06pm UTC](https://community.cesium.com/t/removing-specified-customdatasource/16726/2 "2022-01-03T18:06:23Z")

</div>

Hi @Ahyar,

Thank you for the thoughtful question! I recommend using the `remove` method of `DataSourceCollection` to remove `dataSource2`. Here is the documentation for `remove`:

[https://cesium.com/learn/cesiumjs/ref-doc/DataSourceCollection.html#remove](https://cesium.com/learn/cesiumjs/ref-doc/DataSourceCollection.html#remove)

This should help you get started. Please let me know if you have any other questions or concerns.

Best,  
Sam

---

<div class="post-metadata">

**Author:** ![Ahyar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/ahyar/32/6472_2.png) [@Ahyar](https://community.cesium.com/u/Ahyar)\
**Post date:** [January 4, 2022, 2:20am UTC](https://community.cesium.com/t/removing-specified-customdatasource/16726/3 "2022-01-04T02:20:53Z")

</div>

i tried with this

```auto
viewer.dataSources.remove(dataTitik,true)

```

but it doesn’t work and show this error  
 ![Screenshot_20220104_091842](https://global.discourse-cdn.com/cesium/original/2X/0/0aab4dd79fdcef60c4a1cd3410ad54951eb3cc53.png)  
is there any suggestion on my code? thanks

---

<div class="post-metadata">

**Author:** ![sam.rothstein](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sam.rothstein/32/6584_2.png) [@sam.rothstein](https://community.cesium.com/u/sam.rothstein)\
**Post date:** [January 4, 2022, 3:52pm UTC](https://community.cesium.com/t/removing-specified-customdatasource/16726/4 "2022-01-04T15:52:07Z")

</div>

Hi @Ahyar,

Thank you for sharing this with me. It would be helpful if you could provide a more complete code example. For instance, a [sandcastle demo](https://sandcastle.cesium.com/) that showcases the error would be very helpful. I suspect that this issue stems from the variable `dataTitik`.

Best,  
Sam

---

<div class="post-metadata">

**Author:** ![Ahyar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/ahyar/32/6472_2.png) [@Ahyar](https://community.cesium.com/u/Ahyar)\
**Post date:** [January 5, 2022, 2:54am UTC](https://community.cesium.com/t/removing-specified-customdatasource/16726/5 "2022-01-05T02:54:52Z")

</div>

i’ve solved it, i think there’s some typos in my html code. but when i tried it on [my sandcastle](https://sandcastle.cesium.com/#c=rVRNj9owEP0rVi4bJNZAWNSKsqhAEZW6WlYL6qXpwZsMxKpjR7YDzVb899r5gPC120Phkpl5b8aeN2Ofb4hEGwpbkOgecdiiCSiaxvh77nN9J8jtieCaUA7Sdxqf/JwVEk0WIpUBdI6pk1RpEX/Zh92bOLNW5+ac6v0b1cupxd8mEJLwNTwJlq0FNylqZ8HANdUUFCZh6P7xOUKcxNBHvjPPWSgpaVuqI5SAvE2EMgzjiYCuI60Q4SESqWbmwr7TtClKTh/lCRGKKEgigyjr749OpDZfhHfxSpo7wFoCqJGUJPtapHV/FFyEbjvtNm43K9Pr1QwTsr/mFWy3bnw4g368Bu3WoT8b5Qf81jINISxO2EcVwHTlqWxKFTJAKKMx0SApYYe7CyYknj+PHmdTbNs6YklE3DbuVYXKbh6lKX05+STV+GE0+VbCAiYUjIU2g9FfEaag7l+KpHBa385EdsWg2CGxAvBLM+K9MSMzS9r3pdL9f0zBkfx1ne48fFXu09hdPXYAXhW0l8u+x11RbvY8nT5eaDc69Lve2/xpwId+Fm2s7WC+5++hPItamFULiNIMbHQpBHshcpya6ty8PRJisYFy22taoFXKg3xj3UahxYVqBbl+rKYdPlt1937pVyFipEUxRG+VtMClOL2XqeA0nYHSGYNhJdhnGidCapRK5mLc0hAnzAiiWi9p8As0DpSyXAsdtOrUQUg3iIb3F15joxdRykRWKWML+moerOGgZfBnVCZISPl6vgHJSGZhUWf4UDgxxoOWMS8zddEbQ6kOd0Chvw), your suggestion works really well, thanks.

---

<div class="post-metadata">

**Author:** ![sam.rothstein](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sam.rothstein/32/6584_2.png) [@sam.rothstein](https://community.cesium.com/u/sam.rothstein)\
**Post date:** [January 5, 2022, 3:43pm UTC](https://community.cesium.com/t/removing-specified-customdatasource/16726/6 "2022-01-05T15:43:34Z")

</div>

@Ahyar

Glad to hear it!

Best,  
Sam
