Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        public static void changeOritation(AxPageLayoutControl axPageLayoutControl)
        {
            IPageLayout        pageLayout         = axPageLayoutControl.PageLayout;
            IActiveView        activeView         = pageLayout as IActiveView;
            IMap               pMap               = activeView.FocusMap;
            IGraphicsContainer pGraphicsContainer = pageLayout as IGraphicsContainer;
            IMapFrame          mapFrame           = (IMapFrame)pGraphicsContainer.FindFrame(pMap);
            IElement           pElement           = (IElement)mapFrame;
            IEnvelope          pEnvelope          = new EnvelopeClass();

            if (axPageLayoutControl.Page.Orientation == 2)
            {
                pEnvelope.PutCoords(0.5, 0.5, 20.5, 29.2);
                axPageLayoutControl.Page.PutCustomSize(29.7, 21);
                axPageLayoutControl.Page.Orientation = 1;
            }
            else
            {
                pEnvelope.PutCoords(0.5, 0.5, 29.2, 20.5);
                axPageLayoutControl.Page.PutCustomSize(21, 29.7);
                axPageLayoutControl.Page.Orientation = 2;
            }
            pElement.Geometry = pEnvelope;
            activeView.Refresh();
        }
Ejemplo n.º 3
0
        public static void CopyAndOverwriteMap(AxMapControl axMapControl, AxPageLayoutControl axPageLayoutControl)
        {
            IObjectCopy objectCopy   = new ObjectCopyClass();
            object      toCopyMap    = axMapControl.Map;
            object      copiedMap    = objectCopy.Copy(toCopyMap);
            IPageLayout pagelayout   = axPageLayoutControl.PageLayout;
            object      overwriteMap = (pagelayout as IActiveView).FocusMap;

            objectCopy.Overwrite(toCopyMap, ref overwriteMap);
            IGraphicsContainer pGraphicsContainer = pagelayout as IGraphicsContainer;
            IMapFrame          pMapFrame          = (IMapFrame)pGraphicsContainer.FindFrame(overwriteMap);
            IElement           pElement           = pMapFrame as IElement;
            IEnumElement       pEnumElement       = pGraphicsContainer.LocateElementsByEnvelope(pElement.Geometry.Envelope);
            IElement           pElementIcon       = pEnumElement.Next();

            while (pElementIcon != null)
            {
                if (pElementIcon is IMapSurroundFrame)
                {
                    if ((pElementIcon as IMapSurroundFrame).MapSurround is IScaleBar)
                    {
                        (pElementIcon as IMapSurroundFrame).MapFrame = pMapFrame;
                    }
                }
                pElementIcon = pEnumElement.Next();
            }
            axPageLayoutControl.ActiveView.Refresh();
        }
        public static void SaveCurrentToImage(AxPageLayoutControl axPageLayoutControl, string savePath)
        {
            tagRECT rect = new tagRECT();

            rect.left   = rect.top = 0;
            rect.right  = 1000;
            rect.bottom = 600;
            try
            {
                IActiveView pActiveView = axPageLayoutControl.ActiveView;
                Image       image       = new Bitmap(1000, 600);
                Graphics    graphics    = Graphics.FromImage(image);
                //
                graphics.FillRectangle(Brushes.White, 0, 0, 1000, 600);
                int dpi = (int)(1000 / 500);
                //保存范围
                IGraphicsContainer pGraphicsContainer = axPageLayoutControl.GraphicsContainer;
                IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame;


                IEnvelope pMapExt = pActiveView.Extent;

                IEnvelope pEnvelope = new EnvelopeClass();
                pEnvelope.PutCoords(pMapExt.XMin - 2, pMapExt.YMin - 2, pMapExt.XMax + 1, pMapExt.YMax + 1);
                pActiveView.Output(graphics.GetHdc().ToInt32(), dpi, ref rect, pEnvelope, null);
                graphics.ReleaseHdc();
                //保存影像
                image.Save(savePath);
            }
            catch (Exception e)
            {
                MessageBox.Show("保存失败:" + e.ToString());
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public void AddMapGrid()
        {
            m_styleSelector = new MapGridSelectorClass();             //Create a style selector and grab holf of the IMapGridSelector interface

            m_Ok = m_styleSelector.DoModal(m_pagelayoutControl.hWnd); //Display the style selector to the user

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

            if (mapFrame == null)
            {
                return;
            }

            if (m_Ok == true)
            {
                IMapGrid m_mapGrid;
                m_mapGrid = (IMapGrid )m_styleSelector.GetStyle(0);//获得所选的MapGrid的类型;

                IMapGrids m_mapGrids = mapFrame as IMapGrids;

                m_mapGrids.ClearMapGrids();//删除原有的地图格网

                if (m_mapGrid != null)
                {
                    m_mapGrids.AddMapGrid(m_mapGrid);                                                          //添加地图格网到地图上
                }
                m_pagelayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //刷新
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 添加指北针
        /// </summary>
        /// <param name="layoutControl">布局视图</param>
        /// <param name="pEnv">矩形框</param>
        /// <param name="pStyleGalleryItem">指北针样式</param>
        public static void AddNorthArrow(AxPageLayoutControl layoutControl, IEnvelope pEnv, IStyleGalleryItem pStyleGalleryItem)
        {
            if (pStyleGalleryItem == null)
            {
                return;
            }
            IGraphicsContainer pGraphicsContainer = layoutControl.PageLayout as IGraphicsContainer;

            if (pGraphicsContainer == null)
            {
                return;
            }
            IMap              pMap              = layoutControl.ActiveView.FocusMap;
            IMapFrame         pMapFrame         = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pMapSurroundFrame.MapFrame = pMapFrame;
            //删除已经存在的指北针
            MappingHelper.DeleteElementByName(layoutControl, "North Arrow");
            INorthArrow pNorthArrow = pStyleGalleryItem.Item as INorthArrow;

            if (pNorthArrow != null)
            {
                pNorthArrow.Size = pEnv.Width * 50;
                pMapSurroundFrame.MapSurround = pNorthArrow;//根据用户的选取,获取相应的MapSurround
            }
            IElement pElement = (IElement)pMapSurroundFrame;

            pElement.Geometry = pEnv;
            //添加元素
            MappingHelper.AddElementWithName(pGraphicsContainer, pElement, "North Arrow");
        }
Ejemplo n.º 8
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);
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            IActiveView pActiveView = (IActiveView)m_PageLayOutControl.PageLayout;

            IMap pMap = pActiveView.FocusMap;

            IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)pActiveView;

            IMapFrame pMapFrame = (IMapFrame)pGraphicsContainer.FindFrame(pMap);

            IStyleSelector pStyleSelector = new BackgroundSelectorClass();

            bool m_bOK = pStyleSelector.DoModal(m_PageLayOutControl.hWnd);

            if (!m_bOK)
            {
                return;
            }

            IBackground pBackground = (IBackground)pStyleSelector.GetStyle(0);

            pMapFrame.Background = pBackground;

            m_PageLayOutControl.Refresh(esriViewDrawPhase.esriViewBackground, null, null);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 添加比例尺
        /// </summary>
        /// <param name="layoutControl">布局视图</param>
        /// <param name="pEnv">矩形框</param>
        /// <param name="scaleBar">比例尺</param>
        public static void AddScaleBar(AxPageLayoutControl layoutControl, IEnvelope pEnv, IScaleBar2 scaleBar)
        {
            if (scaleBar == null)
            {
                return;
            }
            IGraphicsContainer pGraphicsContainer = layoutControl.PageLayout as IGraphicsContainer;

            if (pGraphicsContainer == null)
            {
                return;
            }
            IMap              pMap              = layoutControl.ActiveView.FocusMap;
            IMapFrame         pMapFrame         = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pMapSurroundFrame.MapFrame = pMapFrame;
            scaleBar.BarHeight         = pEnv.Height * 10;
            //删除已经存在的比例尺
            MappingHelper.DeleteElementByName(layoutControl, "Scale Line");
            pMapSurroundFrame.MapSurround = scaleBar as IMapSurround;
            IElement pElement = (IElement)pMapSurroundFrame;

            pElement.Geometry = pEnv;
            //添加元素
            MappingHelper.AddElementWithName(pGraphicsContainer, pElement, "Scale Line");
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 添加默认比例尺
        /// </summary>
        /// <param name="layoutControl">布局视图</param>
        /// <param name="pEnv">矩形框</param>
        /// <param name="pStyleGalleryItem">比例尺样式</param>
        public static void AddDefaultScaleBar(AxPageLayoutControl layoutControl, IEnvelope pEnv, IStyleGalleryItem pStyleGalleryItem)
        {
            if (pStyleGalleryItem == null)
            {
                return;
            }
            IGraphicsContainer pGraphicsContainer = layoutControl.PageLayout as IGraphicsContainer;

            if (pGraphicsContainer == null)
            {
                return;
            }
            IMap              pMap              = layoutControl.ActiveView.FocusMap;
            IMapFrame         pMapFrame         = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pMapSurroundFrame.MapFrame = pMapFrame;
            //删除已经存在的比例尺
            MappingHelper.DeleteElementByName(layoutControl, "Scale Line");
            IScaleBar2 scaleBar2 = pStyleGalleryItem.Item as IScaleBar2;

            if (scaleBar2 != null)
            {
                scaleBar2.BarHeight           = pEnv.Height * 20;
                scaleBar2.Divisions           = 1;
                scaleBar2.Subdivisions        = 2;
                pMapSurroundFrame.MapSurround = scaleBar2 as IMapSurround;
            }
            IElement pElement = (IElement)pMapSurroundFrame;

            pElement.Geometry = pEnv;
            //添加元素
            MappingHelper.AddElementWithName(pGraphicsContainer, pElement, "Scale Line");
        }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
0
        private void method_5(IActiveView iactiveView_0)
        {
            IGraphicsContainer graphicsContainer = iactiveView_0.GraphicsContainer;
            IMapFrame          frame             = graphicsContainer.FindFrame(iactiveView_0.FocusMap) as IMapFrame;

            graphicsContainer.Reset();
            IElement        item = graphicsContainer.Next();
            List <IElement> list = new List <IElement>();

            while (item != null)
            {
                if (item != frame)
                {
                    list.Add(item);
                }
                item = graphicsContainer.Next();
            }
            for (int i = 0; i < list.Count; i++)
            {
                try
                {
                    graphicsContainer.DeleteElement(list[i]);
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 14
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);
            }
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        private void ClearElements(IActiveView pActiveView)
        {
            IGraphicsContainer graphicsContainer = pActiveView.GraphicsContainer;
            IMapFrame          mapFrame          = graphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame;

            (mapFrame as IMapGrids).ClearMapGrids();
            graphicsContainer.Reset();
            IElement        element = graphicsContainer.Next();
            List <IElement> list    = new List <IElement>();

            while (element != null)
            {
                if (element != mapFrame)
                {
                    list.Add(element);
                }
                element = graphicsContainer.Next();
            }
            try
            {
                graphicsContainer.DeleteAllElements();
                graphicsContainer.Reset();
                element = graphicsContainer.Next();
                if (element != null)
                {
                    graphicsContainer.DeleteElement(element);
                }
                graphicsContainer.AddElement(mapFrame as IElement, -1);
                pActiveView.FocusMap = mapFrame.Map;
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 17
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();
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
        void addNorthArrow(IPageLayout pPageLayout, IEnvelope pEnv, IActiveView pActiveView)
        {
            IMap pMap = pActiveView.FocusMap;
            IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(pMap) as IMapFrame;

            if (pStyleGalleryItem == null)
            {
                return;
            }
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pMapSurroundFrame.MapFrame = pMapFrame;
            INorthArrow pNorthArrow = new MarkerNorthArrowClass();

            pNorthArrow      = pStyleGalleryItem.Item as INorthArrow;
            pNorthArrow.Size = pEnv.Width * 50;
            pMapSurroundFrame.MapSurround = (IMapSurround)pNorthArrow;                 //根据用户的选取,获取相应的MapSurround
            IElement pElement = axPageLayoutControl1.FindElementByName("NorthArrows"); //获取PageLayout中的指北针元素

            if (pElement != null)
            {
                pGraphicsContainer.DeleteElement(pElement);  //如果存在指北针,删除已经存在的指北针
            }
            IElementProperties pElePro = null;

            pElement          = (IElement)pMapSurroundFrame;
            pElement.Geometry = (IGeometry)pEnv;
            pElePro           = pElement as IElementProperties;
            pElePro.Name      = "NorthArrows";
            pGraphicsContainer.AddElement(pElement, 0);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Ejemplo n.º 20
0
        public void makeScaleBar(IActiveView pActiveView, IPageLayout pPageLayout, IEnvelope pEnv)
        {
            IMap pMap = pActiveView.FocusMap;
            IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(pMap) as IMapFrame;

            if (pStyleGalleryItem == null)
            {
                return;
            }
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pMapSurroundFrame.MapFrame    = pMapFrame;
            pMapSurroundFrame.MapSurround = (IMapSurround)pStyleGalleryItem.Item;
            IElement pElement = axPageLayoutControl1.FindElementByName("ScaleBar");

            if (pElement != null)
            {
                pGraphicsContainer.DeleteElement(pElement);  //删除已经存在的比例尺
            }
            IElementProperties pElePro = null;

            pElement          = (IElement)pMapSurroundFrame;
            pElement.Geometry = (IGeometry)pEnv;
            pElePro           = pElement as IElementProperties;
            pElePro.Name      = "ScaleBar";
            pGraphicsContainer.AddElement(pElement, 0);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 获得图饰位置
        /// </summary>
        void GetSurroundPose()
        {
            m_mapSurroundList = new List <MapSurroundEntity>();
            IGraphicsContainer graphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer;
            IEnvelope          mapEnvelop        = (graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IElement).Geometry.Envelope;

            graphicsContainer.Reset();
            IElement element = graphicsContainer.Next();

            while (element != null)
            {
                if (element is IMapFrame)
                {
                    element = graphicsContainer.Next();
                    continue;
                }
                else
                {
                    IEnvelope         envelop           = element.Geometry.Envelope as IEnvelope;
                    MapSurroundEntity mapSurroundEntity = new MapSurroundEntity();
                    mapSurroundEntity.left    = envelop.XMin - mapEnvelop.XMin;
                    mapSurroundEntity.right   = mapEnvelop.XMax - envelop.XMax;
                    mapSurroundEntity.top     = mapEnvelop.YMax - envelop.YMax;
                    mapSurroundEntity.bottom  = envelop.YMin - mapEnvelop.YMin;
                    mapSurroundEntity.width   = envelop.Width;
                    mapSurroundEntity.height  = envelop.Height;
                    mapSurroundEntity.element = element;
                    m_mapSurroundList.Add(mapSurroundEntity);
                }
                element = graphicsContainer.Next();
            }
        }
Ejemplo n.º 22
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;
            }
        }
Ejemplo n.º 23
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);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 更新图饰位置
        /// </summary>
        private void UpdataSurroundPose()
        {
            if (m_mapSurroundList == null && m_mapSurroundList.Count < 1)
            {
                return;
            }

            IGraphicsContainer graphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer;
            IEnvelope          mapEnvelop        = (graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IElement).Geometry.Envelope;
            MapSurroundEntity  mapSurroundEntity;
            bool isUpdate = false;

            for (int i = 0; i < m_mapSurroundList.Count; i++)
            {
                mapSurroundEntity = m_mapSurroundList[i];
                IEnvelope elementEnv = mapSurroundEntity.element.Geometry.Envelope;
                isUpdate = false;
                if (mapSurroundEntity.element is IMapSurroundFrame)
                {
                    isUpdate = UpdateMapSurroundFrame(mapEnvelop, mapSurroundEntity);
                }
                else if (mapSurroundEntity.element is ITextElement)
                {
                    isUpdate = UpdateTextElement(mapEnvelop, mapSurroundEntity);
                }

                if (isUpdate)
                {
                    graphicsContainer.UpdateElement(mapSurroundEntity.element);
                }
            }
        }
Ejemplo n.º 25
0
        public void add_grid()
        {
            activeView = pageLayoutControl.PageLayout as IActiveView;
            map        = activeView.FocusMap;

            IMapGrid      mapGrid;
            IMeasuredGrid measuredGrid;

            measuredGrid               = new MeasuredGrid() as IMeasuredGrid;
            mapGrid                    = measuredGrid as IMapGrid;
            measuredGrid.FixedOrigin   = true;
            measuredGrid.Units         = map.MapUnits;
            measuredGrid.XIntervalSize = 10;
            measuredGrid.YIntervalSize = 10;
            measuredGrid.XOrigin       = -180;
            measuredGrid.YOrigin       = -90;

            IProjectedGrid projectedGrid;

            projectedGrid = measuredGrid as IProjectedGrid;
            projectedGrid.SpatialReference = map.SpatialReference;
            mapGrid.Name = "Measured Grid";
            IMapFrame          mapFrame;
            IGraphicsContainer graphicsContainer;

            graphicsContainer = activeView as IGraphicsContainer;
            mapFrame          = graphicsContainer.FindFrame(map) as IMapFrame;
            IMapGrids mapGrids = mapFrame as IMapGrids;

            mapGrids.AddMapGrid(mapGrid);
            activeView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 添加图例
        /// </summary>
        /// <param name="layoutControl">布局视图</param>
        /// <param name="pEnv">矩形框</param>
        /// <param name="pLegend">图例</param>
        public static void AddLegend(AxPageLayoutControl layoutControl, IEnvelope pEnv, ILegend2 pLegend)
        {
            if (pLegend == null)
            {
                return;
            }
            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;
            }
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pMapSurroundFrame.MapFrame = pMapFrame;
            //如果已经存在图例,删除已经存在的图例
            MappingHelper.DeleteElementByName(layoutControl, "Legend");
            pMapSurroundFrame.MapSurround = pLegend as IMapSurround;
            //添加图例
            IElement pElement = pMapSurroundFrame as IElement;

            pElement.Geometry = pEnv;
            //添加元素
            MappingHelper.AddElementWithName(pGraphicsContainer, pElement, "Legend");
        }
Ejemplo n.º 27
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);
            }
        }
Ejemplo n.º 28
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);
        }
