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實現地圖測距功能API地圖
- ArcGIS API for Silverlight動態標繪的實現API
- ArcGIS API for Silverlight 中根據座標點在地圖上打標記API地圖
- ArcGIS API for Silverlight 點選地圖上的要素,彈出視窗(使用Telerik RadWindow)API地圖
- ArcGIS API for Silverlight之ElementLayer使用注意點API
- ArcGIS API for Silverlight 載入google地圖APIGo地圖
- ArcGIS API for Silverlight 點選地圖彈出自定義窗體API地圖
- ArcGIS API for Silverlight 查詢點聚焦的一個注意點API
- ArcGIS API for Silverlight中載入Google地形圖(瓦片圖)APIGo
- ArcGIS API for Silverlight 地圖中解決點眾多的簇解決方法API地圖
- ArcGIS API for Silverlight 查詢點閃爍顯示API
- ArcGIS API for Silverlight開發中滑鼠左鍵點選地圖上的點彈出視窗及右鍵點選彈出快捷選單的實現程式碼API地圖
- ArcGIS API for Silverlight載入google地圖(後續篇)APIGo地圖
- ArcGIS API for Silverlight載入BingMap遙感地圖API地圖
- ArcGIS API for Silverlight 地圖元素點閃爍,線流動顯示的處理方式API地圖
- ArcGIS API for Silverlight 學習筆記API筆記
- ArcGIS API for Silverlight 解決眾多密集點分層顯示API
- ArcGIS API for Silverlight 呼叫GP服務載入等值線圖層API
- ArcGIS API for Silverlight 動態圖層(ArcGISDynamicMapServiceLayer)的顯示與隱藏API
- ArcGIS API for Silverlight地圖載入眾多點時,使用Clusterer解決重疊問題API地圖
- ArcGIS API for Silverlight之配準JPG圖片地圖文字傾斜解決方案API地圖
- ArcGIS API for JavaScript根據兩個點座標在地圖上畫線APIJavaScript地圖
- ArcGIS API for Silverlight 地圖載入進度條類之MapProgressBarAPI地圖APP
- ArcGIS API for Silverlight 繪製降雨路徑動畫API動畫
- ArcGIS API for Silverlight程式碼中使用Template模板API
- ArcGIS API for Silverlight開發入門準備API
- 建立第一個ArcGIS API for Silverlight應用API
- ArcGIS API for Silverlight 之ElementLayer使用及TextSymbol的模板使用APISymbol
- 解決ArcGIS API for Silverlight 載入地圖的內外網訪問問題API地圖
- ArcGIS API for Silverlight 呼叫WebService出現跨域訪問報錯的解決方法APIWeb跨域
- ArcGIS API for Silverlight 呼叫GP服務繪製等值面API
- ArcGIS API for Silverlight開發中常用問題彙總API
- ArcGIS API for Silverlight 滑鼠移動顯示地理座標API
- ArcGIS實現打點、線路圖、色塊、自定義彈窗
- ArcGIS API for Silverlight 滑鼠移入移出地圖要素彈出視窗(優化處理)API地圖優化
- ECharts 實現地圖散點圖(上)Echarts地圖
- ArcGIS API for Silverlight 動態新增點的同時,新增文字說明(利用TextSymbol新增多文字資訊 )APISymbol
- 收集的一些關於ArcGIS API for Silverlight開發的連線API