@H_
197_18@
@H_
197_18@启发来源于
http://blog.csdn.net/qq364981997/article/details/8769388
@H_
197_18@
http://www.cnblogs.com/potential/archive/2012/11/03/2752289.html
@H_
197_18@
@H_
197_18@写
代码之前制作模型,这里使用的是ArcTutor\GP
service Examples\BufferPoints。
@H_
197_18@
![silverlight调用GP服务实现缓冲区 silverlight调用GP服务实现缓冲区](http://img.voidcn.com/vcimg/static/loading.png)
@H_
197_18@也可以根据
http://help.arcgis.com/zh-cn/arcgisdesktop/10.0/help/index.html#//002v00000014000000自己做数据。做完之后测试一下。
@H_
197_18@前端
代码:
<UserControl x:Class="GPBuffer.MainPage"
xmlns="http://scheR_363_11845@as.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://scheR_363_11845@as.microsoft.com/winfx/2006/xaml"
xmlns:d="http://scheR_363_11845@as.microsoft.com/expression/blend/2008"
xmlns:esri="http://scheR_363_11845@as.esri.com/arcgis/client/2009"
xmlns:mc="http://scheR_363_11845@as.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" BACkground="White">
<Grid.resources>
<esri:PictuREMARKerSymbol x:Key="DefaultClickSymbol" OffsetX="11" OffsetY="39" source="/car-red-16x16.png" />
<esri:SimpleFillSymbol x:Key="DefaultBufferSymbol" Fill="#660000FF" BorderBrush="Blue" BorderThickness="2" />
</Grid.resources>
<esri:Map x:Name="Mymap" BACkground="White"
MouseClick="Mymap_MouseClick" >
<esri:ArcGISDynamicMapserviceLayer ID="buffer"
Url="http://localhost/arcgis/rest/services/bufferpoint/MapServer"/>
<esri:GraphicsLayer ID="MyGraphicsLayer">
</esri:GraphicsLayer>
</esri:Map>
<Grid HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,0" >
<Rectangle Fill="#77919191" stroke="Gray" RadiusX="10" RadiusY="10" Margin="0,5" >
<Rectangle.Effect>
<DropShadowEffect/>
</Rectangle.Effect>
</Rectangle>
<Rectangle Fill="#FFFFFFFF" stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,15" />
<TextBlock x:Name="Informationtext" Text="Click on map to set a LOCATIOn. A buffer of 1000 meters will be displayed."
Width="200" Margin="30,20,30,25" HorizontalAlignment="Left" textwrapping="Wrap" />
</Grid>
</Grid>
</UserControl>
@H_
197_18@
@H_
197_18@
后台代码:
@H_
197_18@using Sy
stem;
using Sy
stem.Collection
s.Generi
c; using Sy
stem.Linq;
using Sy
stem.Net;
using Sy
stem.Windows;
using Sy
stem.Window
s.Controls;
using Sy
stem.Window
s.Documents;
using Sy
stem.Window
s.Input;
using Sy
stem.Window
s.Media;
using Sy
stem.Window
s.Media.Animation;
using Sy
stem.Window
s.Shapes;
@H_
197_18@using ESRI.ArcGI
s.CLIENt;
using ESRI.ArcGI
s.CLIENt.Tasks;
using ESRI.ArcGI
s.CLIENt.S
ymbols;
@H_
197_18@namespace GPBuffer
{ public partial class MainPage : UserControl
{ Geoprocessor _geoprocessorTask;
public MainPage()
{ InitializeComponent(
); _geoprocessorTask = new Geoprocessor("
http://localhost/arcgis/rest/services/bufferpoint/GPServer/Buffer%20Points"
); _geoprocessorTask.JobCompleted += new EventHandler<JobInfoEventArgs>(_geoprocessorTask_JobCompleted
); _geoprocessorTask.GetResultDataCompleted += new EventHandler<GPParameterEventArgs>(_geoprocessorTask_GetResultDataCompleted
); _geoprocessorTask.
Failed += new EventHandler<Task
FailedEventArgs>(_geoprocessorTask_
Failed); }
@H_
197_18@
void _geoprocessorTask_
Failed(ob
ject sender,Task
FailedEventArgs
E) { message
Box.Show("请求服务失败:" + e.Error.To
String()
); }
@H_
197_18@
void _geoprocessorTask_GetResultDataCompleted(ob
ject sender,GPParameterEventArgs
E) { GraphicsLayer graphicsLayer = new GraphicsLayer(
); GPFeatureRecordSetLayer featureSetLayer = e.Parameter as GPFeatureRecordSetLayer;
foreach (Graphic graphic in featureSetLayer.FeatureSet.Features)
{ graphic.S
ymbol = LayoutRoot.
resources["DefaultBufferS
ymbol"] as S
ymbol;
graphicsLayer.Graphic
s.Add(graphic
); }
M
ymap.Layer
s.Add(graphicsLayer
); message
Box.Show("
********************"
); }
@H_
197_18@
void _geoprocessorTask_JobCompleted(ob
ject sender,JobInfoEventArgs
E) { if (e.JobInfo.JobStatus == esriJobStatu
s.esriJob
Failed)
{ message
Box.Show("请求服务失败:"+e.JobInfo.
message
s.To
String()
); return;
}
httpWeb
request.RegisterPrefix("
http://",System.Net.Browser.WebRequestCreator.ClientHttp); _geoprocessorTask.GetResultDataAsync(e.JobInfo.JobId,"Output_Polygons"
); }
private void M
ymap_MouseClick(ob
ject sender,ESRI.ArcGI
s.CLIENt.Map.MouseEventArgs
E) { GraphicsLayer graphicsLayer = M
ymap.Layers["MyGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics(
);
@H_
197_18@
e.MapPoint.SpatialReference = M
ymap.SpatialReference;
Graphic graphic = new Graphic()
{ Geometry=e.MapPoint,
S
ymbol=LayoutRoot.
resources["DefaultClickS
ymbol"] as S
ymbol
};
graphic.SetZIndex
(1);
graphicsLayer.Graphic
s.Add(graphic
);
@H_
197_18@
List<GPParameter> parameters = new List<GPParameter>(
); parameter
s.Add(new GPFeatureRecordSetLayer("Input_Points",e.MapPo
int)); parameter
s.Add(new GPLinearUnit("Distance",esriUnit
s.esriMeters,1000)
);
@H_
197_18@
_geoprocessorTask.SubmitJobAsync(parameters
); }
@H_
197_18@
//void _geoprocessorTask_
Failed(ob
ject sender,Task
FailedEventArgs
E) //
{ //
message
Box.Show("Geoprocessing
service
Failed: " + e.Error
); //}
@H_
197_18@
//void _geoprocessorTask_ExecuteCompleted(ob
ject sender,GPExecuteCompleteEventArgs
E) //
{ // GraphicsLayer graphicsLayer = M
ymap.Layers["MyGraphicsLayer"] as GraphicsLayer;
@H_
197_18@
// foreach (GPParameter parameter in e.Result
s.OutParameters)
//
{ //
if (parameter is GPFeatureRecordSetLayer)
//
{ //
GPFeatureRecordSetLayer gpLayer = parameter as GPFeatureRecordSetLayer;
@H_
197_18@
//
foreach (Graphic graphic in gpLayer.FeatureSet.Features)
//
{ //
graphic.S
ymbol = LayoutRoot.
resources["DefaultBufferS
ymbol"] as S
ymbol;
//
graphicsLayer.Graphic
s.Add(graphic
); //
}
//
}
// }
//}
}
}
@H_
197_18@
@H_
197_18@注释掉的是同步执行的
方法,但是好像不管用
@H_
197_18@下图是Buffer GP服务的详细信息。
@H_
197_18@
![silverlight调用GP服务实现缓冲区 silverlight调用GP服务实现缓冲区](http://img.voidcn.com/vcimg/static/loading.png)
@H_
197_18@结果:
@H_
197_18@
![silverlight调用GP服务实现缓冲区 silverlight调用GP服务实现缓冲区](http://img.voidcn.com/vcimg/static/loading.png)