예제 #1
0
        private void Btn_AddLegend_Click(object sender, EventArgs e)
        {
            IGraphicsContainer pGraphicsContainer = Ctrl_PageLayout.ActiveView.GraphicsContainer;
            IMapFrame          pMapFrame          = (IMapFrame)pGraphicsContainer.FindFrame(Ctrl_PageLayout.ActiveView.FocusMap);

            if (pMapFrame == null)
            {
                return;
            }
            UID uid = new UIDClass
            {
                Value = "esriCarto.Legend"
            };
            IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(uid, null);

            if (pMapSurroundFrame == null || pMapSurroundFrame.MapSurround == null)
            {
                return;
            }
            pMapSurroundFrame.MapSurround.Name = "Legend";
            ILegend pLegend = new Legend();

            pLegend       = pMapSurroundFrame.MapSurround as ILegend;
            pLegend.Title = "Legend";
            IElement pElement = (IElement)pMapSurroundFrame;

            pElement.Geometry = m_pEnvelopDrawed;
            if (m_pLegendElement != null)
            {
                Ctrl_PageLayout.ActiveView.GraphicsContainer.DeleteElement(m_pLegendElement);
            }
            Ctrl_PageLayout.ActiveView.GraphicsContainer.AddElement(pElement, 0);
            m_pLegendElement = pElement;
            Ctrl_PageLayout.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
예제 #2
0
        /// <summary>
        /// 比例尺
        /// </summary>
        /// <param name="pActiveView"></param>
        /// <param name="pPageLayout"></param>
        /// <param name="pEnv"></param>
        public void makeScaleBar(IActiveView pActiveView, IPageLayout pPageLayout, IEnvelope pEnv)
        {
            IGraphicsContainer container = pPageLayout as IGraphicsContainer;
            // 获得MapFrame
            IFrameElement frameElement = container.FindFrame(pActiveView.FocusMap);
            IMapFrame     mapFrame     = frameElement as IMapFrame;
            //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround
            UID uid = new UIDClass();

            uid.Value = "esriCarto.AlternatingScaleBar";
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);
            //设置MapSurroundFrame中比例尺的样式
            IMapSurround mapSurround    = mapSurroundFrame.MapSurround;
            IScaleBar    markerScaleBar = ((IScaleBar)mapSurround);

            markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow;
            markerScaleBar.UseMapSettings();
            //QI,确定mapSurroundFrame的位置
            IElement element = mapSurroundFrame as IElement;

            element.Geometry = pEnv;
            //使用IGraphicsContainer接口添加显示
            container.AddElement(element, 0);
            pActiveView.Refresh();
        }
예제 #3
0
        /// <summary>
        /// 生成一个默认指北针
        /// </summary>
        /// <param name="pageLayoutControl"></param>
        /// <param name="startX"></param>
        /// <param name="startY"></param>
        /// <returns></returns>
        public static IMapSurround GetDefaultNortthArrow(IPageLayoutControlDefault pageLayoutControl, double startX, double startY)
        {
            try
            {
                IPageLayout pageLayout  = pageLayoutControl.PageLayout;
                IActiveView pActiveView = pageLayoutControl.ActiveView;
                IMap        map         = pActiveView.FocusMap;

                if (pageLayout == null || map == null)
                {
                    return(null);
                }
                IEnvelope envelope = new EnvelopeClass();
                envelope.PutCoords(startX, startY, startX + 48, startY + 48); //  Specify the location and size of the north arrow

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

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

                return(mapSurround);
            }
            catch (System.Exception ex)
            {
                return(null);
            }
        }
예제 #4
0
        public static void AddNorthArrow(AxPageLayoutControl pageLayoutControl, IEnvelope envelope)
        {
            IUID uid = new UIDClass()
            {
                Value = "esriCarto.MarkerNorthArrow"
            };

            IFrameElement frameElement = (pageLayoutControl.PageLayout as IGraphicsContainer)
                                         .FindFrame(pageLayoutControl.ActiveView.FocusMap);
            IMapFrame         mapFrame         = frameElement as IMapFrame;
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as UID, null); // Dynamic Cast
            IElement          element          = mapSurroundFrame as IElement;                   // Dynamic Cast

            element.Geometry = envelope;
            element.Activate(pageLayoutControl.ActiveView.ScreenDisplay);
            (pageLayoutControl.PageLayout as IGraphicsContainer).AddElement(element, 0);
            IMapSurround mapSurround = mapSurroundFrame.MapSurround;

            // Change out the default north arrow
            IMarkerNorthArrow      markerNorthArrow      = mapSurround as IMarkerNorthArrow;       // Dynamic Cast
            IMarkerSymbol          markerSymbol          = markerNorthArrow.MarkerSymbol;
            ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ICharacterMarkerSymbol; // Dynamic Cast

            characterMarkerSymbol.CharacterIndex = 202;
            markerNorthArrow.MarkerSymbol        = characterMarkerSymbol;
        }
