Select to view content in your preferred language

Identify using a layer definition at version 1.3?

967
5
06-28-2010 05:39 PM
IanParfitt
Deactivated User
Hi there-

I'm using a definition query on an arcgis service before it is added as a layer to the map, which works fine, and would like to then use the identify tool to select from the this subset of the original data.  Unfortunately, the identify tool selects against the full layer, not the one resulting from the definition query.  I notice that IdentifyParameters includes a LayerDefinition property in API 2.0, but not in 1.3 (which I'm using).  Is there any way to pre-select the records (same as the definition query) in the Identify task somehow at 1.3?   Ideally I'd like to access the original layerdef array that I define in MapManager to do this.

Thanks for any help

Ian
Tags (2)
0 Kudos
5 Replies
DasaPaddock
Esri Regular Contributor
The ArcGIS Server Identify operation added support for layerDefs at version 10.
http://sampleserver3.arcgisonline.com/ArcGIS/SDK/REST/identify.html

If you're using ArcGIS Server 10 with ArcGIS API for Flex 1.3, you can append the layerDefs url parameter to the url you set on the IdentifyTask and it will be included in the request.
0 Kudos
IanParfitt
Deactivated User
I am using version 9.3.1. .  Are there any other options?

Thanks

Ian
0 Kudos
IanParfitt
Deactivated User
The ArcGIS Server Identify operation added support for layerDefs at version 10.
http://sampleserver3.arcgisonline.com/ArcGIS/SDK/REST/identify.html

If you're using ArcGIS Server 10 with ArcGIS API for Flex 1.3, you can append the layerDefs url parameter to the url you set on the IdentifyTask and it will be included in the request.


I've installed version 10, but have not discovered how to append the layerDefs url parameter to the url set on the IdentifyTask.   The final url with all parameters, which I'd like to append to, seems to be created by the execute method - if I try to append my layerDefs to the url used when creating the IndentifyTask object it appears before the /indentify part of the url, instead of after.  Could you please provide a snippet of example code for your solution.

Thanks
Ian Parfitt
UBC Geography
0 Kudos
DasaPaddock
Esri Regular Contributor
Here's an example. I've modified IdentifySample.mxml to use a 10.0 service.

<?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">

    <mx:Script>
        <![CDATA[
            import com.esri.ags.Graphic;
            import com.esri.ags.events.MapMouseEvent;
            import com.esri.ags.symbol.InfoSymbol;
            import com.esri.ags.tasks.IdentifyParameters;
            import com.esri.ags.tasks.IdentifyResult;

            import mx.controls.Alert;
            import mx.rpc.AsyncResponder;
            
            private function mapClickHandler(event:MapMouseEvent):void
            {
                clickGraphicsLayer.clear();

                var identifyParams:IdentifyParameters = new IdentifyParameters();
                identifyParams.returnGeometry = true;
                identifyParams.tolerance = 3;
                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;
                    
                    // 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"/>
        
        <!-- Identify Task -->
        <esri:IdentifyTask id="identifyTask"
            concurrency="last"
            url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/EarthquakesFromLastSevenDays/MapServer?layerDefs=0:magnitude &gt; 5"/>
    <!-- end declarations -->

    <esri:Map id="myMap" mapClick="mapClickHandler(event)" openHandCursorVisible="false">
        <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer"/>
        <esri:ArcGISDynamicMapServiceLayer url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/EarthquakesFromLastSevenDays/MapServer">
            <esri:layerDefinitions>
                <mx:String>magnitude &gt; 5</mx:String>
            </esri:layerDefinitions>
        </esri:ArcGISDynamicMapServiceLayer>
        <esri:GraphicsLayer id="clickGraphicsLayer"/>
    </esri:Map>

</mx:Application>
0 Kudos
IanParfitt
Deactivated User
Thanks Dasa.  I'm working with simple flex viewer, so I've added your declarations to the IdentifyWidget.mxml.   If I hard code in the layerdefs, then this works - however I want to use the URL to pass parameters to use (I'm working with large species databases - URL passes selected species, want to have the identify only working with the selected species - e.g. 'Aster borealis').   When I attempt to concatenate the URL string in the declaration section I get errors, if I attempt to use a variable instead of a string I get errors.   Essentially I need to build the layerdefs query parameter as a variable instead of the hard-coded example.   See attached.
0 Kudos