十,Find and Identity
identifyTask,属性:concurrency:并行执行的设定(last,single,multi)
url:指定的是一个图层的MapServer
identifyTask查询:identifyParams.geometry = event.mapPoint;
identifyParams.tolerance = 3;//公差
identifyTask.execute(identifyParams, new AsyncResponder(myResultFunction, myFaultFunction, clickGraphic));
查询结果:返回的结果只有一个graphic
var result:IdentifyResult = results[0];
var resultGraphic:Graphic = result.feature;
I查询,最常用的geometry就是一个点。
<?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:esri="http://www.esri.com/2008/ags"
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 executeCompleteHandler function loops
through the features in the IdentifyResult and adds them to the map.
-->
<fx:Script>
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.events.MapMouseEvent;
import com.esri.ags.geometry.Geometry;
import com.esri.ags.symbols.InfoSymbol;
import com.esri.ags.tasks.supportClasses.IdentifyParameters;
import com.esri.ags.tasks.supportClasses.IdentifyResult;
import mx.controls.Alert;
import mx.rpc.AsyncResponder;
[Bindable]private var lastIdentifyResultGraphic:Graphic;
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);
clickGraphicsLayer.add(clickGraphic);
identifyTask.execute(identifyParams, new AsyncResponder(myResultFunction, myFaultFunction, 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");
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Symbol for where the user clicked -->
<esri:SimpleMarkerSymbol id="clickPtSym"
color="0xFF0000"
size="12"
style="x"/>
<!-- Symbol for Identify Result as Polyline -->
<esri:SimpleLineSymbol id="slsIdentify"
width="2"
alpha="1"
color="0x00FF00"
style="solid"/>
<!-- Symbol for Identify Result as Point -->
<esri:SimpleMarkerSymbol id="smsIdentify"
color="0x00FF00"
size="15"
style="diamond"/>
<!-- Symbol for Identify Result as Polygon -->
<esri:SimpleFillSymbol id="sfsIdentify"/>
<!-- Identify Task -->
<esri:IdentifyTask id="identifyTask"
concurrency="last"
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer"/>
</fx:Declarations>
<esri:Map id="myMap"
mapClick="mapClickHandler(event)"
openHandCursorVisible="false">
<esri:extent>
<esri:WebMercatorExtent minlon="-120" minlat="30" maxlon="-100" maxlat="50"/>
</esri:extent>
<esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
<esri:GraphicsLayer graphicProvider="{lastIdentifyResultGraphic}"/>
<esri:GraphicsLayer id="clickGraphicsLayer"/>
</esri:Map>
</s:Application>
FindTask的url是MapServer.
FindTask查询:通过对FindParameters的searchText进行字符匹配来查询。
searchText展示的是图层的展示字段。
findTask.execute(myFindParams);
返回:数组。
findTask.executeLastResult
<?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"
xmlns:esri="http://www.esri.com/2008/ags"
pageTitle="Find features in Map Layers">
<!--
This sample shows how to search the data using the find task:
The FindParameters designate which layers and fields will be searched.
If multiple layers contain the same field name (for example "NAME")
both fields will be searched.
Note that in this example returnGeometry is set to true so that the results
can be displayed on the map.
The searchText of the FindParameters is what the task will search for.
This text comes from the input box and is sent to the execute function when
the user click the Find button. This line executes the task:
findTask.execute(myFindParams);
When the task finishes executing, the executeCompleteHandler function loops
through the array of graphics in the FindResult and adds each graphic to the map.
The datagrid at the bottom gets its content directly from the task:
dataProvider="{findTask.executeLastResult}"
-->
<s:layout>
<s:VerticalLayout horizontalAlign="center"/>
</s:layout>
<fx:Script>
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.events.FindEvent;
import com.esri.ags.geometry.Geometry;
private function doFind():void
{
findTask.execute(myFindParams);
}
private function executeCompleteHandler(event:FindEvent):void
{
myGraphicsLayer.clear();
var graphic:Graphic;
resultSummary.text = "Found " + event.findResults.length + " results.";
var resultCount:int = event.findResults.length;
for (var i:Number = 0; i < resultCount; i++)
{
graphic = event.findResults[i].feature;
graphic.toolTip = event.findResults[i].foundFieldName + ": " + event.findResults[i].value;
switch (graphic.geometry.type)
{
case Geometry.MAPPOINT:
{
graphic.symbol = smsFind;
break;
}
case Geometry.POLYLINE:
{
graphic.symbol = slsFind;
break;
}
case Geometry.POLYGON:
{
graphic.symbol = sfsFind;
break;
}
}
myGraphicsLayer.add(graphic);
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Symbol for Find Result as Polyline -->
<esri:SimpleLineSymbol id="slsFind"
width="3"
alpha="0.9"
color="0xFFFF00"
style="solid"/>
<!-- Symbol for Find Result as Point -->
<esri:SimpleMarkerSymbol id="smsFind"
alpha="0.9"
color="0xFFFF00"
size="11"
style="square">
<esri:SimpleLineSymbol color="0x000000"/>
</esri:SimpleMarkerSymbol>
<!-- Symbol for Find Result as Polygon -->
<esri:SimpleFillSymbol id="sfsFind"
alpha="0.7"
color="0xFFFF00"/>
<!-- Find Task -->
<esri:FindTask id="findTask"
executeComplete="executeCompleteHandler(event)"
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer"/>
<esri:FindParameters id="myFindParams"
contains="true"
layerIds="[0,1,2]"
outSpatialReference="{map.spatialReference}"
returnGeometry="true"
searchFields="[CITY_NAME,NAME,SYSTEM,STATE_ABBR,STATE_NAME]"
searchText="{fText.text}"/>
</fx:Declarations>
<s:BorderContainer width="100%" height="40"
backgroundColor="0xDDDDFF">
<s:layout>
<s:HorizontalLayout horizontalAlign="center" verticalAlign="middle"/>
</s:layout>
<s:Label text="Search for names of States, Cities, and Rivers:"/>
<s:TextInput id="fText"
enter="doFind()"
maxWidth="400"
text="Paradise"/>
<s:Button click="doFind()" label="Find"/>
</s:BorderContainer>
<s:Label id="resultSummary" height="15"/>
<mx:VDividedBox width="100%" height="100%">
<esri:Map id="map">
<esri:extent>
<esri:Extent xmin="-126" ymin="24" xmax="-67" ymax="50">
<esri:SpatialReference wkid="4326"/>
</esri:Extent>
</esri:extent>
<esri:ArcGISDynamicMapServiceLayer url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer"/>
<esri:GraphicsLayer id="myGraphicsLayer"/>
</esri:Map>
<mx:DataGrid width="100%" height="40%"
dataProvider="{findTask.executeLastResult}">
<mx:columns>
<mx:DataGridColumn width="70"
dataField="layerId"
headerText="Layer ID"/>
<mx:DataGridColumn dataField="layerName" headerText="Layer Name"/>
<mx:DataGridColumn dataField="foundFieldName" headerText="Found Field Name"/>
<mx:DataGridColumn dataField="value" headerText="Found Field Value"/>
</mx:columns>
</mx:DataGrid>
</mx:VDividedBox>
</s:Application>