I have a map where when it is initialized, I want to highlight two different kinds of features -- each with a different color -- in my FeatureLayer. I'm creating two different Query objects, setting the FeatureLayer.selectionColor, and calling FeatureLayer.selectFeatures(). The effect is that it's highlighting features from both queries but it's setting the color for all to the last color I used for FeatureLayer.selectionColor. I realized that this was because when creating a new FeatureLayer and setting it equal to the layer that I'm querying against, it's using a reference for the new layer, not a value/copy. I attempted to clone the FeatureLayer using the code in this post (excellent code btw) which does create a true clone of the FeatureLayer (and not a reference) but the FeatureLayer.url property is not being copied (among other properties I think) so the selectFeatures() method fails. Am I going about this the wrong way? Is there a way to easily set the selectionColor to different colors on a layer? I like the highlighting of the selectedFeatures and would prefer to use it if at all possible. But if I have have to use a GraphicsLayer to different effect then I will.My code:
if (requestSites && requestSites != "")
{
queryExpr = "PK IN (" + requestSites + ")";
highlightSitesOnMap(queryExpr, queryUrl, 0xFFFF00);
}
. . .
if (manualSites && manualSites != "")
{
queryExpr = "PK IN (" + manualSites + ")";
highlightSitesOnMap(queryExpr, queryUrl, 0x0000FF);
}
. . .
private function highlightSitesOnMap(queryExpr:String, queryUrl:String, highlightColor:uint):void
{
facsQuery.where = queryExpr;
facsQuery.outSpatialReference = map.spatialReference;
facsQuery.returnGeometry = true;
var fLayer:FeatureLayer = new FeatureLayer();
for each (var lyr:Layer in map.layers)
{
if (lyr is FeatureLayer)
{
//fLayer = FeatureLayer(lyr); -- original attempt, makes a reference, not a copy
fLayer = WindsorUtils.deepClone(lyr) as FeatureLayer;
//fLayer.url = lyr.url; -- causes exception 'Access of possibly undefined property url through a reference with a static type com.esri.ags.layers:Layer'
if ((fLayer != null) && (fLayer.url == queryUrl))
break;
}
}
var selectionMethod:String = FeatureLayer.SELECTION_ADD;
fLayer.selectionColor = highlightColor;
fLayer.selectFeatures(facsQuery, selectionMethod, new AsyncResponder(onSelectResult, onSelectFault, fLayer));
this.map.addLayer(fLayer);
}