ArcGIS API for Silverlight 点击地图d出自定义窗体

ArcGIS API for Silverlight 点击地图d出自定义窗体,第1张

概述在之前的博客中,关于d出窗体,样式比较单一,不能满足自定义各种样式,源连接地址:http://blog.csdn.net/taomanman/article/details/7333612   下面是通过新建一个Silverlight的UserControl类,里面自定义样式,只要你能想到的,都可以做出来,然后在地图中点击点,实例化该类即可,主要代码如下: using System; using  在之前的博客中,关于d出窗体,样式比较单一,不能满足自定义各种样式,源连接地址:http://blog.csdn.net/taomanman/article/details/7333612

  下面是通过新建一个Silverlight的UserControl类,里面自定义样式,只要你能想到的,都可以做出来,然后在地图中点击点,实例化该类即可,主要代码如下:

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 MapClIEnt.ServiceReference1;
using System.windows.browser;
using System.windows.Controls.Primitives;
using ESRI.ArcGIS.ClIEnt;

namespace MapClIEnt
{
    public partial class MapTip : UserControl
    {
        string _placename = string.Empty; //监测点名称
        string _areaID = string.Empty; //地区编号
        string _monitorID = string.Empty; //监测点ID
        string _year = string.Empty; //年份
        string _issueNum = string.Empty; //期号
        string _cycleID = string.Empty; //生育周期ID
        string _seedingTypeID = string.Empty; //苗情等级ID

        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;
            }
        }

        //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,用来监测菜单项外面的鼠标点击事件
        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 = this;
            _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;
            }
        }

        public MapTip(string name, string areaID, string monitorID, string year, string cycleID, string issueNum, string seedingTypeID)
        {
            InitializeComponent();
            this._placename = name;
            this._areaID = areaID;
            this._monitorID = monitorID;
            this._issueNum = issueNum;
            this._year = year;
            this._cycleID = cycleID;
            this._seedingTypeID = seedingTypeID;
        }

        private voID UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            getData1SoapClIEnt clIEnt = new getData1SoapClIEnt();
            clIEnt.GetMonitorInfoByIssueNumCompleted += new EventHandler<GetMonitorInfoByIssueNumCompletedEventArgs>(clIEnt_GetMonitorInfoByIssueNumCompleted);
            clIEnt.GetMonitorInfoByIssueNumAsync(_areaID, _monitorID, _year, _issueNum, _cycleID);
        }

        voID clIEnt_GetMonitorInfoByIssueNumCompleted(object sender, GetMonitorInfoByIssueNumCompletedEventArgs e)
        {
            try
            {
                string result = e.Result;
                if (result.Split('|').Length == 1)
                {
                    this.tb_Title.Text = _placename;
                    this.tb_zjyl.Text = result.Split('|')[0].ToString();
                    this.tb_zjyl.Foreground = new SolIDcolorBrush(colors.Red);
                    this.tb_zjyl.HorizontalAlignment = HorizontalAlignment.Center;
                }
                else
                {
                    this.tb_Title.Text = result.Split('|')[0].ToString(); //标题
                    this.tb_grade.Text = result.Split('|')[1].ToString(); //所属类型
                    this.tb_area.Text = result.Split('|')[2].ToString(); //代表面积
                    this.tb_varIEty.Text = result.Split('|')[3].ToString(); //品种
                    this.tb_varIEtyType.Text = result.Split('|')[4].ToString(); //品种类型
                    switch (_cycleID)
                    {
                        case "5":
                            //越冬期
                            this.tb_zjyl.Text = result.Split('|')[5].ToString(); //主茎叶龄
                            this.tb_dzjn.Text = result.Split('|')[6].ToString(); //单株茎蘖
                            this.tb_csg.Text = result.Split('|')[7].ToString(); //次生根
                            this.tb_mjn.Text = result.Split('|')[8].ToString(); //亩茎蘖
                            break;
                        case "6":
                            //返青期
                            this.tb_zjyl.Text = result.Split('|')[5].ToString(); //主茎叶龄
                            this.tb_dzjn.Text = result.Split('|')[6].ToString(); //单株茎蘖
                            this.tb_csg.Text = result.Split('|')[7].ToString(); //次生根
                            this.tb_mjn.Text = result.Split('|')[8].ToString(); //亩茎蘖
                            break;
                        case "8":
                            //拔节期
                            this.tb_zjyl.Text = result.Split('|')[5].ToString(); //主茎叶龄
                            this.tb_dzjn.Text = result.Split('|')[6].ToString(); //单株茎蘖
                            this.tb_csg.Text = result.Split('|')[7].ToString(); //亩茎蘖
                            break;
                        case "10":
                            //抽穗期
                            this.tb_zjyl.Text = result.Split('|')[5].ToString(); //主茎叶龄
                            this.tb_dzjn.Text = result.Split('|')[6].ToString(); //亩茎蘖
                            break;
                    }
                    //苗情评价分析
                    btn1.Content = result.Split('|')[0].ToString().Split(')')[0] + ")苗情评价信息";
                    //苗情数据报表
                    btn2.Content = result.Split('|')[0].ToString().Split(')')[0] + ")小麦苗情数据报表";
                    //苗情监测报告
                    btn3.Content = result.Split('|')[0].ToString().Split(')')[0] + ")苗情监测报告";
                }
            }
            catch (Exception)
            {
                this.tb_Title.Text = _placename;
                this.tb_zjyl.Text = "暂无数据!";
                this.tb_zjyl.Foreground = new SolIDcolorBrush(colors.Red);
                this.tb_zjyl.HorizontalAlignment = HorizontalAlignment.Center;
            }
        }

        voID btn1_Click(object sender, RoutedEventArgs e)
        {
            //页面跳转后并关闭当前d出窗体
            try
            {
                ScriptObject SetMaterial = HTMLPage.Window.GetProperty("GotoHomeMenuname"as ScriptObject;
                string firstMenuname = "农情分析";
                string secondMenuname = "苗情评价";
                string menuname = "GIS地图监测点小麦苗情评价";
                string str = "?pAreaType=&pCounty=" + _areaID + "&pYear=" + _year + "&pPeriod=" + _issueNum + "&pStageID=" + _cycleID + "&pSeedlingType=" + 
_seedingTypeID + "&pMonitorID=" + _monitorID;
                SetMaterial.InvokeSelf(firstMenuname, secondMenuname, menuname, str);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            Close();
        }

        voID btn2_Click(object sender, RoutedEventArgs e)
        {
            //页面跳转后并关闭当前d出窗体
            ScriptObject SetMaterial = HTMLPage.Window.GetProperty("GotoHomeUrlStr"as ScriptObject;
            string firstMenuname = "农情分析";
            string secondMenuname = "苗情分布统计分析";
            string thirdMenuname = "苗情分布统计";
            string str = "?Areaname=" + _placename;
            SetMaterial.InvokeSelf(firstMenuname, thirdMenuname, str);
            Close();
        }

        voID btn3_Click(object sender, RoutedEventArgs e)
        {
            //页面跳转后并关闭当前d出窗体
            ScriptObject SetMaterial = HTMLPage.Window.GetProperty("GotoHomeUrlStr"as ScriptObject;
            string firstMenuname = "农情管理";
            string secondMenuname = "信息录入";
            string thirdMenuname = "小麦苗情监测报告";
            string str = "?Areaname=" + _placename;
            SetMaterial.InvokeSelf(firstMenuname, str);
            Close();
        }
  private voID tb_zjhy_MouseleftbuttonDown(object sender, System.windows.input.MousebuttonEventArgs e)
        {
            //专家会议
            ScriptObject SetMaterial = HTMLPage.Window.GetProperty("GotoHomeUrlStr"as ScriptObject;
            string firstMenuname = "农情监控";
            string secondMenuname = "农情监控";
            string thirdMenuname = "农田监控";
            string str = "?Areaname=" + _placename;
            SetMaterial.InvokeSelf(firstMenuname, str);
            Close();
        }

        private voID tb_xcld_MouseleftbuttonDown(object sender, System.windows.input.MousebuttonEventArgs e)
        {
            //现场联动
            ScriptObject SetMaterial = HTMLPage.Window.GetProperty("GotoHomeUrlStr"as ScriptObject;
            string firstMenuname = "农情监控";
            string secondMenuname = "农情监控";
            string thirdMenuname = "农田图像监控";
            string str = "?Areaname=" + _placename;
            SetMaterial.InvokeSelf(firstMenuname, str);
            Close();
        }

        private voID tb_tJsp_MouseleftbuttonDown(object sender, System.windows.input.MousebuttonEventArgs e)
        {
          // 田间视频
      ScriptObject SetMaterial = HTMLPage.Window.GetProperty("GotoHomeUrlStr"as ScriptObject;
            string firstMenuname = "农情监控";
            string secondMenuname = "农情监控";
            string thirdMenuname = "农田图像监控";
            string str = "?Areaname=" + _placename;
            SetMaterial.InvokeSelf(firstMenuname, str);
            Close();
        }

        private voID tb_zwtp_MouseleftbuttonDown(object sender, System.windows.input.MousebuttonEventArgs e)
        {
          // 作物图片
      ScriptObject SetMaterial = HTMLPage.Window.GetProperty("GotoHomeUrlStr"as ScriptObject;
            string firstMenuname = "农情监控";
            string secondMenuname = "农情监控";
            string thirdMenuname = "农田图像监控";
            string str = "?Areaname=" + _placename;
            SetMaterial.InvokeSelf(firstMenuname, str);
            Close();
        }

    }
}

         #region 鼠标左键事件开始
         voID Feature_MouseleftbuttonUp( object sender, MousebuttonEventArgs e)
        {
             //鼠标左键,显示tooltip信息
            Graphic g = sender  as Graphic;
             for ( int i = 0; i < areaID.Length; i++)
            {
                 if (areaID[i] == g.Attributes[ "ID"].ToString())
                {
                     //d出对应的提示信息
                    MapTip tip =  new MapTip(g.Attributes[ "name"].ToString(), g.Attributes[ "AreaID"].ToString(), areaID[i], year[i], cycleID[i], issueNum[i], seedlingType[i]);
                    Point p = e.Getposition(LayoutRoot);
                    p.X = p.X - 220;
                    p.Y = p.Y + 80;
                    tip.Show(p);
                }
            }
        }

  效果如下图所示:

  

  本文来自taomanman的博客,原文地址:http://blog.csdn.net/taomanman/article/details/7469594

总结

以上是内存溢出为你收集整理的ArcGIS API for Silverlight 点击地图d出自定义窗体全部内容,希望文章能够帮你解决ArcGIS API for Silverlight 点击地图d出自定义窗体所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存