<?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 Re: override layer.add() method in ArcGIS API for Flex Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691985#M15459</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;there we go...&amp;nbsp; this is what I was missing:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;this.addEventListener(GraphicEvent.GRAPHIC_ADD, onGraphicAdd);
this.addEventListener(GraphicEvent.GRAPHIC_REMOVE, onGraphicRemove);
this.addEventListener(GraphicsLayerEvent.GRAPHICS_CLEAR, onGraphicsClear);&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Drew was on the right track -- I just wasnt sure how to grab that event in the context of what I was doing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I shall give this a whirl... thank you both!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;greg&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 05:07:34 GMT</pubDate>
    <dc:creator>GregKnight</dc:creator>
    <dc:date>2021-12-12T05:07:34Z</dc:date>
    <item>
      <title>override layer.add() method</title>
      <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691978#M15452</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would like to build some custom Graphic and Feature Layers.&amp;nbsp; I would like to include behavior (mouseOvers, mouseClicks, etc) of the layer's graphics in this customization.&amp;nbsp; It would seem that in order to do so, I need to override the layer.add() method... although this is not supported according to the API docs.&amp;nbsp; So, there must be another way...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How do I go about accessing the graphics as they are added to the layer so I can add the appropriate listeners?&amp;nbsp; Is the approach the same for both graphic/feature layers?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Many thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-g&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 Mar 2011 11:24:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691978#M15452</guid>
      <dc:creator>GregKnight</dc:creator>
      <dc:date>2011-03-26T11:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: override layer.add() method</title>
      <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691979#M15453</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;When you get your query results just add the listeners to the graphic.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Below is a code sample..&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

queryTask.execute(query, new AsyncResponder(onResult, onFault));
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
function onResult(featureSet:FeatureSet, token:Object = null):void
{
 for each (var graphic:Graphic in featureSet.features)
 {
&amp;nbsp; &lt;STRONG&gt;graphic.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent):void&lt;/STRONG&gt;
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; graphic.useHandCursor = true;
&amp;nbsp;&amp;nbsp; graphic.buttonMode = true;
&amp;nbsp;&amp;nbsp; map.openHandCursorVisible = false;
&amp;nbsp;&amp;nbsp; trace("mouse over"); 
&amp;nbsp; });
&amp;nbsp; 
&amp;nbsp; &lt;STRONG&gt;graphic.addEventListener(MouseEvent.MOUSE_OUT, function(event:MouseEvent):void&lt;/STRONG&gt;
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; graphic.useHandCursor = false;
&amp;nbsp;&amp;nbsp; graphic.buttonMode = false;
&amp;nbsp;&amp;nbsp; map.openHandCursorVisible = true;
&amp;nbsp;&amp;nbsp; trace("mouse out");
&amp;nbsp; });
&amp;nbsp; &lt;STRONG&gt;graphic.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void&lt;/STRONG&gt;
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; trace("Click");
&amp;nbsp; })
 }
}

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Drew&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:07:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691979#M15453</guid>
      <dc:creator>Drew</dc:creator>
      <dc:date>2021-12-12T05:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: override layer.add() method</title>
      <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691980#M15454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That would certainly work if I were using the default graphic/feature layer... but I wish to extend it to create a custom layer as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;public class BuildingFeatureLayer extends FeatureLayer
 {
&amp;nbsp; 
&amp;nbsp; private var defaultSymbol:SimpleFillSymbol = new SimpleFillSymbol();
&amp;nbsp; private var mouseOverSymbol:SimpleFillSymbol = new SimpleFillSymbol();
&amp;nbsp; 
&amp;nbsp; public function BuildingFeatureLayer()
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; super();

&amp;nbsp;&amp;nbsp; setLoaded(true);
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; defaultSymbol.color = 0xFFFFFF;
&amp;nbsp;&amp;nbsp; defaultSymbol.alpha = 0.1;
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; mouseOverSymbol.color = 0xFF0000;
&amp;nbsp;&amp;nbsp; mouseOverSymbol.alpha = 0.5;
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; this.mode = "snapshot";
&amp;nbsp;&amp;nbsp; this.symbol=defaultSymbol;
&amp;nbsp;&amp;nbsp; this.outFields = [];
&amp;nbsp;&amp;nbsp; this.url="http://&amp;lt;server&amp;gt;/ArcGIS/rest/services/layers/&amp;lt;layername&amp;gt;/MapServer/0"
&amp;nbsp;&amp;nbsp; this.useAMF=false;
&amp;nbsp;&amp;nbsp; this.visible=true;
&amp;nbsp; }

