<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic attempting to clone a FeatureLayer to get different selectionColors in ArcGIS API for Flex Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/attempting-to-clone-a-featurelayer-to-get/m-p/278393#M6571</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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().&amp;nbsp; 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.&amp;nbsp; 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.&amp;nbsp; I attempted to clone the FeatureLayer using the code in &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/14666-Cloning-Graphics-and-other-ESRI-Objects?highlight=clone" rel="nofollow noopener noreferrer" target="_blank"&gt;this post&lt;/A&gt;&lt;SPAN&gt; (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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I going about this the wrong way?&amp;nbsp; Is there a way to easily set the selectionColor to different colors on a layer?&amp;nbsp; I like the highlighting of the selectedFeatures and would prefer to use it if at all possible.&amp;nbsp; But if I have have to use a GraphicsLayer to different effect then I will.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
if (requestSites &amp;amp;&amp;amp; requestSites != "")
{
 queryExpr = "PK IN (" + requestSites + ")";
 highlightSitesOnMap(queryExpr, queryUrl, 0xFFFF00);
}

. . .

if (manualSites &amp;amp;&amp;amp; 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;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 var fLayer:FeatureLayer = new FeatureLayer();

 for each (var lyr:Layer in map.layers)
 {
&amp;nbsp; if (lyr is FeatureLayer) 
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; //fLayer = FeatureLayer(lyr); -- original attempt, makes a reference, not a copy
&amp;nbsp;&amp;nbsp; fLayer = WindsorUtils.deepClone(lyr) as FeatureLayer;
&amp;nbsp;&amp;nbsp; //fLayer.url = lyr.url;&amp;nbsp; -- causes exception 'Access of possibly undefined property url through a reference with a static type com.esri.ags.layers:Layer'
&amp;nbsp;&amp;nbsp; if ((fLayer != null) &amp;amp;&amp;amp; (fLayer.url == queryUrl))
&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp; }
 }
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 var selectionMethod:String = FeatureLayer.SELECTION_ADD;
 fLayer.selectionColor = highlightColor;
 fLayer.selectFeatures(facsQuery, selectionMethod, new AsyncResponder(onSelectResult, onSelectFault, fLayer));
 this.map.addLayer(fLayer);
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 13:33:20 GMT</pubDate>
    <dc:creator>ChrisBeaudette</dc:creator>
    <dc:date>2021-12-11T13:33:20Z</dc:date>
    <item>
      <title>attempting to clone a FeatureLayer to get different selectionColors</title>
      <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/attempting-to-clone-a-featurelayer-to-get/m-p/278393#M6571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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().&amp;nbsp; 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.&amp;nbsp; 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.&amp;nbsp; I attempted to clone the FeatureLayer using the code in &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/14666-Cloning-Graphics-and-other-ESRI-Objects?highlight=clone" rel="nofollow noopener noreferrer" target="_blank"&gt;this post&lt;/A&gt;&lt;SPAN&gt; (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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I going about this the wrong way?&amp;nbsp; Is there a way to easily set the selectionColor to different colors on a layer?&amp;nbsp; I like the highlighting of the selectedFeatures and would prefer to use it if at all possible.&amp;nbsp; But if I have have to use a GraphicsLayer to different effect then I will.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
if (requestSites &amp;amp;&amp;amp; requestSites != "")
{
 queryExpr = "PK IN (" + requestSites + ")";
 highlightSitesOnMap(queryExpr, queryUrl, 0xFFFF00);
}

. . .

if (manualSites &amp;amp;&amp;amp; 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;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 var fLayer:FeatureLayer = new FeatureLayer();

 for each (var lyr:Layer in map.layers)
 {
&amp;nbsp; if (lyr is FeatureLayer) 
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; //fLayer = FeatureLayer(lyr); -- original attempt, makes a reference, not a copy
&amp;nbsp;&amp;nbsp; fLayer = WindsorUtils.deepClone(lyr) as FeatureLayer;
&amp;nbsp;&amp;nbsp; //fLayer.url = lyr.url;&amp;nbsp; -- causes exception 'Access of possibly undefined property url through a reference with a static type com.esri.ags.layers:Layer'
&amp;nbsp;&amp;nbsp; if ((fLayer != null) &amp;amp;&amp;amp; (fLayer.url == queryUrl))
&amp;nbsp;&amp;nbsp;&amp;nbsp; break;
&amp;nbsp; }
 }
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
 var selectionMethod:String = FeatureLayer.SELECTION_ADD;
 fLayer.selectionColor = highlightColor;
 fLayer.selectFeatures(facsQuery, selectionMethod, new AsyncResponder(onSelectResult, onSelectFault, fLayer));
 this.map.addLayer(fLayer);
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:33:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-flex-questions/attempting-to-clone-a-featurelayer-to-get/m-p/278393#M6571</guid>
      <dc:creator>ChrisBeaudette</dc:creator>
      <dc:date>2021-12-11T13:33:20Z</dc:date>
    </item>
  </channel>
</rss>

