Esempio n. 1
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);
        }
Esempio n. 2
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();
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            if (m_pHookHelper.PageLayout == null)
            {
                return;
            }

            try
            {
                IActiveView  pView = (IActiveView)m_pHookHelper.PageLayout;
                frmAddLegend frm   = new frmAddLegend(true);

                IMapSurroundFrame pLegendFrame = frm.GetMapLegend(pView);
                if (pLegendFrame == null)
                {
                    return;
                }
                frm.Dispose();

                pView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ìí¼ÓͼÀýʧ°Ü£º" + ex.Message, "Ìáʾ");
            }
        }
Esempio n. 5
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();
        }
Esempio n. 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);
        }
Esempio n. 7
0
        /// <summary>
        /// 替换原地图容器中的元素为模板的元素
        /// </summary>
        /// <param name="tempGraph">模板</param>
        /// <param name="oldMapFrame">原地图容器</param>
        /// <returns></returns>
        private static IArray ReplaceOldIntoTempElement(IGraphicsContainer tempGraph, IMapFrame oldMapFrame)
        {
            tempGraph.Reset();
            IElement tempElement = tempGraph.Next();
            IArray   pArray      = new ArrayClass();

            while (tempElement != null)
            {
                if (tempElement is IMapFrame)
                {
                    //改变布局边框几何形状
                    IElement pMapFrameElement = oldMapFrame as IElement;
                    if (pMapFrameElement != null)
                    {
                        pMapFrameElement.Geometry = tempElement.Geometry;
                    }
                }
                else
                {
                    IMapSurroundFrame pTempMapSurroundFrame = tempElement as IMapSurroundFrame;
                    if (pTempMapSurroundFrame != null)
                    {
                        //设置地图框架
                        pTempMapSurroundFrame.MapFrame = oldMapFrame;
                    }

                    //获取图例指北针等元素
                    pArray.Add(tempElement);
                }

                tempElement = tempGraph.Next();
            }

            return(pArray);
        }
        //复制MapFrame
        private void CopyMapSurroundFrame(IMapSurroundFrame srcArrow, IMapSurroundFrame destArrow)
        {
            IClone pSrc  = srcArrow as IClone;
            IClone pDest = pSrc.Clone();

            destArrow = pDest as IMapSurroundFrame;
        }
Esempio n. 9
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;
        }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
            }
        }
Esempio n. 13
0
 private void SetMapSurroundFrameMapGroupRecursion(IGroupElement pGroupElement, IMap pMap)
 {
     try
     {
         if (((pGroupElement != null) && (pGroupElement.ElementCount > 0)) && (pMap != null))
         {
             IEnumElement elements = null;
             elements = pGroupElement.Elements;
             elements.Reset();
             IMapSurroundFrame frame    = null;
             IElement          element2 = null;
             for (element2 = elements.Next(); element2 != null; element2 = elements.Next())
             {
                 if (element2 is IMapSurroundFrame)
                 {
                     frame = element2 as IMapSurroundFrame;
                     frame.MapSurround.Map = pMap;
                 }
                 else if (element2 is IGroupElement)
                 {
                     this.SetMapSurroundFrameMapGroupRecursion(element2 as IGroupElement, pMap);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.ElementFun", "SetMapSurroundFrameMapGroupRecursion", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
     }
 }
Esempio n. 14
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);
            }
        }
Esempio n. 15
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();
        }
Esempio n. 16
0
        private ISymbolShadow m_SymbolShadow;         //阴影

        public frmLegendWizard(IMap pmap, IPageLayoutControlDefault pPageLayoutControl, IMapSurroundFrame pMapSurroundFrame)
        {//用于在 任意范围打印的对话框 中编辑图例
            InitializeComponent();
            mapSurroundFrame    = pMapSurroundFrame;
            m_pageLayoutControl = pPageLayoutControl;
            m_Map = pmap;
        }
Esempio n. 17
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;
            }
        }
Esempio n. 18
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);
        }
Esempio n. 19
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);
        }
