大佬教程收集整理的这篇文章主要介绍了ArcGIS API for Silverlight 实现修改地图上的工程点位置 .,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
[csharp] view plaincopyprint? 01. #region 处理工程点点击编辑相关事件 02. 03. public Graphic editgraphics = null; //待编辑的Graphics图层 04. public Graphic oldgraphics = null; //原先Graphics图层 05. public Symbol symbolold = null; 06. 07. /// <sumMary> 08. /// 在地图上点击编辑点处理事件 09. /// </sumMary> 10. /// <param name="sender"></param> 11. /// <param name="e"></param> 12. void mymap_MouSELEftButtonDown(object sender,MouseButtonEventArgs E) 13. { 14. ESRI.ArcGIs.CLIENt.Projection.WebMercator mercator = new ESRI.ArcGIs.CLIENt.Projection.WebMercator(); 15. try 16. { 17. if (editgraphics != null) 18. { 19. if (isedit) 20. { 21. System.Windows.Point screenPoint = e.GetPosition(mymap); 22. ESRI.ArcGIs.CLIENt.Geometry.MapPoint mapPoint = mymap.ScreenToMap(screenPoint); 23. double x = Math.round(R_55_11845@apPoint.X,4); 24. double y = Math.round(R_55_11845@apPoint.Y,4); 25. MapPoint mp = new MapPoint(x,y); 26. editgraphics.Geometry = mp; 27. } 28. else 29. { 30. editgraphics = oldgraphics; 31. } 32. } 33. else 34. { 35. 36. } 37. } 38. catch (Exception) 39. { 40. return; 41. } 42. } 43. 44. void graphic_MouSELEftButtonDown(object sender,MouseButtonEventArgs E) 45. { 46. Graphic graphic = sender as Graphic; 47. oldgraphics = graphic; //保存原先的Graphics图层 48. isedit = true; 49. //选工程点 50. if (graphic != null) 51. { 52. //将上一个图元还原第一个图元 53. if (symbolold != null) 54. { 55. editgraphics.Symbol = symbolold; 56. } 57. 58. editgraphics = graphic; 59. symbolold = editgraphics.Symbol; 60. editgraphics.Symbol = ((SimpleMarkerSymbol)this.FindName("SimpleSymbol")); 61. 62. ESRI.ArcGIs.CLIENt.Geometry.MapPoint mp = (MapPoint)graphic.Geometry; 63. ESRI.ArcGIs.CLIENt.Projection.WebMercator mercator = new ESRI.ArcGIs.CLIENt.Projection.WebMercator(); 64. mp = WKIDConvert.mercator2lonlat(ESRI.ArcGIs.CLIENt.Geometry.Geometry.NormalizeCentralMeridian(mp) as ESRI.ArcGIs.CLIENt.Geometry.MapPoint); 65. //打开Tab进行编辑操作 66. this.gridTab2.Width = new GridLength(278,GridUnitType.Pixel); 67. tbTip1.Text = "<<"; 68. String title = graphic.Attributes["NAME"].ToString(); //工程名称 69. this.tbProjectName.Text = title; 70. this.tbLatitute.Text = Math.round(R_55_11845@p.X,4).ToString(); //经度 71. this.tbLongitute.Text = Math.round(R_55_11845@p.Y,4).ToString(); //纬度 72. } 73. } 74. 75. void graphic_MouSELEftButtonUp(object sender,MouseButtonEventArgs E) 76. { 77. Graphic graphic = sender as Graphic; 78. 79. editgraphics.Symbol = ((SimpleMarkerSymbol)this.FindName("SimpleSymbol")); 80. 81. ESRI.ArcGIs.CLIENt.Geometry.MapPoint mp = (MapPoint)graphic.Geometry; 82. ESRI.ArcGIs.CLIENt.Projection.WebMercator mercator = new ESRI.ArcGIs.CLIENt.Projection.WebMercator(); 83. mp = WKIDConvert.mercator2lonlat(ESRI.ArcGIs.CLIENt.Geometry.Geometry.NormalizeCentralMeridian(mp) as ESRI.ArcGIs.CLIENt.Geometry.MapPoint); 84. String title = graphic.Attributes["NAME"].ToString(); //工程名称 85. this.tbProjectName.Text = title; 86. this.tblEditName.Text = title; 87. this.tbLatitute.Text = Math.round(R_55_11845@p.X,4).ToString(); //经度 88. this.tbLongitute.Text = Math.round(R_55_11845@p.Y,4).ToString(); //纬度 89. } 90. 91. void graphic_MouseMove(object sender,MouseEventArgs E) 92. { 93. Graphic graphic = sender as Graphic; 94. Grid grid = new Grid(); 95. grid.BACkground = new SolidColorBrush(Colors.bluE); 96. TextBlock msg = new TextBlock(); 97. msg.Foreground = new SolidColorBrush(Colors.WhitE); 98. msg.FontSize = 13; 99. msg.FontFamily = new FontFamily("Microsoft YaHei"); 100. msg.Text = graphic.Attributes["NAME"].ToString(); 101. grid.Children.Add(msg); 102. graphic.MapTip = grid; 103. } 104. 105. RichTextBox rtb; 106. 107. void graphic_MouseRightButtonUp(object sender,MouseButtonEventArgs E) 108. { 109. if (isedit) 110. { 111. //只有在选中点开始编辑后,才可以取消编辑 112. RTBContextMenu menu = new RTBContextMenu(rtb,this); 113. menu.Show(e.GetPosition(LayoutRoot)); 114. } 115. else 116. { 117. //什么也不执行 118. } 119. } 120. 121. void graphic_MouseRightButtonDown(object sender,MouseButtonEventArgs E) 122. { 123. e.Handled = true; 124. } 125. 126. private void btnModify_Click(object sender,System.Windows.RoutedEventArgs E) 127. { 128. try 129. { 130. if (String.IsNullOrEmpty(this.tbProjectName.Text)) 131. { 132. messageBox.Show("请先选择一个工程点!"); 133. } 134. else 135. { 136. MapPoint mp = (MapPoint)editgraphics.Geometry; 137. getDataSoapClient client = new getDataSoapClient(); 138. client.uPDAgePositionCompleted += new EventHandler<AsyncCompletedEventArgs>(client_uPDAgePositionCompleted); 139. MapPoint mapPoint = WKIDConvert.mercator2lonlat(ESRI.ArcGIs.CLIENt.Geometry.Geometry.NormalizeCentralMeridian(mp) as ESRI.ArcGIs.CLIENt.Geometry.MapPoint); 140. client.uPDAgePositionAsync(this.tbProjectName.Text,Math.round(R_55_11845@apPoint.X,4).ToString(),Math.round(R_55_11845@apPoint.Y,4).ToString()); 141. } 142. } 143. catch (Exception) 144. { 145. messageBox.Show("请先选择一个工程点!"); 146. } 147. 148. } 149. 150. void client_uPDAgePositionCompleted(object sender,AsyncCompletedEventArgs E) 151. { 152. //重新加载数据,这里需要维持地图缩放的比例 153. ESRI.ArcGIs.CLIENt.Projection.WebMercator mercator = new ESRI.ArcGIs.CLIENt.Projection.WebMercator(); 154. ESRI.ArcGIs.CLIENt.Geometry.Envelope SELEctedFeatureExtent = mercator.ToGeographic(editgraphics.Geometry).Extent; //选中点的位置 155. double expandPercentage = 10; 156. 157. //加数值后,聚焦(这里需要注意,进行地理坐标和墨卡托坐标的转换) 158. double widthExpand = (SELEctedFeatureExtent.Width + 5) * (expandPercentage / 100); 159. double heightExpand = (SELEctedFeatureExtent.Height + 5) * (expandPercentage / 100); 160. ESRI.ArcGIs.CLIENt.Geometry.Envelope displayExtent = new Envelope(WKIDConvert.lonlat2R_55_11845@ercator(new MapPoint(SELEctedFeatureExtent.XMin - (widthExpand / 2),SELEctedFeatureExtent.ymin - (heightExpand / 2))),WKIDConvert.lonlat2R_55_11845@ercator(new MapPoint(SELEctedFeatureExtent.XMax + (widthExpand / 2),SELEctedFeatureExtent.ymax + (heightExpand / 2)))) 161. { 162. SpatialReference = new SpatialReference(102100) 163. }; 164. 165. messageBox.Show("工程位置更新成功!"); 166. //重新加载地图 167. GetGCInfoByType(tip_Base.Currentvalue); 168. //重新置文本输入框为空 169. this.tbProjectName.Text = ""; 170. this.tbLatitute.Text = ""; 171. this.tbLongitute.Text = ""; 172. } 173. 174. #endregion 175. 176.using System; 177.using System.Net; 178.using System.Windows; 179.using System.Windows.Controls; 180.using System.Windows.Documents; 181.using System.Windows.Ink; 182.using System.Windows.Input; 183.using System.Windows.Media; 184.using System.Windows.Media.Animation; 185.using System.Windows.Shapes; 186.using System.Windows.Media.Imaging; 187.using System.Windows.Media.Effects; 188.using ESRI.ArcGIs.CLIENt.Featureservice.Symbols; 189.using ESRI.ArcGIs.CLIENt.Geometry; 190. 191. 192.namespace MapClient.CommonClass 193.{ 194. public class RTBContextMenu : ContextMenu 195. { 196. RichTextBox rtb; 197. GCSiteM _gcSite; 198. 199. public RTBContextMenu(RichTextBox rtb,GCSiteM gcSitE) 200. { 201. this.rtb = rtb; 202. _gcSite = gcSite; 203. } 204. 205. 206. //构造菜单按钮并返回一个FrameworkElement对象 207. protected override FrameworkElement GetContent() 208. { 209. Border border = new Border() { BorderBrush = new SolidColorBrush(Color.FromArgb(255,167,171,176)),BorderThickness = new Thickness(1),BACkground = new SolidColorBrush(Colors.WhitE) }; 210. border.Effect = new DropShadowEffect() { BlurRadius = 3,Color = Color.FromArgb(255,230,227,236) }; 211. 212. 213. //取消选中 214. Button tjspButton = new Button() { Height = 22,Margin = new Thickness(0,0),HorizontalAlignment = HorizontalAlignment.Stretch,VerticalAlignment = VerticalAlignment.Top,HorizontalContentAlignment = HorizontalAlignment.Left }; 215. tjspButton.Style = Application.Current.resources["ContextMenuButton"] as Style; 216. tjspButton.Click += new RoutedEventHandler(tjspButton_Click); 217. 218. tjspButton.Content = "取消选中"; 219. 220. border.Child = tjspButton; 221. return border; 222. } 223. 224. 225. void tjspButton_Click(object sender,RoutedEventArgs E) 226. { 227. //恢复原来的颜色 228. _gcSite.editgraphics.Symbol = new SimpleMarkerSymbol() 229. { 230. Color = new SolidColorBrush(ColorRevert.ToColor("#FF0551A7")),231. Size = 10,232. Style = ESRI.ArcGIs.CLIENt.Featureservice.Symbols.SimpleMarkerSymbol.SimpleMarkerStyle.Circle 233. }; 234. _gcSite.isedit = false; 235. 236. 237. //重新加载数据,这里需要维持地图缩放的比例 238. ESRI.ArcGIs.CLIENt.Projection.WebMercator mercator = new ESRI.ArcGIs.CLIENt.Projection.WebMercator(); 239. ESRI.ArcGIs.CLIENt.Geometry.Envelope SELEctedFeatureExtent = mercator.ToGeographic(_gcSite.oldgraphics.Geometry).Extent; //原先选中点的位置 240. double expandPercentage = 10; 241. 242. 243. //加数值后,聚焦(这里需要注意,进行地理坐标和墨卡托坐标的转换) 244. double widthExpand = (SELEctedFeatureExtent.Width + 5) * (expandPercentage / 100); 245. double heightExpand = (SELEctedFeatureExtent.Height + 5) * (expandPercentage / 100); 246. ESRI.ArcGIs.CLIENt.Geometry.Envelope displayExt http:// ent = new Envelope(WKIDConvert.lonlat2R_55_11845@ercator(new MapPoint(SELEctedFeatureExtent.XMin - (widthExpand / 2),SELEctedFeatureExtent.ymax + (heightExpand / 2)))) 247. { 248. SpatialReference = new SpatialReference(102100) 249. }; 250. 251. 252. //重新加载地图 253. _gcSite.GetGCInfoByType(tip_Base.Currentvalue); 254. //重新置文本输入框为空 255. _gcSite.tbProjectName.Text = ""; 256. _gcSite.tbLatitute.Text = ""; 257. _gcSite.tbLongitute.Text = ""; 258. Close(); 259. } 260. } 261.}
以上使用到的右键菜单功能ContextMenu.cs类请参考:http://blog.csdn.net/taomanman/article/details/7333612
以上是大佬教程为你收集整理的ArcGIS API for Silverlight 实现修改地图上的工程点位置 .全部内容,希望文章能够帮你解决ArcGIS API for Silverlight 实现修改地图上的工程点位置 .所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。