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

 #region 处理工程点点击编辑相关事件

        public Graphic editgraphics = null; //待编辑的Graphics图层
public Graphic oldgraphics = null; //原先Graphics图层
public Symbol symbolold = null; /// <summary>
/// 在地图上点击编辑点处理事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void myMap_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
ESRI.ArcGIS.Client.Projection.WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator();
try
{
if (editgraphics != null)
{
if (isedit)
{
System.Windows.Point screenPoint = e.GetPosition(myMap);
ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = myMap.ScreenToMap(screenPoint);
double x = Math.Round(mapPoint.X, 4);
double y = Math.Round(mapPoint.Y, 4);
MapPoint mp = new MapPoint(x, y);
editgraphics.Geometry = mp;
}
else
{
editgraphics = oldgraphics;
}
}
else
{ }
}
catch (Exception)
{
return;
}
} void graphic_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Graphic graphic = sender as Graphic;
oldgraphics = graphic; //保存原先的Graphics图层
isedit = true;
//选工程点
if (graphic != null)
{
//将上一个图元还原第一个图元
if (symbolold != null)
{
editgraphics.Symbol = symbolold;
} editgraphics = graphic;
symbolold = editgraphics.Symbol;
editgraphics.Symbol = ((SimpleMarkerSymbol)this.FindName("SimpleSymbol")); ESRI.ArcGIS.Client.Geometry.MapPoint mp = (MapPoint)graphic.Geometry;
ESRI.ArcGIS.Client.Projection.WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator();
mp = WKIDConvert.mercator2lonlat(ESRI.ArcGIS.Client.Geometry.Geometry.NormalizeCentralMeridian(mp) as ESRI.ArcGIS.Client.Geometry.MapPoint);
//打开Tab进行编辑操作
this.gridTab2.Width = new GridLength(278, GridUnitType.Pixel);
tbTip1.Text = "<<";
string title = graphic.Attributes["NAME"].ToString(); //工程名称
this.tbProjectName.Text = title;
this.tbLatitute.Text = Math.Round(mp.X, 4).ToString(); //经度
this.tbLongitute.Text = Math.Round(mp.Y, 4).ToString(); //纬度
}
} void graphic_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Graphic graphic = sender as Graphic; editgraphics.Symbol = ((SimpleMarkerSymbol)this.FindName("SimpleSymbol")); ESRI.ArcGIS.Client.Geometry.MapPoint mp = (MapPoint)graphic.Geometry;
ESRI.ArcGIS.Client.Projection.WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator();
mp = WKIDConvert.mercator2lonlat(ESRI.ArcGIS.Client.Geometry.Geometry.NormalizeCentralMeridian(mp) as ESRI.ArcGIS.Client.Geometry.MapPoint);
string title = graphic.Attributes["NAME"].ToString(); //工程名称
this.tbProjectName.Text = title;
this.tblEditName.Text = title;
this.tbLatitute.Text = Math.Round(mp.X, 4).ToString(); //经度
this.tbLongitute.Text = Math.Round(mp.Y, 4).ToString(); //纬度
} void graphic_MouseMove(object sender, MouseEventArgs e)
{
Graphic graphic = sender as Graphic;
Grid grid = new Grid();
grid.Background = new SolidColorBrush(Colors.Blue);
TextBlock msg = new TextBlock();
msg.Foreground = new SolidColorBrush(Colors.White);
msg.FontSize = 13;
msg.FontFamily = new FontFamily("Microsoft YaHei");
msg.Text = graphic.Attributes["NAME"].ToString();
grid.Children.Add(msg);
graphic.MapTip = grid;
} RichTextBox rtb; void graphic_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
if (isedit)
{
//只有在选中点开始编辑后,才可以取消编辑
RTBContextMenu menu = new RTBContextMenu(rtb, this);
menu.Show(e.GetPosition(LayoutRoot));
}
else
{
//什么也不执行
}
} void graphic_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
} private void btnModify_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
if (string.IsNullOrEmpty(this.tbProjectName.Text))
{
MessageBox.Show("请先选择一个工程点!");
}
else
{
MapPoint mp = (MapPoint)editgraphics.Geometry;
getDataSoapClient client = new getDataSoapClient();
client.updagePositionCompleted += new EventHandler<AsyncCompletedEventArgs>(client_updagePositionCompleted);
MapPoint mapPoint = WKIDConvert.mercator2lonlat(ESRI.ArcGIS.Client.Geometry.Geometry.NormalizeCentralMeridian(mp) as ESRI.ArcGIS.Client.Geometry.MapPoint);
client.updagePositionAsync(this.tbProjectName.Text, Math.Round(mapPoint.X, 4).ToString(), Math.Round(mapPoint.Y, 4).ToString());
}
}
catch (Exception)
{
MessageBox.Show("请先选择一个工程点!");
} } void client_updagePositionCompleted(object sender, AsyncCompletedEventArgs e)
{
//重新加载数据,这里需要维持地图缩放的比例
ESRI.ArcGIS.Client.Projection.WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator();
ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = mercator.ToGeographic(editgraphics.Geometry).Extent; //选中点的位置
double expandPercentage = 10; //加数值后,聚焦(这里需要注意,进行地理坐标和墨卡托坐标的转换)
double widthExpand = (selectedFeatureExtent.Width + 5) * (expandPercentage / 100);
double heightExpand = (selectedFeatureExtent.Height + 5) * (expandPercentage / 100);
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))))
{
SpatialReference = new SpatialReference(102100)
}; MessageBox.Show("工程位置更新成功!");
//重新加载地图
GetGCInfoByType(tip_Base.CurrentValue);
//重新置文本输入框为空
this.tbProjectName.Text = "";
this.tbLatitute.Text = "";
this.tbLongitute.Text = "";
} #endregion using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;
using System.Windows.Media.Effects;
using ESRI.ArcGIS.Client.FeatureService.Symbols;
using ESRI.ArcGIS.Client.Geometry; namespace MapClient.CommonClass
{
public class RTBContextMenu : ContextMenu
{
RichTextBox rtb;
GCSiteM _gcSite; public RTBContextMenu(RichTextBox rtb, GCSiteM gcSite)
{
this.rtb = rtb;
_gcSite = gcSite;
} //构造菜单按钮并返回一个FrameworkElement对象
protected override FrameworkElement GetContent()
{
Border border = new Border() { BorderBrush = new SolidColorBrush(Color.FromArgb(255, 167, 171, 176)), BorderThickness = new Thickness(1), Background = new SolidColorBrush(Colors.White) };
border.Effect = new DropShadowEffect() { BlurRadius = 3, Color = Color.FromArgb(255, 230, 227, 236) }; //取消选中
Button tjspButton = new Button() { Height = 22, Margin = new Thickness(0, 0, 0, 0), HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Top, HorizontalContentAlignment = HorizontalAlignment.Left };
tjspButton.Style = Application.Current.Resources["ContextMenuButton"] as Style;
tjspButton.Click += new RoutedEventHandler(tjspButton_Click); tjspButton.Content = "取消选中"; border.Child = tjspButton;
return border;
} void tjspButton_Click(object sender, RoutedEventArgs e)
{
//恢复原来的颜色
_gcSite.editgraphics.Symbol = new SimpleMarkerSymbol()
{
Color = new SolidColorBrush(ColorRevert.ToColor("#FF0551A7")),
Size = 10,
Style = ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleMarkerSymbol.SimpleMarkerStyle.Circle
};
_gcSite.isedit = false; //重新加载数据,这里需要维持地图缩放的比例
ESRI.ArcGIS.Client.Projection.WebMercator mercator = new ESRI.ArcGIS.Client.Projection.WebMercator();
ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = mercator.ToGeographic(_gcSite.oldgraphics.Geometry).Extent; //原先选中点的位置
double expandPercentage = 10; //加数值后,聚焦(这里需要注意,进行地理坐标和墨卡托坐标的转换)
double widthExpand = (selectedFeatureExtent.Width + 5) * (expandPercentage / 100);
double heightExpand = (selectedFeatureExtent.Height + 5) * (expandPercentage / 100);
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))))
{
SpatialReference = new SpatialReference(102100)
}; //重新加载地图
_gcSite.GetGCInfoByType(tip_Base.CurrentValue);
//重新置文本输入框为空
_gcSite.tbProjectName.Text = "";
_gcSite.tbLatitute.Text = "";
_gcSite.tbLongitute.Text = "";
Close();
}
}
}

