Transparency of graphics

2267
6
Jump to solution
08-22-2014 07:44 AM
TimWitt2
MVP Alum

Hey everybody,

Is there a way to change the transparency of a particular graphic or is this only possible for a graphic layer?

Tim

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Tim,

If the graphics is already created, you can use the setSymbol method to do this.  Ex:

var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,

        new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,

        new Color([255,0,0]), 2),new Color([255,255,0,0.25])

        )

map.graphics.graphics[2].setSymbol(symbol);

View solution in original post

6 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Tim,

If the graphics is already created, you can use the setSymbol method to do this.  Ex:

var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,

        new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,

        new Color([255,0,0]), 2),new Color([255,255,0,0.25])

        )

map.graphics.graphics[2].setSymbol(symbol);

TimWitt2
MVP Alum

Thanks Jake!

0 Kudos
TimWitt2
MVP Alum

One more question, how does this work if my color is in Hex string?

0 Kudos
KenBuja
MVP Esteemed Contributor

According to the documentation, the transparency option is only available for RGB colors

TimWitt2
MVP Alum

Thanks Ken, I guess I need to change my color palette then to return RGB values.

0 Kudos
KenBuja
MVP Esteemed Contributor

You can change the transparency of the color you assign different graphics.

var trans = Math.random();

// lineSymbol used for freehand polyline, polyline and line.

var lineSymbol = new CartographicLineSymbol(

  CartographicLineSymbol.STYLE_SOLID,

  new Color([255, 0, 0, trans]), 10,

  CartographicLineSymbol.CAP_ROUND,

  CartographicLineSymbol.JOIN_MITER, 5

);