예제 #5
0
        public void AddMapLegend(IPageLayout pageLayout, IMap map, System.Double posX, System.Double posY, System.Double legW)
        {
            try
            {
                if (pageLayout == null || map == null)
                {
                    return;
                }
                IGraphicsContainer          graphicsContainer = pageLayout as IGraphicsContainer;              // Dynamic Cast
                IMapFrame                   mapFrame          = graphicsContainer.FindFrame(map) as IMapFrame; // Dynamic Cast
                ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
                uid.Value = "esriCarto.Legend";
                IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame((ESRI.ArcGIS.esriSystem.UID)uid, null); // Explicit Cast

                //Get aspect ratio
                IQuerySize    querySize = mapSurroundFrame.MapSurround as IQuerySize; // Dynamic Cast
                System.Double w         = 0;
                System.Double h         = 0;
                querySize.QuerySize(ref w, ref h);
                System.Double aspectRatio = w / h;

                IEnvelope envelope = new EnvelopeClass();

                envelope.PutCoords(posX, posY, (posX * legW), (posY * legW / aspectRatio));
                IElement element = mapSurroundFrame as IElement; // Dynamic Cast
                element.Geometry = envelope;
                graphicsContainer.AddElement(element, 0);
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
예제 #6
0
        /// <summary>
        /// 文字比例尺
        /// </summary>
        /// <returns></returns>
        public bool AddTxtSacleBar()
        {
            IStyleSelector pStyleSelector = new ScaleTextSelectorClass();
            bool           m_bOK          = pStyleSelector.DoModal(0);

            if (m_bOK == true)
            {
                IScaleText pScaleText = pStyleSelector.GetStyle(0) as IScaleText;

                IEnvelope envelope = new EnvelopeClass();
                envelope.PutCoords(0.2, 0.2, 5, 1);
                ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
                uid.Value = "esriCarto.Scaletext";
                IMap pMap = mainPage.ActiveView.FocusMap;
                IGraphicsContainer graphicsContainer = mainPage.ActiveView as IGraphicsContainer;
                IActiveView        activeView        = mainPage.ActiveView as IActiveView;
                IFrameElement      frameElement      = graphicsContainer.FindFrame(pMap);
                IMapFrame          mapFrame          = frameElement as IMapFrame;
                IMapSurroundFrame  mapSurroundFrame  = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null);
                IMapSurround       mapsurround       = pScaleText as IMapSurround;
                mapSurroundFrame.MapSurround = mapsurround;
                IElement element = mapSurroundFrame as IElement;
                element.Geometry = envelope;
                element.Activate(activeView.ScreenDisplay);
                graphicsContainer.AddElement(element, 0);
                IMapSurround mapSurround = mapSurroundFrame.MapSurround;
            }
            return(true);
        }
예제 #7
0
        /// <summary>
        /// 添加图例或指北针——根据UID元素添加相应的元素
        /// </summary>
        /// <param name="uid"></param>
        private void AddElementInPageLayer(UID uid)
        {
            //提供对控制图形容器的成员的访问。
            IGraphicsContainer graphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer;
            //提供对成员的访问, 控制map元素的对象, IMapFrame是地图浏览栏对象的默认接口
            //通过FindFrame方法, 查找axPageLayoutControl1中屏幕包含指定对象的框架
            IMapFrame mapFrame = graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IMapFrame;
            //提供对成员的访问, 控制地图环绕元素映射的接口, 是附属物框架的对象的默认接口
            //通过CreateSurroundFrame方法创建基于当前地图框下的一个新地图环绕元素(如图例、指北针)
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);
            //IElement是所有图形元素和框架元素类都要实现的接口
            //将mapSurroundFrame强转成IElement类型
            IElement element = mapSurroundFrame as IElement;
            //实例化一个包络线
            IEnvelope envelope = new EnvelopeClass();

            //设定坐标
            envelope.PutCoords(1, 1, 2, 2);
            //设置元素中的几何形状
            element.Geometry = envelope;
            try
            {
                //提供对控制图例的成员的访问。
                ILegend legend = (ILegend)mapSurroundFrame.MapSurround;
                legend.Title = "图例";
            }
            catch
            { }
            graphicsContainer.AddElement(element, 0);
            //设置元素将在axPageLayoutControl屏幕上显示图形
            element.Activate(axPageLayoutControl1.ActiveView.ScreenDisplay);
            //部分刷新
            axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
예제 #8
0
        public void AddNorthArrow(IPageLayout pageLayout)
        {
            IGraphicsContainer container  = pageLayout as IGraphicsContainer;
            IActiveView        activeView = pageLayout as IActiveView;
            // 获得MapFrame
            IFrameElement frameElement = container.FindFrame(activeView.FocusMap);
            IMapFrame     mapFrame     = frameElement as IMapFrame;
            //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround
            UID uid = new UIDClass();

            uid.Value = "esriCarto.MarkerNorthArrow";
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);
            //设置MapSurroundFrame中指北针的点符号
            IMapSurround      mapSurround      = mapSurroundFrame.MapSurround;
            IMarkerNorthArrow markerNorthArrow = mapSurround as IMarkerNorthArrow;
            IMarkerSymbol     markerSymbol     = markerNorthArrow.MarkerSymbol;

            markerSymbol.Size             = 18;
            markerNorthArrow.MarkerSymbol = markerSymbol;
            //QI,确定mapSurroundFrame的位置
            IElement  element  = mapSurroundFrame as IElement;
            IEnvelope envelope = new EnvelopeClass();

            envelope.PutCoords(0.2, 0.2, 5, 5);
            element.Geometry = envelope;
            //使用IGraphicsContainer接口添加显示
            container.AddElement(element, 0);
            activeView.Refresh();
        }
