一、首先保证能有一个Geometry Service类型的服务,如何新建该服务,步骤如下:开始------>ArcGIS------>ArcGIS Server for the Microsoft .NET Framework------->ArcGIS Server Manager------->进入登录页面后,我们输入登录名和密码,登录名,例如:PC-201306130927\ArcGISSom(PC-201306130927=第一个为计算机名称),
看到主界面后:
二、有了此服务后,我们要做两件事,1添加代码,2、经纬度定位提示图标。 代码 :
public voID JWDDW(string XString,string YString) { try { double x; double y; try { x = Convert.Todouble(XString); y = Convert.Todouble(YString); } catch (Exception ex) { _errorLog.InsertErrorLogfileAsync("JWDDW_不是有效的经纬度",ex.ToString()); return; } //投影服务 GeometryService geoService = new GeometryService("http://pc-201306130927/ArcGIS/rest/services/Geometry/GeometryServer"); geoService.ProjectCompleted += new EventHandler<GraphicsEventArgs>(geoService_ProjectCompleted); geoService.Failed += new EventHandler<TaskFailedEventArgs>(geoService_Failed); MapPoint inputMapPoint = new MapPoint(x,y,new SpatialReference(4326)); geoService.ProjectAsync(new List<Graphic>() { new Graphic() { Geometry = inputMapPoint } },yzxfMap.SpatialReference,inputMapPoint); } catch (Exception ex) { _errorLog.InsertErrorLogfileAsync("JWDDW",ex.ToString()); ex.ToString(); } }其中有两个地方需要说明一下:1,投影服务,就是我们刚刚创建的服务地址,。2、有两个事件我们需要创建geoService_ProjectCompleted和geoService_Failed(第一个事件方法是用来初始化数据用的,第一个是错误提示) a、
private Graphicslayer firePointLayer = new Graphicslayer(); voID geoService_ProjectCompleted(object sender,GraphicsEventArgs e) { try { firePointLayer.Cleargraphics(); Graphic resultGraphic = e.Results[0]; if (resultGraphic.Geometry.Extent != null) { resultGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as Symbol; MapPoint resultMapPoint = resultGraphic.Geometry as MapPoint; resultGraphic.Attributes.Add("ID","0"); resultGraphic.Attributes.Add("Output_CoordinateX",resultMapPoint.X); resultGraphic.Attributes.Add("Output_CoordinateY",resultMapPoint.Y); MapPoint inputMapPoint = e.UserState as MapPoint; resultGraphic.Attributes.Add("input_CoordinateX",inputMapPoint.X); resultGraphic.Attributes.Add("input_CoordinateY",inputMapPoint.Y); firePointLayer.Graphics.Add(resultGraphic); yzxfMap.Layers.Add(firePointLayer); Envelope displayExtent = new Envelope( resultMapPoint.X - (resultMapPoint.X / 1000),resultMapPoint.Y - (resultMapPoint.Y / 1000),resultMapPoint.X + (resultMapPoint.X / 1000),resultMapPoint.Y + (resultMapPoint.Y / 1000)); yzxfMap.ZoomTo(displayExtent); } } catch (Exception ex) { _errorLog.InsertErrorLogfileAsync("geoService_ProjectCompleted",ex.ToString()); } }注意: resultGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as Symbol; 这句话里面的 DefaultMarkerSymbol 对象是我们前台代码:
<esriSymbols:SimpleFillSymbol x:name="DefaultFillSymbol" Fill="#33FF0000" borderBrush="Red" borderThickness="2" /> <esri:MarkerSymbol x:name="DefaultMarkerSymbol"> <esri:MarkerSymbol.ControlTemplate> <ControlTemplate> <Canvas> <visualstatemanager.VisualStateGroups> <VisualStateGroup x:name="CommonStates"> <VisualState x:name="normal"> <Storyboard RepeatBehavior="Forever"> <DoubleAnimation BeginTime="00:00:00" Storyboard.Targetname="ellipse" Storyboard.TargetProperty="(UIElement.Rendertransform).(Scaletransform.ScaleX)" From="1" To="10" Duration="00:00:01" /> <DoubleAnimation BeginTime="0:0:0" Storyboard.Targetname="ellipse" Storyboard.TargetProperty="(UIElement.Rendertransform).(Scaletransform.ScaleY)" From="1" To="10" Duration="00:00:01" /> <DoubleAnimation BeginTime="00:00:00" Storyboard.Targetname="ellipse" Storyboard.TargetProperty="(UIElement.Opacity)" From="1" To="0" Duration="00:00:01" /> </Storyboard> </VisualState> </VisualStateGroup> </visualstatemanager.VisualStateGroups> <Ellipse Height="10" WIDth="10" Canvas.left="-5" Canvas.top="-5" RendertransformOrigin="0.5,0.5" x:name="ellipse" IsHitTestVisible="False"> <Ellipse.Rendertransform> <Scaletransform /> </Ellipse.Rendertransform> <Ellipse.Fill> <RadialGradIEntBrush> <GradIEntStop color="#00FF0000" /> <GradIEntStop color="#FFFF0000" Offset="0.25" /> <GradIEntStop color="#00FF0000" Offset="0.5" /> <GradIEntStop color="#FFFF0000" Offset="0.75" /> <GradIEntStop color="#00FF0000" Offset="1" /> </RadialGradIEntBrush> </Ellipse.Fill> </Ellipse> <Ellipse Height="10" WIDth="10" Canvas.left="-5" Canvas.top="-5" Fill="#FFFF0000" x:name="ellipse1" /> </Canvas> </ControlTemplate> </esri:MarkerSymbol.ControlTemplate> </esri:MarkerSymbol> </GrID.Resources>
事就这么成了!
三、我们来看看,效果图:
中间闪烁的小图标就是我们根据 经纬度定位的地方。点击打开链接下载源码
总结以上是内存溢出为你收集整理的Silverlight for ArcGIS 经纬度定位全部内容,希望文章能够帮你解决Silverlight for ArcGIS 经纬度定位所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)