Ejemplo n.º 29
0
        public void fGetElements(double mapX, double mapY, ref IElement pElement)
        {
            IGraphicsContainerSelect m_graphicsContainerSelect;
            IGraphicsContainer       m_graphicsContainer = m_pagelayoutControl.ActiveView as IGraphicsContainer;
            int       i, m_selectCount;
            IElement  m_element, m_selectElement = null;
            IGeometry m_geometry;
            IMapFrame m_mapFrame;
            bool      ifElementHited;



            IPoint m_point = new ESRI.ArcGIS.Geometry.Point();

            m_point.X = mapX;
            m_point.Y = mapY;

            m_mapFrame = m_graphicsContainer.FindFrame(m_pagelayoutControl.ActiveView.FocusMap) as IMapFrame;

            IFrameElement pFramElement = m_mapFrame as IFrameElement;

            ///////////////////////////////////////////////////////////////////////////////////////

            m_graphicsContainerSelect = m_pagelayoutControl.PageLayout as IGraphicsContainerSelect;
            m_selectCount             = m_graphicsContainerSelect.ElementSelectionCount;//m_graphicsContainerSelect 中有的可供选择的元素
            if (m_selectCount == 0)
            {
                m_elementToMove = null;
                if (pFramElement != null)
                {
                    pElement = pFramElement as IElement;
                }
            }
            else
            {
                for (i = 0; i < m_selectCount; i++)
                {
                    m_element  = m_graphicsContainerSelect.SelectedElement(i);
                    m_geometry = m_element.Geometry;
                    m_graphicsContainer.LocateElementsByEnvelope(m_geometry.Envelope); //定位第i个元素所在的位置
                    ifElementHited = m_element.HitTest(mapX, mapY, 0.1);               //判断鼠标点击位置是否与元素位置相同
                    if (ifElementHited)
                    {
                        m_graphicsContainerSelect.SelectElement(m_element);    //选中元素,一遍对其进行移动
                        m_selectElement = m_element;
                    }
                }
                if (m_selectElement == null)    //当鼠标没有选择graphicsContainerSelect中的元素时
                {
                    m_elementToMove = pFramElement as IElement;
                    pElement        = pFramElement as IElement;//鼠标选择地图数据框
                }
                else
                {
                    pElement        = m_selectElement;
                    m_elementToMove = m_selectElement;    //是则可以移动该元素并选择元素
                }
            }
        }
Ejemplo n.º 30
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);
        }