Change png icon's background color dynamically for feature in feature layer

3215
15
Jump to solution
04-25-2017 05:18 AM
ZdeněkSoldán
Occasional Contributor

Hello,

I have a point feature layer created from feature collection. As symbol for features in this FL is a png image with transaprent background. For every feature I have a html code of color readed from web service. Is it possible to change the background color for every feature using this hex code?  

I tried a pictureMarkerSymbol:

var symb = new PictureMarkerSymbol("images/trafLight.png",12,25);
var colorHex = Color.fromHex('#'+ String(item.color));
symb.setColor(colorHex);
var geometry = new Point({"x":"-"+item.geometry.y,"y":"-"+item.geometry.x,"spatialReference":{"wkid":102067}});
var graphic = new Graphic(geometry);
graphic.setSymbol(symb);
features.push(graphic);

The color doesn't change and if so I think it would change color of the border lines not the background color. 

0 Kudos
15 Replies
ZdeněkSoldán
Occasional Contributor

Robert,

in this link is printscreen from online font viewer http://imgur.com/a/0IFv4 

so from the prinscreen I think that my icon should be \0040. Am I wrong?

And to my step 4 - the folder with fonts has the name fonts already maybe it's not clear from my post but the path to the 4 files TraficLight.eot, TraficLight.svg, TraficLight.ttf and TraficLight.woff already was WebAppBuilderForArcGIS\server\apps\apID\widgets\nameOfTheWidget\fonts

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

That would be \eu0040

0 Kudos
ZdeněkSoldán
Occasional Contributor

Robert,

in my font the icon in on the place of the upper A so when my code is

var textSymbol = new TextSymbol('A', new Font("20pt", Font.STYLE_NORMAL, Font.VARIANT_NORMAL, Font.WEIGHT_BOLD, "TraficLight"));

it works!

But this way I know only how to change color of the TextSymbol but is it possible to change only the background color of TextSymbol?

0 Kudos
ZdeněkSoldán
Occasional Contributor

Robert, 

I used a halo property of the TextSymbol and it's good enough for me.

So thank you a lot for your help.

Zdenek

0 Kudos
KumarHarish
New Contributor III

Zdeněk,

 

Robert suggestion is  right.  Alternative convert the PNG image into SVG format.  Use the https://developers.arcgis.com/javascript/3/jssamples/graphics_svg_path.html tutorial to change the color of icon 

ZdeněkSoldán
Occasional Contributor

Kumar,

Thank you. This method works for me but it change directly the color of my svg picture but I want to change only the background of it.

0 Kudos