码迷,mamicode.com
首页 > Web开发 > 详细

PIE SDK 基于Dot net bar实现比例尺控件

时间:2019-08-27 12:29:01      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:利用   car   send   help   hid   nta   form   tran   更新   

最近在搭建主界面的过程中,为了界面美观大方,使用了Dot net bar。但是,在Dot net bar的状态栏中放置PIE SDK自带的比例尺控件,运行主界面程序后,比例尺控件始终不显示比例尺信息,得不到想要的效果。如果使用Windows Form自带的状态栏,则能够正常显示比例尺信息。我猜想,可能是PIE SDK自带的比例尺控件与Dot net bar不兼容。我参考了官方博客(https://www.cnblogs.com/PIESat/p/10272779.html),利用Dot net bar拓展实现了比例尺控件。

基于Dot net bar,利用PIE SDK自带的比例尺控件(代码如下),运行程序后的显示效果如下图(不能正常显示比例尺信息):

技术图片
 1  public FormMain()
 2         {
 3             InitializeComponent();
 4             mapControlMain.OnExtentUpdated += mapControlMain_OnExtentUpdated;//鹰眼图          
 5             ///比例尺控件
 6             //Common.MapScaleCommandControl mapScaleControl = new Common.MapScaleCommandControl();
 7             //mapScaleControl.Control = comboBoxItem_MapScale;
 8             //mapScaleControl.OnCreate(mapControlMain);
 9             MapScaleCommandControl mapScale = new MapScaleCommandControl();
10             mapScale.Control = comboBoxItem_MapScale;
11             mapScale.OnCreate(mapControlMain);
12             //进度条//首先隐藏需要时显现
13             this.progressBarItem.Visible = false;
14             Control.CheckForIllegalCrossThreadCalls = false;
15         }
View Code

技术图片

利用基于Dot net bar拓展实现的比例尺控件(代码如下),运行程序后显示的效果如下图(可正常显示比例尺信息):

技术图片
 1 public FormMain()
 2         {
 3             InitializeComponent();
 4             mapControlMain.OnExtentUpdated += mapControlMain_OnExtentUpdated;//鹰眼图          
 5             ///比例尺控件
 6             Common.MapScaleCommandControl mapScaleControl = new Common.MapScaleCommandControl();
 7             mapScaleControl.Control = comboBoxItem_MapScale;
 8             mapScaleControl.OnCreate(mapControlMain);
 9             //MapScaleCommandControl mapScale = new MapScaleCommandControl();
10             //mapScale.Control = comboBoxItem_MapScale;
11             //mapScale.OnCreate(mapControlMain);
12             //进度条//首先隐藏需要时显现
13             this.progressBarItem.Visible = false;
14             Control.CheckForIllegalCrossThreadCalls = false;
15         }
View Code

技术图片

利用Dot net bar拓展实现的比例尺控件代码如下:

技术图片
  1 /// <summary>
  2     /// 比例尺控件
  3     /// </summary>
  4     #region
  5     class MapScaleCommandControl : PIE.Controls.BaseCommandControl
  6     {
  7         #region 成员变量
  8         /// <summary>
  9         /// ToolStripComboBox
 10         /// </summary>
 11         private DevComponents.DotNetBar.ComboBoxItem m_DotNetBarComboxItem = null;
 12         #endregion
 13 
 14         /// <summary>
 15         /// 构造函数
 16         /// </summary>
 17         public MapScaleCommandControl()
 18         {
 19             this.Caption = "";
 20             this.Name = "";
 21             this.Checked = false;
 22             this.Enabled = false;
 23         }
 24         /// <summary>
 25         /// Control
 26         /// </summary>
 27         public override object Control
 28         {
 29             get
 30             {
 31                 return m_DotNetBarComboxItem;
 32             }
 33             set
 34             {
 35                 m_DotNetBarComboxItem = value as DevComponents.DotNetBar.ComboBoxItem;
 36             }
 37         }
 38         /// <summary>
 39         /// 是否可用
 40         /// </summary>
 41         public override bool Enabled
 42         {
 43             get
 44             {
 45                 if (m_Hook == null || m_HookHelper.ActiveView.FocusMap.LayerCount < 1) return false;
 46                 return true;
 47             }
 48             protected set
 49             {
 50                 base.Enabled = value;
 51             }
 52         }
 53         /// <summary>
 54         /// 创建插件对象
 55         /// </summary>
 56         /// <param name="hook"></param>
 57         public override void OnCreate(object hook)
 58         {
 59             if (hook == null) return;
 60             if (!(hook is PIE.Carto.IPmdContents)) return;
 61             this.Enabled = true;
 62             m_Hook = hook;
 63             m_HookHelper.Hook = hook;
 64 
 65             if (m_DotNetBarComboxItem == null) return;
 66             DevComponents.DotNetBar.ComboBoxItem comboxItem = this.m_DotNetBarComboxItem as DevComponents.DotNetBar.ComboBoxItem;
 67             if (comboxItem == null) return;
 68 
 69             comboxItem.Items.Add("1:500");
 70             comboxItem.Items.Add("1:1000");
 71             comboxItem.Items.Add("1:5000");
 72             comboxItem.Items.Add("1:10000");
 73             comboxItem.Items.Add("1:50000");
 74             comboxItem.Items.Add("1:100000");
 75             comboxItem.Items.Add("1:500000");
 76             comboxItem.Items.Add("1:1000000");
 77             //comboxItem.KeyPress += comboxItem_KeyPress;
 78             comboxItem.SelectedIndexChanged += comboxItem_SelectedIndexChanged;
 79             (hook as PIE.AxControls.MapControl).OnExtentUpdated += MapScaleCommandControl_OnExtentUpdated;    
 80         }
 81         void comboxItem_SelectedIndexChanged(object sender, EventArgs e)
 82         {
 83             //获取选中的比例尺
 84             string strScale = m_DotNetBarComboxItem.Text.ToString();
 85             int count = strScale.Length;
 86             if (count < 3) return;
 87             string str = strScale.Substring(2, count - 2);
 88             double scale = Convert.ToDouble(str);
 89             if (scale < 1) return;
 90 
 91             //改变地图的比例尺并更新
 92             m_HookHelper.ActiveView.DisplayTransformation.MapScale = scale;
 93             m_HookHelper.ActiveView.PartialRefresh(PIE.Carto.ViewDrawPhaseType.ViewAll);
 94         }
 95         private void MapScaleCommandControl_OnExtentUpdated(object sender, bool sizeChanged, PIE.Geometry.IEnvelope newEnvelope)
 96         {
 97             string strScale = m_HookHelper.ActiveView.DisplayTransformation.MapScale.ToString();
 98             double scale = Convert.ToDouble(strScale);
 99             strScale = "1:" + scale.ToString("0");
100             m_DotNetBarComboxItem.ComboBoxEx.Text = strScale;
101             this.m_DotNetBarComboxItem.Text = strScale;
102         }   
103         /// <summary>
104         /// 比例尺文本变化事件
105         /// </summary>
106         /// <param name="sender"></param>
107         /// <param name="e"></param>
108         void comboxItem_TextChanged(object sender, EventArgs e)
109         {
110             //获取选中的比例尺
111             string strScale = m_DotNetBarComboxItem.Text.ToString();
112             int count = strScale.Length;
113             if (count < 3) return;
114             string str = strScale.Substring(2, count - 2);
115             double scale = Convert.ToDouble(str);
116             if (scale < 1) return;
117 
118             //改变地图的比例尺并更新
119             m_HookHelper.ActiveView.DisplayTransformation.MapScale = scale;
120             m_HookHelper.ActiveView.PartialRefresh(PIE.Carto.ViewDrawPhaseType.ViewAll);
121         }
122         /// <summary>
123         /// 点击事件
124         /// </summary>
125         public override void OnClick()
126         {
127             base.OnClick();
128         }
129     }
130 #endregion
View Code

有不对的地方,请大家批评指正。

PIE SDK 基于Dot net bar实现比例尺控件

标签:利用   car   send   help   hid   nta   form   tran   更新   

原文地址:https://www.cnblogs.com/LW-MA/p/11417552.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!