Esempio n. 20
0
        /// <summary>
        /// Add the mapscale text to the Graphic Container. Places this text under the scale bar.
        /// </summary>
        /// <param name="sMapScale"></param>
        public override void addMapScaleText(string sMapScale)
        {
            CSpatialSubs       oSpatialSubs = new CSpatialSubs();
            IMxDocument        pMxDoc       = (IMxDocument)this.App.Document;
            IGraphicsContainer pGC          = (IGraphicsContainer)pMxDoc.PageLayout;

            IMapSurroundFrame pMSFrame  = null;
            IEnvelope         pEnv      = null;
            ITextSymbol       pTextSym  = null;
            ITextElement      pTextElem = null;

            try
            {
                //Locate the scalebar in the graphics container because we
                //want to put the mapscale right under it.
                //A scalebar is contained within a MapSurroundFrame.
                pGC.Reset();
                IElement pElem = pGC.Next();
                while (pElem != null)
                {
                    if (pElem is IMapSurroundFrame)
                    {
                        pMSFrame = (IMapSurroundFrame)pElem;
                        if (pMSFrame.Object is IScaleBar)
                        {
                            break;  // we got the scalebar
                        }
                    }
                    pElem = pGC.Next();
                }

                pEnv = new EnvelopeClass();
                //get the envelope of the scalebar
                pElem.QueryBounds(pMxDoc.ActiveView.ScreenDisplay, pEnv);

                double xMin = SPrintConst.MapscaleText_XMin * base.XFactor;
                double xMax = SPrintConst.MapscaleText_XMax * base.XFactor;
                double yMax = pEnv.YMin - 0.02;  //this is the min y value of the scalebar envelope - .02
                double yMin = SPrintConst.MapscaleText_YMin * base.YFactor;

                //Set pMapscaleText symbol to the textsymbol
                pTextSym  = oSpatialSubs.createTextSymbol(0, 0, 0, 7 * this.YFactor, esriTextHorizontalAlignment.esriTHALeft, esriTextVerticalAlignment.esriTVATop, "Arial");
                pTextElem = oSpatialSubs.addTextToGraphicsContainer(pGC, pTextSym, xMin, xMax, yMin, yMax, sMapScale);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Errors: CPortraitLayout:addMapScaleText()\r\n" + ex.Message, "Errors occurred", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            finally
            {
                oSpatialSubs.Dispose();
                pMxDoc    = null;
                pGC       = null;
                pMSFrame  = null;
                pEnv      = null;
                pTextSym  = null;
                pTextElem = null;
            }
        }
Esempio n. 21
0
 public void SetObjects(object object_0)
 {
     this.imapSurroundFrame_0 = object_0 as IMapSurroundFrame;
     if (this.imapSurroundFrame_0 != null)
     {
         m_pScaleBar = (this.imapSurroundFrame_0.MapSurround as IClone).Clone() as IScaleBar;
     }
 }
Esempio n. 22
0
        public void SetObjects(object object_0)
        {
            this.imapSurroundFrame_0 = object_0 as IMapSurroundFrame;
            this.ilegend_0           = this.imapSurroundFrame_0.MapSurround as ILegend;
            ILegendFormat format = this.ilegend_0.Format;

            this.itextSymbol_0 = format.TitleSymbol;
        }
Esempio n. 23
0
        public NorthArrowPropertyFr(IElement pEle)
        {
            InitializeComponent();
            m_pElement = pEle;
            IMapSurroundFrame pSurround = pEle as IMapSurroundFrame;

            m_northArrow = pSurround.MapSurround as INorthArrow;
        }
Esempio n. 24
0
        private ITextElement pTitleElement; //图例标题的字体样式;

        #endregion Fields

        #region Constructors

        public frmLegendWizard(IMap pmap,IPageLayoutControlDefault  pPageLayoutControl,IMapSurroundFrame pMapSurroundFrame)
        {
            //用于在 任意范围打印的对话框 中编辑图例
            InitializeComponent();
            mapSurroundFrame  = pMapSurroundFrame;
            m_pageLayoutControl = pPageLayoutControl;
            m_Map = pmap;
        }
Esempio n. 25
0
        public ScalePropertyFr(IElement pEle)
        {
            InitializeComponent();
            m_pElement = pEle;
            IMapSurroundFrame pSurround = m_pElement as IMapSurroundFrame;

            m_ScaleBar = pSurround.MapSurround as IScaleBar;
        }
Esempio n. 26
0
 public void SetObjects(object object_0)
 {
     this.imapSurroundFrame_0 = object_0 as IMapSurroundFrame;
     if (this.imapSurroundFrame_0 != null)
     {
         this.inorthArrow_0 = (this.imapSurroundFrame_0.MapSurround as IClone).Clone() as INorthArrow;
     }
 }
 public void SetObjects(object object_0)
 {
     this.imapSurroundFrame_0 = object_0 as IMapSurroundFrame;
     if ((this.imapSurroundFrame_0 != null) && (m_pScaleText == null))
     {
         m_pScaleText = (this.imapSurroundFrame_0.MapSurround as IClone).Clone() as IScaleText;
     }
 }
Esempio n. 28
0
 public void SetObjects(object object_0)
 {
     this.imapSurroundFrame_0 = object_0 as IMapSurroundFrame;
     if (ScaleBarFormatPropertyPage.m_pScaleBar == null)
     {
         ScaleBarFormatPropertyPage.m_pScaleBar =
             (this.imapSurroundFrame_0.MapSurround as IClone).Clone() as IScaleBar;
     }
 }
Esempio n. 29
0
 public void SetObjects(object object_0)
 {
     this.mapTemplateElement_0 = object_0 as MapTemplateElement;
     this.imapSurroundFrame_0  = this.mapTemplateElement_0.Element as IMapSurroundFrame;
     if (this.imapSurroundFrame_0 != null)
     {
         m_pScaleBar = (this.imapSurroundFrame_0.MapSurround as IClone).Clone() as IScaleBar;
     }
 }
Esempio n. 30
0
 public void SetObjects(object object_0)
 {
     this.mapTemplateElement_0 = object_0 as MapTemplateElement;
     this.imapSurroundFrame_0  = this.mapTemplateElement_0.Element as IMapSurroundFrame;
     if (this.imapSurroundFrame_0 != null)
     {
         this.inorthArrow_0 = (this.imapSurroundFrame_0.MapSurround as IClone).Clone() as INorthArrow;
     }
 }
        // 添加图例
        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);
        }
