Select to view content in your preferred language

Setting Graphic symbol color after graphics layer is drawn on the map

2489
2
Jump to solution
05-02-2014 07:10 AM
SanthoshKumar3
Emerging Contributor
Hello,

I have a graphics layer drawn on the map with several other layers. I want to set a different color for the symbol based on a condition. So, I have used symbol.SetColor method which does not work.

var layer = map.getLayer('layerid'); layer.graphics[0].symbol.setColor(new dojo.Color("red"));


Any suggestions?

-Santhosh
0 Kudos
1 Solution

Accepted Solutions
JohnGrayson
Esri Regular Contributor
Suggestions:

  1) Best solution is to add a renderer to the layer based on the conditions so you don't have to worry about changing symbol colors directly.

  2) To change the symbol directly, here are the general steps (not tested):

var layer = map.getLayer('layerid'); // get the symbol var symbol = layer.graphics[0].symbol; // change color symbol.setColor(new dojo.Color("red")); // assign symbol back to graphic layer.graphics[0].setSymbol(symbol);

View solution in original post

0 Kudos
2 Replies
JohnGrayson
Esri Regular Contributor
Suggestions:

  1) Best solution is to add a renderer to the layer based on the conditions so you don't have to worry about changing symbol colors directly.

  2) To change the symbol directly, here are the general steps (not tested):

var layer = map.getLayer('layerid'); // get the symbol var symbol = layer.graphics[0].symbol; // change color symbol.setColor(new dojo.Color("red")); // assign symbol back to graphic layer.graphics[0].setSymbol(symbol);
0 Kudos
SanthoshKumar3
Emerging Contributor
Thanks John. Setting the symbol for the graphic worked. I thought setting the color will refresh the graphic automatically.  I will look up renderer examples in the API documentation. It sounds like that is a clean solution.
0 Kudos