# How to update polygon material if I know Id of polygon?

**URL:** <https://community.cesium.com/t/how-to-update-polygon-material-if-i-know-id-of-polygon/4177>\
**Category:** CesiumJS\
**Created:** [June 1, 2016, 7:21am UTC](https://community.cesium.com/t/how-to-update-polygon-material-if-i-know-id-of-polygon/4177 "2016-06-01T07:21:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MP11](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@MP11](https://community.cesium.com/u/MP11)\
**Post date:** [June 1, 2016, 7:21am UTC](https://community.cesium.com/t/how-to-update-polygon-material-if-i-know-id-of-polygon/4177/1 "2016-06-01T07:21:18Z")

</div>

I am loading a CZML file in cesium. And want to highlight multiple polygons (like myid\_1, myid\_2, myid\_3) if polygon with id as “myid” is clicked. But I am unable to process it as I am not getting the entity objects of other polygons to process its color change. On click handler is as below.

```auto
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(click) {
    var pickedObject = scene.pick(click.position);
    if (Cesium.defined(pickedObject)) {
        console.log(pickedObject.id instanceof Cesium.Entity); //returns true
        var colorProperty = Cesium.Color.YELLOW;
        pickedObject.id.polygon.material = new Cesium.ColorMaterialProperty(colorProperty);
    }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

```

How can I get the other related polygons processed on click?

---

<div class="post-metadata">

**Author:** ![hannah](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hannah/32/4509_2.png) [@hannah](https://community.cesium.com/u/hannah)\
**Post date:** [June 1, 2016, 12:49pm UTC](https://community.cesium.com/t/how-to-update-polygon-material-if-i-know-id-of-polygon/4177/2 "2016-06-01T12:49:22Z")

</div>

Hello,

You can use entities.getById to get the polygons with similar ids. Here is an example:

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

var promise = Cesium.CzmlDataSource.load(‘path/to/file’);  
promise.then(function(dataSource) {  
viewer.dataSources.add(dataSource);

```
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(click) {
    var pickedObject = scene.pick(click.position);
    var entity = pickedObject.id;
    if (dataSource.entities.contains(entity)) {
        var entityId = entity.id;
        var otherId = '';//figure out id of related entities using entityId
        var otherEntity = dataSource.entities.getById(otherId);
        ...
    }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

```

});

``

Best,

Hannah
