I am trying to see if there is a better way to highlight a graphic in the map when you click on it. I currently have a layer of railroad tracks in the US and the project is to come up with a way to calculate the distance in the highlighted path. Right now, I have it set up so that you can click on a segment of track, click a button to save it, and it will store the information about the segment while keeping it highlighted. In that same list, I want to be able to click on a row in the list and have it change that track segment to a different color. As far as I am aware, the graphics are being stored on the main GraphicsLayer when using map.graphics.add()
. The problem is that when it changes the color on the one graphic, any future graphics made get set to that same color. I'm able to reset the color on the graphic (without it visibly changing on the map) as a workaround, but there has to be a better way to do this.
var g = map.graphics.graphics[idx];
var originalColor = g.symbol.color;
map.graphics.remove(g);
g.symbol.setColor(new dojo.Color([0, 0, 0, 1]));
map.graphics.add(g);
g.symbol.setColor(originalColor);