My goal is to display a complete feature layer of ~400 features with a default symbology when the map loads and then replace the symbology of a single polygon in that feature layer on a mouse hover event. Eventually, I'll want to be able to select that polygon and permanently alter the symbology while also changing the symbology of the remaining polygons in the same feature layer... this is basically a highlight and whiteout.
Here how I started:
map = new Map("mapDiv", {
basemap: "topo",
center: [-50, 50]
});
map.on("load", function(){
map.graphics.enableMouseEvents();
map.graphics.on("mouse-out", function(evt){
map.graphics.clear();
});
});
var layer = new FeatureLayer("http://myserver/arcgis/rest/services/my_map/MapServer/1", {
mode: FeatureLayer.MODE_SNAPSHOT
});
map.addLayer(layer);
var hover_symbol = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color([38,115,0]),
2
),
new Color([38,115,0,0.75])
);
layer.on("mouse-over", function(evt){
var hover_graphic = new Graphic(evt.graphic.geometry, hover_symbol);
map.graphics.add(hover_graphic);
});
This works to get a highlight over the feature that the mouse is hovering on. I now realize, however, that the new graphic is merely covering the old feature layer graphic instead of replacing it.
I see a Unique Value Renderer that allows you to style a feature layer by an attribute, but it seems like I would need to query the layer for that to apply here.
Any ideas on how to accomplish this on-the-fly? Can I somehow loop through the graphics in the feature layer and single out the polygon over which the mouse is hovering?