首页 技术 正文
技术 2022年11月15日
0 收藏 437 点赞 4,675 浏览 1574 个字

本文转自: 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,这有点让我想不通,希望有高手能解决这个问题。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,557
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898