Select to view content in your preferred language

Control the "Identify Features" sample with TOC

494
1
11-03-2010 05:49 AM
GISTeam
Deactivated User
Hi all,

I want to modify the "Identify Features" sample to use the dynamic service that is loaded in the begginig of the app and linked to the TOC menu instead of the driect link in <esri:IdentifyTask id="identifyTask"> that it's using now. That way  the users can get to the layer they want by switching off other in the TOC and the Identify it.

I chaged it a bit but I get an RPC error when I try to identify

Here are the changes I made:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:esri="http://www.esri.com/2008/ags"
    layout="vertical"
    styleName="plain"
    pageTitle="Identify Features on the Map">
<!--
    This sample shows how to identify features with a MapClick and the Identify task.

    The IdentifyParameters designate which layers are being identified.
    Identify operations can potentially return a lot of information
    depending on the number of layers being identified and a given tolerance.
    The tolerance is the number of pixels a feature is allowed to lie away
    from the clicked point in order to be counted as a result.

    In this sample, when user clicks the map, an "Identify" task is executed.

    When the task finishes executing, the identifyCompleteHandler function loops
    through the features in the IdentifyResult and adds them to the map.
--> 
    <mx:Script>
        <![CDATA[
            import com.esri.ags.Graphic;
            import com.esri.ags.events.MapMouseEvent;
            import com.esri.ags.geometry.Geometry;
            import com.esri.ags.symbol.InfoSymbol;
            import com.esri.ags.tasks.IdentifyParameters;
            import com.esri.ags.tasks.IdentifyResult;
   import mx.collections.ArrayCollection
            import mx.controls.Alert;
            import mx.rpc.AsyncResponder;
            
            [Bindable]
            private var lastIdentifyResultGraphic:Graphic;
   
   [Bindable]private var DynamicLayer:ArcGISDynamicMapServiceLayer = ArcGISDynamicMapServiceLayer(dynamic1);
   //[Bindable]private var DynamicLayerUrl:String= DynamicLayer.url;
   //[Bindable]private var visibleLayers:ArrayCollection = DynamicLayer.visibleLayers;
   
            private function mapClickHandler(event:MapMouseEvent):void
            {
                clickGraphicsLayer.clear();

                var identifyParams:IdentifyParameters = new IdentifyParameters();
                identifyParams.returnGeometry = true;
                identifyParams.tolerance = 3;
                identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_TOP;
                identifyParams.width = myMap.width;
                identifyParams.height = myMap.height;
                identifyParams.geometry = event.mapPoint;
                identifyParams.mapExtent = myMap.extent;
                identifyParams.spatialReference = myMap.spatialReference;
               
                var clickGraphic:Graphic = new Graphic(event.mapPoint, clickPtSym);
                identifyTask.execute(identifyParams, new AsyncResponder(myResultFunction, myFaultFunction, clickGraphic));
                clickGraphicsLayer.add(clickGraphic);
            }

            private function myResultFunction(results:Array, clickGraphic:Graphic = null):void
            {
                if (results && results.length > 0)
                {
                    var result:IdentifyResult = results[0];
                    var resultGraphic:Graphic = result.feature;
                    switch (resultGraphic.geometry.type)
                    {
                        case Geometry.MAPPOINT:
                        {
                            resultGraphic.symbol = smsIdentify;
                            break;
                        }
                        case Geometry.POLYLINE:
                        {
                            resultGraphic.symbol = slsIdentify;
                            break;
                        }
                        case Geometry.POLYGON:
                        {
                            resultGraphic.symbol = sfsIdentify;
                            break;
                        }
                    }
                    lastIdentifyResultGraphic = resultGraphic;
                    
                    // update clickGraphic (from mouse click to returned feature)
                    clickGraphic.symbol = new InfoSymbol(); // use default renderer
                    clickGraphic.attributes = resultGraphic.attributes;
                }
            }
            
            private function myFaultFunction(error:Object, clickGraphic:Graphic = null):void
            {
                Alert.show(String(error), "Identify Error");
            }
        ]]>
    </mx:Script>

    <!-- start declarations -->
    
        <!-- Symbol for where the user clicked -->
        <esri:SimpleMarkerSymbol id="clickPtSym" style="x" color="0xFF0000" size="12"/>
        
        <!-- Symbol for Identify Result as Polyline -->
        <esri:SimpleLineSymbol id="slsIdentify" style="solid" color="0x00FF00" width="2" alpha="1"/>
    
        <!-- Symbol for Identify Result as Point -->
        <esri:SimpleMarkerSymbol id="smsIdentify" style="diamond" color="0x00FF00" size="15"/>
    
        <!-- Symbol for Identify Result as Polygon -->
        <esri:SimpleFillSymbol id="sfsIdentify"/>
    
        <!-- Identify Task -->
        <esri:IdentifyTask id="identifyTask"
            concurrency="last"
            url="{DynamicLayer}"/>
            
    <!-- end declarations -->

    <esri:Map id="myMap" mapClick="mapClickHandler(event)">
        <esri:extent>
            <esri:Extent xmin="-120" ymin="30" xmax="-100" ymax="50">
                <esri:SpatialReference wkid="4326"/>
            </esri:Extent>
        </esri:extent>
        <esri:ArcGISTiledMapServiceLayer id="dynamic1"
            url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
        <esri:GraphicsLayer graphicProvider="{lastIdentifyResultGraphic}"/>
        <esri:GraphicsLayer id="clickGraphicsLayer"/>
    </esri:Map>
    
</mx:Application>
Tags (2)
0 Kudos
1 Reply
DasaPaddock
Esri Regular Contributor
The IdentifyTask url needs to be a String. You can use layerOption = "all" and set the layerIds to the layers that are turned on in the TOC to control which layers are identified:
http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/tasks/supportClasses/IdentifyParameters.ht...
0 Kudos