예제 #9
0
        public static void addScalebar(AxPageLayoutControl axPageLayoutControl, String type)
        {
            IPageLayout        pageLayout         = axPageLayoutControl.PageLayout;
            IActiveView        activeView         = pageLayout as IActiveView;
            IMap               pMap               = activeView.FocusMap;
            IGraphicsContainer pGraphicsContainer = pageLayout as IGraphicsContainer;
            IMapFrame          mapFrame           = (IMapFrame)pGraphicsContainer.FindFrame(pMap);
            UID uid = new UIDClass();

            uid.Value = type;
            IMapSurroundFrame pMapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);
            IMapSurround      pMapSurround      = pMapSurroundFrame.MapSurround;
            IScaleBar         pScaleBar         = (IScaleBar)pMapSurround;

            pScaleBar.LabelPosition = esriVertPosEnum.esriBelow;
            pScaleBar.UseMapSettings();
            IEnvelope pEnvelope = new EnvelopeClass();

            pEnvelope.PutCoords(0.8, 0.8, 13, 2);
            IElement element = pMapSurroundFrame as IElement;

            element.Geometry = pEnvelope;
            pGraphicsContainer.AddElement(element, 0);
            activeView.Refresh();
        }
예제 #10
0
        public override void OnClick()
        {
            LegendWizard legendWizard = new LegendWizard();

            legendWizard.StyleGallery = this._context.StyleGallery;
            IGraphicsContainer graphicsContainer = this._context.ActiveView as IGraphicsContainer;
            IMapFrame          mapFrame          = graphicsContainer.FindFrame(this._context.FocusMap) as IMapFrame;
            IMapSurroundFrame  mapSurroundFrame  = mapFrame.CreateSurroundFrame(new UID
            {
                Value = "esriCarto.Legend"
            }, null);

            legendWizard.InitialLegendFrame = mapSurroundFrame;
            legendWizard.FocusMap           = this._context.FocusMap;
            legendWizard.ShowDialog();
            IEnvelope envelope = new Envelope() as IEnvelope;

            envelope.PutCoords(0.0, 0.0, 5.0, 10.0);
            IEnvelope envelope2 = new Envelope() as IEnvelope;

            mapSurroundFrame.MapSurround.QueryBounds(this._context.ActiveView.ScreenDisplay, envelope, envelope2);
            (mapSurroundFrame as IElement).Geometry = envelope2;
            INewElementOperation newElementOperation = new NewElementOperation();

            newElementOperation.ActiveView = this._context.ActiveView;
            newElementOperation.Element    = (mapSurroundFrame as IElement);
            this._context.OperationStack.Do(newElementOperation);
        }
예제 #11
0
        /// <summary>
        /// 生成默认比例尺
        /// </summary>
        /// <param name="pageLayoutControl"></param>
        /// <param name="startX"></param>
        /// <param name="startY"></param>
        /// <returns></returns>
        public static IMapSurround GetDefaultScaleBar(IPageLayoutControlDefault pageLayoutControl, double startX, double startY)
        {
            try
            {
                IPageLayout        pageLayout = pageLayoutControl.PageLayout;
                IGraphicsContainer container  = pageLayout as IGraphicsContainer;
                IActiveView        activeView = pageLayout as IActiveView;
                // 获得MapFrame
                IFrameElement frameElement = container.FindFrame(activeView.FocusMap);
                IMapFrame     mapFrame     = frameElement as IMapFrame;
                //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround
                UID uid = new UIDClass();
                uid.Value = "esriCarto.AlternatingScaleBar";
                IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);
                //设置MapSurroundFrame中比例尺的样式
                IMapSurround mapSurround    = mapSurroundFrame.MapSurround;
                IScaleBar    markerScaleBar = ((IScaleBar)mapSurround);
                markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow;
                markerScaleBar.UseMapSettings();
                //QI,确定mapSurroundFrame的位置
                IElement  element  = mapSurroundFrame as IElement;
                IEnvelope envelope = new EnvelopeClass();
                envelope.PutCoords(startX, startY, startX + 10, startY + 10);
                element.Geometry = envelope;

                mapSurround = mapSurroundFrame.MapSurround;
                return(mapSurround);
            }
            catch (System.Exception ex)
            {
                return(null);
            }
        }
예제 #12
0
        private void mi_AddNorthArrow_Click(object sender, EventArgs e)
        {
            IActiveView        pActiveView        = axPageLayoutControl1.PageLayout as IActiveView;
            IMap               pMap               = pActiveView.FocusMap as IMap;
            IGraphicsContainer pGraphicsContainer = pActiveView as IGraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
            IMapSurround       pMapSurround;
            INorthArrow        pNorthArrow;

            pNorthArrow       = new MarkerNorthArrowClass();
            pMapSurround      = pNorthArrow;
            pMapSurround.Name = "NorthArrow";
            //定义UID
            UID uid = new UIDClass();

            uid.Value = "esriCarto.MarkerNorthArrow";
            //定义MapSurroundFrame对象
            IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(uid, null);

            pMapSurroundFrame.MapSurround = pMapSurround;
            //定义Envelope设置Element摆放的位置
            IEnvelope pEnvelope = new EnvelopeClass();

            pEnvelope.PutCoords(17, 25, 17, 25);


            IElement pElement = pMapSurroundFrame as IElement;

            pElement.Geometry = pEnvelope;
            pGraphicsContainer.AddElement(pElement, 0);
        }