&amp;nbsp; override protected function updateLayer():void
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; super.updateLayer();
&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // OVERRIDING THIS METHOD IS NOT PERMITTED BY THE API
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; override public function add(graphic:Graphic):void
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; graphic.toolTip = graphic.attributes.BUILDING_NAME;
&amp;nbsp;&amp;nbsp; graphic.addEventListener( MouseEvent.ROLL_OVER, graphic_mouseOverHandler );
&amp;nbsp;&amp;nbsp; graphic.addEventListener( MouseEvent.ROLL_OUT, graphic_mouseOutHandler );
&amp;nbsp; }&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Problem is, the API does not permit overriding the add(graphic:Graphic) method, so that I can add the necessary listeners.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:07:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691980#M15454</guid>
      <dc:creator>GregKnight</dc:creator>
      <dc:date>2021-12-12T05:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: override layer.add() method</title>
      <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691981#M15455</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;On the FeatureLayer there is a "&lt;/SPAN&gt;&lt;STRONG&gt;graphicAdd&lt;/STRONG&gt;&lt;SPAN&gt;" event. This will give you a graphic to apply the listeners on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;See the below ESRI sample illustrating adding tooltips to a graphic. I have not tested this, but I assume you would apply similar code to as i showed above.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Link:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/webapi/flex/samples/index.html?sample=FeatureLayerWithTooltips"&gt;http://help.arcgis.com/en/webapi/flex/samples/index.html?sample=FeatureLayerWithTooltips&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Drew&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 Mar 2011 15:16:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691981#M15455</guid>
      <dc:creator>Drew</dc:creator>
      <dc:date>2011-03-26T15:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: override layer.add() method</title>
      <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691982#M15456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't see in the docs where overriding the add() method is not supported. &lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/layers/GraphicsLayer.html#add("&gt;http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/layers/GraphicsLayer.html#add(&lt;/A&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;According to the docs you could add your listeners there, then call super.add(graphic).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I usually try to assign my changes before calling the super.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or you could add a listener in your constructor for com.esri.ags.events.GraphicEvent.GRAPHIC_ADD event and do it that way.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 Mar 2011 17:33:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691982#M15456</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2011-03-26T17:33:33Z</dc:date>
    </item>
    <item>
      <title>Re: override layer.add() method</title>
      <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691983#M15457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So... no takers eh?&amp;nbsp; Bjorn? Dasa? Any suggestions?&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2011 11:22:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691983#M15457</guid>
      <dc:creator>GregKnight</dc:creator>
      <dc:date>2011-03-29T11:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: override layer.add() method</title>
      <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691984#M15458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The GraphicEvent.GRAPHIC_ADD method is probably your best approach. I tried it out and it works on all Selection Modes and gives you access to the graphic when it is added.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
package org.lacsd.layers
{
 import com.esri.ags.Graphic;
 import com.esri.ags.events.GraphicEvent;
 import com.esri.ags.events.GraphicsLayerEvent;
 import com.esri.ags.layers.FeatureLayer;
 import flash.events.MouseEvent;
 import mx.utils.ObjectUtil;
 public class TestFeatureLayer extends FeatureLayer
 {
&amp;nbsp; public function TestFeatureLayer(url:String=null, proxyURL:String=null, token:String=null)
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; super(url, proxyURL, token);
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; this.addEventListener(GraphicEvent.GRAPHIC_ADD, onGraphicAdd);
&amp;nbsp;&amp;nbsp; this.addEventListener(GraphicEvent.GRAPHIC_REMOVE, onGraphicRemove);
&amp;nbsp;&amp;nbsp; this.addEventListener(GraphicsLayerEvent.GRAPHICS_CLEAR, onGraphicsClear);
&amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; private function addListener(graphic:Graphic):void
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; graphic.addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent):void
&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; graphic.useHandCursor = true;
&amp;nbsp;&amp;nbsp;&amp;nbsp; graphic.buttonMode = true;
&amp;nbsp;&amp;nbsp;&amp;nbsp; map.openHandCursorVisible = false;
&amp;nbsp;&amp;nbsp;&amp;nbsp; trace("mouse over"); 
&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; graphic.addEventListener(MouseEvent.MOUSE_OUT, function(event:MouseEvent):void
&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; graphic.useHandCursor = false;
&amp;nbsp;&amp;nbsp;&amp;nbsp; graphic.buttonMode = false;
&amp;nbsp;&amp;nbsp;&amp;nbsp; map.openHandCursorVisible = true;
&amp;nbsp;&amp;nbsp;&amp;nbsp; trace("mouse out");
&amp;nbsp;&amp;nbsp; });
&amp;nbsp;&amp;nbsp; graphic.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void
&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; trace("Click");
&amp;nbsp;&amp;nbsp; })
&amp;nbsp; 
&amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; private function onGraphicAdd(event:GraphicEvent):void
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; trace("graphic has been added", ObjectUtil.toString(event.graphic.attributes));
&amp;nbsp;&amp;nbsp; this.addListener(event.graphic);
&amp;nbsp;&amp;nbsp; // add listeners here
&amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; private function onGraphicRemove(event:GraphicEvent):void
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; trace("graphic has been removed", ObjectUtil.toString(event.graphic.attributes));
&amp;nbsp;&amp;nbsp; // remove listeners here
&amp;nbsp; }
&amp;nbsp; 
&amp;nbsp; private function onGraphicsClear(event:GraphicsLayerEvent):void
&amp;nbsp; {
&amp;nbsp;&amp;nbsp; // may want to find a way to remove listeners here or add them with a weak reference
&amp;nbsp; }
 }
}
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think the reason you can't override the add() method for FeatureLayer is because the internal Relate/Query tasks interact directly with the GraphicsProvider/SelectedFeatures.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:07:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691984#M15458</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-12-12T05:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: override layer.add() method</title>
      <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691985#M15459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;there we go...&amp;nbsp; this is what I was missing:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;this.addEventListener(GraphicEvent.GRAPHIC_ADD, onGraphicAdd);
this.addEventListener(GraphicEvent.GRAPHIC_REMOVE, onGraphicRemove);
this.addEventListener(GraphicsLayerEvent.GRAPHICS_CLEAR, onGraphicsClear);&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Drew was on the right track -- I just wasnt sure how to grab that event in the context of what I was doing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I shall give this a whirl... thank you both!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;greg&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:07:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-flex-questions/override-layer-add-method/m-p/691985#M15459</guid>
      <dc:creator>GregKnight</dc:creator>
      <dc:date>2021-12-12T05:07:34Z</dc:date>
    </item>
  </channel>
</rss>

