silverlight   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ArcGIS API for Silverlight开发中鼠标左键点击地图上的点弹出窗口及右键点击弹出快捷菜单的实现代码大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

ArcGIS API for Silverlight开发中鼠标左键点击地图上的点弹出窗口及右键点击弹出快捷菜单的实现代码 分类: web GIS 2012-03-08 17:15 844人阅读 评论(1) 收藏 举报 silverlight api String object border button 1、首先在SL项目中添加一个抽象类ContextMenu.cs文件,代码如下: [csharp

ArcGIS API for Silverlight开发中鼠标左键点击地图上的点弹出窗口及右键点击弹出快捷菜单的实现代码

分类 web GIS 844人阅读 评论(1) 收藏 举报
@H_675_39@1、首先在SL项目中添加一个抽象类ContextMenu.cs文件代码如下:

@H_675_39@

  1. using System;  
  2. using System.Net;  
  3. using System.Windows;  
  4. using System.Windows.Controls;  
  5. using System.Windows.Documents;  
  6. using System.Windows.Ink;  
  7. using System.Windows.Input;  
  8. using System.Windows.Media;  
  9. using System.Windows.Media.Animation;  
  10. using System.Windows.Shapes;  
  11. using System.Windows.Controls.Primitives;  
  12.   
  13. namespace MapClient  
  14. {  
  15.     public abstract class ContextMenu  
  16.     {  
  17.         private Point _LOCATIOn;  
  18.         private bool _isShowing;  
  19.         private Popup _popup;  
  20.         private Grid _grid;  
  21.         private Canvas _canvas;  
  22.         private FrameworkElement _content;  
  23.   
  24.         //初始化并显示弹出窗体.公共方法显示菜单项时调用   
  25.         public void Show(Point LOCATIOn)  
  26.         {  
  27.             if (_isShowing)  
  28.                 throw new InvalidoperationException();  
  29.             _isShowing = true;  
  30.             _LOCATIOn = LOCATIOn;  
  31.             constructPopup();  
  32.             _popup.IsOpen = true;  
  33.         }  
  34.   
  35.         //关闭弹出窗体   
  36.         public void Close()  
  37.         {  
  38.             _isShowing = false;  
  39.             if (_popup != null)  
  40.             {  
  41.                 _popup.IsOpen = false;  
  42.             }  
  43.         }  
  44.   
  45.         //abstract@R_676_3816@ that the child class needs to implement to return the framework element that needs to be displayed in the popup window.   
  46.         protected abstract FrameworkElement GetContent();  
  47.   
  48.         //Default behavior for OnClickOutside() is to close the context menu when there is a mouse click event outside the context menu   
  49.         protected virtual void OnClickOutside()  
  50.         {  
  51.             Close();  
  52.         }  
  53.   
  54.         // 用Grid来布局,初始化弹出窗体   
  55.         //在Grid里面添加一个Canvas,用来监测菜单项外面的鼠标点击事件   
  56.         //   
  57.         // Add the Framework Element returned by GetContent() to the grid and position it at _LOCATIOn   
  58.         private void constructPopup()  
  59.         {  
  60.             if (_popup != null)  
  61.                 return;  
  62.             _popup = new Popup();  
  63.             _grid = new Grid();  
  64.             _popup.Child = _grid;  
  65.             _canvas = new Canvas();  
  66.             _canvas.MouSELEftButtonDown += (sender, args) => { OnClickOutside(); };  
  67.             _canvas.MouseRightButtonDown += (sender, args) => { args.Handled = true; OnClickOutside(); };  
  68.             _canvas.BACkground = new SolidColorBrush(Colors.Transparent);  
  69.             _grid.Children.Add(_canvas);  
  70.             _content = GetContent();  
  71.             _content.HorizontalAlignment = HorizontalAlignment.Left;  
  72.             _content.VerticalAlignment = VerticalAlignment.Top;  
  73.             _content.Margin = new Thickness(_LOCATIOn.X, _LOCATIOn.Y, 0, 0);  
  74.             _grid.Children.Add(_content);  
  75.             UPDATESize();  
  76.         }  
  77.   
  78.         /// <sumMary>   
  79.         /// 更新大小   
  80.         /// </sumMary>   
  81.         private void UPDATESize()  
  82.         {  
  83.             _grid.Width = Application.Current.Host.Content.ActualWidth;  
  84.             _grid.Height = Application.Current.Host.Content.ActualHeight;  
  85.             if (_canvas != null)  
  86.             {  
  87.                 _canvas.Width = _grid.Width;  
  88.                 _canvas.Height = _grid.Height;  
  89.             }  
  90.         }  
  91.     }  
  92. }  

2、再添加一个类用来实现左键点击弹出控件MapTips.cs文件代码如下
@H_675_39@

@H_675_39@

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Net;  
  5. using System.Windows;  
  6. using System.Windows.Controls;  
  7. using System.Windows.Documents;  
  8. using System.Windows.Input;  
  9. using System.Windows.Media;  
  10. using System.Windows.Media.Animation;  
  11. using System.Windows.Shapes;  
  12. using System.Windows.Media.Effects;  
  13. using System.Windows.Media.Imaging;  
  14. using MapClient.serviceReference1;  
  15.   
  16. namespace MapClient  
  17. {  
  18.     public class MapTips : ContextMenu  
  19.     {  
  20.         richTextBox rtb;  
  21.         String placename = String.Empty;  
  22.         String areaID = String.Empty;  
  23.         String year = String.Empty;  
  24.         String cyclEID = String.Empty;  
  25.   
  26.         //弹出窗口中的显示文本控件   
  27.         textBlock tb_title; //标题   
  28.         textBlock tb_grade1; //苗情等级1   
  29.         textBlock tb_grade2; //苗情等级2   
  30.         textBlock tb_grade3; //苗情等级3   
  31.         textBlock tb_grade4; //苗情等级4   
  32.   
  33.         textBlock tb_percent1; //占比1   
  34.         textBlock tb_percent2; //占比2   
  35.         textBlock tb_percent3; //占比3   
  36.         textBlock tb_percent4; //占比4   
  37.   
  38.         textBlock tb_area1; //面积1   
  39.         textBlock tb_area2; //面积2   
  40.         textBlock tb_area3; //面积3   
  41.         textBlock tb_area4; //面积4   
  42.   
  43.         HyperlinkButton hlb1; //超链接1   
  44.         HyperlinkButton hlb2; //超链接2   
  45.         HyperlinkButton hlb3; //超链接3   
  46.   
  47.         public MapTips(RichTextBox rtb, String NAMEString areaID, String year, String cyclEID)  
  48.         {  
  49.             this.rtb = rtb;  
  50.             this.placename = NAME;  
  51.             this.areaID = areaID;  
  52.             this.year = year;  
  53.             this.cyclEID = cyclEID;  
  54.         }  
  55.   
  56.   
  57.         //构造菜单按钮并返一个FrameworkElement对象   
  58.         protected override FrameworkElement GetContent()  
  59.         {  
  60.             Border border = new Border() { BorderBrush = new SolidColorBrush(Color.FromArgb(255, 167, 171, 176)), BorderThickness = new Thickness(1)BACkground = new SolidColorBrush(Colors.WhitE) };  
  61.             border.Effect = new DropShadowEffect() { BlurRadius = 3, Color = Color.FromArgb(255, 230, 227, 236) };  
  62.             Grid grid = new Grid() { Margin = new Thickness(1) };  
  63.             //九行   
  64.             grid.RowDeFinitions.Add(new rowDeFinition() { Height = new GridLength(30) });  
  65.             grid.RowDeFinitions.Add(new rowDeFinition() { Height = new GridLength(30) });  
  66.             grid.RowDeFinitions.Add(new rowDeFinition() { Height = new GridLength(30) });  
  67.             grid.RowDeFinitions.Add(new rowDeFinition() { Height = new GridLength(30) });  
  68.             grid.RowDeFinitions.Add(new rowDeFinition() { Height = new GridLength(30) });  
  69.             grid.RowDeFinitions.Add(new rowDeFinition() { Height = new GridLength(30) });  
  70.             grid.RowDeFinitions.Add(new rowDeFinition() { Height = new GridLength(30) });  
  71.             grid.RowDeFinitions.Add(new rowDeFinition() { Height = new GridLength(30) });  
  72.             grid.RowDeFinitions.Add(new rowDeFinition() { Height = new GridLength(30) });  
  73.             //三列   
  74.             grid.columnDeFinitions.Add(new columnDeFinition() { Width = new GridLength(80) });  
  75.             grid.columnDeFinitions.Add(new columnDeFinition() { Width = new GridLength(80) });  
  76.             grid.columnDeFinitions.Add(new columnDeFinition() { Width = new GridLength(80) });  
  77.             //标题第一列   
  78.             tb_title = new textBlock() { FontSize = 14, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };  
  79.             Grid.SetRow(tb_title, 0);  
  80.             Grid.Setcolumn(tb_title, 0);  
  81.             Grid.SetcolumnSpan(tb_title, 3);  
  82.             grid.Children.Add(tb_titlE);  
  83.             //苗情等级标题   
  84.             textBlock tb_grade = new textBlock() { text = "苗情等级", FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  85.             Grid.SetRow(tb_grade, 1);  
  86.             Grid.Setcolumn(tb_grade, 0);  
  87.             grid.Children.Add(tb_gradE);  
  88.             //旺苗   
  89.             tb_grade1 = new textBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  90.             Grid.SetRow(tb_grade1, 2);  
  91.             Grid.Setcolumn(tb_grade1, 0);  
  92.             grid.Children.Add(tb_grade1);  
  93.             //一级苗   
  94.             tb_grade2 = new textBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  95.             Grid.SetRow(tb_grade2, 3);  
  96.             Grid.Setcolumn(tb_grade2, 0);  
  97.             grid.Children.Add(tb_grade2);  
  98.             //二级苗   
  99.             tb_grade3 = new textBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  100.             Grid.SetRow(tb_grade3, 4);  
  101.             Grid.Setcolumn(tb_grade3, 0);  
  102.             grid.Children.Add(tb_grade3);  
  103.             //三级苗   
  104.             tb_grade4 = new textBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  105.             Grid.SetRow(tb_grade4, 5);  
  106.             Grid.Setcolumn(tb_grade4, 0);  
  107.             grid.Children.Add(tb_grade4);  
  108.             //占比标题   
  109.             textBlock tb_percent = new textBlock() { text = "占   比", VerticalAlignment = VerticalAlignment.Center };  
  110.             Grid.SetRow(tb_percent, 1);  
  111.             Grid.Setcolumn(tb_percent, 1);  
  112.             grid.Children.Add(tb_percent);  
  113.             //旺苗占比   
  114.             tb_percent1 = new textBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  115.             Grid.SetRow(tb_percent1, 2);  
  116.             Grid.Setcolumn(tb_percent1, 1);  
  117.             grid.Children.Add(tb_percent1);  
  118.             //一级苗占比   
  119.             tb_percent2 = new textBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  120.             Grid.SetRow(tb_percent2, 3);  
  121.             Grid.Setcolumn(tb_percent2, 1);  
  122.             grid.Children.Add(tb_percent2);  
  123.             //二级苗占比   
  124.             tb_percent3 = new textBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  125.             Grid.SetRow(tb_percent3, 4);  
  126.             Grid.Setcolumn(tb_percent3, 1);  
  127.             grid.Children.Add(tb_percent3);  
  128.             //三级苗占比   
  129.             tb_percent4 = new textBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  130.             Grid.SetRow(tb_percent4, 5);  
  131.             Grid.Setcolumn(tb_percent4, 1);  
  132.             grid.Children.Add(tb_percent4);  
  133.             //面积标题   
  134.             textBlock tb_area = new textBlock() { text = "面积(万亩)", VerticalAlignment = VerticalAlignment.Center };  
  135.             Grid.SetRow(tb_area, 1);  
  136.             Grid.Setcolumn(tb_area, 2);  
  137.             grid.Children.Add(tb_area);  
  138.             //旺苗面积(万亩)   
  139.             tb_area1 = new textBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  140.             Grid.SetRow(tb_area1, 2);  
  141.             Grid.Setcolumn(tb_area1, 2);  
  142.             grid.Children.Add(tb_area1);  
  143.             //一级苗面积(万亩)   
  144.             tb_area2 = new textBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  145.             Grid.SetRow(tb_area2, 3);  
  146.             Grid.Setcolumn(tb_area2, 2);  
  147.             grid.Children.Add(tb_area2);  
  148.             //二级苗面积(万亩)   
  149.             tb_area3 = new textBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  150.             Grid.SetRow(tb_area3, 4);  
  151.             Grid.Setcolumn(tb_area3, 2);  
  152.             grid.Children.Add(tb_area3);  
  153.             //三级苗面积(万亩)   
  154.             tb_area4 = new textBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  155.             Grid.SetRow(tb_area4, 5);  
  156.             Grid.Setcolumn(tb_area4, 2);  
  157.             grid.Children.Add(tb_area4);  
  158.   
  159.             //超链接(苗情评价分析)   
  160.             hlb1 = new HyperlinkButton() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  161.             Grid.SetRow(hlb1, 6);  
  162.             Grid.Setcolumn(hlb1, 0);  
  163.             Grid.SetcolumnSpan(hlb1, 3);  
  164.             grid.Children.Add(hlb1);  
  165.             //超链接(苗情数据报表)   
  166.             hlb2 = new HyperlinkButton() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  167.             Grid.SetRow(hlb2, 7);  
  168.             Grid.Setcolumn(hlb2, 0);  
  169.             Grid.SetcolumnSpan(hlb2, 3);  
  170.             grid.Children.Add(hlb2);  
  171.             //超链接(苗情监测报告)   
  172.             hlb3 = new HyperlinkButton() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };  
  173.             Grid.SetRow(hlb3, 8);  
  174.             Grid.Setcolumn(hlb3, 0);  
  175.             Grid.SetcolumnSpan(hlb3, 3);  
  176.             grid.Children.Add(hlb3);  
  177.   
  178.   
  179.   
  180.             border.Child = grid;  
  181.   
  182.             getData1SoapClient client = new getData1SoapClient();  
  183.             client.GetCommenTinfoCompleted += new EventHandler<GetCommenTinfoCompletedEventArgs>(client_GetCommenTinfoCompleted);  
  184.             client.GetCommenTinfoAsync(areaID, year, cyclEID);  
  185.   
  186.             return border;  
  187.         }  
  188.   
  189.         void client_GetCommenTinfoCompleted(object sender, GetCommenTinfoCompletedEventArgs E)  
  190.         {  
  191.             //设置值   
  192.             tb_title.Text = result.Split(',')[0].Split(':')[1];  
  193.             //苗情评价分析   
  194.             hlb1.Content = result.Split(',')[1].Split(':')[1];  
  195.             hlb1.NavigateUri = new Uri("http://www.baidu.com", UriKind.RelativeOrAbsolutE);  
  196.             //苗情数据报表   
  197.             hlb2.Content = result.Split(',')[2].Split(':')[1];  
  198.             hlb2.NavigateUri = new Uri("http://www.baidu.com", UriKind.RelativeOrAbsolutE);  
  199.             //苗情监测报告   
  200.             hlb3.Content = result.Split(',')[3].Split(':')[1];  
  201.             hlb3.NavigateUri = new Uri("http://www.baidu.com", UriKind.RelativeOrAbsolutE);  
  202.             //旺苗等级、占比和面积   
  203.             tb_grade1.Text = result.Split(',')[4].Split('|')[0].Split(':')[1];  
  204.             tb_percent1.Text = result.Split(',')[4].Split('|')[1].Split(':')[1];  
  205.             tb_area1.Text = result.Split(',')[4].Split('|')[2].Split(':')[1];  
  206.             //一级苗等级、占比和面积   
  207.             tb_grade2.Text = result.Split(',')[5].Split('|')[0].Split(':')[1];  
  208.             tb_percent2.Text = result.Split(',')[5].Split('|')[1].Split(':')[1];  
  209.             tb_area2.Text = result.Split(',')[5].Split('|')[2].Split(':')[1];  
  210.             //二级苗等级、占比和面积   
  211.             tb_grade3.Text = result.Split(',')[6].Split('|')[0].Split(':')[1];  
  212.             tb_percent3.Text = result.Split(',')[6].Split('|')[1].Split(':')[1];  
  213.             tb_area3.Text = result.Split(',')[6].Split('|')[2].Split(':')[1];  
  214.             //三级苗等级、占比和面积   
  215.             tb_grade4.Text = result.Split(',')[7].Split('|')[0].Split(':')[1];  
  216.             tb_percent4.Text = result.Split(',')[7].Split('|')[1].Split(':')[1];  
  217.             tb_area4.Text = result.Split(',')[7].Split('|')[2].Split(':')[1];  
  218.   
  219.         }  
  220.     }  
  221. }  
@H_675_39@

@H_675_39@3、添加一个鼠标右键弹出的快捷菜单控件RTBContextMenu .cs文件代码如下:

@H_675_39@

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Net;  
  5. using System.Windows;  
  6. using System.Windows.Controls;  
  7. using System.Windows.Documents;  
  8. using System.Windows.Input;  
  9. using System.Windows.Media;  
  10. using System.Windows.Media.Animation;  
  11. using System.Windows.Shapes;  
  12. using System.Windows.Media.Effects;  
  13. using System.Windows.Media.Imaging;  
  14.   
  15. namespace MapClient  
  16. {  
  17.     public class rTBContextMenu : ContextMenu  
  18.     {  
  19.         richTextBox rtb;  
  20.         String placename = String.Empty;  
  21.   
  22.         public rTBContextMenu(RichTextBox rtb, String Name)  
  23.         {  
  24.             this.rtb = rtb;  
  25.             this.placename = NAME;  
  26.         }  
  27.   
  28.         //构造菜单按钮并返一个FrameworkElement对象   
  29.         protected override FrameworkElement GetContent()  
  30.         {  
  31.             Border border = new Border() { BorderBrush = new SolidColorBrush(Color.FromArgb(255, BACkground = new SolidColorBrush(Colors.WhitE) };  
  32.             border.Effect = new DropShadowEffect() { BlurRadius = 3, 236) };  
  33.             Grid grid = new Grid() { Margin = new Thickness(1) };  
  34.             grid.columnDeFinitions.Add(new columnDeFinition() { Width = new GridLength(25) });  
  35.             grid.columnDeFinitions.Add(new columnDeFinition() { Width = new GridLength(105) });  
  36.             grid.Children.Add(new rectangle() { Fill = new SolidColorBrush(Color.FromArgb(255, 233, 238, 238)) });  
  37.             grid.Children.Add(new rectangle() { Fill = new SolidColorBrush(Color.FromArgb(255, 226, 228, 231)), HorizontalAlignment = HorizontalAlignment.Right, Width = 1 });  
  38.   
  39.             //田间视频   
  40.             Button tjspButton = new Button() { Height = 22, Margin = new Thickness(0, 0), HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Top, HorizontalContentAlignment = HorizontalAlignment.Left };  
  41.             tjspButton.Style = Application.Current.resources["ContextMenuButton"as Style;  
  42.             tjspButton.Click += tjsp_MouSELEftButtonUp;  
  43.             Grid.SetcolumnSpan(tjspButton, 2);  
  44.             StackPanel sp = new StackPanel() { Orientation = Orientation.Horizontal };  
  45.             Image tjspImage = new Image() { HorizontalAlignment = HorizontalAlignment.Left, Width = 16, Height = 16, Margin = new Thickness(1, 0) };  
  46.             tjspImage.source = new BitmapImage(new Uri("/MapClient;component/Images/pop-movie.png", UriKind.RelativeOrAbsolutE));  
  47.             sp.Children.Add(tjspImagE);  
  48.             textBlock tjspText = new textBlock() { text = "田间视频", HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(16, 0) };  
  49.             sp.Children.Add(tjspText);  
  50.             tjspButton.Content = sp;  
  51.             grid.Children.Add(tjspButton);  
  52.   
  53.             //作物像片   
  54.             Button zwxpButton = new Button() { Height = 22, 24, HorizontalContentAlignment = HorizontalAlignment.Left };  
  55.             zwxpButton.Style = Application.Current.resources["ContextMenuButton"as Style;  
  56.             zwxpButton.Click += zwxp_MouSELEftButtonUp;  
  57.             Grid.SetcolumnSpan(zwxpButton, 2);  
  58.             sp = new StackPanel() { Orientation = Orientation.Horizontal };  
  59.             Image zwxpImage = new Image() { HorizontalAlignment = HorizontalAlignment.Left, 0) };  
  60.             zwxpImage.source = new BitmapImage(new Uri("/MapClient;component/Images/pop-pic.png", UriKind.RelativeOrAbsolutE));  
  61.             sp.Children.Add(zwxpImagE);  
  62.             textBlock zwxpText = new textBlock() { text = "作物图片", 0) };  
  63.             sp.Children.Add(zwxpText);  
  64.             zwxpButton.Content = sp;  
  65.             grid.Children.Add(zwxpButton);  
  66.   
  67.   
  68.             //专家会议   
  69.             Button zjhyButton = new Button() { Height = 22, 48, HorizontalContentAlignment = HorizontalAlignment.Left };  
  70.             zjhyButton.Style = Application.Current.resources["ContextMenuButton"as Style;  
  71.             zjhyButton.Click += zjhy_MouSELEftButtonUp;  
  72.             Grid.SetcolumnSpan(zjhyButton, 2);  
  73.             sp = new StackPanel() { Orientation = Orientation.Horizontal };  
  74.             Image zjhyImage = new Image() { HorizontalAlignment = HorizontalAlignment.Left, 0) };  
  75.             zjhyImage.source = new BitmapImage(new Uri("/MapClient;component/Images/pop-person.png", UriKind.RelativeOrAbsolutE));  
  76.             sp.Children.Add(zjhyImagE);  
  77.             textBlock zjhyText = new textBlock() { text = "专家会议", 0) };  
  78.             sp.Children.Add(zjhyText);  
  79.             zjhyButton.Content = sp;  
  80.             grid.Children.Add(zjhyButton);  
  81.   
  82.             //现场联动   
  83.             Button xcldButton = new Button() { Height = 22, 72, HorizontalContentAlignment = HorizontalAlignment.Left };  
  84.             xcldButton.Style = Application.Current.resources["ContextMenuButton"as Style;  
  85.             xcldButton.Click += xcld_MouSELEftButtonUp;  
  86.             Grid.SetcolumnSpan(xcldButton, 2);  
  87.             sp = new StackPanel() { Orientation = Orientation.Horizontal };  
  88.             Image xcldImage = new Image() { HorizontalAlignment = HorizontalAlignment.Left, 0) };  
  89.             xcldImage.source = new BitmapImage(new Uri("/MapClient;component/Images/pop-link.png", UriKind.RelativeOrAbsolutE));  
  90.             sp.Children.Add(xcldImagE);  
  91.             textBlock xcldText = new textBlock() { text = "现场联动", 0) };  
  92.             sp.Children.Add(xcldText);  
  93.             xcldButton.Content = sp;  
  94.             grid.Children.Add(xcldButton);  
  95.   
  96.             border.Child = grid;  
  97.             return border;  
  98.         }  
  99.   
  100.         //   
  101.         //处理事件   
  102.         //   
  103.         void tjsp_MouSELEftButtonUp(object sender, routedEventArgs E)  
  104.         {  
  105.             //页面跳转,使用参数进行url传递 参数值为placename(请注意)   
  106.             System.Windows.browser.HtmlPage.Window.Navigate(new Uri("../SensorMonitor/VedioList.aspx?AreaName=" + placename, UriKind.RelativeOrAbsolutE)"_self");  
  107.             Close();  
  108.         }  
  109.   
  110.         void zwxp_MouSELEftButtonUp(object sender, routedEventArgs E)  
  111.         {  
  112.             //页面跳转   
  113.             System.Windows.browser.HtmlPage.Window.Navigate(new Uri("../SensorMonitor/InstantImage.aspx?AreaName=" + placename"_self");  
  114.             Close();  
  115.         }  
  116.   
  117.         void zjhy_MouSELEftButtonUp(object sender, routedEventArgs E)  
  118.         {  
  119.             //页面跳转   
  120.             System.Windows.browser.HtmlPage.Window.Navigate(new Uri("http://www.baidu.com""_self");  
  121.             Close();  
  122.         }  
  123.   
  124.         void xcld_MouSELEftButtonUp(object sender, routedEventArgs E)  
  125.         {  
  126.             //页面跳转   
  127.             System.Windows.browser.HtmlPage.Window.Navigate(new Uri("http://www.baidu.com""_self");  
  128.             Close();  
  129.         }  
  130.     }  
  131. }  

4、MainPage.xaml及MainPage.xaml.cs代码如下: @H_675_39@

@H_675_39@

  1. <UserControl xmlns="http://scheR_216_11845@as.microsoft.com/winfx/2006/xaml/presentation"  
  2.              xmlns:x="http://scheR_216_11845@as.microsoft.com/winfx/2006/xaml"  
  3.              xmlns:d="http://scheR_216_11845@as.microsoft.com/expression/blend/2008"  
  4.              xmlns:mc="http://scheR_216_11845@as.openxmlformats.org/markup-compatibility/2006"  
  5.              xmlns:esri="http://scheR_216_11845@as.esri.com/arcgis/client/2009"  
  6.              xmlns:toolkit="clr-namespace:ESRI.ArcGIs.CLIENt.Toolkit;assembly=ESRI.ArcGIs.CLIENt.Toolkit"  
  7.              xmlns:symbols="clr-namespace:ESRI.ArcGIs.CLIENt.Symbols;assembly=ESRI.ArcGIs.CLIENt"  
  8.              xmlns:local="clr-namespace:GrowthMonitor"  
  9.              xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"  
  10.              xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"   
  11.              xmlns:sys="clr-namespace:System;assembly=mscorlib"  
  12.              xmlns:interaction="http://scheR_216_11845@as.microsoft.com/expression/2010/interactivity"  
  13.              xmlns:sdk="http://scheR_216_11845@as.microsoft.com/winfx/2006/xaml/presentation/sdk"  
  14.              xmlns:slData="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  
  15.              x:Class="MapClient.MainPage" d:DesignHeight="300" d:DesignWidth="400" Loaded="UserControl_Loaded" mc:Ignorable="d">  
  16.   
  17.     <Grid x:Name="LayoutRoot" BACkground="White">  
  18.         <Grid.resources>  
  19.             <esri:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Size="12" x:Name="dms_Point" Style="Circle">  
  20.                 <esri:SimpleMarkerSymbol.ControlTemplate>  
  21.                     <ControlTemplate>  
  22.                         <Grid x:Name="RootElement" renderTransformOrigin="0.5,0.5" >  
  23.                             <Grid.RenderTransform>  
  24.                                 <ScaleTransform ScaleX="1" ScaleY="1" />  
  25.                             </Grid.RenderTransform>  
  26.                             <VisualStateManager.VisualStateGroups>  
  27.                                 <VisualStateGroup x:Name="CommonStates">  
  28.                                     <VisualState x:Name="Normal">  
  29.                                         <Storyboard>  
  30.                                             <DoubleAnimation BeginTime="00:00:00"   
  31.                                                                       Storyboard.TargetName="RootElement"   
  32.                                                                       Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)"   
  33.                                                                       To="1" Duration="0:0:0.1" />  
  34.                                             <DoubleAnimation BeginTime="00:00:00"   
  35.                                                                       Storyboard.TargetName="RootElement"   
  36.                                                                       Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)"   
  37.                                                                       To="1" Duration="0:0:0.1" />  
  38.                                         </Storyboard>  
  39.                                     </VisualState>  
  40.                                     <VisualState x:Name="MouSEOver">  
  41.                                         <Storyboard>  
  42.                                             <DoubleAnimation BeginTime="00:00:00"   
  43.                                                                       Storyboard.TargetName="RootElement"   
  44.                                                                       Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)"   
  45.                                                                       To="1.5" Duration="0:0:0.1" />  
  46.                                             <DoubleAnimation BeginTime="00:00:00"   
  47.                                                                       Storyboard.TargetName="RootElement"   
  48.                                                                       Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)"   
  49.                                                                       To="1.5" Duration="0:0:0.1" />  
  50.                                         </Storyboard>  
  51.                                     </VisualState>  
  52.                                 </VisualStateGroup>  
  53.                             </VisualStateManager.VisualStateGroups>  
  54.                             <Ellipse x:Name="ellipse"                                                      
  55.                                                     Width="{Binding Symbol.SizE}"  
  56.                                                     Height="{Binding Symbol.SizE}" >  
  57.                                 <Ellipse.Fill>  
  58.                                     <RadialGradientBrush GradientOrigin="0.5,0.5" Center="0.5,0.5"  
  59.                                                                 radiusX="0.5" radiusY="0.5">  
  60.                                         <GradientStop Color="Red" Offset="0.25" />  
  61.   
  62.                                     </RadialGradientBrush>  
  63.                                 </Ellipse.Fill>  
  64.                             </Ellipse>  
  65.                         </Grid>  
  66.                     </ControlTemplate>  
  67.                 </esri:SimpleMarkerSymbol.ControlTemplate>  
  68.             </esri:SimpleMarkerSymbol>  
  69.             <esri:SimpleLinesymbol x:Key="DefaultLinesymbol" Color="Red" Width="6"  />  
  70.             <esri:SimpleFillSymbol x:Key="DefaultFillSymbol" BorderBrush="Red" BorderThickness="2" x:Name="sf_Point"/>  
  71.   
  72.         </Grid.resources>  
  73.         <esri:Map x:Name="mymap" IslogoVisible="false" Extent="114.289579051054,29.3907111115968,121.380372848428,33.7272787947227">  
  74.             <i:Interaction.behaviors>  
  75.                 <local:WheelZoom />  
  76.             </i:Interaction.behaviors>  
  77.             <esri:Map.Layers>  
  78.                 <esri:ArcGISTiledMapserviceLayer ID="BaseLayer" Url="http://192.168.2.5/arcgis/rest/services/AnHuiBase/MapServer"/>  
  79.                 <!---特征图层-->  
  80.                 <!--<esri:FeatureLayer ID="MyFeatureLayer" Url="http://192.168.2.5/arcgis/rest/services/AnHuiDynamic/MapServer/0">  
  81.                 <esri:FeatureLayer.Clusterer>  
  82.                     <esri:FlareClusterer  
  83.                             FlareBACkground="#99FF0000"  
  84.                             FlareForeground="White"  
  85.                             R_216_11845@aximumFlareCount="9"/>  
  86.                 </esri:FeatureLayer.Clusterer>  
  87.                 <esri:FeatureLayer.outFields>  
  88.                     <sys:string>ID</sys:string>  
  89.                     <sys:string>Name</sys:string>  
  90.                 </esri:FeatureLayer.outFields>  
  91.                 <esri:FeatureLayer.MapTip>  
  92.                     <Grid BACkground="Blue" Width="200" Height="200">  
  93.                         <StackPanel>  
  94.                             <TextBlock text="{Binding [Name]}" Foreground="White" FontWeight="Bold" />  
  95.                         </StackPanel>  
  96.                     </Grid>  
  97.                 </esri:FeatureLayer.MapTip>  
  98.             </esri:FeatureLayer>-->  
  99.                 <!--GraphicsLayer-->  
  100.                 <esri:GraphicsLayer ID="MyGraphicsLayer">  
  101.                 </esri:GraphicsLayer>  
  102.             </esri:Map.Layers>  
  103.         </esri:Map>  
  104.         <Grid Height="60" HorizontalAlignment="Right" VerticalAlignment="Top"  Width="300">  
  105.             <Grid.columnDeFinitions>  
  106.                 <columnDeFinition Width="0.128*"/>  
  107.                 <columnDeFinition Width="0.142*"/>  
  108.                 <columnDeFinition Width="0.14*"/>  
  109.                 <columnDeFinition Width="0.15*"/>  
  110.                 <columnDeFinition Width="0.14*"/>  
  111.                 <columnDeFinition Width="0.14*"/>  
  112.                 <columnDeFinition Width="0.15*"/>  
  113.             </Grid.columnDeFinitions>  
  114.             <Border x:Name="bZoomIn" BorderThickness="1" Margin="0,-1,1">  
  115.                 <Border.BACkground>  
  116.                     <ImageBrush Imagesource="Images/i_zoomin.png" Stretch="None"/>  
  117.                 </Border.BACkground>  
  118.             </Border>  
  119.             <Border x:Name="bZoomOut" BorderThickness="1" Grid.column="1" Margin="3,-2,2,2">  
  120.                 <Border.BACkground>  
  121.                     <ImageBrush Imagesource="Images/i_zoomout.png" Stretch="None"/>  
  122.                 </Border.BACkground>  
  123.             </Border>  
  124.             <Border x:Name="bPan" BorderThickness="1" Grid.column="2" Margin="2,1">  
  125.                 <Border.BACkground>  
  126.                     <ImageBrush Imagesource="Images/i_pan.png" Stretch="None"/>  
  127.                 </Border.BACkground>  
  128.             </Border>  
  129.             <Border x:Name="bPrevIoUs" BorderThickness="1" Grid.column="3" Margin="4,1,5,-1">  
  130.                 <Border.BACkground>  
  131.                     <ImageBrush Imagesource="Images/i_prevIoUs.png" Stretch="None"/>  
  132.                 </Border.BACkground>  
  133.             </Border>  
  134.             <Border x:Name="bNext" BorderThickness="1" Grid.column="4" Margin="4,-2" renderTransformOrigin="1.385,0.545">  
  135.                 <Border.BACkground>  
  136.                     <ImageBrush Imagesource="Images/i_next.png" Stretch="None"/>  
  137.                 </Border.BACkground>  
  138.             </Border>  
  139.             <Border x:Name="bFullExtent" BorderThickness="1" Grid.column="5" Margin="2,0" renderTransformOrigin="1.385,0.545">  
  140.                 <Border.BACkground>  
  141.                     <ImageBrush Imagesource="Images/i_globe.png" Stretch="None"/>  
  142.                 </Border.BACkground>  
  143.             </Border>  
  144.             <Border x:Name="bFullScreen" BorderThickness="1" Grid.column="6" Margin="8,0.545">  
  145.                 <Border.BACkground>  
  146.                     <ImageBrush Imagesource="Images/i_widget.png" Stretch="None"/>  
  147.                 </Border.BACkground>  
  148.             </Border>  
  149.         </Grid>  
  150.   
  151.         <esri:Navigation Margin="5" HorizontalAlignment="Left" VerticalAlignment="Bottom"  
  152.                          Map="{Binding ELEMENTNAME=mymap}"  >  
  153.         </esri:Navigation>  
  154.         <esri:MapProgressBar x:Name="MyProgressBar"   
  155.             Map="{Binding ELEMENTNAME=mymap}"  
  156.             HorizontalAlignment="Center" VerticalAlignment="Bottom"  
  157.             Width="200" Height="36"  
  158.             Margin="25"  />  
  159.         <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Margin="0,0" VerticalAlignment="Top">  
  160.             <Button Style="{Staticresource darkButtonStylE}" Margin="3,0" >  
  161.                 <i:Interaction.triggers>  
  162.                     <i:Eventtrigger EventName="Click" >  
  163.                         <local:ToggleFullScreenAction />  
  164.                     </i:Eventtrigger>  
  165.                 </i:Interaction.triggers>  
  166.                 <Image source="Images/Fullscreen-32.png" Height="24" Margin="-4"  
  167.                                ToolTipservice.ToolTip="全屏"/>  
  168.             </Button>  
  169.         </StackPanel>  
  170.         <Button Content="查找" Height="23" HorizontalAlignment="Left" Margin="279,110,0" NAME="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />  
  171.         <TextBox Height="23" HorizontalAlignment="Left" Margin="161,0" NAME="textBox1" VerticalAlignment="Top" Width="120" />  
  172.         <sdk:Label Height="28" HorizontalAlignment="Left" Margin="45,0" NAME="label1" FontSize="15" Content="输入监测点名称:" VerticalAlignment="Top" Width="120" />  
  173.     </Grid>  
  174. </UserControl>  

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Net;  
  5. using System.Windows;  
  6. using System.Windows.Controls;  
  7. using System.Windows.Documents;  
  8. using System.Windows.Input;  
  9. using System.Windows.Media;  
  10. using System.Windows.Media.Animation;  
  11. using System.Windows.Shapes;  
  12. using ESRI.ArcGIs.CLIENt.Symbols;  
  13. using ESRI.ArcGIs.CLIENt;  
  14. using ESRI.ArcGIs.CLIENt.Tasks;  
  15. using System.Windows.Data;  
  16. using System.Runtime.serialization;  
  17. using ESRI.ArcGIs.CLIENt.Geometry;  
  18. using MapClient.UserControls;  
  19.   
  20. namespace MapClient  
  21. {  
  22.     public partial class MainPage : UserControl  
  23.     {  
  24.         //一些列变量定义   
  25.         public String str = null//用来接收aspx页面传递到xap中的参数字符串   
  26.         String[] infos = null;  
  27.         public String level = String.Empty; //市县等级 市=1/县=2   
  28.         public String areaId = String.Empty; //地区ID,包括市及县的编号   
  29.         public String color = String.Empty; //颜色值   
  30.         public String year = String.Empty; //年份   
  31.         public String cyclEID = String.Empty; //生育周期编号   
  32.   
  33.         public MainPage(Dictionary<StringString> paramsDic)  
  34.         {  
  35.             initializeComponent();  
  36.             if (paramsDic.TryGetValue("STR"out str))  
  37.             {  
  38.                 //获取到aspx页面传递过来的参数   
  39.   
  40.             }  
  41.             //按照|进行拆分成每一个监测点的信息   
  42.             infos = str.Split('|');  
  43.   
  44.             //初始化页面,开始地图加载条   
  45.             MyDrawObject = new Draw(mymap)  
  46.             {  
  47.                 FillSymbol = LayoutRoot.resources["DefaultFillSymbol"as ESRI.ArcGIs.CLIENt.Symbols.FillSymbol,  
  48.                 DrawMode = DrawMode.Rectangle  
  49.             };  
  50.   
  51.             MyDrawObject.DrawComplete += myDrawObject_DrawComplete;  
  52.         }  
  53.   
  54.   
  55.         private void UserControl_Loaded(object sender, routedEventArgs E)  
  56.         {  
  57.             FindGraphicsAndShowInMap("监测点");  
  58.         }  
  59.   
  60.   
  61.         private void Button_Click(object sender, routedEventArgs E)  
  62.         {  
  63.             FindGraphicsAndShowInMap("临泉监测点");  
  64.         }  
  65.   
  66.         //#region 市界图层   
  67.         //public void FindCityGraphicsAndShowInMap(String conditions)   
  68.         //{   
  69.         //    // 初始化查找操作   
  70.         //    FindTask findCityTask = new FindTask("http://192.168.2.5/arcgis/rest/services/AnHuiDynamic/MapServer/");   
  71.         //    findCityTask.ExecuteCompleted += new EventHandler<FindEventArgs>(findCityTask_ExecuteCompleted);   
  72.         //    findCityTask.Failed += new EventHandler<TaskFailedEventArgs>(findCityTask_Failed);   
  73.   
  74.         //    //初始化查找参数,指定Name字段作为小麦监测点层的搜素条件,并返回特征图层作为查找结果   
  75.         //    FindParameters findParameters = new FindParameters();   
  76.         //    findParameters.LayerIds.AddRange(new int[] { 2 });   
  77.         //    findParameters.SearchFields.AddRange(new String[] { "AreaID", "NAME" });   
  78.         //    findParameters.ReturnGeometry = true;   
  79.   
  80.         //    //要查找点的信息   
  81.         //    findParameters.SearchText = conditions;   
  82.   
  83.         //    findCityTask.ExecuteAsync(findParameters);   
  84.         //}   
  85.   
  86.         ////查找失败   
  87.         //void findCityTask_Failed(object sender, TaskFailedEventArgs E)   
  88.         //{   
  89.         //    messageBox.Show("查找失败: " + e.Error);   
  90.         //}   
  91.   
  92.         //void findCityTask_ExecuteCompleted(object sender, FindEventArgs E)   
  93.         //{   
  94.         //    // 清除先前的图层   
  95.         //    GraphicsLayer graphicsLayer = mymap.Layers["MyGraphicsLayer"] as GraphicsLayer;   
  96.         //    graphicsLayer.ClearGraphics();   
  97.   
  98.         //    // 检查新的结果   
  99.         //    if (e.FindResults.Count > 0)   
  100.         //    {   
  101.         //        //将查询出来的结果在地图上显示出来   
  102.         //        foreach (FindResult result in e.FindResults)   
  103.         //        {   
  104.         //            result.Feature.Symbol = LayoutRoot.resources["DefaultFillSymbol"] as ESRI.ArcGIs.CLIENt.Symbols.Symbol;   
  105.         //            graphicsLayer.Graphics.Add(result.FeaturE);   
  106.   
  107.         //            //左键菜单   
  108.         //            result.Feature.MouSELEftButtonDown += new MouseButtonEventHandler(Feature_MouSELEftButtonDown);   
  109.         //            result.Feature.MouSELEftButtonUp += new MouseButtonEventHandler(Feature_MouSELEftButtonUp);   
  110.         //            //右键菜单   
  111.         //            result.Feature.MouseRightButtonDown += new MouseButtonEventHandler(Feature_MouseRightButtonDown);   
  112.         //            result.Feature.MouseRightButtonUp += new MouseButtonEventHandler(Feature_MouseRightButtonUp);   
  113.   
  114.         //        }   
  115.         //        //坐标自动定位   
  116.         //        ESRI.ArcGIs.CLIENt.Geometry.Envelope SELEctedFeatureExtent = e.FindResults[0].Feature.Geometry.Extent;   
  117.   
  118.         //        double expandPercentage = 30;   
  119.   
  120.         //        double widthExpand = SELEctedFeatureExtent.Width * (expandPercentage / 100);   
  121.         //        double heightExpand = SELEctedFeatureExtent.Height * (expandPercentage / 100);   
  122.   
  123.         //        ESRI.ArcGIs.CLIENt.Geometry.Envelope displayExtent = new ESRI.ArcGIs.CLIENt.Geometry.Envelope(   
  124.         //        SELEctedFeatureExtent.XMin - (widthExpand / 2),  
  125.         //        SELEctedFeatureExtent.ymin - (heightExpand / 2),  
  126.         //        SELEctedFeatureExtent.XMax + (widthExpand / 2),  
  127.         //        SELEctedFeatureExtent.ymax + (heightExpand / 2));   
  128.   
  129.         //        mymap.ZoomTo(displayExtent);   
  130.         //    }   
  131.         //    else   
  132.         //    {   
  133.         //        messageBox.Show("没有发现匹配该搜索的记录!");   
  134.         //    }   
  135.         //}   
  136.   
  137.         //#endregion  
  138.  
  139.         #region 小麦监测点图层   
  140.   
  141.         /// <sumMary>   
  142.         /// 根据条件查找监测点图层(0)   
  143.         /// </sumMary>   
  144.         /// <param NAME="conditions"></param>   
  145.         public void FindGraphicsAndShowInMap(String conditions)  
  146.         {  
  147.             // 初始化查找操作   
  148.             FindTask findTask = new FindTask("http://192.168.2.5/arcgis/rest/services/AnHuiDynamic/MapServer/");  
  149.             findTask.ExecuteCompleted += FindTask_ExecuteCompleted;  
  150.             findTask.Failed += FindTask_Failed;  
  151.   
  152.             //初始化查找参数,指定Name字段作为小麦监测点层的搜素条件,并返回特征图层作为查找结果   
  153.             FindParameters findParameters = new FindParameters();  
  154.             findParameters.LayerIds.AddRange(new int[] { 0 });  
  155.             findParameters.SearchFields.AddRange(new String[] { "ID""Name" });  
  156.             findParameters.ReturnGeometry = true;  
  157.   
  158.             //要查找点的信息   
  159.             findParameters.SearchText = conditions;  
  160.   
  161.             findTask.ExecuteAsync(findParameters);  
  162.         }  
  163.  
  164.         #region FindTask 查找任务开始   
  165.         // 查找结束时,开始绘制点到图层上   
  166.         private void FindTask_ExecuteCompleted(object sender, FindEventArgs args)  
  167.         {  
  168.             // 清除先前的图层   
  169.             GraphicsLayer graphicsLayer = mymap.Layers["MyGraphicsLayer"as GraphicsLayer;  
  170.             graphicsLayer.ClearGraphics();  
  171.   
  172.             // 检查新的结果   
  173.             if (args.FindResults.Count > 0)  
  174.             {  
  175.                 //将查询出来的结果在地图上显示出来   
  176.                 foreach (FindResult result in args.FindResults)  
  177.                 {  
  178.                     //赋值颜色值   
  179.                     this.dms_Point.Color = new SolidColorBrush(Colors.Red);  
  180.                     result.Feature.Symbol = LayoutRoot.resources["DefaultMarkerSymbol"as ESRI.ArcGIs.CLIENt.Symbols.Symbol;  
  181.                     graphicsLayer.Graphics.Add(result.FeaturE);  
  182.   
  183.                     //左键菜单   
  184.                     result.Feature.MouSELEftButtonDown += new MouseButtonEventHandler(Feature_MouSELEftButtonDown);  
  185.                     result.Feature.MouSELEftButtonUp += new MouseButtonEventHandler(Feature_MouSELEftButtonUp);  
  186.                     //右键菜单   
  187.                     result.Feature.MouseRightButtonDown += new MouseButtonEventHandler(Feature_MouseRightButtonDown);  
  188.                     result.Feature.MouseRightButtonUp += new MouseButtonEventHandler(Feature_MouseRightButtonUp);  
  189.   
  190.                 }  
  191.                 //坐标自动定位   
  192.                 ESRI.ArcGIs.CLIENt.Geometry.Envelope SELEctedFeatureExtent = args.FindResults[0].Feature.Geometry.Extent;  
  193.   
  194.                 double expandPercentage = 30;  
  195.   
  196.                 double widthExpand = SELEctedFeatureExtent.Width * (expandPercentage / 100);  
  197.                 double heightExpand = SELEctedFeatureExtent.Height * (expandPercentage / 100);  
  198.   
  199.                 ESRI.ArcGIs.CLIENt.Geometry.Envelope displayExtent = new ESRI.ArcGIs.CLIENt.Geometry.Envelope(  
  200.                 SELEctedFeatureExtent.XMin - (widthExpand / 2),  
  201.                 SELEctedFeatureExtent.ymin - (heightExpand / 2),  
  202.                 SELEctedFeatureExtent.XMax + (widthExpand / 2),  
  203.                 SELEctedFeatureExtent.ymax + (heightExpand / 2));  
  204.   
  205.                 mymap.ZoomTo(displayExtent);  
  206.             }  
  207.             else  
  208.             {  
  209.                 messageBox.Show("没有发现匹配该搜索的记录!");  
  210.             }  
  211.         }  
  212.   
  213.         //当查找失败时进行提示操作   
  214.         private void FindTask_Failed(object sender, TaskFailedEventArgs args)  
  215.         {  
  216.             messageBox.Show("查找失败: " + args.Error);  
  217.         }  
  218.  
  219.         #endregion FindTask 查找任务结束  
  220.  
  221.         #endregion   
  222.   
  223.         richTextBox rtb;  
  224.         #region 鼠标左键事件开始   
  225.         void Feature_MouSELEftButtonUp(object sender, MouseButtonEventArgs E)  
  226.         {  
  227.             //鼠标左键,显示ToolTip信息   
  228.             Graphic g = sender as Graphic;  
  229.             //这里需要添加一个不消失的弹出框,并可以移入进行点击   
  230.             MapTips tips = new MapTips(rtb, g.Attributes["Name"].ToString().Trim(), g.Attributes["AreaID"].ToString().Trim(), "-1""-1");  
  231.             tips.Show(e.GetPosition(LayoutRoot));  
  232.         }  
  233.   
  234.         void Feature_MouSELEftButtonDown(object sender, MouseButtonEventArgs E)  
  235.         {  
  236.             e.Handled = true;  
  237.         }  
  238.         #endregion 鼠标左键事件结束  
  239.  
  240.         #region 鼠标右键事件开始   
  241.         void Feature_MouseRightButtonUp(object sender, MouseButtonEventArgs E)  
  242.         {  
  243.             Graphic g = sender as Graphic;  
  244.             rTBContextMenu menu = new rTBContextMenu(rtb, g.Attributes["Name"].ToString().Trim());  
  245.             menu.Show(e.GetPosition(LayoutRoot));  
  246.         }  
  247.   
  248.         void Feature_MouseRightButtonDown(object sender, MouseButtonEventArgs E)  
  249.         {  
  250.             e.Handled = true;  
  251.         }  
  252.  
  253.         #endregion 鼠标右键事件结束   
  254.   
  255.         String _toolmode = "";  
  256.         List<Envelope> _extentHistory = new List<Envelope>();  
  257.         int _currentextenTindex = 0;  
  258.         bool _newExtent = true;  
  259.   
  260.         Image _prevIoUsExtentImage;  
  261.         Image _nextExtentImage;  
  262.         private Draw MyDrawObject;  
  263.   
  264.   
  265.   
  266.         private void myToolbar_ToolbarItemClicked(object sender, ESRI.ArcGIs.CLIENt.Toolkit.SELEctedToolbarItemArgs E)  
  267.         {  
  268.             MyDrawObject.IsEnabled = false;  
  269.             _toolmode = "";  
  270.             switch (e.IndeX)  
  271.             {  
  272.                 case 0: // ZoomIn Layers   
  273.                     MyDrawObject.IsEnabled = true;  
  274.                     _toolmode = "zoomin";  
  275.                     break;  
  276.                 case 1: // Zoom Out   
  277.                     MyDrawObject.IsEnabled = true;  
  278.                     _toolmode = "zoomout";  
  279.                     break;  
  280.                 case 2: // Pan   
  281.                     break;  
  282.                 case 3: // PrevIoUs Extent   
  283.                     if (_currentextenTindex != 0)  
  284.                     {  
  285.                         _currentextenTindex--;  
  286.   
  287.                         if (_currentextenTindex == 0)  
  288.                         {  
  289.                             _prevIoUsExtentImage.opacity = 0.3;  
  290.                             _prevIoUsExtentImage.IsHitTestVisible = false;  
  291.                         }  
  292.   
  293.                         _newExtent = false;  
  294.   
  295.                         mymap.IsHitTestVisible = false;  
  296.                         mymap.ZoomTo(_extentHistorY[_currentextenTindex]);  
  297.   
  298.                         if (_nextExtentImage.IsHitTestVisible == false)  
  299.                         {  
  300.                             _nextExtentImage.opacity = 1;  
  301.                             _nextExtentImage.IsHitTestVisible = true;  
  302.                         }  
  303.                     }  
  304.                     break;  
  305.                 case 4: // Next Extent   
  306.                     if (_currentextenTindex < _extentHistory.Count - 1)  
  307.                     {  
  308.                         _currentextenTindex++;  
  309.   
  310.                         if (_currentextenTindex == (_extentHistory.Count - 1))  
  311.                         {  
  312.                             _nextExtentImage.opacity = 0.3;  
  313.                             _nextExtentImage.IsHitTestVisible = false;  
  314.                         }  
  315.   
  316.                         _newExtent = false;  
  317.   
  318.                         mymap.IsHitTestVisible = false;  
  319.                         mymap.ZoomTo(_extentHistorY[_currentextenTindex]);  
  320.   
  321.                         if (_prevIoUsExtentImage.IsHitTestVisible == false)  
  322.                         {  
  323.                             _prevIoUsExtentImage.opacity = 1;  
  324.                             _prevIoUsExtentImage.IsHitTestVisible = true;  
  325.                         }  
  326.                     }  
  327.                     break;  
  328.                 case 5: // Full Extent   
  329.                     mymap.ZoomTo(mymap.Layers.GetFullExtent());  
  330.                     break;  
  331.                 case 6: // Full Screen   
  332.                     Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen;  
  333.                     break;  
  334.             }  
  335.         }  
  336.   
  337.         private void myDrawObject_DrawComplete(object sender, DrawEventArgs args)  
  338.         {  
  339.             if (_toolmode == "zoomin")  
  340.             {  
  341.                 mymap.ZoomTo(args.Geometry as ESRI.ArcGIs.CLIENt.Geometry.EnvelopE);  
  342.             }  
  343.             else if (_toolmode == "zoomout")  
  344.             {  
  345.                 Envelope currentextent = mymap.Extent;  
  346.   
  347.                 Envelope zoomBoxExtent = args.Geometry as Envelope;  
  348.                 MapPoint zoomBoxCenter = zoomBoxExtent.GetCenter();  
  349.   
  350.                 double whRatioCurrent = currentextent.Width / currentextent.Height;  
  351.                 double whRatioZoomBox = zoomBoxExtent.Width / zoomBoxExtent.Height;  
  352.   
  353.                 Envelope newEnv = null;  
  354.   
  355.                 if (whRatioZoomBox > whRatioCurrent)  
  356.                 // use width   
  357.                 {  
  358.                     double mapWidthPixels = mymap.Width;  
  359.                     double multiplier = currentextent.Width / zoomBoxExtent.Width;  
  360.                     double newWidthMapUnits = currentextent.Width * multiplier;  
  361.                     newEnv = new Envelope(new MapPoint(zoomBoxCenter.X - (newWidthMapUnits / 2), zoomBoxCenter.Y),  
  362.                                                    new MapPoint(zoomBoxCenter.X + (newWidthMapUnits / 2), zoomBoxCenter.Y));  
  363.                 }  
  364.                 else  
  365.                 // use height   
  366.                 {  
  367.                     double mapHeightPixels = mymap.Height;  
  368.                     double multiplier = currentextent.Height / zoomBoxExtent.Height;  
  369.                     double newHeightMapUnits = currentextent.Height * multiplier;  
  370.                     newEnv = new Envelope(new MapPoint(zoomBoxCenter.X, zoomBoxCenter.Y - (newHeightMapUnits / 2)),  
  371.                                                    new MapPoint(zoomBoxCenter.X, zoomBoxCenter.Y + (newHeightMapUnits / 2)));  
  372.                 }  
  373.   
  374.                 if (newEnv != null)  
  375.                     mymap.ZoomTo(newEnv);  
  376.             }  
  377.         }  
  378.   
  379.         private void Mymap_ExtentChanged(object sender, ExtentEventArgs E)  
  380.         {  
  381.             if (e.oldExtent == null)  
  382.             {  
  383.                 _extentHistory.Add(e.NewExtent.Clone());  
  384.                 return;  
  385.             }  
  386.   
  387.             if (_newExtent)  
  388.             {  
  389.                 _currentextenTindex++;  
  390.   
  391.                 if (_extentHistory.Count - _currentextenTindex > 0)  
  392.                     _extentHistory.RemoveRange(_currentextenTindex, (_extentHistory.Count - _currentextenTindeX));  
  393.   
  394.                 if (_nextExtentImage.IsHitTestVisible == true)  
  395.                 {  
  396.                     _nextExtentImage.opacity = 0.3;  
  397.                     _nextExtentImage.IsHitTestVisible = false;  
  398.                 }  
  399.   
  400.                 _extentHistory.Add(e.NewExtent.Clone());  
  401.   
  402.                 if (_prevIoUsExtentImage.IsHitTestVisible == false)  
  403.                 {  
  404.                     _prevIoUsExtentImage.opacity = 1;  
  405.                     _prevIoUsExtentImage.IsHitTestVisible = true;  
  406.                 }  
  407.             }  
  408.             else  
  409.             {  
  410.                 mymap.IsHitTestVisible = true;  
  411.                 _newExtent = true;  
  412.             }  
  413.         }  
  414.   
  415.         private void button1_Click(object sender, routedEventArgs E)  
  416.         {  
  417.             if (this.textBox1.Text == "")  
  418.             {  
  419.                 FindGraphicsAndShowInMap("0");  
  420.             }  
  421.             else  
  422.             {  
  423.                 FindGraphicsAndShowInMap(this.textBox1.Text.Trim());  
  424.             }  
  425.         }  
  426.   
  427.     }  
  428. }  

效果图如下:鼠标点击后弹出窗体,及鼠标右键弹出快捷菜单,如下: @H_675_39@

@H_675_39@

ArcGIS API for Silverlight开发中鼠标左键点击地图上的点弹出窗口及右键点击弹出快捷菜单的实现代码

@H_675_39@

ArcGIS API for Silverlight开发中鼠标左键点击地图上的点弹出窗口及右键点击弹出快捷菜单的实现代码

@H_675_39@以后继续完善,不断改进。

@H_607_7887@

大佬总结

以上是大佬教程为你收集整理的ArcGIS API for Silverlight开发中鼠标左键点击地图上的点弹出窗口及右键点击弹出快捷菜单的实现代码全部内容,希望文章能够帮你解决ArcGIS API for Silverlight开发中鼠标左键点击地图上的点弹出窗口及右键点击弹出快捷菜单的实现代码所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。