码迷,mamicode.com
首页 > 其他好文 > 详细

map与pagelayout同步新方法

时间:2015-07-25 16:50:59      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

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

map与pagelayout同步新方法

标签:

原文地址:http://www.cnblogs.com/gisoracle/p/4676109.html

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