• 添加制图图例(转)


    AE二次开发-添加制图图例

     

    添加图例方法代码:

            /// <summary>
            /// 添加图例
            /// </summary>
            /// <param name="layoutControl">布局视图</param>
            /// <param name="pEnv">矩形框</param>
            public static void AddLegend(AxPageLayoutControl layoutControl, IEnvelope pEnv)
            {
                IGraphicsContainer pGraphicsContainer = layoutControl.PageLayout as IGraphicsContainer;
                if (pGraphicsContainer == null) return;
                IMap pMap = layoutControl.ActiveView.FocusMap;
                IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
                if (pMapFrame == null) return;
                UID pID = new UID();
                pID.Value = "esriCarto.Legend";
                IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pID, null);//根据唯一标示符,创建与之对应MapSurroundFrame
                IElement pDeletElement = layoutControl.FindElementByName("Legend");//获取PageLayout中的图例元素
                if (pDeletElement != null)
                {
                    pGraphicsContainer.DeleteElement(pDeletElement);  //如果已经存在图例,删除已经存在的图例
                }
                //获取图例背景
                pMapSurroundFrame.Background = GetSymbolBackground();
                //添加图例
                IElement pElement = pMapSurroundFrame as IElement;
                if (pElement == null) return;
                pElement.Geometry = pEnv;
                IMapSurround pMapSurround = pMapSurroundFrame.MapSurround;
                ILegend2 pLegend = pMapSurround as ILegend2;
                if (pLegend == null) return;
                //设置图例属性
                SetLegendProperty(pLegend, pMap);
                pGraphicsContainer.AddElement(pElement, 0);
            }
    
            /// <summary>
            /// 获取图例背景
            /// </summary>
            /// <returns></returns>
            private static ISymbolBackground GetSymbolBackground()
            {
                //设置MapSurroundFrame背景
                ISymbolBackground pSymbolBackground = new SymbolBackgroundClass();
                IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
                ILineSymbol pLineSymbol = new SimpleLineSymbolClass();
                pLineSymbol.Color = AeFunction.GetRgbColor(0, 0, 0);
                pFillSymbol.Color = AeFunction.GetRgbColor(240, 240, 240);
                pFillSymbol.Outline = pLineSymbol;
                pSymbolBackground.FillSymbol = pFillSymbol;
                return pSymbolBackground;
            }
    
            /// <summary>
            /// 设置图例属性
            /// </summary>
            /// <param name="pLegend">图例</param>
            /// <param name="pMap">地图</param>
            private static void SetLegendProperty(ILegend2 pLegend, IMap pMap)
            {
                pLegend.ClearItems();
                pLegend.Title = "图例";
                pLegend.AutoVisibility = true;
                for (int i = 0; i < pMap.LayerCount; i++)
                {
                    ILegendItem pLegendItem = new HorizontalLegendItemClass();
                    pLegendItem.Layer = pMap.Layer[i];//获取添加图例关联图层             
                    pLegendItem.ShowDescriptions = false;
                    pLegendItem.Columns = 1;
                    pLegendItem.ShowHeading = true;
                    pLegendItem.ShowLabels = true;
                    pLegend.AddItem(pLegendItem);//添加图例内容
                }
            }

    在布局视图上绘制矩形框,添加图例到矩形框内。 
    调用方法代码:

    //在布局视图上绘制矩形框,添加图例到矩形框内
    private void axPageLayoutControl1_OnMouseDown(object sender, IPageLayoutControlEvents_OnMouseDownEvent e)
            {
                if (e.button == 1) //左键点击
                {
    
                    IGeometry pGeometry = axPageLayoutControl1.TrackRectangle();
                    AddLegend(axPageLayoutControl1, (IEnvelope)pGeometry);
                }
    
            }
  • 相关阅读:
    Microsoft Dynamics CRM4.0 Data Auditing and Restore (数据审核和恢复)
    Microsoft Dynamics CRM4.0 在联系人contact列表上直接发送邮件
    安装Microsoft Dynamics CRM 2011时出现“Microsoft.Crm.Setup.Common.Analyzer+CollectAction 操作失败”的解决办法
    Microsoft Dynamics CRM4.0 控制是否显示 '设置Setting’ 区域
    Microsoft CRM "您查看的网页正在试图关闭窗口" 不能自动关闭的解决办法
    Dynamics CRM 2011 Ribbon 默认收起collapse和隐藏hide
    Microsoft Dynamics CRM4.0 在线用户检测(Online user detect)
    C语言I博客作业03
    C语言I博客作业06
    第一次作业
  • 原文地址:https://www.cnblogs.com/lianghong/p/8487505.html
Copyright © 2020-2023  润新知