原文:ArcGIS API for Silverlight 实现修改地图上的工程点位置

  1. #region 处理工程点点击编辑相关事件
  2.  
  3. public Graphic editgraphics = null; //待编辑的Graphics图层
  4. public Graphic oldgraphics = null; //原先Graphics图层
  5. public Symbol symbolold = null;
  6.  
  7. /// <summary>
  8. /// 在地图上点击编辑点处理事件
  9. /// </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(mapPoint.X, 4);
  24. double y = Math.Round(mapPoint.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(mp.X, 4).ToString(); //经度
  71. this.tbLongitute.Text = Math.Round(mp.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(mp.X, 4).ToString(); //经度
  88. this.tbLongitute.Text = Math.Round(mp.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(mapPoint.X, 4).ToString(), Math.Round(mapPoint.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.lonlat2mercator(new MapPoint(selectedFeatureExtent.XMin - (widthExpand / 2), selectedFeatureExtent.YMin - (heightExpand / 2))), WKIDConvert.lonlat2mercator(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. namespace MapClient.CommonClass
  192. {
  193. public class RTBContextMenu : ContextMenu
  194. {
  195. RichTextBox rtb;
  196. GCSiteM _gcSite;
  197.  
  198. public RTBContextMenu(RichTextBox rtb, GCSiteM gcSite)
  199. {
  200. this.rtb = rtb;
  201. _gcSite = gcSite;
  202. }
  203.  
  204. //构造菜单按钮并返回一个FrameworkElement对象
  205. protected override FrameworkElement GetContent()
  206. {
  207. Border border = new Border() { BorderBrush = new SolidColorBrush(Color.FromArgb(255, 167, 171, 176)), BorderThickness = new Thickness(1), Background = new SolidColorBrush(Colors.White) };
  208. border.Effect = new DropShadowEffect() { BlurRadius = 3, Color = Color.FromArgb(255, 230, 227, 236) };
  209.  
  210. //取消选中
  211. Button tjspButton = new Button() { Height = 22, Margin = new Thickness(0, 0, 0, 0), HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Top, HorizontalContentAlignment = HorizontalAlignment.Left };
  212. tjspButton.Style = Application.Current.Resources["ContextMenuButton"] as Style;
  213. tjspButton.Click += new RoutedEventHandler(tjspButton_Click);
  214.  
  215. tjspButton.Content = "取消选中";
  216.  
  217. border.Child = tjspButton;
  218. return border;
  219. }
  220.  
  221. void tjspButton_Click(object sender, RoutedEventArgs e)
  222. {
  223. //恢复原来的颜色
  224. _gcSite.editgraphics.Symbol = new SimpleMarkerSymbol()
  225. {
  226. Color = new SolidColorBrush(ColorRevert.ToColor("#FF0551A7")),
  227. Size = 10,
  228. Style = ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleMarkerSymbol.SimpleMarkerStyle.Circle
  229. };
  230. _gcSite.isedit = false;
  231.  
  232. //重新加载数据,这里需要维持地图缩放的比例
  233. ESRI.ArcGIS.Client.Projection.WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator();
  234. ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = mercator.ToGeographic(_gcSite.oldgraphics.Geometry).Extent; //原先选中点的位置
  235. double expandPercentage = 10;
  236.  
  237. //加数值后,聚焦(这里需要注意,进行地理坐标和墨卡托坐标的转换)
  238. double widthExpand = (selectedFeatureExtent.Width + 5) * (expandPercentage / 100);
  239. double heightExpand = (selectedFeatureExtent.Height + 5) * (expandPercentage / 100);
  240. ESRI.ArcGIS.Client.Geometry.Envelope displayExt http:// ent = new Envelope(WKIDConvert.lonlat2mercator(new MapPoint(selectedFeatureExtent.XMin - (widthExpand / 2), selectedFeatureExtent.YMin - (heightExpand / 2))), WKIDConvert.lonlat2mercator(new MapPoint(selectedFeatureExtent.XMax + (widthExpand / 2), selectedFeatureExtent.YMax + (heightExpand / 2))))
  241. {
  242. SpatialReference = new SpatialReference(102100)
  243. };
  244.  
  245. //重新加载地图
  246. _gcSite.GetGCInfoByType(tip_Base.CurrentValue);
  247. //重新置文本输入框为空
  248. _gcSite.tbProjectName.Text = "";
  249. _gcSite.tbLatitute.Text = "";
  250. _gcSite.tbLongitute.Text = "";
  251. Close();
  252. }
  253. }
  254. }

以上使用到的右键菜单功能ContextMenu.cs类请参考:http://blog.csdn.net/taomanman/article/details/7333612

ArcGIS API for Silverlight 实现修改地图上的工程点位置的更多相关文章

  1. 解决ArcGIS API for Silverlight 加载地图的内外网访问问题

    原文:解决ArcGIS API for Silverlight 加载地图的内外网访问问题 先上一个类,如下: public class BaseClass { public static string ...

  2. 使用ArcGIS API for Silverlight + Visifire绘制地图统计图

    原文:使用ArcGIS API for Silverlight + Visifire绘制地图统计图 最近把很久之前做的统计图又拿出来重新做了一遍,感觉很多时候不复习,不记录就真的忘了,时间是最好的稀释 ...

  3. ArcGIS API For Silverlight使用在线地图的多种方法总结

    引自:http://www.cnblogs.com/meimao5211/p/3283969.html ArcGIS API For Silverlight使用在线地图的多种方法总结 本人也正在学习A ...

  4. ArcGIS API for Silverlight部署本地地图服务

    这一节我们来讲新建立的ArcGIS API for Silverlight应用程序如何加载自己的地图服务的问题,网上的资料讲的都有点含糊不清,这次我们详细的讲一下配置的步骤: 首先介绍下我们的开发和部 ...

  5. ArcGIS API for Silverlight实现地图测距功能

    原文:ArcGIS API for Silverlight实现地图测距功能 问题:如何实现地图测距功能? 地图工具栏 <Grid x:Name="gToolMenu" Hei ...

  6. ArcGIS API for Silverlight 当DataGrid选中项时,地图聚焦弹出窗口,并可以播放音频文件

    原文:ArcGIS API for Silverlight 当DataGrid选中项时,地图聚焦弹出窗口,并可以播放音频文件 先看效果图,然后上代码: <UserControl x:Class= ...

  7. ArcGIS API for Silverlight之配准JPG图片地图文字倾斜解决方案

    原文:ArcGIS API for Silverlight之配准JPG图片地图文字倾斜解决方案 根据实际JPG图片进行配准后,发布的地图,利用ArcGIS API for Silverlight在网页 ...

  8. arcgis api for silverlight使用google map等多个在线地图

    原文 http://blog.csdn.net/leesmn/article/details/6820245 无可否认,google map实在是很漂亮.可惜对于使用arcgis api for si ...

  9. ArcGIS api fo silverlight学习一(silverlight加载GeoServer发布的WMS地图)

    最好的学习资料ArcGIS api fo silverlight官网:http://help.arcgis.com/en/webapi/silverlight/samples/start.htm 一. ...

随机推荐

  1. C#控制鼠标位置

    It is not possible using the .NET BCL. However if you really want it you can use native SetCursorPos ...

  2. ural 1217. Unlucky Tickets

    1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each ...

  3. BZOJ3482 : [COCI2013]hiperprostor

    对于每组询问,spfa求出f[i][j]表示从S出发,经过j条x边到达i的最短路. 若f[T][i]都为inf,则无解. 若f[T][0]为inf,则有无穷个解. 否则可以看作若干条直线,$O(n)$ ...

  4. POJ 1523 (割点+连通分量)

    题目链接:http://poj.org/problem?id=1523 题目大意:连通图,找图中割点,并计算切除该割点后,图中的连通分量个数. 解题思路: POJ的数据很弱. Tarjan法求割点. ...

  5. JAVA_RSA密钥生成

    在网上找了下RSA的密钥的创建,结果全是用java序列化PublicKey和PrivateKey来保存,就自己写了个RSA公钥和私钥的创建,及进行Base64编码后保存. 这里用到了 bcprov-j ...

  6. [转]Redis集群的配置

    一:memcache 和 Redis 对比总结 [memecache 特点] 1:速度最快(没有自测,但网上有详细的测试用例) 2:支持水平扩展,可以任意添加节点 [redis 特点] 1:速度没有m ...

  7. MySQL 记录不存在时插入 记录存在则更新的实现方法

    INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1; INSERT 中 ON DUPLICATE KEY UP ...

  8. jar MANIFEST.MF 汇总

    : Manifest-Version: 1.0Created-By: Apache Ant 1.5.1Extension-Name: Struts FrameworkSpecification-Tit ...

  9. 在vs2013中配置openGL(绝对可靠 !)

    首先要下载glut.h glut32.dll glut32.lib.(这个在glut-3.7.6-bin的包里面,可以直接下载 ) 然后: glut.h:放到 D:\vs2013\VC\include ...

  10. hdu Strange fuction

    本题是一道二分题,但是要利用导数来求最小值.对原函数进行求导,得到的导函数为f(x)=42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y;因为0<=x<= ...