예제 #13
0
        private bool method_0()
        {
            IActiveView        activeView        = this._context.ActiveView;
            IGraphicsContainer graphicsContainer = activeView.GraphicsContainer;
            bool result;

            if (graphicsContainer == null)
            {
                result = false;
            }
            else
            {
                try
                {
                    frmSymbolSelector frmSymbolSelector = new frmSymbolSelector();
                    if (frmSymbolSelector == null)
                    {
                        result = false;
                        return(result);
                    }
                    IScaleBar scaleBar = new HollowScaleBar();
                    frmSymbolSelector.SetSymbol(scaleBar);
                    frmSymbolSelector.SetStyleGallery(this._context.StyleGallery);
                    if (frmSymbolSelector.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        scaleBar = (frmSymbolSelector.GetSymbol() as IScaleBar);
                        if (scaleBar == null)
                        {
                            result = false;
                            return(result);
                        }
                        UID clsid = new UID
                        {
                            Value = "esriCarto.ScaleBar"
                        };
                        IMapFrame mapFrame = graphicsContainer.FindFrame(activeView.FocusMap) as IMapFrame;
                        scaleBar.Units = mapFrame.Map.DistanceUnits;
                        IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(clsid, scaleBar);
                        IElement          element          = mapSurroundFrame as IElement;
                        IEnvelope         envelope         = new Envelope() as IEnvelope;
                        envelope.PutCoords(2.0, 8.0, 9.0, 10.0);
                        IEnvelope envelope2 = new Envelope() as IEnvelope;
                        scaleBar.QueryBounds(this._context.ActiveView.ScreenDisplay, envelope, envelope2);
                        element.Geometry = envelope2;
                        INewElementOperation newElementOperation = new NewElementOperation();
                        newElementOperation.ActiveView = this._context.ActiveView;
                        newElementOperation.Element    = element;
                        this._context.OperationStack.Do(newElementOperation);
                        result = true;
                        return(result);
                    }
                }
                catch
                {
                }
                result = false;
            }
            return(result);
        }
예제 #14
0
        private bool method_0()
        {
            IActiveView        activeView        = this._context.ActiveView;
            IGraphicsContainer graphicsContainer = activeView.GraphicsContainer;
            bool result;

            if (graphicsContainer == null)
            {
                return(false);
            }

            try
            {
                frmSymbolSelector frmSymbolSelector = new frmSymbolSelector();
                if (frmSymbolSelector == null)
                {
                    return(false);
                }
                INorthArrow northArrow = new MarkerNorthArrow();
                frmSymbolSelector.SetSymbol(northArrow);
                frmSymbolSelector.SetStyleGallery(this._context.StyleGallery);
                if (frmSymbolSelector.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    northArrow = (frmSymbolSelector.GetSymbol() as INorthArrow);
                    if (northArrow == null)
                    {
                        result = false;
                        return(result);
                    }
                    northArrow.Refresh();
                    IEnvelope envelope = new Envelope() as IEnvelope;
                    envelope.PutCoords(5.0, 10.0, 8.0, 13.0);
                    IEnvelope envelope2 = new Envelope() as IEnvelope;
                    northArrow.QueryBounds(this._context.ActiveView.ScreenDisplay, envelope, envelope2);
                    UID clsid = new UID
                    {
                        Value = "esriCarto.MarkerNorthArrow"
                    };
                    IMapFrame         mapFrame         = graphicsContainer.FindFrame(activeView.FocusMap) as IMapFrame;
                    IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(clsid, northArrow);
                    IElement          element          = mapSurroundFrame as IElement;
                    element.Geometry = envelope2;
                    INewElementOperation operation = new NewElementOperation
                    {
                        ActiveView = this._context.ActiveView,
                        Element    = element
                    };
                    this._context.OperationStack.Do(operation);
                    result = true;
                    return(result);
                }
            }
            catch
            {
            }
            result = false;

            return(result);
        }
예제 #15
0
        // 添加图例
        public static void MakeLegend(AxPageLayoutControl pageLayoutControl, IEnvelope envelope)
        {
            IActiveView pActiveView = pageLayoutControl.ActiveView;

            UID pUID = new UID()
            {
                Value = "esriCarto.Legend"
            };
            IGraphicsContainer pGraphicsContainer = pageLayoutControl.PageLayout as IGraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame;
            // 根据唯一标识符,创建与之对应的MapSurroundFrame
            IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pUID, null);
            // 获取PageLayout中的图例元素
            IElement pDeleteElement = pageLayoutControl.FindElementByName("Legend");

            if (pDeleteElement != null)
            {
                pGraphicsContainer.DeleteElement(pDeleteElement); // 如果已存在图例,删除已经存在的图例
            }
            // 设置MapSurroundFrame背景
            ISymbolBackground pSymbolBackground = new SymbolBackgroundClass()
            {
                FillSymbol = new SimpleFillSymbolClass()
                {
                    Color   = AeUtilsSymbology.GetRgbColor(240, 240, 240),
                    Outline = new SimpleLineSymbolClass()
                    {
                        Color = AeUtilsSymbology.GetRgbColor(0, 0, 0)
                    }
                }
            };

            pMapSurroundFrame.Background = pSymbolBackground;
            // 添加图例
            IElement pElement = pMapSurroundFrame as IElement;

            pElement.Geometry = envelope as IGeometry;
            IMapSurround pMapSurround = pMapSurroundFrame.MapSurround;
            ILegend      pLegend      = pMapSurround as ILegend;

            pLegend.ClearItems();
            pLegend.Title = "图例";
            for (int i = 0; i < pActiveView.FocusMap.LayerCount; i++)
            {
                ILegendItem pLegendItem = new HorizontalLegendItemClass()
                {
                    Layer            = pActiveView.FocusMap.get_Layer(i),
                    ShowDescriptions = false,
                    Columns          = 1,
                    ShowHeading      = true,
                    ShowLabels       = true
                };
                pLegend.AddItem(pLegendItem);
            }
            pGraphicsContainer.AddElement(pElement, 0);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
