In arcgis api for flex, esri also provides the GP service for us
The services include CreateDriveTimePolygons and Viewshed.
The CreateDriveTimePolygons service is used as an example to see how to use GP in arcgis api for flex.
Service.
First, use the <esri: Geoprocessor> label to create a gp service. The url points to
Address.
<Esri: Geoprocessor id = "gp"
Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Network
/ESRI_DriveTime_US/GPServer/CreateDriveTimePolygons "/>
The remaining steps are basically the same as the previous usage of Geometry service, that is, to set parameters and call the gp Server
Service, get the results, and show the results.
Complete code:
Code
<? Xml version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: mx = "http://www.adobe.com/2006/mxml"
PageTitle = "Service Area"
Xmlns: esri = "http://www.esri.com/2008/ags"
Layout = "absolute"
>
<Mx: Script>
<! [CDATA [
// Synopsis:
// The map has a click event that callcomputeservicearea
(Event) when you click the map
// <Esri: Map click = "computeServiceArea (event)">
// The computeServiceArea function sends a request to a GP
Task to create the geometries for the different drive times
// The return drivetime features are used as
GraphicProvider for a graphics layer.
// GraphicsLayer. graphicProvider = fs. features;
// The graphics layer is using a symbolFunction which will
Symbolize the drivetimes in different colors
// <Esri: GraphicsLayer id = "graphicsLayer"
SymbolFunction = "fillFunc"/>
// The fillFunc () is using the "ToBreak" attributes, which
The GP task returned, to set different symbols on different drive
Times.
Import com. esri. ags. Graphic;
Import com. esri. ags. symbol. Symbol;
Import com. esri. ags. tasks. ExecuteResult;
Import com. esri. ags. tasks. FeatureSet;
Import com. esri. ags. tasks. ParameterValue;
Import com. esri. ags. geometry. MapPoint;
Import com. esri. ags. geometry. Geometry;
Import mx. controls. Alert;
Import mx. rpc. AsyncResponder;
Import mx. utils. ObjectUtil;
Private var driveTimes: String = "1 2 3 ";
Private function computeServiceArea (event: MouseEvent ):
Void
{
GraphicsLayer. clear ();
Var mapPoint: MapPoint = myMap. toMapFromStage
(Event. stageX, event. stageY );
Var graphic: Graphic = new Graphic (mapPoint,
Sms_circleAlphaSizeOutline );
GraphicsLayer. add (graphic );
Var featureSet: FeatureSet = new FeatureSet ([graphic]);
Var params: Object = {
"Input_Location": featureSet,
"Drive_Times": driveTimes
};
Gp.exe cute (params, new AsyncResponder (onResult,
OnFault ));
Function onResult (
GpResult: ExecuteResult,
Token: Object = null
): Void
{
Var pv: ParameterValue = gpResult. parameterValues
[0];
Var fs: FeatureSet = pv. value as FeatureSet;
GraphicsLayer. graphicProvider = fs. features;
}
Function onFault (info: Object, token: Object = null
): Void
{
Alert. show (info. toString ());
}
}
Private function fillFunc (g: Graphic): Symbol
{
Var toBreak: Number = g. attributes. ToBreak;
If (toBreak = 1)
{
Return rFill;
}
If (toBreak = 2)
{
Return gFill;
}
Return bFill;
}
]>
</Mx: Script>
<Esri: SimpleMarkerSymbol id = "sms_circleAlphaSizeOutline"
Alpha = "0.5" size = "15" style = "circle"/>
<Esri: SimpleFillSymbol id = "rFill" alpha = "0.5" color = "0xFF0000"/>
<Esri: SimpleFillSymbol id = "gFill" alpha = "0.5" color = "0x00FF00"/>
<Esri: SimpleFillSymbol id = "bFill" alpha = "0.5" color = "0x0000FF"/>
<Esri: Map id = "myMap" click = "computeServiceArea (event )"
OpenHandCursorVisible = "false">
<Esri: extent>
<Esri: Extent xmin = "-95.41" ymin = "38.86" xmax = "-95.1"
Ymax= "39.06"/>
</Esri: extent>
<Esri: ArcGISTiledMapServiceLayer
Url = "http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap
_ World_2D/MapServer "/>
<Esri: GraphicsLayer id = "graphicsLayer"
SymbolFunction = "fillFunc"/>
</Esri: Map>
<Esri: Geoprocessor
Id = "gp"
Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Network
/ESRI_DriveTime_US/GPServer/CreateDriveTimePolygons"
/>
</Mx: Application>
Original address: http://bbs.esrichina-bj.cn/ESRI/viewthread.php? Tid = 35700 & extra = page % 3D4% 26amp % 3 Borderby % 3 Ddateline