免费视频|新人指南|投诉删帖|广告合作|地信网APP下载

查看: 2255|回复: 1
收起左侧

[求助] 二次开发,制图输出时如何实现图例的编辑

[复制链接]

0

主题

258

铜板

1

好友

实习生

Rank: 1

积分
6
发表于 2018-2-26 17:04 | 显示全部楼层 |阅读模式
本帖最后由 化云随风 于 2018-2-27 11:48 编辑

因为涉及到的图层比较多,图例占比太大,想要实现ArcMap中的功能,添加图例时可以自己设置图例分几列,网上没找到相关资料,涉及到多个图层组,目前输出情况截图如下

private void btnAddLegend_ItemClick(object sender, ItemClickEventArgs e)
        {           
            IActiveView pActiveView = this.axPageLayoutControlThematic.ActiveView as IActiveView;
            IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer;
            UID pID = new UID();
            pID.Value = "esriCarto.Legend";

            IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame;
            IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pID, null);//根据唯一标示符,创建与之对应MapSurroundFrame

            IElement pDeletElement = axPageLayoutControlThematic.FindElementByName("Legend");//获取PageLayout中的图例元素
            if (pDeletElement != null)
            {
                pGraphicsContainer.DeleteElement(pDeletElement);  //如果已经存在图例,删除已经存在的图例
            }            
            //添加图例
            IElement pElement = pMapSurroundFrame as IElement;
            IEnvelope pEnv = null;
            if (null == pEnv)
            {
                pEnv = new EnvelopeClass();
                pEnv.PutCoords(1, 1, 2, 2);
            }
            pElement.Geometry = pEnv as IGeometry;
            IMapSurround pMapSurround = pMapSurroundFrame.MapSurround;
            ILegend pLegend = pMapSurround as ILegend;            
            pLegend.ClearItems();
            pLegend.Title = "图例";

            for (int i = 0; i < pActiveView.FocusMap.LayerCount; i++)
            {
                ILayer pLayer = pActiveView.FocusMap.get_Layer(i);
                if (pLayer.Visible == true)
                {

                    if (pLayer is IGroupLayer || pLayer is ICompositeLayer)
                    {
                        ICompositeLayer pCompositeLayer = (ICompositeLayer)pLayer;
                        for (int j = pCompositeLayer.Count - 1; j >= 0; j--)
                        {                           
                            ILayer pSubLayer = pCompositeLayer.get_Layer(j);                           
                            ILegendItem pItem = SetItemStyle(pSubLayer);                           
                            pLegend.AddItem(pItem);//添加图例内容                           
                        }
                    }
                    else
                    {                                             
                        ILegendItem pItem = SetItemStyle(pLayer);                     
                        pLegend.AddItem(pItem);//添加图例内容                       
                    }
                }
            }           
            pGraphicsContainer.AddElement(pElement, 0);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);         
        }

        private ILegendItem SetItemStyle(ILayer layer)
        {
            StdFont myFont = new stdole.StdFontClass();
            myFont.Name = "宋体";
            myFont.Size = 10;

            ITextSymbol txtSymbol = new TextSymbolClass();
            txtSymbol.Font = (IFontDisp)myFont;                       
            ILegendItem pLegendItem = new HorizontalLegendItemClass();            
            pLegendItem.NewColumn = false;                          
            pLegendItem.Layer = layer;//获取添加图例关联图层            
            pLegendItem.ShowDescriptions = false;
            pLegendItem.Columns = 3;
            pLegendItem.LayerNameSymbol = txtSymbol;
            pLegendItem.ShowHeading = true;
            pLegendItem.ShowLabels = true;            
            //IMapSurroundFrame
            return pLegendItem;
        }
图例.jpg
头像被屏蔽

141

主题

980万

铜板

3万

好友

管理员

Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20

积分
627184
发表于 2018-2-26 17:26 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

在线客服
快速回复 返回顶部 返回列表