As a follow up question to this link: https://community.esri.com/message/593549
I select the symbol that I want to change by creating img elements and adding attributes such as index, id, etc. It's the onclick of that image that triggers the iteration through the layer's symbols to match the img.attribute['index'] with the iteration of the symbol loop. Then, I setUrl for that symbol.
I couldn't find the proper way to look at a collection of symbols. I noticed that if a layer/service has 1 symbol in the renderer, there is a layer.renderer.symbol object. If there is a collection of symbols, layer.renderer.symbol is undefined but layer.renderer._symbols is an object. I iterate through _symbols with for (key in layer.renderer_symbols).
I check the layer.renderer._symbols[key].type for 'picturemarkersymbol' then check to see if the img element (that the user clicked) index attribute matches key (so that I am stopping the loop to setUrl on the correct symbol).
I sort of do the same thing if the type is simplemarkersymbol. The difference is that I can't setUrl of a simplemarkersymbol so I try to do layer.renderer._symbols[key].setSymbol(new PictureMarkerSymbol...). However, layer.renderer._symbols[key] does not support 'setSymbol'.
I also tried messing with the setRenderer but that affects all of the other symbols on the layer. This particular layer that I'm testing has several symbols of different types.
What is the proper way to set the symbol of just one symbol in a collection of symbols?
Is there a better way to reference the collection of symbols in lieu of layer.renderer._symbols?
I feel like I'm also going to have the same issues when I try to change the simpleline and simplefill symbols? I will be changing their colors and thickness only though. I won't be changing the simpleline to a picture or anything too off the wall.
Thank you
I sort of hacked layer.renderer._symbols[key].symbol = new PictureMarkerSymbol...
That works but there has to be a proper way?
What type of renderer are you working with? Have you tried to just use setSymbol on the graphic and just ignore the renderer?
UniqueValueRenderer and SimpleRenderer most of the time. It depends on the layer that comes in.
I wasn't sure if I could mess with the graphic b/c that just contains the coordinates mostly, correct? layer.graphics[0].symbol is undefined when layer.renderer._symbols[0].symbol is the picturemarker or simplemarker symbol.
Yes the individual symbol on the graphic will be null when using a renderer but try setting it anyway.
I tried that for simplefill and simplelines and that works well. I'll have to try it for picturemarkers too.
Changing the graphic doesn't actually work all of the time. One layer that I found has a set of polygons for each LOD of the map. When I use graphic.setSymbol, only one LOD is modified.
And sure, I could iterate through all of the LODs and all of the graphics, but there has to be an easier way, yea?
Tyrone,
Sorry it took so long to get back with you. I am at the Dev Summit and I had the chance to ask about this with the JS API team, and the answer I got is that you will have to add a new value to the UniqueValueRenderer if that is the renderer you are using.
Nice! I feel famous now. I will play with that tomorrow. Thank you.
Sadly due to time constraints, I can't play with this much longer. What I have is working... I just have to use the _symbols object. I get that the _object names are reserved/internal objects. But, if it aint broke...