liutingxiang的个人博客分享 http://blog.sciencenet.cn/u/liutingxiang

博文

ArcGIS Engine二次开发学习(10)PageLayoutControl

已有 6154 次阅读 2018-4-30 23:09 |个人分类:地理信息系统二次开发|系统分类:教学心得

 1、设置axPageLayoutControl1的可用工具。

在toolbar控件中添加一些axPageLayoutControl1中可用的工具,如pan、选择element等。

在之前的tabControl1_SelectedIndexChanged事件中,对选择了MapControl还是PageLayoutControl进行了判断。现在添加一句话,如果选了PageLayoutControl,则

axToolbarControl1.SetBuddyControl(axPageLayoutControl1);


2、设置菜单,添加图例、添加比例尺、添加指北针等。


以指北针为例:

定义方法:

public void AddNorthArrow(ESRI.ArcGIS.Carto.IPageLayout pageLayout, ESRI.ArcGIS.Carto.IMap map)
        {

            if (pageLayout == null || map == null)
            {
                return;
            }
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(0.2, 0.2, 5, 5); //  Specify the location and size of the north arrow

            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.MarkerNorthArrow";

            // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
            // Activate it and add it to the PageLayout's graphics container
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer; // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView activeView = pageLayout as ESRI.ArcGIS.Carto.IActiveView; // Dynamic Cast
            ESRI.ArcGIS.Carto.IFrameElement frameElement = graphicsContainer.FindFrame(map);
            ESRI.ArcGIS.Carto.IMapFrame mapFrame = frameElement as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
            ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast
            element.Geometry = envelope;
            element.Activate(activeView.ScreenDisplay);
            graphicsContainer.AddElement(element, 0);
            ESRI.ArcGIS.Carto.IMapSurround mapSurround = mapSurroundFrame.MapSurround;

            // Change out the default north arrow
            ESRI.ArcGIS.Carto.IMarkerNorthArrow markerNorthArrow = mapSurround as ESRI.ArcGIS.Carto.IMarkerNorthArrow; // Dynamic Cast
            ESRI.ArcGIS.Display.IMarkerSymbol markerSymbol = markerNorthArrow.MarkerSymbol;
            ESRI.ArcGIS.Display.ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ESRI.ArcGIS.Display.ICharacterMarkerSymbol; // Dynamic Cast
            characterMarkerSymbol.CharacterIndex = 200; // change the symbol for the North Arrow
            markerNorthArrow.MarkerSymbol = characterMarkerSymbol;
        }

调用方法:

private void 指北针ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IPageLayout pageLayout = axPageLayoutControl1.ActiveView as IPageLayout;
            AddNorthArrow(pageLayout, axPageLayoutControl1.ActiveView.FocusMap);
        }


可以用鼠标移动其位置(关键是设置buddycontrol)。



https://blog.sciencenet.cn/blog-3373120-1111732.html

上一篇:ArcGIS Engine二次开发学习(9)MapControl、TOCControl右键菜单
下一篇:ArcGIS Engine二次开发学习(11)根据空间关系查询
收藏 IP: 58.244.72.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-20 11:16

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部