以上使用到的右键菜单功能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. POJ 1064 (二分)

    题目链接: http://poj.org/problem?id=1064 题目大意:一堆棍子可以截取,问要求最后给出K根等长棍子,求每根棍子的最大长度.保留2位小数.如果小于0.01,则输出0.00 ...

  2. 一个spring jdbc实例

    一.使用示例 (1)springJdbcContext.xml <?xml version="1.0" encoding="UTF-8"?> < ...

  3. 常用移动web开发框架研究分析

    纯粹的总结一下移动web开发框架,移动web开发框架有jQuery Mobile .Sencha Touch等等,他们都来源于web开发,是成熟的框架,jQuery Mobile出自于jQuery家族 ...

  4. 【BZOJ】1934: [Shoi2007]Vote 善意的投票(网络流/-二分图匹配)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1934 一开始我想到了这是求最小割,但是我认为这题二分图可做,将1的放在左边,0的放在右边,然后朋友连 ...

  5. BZOJ1367 [Baltic2004]sequence

    现学的左偏树...这可是道可并堆的好题目. 首先我们考虑z不减的情况: 我们发现对于一个区间[l, r],里面是递增的,则对于此区间最优解为z[i] = t[i]: 如果里面是递减的,z[l] = z ...

  6. EnableViewState=“false”不能乱用啊

    有时候页面源文件里有一段看上去像乱码的代码,这时候为了加快页面的加载速度,可以使用EnableViewState=“false”,这时候页面上的乱码就会消失了.但是,关于这个问题作者郁闷了好久,之前为 ...

  7. JS function的参数问题

    1.当传入的参数个数小于声明的参数个数时,缺少的参数值就是:undefined 类似方法重载 var f1 = function(p1,p2,p3){     switch(arguments.len ...

  8. MySQL 用户管理——权限表

    权限表 权限表存放在mysql数据库中 user表结构 用户列:Host.User.Password 权限列:*priv 资源控制列:max* 安全列:其余   db表 存储了用户对某个数据库的操作权 ...

  9. freemarker 图片输出、多张图片输出(图片重复原因及解决)

    单张图片显示: 先写好word格式的文档,在其中插入一张图片,然后重命名为ftl,再用编辑器打开,把图片那一段base64信息用freemarker表达式替换掉. 之后把图片的信息输出到模板即可. 多 ...

  10. lightning mdb 源代码分析(5)-事务控制

    本博文系列前面已经探讨了LMDB的系统架构.MMAP映射.B-Tree操作等部分,本文将尝试描述LMDB中的事务控制的实现. 事务的基本特征: 事务是恢复和并发控制的基本单位.它是一个操作序列,这些操 ...