예제 #16
0
        public void AddNorthArrow()
        {   //添加指北针
            IGraphicsContainer graphicsContainer = m_pagelayoutControl.GraphicsContainer;

            //Get the MapFrame
            IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_pagelayoutControl.ActiveView.FocusMap);

            if (mapFrame == null)
            {
                return;
            }
            //Create a legend
            UID uID = new UIDClass();

            uID.Value = "esriCarto.MarkerNorthArrow";

            //Create a MapSurroundFrame from the MapFrame
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null);

            if (mapSurroundFrame == null)
            {
                return;
            }
            if (mapSurroundFrame.MapSurround == null)
            {
                return;
            }

            IEnvelope m_envelop = new EnvelopeClass();

            m_envelop.PutCoords(15, 15, 20, 20);
            INorthArrow         northArrow      = null;
            frmNorthArrowSymbol frmNorthArrow   = new frmNorthArrowSymbol();
            IStyleGalleryItem   pstyGallertItem = frmNorthArrow.GetItem(ESRI.ArcGIS.Controls.esriSymbologyStyleClass.esriStyleClassNorthArrows);;

            if (pstyGallertItem != null)
            {
                northArrow     = (INorthArrow)pstyGallertItem.Item;
                northArrow.Map = this.m_pagelayoutControl.ActiveView.FocusMap;
                northArrow.CalibrationAngle = frmNorthArrow.Angle();
            }
            else
            {
                return;
            }

            IMapSurround m_mapSurround;

            m_mapSurround = (IMapSurround)northArrow;
            mapSurroundFrame.MapSurround = m_mapSurround;
            IElement m_element = (IElement)mapSurroundFrame;

            m_element.Geometry = m_envelop;
            m_pagelayoutControl.AddElement(m_element, Type.Missing, Type.Missing, "NorthArrow", 2);
            m_pagelayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
예제 #17
0
        public void AddScaleBar()
        {
            IGraphicsContainer graphicsContainer = m_pagelayoutControl.GraphicsContainer;
            //Get the MapFrame
            IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_pagelayoutControl.ActiveView.FocusMap);

            if (mapFrame == null)
            {
                return;
            }

            //Create a legend
            UID uID = new UIDClass();

            uID.Value = "esriCarto.ScaleLine";
            //Create a MapSurroundFrame from the MapFrame
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null);

            if (mapSurroundFrame == null)
            {
                return;
            }
            if (mapSurroundFrame.MapSurround == null)
            {
                return;
            }

            // m_styleSelector = new ScaleBarSelectorClass();
            IEnvelope m_envelop = new EnvelopeClass();

            m_envelop.PutCoords(5, 5, 10, 10);

            ESRI.ArcGIS.Controls.esriSymbologyStyleClass styleClass = esriSymbologyStyleClass.esriStyleClassScaleBars;
            frmLegendItemSymbol frmScaleBar     = new frmLegendItemSymbol();
            IStyleGalleryItem   pstyGallertItem = frmScaleBar.GetItem(styleClass);

            if (pstyGallertItem == null)
            {
                return;
            }
            IScaleBar pScalebar = pstyGallertItem.Item as IScaleBar;

            pScalebar.Units = m_pagelayoutControl.ActiveView.FocusMap.MapUnits;
            pScalebar.Map   = m_pagelayoutControl.ActiveView.FocusMap;
            pScalebar.UseMapSettings();

            IMapSurround m_mapSurround;

            m_mapSurround = (IMapSurround)pScalebar;
            mapSurroundFrame.MapSurround = m_mapSurround;
            IElement m_element = (IElement)mapSurroundFrame;

            m_element.Geometry = m_envelop;
            m_pagelayoutControl.AddElement(m_element, Type.Missing, Type.Missing, "ScaleLine", 3);
            m_pagelayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
