arcgis api for flex 开发入门(八)GP服务的使用

在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服
务,得到结果,表现结果。

完整代码:

<?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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值