# Changing the style of newly added entities (GeoJsonDataSource).

**URL:** <https://community.cesium.com/t/changing-the-style-of-newly-added-entities-geojsondatasource/1508>\
**Category:** CesiumJS\
**Created:** [September 19, 2014, 3:09pm UTC](https://community.cesium.com/t/changing-the-style-of-newly-added-entities-geojsondatasource/1508 "2014-09-19T15:09:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alessio\_Pierluigi\_Pl](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@Alessio\_Pierluigi\_Pl](https://community.cesium.com/u/Alessio_Pierluigi_Pl)\
**Post date:** [September 19, 2014, 3:09pm UTC](https://community.cesium.com/t/changing-the-style-of-newly-added-entities-geojsondatasource/1508/1 "2014-09-19T15:09:49Z")

</div>

Hi all,

I’m trying to change the style of an entity (change its billboard and adding some text) as soon as it changes because of some new data coming from the DataSource (GeoJson in this case, slightly  
modified to make getOrCreateEntity get the correct Id and to allow to add new entities without removing the previous ones, like the CzmlDataSource).

My code looks like this:

dataSource.entities.collectionChanged.addEventListener(  
function collectionChangedEventCallback(collection, added, removed, changed){

```
          for (var i = 0; i < added.length; i++) {
              var entity = added[i];

              var style = _getStyle(entity);

              entity.point = style[0];
              entity.billboard = style[1];
          }
      });

```

As soon as it calls the entity.point … line, it triggers another collectionChanged event with an “added” count equal to 1. I understand  
that collection.suspendEvents() and collection.resumeEvents() can be used to mitigate this issue. Unfortunately, the problem is the same since resumeEvents() triggers another collectionChanged  
event.

Is there any way to achieve my objective?

Alessio

---

<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:** [September 19, 2014, 7:04pm UTC](https://community.cesium.com/t/changing-the-style-of-newly-added-entities-geojsondatasource/1508/2 "2014-09-19T19:04:01Z")

</div>

You could modify your callback function to detect re-entrancy and ignore the events that are triggered from inside your callback:

var inCallback = false;

dataSource.entities.collectionChanged.addEventListener(

function collectionChangedEventCallback(collection, added, removed, changed){

if (inCallback) {

return;

}

inCallback = true;

collection.suspendEvents();

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

var entity = added[i];

var style = \_getStyle(entity);

entity.point = style[0];

entity.billboard = style[1];

}

collection.resumeEvents();

inCallback = false;

});

---

<div class="post-metadata">

**Author:** ![Alessio\_Pierluigi\_Pl](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@Alessio\_Pierluigi\_Pl](https://community.cesium.com/u/Alessio_Pierluigi_Pl)\
**Post date:** [September 22, 2014, 3:10pm UTC](https://community.cesium.com/t/changing-the-style-of-newly-added-entities-geojsondatasource/1508/3 "2014-09-22T15:10:09Z")

</div>

Thanks, that did it!