예제 #18
0
        public void AddTextScale()
        {
            IGraphicsContainer graphicsContainer = m_pagelayoutControl.GraphicsContainer;
            //Get the MapFrame
            IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_pagelayoutControl.ActiveView.FocusMap);

            if (mapFrame == null)
            {
                return;
            }

            //Create a legend
            UID uID = new UIDClass();

            uID.Value = "esriCarto.ScaleText";
            //Create a MapSurroundFrame from the MapFrame
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null);

            if (mapSurroundFrame == null)
            {
                return;
            }
            if (mapSurroundFrame.MapSurround == null)
            {
                return;
            }
            IEnvelope m_envelop = new EnvelopeClass();

            m_envelop.PutCoords(15, 15, 20, 20);

            frmLegendItemSymbol frmTextScal     = new frmLegendItemSymbol();
            IStyleGalleryItem   pStyGalleryItem = frmTextScal.GetItem(esriSymbologyStyleClass.esriStyleClassScaleTexts);
            IScaleText          pScaleText      = null;

            if (pStyGalleryItem != null)
            {
                pScaleText          = (IScaleText)pStyGalleryItem.Item;
                pScaleText.Map      = this.m_pagelayoutControl.ActiveView.FocusMap;
                pScaleText.MapUnits = this.m_pagelayoutControl.ActiveView.FocusMap.MapUnits;
            }

            else
            {
                return;
            }
            IMapSurround m_mapSurround;

            m_mapSurround = (IMapSurround)pScaleText;
            mapSurroundFrame.MapSurround = m_mapSurround;
            IElement m_element = (IElement)mapSurroundFrame;

            m_element.Geometry = m_envelop;
            m_pagelayoutControl.AddElement(m_element, Type.Missing, Type.Missing, "ScaleText", 4);
            m_pagelayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            //Get the GraphicsContainer
            IGraphicsContainer graphicsContainer = axPageLayoutControl1.GraphicsContainer;

            //Get the MapFrame
            IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap);

            if (mapFrame == null)
            {
                return;
            }

            //Create a legend
            UID uID = new UIDClass();

            uID.Value = "esriCarto.Legend";

            //Create a MapSurroundFrame from the MapFrame
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null);

            if (mapSurroundFrame == null)
            {
                return;
            }
            if (mapSurroundFrame.MapSurround == null)
            {
                return;
            }
            //Set the name
            mapSurroundFrame.MapSurround.Name = "Legend";

            //Envelope for the legend
            IEnvelope envelope = new EnvelopeClass();

            envelope.PutCoords(1, 1, 3.4, 2.4);

            //Set the geometry of the MapSurroundFrame
            IElement element = (IElement)mapSurroundFrame;

            element.Geometry = envelope;

            //Add the legend to the PageLayout
            axPageLayoutControl1.AddElement(element, Type.Missing, Type.Missing, "Legend", 0);

            //Refresh the PageLayoutControl
            axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

            //disable/enable buttons
            cmdDraw.Enabled       = false;
            cmdDelete.Enabled     = true;
            cmdChangeArea.Enabled = true;
            cmdChangeLine.Enabled = true;
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            IGraphicsContainer graphicsContainer = m_PageLayOutControl.GraphicsContainer;

            //Get the MapFrame
            IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_PageLayOutControl.ActiveView.FocusMap);

            if (mapFrame == null)
            {
                return;
            }

            //Create a legend
            UID uID = new UIDClass();

            uID.Value = "esriCarto.Legend";

            //Create a MapSurroundFrame from the MapFrame
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null);

            if (mapSurroundFrame == null)
            {
                return;
            }
            if (mapSurroundFrame.MapSurround == null)
            {
                return;
            }
            //Set the name
            mapSurroundFrame.MapSurround.Name = "图例";


            //Envelope for the legend
            IEnvelope envelope = new EnvelopeClass();

            envelope.PutCoords(1, 1, 3.4, 2.4);

            //Set the geometry of the MapSurroundFrame
            IElement element = (IElement)mapSurroundFrame;

            element.Geometry = envelope;

            //Add the legend to the PageLayout
            m_PageLayOutControl.AddElement(element, Type.Missing, Type.Missing, "图例", 0);

            //Refresh the PageLayoutControl
            m_PageLayOutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
예제 #21
0
        private IMapSurround CreateMapSurround(UID ipUID, IEnvelope ipEnv, string sName, IMapSurround ipStyle)
        {
            IMapSurround ms = null;
            IMapFrame    mf = m_hookHelper.ActiveView.GraphicsContainer.FindFrame(
                m_hookHelper.ActiveView.FocusMap) as IMapFrame;
            IMapSurroundFrame msf = mf.CreateSurroundFrame(ipUID, ipStyle);
            IElement          ele = msf as IElement;

            ele.Geometry = ipEnv;
            ms           = msf.MapSurround;
            ms.Name      = sName;
            m_hookHelper.ActiveView.GraphicsContainer.AddElement(ele, 0);
            m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,
                                                   null, null);
            return(ms);
        }
예제 #22
0
 public void add(string value, double xmin, double ymin, double xmax, double ymax)
 {
     uid       = new UID();
     uid.Value = value;
     envelope  = new Envelope() as IEnvelope;
     envelope.PutCoords(xmin, ymin, xmax, ymax);
     graphicsContainer = pageLayoutControl.PageLayout as IGraphicsContainer;
     mapFrame          = graphicsContainer.FindFrame(pageLayoutControl.ActiveView.FocusMap) as IMapFrame;
     mapSurroundFrame  = mapFrame.CreateSurroundFrame(uid, null);
     element           = mapSurroundFrame as IElement;
     element.Geometry  = envelope;
     element.Activate(pageLayoutControl.ActiveView.ScreenDisplay);
     trackCancel = new CancelTracker();
     element.Draw(pageLayoutControl.ActiveView.ScreenDisplay, trackCancel);
     graphicsContainer.AddElement(element, 0);
 }
예제 #23
0
        //插入图例
        public void InsertLegend()
        {
            this.SetCurrentTool();
            IGraphicsContainer graphicsContainer = this.m_pageLayoutControl.ActiveView.GraphicsContainer;

            //得到MapFrame对象
            IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_pageLayoutControl.ActiveView.FocusMap);

            if (mapFrame == null)
            {
                return;
            }
            //生成一个图例
            UID uID = new UIDClass();

            uID.Value = "esriCarto.Legend";
            //从MapFrame中生成一个MapSurroundFrame
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null);

            if (mapSurroundFrame == null)
            {
                return;
            }
            if (mapSurroundFrame.MapSurround == null)
            {
                return;
            }
            //MapSurroundFrame名称
            mapSurroundFrame.MapSurround.Name = "图例";
            ILegend pleg;

            pleg       = new Legend();
            pleg       = mapSurroundFrame.MapSurround as ILegend;
            pleg.Title = "图例";
            //设置图例的显示范围
            IEnvelope envelop = new EnvelopeClass();

            envelop.PutCoords(3, 3, 13, 5);
            IElement element = (IElement)mapSurroundFrame;

            element.Geometry = envelop;

            //添加图例元素
            m_pageLayoutControl.ActiveView.GraphicsContainer.AddElement(element, 0);
            //PageLayOutControl
            m_pageLayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
