Identifytask features:
- Multi-layer query supported
- The returned field cannot be specified.
- Only property information can be queried, and space information cannot be queried.
- Interaction Process with users
Steps:
- Create an identifytask class
- Create identifyparameters class
- Execute the identifytask method Execute
- Receive and Display Results
Sample Code:
<? 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: SCRIPT>
<! [CDATA [
Import com. ESRI. AGS. Graphic;
Import com. ESRI. AGS. Events. identifyevent;
Import com. ESRI. AGS. Events. mapmouseevent;
Import com. ESRI. AGS. Geometry. mappoint;
Import com. ESRI. AGS. symbols. infosymbol;
Import com. ESRI. AGS. Tasks. supportclasses. identifyresult;
Import MX. rpc. asyncresponder;
Protected function mymap_mapclickhandler (Event: mapmouseevent): void // map mapclick event
{
VaR point: mappoint = event. mappoint; // obtain the mappoint from the map mapclick event parameter event.
VaR grahic: graphic = new graphic (point); // use a vertex as a parameter to construct a graphic
Mygraphicslayer. Clear (); // clear graphicslayer content
// Construct the identifyparameters Parameter
Myparameters. DPI = 96; // 96 pixels per inch, resolution
Myparameters. Height = mymap. height; // value map height
Myparameters. width = mymap. width; // value map width
Myparameters. layeroption = identifyparameters. layer_option_all; // query all layers
Myparameters. Tolerance = 3; // margin difference
Myparameters. mapextent = mymap. extent; // value range of the map
Myparameters. spatialreference = mymap. spatialreference; // map space reference
Myparameters. Geometry = grahic. geometry; // you can specify the value of graphic when a map is clicked.
Myparameters. returngeometry = true; // returns the ry.
Identifytask.exe cute (myparameters, new asyncresponder (onok, onerr, point) // executes the execute method of identify and transmits the point as a parameter.
}
Protected function onok (OBJ: array, Token: mappoint): void // obj is defined as a data, because multiple clicks will generate multiple identifyresults
{
For each (VAR identifyresult: identifyresult in OBJ) // traverses the identifyresult object in OBJ.
{
VaR pointgraphic: graphic = new graphic (token); // click a point on the map to construct a graphic object.
Pointgraphic. Attributes = identifyresult. feature. attributes; // copy the attribute of the feature obtained after an identify operation.
Pointgraphic. symbol = new infosymbol (); // This point is signed. Note that there is no difference between the infosymbol object and the image or the symbol.
Mygraphicslayer. Add (pointgraphic); // Add
VaR newgraphic: graphic = identifyresult. feature; // obtain the feature obtained after identify execution
Mygraphicslayer. Add (newgraphic); // Add the obtained feature to graphic
}
}
Protected function onerr (OBJ: object, Token: Object): void
{
}
]>
</FX: SCRIPT>
<FX: declarations>
<! -- Place non-visual elements (e.g., services, value objects) Here -->
<ESRI: identifytask id = "identifytask" url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer" showbusycursor = "true"/>
<ESRI: identifyparameters id = "myparameters"/>
</FX: declarations>
<ESRI: Map id = "mymap" mapclick = "mymap_mapclickhandler (event)">
<ESRI: arcgistiledmapservicelayer url = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
<ESRI: graphicslayer id = "mygraphicslayer"/>
</ESRI: Map>
</S: Application>