zoukankan      html  css  js  c++  java
  • map与pagelayout同步新方法

    本文转自: http://hi.baidu.com/murphy1314/blog/item/3d3144f319b19dcf0a46e0a4.html

    前天写的那个MapControl和Pagelayout同步用IMaps接口来实现,今天我却又发现了一种更简便的方法,竟然可以不用到IMaps,省下好多功夫。(回想下例子竟然是一种误导...)

           因为MapDocument就包含了map和pagelayout这两者,所以当用IMapDocument去打开的时候,可以直接把类包含的map和pagelayout传递给这两个控件,因为pagelayout是共享map的,所以自然达到了'同步'的效果。两行代码就够了:
              1:axPageLayoutControl1.PageLayout = mapDoc.PageLayout;
              2:axMapControl1.Map = mapDoc.get_Map(0);

           不过这样会存在一个刷新的问题,因为操作完1时,activeview是在pagelayout视图;所以我们要在加载的map(第2行)切换activeview到map视图。完整代码如下:
                    axPageLayoutControl1.PageLayout = mapDoc.PageLayout;
                    axPageLayoutControl1.ActiveView.Deactivate(); //取消layout的activeview
                    IActiveView pact = (IActiveView)axMapControl1.ActiveView; //激活map
                    axMapControl1.Map = mapDoc.get_Map(0);
                    axMapControl1.Refresh();

           关于为什么要这样做,可以查看原文(MapDocumentClass Class):
    When opening or creating a map document with the IMapDocument Open() or New() methods, you should always make subsequent calls to IActiveView::Activate() in order to properly initialize the display of the PageLayout and Map objects. Call Activate() once for the PageLayout and once for each Map you will be working with. If your application has a user interface, you should call Activate() with the hWnd of the application's client area.

           同步加载的问题解决了,但是同步保存的问题却依然没有解决,这个我纳闷。因为用按上面的道理:
                       pMapDocument.ReplaceContents((IMxdContents)axMapControl1.Map);
                       pMapDocument.ReplaceContents((IMxdContents)axPageLayoutControl1.PageLayout);
                       pMapDocument.Save(pMapDocument.UsesRelativePaths,true);
    这几个语句是应该可以同时保存的,但结果却是只保存了pagelayout,这有点让我想不通,希望有高手能解决这个问题。

  • 相关阅读:
    Oracle Index 索引监控
    Oracle Job
    Oracle 数据类型
    Greenplum 的发展历史
    Mongodb账户管理
    MongoDB 备份与恢复
    MySQL 查看用户授予的权限
    Linux 不同方法查看进程消耗CPU IO 等
    Oracle 体系结构图
    Oracle 后台进程(六)PMON进程
  • 原文地址:https://www.cnblogs.com/gisoracle/p/4676109.html
Copyright © 2011-2022 走看看