예제 #24
0
        /// <summary>
        /// 添加比例尺
        /// </summary>
        /// <param name="pageLayout"></param>
        /// <param name="map"></param>
        private void AddScalebar(IPageLayout pageLayout, IMap map)
        {
            if (pageLayout == null || map == null)
            {
                return;//当pageLayerout和map为空时返回
            }
            //实例化一个包络线
            IEnvelope envelope = new EnvelopeClass();

            //设定坐标
            envelope.PutCoords(1, 1, 3, 2);
            //实例化一个uid
            IUID uid = new UIDClass();

            //将uid设置为ESRICarto.scalebar
            uid.Value = "ESRICarto.scalebar";
            //提供对控制图形容器的成员的访问
            IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;
            //查找map中指定对象的框架
            IMapFrame mapFrame = graphicsContainer.FindFrame(map) as IMapFrame;
            //创建基于当前地图框下的一个新地图环绕元素
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as UID, null);
            //元素属性
            IElementProperties pElePro;
            //实例化一个比例尺对象
            IScaleBar markerScaleBar = new AlternatingScaleBarClass();

            //可以有多种比例尺类型
            markerScaleBar.Division          = 2;
            markerScaleBar.Divisions         = 2;
            markerScaleBar.LabelPosition     = esriVertPosEnum.esriAbove;
            markerScaleBar.Map               = map;
            markerScaleBar.Subdivisions      = 2;
            markerScaleBar.UnitLabel         = "";
            markerScaleBar.UnitLabelGap      = 4;
            markerScaleBar.UnitLabelPosition = esriScaleBarPos.esriScaleBarAbove; //位于比例尺上方
            markerScaleBar.Units             = esriUnits.esriKilometers;          //千米
            mapSurroundFrame.MapSurround     = markerScaleBar;
            //将mapSurroundFrame强转为IElementProperties
            pElePro = mapSurroundFrame as IElementProperties;
            //设置元素Name属性
            pElePro.Name = "my scale";
            //添加元素至axPageLayoutControl1
            axPageLayoutControl1.AddElement(mapSurroundFrame as IElement, envelope, Type.Missing, Type.Missing, 0);
            //部分刷新
            axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, Type.Missing, null);
        }
예제 #25
0
        public override IElement CreateElement(IPageLayout ipageLayout_0)
        {
            IElement   element = null;
            IScaleText style;

            if (base.Style != null)
            {
                style = base.Style as IScaleText;
            }
            else
            {
                style = new ScaleTextClass();
            }
            UIDClass class2 = new UIDClass
            {
                Value = "esriCarto.ScaleText"
            };
            UID       clsid = class2;
            IMapFrame frame =
                (ipageLayout_0 as IGraphicsContainer).FindFrame((ipageLayout_0 as IActiveView).FocusMap) as IMapFrame;

            style.MapUnits  = frame.Map.DistanceUnits;
            style.PageUnits = ipageLayout_0.Page.Units;
            style.Style     = esriScaleTextStyleEnum.esriScaleTextAbsolute;
            INumberFormat numberFormat = style.NumberFormat;

            if (numberFormat is INumericFormat)
            {
                (numberFormat as INumericFormat).RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals;
                (numberFormat as INumericFormat).UseSeparator   = false;
                (numberFormat as INumericFormat).RoundingValue  = 0;
                style.NumberFormat = numberFormat;
            }
            element = frame.CreateSurroundFrame(clsid, style) as IElement;
            IEnvelope oldBounds = new EnvelopeClass();
            IPoint    position  = this.GetPosition(ipageLayout_0);

            oldBounds.PutCoords(position.X, position.Y, position.X + 4.0, position.Y + 8.0);
            IEnvelope newBounds = new EnvelopeClass();

            style.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, oldBounds, newBounds);
            oldBounds.PutCoords(position.X, position.Y, position.X + newBounds.Width, position.Y + newBounds.Height);
            element.Geometry = oldBounds;
            this.Element     = element;
            return(element);
        }
예제 #26
0
        private void MakeLegend(IActiveView pActiveView, IPageLayout pPageLayout, IEnvelope pEnv)
        {
            UID pID = new UID();

            pID.Value = "esriCarto.Legend";
            IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame;
            IMapSurroundFrame  pMapSurroundFrame  = pMapFrame.CreateSurroundFrame(pID, null);         //根据唯一标示符,创建与之对应MapSurroundFrame
            IElement           pDeletElement      = axPageLayoutControl1.FindElementByName("Legend"); //获取PageLayout中的图例元素

            if (pDeletElement != null)
            {
                pGraphicsContainer.DeleteElement(pDeletElement);  //如果已经存在图例,删除已经存在的图例
            }
            //设置MapSurroundFrame背景
            ISymbolBackground pSymbolBackground = new SymbolBackgroundClass();
            IFillSymbol       pFillSymbol       = new SimpleFillSymbolClass();
            ILineSymbol       pLineSymbol       = new SimpleLineSymbolClass();

            pLineSymbol.Color            = m_OperatePageLayout.GetRgbColor(0, 0, 0);
            pFillSymbol.Color            = m_OperatePageLayout.GetRgbColor(240, 240, 240);
            pFillSymbol.Outline          = pLineSymbol;
            pSymbolBackground.FillSymbol = pFillSymbol;
            pMapSurroundFrame.Background = pSymbolBackground;
            //添加图例
            IElement pElement = pMapSurroundFrame as IElement;

            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++)
            {
                ILegendItem pLegendItem = new HorizontalLegendItemClass();
                pLegendItem.Layer            = pActiveView.FocusMap.get_Layer(i);//获取添加图例关联图层
                pLegendItem.ShowDescriptions = false;
                pLegendItem.Columns          = 1;
                pLegendItem.ShowHeading      = true;
                pLegendItem.ShowLabels       = true;
                pLegend.AddItem(pLegendItem);//添加图例内容
            }
            pGraphicsContainer.AddElement(pElement, 0);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
