当前位置:主页   - 电脑 - 网站开发 - ASP.Net
学习ArcEngine(5)全图
来源:网络   作者:liuyh208   更新时间:2011-10-12
收藏此页】    【字号    】    【打印】    【关闭

  和zoomout、zoomin等工具不同,全图工具不用和地图交互,属于命令类工具,只要实现ICommand接口即可。参考zoomout的实现,首先新建一个基类CommandBase,实现Icommand接口,然后新建FullExtent类,继承这个基类,重写一下OnClick方法,即可。

  1: public class CommandBase:BaseCommand,IDisposable
  2:   {
  3:     protected IHookHelper m_pHookHelper;
  4:  
  5:     protected object m_pControl;
  6:     protected IActiveView m_pActiveView;
  7:     protected IMap m_pMap;
  8:   
  9:      /// <summary>
 10:      /// 
 11:      /// </summary>
 12:      /// <param name="str">工具的名称</param>
 13:     public CommandBase(string str):base()
 14:     {
 15:       m_pHookHelper=new HookHelperClass();
 16:       InitialToolRes(str);
 17:     }
 18:     /// <summary>
 19:     /// 
 20:     /// </summary>
 21:     /// <param name="mapCtl">工具关联的地图控件</param>
 22:     /// <param name="str"></param>
 23:     public CommandBase(AxMapControl mapCtl, string str)
 24:       :this(str)
 25:     {
 26:       OnCreate(mapCtl.Object);
 27:     }
 28:  
 29:     /// <summary>
 30:     /// 
 31:     /// </summary>
 32:     /// <param name="plCtl">工具关联的地图控件</param>
 33:     /// <param name="str"></param>
 34:     public CommandBase(AxPageLayoutControl plCtl, string str)
 35:       : this(str)
 36:     {
 37:       OnCreate(plCtl.Object);
 38:     }
 39:  
 40:  
 41:     public override void OnCreate(object hook)
 42:     {
 43:       m_pHookHelper.Hook=hook;
 44:  
 45:       if (hook is Control)
 46:       {
 47:         m_pControl = hook;
 48:         if (hook is AxMapControl)
 49:         {
 50:           AxMapControl mapcontrl = hook as AxMapControl;
 51:           m_pHookHelper.Hook = mapcontrl.Object;
 52:         }
 53:         else if (hook is AxPageLayoutControl)
 54:         {
 55:           AxPageLayoutControl pagepcontrl = hook as AxPageLayoutControl;
 56:           m_pHookHelper.Hook = pagepcontrl.Object;
 57:         }
 58:       }
 59:       else
 60:       {
 61:         if (hook is IMapControlDefault)
 62:         {
 63:           IMapControlDefault pMapDefault = hook as IMapControlDefault;
 64:           m_pControl = Control.FromChildHandle(new IntPtr(pMapDefault.hWnd));
 65:           m_pHookHelper.Hook = pMapDefault;
 66:         }
 67:         else if (hook is IPageLayoutControlDefault)
 68:         {
 69:           IPageLayoutControlDefault pPageDefault = hook as IPageLayoutControlDefault;
 70:           m_pControl = Control.FromChildHandle(new IntPtr(pPageDefault.hWnd));
 71:           m_pHookHelper.Hook = pPageDefault;
 72:         }
 73:       }
 74:  
 75:       m_pActiveView = m_pHookHelper.ActiveView;
 76:       m_pMap = m_pHookHelper.FocusMap;
 77:     }
 78:  
 79:  
 80:     //初始化该功能的GUI资源
 81:     private void InitialToolRes(string str)
 82:     {
 83:    s ResourceManager pResourceManager = Resources.ResourceManager;
 84:       pResourceManager.IgnoreCase=true;
 85:       base.m_bitmap=(Bitmap)pResourceManager.GetObject("bmp"+str);
 86:       base.m_name = (string)pResourceManager.GetObject("na" + str);
 87:       base.m_caption = (string)pResourceManager.GetObject("cpt" + str);
 88:       if (m_caption == string.Empty) m_caption = m_name;
 89:  
 90:       base.m_category=(string)pResourceManager.GetObject("ctg"+str);
 91:  
 92:       base.m_message=(string)pResourceManager.GetObject("msg"+str);
 93:       if (m_message == string.Empty) m_message = m_name;
 94:       
 95:       base.m_toolTip=(string)pResourceManager.GetObject("tlt"+str);
 96:       if (m_toolTip == string.Empty) m_toolTip = m_name;
 97:  
 98:       pResourceManager.ReleaseAllResources();
 99:     }
 100:  
 101:  
 102:  
 103:     #region IDisposable 成员
 104:  
 105:     public void Dispose()
 106:     {
 107:       m_pHookHelper = null;
 108:       m_bitmap = null;
 109:       Marshal.ReleaseComObject(m_pHookHelper);
 110:     }
 111:  
 112:     #endregion
 113:   }

编缉推荐阅读以下文章

  • 学习ArcEngine(4)平移
  • 学习ArcEngine(3)缩小
  • 学习ArcEngine(2)-重构
  • 学习ArcEngine(1)-放大工具
其它资源
来源声明

版权与免责声明
1、本站所发布的文章仅供技术交流参考,本站不主张将其做为决策的依据,浏览者可自愿选择采信与否,本站不对因采信这些信息所产生的任何问题负责。
2、本站部分文章来源于网络,其版权为原权利人所有。由于来源之故,有的文章未能获得作者姓名,署“未知”或“佚名”。对于这些文章,有知悉作者姓名的请告知本站,以便及时署名。如果作者要求删除,我们将予以删除。除此之外本站不再承担其它责任。
3、本站部分文章来源于本站原创,本站拥有所有权利。
4、如对本站发布的信息有异议,请联系我们,经本站确认后,将在三个工作日内做出修改或删除处理。
请参阅权责声明