Select to view content in your preferred language

feature layer graphicprovider

3958
10
09-28-2010 08:01 AM
abukhan
Occasional Contributor
I have a feature layer and i use its graphicprovider to access the graphics..

First time i use a definition expression to limit my output and get the graphics..

Next time I change the definitiondexpression to get features and this time graphicsprovider does not return any value..

Why I am not getting any value from the graphicsprovider???

Is there anyway to get the return graphics from this feature layer with the new definitionexpression?

Thanks...
Tags (2)
0 Kudos
10 Replies
DasaPaddock
Esri Regular Contributor
Wait for the next LayerEvent.UPDATE_END event.
0 Kudos
abukhan
Occasional Contributor
i think it is happening because of the onDemand mode and the current viewport is not in the definitionexpression area...

Snapshot mode works fine..



Note first time onDemand mode, it zoom to the extent of the queried area(say example some parts of California).
second time I put a different definitionexpression (say some parts in Florida and this area is not in the current viewport),
then it can not get to the extent of the queried area...

But If I pan to the new queried area(parts of Florida), I can see the new area is drawn(I think the drawing of these graphics are happening after the panning to the new area on demand)

Is there a way to zoom to the extent of the new definitionexpression area in the OnDemand mode
without user needs to pan to the new area?
0 Kudos
DasaPaddock
Esri Regular Contributor
Not in onDemand mode since it only queries for features within the current extent so there's no way to know what the extent is of all the features matching the new definition expression. I'd stick with snapshot mode and then you can zoom to the extent of the features in the graphicProvider after updateEnd.
0 Kudos
AmyRamsdell
Occasional Contributor
I am pretty sure that I am using this updateEnd wrong. I am trying to do the same with a featurelayer that has around 500 polys, they are counties at a national level. My counties feature layer is set to snapshot mode. But when I set the definition expression  I cannot use the graphicsprovider to zoom to the extent. The graphicsprovider is null if I add the code to locateBoundary function but if I add it to the updateEnd event handler, it never fires. Any insight for my bleary eyes?

private function locateBoundary(event:Event) : void 
{
 layerCOUNTIES.definitionExpression = "STATE = '" + (event.currentTarget as TextArea).data.STATEFP + "'";
}

private function zoomToExtent(event: Event) : void {
 var graphicProvider:ArrayCollection = layerCOUNTIES.graphicProvider as ArrayCollection;
 var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());
 mainMap.extent = graphicsExtent.expand(1.1); // zoom out a little
}

  <esri:FeatureLayer id="layerCOUNTIES"
         visible="false"
         useAMF="false" 
         symbol="{featurePolySym}"
         useHandCursor="true"
         buttonMode="true" 
         mode="snapshot"
         outFields="[NAME,COUNTY,STATE]"
         alpha="0.6" 
         updateEnd="zoomToExtent(event)"
         graphicAdd="featureLayerGraphicAddHandler(event)"
         />
0 Kudos
DasaPaddock
Esri Regular Contributor
Try setting the layer's visibility to true. It won't update itself if visible is false.
0 Kudos
tanyabisen
Emerging Contributor
Hello Dasa,

I tried using updateEnd event but for me the map zooms to the location and zooms out immediately.
I am not understanding what could be the issue.Here is my code:

private function initApp():void{
if(FlexGlobals.topLevelApplication.parameters.ward_number != undefined){
     fLayer.definitionExpression = "Ward_No = " + FlexGlobals.topLevelApplication.parameters.ward_number;
    }
   }

private function zoomToExtent(event: Event) : void {
    var graphicProvider:ArrayCollection = fLayer.graphicProvider as ArrayCollection;
    var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());
    myMap.extent = graphicsExtent.expand(1.1); // zoom out a little
   }

<esri:FeatureLayer id="fLayer"  graphicAdd="fLayer_graphicAddHandler(event)"
         load="{initApp()}"
         symbol="{mySymbol}"
         updateEnd="zoomToExtent(event)"
         mode="snapshot"
         outFields="[Ward_No,Ward_Name]"
         url="http://124.153.103.152/ArcGIS/rest/services/Find_your_Ward/MapServer/0"/>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Tanya,

   This code works for me:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               minWidth="955" minHeight="600"
               xmlns:esri="http://www.esri.com/2008/ags">
    <fx:Declarations>
        <esri:SimpleFillSymbol id="mySymbol"
                               alpha="1"
                               color="0xff0000"
                               style="solid">
            <esri:SimpleLineSymbol width="1"
                                   alpha="1"
                                   color="0x000000"
                                   style="solid"/>
        </esri:SimpleFillSymbol>
    </fx:Declarations>
    
    <fx:Script>
        <![CDATA[
            import com.esri.ags.geometry.MapPoint;
            import com.esri.ags.events.GraphicEvent;
            import com.esri.ags.events.LayerEvent;
            import com.esri.ags.geometry.Extent;
            import com.esri.ags.utils.GraphicUtil;
            
            import mx.collections.ArrayCollection;
            
            private function initApp():void{
                //if(FlexGlobals.topLevelApplication.parameters.ward_number != undefined){
                fLayer.definitionExpression = "Ward_No = 192"; //+ FlexGlobals.topLevelApplication.parameters.ward_number;
                //}
                fLayer.addEventListener(LayerEvent.UPDATE_END, zoomToExtent);
                fLayer.refresh();
            }
            
            private function zoomToExtent(event: Event) : void {
                fLayer.removeEventListener(LayerEvent.UPDATE_END, zoomToExtent);
                fLayer = event.currentTarget as FeatureLayer;
                var graphicProvider:ArrayCollection = fLayer.graphicProvider as ArrayCollection;
                var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());
                if(graphicsExtent){
                    myMap.extent = graphicsExtent.expand(1.1); 
                    fLayer.refresh();
                }else if (graphicProvider.length == 1){
                    var mapPoint:MapPoint = graphicProvider[0].geometry as MapPoint;
                    myMap.zoom(1 / 16, mapPoint);
                }
            }
            
            protected function fLayer_graphicAddHandler(event:GraphicEvent):void
            {
                // TODO Auto-generated method stub
                
            }
            
        ]]>
    </fx:Script>
    <esri:Map id="myMap">
        <esri:extent>
            <esri:Extent xmax="77.7843275260001" xmin="77.4601488560001" ymax="13.1465311620001" ymin="12.8337825080001">
                <esri:SpatialReference wkid="4326"/>
            </esri:Extent>
        </esri:extent>
        <esri:FeatureLayer id="fLayer" graphicAdd="fLayer_graphicAddHandler(event)"
                           load="{initApp()}"
                           symbol="{mySymbol}"
                           mode="snapshot"
                           outFields="[Ward_No,Ward_Name]"
                           url="http://124.153.103.152/ArcGIS/rest/services/Find_your_Ward/MapServer/0"/>
    </esri:Map>
</s:Application>
0 Kudos
tanyabisen
Emerging Contributor
Thanks Robert..

It works.. but can you please explain as to why when I was giving the the same update end event in mxml it didnt work but you just made few chnages in actionscript and it worked..

Would love if you can explain me that concept.

Thanks again
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Tanya,

   It all has to do with timing. I add the event listener after the layer is loaded and then call refresh and when the listener is called I remove it as you only want this event to fire the first time you load the map.
0 Kudos