服务有CreateDriveTimePolygons和Viewshed,下面我们以
CreateDriveTimePolygons服务为例来看看在arcgis api for flex中如何使用GP
服务。
首先使用 <esri:Geoprocessor >标签创建一个gp服务,url指向提供gp服务的
地址。
<esri:Geoprocessor id="gp"
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Network
/ESRI_DriveTime_US/GPServer/CreateDriveTimePolygons" />
剩下的步骤和上一讲Geometry service的使用基本相同,即设置参数,调用gp服
务,得到结果,表现结果。
完整代码:
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 calls computeServiceArea
(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 the
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.execute(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>
<?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 calls computeServiceArea
(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 the
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.execute(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>
原文地址:http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=35700&extra=page%3D4%26amp%3Borderby%3Ddateline
本文转自温景良(Jason)博客园博客,原文链接:http://www.cnblogs.com/wenjl520/archive/2009/06/02/1494575.html,如需转载请自行联系原作者