Esempio n. 32
0
        private void LegendWizard_Load(object sender, EventArgs e)
        {
            if (m_pageLayoutControl.ActiveView.FocusMap == null)
            {
                MessageBox.Show("请先添加地图");
                return;

            }
            #region //点击 添加图例按钮 或在 PageLayoutControl中双击图例时
            if (mapSurroundFrame == null)  //当点击 添加图例按钮 或在 PageLayoutControl中双击图例时 先创建图例 或从地图上获得已经添加的图例;
            {

                //Get the GraphicsContainer
                IGraphicsContainer graphicsContainer = m_pageLayoutControl.GraphicsContainer;
                graphicsContainer.Reset();
                IElementProperties pElementPerties = graphicsContainer.Next() as IElementProperties;
                //Get the MapFrame
                IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_pageLayoutControl.ActiveView.FocusMap);
                if (mapFrame == null) return;
                while (pElementPerties != null) //从地图中获得已有的图例
                {
                    if (pElementPerties.Type == "Map Surround Frame")
                    {
                        pMapSurrounFrame = pElementPerties as IMapSurroundFrame;
                        if (pMapSurrounFrame.MapSurround.Name == "Legend")
                        {
                            m_legend = pMapSurrounFrame.MapSurround as ILegend;
                            break;
                        }
                    }
                    pElementPerties = (IElementProperties)graphicsContainer.Next();
                }
                if (m_legend == null) //当地图中没有添加图例时 创建新图例
                {
                    //Create a legend
                    UID uID = new UIDClass();
                    uID.Value = "esriCarto.Legend";

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

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

                    m_legend = mapSurroundFrame.MapSurround as ILegend;
                }
                else
                {
                    mapSurroundFrame = pMapSurrounFrame;

                }

                UID m_uid = new UIDClass();
                m_uid.Value = "{34C20002-4D3C-11D0-92D8-00805F7C28B0}";
                m_mapLayers = m_mapControl.Map as IMapLayers;
                m_emuLayer = m_mapLayers.get_Layers(m_uid, true);//获取图层
                if (m_emuLayer != null)
                {
                    m_emuLayer.Reset();
                    ILayer m_layer = null;
                    while ((m_layer = m_emuLayer.Next()) != null)
                    {
                        this.listBox1.Items.Add(m_layer.Name);//将图层名添加到图例备选项中
                    }
                }
            }
               #endregion
            else //在双击任意范围打印框中图例时,获得图例,及图层信息;
            {
                if (m_Map == null)
                {
                    MessageBox.Show("请先添加地图!");
                }
                for (int k = 0; k < m_Map.LayerCount; k++)
                {
                    listBox1.Items.Add(m_Map.get_Layer(k).Name.ToString());
                }
                m_legend = mapSurroundFrame .MapSurround as ILegend;
            }
            //以下设置需要用到的变量 及初始化 对话框
            plegendFormat = m_legend.Format as ILegendFormat; //设置图例格式需要用到的

            pTextSymbol = new TextSymbolClass();
            pTextSymbol.Size = 10;
            pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; //初始化图例标签的文本格式

            if (m_legend.Title != null)
                textBox1.Text = m_legend.Title.ToString(); //初始化对话框中的文本框 文本
            else
                textBox1.Text = "Legend";

            this.textBoxWidth.Text = "36";
            this.textBoxHeight.Text = "15";
            IMapSurround mapSurround = m_legend as IMapSurround;
            mapSurroundFrame.MapSurround = mapSurround;
            m_FrameProperties = (IFrameProperties)mapSurroundFrame;
            ISymbolBackground pSymbolBack = m_FrameProperties.Background as ISymbolBackground;
            ISymbolBorder pSymbolBorder = m_FrameProperties.Border as ISymbolBorder;
            ISymbolShadow pSymbolShadow = m_FrameProperties.Shadow as ISymbolShadow;
            if (pSymbolBack !=null )
            this.btnBackGroundColor.BackColor =ColorTranslator.FromOle ( pSymbolBack.FillSymbol.Color.RGB ) ;
            if (pSymbolBorder != null)
            this.btnBolderColor.BackColor = ColorTranslator.FromOle(pSymbolBorder.LineSymbol.Color.RGB);
             if (pSymbolShadow != null)
            this.btnShadowColor.BackColor = ColorTranslator.FromOle(pSymbolShadow.FillSymbol.Color.RGB);
        }