예제 #1
0
        /// <summary>
        /// 添加默认图例
        /// </summary>
        /// <param name="layoutControl">布局视图</param>
        /// <param name="pEnv">矩形框</param>
        public static void AddDefaultLegend(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 {
                Value = "esriCarto.Legend"
            };
            IMapSurroundFrame
                pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pID, null); //根据唯一标示符,创建与之对应MapSurroundFrame

            //如果已经存在图例,删除已经存在的图例
            MappingHelper.DeleteElementByName(layoutControl, "Legend");
            //添加图例
            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);
            //添加元素
            MappingHelper.AddElementWithName(pGraphicsContainer, pElement, "Legend");
        }
예제 #2
0
        /// <summary>
        /// 添加制图标题
        /// </summary>
        /// <param name="layoutControl">布局视图</param>
        /// <param name="pEnv">矩形框</param>
        /// <param name="textElement">文本元素</param>
        public static void AddMapTitle(AxPageLayoutControl layoutControl, IEnvelope pEnv, ITextElement textElement)
        {
            if (textElement == null)
            {
                return;
            }
            IGraphicsContainer pGraphicsContainer = layoutControl.PageLayout as IGraphicsContainer;

            if (pGraphicsContainer == null)
            {
                return;
            }
            //如果存在标题,则删除标题
            MappingHelper.DeleteElementByName(layoutControl, MapTitle);
            IElement pElement = (IElement)textElement;

            pElement.Geometry = pEnv;
            //添加元素
            MappingHelper.AddElementWithName(pGraphicsContainer, pElement, MapTitle);
        }
예제 #3
0
 /// <summary>
 /// 获取制图标题元素
 /// </summary>
 /// <param name="layoutControl"></param>
 /// <returns></returns>
 public static ITextElement GetMapTitle(AxPageLayoutControl layoutControl)
 {
     return(MappingHelper.GetElementByName(layoutControl, MapTitle) as ITextElement);
 }