예제 #27
0
파일: Form1.cs 프로젝트: YNatsu/ArcEngine
//        图例

        private void AddLegend(AxPageLayoutControl axPageLayout)
        {
            //删除已经存在的图例

            IElement pElement = axPageLayout.FindElementByName("Legends");

            if (pElement != null)
            {
                axPageLayout.ActiveView.GraphicsContainer.DeleteElement(pElement);
            }

            IActiveView        pActiveView = axPageLayout.PageLayout as IActiveView;
            IGraphicsContainer container   = axPageLayout.PageLayout as IGraphicsContainer;
            // 获得MapFrame
            IMapFrame mapFrame = container.FindFrame(pActiveView.FocusMap) as IMapFrame;
            //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround
            UID uid = new UIDClass();

            uid.Value = "esriCarto.Legend";
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);
            //设置图例的Title
            ILegend2 legend = mapSurroundFrame.MapSurround as ILegend2;

            legend.Title = "地图图例";
            ILegendFormat format = new LegendFormatClass();
            ITextSymbol   symbol = new TextSymbolClass();

            symbol.Size        = 4;
            format.TitleSymbol = symbol;
            legend.Format      = format;
            //QI,确定mapSurroundFrame的位置
            IElement  element  = mapSurroundFrame as IElement;
            IEnvelope envelope = new EnvelopeClass();

            double x = 3;
            double y = 5;

            envelope.PutCoords(x, y, x + 5, y + 5);
            element.Geometry = envelope;
            //使用IGraphicsContainer接口添加显示
            container.AddElement(element, 0);
            pActiveView.Refresh();
        }
예제 #28
0
파일: Form1.cs 프로젝트: YNatsu/ArcEngine
//        指北针

        public void AddNorthArrow(AxPageLayoutControl axPageLayout)
        {
            //删除已经存在的指北针

            IElement pElement = axPageLayout.FindElementByName("NorthArrows");

            if (pElement != null)
            {
                axPageLayout.ActiveView.GraphicsContainer.DeleteElement(pElement);
            }


            IGraphicsContainer container  = axPageLayout.PageLayout as IGraphicsContainer;
            IActiveView        activeView = axPageLayout.PageLayout as IActiveView;
            // 获得MapFrame
            IFrameElement frameElement = container.FindFrame(activeView.FocusMap);
            IMapFrame     mapFrame     = frameElement as IMapFrame;
            //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround
            UID uid = new UIDClass();

            uid.Value = "esriCarto.MarkerNorthArrow";
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);
            //设置MapSurroundFrame中指北针的点符号
            IMapSurround      mapSurround      = mapSurroundFrame.MapSurround;
            IMarkerNorthArrow markerNorthArrow = mapSurround as IMarkerNorthArrow;
            IMarkerSymbol     markerSymbol     = markerNorthArrow.MarkerSymbol;

            markerSymbol.Size             = 48;
            markerNorthArrow.MarkerSymbol = markerSymbol;

            //QI,确定mapSurroundFrame的位置
            IElement  element  = mapSurroundFrame as IElement;
            IEnvelope envelope = new EnvelopeClass();

            double x = 15;
            double y = 22;

            envelope.PutCoords(x, y, x + 5, y + 5);
            element.Geometry = envelope;
            //使用IGraphicsContainer接口添加显示
            container.AddElement(element, 0);
            activeView.Refresh();
        }
예제 #29
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");
        }
예제 #30
0
        public void AddNorthArrow(IPageLayout pageLayout, IMap map, double posX, double posY, double division)
        {
            try
            {
                if (pageLayout == null || map == null)
                {
                    return;
                }

                IEnvelope envelope = new EnvelopeClass();
                envelope.PutCoords(posX - division, posY - division, posX, posY); //  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
                IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;                                      // Dynamic Cast
                IActiveView        activeView        = pageLayout as IActiveView;                                             // Dynamic Cast
                IFrameElement      frameElement      = graphicsContainer.FindFrame(map);
                IMapFrame          mapFrame          = frameElement as IMapFrame;                                             // Dynamic Cast
                IMapSurroundFrame  mapSurroundFrame  = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
                IElement           element           = mapSurroundFrame as IElement;                                          // Dynamic Cast
                element.Geometry = envelope;
                element.Activate(activeView.ScreenDisplay);
                graphicsContainer.AddElement(element, 0);
                IMapSurround mapSurround = mapSurroundFrame.MapSurround;

                // Change out the default north arrow
                IMarkerNorthArrow      markerNorthArrow      = mapSurround as IMarkerNorthArrow;       // Dynamic Cast
                IMarkerSymbol          markerSymbol          = markerNorthArrow.MarkerSymbol;
                ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ICharacterMarkerSymbol; // Dynamic Cast
                characterMarkerSymbol.CharacterIndex = 174;                                            // change the symbol for the North Arrow
                markerNorthArrow.MarkerSymbol        = characterMarkerSymbol;
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }