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

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

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

1、首先在SL项目中添加一个抽象类ContextMenu.cs文件,代码如下:


[csharp] view plain copy print ? 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.Controls.Primitives;      namespace MapClIEnt   {       public abstract class ContextMenu       {           private Point _location;           private bool _isShowing;           private Popup _popup;           private GrID _grID;           private Canvas _canvas;           private FrameworkElement _content;              //初始化并显示d出窗体.公共方法在显示菜单项时调用            public voID Show(Point location)           {               if (_isShowing)                   throw new InvalIDOperationException();               _isShowing = true;               _location = location;               ConstructPopup();               _popup.IsOpen = true;           }              //关闭d出窗体            public voID Close()           {               _isShowing = false;               if (_popup != null)               {                   _popup.IsOpen = false;               }           }              //abstract function that the child class needs to implement to return the framework element that needs to be displayed in the popup window.            protected abstract FrameworkElement GetContent();              //Default behavior for OnClickOutsIDe() is to close the context menu when there is a mouse click event outsIDe the context menu            protected virtual voID OnClickOutsIDe()           {               Close();           }              // 用GrID来布局,初始化d出窗体            //在GrID里面添加一个Canvas,用来监测菜单项外面的鼠标点击事件            //            // Add the Framework Element returned by GetContent() to the grID and position it at _location            private voID ConstructPopup()           {               if (_popup != null)                   return;               _popup = new Popup();               _grID = new GrID();               _popup.Child = _grID;               _canvas = new Canvas();               _canvas.MouseleftbuttonDown += (sender, args) => { OnClickOutsIDe(); };               _canvas.MouseRightbuttonDown += (sender, args) => { args.Handled = true; OnClickOutsIDe(); };               _canvas.Background = new SolIDcolorBrush(colors.transparent);               _grID.Children.Add(_canvas);               _content = GetContent();               _content.HorizontalAlignment = HorizontalAlignment.left;               _content.VerticalAlignment = VerticalAlignment.top;               _content.margin = new Thickness(_location.X, _location.Y, 0, 0);               _grID.Children.Add(_content);               UpdateSize();           }              /// <summary>            /// 更新大小            /// </summary>            private voID UpdateSize()           {               _grID.WIDth = Application.Current.Host.Content.ActualWIDth;               _grID.Height = Application.Current.Host.Content.ActualHeight;               if (_canvas != null)               {                   _canvas.WIDth = _grID.WIDth;                   _canvas.Height = _grID.Height;               }           }       }   }  
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.Controls.Primitives;namespace MapClIEnt{    public abstract class ContextMenu    {        private Point _location;        private bool _isShowing;        private Popup _popup;        private GrID _grID;        private Canvas _canvas;        private FrameworkElement _content;        //初始化并显示d出窗体.公共方法在显示菜单项时调用        public voID Show(Point location)        {            if (_isShowing)                throw new InvalIDOperationException();            _isShowing = true;            _location = location;            ConstructPopup();            _popup.IsOpen = true;        }        //关闭d出窗体        public voID Close()        {            _isShowing = false;            if (_popup != null)            {                _popup.IsOpen = false;            }        }        //abstract function that the child class needs to implement to return the framework element that needs to be displayed in the popup window.        protected abstract FrameworkElement GetContent();        //Default behavior for OnClickOutsIDe() is to close the context menu when there is a mouse click event outsIDe the context menu        protected virtual voID OnClickOutsIDe()        {            Close();        }        // 用GrID来布局,初始化d出窗体        //在GrID里面添加一个Canvas,用来监测菜单项外面的鼠标点击事件        //        // Add the Framework Element returned by GetContent() to the grID and position it at _location        private voID ConstructPopup()        {            if (_popup != null)                return;            _popup = new Popup();            _grID = new GrID();            _popup.Child = _grID;            _canvas = new Canvas();            _canvas.MouseleftbuttonDown += (sender,args) => { OnClickOutsIDe(); };            _canvas.MouseRightbuttonDown += (sender,args) => { args.Handled = true; OnClickOutsIDe(); };            _canvas.Background = new SolIDcolorBrush(colors.transparent);            _grID.Children.Add(_canvas);            _content = GetContent();            _content.HorizontalAlignment = HorizontalAlignment.left;            _content.VerticalAlignment = VerticalAlignment.top;            _content.margin = new Thickness(_location.X,_location.Y,0);            _grID.Children.Add(_content);            UpdateSize();        }        /// <summary>        /// 更新大小        /// </summary>        private voID UpdateSize()        {            _grID.WIDth = Application.Current.Host.Content.ActualWIDth;            _grID.Height = Application.Current.Host.Content.ActualHeight;            if (_canvas != null)            {                _canvas.WIDth = _grID.WIDth;                _canvas.Height = _grID.Height;            }        }    }}

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



[csharp] view plain copy print ? using System;   using System.Collections.Generic;   using System.linq;   using System.Net;   using System.windows;   using System.windows.Controls;   using System.windows.documents;   using System.windows.input;   using System.windows.Media;   using System.windows.Media.Animation;   using System.windows.Shapes;   using System.windows.Media.Effects;   using System.windows.Media.Imaging;   using MapClIEnt.ServiceReference1;      namespace MapClIEnt   {       public class MapTips : ContextMenu       {           RichTextBox rtb;           string placename = string.Empty;           string areaID = string.Empty;           string year = string.Empty;           string cycleID = string.Empty;              //d出窗口中的显示文本控件            TextBlock tb_Title; //标题            TextBlock tb_grade1; //苗情等级1            TextBlock tb_grade2; //苗情等级2            TextBlock tb_grade3; //苗情等级3            TextBlock tb_grade4; //苗情等级4               TextBlock tb_percent1; //占比1            TextBlock tb_percent2; //占比2            TextBlock tb_percent3; //占比3            TextBlock tb_percent4; //占比4               TextBlock tb_area1; //面积1            TextBlock tb_area2; //面积2            TextBlock tb_area3; //面积3            TextBlock tb_area4; //面积4               Hyperlinkbutton hlb1; //超链接1            Hyperlinkbutton hlb2; //超链接2            Hyperlinkbutton hlb3; //超链接3               public MapTips(RichTextBox rtb, string name, string areaID, string year, string cycleID)           {               this.rtb = rtb;               this.placename = name;               this.areaID = areaID;               this.year = year;               this.cycleID = cycleID;           }                 //构造菜单按钮并返回一个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) };               GrID grID = new GrID() { margin = new Thickness(1) };               //九行                grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });               grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });               grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });               grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });               grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });               grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });               grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });               grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });               grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });               //三列                grID.ColumnDeFinitions.Add(new ColumnDeFinition() { WIDth = new GrIDLength(80) });               grID.ColumnDeFinitions.Add(new ColumnDeFinition() { WIDth = new GrIDLength(80) });               grID.ColumnDeFinitions.Add(new ColumnDeFinition() { WIDth = new GrIDLength(80) });               //标题第一列                tb_Title = new TextBlock() { FontSize = 14, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_Title, 0);               GrID.SetColumn(tb_Title, 0);               GrID.SetColumnSpan(tb_Title, 3);               grID.Children.Add(tb_Title);               //苗情等级标题                TextBlock tb_grade = new TextBlock() { Text = "苗情等级", FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_grade, 1);               GrID.SetColumn(tb_grade, 0);               grID.Children.Add(tb_grade);               //旺苗                tb_grade1 = new TextBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_grade1, 2);               GrID.SetColumn(tb_grade1, 0);               grID.Children.Add(tb_grade1);               //一级苗                tb_grade2 = new TextBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_grade2, 3);               GrID.SetColumn(tb_grade2, 0);               grID.Children.Add(tb_grade2);               //二级苗                tb_grade3 = new TextBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_grade3, 4);               GrID.SetColumn(tb_grade3, 0);               grID.Children.Add(tb_grade3);               //三级苗                tb_grade4 = new TextBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_grade4, 5);               GrID.SetColumn(tb_grade4, 0);               grID.Children.Add(tb_grade4);               //占比标题                TextBlock tb_percent = new TextBlock() { Text = "占   比", VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_percent, 1);               GrID.SetColumn(tb_percent, 1);               grID.Children.Add(tb_percent);               //旺苗占比                tb_percent1 = new TextBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_percent1, 2);               GrID.SetColumn(tb_percent1, 1);               grID.Children.Add(tb_percent1);               //一级苗占比                tb_percent2 = new TextBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_percent2, 3);               GrID.SetColumn(tb_percent2, 1);               grID.Children.Add(tb_percent2);               //二级苗占比                tb_percent3 = new TextBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_percent3, 4);               GrID.SetColumn(tb_percent3, 1);               grID.Children.Add(tb_percent3);               //三级苗占比                tb_percent4 = new TextBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_percent4, 5);               GrID.SetColumn(tb_percent4, 1);               grID.Children.Add(tb_percent4);               //面积标题                TextBlock tb_area = new TextBlock() { Text = "面积(万亩)", VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_area, 1);               GrID.SetColumn(tb_area, 2);               grID.Children.Add(tb_area);               //旺苗面积(万亩)                tb_area1 = new TextBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_area1, 2);               GrID.SetColumn(tb_area1, 2);               grID.Children.Add(tb_area1);               //一级苗面积(万亩)                tb_area2 = new TextBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_area2, 3);               GrID.SetColumn(tb_area2, 2);               grID.Children.Add(tb_area2);               //二级苗面积(万亩)                tb_area3 = new TextBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_area3, 4);               GrID.SetColumn(tb_area3, 2);               grID.Children.Add(tb_area3);               //三级苗面积(万亩)                tb_area4 = new TextBlock() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(tb_area4, 5);               GrID.SetColumn(tb_area4, 2);               grID.Children.Add(tb_area4);                  //超链接(苗情评价分析)                hlb1 = new Hyperlinkbutton() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(hlb1, 6);               GrID.SetColumn(hlb1, 0);               GrID.SetColumnSpan(hlb1, 3);               grID.Children.Add(hlb1);               //超链接(苗情数据报表)                hlb2 = new Hyperlinkbutton() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(hlb2, 7);               GrID.SetColumn(hlb2, 0);               GrID.SetColumnSpan(hlb2, 3);               grID.Children.Add(hlb2);               //超链接(苗情监测报告)                hlb3 = new Hyperlinkbutton() { FontSize = 14, VerticalAlignment = VerticalAlignment.Center };               GrID.SetRow(hlb3, 8);               GrID.SetColumn(hlb3, 0);               GrID.SetColumnSpan(hlb3, 3);               grID.Children.Add(hlb3);                        border.Child = grID;                  getData1SoapClIEnt clIEnt = new getData1SoapClIEnt();               clIEnt.GetCommentInfoCompleted += new EventHandler<GetCommentInfoCompletedEventArgs>(clIEnt_GetCommentInfoCompleted);               clIEnt.GetCommentInfoAsync(areaID, year, cycleID);                  return border;           }              voID clIEnt_GetCommentInfoCompleted(object sender, GetCommentInfoCompletedEventArgs e)           {               //设置值                tb_Title.Text = result.Split(',')[0].Split(':')[1];               //苗情评价分析                hlb1.Content = result.Split(',')[1].Split(':')[1];               hlb1.NavigateUri = new Uri("http://www.baIDu.com", UriKind.relativeOrabsolute);               //苗情数据报表                hlb2.Content = result.Split(',')[2].Split(':')[1];               hlb2.NavigateUri = new Uri("http://www.baIDu.com", UriKind.relativeOrabsolute);               //苗情监测报告                hlb3.Content = result.Split(',')[3].Split(':')[1];               hlb3.NavigateUri = new Uri("http://www.baIDu.com", UriKind.relativeOrabsolute);               //旺苗等级、占比和面积                tb_grade1.Text = result.Split(',')[4].Split('|')[0].Split(':')[1];               tb_percent1.Text = result.Split(',')[4].Split('|')[1].Split(':')[1];               tb_area1.Text = result.Split(',')[4].Split('|')[2].Split(':')[1];               //一级苗等级、占比和面积                tb_grade2.Text = result.Split(',')[5].Split('|')[0].Split(':')[1];               tb_percent2.Text = result.Split(',')[5].Split('|')[1].Split(':')[1];               tb_area2.Text = result.Split(',')[5].Split('|')[2].Split(':')[1];               //二级苗等级、占比和面积                tb_grade3.Text = result.Split(',')[6].Split('|')[0].Split(':')[1];               tb_percent3.Text = result.Split(',')[6].Split('|')[1].Split(':')[1];               tb_area3.Text = result.Split(',')[6].Split('|')[2].Split(':')[1];               //三级苗等级、占比和面积                tb_grade4.Text = result.Split(',')[7].Split('|')[0].Split(':')[1];               tb_percent4.Text = result.Split(',')[7].Split('|')[1].Split(':')[1];               tb_area4.Text = result.Split(',')[7].Split('|')[2].Split(':')[1];              }       }   }  
using System;using System.Collections.Generic;using System.linq;using System.Net;using System.windows;using System.windows.Controls;using System.windows.documents;using System.windows.input;using System.windows.Media;using System.windows.Media.Animation;using System.windows.Shapes;using System.windows.Media.Effects;using System.windows.Media.Imaging;using MapClIEnt.ServiceReference1;namespace MapClIEnt{    public class MapTips : ContextMenu    {        RichTextBox rtb;        string placename = string.Empty;        string areaID = string.Empty;        string year = string.Empty;        string cycleID = string.Empty;        //d出窗口中的显示文本控件        TextBlock tb_Title; //标题        TextBlock tb_grade1; //苗情等级1        TextBlock tb_grade2; //苗情等级2        TextBlock tb_grade3; //苗情等级3        TextBlock tb_grade4; //苗情等级4        TextBlock tb_percent1; //占比1        TextBlock tb_percent2; //占比2        TextBlock tb_percent3; //占比3        TextBlock tb_percent4; //占比4        TextBlock tb_area1; //面积1        TextBlock tb_area2; //面积2        TextBlock tb_area3; //面积3        TextBlock tb_area4; //面积4        Hyperlinkbutton hlb1; //超链接1        Hyperlinkbutton hlb2; //超链接2        Hyperlinkbutton hlb3; //超链接3        public MapTips(RichTextBox rtb,string name,string areaID,string year,string cycleID)        {            this.rtb = rtb;            this.placename = name;            this.areaID = areaID;            this.year = year;            this.cycleID = cycleID;        }        //构造菜单按钮并返回一个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) };            GrID grID = new GrID() { margin = new Thickness(1) };            //九行            grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });            grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });            grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });            grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });            grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });            grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });            grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });            grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });            grID.RowDeFinitions.Add(new RowDeFinition() { Height = new GrIDLength(30) });            //三列            grID.ColumnDeFinitions.Add(new ColumnDeFinition() { WIDth = new GrIDLength(80) });            grID.ColumnDeFinitions.Add(new ColumnDeFinition() { WIDth = new GrIDLength(80) });            grID.ColumnDeFinitions.Add(new ColumnDeFinition() { WIDth = new GrIDLength(80) });            //标题第一列            tb_Title = new TextBlock() { FontSize = 14,HorizontalAlignment = HorizontalAlignment.Center,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_Title,0);            GrID.SetColumn(tb_Title,0);            GrID.SetColumnSpan(tb_Title,3);            grID.Children.Add(tb_Title);            //苗情等级标题            TextBlock tb_grade = new TextBlock() { Text = "苗情等级",FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_grade,1);            GrID.SetColumn(tb_grade,0);            grID.Children.Add(tb_grade);            //旺苗            tb_grade1 = new TextBlock() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_grade1,2);            GrID.SetColumn(tb_grade1,0);            grID.Children.Add(tb_grade1);            //一级苗            tb_grade2 = new TextBlock() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_grade2,3);            GrID.SetColumn(tb_grade2,0);            grID.Children.Add(tb_grade2);            //二级苗            tb_grade3 = new TextBlock() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_grade3,4);            GrID.SetColumn(tb_grade3,0);            grID.Children.Add(tb_grade3);            //三级苗            tb_grade4 = new TextBlock() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_grade4,5);            GrID.SetColumn(tb_grade4,0);            grID.Children.Add(tb_grade4);            //占比标题            TextBlock tb_percent = new TextBlock() { Text = "占   比",VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_percent,1);            GrID.SetColumn(tb_percent,1);            grID.Children.Add(tb_percent);            //旺苗占比            tb_percent1 = new TextBlock() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_percent1,2);            GrID.SetColumn(tb_percent1,1);            grID.Children.Add(tb_percent1);            //一级苗占比            tb_percent2 = new TextBlock() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_percent2,3);            GrID.SetColumn(tb_percent2,1);            grID.Children.Add(tb_percent2);            //二级苗占比            tb_percent3 = new TextBlock() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_percent3,4);            GrID.SetColumn(tb_percent3,1);            grID.Children.Add(tb_percent3);            //三级苗占比            tb_percent4 = new TextBlock() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_percent4,5);            GrID.SetColumn(tb_percent4,1);            grID.Children.Add(tb_percent4);            //面积标题            TextBlock tb_area = new TextBlock() { Text = "面积(万亩)",VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_area,1);            GrID.SetColumn(tb_area,2);            grID.Children.Add(tb_area);            //旺苗面积(万亩)            tb_area1 = new TextBlock() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_area1,2);            GrID.SetColumn(tb_area1,2);            grID.Children.Add(tb_area1);            //一级苗面积(万亩)            tb_area2 = new TextBlock() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_area2,3);            GrID.SetColumn(tb_area2,2);            grID.Children.Add(tb_area2);            //二级苗面积(万亩)            tb_area3 = new TextBlock() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_area3,4);            GrID.SetColumn(tb_area3,2);            grID.Children.Add(tb_area3);            //三级苗面积(万亩)            tb_area4 = new TextBlock() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(tb_area4,5);            GrID.SetColumn(tb_area4,2);            grID.Children.Add(tb_area4);            //超链接(苗情评价分析)            hlb1 = new Hyperlinkbutton() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(hlb1,6);            GrID.SetColumn(hlb1,0);            GrID.SetColumnSpan(hlb1,3);            grID.Children.Add(hlb1);            //超链接(苗情数据报表)            hlb2 = new Hyperlinkbutton() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(hlb2,7);            GrID.SetColumn(hlb2,0);            GrID.SetColumnSpan(hlb2,3);            grID.Children.Add(hlb2);            //超链接(苗情监测报告)            hlb3 = new Hyperlinkbutton() { FontSize = 14,VerticalAlignment = VerticalAlignment.Center };            GrID.SetRow(hlb3,8);            GrID.SetColumn(hlb3,0);            GrID.SetColumnSpan(hlb3,3);            grID.Children.Add(hlb3);            border.Child = grID;            getData1SoapClIEnt clIEnt = new getData1SoapClIEnt();            clIEnt.GetCommentInfoCompleted += new EventHandler<GetCommentInfoCompletedEventArgs>(clIEnt_GetCommentInfoCompleted);            clIEnt.GetCommentInfoAsync(areaID,year,cycleID);            return border;        }        voID clIEnt_GetCommentInfoCompleted(object sender,GetCommentInfoCompletedEventArgs e)        {            //设置值            tb_Title.Text = result.Split(',')[0].Split(':')[1];            //苗情评价分析            hlb1.Content = result.Split(',')[1].Split(':')[1];            hlb1.NavigateUri = new Uri("http://www.baIDu.com",UriKind.relativeOrabsolute);            //苗情数据报表            hlb2.Content = result.Split(',')[2].Split(':')[1];            hlb2.NavigateUri = new Uri("http://www.baIDu.com",UriKind.relativeOrabsolute);            //苗情监测报告            hlb3.Content = result.Split(',')[3].Split(':')[1];            hlb3.NavigateUri = new Uri("http://www.baIDu.com",UriKind.relativeOrabsolute);            //旺苗等级、占比和面积            tb_grade1.Text = result.Split(',')[4].Split('|')[0].Split(':')[1];            tb_percent1.Text = result.Split(',')[4].Split('|')[1].Split(':')[1];            tb_area1.Text = result.Split(',')[4].Split('|')[2].Split(':')[1];            //一级苗等级、占比和面积            tb_grade2.Text = result.Split(',')[5].Split('|')[0].Split(':')[1];            tb_percent2.Text = result.Split(',')[5].Split('|')[1].Split(':')[1];            tb_area2.Text = result.Split(',')[5].Split('|')[2].Split(':')[1];            //二级苗等级、占比和面积            tb_grade3.Text = result.Split(',')[6].Split('|')[0].Split(':')[1];            tb_percent3.Text = result.Split(',')[6].Split('|')[1].Split(':')[1];            tb_area3.Text = result.Split(',')[6].Split('|')[2].Split(':')[1];            //三级苗等级、占比和面积            tb_grade4.Text = result.Split(',')[7].Split('|')[0].Split(':')[1];            tb_percent4.Text = result.Split(',')[7].Split('|')[1].Split(':')[1];            tb_area4.Text = result.Split(',')[7].Split('|')[2].Split(':')[1];        }    }}


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


[csharp] view plain copy print ? using System;   using System.Collections.Generic;   using System.linq;   using System.Net;   using System.windows;   using System.windows.Controls;   using System.windows.documents;   using System.windows.input;   using System.windows.Media;   using System.windows.Media.Animation;   using System.windows.Shapes;   using System.windows.Media.Effects;   using System.windows.Media.Imaging;      namespace MapClIEnt   {       public class RTBContextMenu : ContextMenu       {           RichTextBox rtb;           string placename = string.Empty;              public RTBContextMenu(RichTextBox rtb, string name)           {               this.rtb = rtb;               this.placename = name;           }              //构造菜单按钮并返回一个FrameworkElement对象            protected overrIDe FrameworkElement GetContent()           {               border border = new border() { borderBrush = new SolIDcolorBrush(color.FromArgb(255, Background = new SolIDcolorBrush(colors.White) };               border.Effect = new DropShadowEffect() { BlurRadius = 3, 236) };               GrID grID = new GrID() { margin = new Thickness(1) };               grID.ColumnDeFinitions.Add(new ColumnDeFinition() { WIDth = new GrIDLength(25) });               grID.ColumnDeFinitions.Add(new ColumnDeFinition() { WIDth = new GrIDLength(105) });               grID.Children.Add(new Rectangle() { Fill = new SolIDcolorBrush(color.FromArgb(255, 233, 238, 238)) });               grID.Children.Add(new Rectangle() { Fill = new SolIDcolorBrush(color.FromArgb(255, 226, 228, 231)), HorizontalAlignment = HorizontalAlignment.Right, WIDth = 1 });                  //田间视频                button tJspbutton = new button() { Height = 22, margin = new Thickness(0, 0), HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.top, HorizontalContentAlignment = HorizontalAlignment.left };               tJspbutton.Style = Application.Current.Resources["ContextMenubutton"as Style;               tJspbutton.Click += tJsp_MouseleftbuttonUp;               GrID.SetColumnSpan(tJspbutton, 2);               StackPanel sp = new StackPanel() { OrIEntation = OrIEntation.Horizontal };               Image tJspImage = new Image() { HorizontalAlignment = HorizontalAlignment.left, WIDth = 16, Height = 16, margin = new Thickness(1, 0) };               tJspImage.source = new BitmAPImage(new Uri("/MapClIEnt;component/Images/pop-movIE.png", UriKind.relativeOrabsolute));               sp.Children.Add(tJspImage);               TextBlock tJspText = new TextBlock() { Text = "田间视频", HorizontalAlignment = HorizontalAlignment.left, margin = new Thickness(16, 0) };               sp.Children.Add(tJspText);               tJspbutton.Content = sp;               grID.Children.Add(tJspbutton);                  //作物像片                button zwxpbutton = new button() { Height = 22, 24, HorizontalContentAlignment = HorizontalAlignment.left };               zwxpbutton.Style = Application.Current.Resources["ContextMenubutton"as Style;               zwxpbutton.Click += zwxp_MouseleftbuttonUp;               GrID.SetColumnSpan(zwxpbutton, 2);               sp = new StackPanel() { OrIEntation = OrIEntation.Horizontal };               Image zwxpImage = new Image() { HorizontalAlignment = HorizontalAlignment.left, 0) };               zwxpImage.source = new BitmAPImage(new Uri("/MapClIEnt;component/Images/pop-pic.png", UriKind.relativeOrabsolute));               sp.Children.Add(zwxpImage);               TextBlock zwxpText = new TextBlock() { Text = "作物图片", 0) };               sp.Children.Add(zwxpText);               zwxpbutton.Content = sp;               grID.Children.Add(zwxpbutton);                     //专家会议                button zjhybutton = new button() { Height = 22, 48, HorizontalContentAlignment = HorizontalAlignment.left };               zjhybutton.Style = Application.Current.Resources["ContextMenubutton"as Style;               zjhybutton.Click += zjhy_MouseleftbuttonUp;               GrID.SetColumnSpan(zjhybutton, 2);               sp = new StackPanel() { OrIEntation = OrIEntation.Horizontal };               Image zjhyImage = new Image() { HorizontalAlignment = HorizontalAlignment.left, 0) };               zjhyImage.source = new BitmAPImage(new Uri("/MapClIEnt;component/Images/pop-person.png", UriKind.relativeOrabsolute));               sp.Children.Add(zjhyImage);               TextBlock zjhyText = new TextBlock() { Text = "专家会议", 0) };               sp.Children.Add(zjhyText);               zjhybutton.Content = sp;               grID.Children.Add(zjhybutton);                  //现场联动                button xcldbutton = new button() { Height = 22, 72, HorizontalContentAlignment = HorizontalAlignment.left };               xcldbutton.Style = Application.Current.Resources["ContextMenubutton"as Style;               xcldbutton.Click += xcld_MouseleftbuttonUp;               GrID.SetColumnSpan(xcldbutton, 2);               sp = new StackPanel() { OrIEntation = OrIEntation.Horizontal };               Image xcldImage = new Image() { HorizontalAlignment = HorizontalAlignment.left, 0) };               xcldImage.source = new BitmAPImage(new Uri("/MapClIEnt;component/Images/pop-link.png", UriKind.relativeOrabsolute));               sp.Children.Add(xcldImage);               TextBlock xcldText = new TextBlock() { Text = "现场联动", 0) };               sp.Children.Add(xcldText);               xcldbutton.Content = sp;               grID.Children.Add(xcldbutton);                  border.Child = grID;               return border;           }              //            //处理事件            //            voID tJsp_MouseleftbuttonUp(object sender, RoutedEventArgs e)           {               //页面跳转,使用参数进行url传递 参数值为placename(请注意)                System.windows.browser.HTMLPage.Window.Navigate(new Uri("../SensorMonitor/VedioList.aspx?Areaname=" + placename, UriKind.relativeOrabsolute), "_self");               Close();           }              voID zwxp_MouseleftbuttonUp(object sender, RoutedEventArgs e)           {               //页面跳转                System.windows.browser.HTMLPage.Window.Navigate(new Uri("../SensorMonitor/Instantimage.aspx?Areaname=" + placename, "_self");               Close();           }              voID zjhy_MouseleftbuttonUp(object sender, RoutedEventArgs e)           {               //页面跳转                System.windows.browser.HTMLPage.Window.Navigate(new Uri("http://www.baIDu.com""_self");               Close();           }              voID xcld_MouseleftbuttonUp(object sender, RoutedEventArgs e)           {               //页面跳转                System.windows.browser.HTMLPage.Window.Navigate(new Uri("http://www.baIDu.com""_self");               Close();           }       }   }  
using System;using System.Collections.Generic;using System.linq;using System.Net;using System.windows;using System.windows.Controls;using System.windows.documents;using System.windows.input;using System.windows.Media;using System.windows.Media.Animation;using System.windows.Shapes;using System.windows.Media.Effects;using System.windows.Media.Imaging;namespace MapClIEnt{    public class RTBContextMenu : ContextMenu    {        RichTextBox rtb;        string placename = string.Empty;        public RTBContextMenu(RichTextBox rtb,string name)        {            this.rtb = rtb;            this.placename = name;        }        //构造菜单按钮并返回一个FrameworkElement对象        protected overrIDe FrameworkElement GetContent()        {            border border = new border() { borderBrush = new SolIDcolorBrush(color.FromArgb(255,236) };            GrID grID = new GrID() { margin = new Thickness(1) };            grID.ColumnDeFinitions.Add(new ColumnDeFinition() { WIDth = new GrIDLength(25) });            grID.ColumnDeFinitions.Add(new ColumnDeFinition() { WIDth = new GrIDLength(105) });            grID.Children.Add(new Rectangle() { Fill = new SolIDcolorBrush(color.FromArgb(255,233,238,238)) });            grID.Children.Add(new Rectangle() { Fill = new SolIDcolorBrush(color.FromArgb(255,226,228,231)),HorizontalAlignment = HorizontalAlignment.Right,WIDth = 1 });            //田间视频            button tJspbutton = new button() { Height = 22,margin = new Thickness(0,0),HorizontalAlignment = HorizontalAlignment.Stretch,VerticalAlignment = VerticalAlignment.top,HorizontalContentAlignment = HorizontalAlignment.left };            tJspbutton.Style = Application.Current.Resources["ContextMenubutton"] as Style;            tJspbutton.Click += tJsp_MouseleftbuttonUp;            GrID.SetColumnSpan(tJspbutton,2);            StackPanel sp = new StackPanel() { OrIEntation = OrIEntation.Horizontal };            Image tJspImage = new Image() { HorizontalAlignment = HorizontalAlignment.left,WIDth = 16,Height = 16,margin = new Thickness(1,0) };            tJspImage.source = new BitmAPImage(new Uri("/MapClIEnt;component/Images/pop-movIE.png",UriKind.relativeOrabsolute));            sp.Children.Add(tJspImage);            TextBlock tJspText = new TextBlock() { Text = "田间视频",HorizontalAlignment = HorizontalAlignment.left,margin = new Thickness(16,0) };            sp.Children.Add(tJspText);            tJspbutton.Content = sp;            grID.Children.Add(tJspbutton);            //作物像片            button zwxpbutton = new button() { Height = 22,24,HorizontalContentAlignment = HorizontalAlignment.left };            zwxpbutton.Style = Application.Current.Resources["ContextMenubutton"] as Style;            zwxpbutton.Click += zwxp_MouseleftbuttonUp;            GrID.SetColumnSpan(zwxpbutton,2);            sp = new StackPanel() { OrIEntation = OrIEntation.Horizontal };            Image zwxpImage = new Image() { HorizontalAlignment = HorizontalAlignment.left,0) };            zwxpImage.source = new BitmAPImage(new Uri("/MapClIEnt;component/Images/pop-pic.png",UriKind.relativeOrabsolute));            sp.Children.Add(zwxpImage);            TextBlock zwxpText = new TextBlock() { Text = "作物图片",0) };            sp.Children.Add(zwxpText);            zwxpbutton.Content = sp;            grID.Children.Add(zwxpbutton);            //专家会议            button zjhybutton = new button() { Height = 22,48,HorizontalContentAlignment = HorizontalAlignment.left };            zjhybutton.Style = Application.Current.Resources["ContextMenubutton"] as Style;            zjhybutton.Click += zjhy_MouseleftbuttonUp;            GrID.SetColumnSpan(zjhybutton,2);            sp = new StackPanel() { OrIEntation = OrIEntation.Horizontal };            Image zjhyImage = new Image() { HorizontalAlignment = HorizontalAlignment.left,0) };            zjhyImage.source = new BitmAPImage(new Uri("/MapClIEnt;component/Images/pop-person.png",UriKind.relativeOrabsolute));            sp.Children.Add(zjhyImage);            TextBlock zjhyText = new TextBlock() { Text = "专家会议",0) };            sp.Children.Add(zjhyText);            zjhybutton.Content = sp;            grID.Children.Add(zjhybutton);            //现场联动            button xcldbutton = new button() { Height = 22,72,HorizontalContentAlignment = HorizontalAlignment.left };            xcldbutton.Style = Application.Current.Resources["ContextMenubutton"] as Style;            xcldbutton.Click += xcld_MouseleftbuttonUp;            GrID.SetColumnSpan(xcldbutton,2);            sp = new StackPanel() { OrIEntation = OrIEntation.Horizontal };            Image xcldImage = new Image() { HorizontalAlignment = HorizontalAlignment.left,0) };            xcldImage.source = new BitmAPImage(new Uri("/MapClIEnt;component/Images/pop-link.png",UriKind.relativeOrabsolute));            sp.Children.Add(xcldImage);            TextBlock xcldText = new TextBlock() { Text = "现场联动",0) };            sp.Children.Add(xcldText);            xcldbutton.Content = sp;            grID.Children.Add(xcldbutton);            border.Child = grID;            return border;        }        //        //处理事件        //        voID tJsp_MouseleftbuttonUp(object sender,RoutedEventArgs e)        {            //页面跳转,使用参数进行url传递 参数值为placename(请注意)            System.windows.browser.HTMLPage.Window.Navigate(new Uri("../SensorMonitor/VedioList.aspx?Areaname=" + placename,UriKind.relativeOrabsolute),"_self");            Close();        }        voID zwxp_MouseleftbuttonUp(object sender,RoutedEventArgs e)        {            //页面跳转            System.windows.browser.HTMLPage.Window.Navigate(new Uri("../SensorMonitor/Instantimage.aspx?Areaname=" + placename,"_self");            Close();        }        voID zjhy_MouseleftbuttonUp(object sender,RoutedEventArgs e)        {            //页面跳转            System.windows.browser.HTMLPage.Window.Navigate(new Uri("http://www.baIDu.com","_self");            Close();        }        voID xcld_MouseleftbuttonUp(object sender,"_self");            Close();        }    }}

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



[csharp] view plain copy print ? <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                xmlns:d="http://schemas.microsoft.com/Expression/blend/2008"                xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"                xmlns:esri="http://schemas.esri.com/arcgis/clIEnt/2009"                xmlns:toolkit="clr-namespace:ESRI.ArcGIS.ClIEnt.Toolkit;assembly=ESRI.ArcGIS.ClIEnt.Toolkit"                xmlns:symbols="clr-namespace:ESRI.ArcGIS.ClIEnt.Symbols;assembly=ESRI.ArcGIS.ClIEnt"                xmlns:local="clr-namespace:GrowthMonitor"                xmlns:vsm="clr-namespace:System.windows;assembly=System.windows"                xmlns:i="clr-namespace:System.windows.Interactivity;assembly=System.windows.Interactivity"                 xmlns:sys="clr-namespace:System;assembly=mscorlib"                xmlns:interaction="http://schemas.microsoft.com/Expression/2010/interactivity"                xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"                xmlns:slData="clr-namespace:System.windows.Controls;assembly=System.windows.Controls.Data"                x:Class="MapClIEnt.MainPage" d:DesignHeight="300" d:DesignWIDth="400" Loaded="UserControl_Loaded" mc:Ignorable="d">          <GrID x:name="LayoutRoot" Background="White">           <GrID.Resources>               <esri:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Size="12" x:name="dms_Point" Style="Circle">                   <esri:SimpleMarkerSymbol.ControlTemplate>                       <ControlTemplate>                           <GrID x:name="RootElement" RendertransformOrigin="0.5,0.5" >                               <GrID.Rendertransform>                                   <Scaletransform ScaleX="1" ScaleY="1" />                               </GrID.Rendertransform>                               <visualstatemanager.VisualStateGroups>                                   <VisualStateGroup x:name="CommonStates">                                       <VisualState x:name="normal">                                           <Storyboard>                                               <DoubleAnimation BeginTime="00:00:00"                                                                          Storyboard.Targetname="RootElement"                                                                          Storyboard.TargetProperty="(UIElement.Rendertransform).(Scaletransform.ScaleX)"                                                                          To="1" Duration="0:0:0.1" />                                               <DoubleAnimation BeginTime="00:00:00"                                                                          Storyboard.Targetname="RootElement"                                                                          Storyboard.TargetProperty="(UIElement.Rendertransform).(Scaletransform.ScaleY)"                                                                          To="1" Duration="0:0:0.1" />                                           </Storyboard>                                       </VisualState>                                       <VisualState x:name="MouSEOver">                                           <Storyboard>                                               <DoubleAnimation BeginTime="00:00:00"                                                                          Storyboard.Targetname="RootElement"                                                                          Storyboard.TargetProperty="(UIElement.Rendertransform).(Scaletransform.ScaleX)"                                                                          To="1.5" Duration="0:0:0.1" />                                               <DoubleAnimation BeginTime="00:00:00"                                                                          Storyboard.Targetname="RootElement"                                                                          Storyboard.TargetProperty="(UIElement.Rendertransform).(Scaletransform.ScaleY)"                                                                          To="1.5" Duration="0:0:0.1" />                                           </Storyboard>                                       </VisualState>                                   </VisualStateGroup>                               </visualstatemanager.VisualStateGroups>                               <Ellipse x:name="ellipse"                                                                                                           WIDth="{Binding Symbol.Size}"                                                       Height="{Binding Symbol.Size}" >                                   <Ellipse.Fill>                                       <RadialGradIEntBrush GradIEntOrigin="0.5,0.5" Center="0.5,0.5"                                                                   RadiusX="0.5" RadiusY="0.5">                                           <GradIEntStop color="Red" Offset="0.25" />                                          </RadialGradIEntBrush>                                   </Ellipse.Fill>                               </Ellipse>                           </GrID>                       </ControlTemplate>                   </esri:SimpleMarkerSymbol.ControlTemplate>               </esri:SimpleMarkerSymbol>               <esri:Simplelinesymbol x:Key="Defaultlinesymbol" color="Red" WIDth="6"  />               <esri:SimpleFillSymbol x:Key="DefaultFillSymbol" borderBrush="Red" borderThickness="2" x:name="sf_Point"/>              </GrID.Resources>           <esri:Map x:name="myMap" IslogoVisible="False" Extent="114.289579051054,29.3907111115968,121.380372848428,33.7272787947227">               <i:Interaction.Behaviors>                   <local:WheelZoom />               </i:Interaction.Behaviors>               <esri:Map.Layers>                   <esri:ArcGISTiledMapServiceLayer ID="BaseLayer" Url="http://192.168.2.5/arcgis/rest/services/AnHuiBase/MapServer"/>                   <!---特征图层-->                   <!--<esri:FeatureLayer ID="MyFeatureLayer" Url="http://192.168.2.5/arcgis/rest/services/AnHuIDynamic/MapServer/0">                   <esri:FeatureLayer.Clusterer>                       <esri:FlareClusterer                               FlareBackground="#99FF0000"                               FlareForeground="White"                               MaximumFlareCount="9"/>                   </esri:FeatureLayer.Clusterer>                   <esri:FeatureLayer.OutFIElds>                       <sys:String>ID</sys:String>                       <sys:String>name</sys:String>                   </esri:FeatureLayer.OutFIElds>                   <esri:FeatureLayer.MapTip>                       <GrID Background="Blue" WIDth="200" Height="200">                           <StackPanel>                               <TextBlock Text="{Binding [name]}" Foreground="White" FontWeight="Bold" />                           </StackPanel>                       </GrID>                   </esri:FeatureLayer.MapTip>               </esri:FeatureLayer>-->                   <!--Graphicslayer-->                   <esri:Graphicslayer ID="MyGraphicslayer">                   </esri:Graphicslayer>               </esri:Map.Layers>           </esri:Map>           <GrID Height="60" HorizontalAlignment="Right" VerticalAlignment="top"  WIDth="300">               <GrID.ColumnDeFinitions>                   <ColumnDeFinition WIDth="0.128*"/>                   <ColumnDeFinition WIDth="0.142*"/>                   <ColumnDeFinition WIDth="0.14*"/>                   <ColumnDeFinition WIDth="0.15*"/>                   <ColumnDeFinition WIDth="0.14*"/>                   <ColumnDeFinition WIDth="0.14*"/>                   <ColumnDeFinition WIDth="0.15*"/>               </GrID.ColumnDeFinitions>               <border x:name="bZoomIn" borderThickness="1" margin="0,-1,1">                   <border.Background>                       <ImageBrush ImageSource="Images/i_zoomin.png" Stretch="None"/>                   </border.Background>               </border>               <border x:name="bZoomOut" borderThickness="1" GrID.Column="1" margin="3,-2,2,2">                   <border.Background>                       <ImageBrush ImageSource="Images/i_zoomout.png" Stretch="None"/>                   </border.Background>               </border>               <border x:name="bPan" borderThickness="1" GrID.Column="2" margin="2,1">                   <border.Background>                       <ImageBrush ImageSource="Images/i_pan.png" Stretch="None"/>                   </border.Background>               </border>               <border x:name="bPrevIoUs" borderThickness="1" GrID.Column="3" margin="4,1,5,-1">                   <border.Background>                       <ImageBrush ImageSource="Images/i_prevIoUs.png" Stretch="None"/>                   </border.Background>               </border>               <border x:name="bNext" borderThickness="1" GrID.Column="4" margin="4,-2" RendertransformOrigin="1.385,0.545">                   <border.Background>                       <ImageBrush ImageSource="Images/i_next.png" Stretch="None"/>                   </border.Background>               </border>               <border x:name="bFullExtent" borderThickness="1" GrID.Column="5" margin="2,0" RendertransformOrigin="1.385,0.545">                   <border.Background>                       <ImageBrush ImageSource="Images/i_globe.png" Stretch="None"/>                   </border.Background>               </border>               <border x:name="bFullScreen" borderThickness="1" GrID.Column="6" margin="8,0.545">                   <border.Background>                       <ImageBrush ImageSource="Images/i_Widget.png" Stretch="None"/>                   </border.Background>               </border>           </GrID>              <esri:Navigation margin="5" HorizontalAlignment="left" VerticalAlignment="Bottom"                            Map="{Binding Elementname=myMap}"  >           </esri:Navigation>           <esri:MapProgressbar x:name="MyProgressbar"                Map="{Binding Elementname=myMap}"               HorizontalAlignment="Center" VerticalAlignment="Bottom"               WIDth="200" Height="36"               margin="25"  />           <StackPanel HorizontalAlignment="Right" OrIEntation="Horizontal" margin="0,0" VerticalAlignment="top">               <button Style="{StaticResource darkbuttonStyle}" margin="3,0" >                   <i:Interaction.Triggers>                       <i:EventTrigger Eventname="Click" >                           <local:ToggleFullScreenAction />                       </i:EventTrigger>                   </i:Interaction.Triggers>                   <Image Source="Images/Fullscreen-32.png" Height="24" margin="-4"                                  tooltipService.tooltip="全屏"/>               </button>           </StackPanel>           <button Content="查找" Height="23" HorizontalAlignment="left" margin="279,110,0" name="button1" VerticalAlignment="top" WIDth="75" Click="button1_Click" />           <TextBox Height="23" HorizontalAlignment="left" margin="161,0" name="textBox1" VerticalAlignment="top" WIDth="120" />           <sdk:Label Height="28" HorizontalAlignment="left" margin="45,0" name="label1" FontSize="15" Content="输入监测点名称:" VerticalAlignment="top" WIDth="120" />       </GrID>   </UserControl>  
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"             xmlns:d="http://schemas.microsoft.com/Expression/blend/2008"             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"             xmlns:esri="http://schemas.esri.com/arcgis/clIEnt/2009"             xmlns:toolkit="clr-namespace:ESRI.ArcGIS.ClIEnt.Toolkit;assembly=ESRI.ArcGIS.ClIEnt.Toolkit"             xmlns:symbols="clr-namespace:ESRI.ArcGIS.ClIEnt.Symbols;assembly=ESRI.ArcGIS.ClIEnt"             xmlns:local="clr-namespace:GrowthMonitor"             xmlns:vsm="clr-namespace:System.windows;assembly=System.windows"             xmlns:i="clr-namespace:System.windows.Interactivity;assembly=System.windows.Interactivity"              xmlns:sys="clr-namespace:System;assembly=mscorlib"             xmlns:interaction="http://schemas.microsoft.com/Expression/2010/interactivity"             xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"             xmlns:slData="clr-namespace:System.windows.Controls;assembly=System.windows.Controls.Data"             x:Class="MapClIEnt.MainPage" d:DesignHeight="300" d:DesignWIDth="400" Loaded="UserControl_Loaded" mc:Ignorable="d">    <GrID x:name="LayoutRoot" Background="White">        <GrID.Resources>            <esri:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Size="12" x:name="dms_Point" Style="Circle">                <esri:SimpleMarkerSymbol.ControlTemplate>                    <ControlTemplate>                        <GrID x:name="RootElement" RendertransformOrigin="0.5,0.5" >                            <GrID.Rendertransform>                                <Scaletransform ScaleX="1" ScaleY="1" />                            </GrID.Rendertransform>                            <visualstatemanager.VisualStateGroups>                                <VisualStateGroup x:name="CommonStates">                                    <VisualState x:name="normal">                                        <Storyboard>                                            <DoubleAnimation BeginTime="00:00:00"                                                                       Storyboard.Targetname="RootElement"                                                                       Storyboard.TargetProperty="(UIElement.Rendertransform).(Scaletransform.ScaleX)"                                                                       To="1" Duration="0:0:0.1" />                                            <DoubleAnimation BeginTime="00:00:00"                                                                       Storyboard.Targetname="RootElement"                                                                       Storyboard.TargetProperty="(UIElement.Rendertransform).(Scaletransform.ScaleY)"                                                                       To="1" Duration="0:0:0.1" />                                        </Storyboard>                                    </VisualState>                                    <VisualState x:name="MouSEOver">                                        <Storyboard>                                            <DoubleAnimation BeginTime="00:00:00"                                                                       Storyboard.Targetname="RootElement"                                                                       Storyboard.TargetProperty="(UIElement.Rendertransform).(Scaletransform.ScaleX)"                                                                       To="1.5" Duration="0:0:0.1" />                                            <DoubleAnimation BeginTime="00:00:00"                                                                       Storyboard.Targetname="RootElement"                                                                       Storyboard.TargetProperty="(UIElement.Rendertransform).(Scaletransform.ScaleY)"                                                                       To="1.5" Duration="0:0:0.1" />                                        </Storyboard>                                    </VisualState>                                </VisualStateGroup>                            </visualstatemanager.VisualStateGroups>                            <Ellipse x:name="ellipse"			                                                                                            WIDth="{Binding Symbol.Size}"                                                    Height="{Binding Symbol.Size}" >                                <Ellipse.Fill>                                    <RadialGradIEntBrush GradIEntOrigin="0.5,0.5" Center="0.5,0.5"                                                                RadiusX="0.5" RadiusY="0.5">                                        <GradIEntStop color="Red" Offset="0.25" />                                    </RadialGradIEntBrush>                                </Ellipse.Fill>                            </Ellipse>                        </GrID>                    </ControlTemplate>                </esri:SimpleMarkerSymbol.ControlTemplate>            </esri:SimpleMarkerSymbol>            <esri:Simplelinesymbol x:Key="Defaultlinesymbol" color="Red" WIDth="6"  />            <esri:SimpleFillSymbol x:Key="DefaultFillSymbol" borderBrush="Red" borderThickness="2" x:name="sf_Point"/>        </GrID.Resources>        <esri:Map x:name="myMap" IslogoVisible="False" Extent="114.289579051054,33.7272787947227">            <i:Interaction.Behaviors>                <local:WheelZoom />            </i:Interaction.Behaviors>            <esri:Map.Layers>                <esri:ArcGISTiledMapServiceLayer ID="BaseLayer" Url="http://192.168.2.5/arcgis/rest/services/AnHuiBase/MapServer"/>                <!---特征图层-->                <!--<esri:FeatureLayer ID="MyFeatureLayer" Url="http://192.168.2.5/arcgis/rest/services/AnHuIDynamic/MapServer/0">                <esri:FeatureLayer.Clusterer>                    <esri:FlareClusterer            				FlareBackground="#99FF0000"            				FlareForeground="White"            				MaximumFlareCount="9"/>                </esri:FeatureLayer.Clusterer>                <esri:FeatureLayer.OutFIElds>                    <sys:String>ID</sys:String>                    <sys:String>name</sys:String>                </esri:FeatureLayer.OutFIElds>                <esri:FeatureLayer.MapTip>                    <GrID Background="Blue" WIDth="200" Height="200">                        <StackPanel>                            <TextBlock Text="{Binding [name]}" Foreground="White" FontWeight="Bold" />                        </StackPanel>                    </GrID>                </esri:FeatureLayer.MapTip>            </esri:FeatureLayer>-->                <!--Graphicslayer-->                <esri:Graphicslayer ID="MyGraphicslayer">                </esri:Graphicslayer>            </esri:Map.Layers>        </esri:Map>        <GrID Height="60" HorizontalAlignment="Right" VerticalAlignment="top"  WIDth="300">            <GrID.ColumnDeFinitions>                <ColumnDeFinition WIDth="0.128*"/>                <ColumnDeFinition WIDth="0.142*"/>                <ColumnDeFinition WIDth="0.14*"/>                <ColumnDeFinition WIDth="0.15*"/>                <ColumnDeFinition WIDth="0.14*"/>                <ColumnDeFinition WIDth="0.14*"/>                <ColumnDeFinition WIDth="0.15*"/>            </GrID.ColumnDeFinitions>            <border x:name="bZoomIn" borderThickness="1" margin="0,1">                <border.Background>                    <ImageBrush ImageSource="Images/i_zoomin.png" Stretch="None"/>                </border.Background>            </border>            <border x:name="bZoomOut" borderThickness="1" GrID.Column="1" margin="3,2">                <border.Background>                    <ImageBrush ImageSource="Images/i_zoomout.png" Stretch="None"/>                </border.Background>            </border>            <border x:name="bPan" borderThickness="1" GrID.Column="2" margin="2,1">                <border.Background>                    <ImageBrush ImageSource="Images/i_pan.png" Stretch="None"/>                </border.Background>            </border>            <border x:name="bPrevIoUs" borderThickness="1" GrID.Column="3" margin="4,-1">                <border.Background>                    <ImageBrush ImageSource="Images/i_prevIoUs.png" Stretch="None"/>                </border.Background>            </border>            <border x:name="bNext" borderThickness="1" GrID.Column="4" margin="4,-2" RendertransformOrigin="1.385,0.545">                <border.Background>                    <ImageBrush ImageSource="Images/i_next.png" Stretch="None"/>                </border.Background>            </border>            <border x:name="bFullExtent" borderThickness="1" GrID.Column="5" margin="2,0" RendertransformOrigin="1.385,0.545">                <border.Background>                    <ImageBrush ImageSource="Images/i_globe.png" Stretch="None"/>                </border.Background>            </border>            <border x:name="bFullScreen" borderThickness="1" GrID.Column="6" margin="8,0.545">                <border.Background>                    <ImageBrush ImageSource="Images/i_Widget.png" Stretch="None"/>                </border.Background>            </border>        </GrID>        <esri:Navigation margin="5" HorizontalAlignment="left" VerticalAlignment="Bottom"                         Map="{Binding Elementname=myMap}"  >        </esri:Navigation>        <esri:MapProgressbar x:name="MyProgressbar" 			Map="{Binding Elementname=myMap}"			HorizontalAlignment="Center" VerticalAlignment="Bottom"			WIDth="200" Height="36"			margin="25"  />        <StackPanel HorizontalAlignment="Right" OrIEntation="Horizontal" margin="0,0" VerticalAlignment="top">            <button Style="{StaticResource darkbuttonStyle}" margin="3,0" >                <i:Interaction.Triggers>                    <i:EventTrigger Eventname="Click" >                        <local:ToggleFullScreenAction />                    </i:EventTrigger>                </i:Interaction.Triggers>                <Image Source="Images/Fullscreen-32.png" Height="24" margin="-4"							   tooltipService.tooltip="全屏"/>            </button>        </StackPanel>        <button Content="查找" Height="23" HorizontalAlignment="left" margin="279,0" name="button1" VerticalAlignment="top" WIDth="75" Click="button1_Click" />        <TextBox Height="23" HorizontalAlignment="left" margin="161,0" name="textBox1" VerticalAlignment="top" WIDth="120" />        <sdk:Label Height="28" HorizontalAlignment="left" margin="45,0" name="label1" FontSize="15" Content="输入监测点名称:" VerticalAlignment="top" WIDth="120" />    </GrID></UserControl>

[csharp] view plain copy print ? using System;   using System.Collections.Generic;   using System.linq;   using System.Net;   using System.windows;   using System.windows.Controls;   using System.windows.documents;   using System.windows.input;   using System.windows.Media;   using System.windows.Media.Animation;   using System.windows.Shapes;   using ESRI.ArcGIS.ClIEnt.Symbols;   using ESRI.ArcGIS.ClIEnt;   using ESRI.ArcGIS.ClIEnt.Tasks;   using System.windows.Data;   using System.Runtime.Serialization;   using ESRI.ArcGIS.ClIEnt.Geometry;   using MapClIEnt.UserControls;      namespace MapClIEnt   {       public partial class MainPage : UserControl       {           //一些列变量定义            public string str = null//用来接收aspx页面传递到xap中的参数字符串            string[] infos = null;           public string level = string.Empty; //市县等级 市=1/县=2            public string areaID = string.Empty; //地区ID,包括市及县的编号            public string color = string.Empty; //颜色值            public string year = string.Empty; //年份            public string cycleID = string.Empty; //生育周期编号               public MainPage(Dictionary<stringstring> paramsDic)           {               InitializeComponent();               if (paramsDic.TryGetValue("STR"out str))               {                   //获取到aspx页面传递过来的参数                   }               //按照|进行拆分成每一个监测点的信息                infos = str.Split('|');                  //初始化页面,开始地图加载条                MyDrawObject = new Draw(myMap)               {                   FillSymbol = LayoutRoot.Resources["DefaultFillSymbol"as ESRI.ArcGIS.ClIEnt.Symbols.FillSymbol,                   DrawMode = DrawMode.Rectangle               };                  MyDrawObject.DrawComplete += myDrawObject_DrawComplete;           }                 private voID UserControl_Loaded(object sender, RoutedEventArgs e)           {               FindGraphicsAndShowInMap("监测点");           }                 private voID button_Click(object sender, RoutedEventArgs e)           {               FindGraphicsAndShowInMap("临泉监测点");           }              //#region 市界图层            //public voID FindCityGraphicsAndShowInMap(string conditions)            //{            //    // 初始化查找 *** 作            //    FindTask findCityTask = new FindTask("http://192.168.2.5/arcgis/rest/services/AnHuIDynamic/MapServer/");            //    findCityTask.ExecuteCompleted += new EventHandler<FindEventArgs>(findCityTask_ExecuteCompleted);            //    findCityTask.Failed += new EventHandler<TaskFailedEventArgs>(findCityTask_Failed);               //    //初始化查找参数,指定name字段作为小麦监测点层的搜素条件,并返回特征图层作为查找结果            //    FindParameters findParameters = new FindParameters();            //    findParameters.LayerIDs.AddRange(new int[] { 2 });            //    findParameters.SearchFIElds.AddRange(new string[] { "AreaID", "name" });            //    findParameters.ReturnGeometry = true;               //    //要查找点的信息            //    findParameters.SearchText = conditions;               //    findCityTask.ExecuteAsync(findParameters);            //}               ////查找失败            //voID findCityTask_Failed(object sender, TaskFailedEventArgs e)            //{            //    MessageBox.Show("查找失败: " + e.Error);            //}               //voID findCityTask_ExecuteCompleted(object sender, FindEventArgs e)            //{            //    // 清除先前的图层            //    Graphicslayer graphicslayer = myMap.Layers["MyGraphicslayer"] as Graphicslayer;            //    graphicslayer.Cleargraphics();               //    // 检查新的结果            //    if (e.FindResults.Count > 0)            //    {            //        //将查询出来的结果在地图上显示出来            //        foreach (FindResult result in e.FindResults)            //        {            //            result.Feature.Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.ClIEnt.Symbols.Symbol;            //            graphicslayer.Graphics.Add(result.Feature);               //            //左键菜单            //            result.Feature.MouseleftbuttonDown += new MousebuttonEventHandler(Feature_MouseleftbuttonDown);            //            result.Feature.MouseleftbuttonUp += new MousebuttonEventHandler(Feature_MouseleftbuttonUp);            //            //右键菜单            //            result.Feature.MouseRightbuttonDown += new MousebuttonEventHandler(Feature_MouseRightbuttonDown);            //            result.Feature.MouseRightbuttonUp += new MousebuttonEventHandler(Feature_MouseRightbuttonUp);               //        }            //        //坐标自动定位            //        ESRI.ArcGIS.ClIEnt.Geometry.Envelope selectedFeatureExtent = e.FindResults[0].Feature.Geometry.Extent;               //        double expandPercentage = 30;               //        double wIDthExpand = selectedFeatureExtent.WIDth * (expandPercentage / 100);            //        double heightExpand = selectedFeatureExtent.Height * (expandPercentage / 100);               //        ESRI.ArcGIS.ClIEnt.Geometry.Envelope displayExtent = new ESRI.ArcGIS.ClIEnt.Geometry.Envelope(            //        selectedFeatureExtent.XMin - (wIDthExpand / 2),           //        selectedFeatureExtent.YMin - (heightExpand / 2),           //        selectedFeatureExtent.XMax + (wIDthExpand / 2),           //        selectedFeatureExtent.YMax + (heightExpand / 2));               //        myMap.ZoomTo(displayExtent);            //    }            //    else            //    {            //        MessageBox.Show("没有发现匹配该搜索的记录!");            //    }            //}               //#endregion             #region 小麦监测点图层               /// <summary>            /// 根据条件查找监测点图层(0)            /// </summary>            /// <param name="conditions"></param>            public voID FindGraphicsAndShowInMap(string conditions)           {               // 初始化查找 *** 作                FindTask findTask = new FindTask("http://192.168.2.5/arcgis/rest/services/AnHuIDynamic/MapServer/");               findTask.ExecuteCompleted += FindTask_ExecuteCompleted;               findTask.Failed += FindTask_Failed;                  //初始化查找参数,指定name字段作为小麦监测点层的搜素条件,并返回特征图层作为查找结果                FindParameters findParameters = new FindParameters();               findParameters.LayerIDs.AddRange(new int[] { 0 });               findParameters.SearchFIElds.AddRange(new string[] { "ID""name" });               findParameters.ReturnGeometry = true;                  //要查找点的信息                findParameters.SearchText = conditions;                  findTask.ExecuteAsync(findParameters);           }             #region FindTask 查找任务开始            // 查找结束时,开始绘制点到图层上            private voID FindTask_ExecuteCompleted(object sender, FindEventArgs args)           {               // 清除先前的图层                Graphicslayer graphicslayer = myMap.Layers["MyGraphicslayer"as Graphicslayer;               graphicslayer.Cleargraphics();                  // 检查新的结果                if (args.FindResults.Count > 0)               {                   //将查询出来的结果在地图上显示出来                    foreach (FindResult result in args.FindResults)                   {                       //赋值颜色值                        this.dms_Point.color = new SolIDcolorBrush(colors.Red);                       result.Feature.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"as ESRI.ArcGIS.ClIEnt.Symbols.Symbol;                       graphicslayer.Graphics.Add(result.Feature);                          //左键菜单                        result.Feature.MouseleftbuttonDown += new MousebuttonEventHandler(Feature_MouseleftbuttonDown);                       result.Feature.MouseleftbuttonUp += new MousebuttonEventHandler(Feature_MouseleftbuttonUp);                       //右键菜单                        result.Feature.MouseRightbuttonDown += new MousebuttonEventHandler(Feature_MouseRightbuttonDown);                       result.Feature.MouseRightbuttonUp += new MousebuttonEventHandler(Feature_MouseRightbuttonUp);                      }                   //坐标自动定位                    ESRI.ArcGIS.ClIEnt.Geometry.Envelope selectedFeatureExtent = args.FindResults[0].Feature.Geometry.Extent;                      double expandPercentage = 30;                      double wIDthExpand = selectedFeatureExtent.WIDth * (expandPercentage / 100);                   double heightExpand = selectedFeatureExtent.Height * (expandPercentage / 100);                      ESRI.ArcGIS.ClIEnt.Geometry.Envelope displayExtent = new ESRI.ArcGIS.ClIEnt.Geometry.Envelope(                   selectedFeatureExtent.XMin - (wIDthExpand / 2),                   selectedFeatureExtent.YMin - (heightExpand / 2),                   selectedFeatureExtent.XMax + (wIDthExpand / 2),                   selectedFeatureExtent.YMax + (heightExpand / 2));                      myMap.ZoomTo(displayExtent);               }               else               {                   MessageBox.Show("没有发现匹配该搜索的记录!");               }           }              //当查找失败时进行提示 *** 作            private voID FindTask_Failed(object sender, TaskFailedEventArgs args)           {               MessageBox.Show("查找失败: " + args.Error);           }             #endregion FindTask 查找任务结束             #endregion               RichTextBox rtb;           #region 鼠标左键事件开始            voID Feature_MouseleftbuttonUp(object sender, MousebuttonEventArgs e)           {               //鼠标左键,显示tooltip信息                Graphic g = sender as Graphic;               //这里需要添加一个不消失的d出框,并可以移入进行点击                MapTips tips = new MapTips(rtb, g.Attributes["name"].ToString().Trim(), g.Attributes["AreaID"].ToString().Trim(), "-1""-1");               tips.Show(e.Getposition(LayoutRoot));           }              voID Feature_MouseleftbuttonDown(object sender, MousebuttonEventArgs e)           {               e.Handled = true;           }           #endregion 鼠标左键事件结束             #region 鼠标右键事件开始            voID Feature_MouseRightbuttonUp(object sender, MousebuttonEventArgs e)           {               Graphic g = sender as Graphic;               RTBContextMenu menu = new RTBContextMenu(rtb, g.Attributes["name"].ToString().Trim());               menu.Show(e.Getposition(LayoutRoot));           }              voID Feature_MouseRightbuttonDown(object sender, MousebuttonEventArgs e)           {               e.Handled = true;           }             #endregion 鼠标右键事件结束               string _toolMode = "";           List<Envelope> _extentHistory = new List<Envelope>();           int _currentExtentIndex = 0;           bool _newExtent = true;              Image _prevIoUsExtentimage;           Image _nextExtentimage;           private Draw MyDrawObject;                    private voID MyToolbar_ToolbarItemClicked(object sender, ESRI.ArcGIS.ClIEnt.Toolkit.SelectedToolbarItemArgs e)           {               MyDrawObject.IsEnabled = false;               _toolMode = "";               switch (e.Index)               {                   case 0: // ZoomIn Layers                        MyDrawObject.IsEnabled = true;                       _toolMode = "zoomin";                       break;                   case 1: // Zoom Out                        MyDrawObject.IsEnabled = true;                       _toolMode = "zoomout";                       break;                   case 2: // Pan                        break;                   case 3: // PrevIoUs Extent                        if (_currentExtentIndex != 0)                       {                           _currentExtentIndex--;                              if (_currentExtentIndex == 0)                           {                               _prevIoUsExtentimage.Opacity = 0.3;                               _prevIoUsExtentimage.IsHitTestVisible = false;                           }                              _newExtent = false;                              myMap.IsHitTestVisible = false;                           myMap.ZoomTo(_extentHistory[_currentExtentIndex]);                              if (_nextExtentimage.IsHitTestVisible == false)                           {                               _nextExtentimage.Opacity = 1;                               _nextExtentimage.IsHitTestVisible = true;                           }                       }                       break;                   case 4: // Next Extent                        if (_currentExtentIndex < _extentHistory.Count - 1)                       {                           _currentExtentIndex++;                              if (_currentExtentIndex == (_extentHistory.Count - 1))                           {                               _nextExtentimage.Opacity = 0.3;                               _nextExtentimage.IsHitTestVisible = false;                           }                              _newExtent = false;                              myMap.IsHitTestVisible = false;                           myMap.ZoomTo(_extentHistory[_currentExtentIndex]);                              if (_prevIoUsExtentimage.IsHitTestVisible == false)                           {                               _prevIoUsExtentimage.Opacity = 1;                               _prevIoUsExtentimage.IsHitTestVisible = true;                           }                       }                       break;                   case 5: // Full Extent                        myMap.ZoomTo(myMap.Layers.GetFullExtent());                       break;                   case 6: // Full Screen                        Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen;                       break;               }           }              private voID myDrawObject_DrawComplete(object sender, DrawEventArgs args)           {               if (_toolMode == "zoomin")               {                   myMap.ZoomTo(args.Geometry as ESRI.ArcGIS.ClIEnt.Geometry.Envelope);               }               else if (_toolMode == "zoomout")               {                   Envelope currentExtent = myMap.Extent;                      Envelope zoomBoxExtent = args.Geometry as Envelope;                   MapPoint zoomBoxCenter = zoomBoxExtent.GetCenter();                      double whRatioCurrent = currentExtent.WIDth / currentExtent.Height;                   double whRatioZoomBox = zoomBoxExtent.WIDth / zoomBoxExtent.Height;                      Envelope newEnv = null;                      if (whRatioZoomBox > whRatioCurrent)                   // use wIDth                    {                       double mapWIDthPixels = myMap.WIDth;                       double multiplIEr = currentExtent.WIDth / zoomBoxExtent.WIDth;                       double newWIDthMapUnits = currentExtent.WIDth * multiplIEr;                       newEnv = new Envelope(new MapPoint(zoomBoxCenter.X - (newWIDthMapUnits / 2), zoomBoxCenter.Y),                                                      new MapPoint(zoomBoxCenter.X + (newWIDthMapUnits / 2), zoomBoxCenter.Y));                   }                   else                   // use height                    {                       double mapHeightPixels = myMap.Height;                       double multiplIEr = currentExtent.Height / zoomBoxExtent.Height;                       double newHeightmapUnits = currentExtent.Height * multiplIEr;                       newEnv = new Envelope(new MapPoint(zoomBoxCenter.X, zoomBoxCenter.Y - (newHeightmapUnits / 2)),                                                      new MapPoint(zoomBoxCenter.X, zoomBoxCenter.Y + (newHeightmapUnits / 2)));                   }                      if (newEnv != null)                       myMap.ZoomTo(newEnv);               }           }              private voID MyMap_ExtentChanged(object sender, ExtentEventArgs e)           {               if (e.oldExtent == null)               {                   _extentHistory.Add(e.NewExtent.Clone());                   return;               }                  if (_newExtent)               {                   _currentExtentIndex++;                      if (_extentHistory.Count - _currentExtentIndex > 0)                       _extentHistory.RemoveRange(_currentExtentIndex, (_extentHistory.Count - _currentExtentIndex));                      if (_nextExtentimage.IsHitTestVisible == true)                   {                       _nextExtentimage.Opacity = 0.3;                       _nextExtentimage.IsHitTestVisible = false;                   }                      _extentHistory.Add(e.NewExtent.Clone());                      if (_prevIoUsExtentimage.IsHitTestVisible == false)                   {                       _prevIoUsExtentimage.Opacity = 1;                       _prevIoUsExtentimage.IsHitTestVisible = true;                   }               }               else               {                   myMap.IsHitTestVisible = true;                   _newExtent = true;               }           }              private voID button1_Click(object sender, RoutedEventArgs e)           {               if (this.textBox1.Text == "")               {                   FindGraphicsAndShowInMap("0");               }               else               {                   FindGraphicsAndShowInMap(this.textBox1.Text.Trim());               }           }          }   }  
using System;using System.Collections.Generic;using System.linq;using System.Net;using System.windows;using System.windows.Controls;using System.windows.documents;using System.windows.input;using System.windows.Media;using System.windows.Media.Animation;using System.windows.Shapes;using ESRI.ArcGIS.ClIEnt.Symbols;using ESRI.ArcGIS.ClIEnt;using ESRI.ArcGIS.ClIEnt.Tasks;using System.windows.Data;using System.Runtime.Serialization;using ESRI.ArcGIS.ClIEnt.Geometry;using MapClIEnt.UserControls;namespace MapClIEnt{    public partial class MainPage : UserControl    {        //一些列变量定义        public string str = null; //用来接收aspx页面传递到xap中的参数字符串        string[] infos = null;        public string level = string.Empty; //市县等级 市=1/县=2        public string areaID = string.Empty; //地区ID,包括市及县的编号        public string color = string.Empty; //颜色值        public string year = string.Empty; //年份        public string cycleID = string.Empty; //生育周期编号        public MainPage(Dictionary<string,string> paramsDic)        {            InitializeComponent();            if (paramsDic.TryGetValue("STR",out str))            {                //获取到aspx页面传递过来的参数            }            //按照|进行拆分成每一个监测点的信息            infos = str.Split('|');            //初始化页面,开始地图加载条            MyDrawObject = new Draw(myMap)            {                FillSymbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.ClIEnt.Symbols.FillSymbol,DrawMode = DrawMode.Rectangle            };            MyDrawObject.DrawComplete += myDrawObject_DrawComplete;        }        private voID UserControl_Loaded(object sender,RoutedEventArgs e)        {            FindGraphicsAndShowInMap("监测点");        }        private voID button_Click(object sender,RoutedEventArgs e)        {            FindGraphicsAndShowInMap("临泉监测点");        }        //#region 市界图层        //public voID FindCityGraphicsAndShowInMap(string conditions)        //{        //    // 初始化查找 *** 作        //    FindTask findCityTask = new FindTask("http://192.168.2.5/arcgis/rest/services/AnHuIDynamic/MapServer/");        //    findCityTask.ExecuteCompleted += new EventHandler<FindEventArgs>(findCityTask_ExecuteCompleted);        //    findCityTask.Failed += new EventHandler<TaskFailedEventArgs>(findCityTask_Failed);        //    //初始化查找参数,指定name字段作为小麦监测点层的搜素条件,并返回特征图层作为查找结果        //    FindParameters findParameters = new FindParameters();        //    findParameters.LayerIDs.AddRange(new int[] { 2 });        //    findParameters.SearchFIElds.AddRange(new string[] { "AreaID","name" });        //    findParameters.ReturnGeometry = true;        //    //要查找点的信息        //    findParameters.SearchText = conditions;        //    findCityTask.ExecuteAsync(findParameters);        //}        ////查找失败        //voID findCityTask_Failed(object sender,TaskFailedEventArgs e)        //{        //    MessageBox.Show("查找失败: " + e.Error);        //}        //voID findCityTask_ExecuteCompleted(object sender,FindEventArgs e)        //{        //    // 清除先前的图层        //    Graphicslayer graphicslayer = myMap.Layers["MyGraphicslayer"] as Graphicslayer;        //    graphicslayer.Cleargraphics();        //    // 检查新的结果        //    if (e.FindResults.Count > 0)        //    {        //        //将查询出来的结果在地图上显示出来        //        foreach (FindResult result in e.FindResults)        //        {        //            result.Feature.Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.ClIEnt.Symbols.Symbol;        //            graphicslayer.Graphics.Add(result.Feature);        //            //左键菜单        //            result.Feature.MouseleftbuttonDown += new MousebuttonEventHandler(Feature_MouseleftbuttonDown);        //            result.Feature.MouseleftbuttonUp += new MousebuttonEventHandler(Feature_MouseleftbuttonUp);        //            //右键菜单        //            result.Feature.MouseRightbuttonDown += new MousebuttonEventHandler(Feature_MouseRightbuttonDown);        //            result.Feature.MouseRightbuttonUp += new MousebuttonEventHandler(Feature_MouseRightbuttonUp);        //        }        //        //坐标自动定位        //        ESRI.ArcGIS.ClIEnt.Geometry.Envelope selectedFeatureExtent = e.FindResults[0].Feature.Geometry.Extent;        //        double expandPercentage = 30;        //        double wIDthExpand = selectedFeatureExtent.WIDth * (expandPercentage / 100);        //        double heightExpand = selectedFeatureExtent.Height * (expandPercentage / 100);        //        ESRI.ArcGIS.ClIEnt.Geometry.Envelope displayExtent = new ESRI.ArcGIS.ClIEnt.Geometry.Envelope(        //        selectedFeatureExtent.XMin - (wIDthExpand / 2),//        selectedFeatureExtent.YMin - (heightExpand / 2),//        selectedFeatureExtent.XMax + (wIDthExpand / 2),//        selectedFeatureExtent.YMax + (heightExpand / 2));        //        myMap.ZoomTo(displayExtent);        //    }        //    else        //    {        //        MessageBox.Show("没有发现匹配该搜索的记录!");        //    }        //}        //#endregion        #region 小麦监测点图层        /// <summary>        /// 根据条件查找监测点图层(0)        /// </summary>        /// <param name="conditions"></param>        public voID FindGraphicsAndShowInMap(string conditions)        {            // 初始化查找 *** 作            FindTask findTask = new FindTask("http://192.168.2.5/arcgis/rest/services/AnHuIDynamic/MapServer/");            findTask.ExecuteCompleted += FindTask_ExecuteCompleted;            findTask.Failed += FindTask_Failed;            //初始化查找参数,指定name字段作为小麦监测点层的搜素条件,并返回特征图层作为查找结果            FindParameters findParameters = new FindParameters();            findParameters.LayerIDs.AddRange(new int[] { 0 });            findParameters.SearchFIElds.AddRange(new string[] { "ID","name" });            findParameters.ReturnGeometry = true;            //要查找点的信息            findParameters.SearchText = conditions;            findTask.ExecuteAsync(findParameters);        }        #region FindTask 查找任务开始        // 查找结束时,开始绘制点到图层上        private voID FindTask_ExecuteCompleted(object sender,FindEventArgs args)        {            // 清除先前的图层            Graphicslayer graphicslayer = myMap.Layers["MyGraphicslayer"] as Graphicslayer;            graphicslayer.Cleargraphics();            // 检查新的结果            if (args.FindResults.Count > 0)            {                //将查询出来的结果在地图上显示出来                foreach (FindResult result in args.FindResults)                {                    //赋值颜色值                    this.dms_Point.color = new SolIDcolorBrush(colors.Red);                    result.Feature.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.ClIEnt.Symbols.Symbol;                    graphicslayer.Graphics.Add(result.Feature);                    //左键菜单                    result.Feature.MouseleftbuttonDown += new MousebuttonEventHandler(Feature_MouseleftbuttonDown);                    result.Feature.MouseleftbuttonUp += new MousebuttonEventHandler(Feature_MouseleftbuttonUp);                    //右键菜单                    result.Feature.MouseRightbuttonDown += new MousebuttonEventHandler(Feature_MouseRightbuttonDown);                    result.Feature.MouseRightbuttonUp += new MousebuttonEventHandler(Feature_MouseRightbuttonUp);                }                //坐标自动定位                ESRI.ArcGIS.ClIEnt.Geometry.Envelope selectedFeatureExtent = args.FindResults[0].Feature.Geometry.Extent;                double expandPercentage = 30;                double wIDthExpand = selectedFeatureExtent.WIDth * (expandPercentage / 100);                double heightExpand = selectedFeatureExtent.Height * (expandPercentage / 100);                ESRI.ArcGIS.ClIEnt.Geometry.Envelope displayExtent = new ESRI.ArcGIS.ClIEnt.Geometry.Envelope(                selectedFeatureExtent.XMin - (wIDthExpand / 2),selectedFeatureExtent.YMin - (heightExpand / 2),selectedFeatureExtent.XMax + (wIDthExpand / 2),selectedFeatureExtent.YMax + (heightExpand / 2));                myMap.ZoomTo(displayExtent);            }            else            {                MessageBox.Show("没有发现匹配该搜索的记录!");            }        }        //当查找失败时进行提示 *** 作        private voID FindTask_Failed(object sender,TaskFailedEventArgs args)        {            MessageBox.Show("查找失败: " + args.Error);        }        #endregion FindTask 查找任务结束        #endregion        RichTextBox rtb;        #region 鼠标左键事件开始        voID Feature_MouseleftbuttonUp(object sender,MousebuttonEventArgs e)        {            //鼠标左键,显示tooltip信息            Graphic g = sender as Graphic;            //这里需要添加一个不消失的d出框,并可以移入进行点击            MapTips tips = new MapTips(rtb,g.Attributes["name"].ToString().Trim(),g.Attributes["AreaID"].ToString().Trim(),"-1","-1");            tips.Show(e.Getposition(LayoutRoot));        }        voID Feature_MouseleftbuttonDown(object sender,MousebuttonEventArgs e)        {            e.Handled = true;        }        #endregion 鼠标左键事件结束        #region 鼠标右键事件开始        voID Feature_MouseRightbuttonUp(object sender,MousebuttonEventArgs e)        {            Graphic g = sender as Graphic;            RTBContextMenu menu = new RTBContextMenu(rtb,g.Attributes["name"].ToString().Trim());            menu.Show(e.Getposition(LayoutRoot));        }        voID Feature_MouseRightbuttonDown(object sender,MousebuttonEventArgs e)        {            e.Handled = true;        }        #endregion 鼠标右键事件结束        string _toolMode = "";        List<Envelope> _extentHistory = new List<Envelope>();        int _currentExtentIndex = 0;        bool _newExtent = true;        Image _prevIoUsExtentimage;        Image _nextExtentimage;        private Draw MyDrawObject;        private voID MyToolbar_ToolbarItemClicked(object sender,ESRI.ArcGIS.ClIEnt.Toolkit.SelectedToolbarItemArgs e)        {            MyDrawObject.IsEnabled = false;            _toolMode = "";            switch (e.Index)            {                case 0: // ZoomIn Layers                    MyDrawObject.IsEnabled = true;                    _toolMode = "zoomin";                    break;                case 1: // Zoom Out                    MyDrawObject.IsEnabled = true;                    _toolMode = "zoomout";                    break;                case 2: // Pan                    break;                case 3: // PrevIoUs Extent                    if (_currentExtentIndex != 0)                    {                        _currentExtentIndex--;                        if (_currentExtentIndex == 0)                        {                            _prevIoUsExtentimage.Opacity = 0.3;                            _prevIoUsExtentimage.IsHitTestVisible = false;                        }                        _newExtent = false;                        myMap.IsHitTestVisible = false;                        myMap.ZoomTo(_extentHistory[_currentExtentIndex]);                        if (_nextExtentimage.IsHitTestVisible == false)                        {                            _nextExtentimage.Opacity = 1;                            _nextExtentimage.IsHitTestVisible = true;                        }                    }                    break;                case 4: // Next Extent                    if (_currentExtentIndex < _extentHistory.Count - 1)                    {                        _currentExtentIndex++;                        if (_currentExtentIndex == (_extentHistory.Count - 1))                        {                            _nextExtentimage.Opacity = 0.3;                            _nextExtentimage.IsHitTestVisible = false;                        }                        _newExtent = false;                        myMap.IsHitTestVisible = false;                        myMap.ZoomTo(_extentHistory[_currentExtentIndex]);                        if (_prevIoUsExtentimage.IsHitTestVisible == false)                        {                            _prevIoUsExtentimage.Opacity = 1;                            _prevIoUsExtentimage.IsHitTestVisible = true;                        }                    }                    break;                case 5: // Full Extent                    myMap.ZoomTo(myMap.Layers.GetFullExtent());                    break;                case 6: // Full Screen                    Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen;                    break;            }        }        private voID myDrawObject_DrawComplete(object sender,DrawEventArgs args)        {            if (_toolMode == "zoomin")            {                myMap.ZoomTo(args.Geometry as ESRI.ArcGIS.ClIEnt.Geometry.Envelope);            }            else if (_toolMode == "zoomout")            {                Envelope currentExtent = myMap.Extent;                Envelope zoomBoxExtent = args.Geometry as Envelope;                MapPoint zoomBoxCenter = zoomBoxExtent.GetCenter();                double whRatioCurrent = currentExtent.WIDth / currentExtent.Height;                double whRatioZoomBox = zoomBoxExtent.WIDth / zoomBoxExtent.Height;                Envelope newEnv = null;                if (whRatioZoomBox > whRatioCurrent)                // use wIDth                {                    double mapWIDthPixels = myMap.WIDth;                    double multiplIEr = currentExtent.WIDth / zoomBoxExtent.WIDth;                    double newWIDthMapUnits = currentExtent.WIDth * multiplIEr;                    newEnv = new Envelope(new MapPoint(zoomBoxCenter.X - (newWIDthMapUnits / 2),zoomBoxCenter.Y),new MapPoint(zoomBoxCenter.X + (newWIDthMapUnits / 2),zoomBoxCenter.Y));                }                else                // use height                {                    double mapHeightPixels = myMap.Height;                    double multiplIEr = currentExtent.Height / zoomBoxExtent.Height;                    double newHeightmapUnits = currentExtent.Height * multiplIEr;                    newEnv = new Envelope(new MapPoint(zoomBoxCenter.X,zoomBoxCenter.Y - (newHeightmapUnits / 2)),new MapPoint(zoomBoxCenter.X,zoomBoxCenter.Y + (newHeightmapUnits / 2)));                }                if (newEnv != null)                    myMap.ZoomTo(newEnv);            }        }        private voID MyMap_ExtentChanged(object sender,ExtentEventArgs e)        {            if (e.oldExtent == null)            {                _extentHistory.Add(e.NewExtent.Clone());                return;            }            if (_newExtent)            {                _currentExtentIndex++;                if (_extentHistory.Count - _currentExtentIndex > 0)                    _extentHistory.RemoveRange(_currentExtentIndex,(_extentHistory.Count - _currentExtentIndex));                if (_nextExtentimage.IsHitTestVisible == true)                {                    _nextExtentimage.Opacity = 0.3;                    _nextExtentimage.IsHitTestVisible = false;                }                _extentHistory.Add(e.NewExtent.Clone());                if (_prevIoUsExtentimage.IsHitTestVisible == false)                {                    _prevIoUsExtentimage.Opacity = 1;                    _prevIoUsExtentimage.IsHitTestVisible = true;                }            }            else            {                myMap.IsHitTestVisible = true;                _newExtent = true;            }        }        private voID button1_Click(object sender,RoutedEventArgs e)        {            if (this.textBox1.Text == "")            {                FindGraphicsAndShowInMap("0");            }            else            {                FindGraphicsAndShowInMap(this.textBox1.Text.Trim());            }        }    }}

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


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

分享到:

总结

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

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1018149.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存