在arcgis api for flex中esri还为我们提供了GP服务,在ARCGISONLINE 上的gp
服务有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>原文地址:
http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=35700&extra=page%3D4%26amp%3Borderby%3Ddateline
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?