# Sandcastle example: Change color of GeoJSON

**URL:** <https://community.cesium.com/t/sandcastle-example-change-color-of-geojson/9629>\
**Category:** CesiumJS\
**Created:** [May 15, 2020, 4:02am UTC](https://community.cesium.com/t/sandcastle-example-change-color-of-geojson/9629 "2020-05-15T04:02:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevyn\_Pineda\_Ortiz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevyn_pineda_ortiz/32/2071_2.png) [@Kevyn\_Pineda\_Ortiz](https://community.cesium.com/u/Kevyn_Pineda_Ortiz)\
**Post date:** [May 15, 2020, 4:02am UTC](https://community.cesium.com/t/sandcastle-example-change-color-of-geojson/9629/1 "2020-05-15T04:02:05Z")

</div>

Hi to everyone.  
I’m new in Cesium.  
I’d loaded a GeoJSON and i wanna choose the color of every polygon in the geojson.

I had followed this example:

> **[Cesium Sandcastle](https://sandcastle.cesium.com/?src=GeoJSON%20and%20TopoJSON.html)**
>
> The Cesium Sandcastle provides an interactive environment for testing Cesium code.

And it works fine as you can see in the image:

 ![image](https://global.discourse-cdn.com/cesium/original/2X/9/9b6c37fee87c818bd6c711cadbc2e335d3d29d7b.jpeg)

I’d used this line “colorHash[name] = color” ito give color to every polygon individually,  
But I dont know why I’m not able to give color to one polygon, its the white polygon.  
Can someone help me?

I’d noticed that white polygon is the first one in the definition of the GeoJSON

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [May 18, 2020, 7:50pm UTC](https://community.cesium.com/t/sandcastle-example-change-color-of-geojson/9629/2 "2020-05-18T19:50:51Z")

</div>

It’s hard to know what the issue is without seeing the source GeoJSON here. You can try uploading that to Cesium ion and sharing a Sandcastle here.

---

<div class="post-metadata">

**Author:** ![Kevyn\_Pineda\_Ortiz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevyn_pineda_ortiz/32/2071_2.png) [@Kevyn\_Pineda\_Ortiz](https://community.cesium.com/u/Kevyn_Pineda_Ortiz)\
**Post date:** [May 20, 2020, 6:18pm UTC](https://community.cesium.com/t/sandcastle-example-change-color-of-geojson/9629/3 "2020-05-20T18:18:39Z")

</div>

Thanks for your help!  
This is the code:

> **[Cesium Sandcastle](https://sandcastle.cesium.com/#c=nVbtcto4FH0VDX9KpqkpyZKdDCSzgRBqh48kkBBa+kPYN1hBlogkw5pOHqYP0KfIi/UKm4822d1hGRjbuuecq3t8JVEokIaiwpAaaBZHXpdQ3wetiZEkkbEiTApCtQajhyLFOK4UTgAPNObmbAnuyQkIckKGOUi8cNTwWYd57u3CLbaZq11xU/Jr7pE7md7f1bxjB0FPQWOCIHfefvwctfq3f7dZcdI+r06aveuD1kHdDPpeuBw7uIs6eD/ou6VW32XNmjf9jGKtx9tipzdA8fbj6LDK/cQ96mNy/3CJEYPECyx2cH/NOo/1Yud8kODvY3uBE5hPBT2qFi9Ki94lj0pe+8P14SBRca942b26mN+7T+dt76YkRjAf5spDMRQzqsiMwRwUlilgntnl3C3H8sOcv3yuSWEoE6CGub01b6pkxDQgcePfDWg01wfnAYNn1l43yB8f/Xn8x95QEOKYEET+IRa+sf7nVQbfI99smBAFJlZiJdgA6Wkpzqmh3VSWSxpsWGVLen5TOVhz1tppnc4moh0aBNvIcgbE4kAYZhhorG4DcFajzozyGPTSCkJWHF9yqT5RHSLp23N5FXqQiuRtnOH4xzJeKmt5h4MYmxAH379fT9R+CoULpAH1wxSb7BNfATVAKMG+DmSUpiMjqiEgWDIaQLSxCEEjcLalujLKYpqEdAYkwhZnUw7reewTLcncgqSCpVSqznCRbCuFtjqEmpAai491itaYMqPYcu2QlVZZ2q3ZrM1N0I1V+i/sa/lXiK1hBUgc+/QbIE12sjH9iwVty2wi767o4t3XTaPWbMSpNm/rb8NrVFHSjX1GyQfSpYJcQaDka4Wb+vnbAl2maER3SdmQVPtSvXwXO6RpQjSl5IybN1I1bur19j/ksg0EBL9dKXB94Qt6zR/Um81O/z8F0JwWG8fAd5pBOvEWBIzulrmFiZkY2/dCajKinE53stl7+TGSdAeLqzR8+UFtqR57ihln+JZ2SVjXBpRc8ik3MIWnGP6HVVX6uKNT/2pxtXlWuyzjek5XUSBB41Hph1SMYaOWLb6p5MkYj8YI+0QxyleLbp33Ob3ZaTPONvpsT15IGfXkq604U5Mop+Z41GxJglJSrdV828fcHg/jLJLx8ZLbz1W0STic2qG/WDSVypBY8bzjFAy6xO2+WBjF/gSM42ttSZXCilIJ2Iyw4OSNo5D4HP9BYOQh5rzLFjDMnVYKiP+FZo8sbNnODBSnCULsNCph8bSZBhzHqRTw0Sb9nWuk5COqtnR/Ag)**
>
> The Cesium Sandcastle provides an interactive environment for testing Cesium code.

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [May 22, 2020, 1:56am UTC](https://community.cesium.com/t/sandcastle-example-change-color-of-geojson/9629/4 "2020-05-22T01:56:07Z")

</div>

This is just a coding error. You’re defining your colors after you check the name of the entity. So the first entity doesn’t get any color.

---

<div class="post-metadata">

**Author:** ![Kevyn\_Pineda\_Ortiz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevyn_pineda_ortiz/32/2071_2.png) [@Kevyn\_Pineda\_Ortiz](https://community.cesium.com/u/Kevyn_Pineda_Ortiz)\
**Post date:** [May 22, 2020, 3:35am UTC](https://community.cesium.com/t/sandcastle-example-change-color-of-geojson/9629/5 "2020-05-22T03:35:44Z")

</div>

Thanks a lot!  
I appreaciate your answer.
