• ArcEngine IPageLayout 添加经纬网和公里网


    http://www.gisall.com/html/52/25952-2932.html

    向AxPageLayoutControl的PageLayout中添加格网分为两种情况: 添加经纬网   和   添加公里网。

             ///

            /// 为PageLayout对象添加经纬网格

            ///

            ///

            /// 

            public  void CreateGraticuleMapGrid(IPageLayout pPageLayout)

            {

                //获取MapFrame对象

                IActiveView pActiveView = pPageLayout as IActiveView;

                IMap pMap = pActiveView.FocusMap;

                IGraphicsContainer pGraphicsContainer = pActiveView as IGraphicsContainer;

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

                IMapGrids pMapGrids = pMapFrame. as IMapGrids;      

                //创建网格对象

     

     

             

                //设置网格线的符号样式

                ICartographicLineSymbol pLineSymbol;

                pLineSymbol = new CartographicLineSymbolClass();           

                pLineSymbol.Cap = esriLineCapStyle.esriLCSButt;

                pLineSymbol.Width = 1;  

                IRgbColor rgbColor = new RgbColor();

                rgbColor.Red = 166;

                rgbColor.Green = 187;

                rgbColor.Blue = 208;

                IColor color = rgbColor as IColor;

                pLineSymbol.Color = color;

                pMapGrid.LineSymbol = pLineSymbol;

                //设置网格的边框样式,为简单边框样式            

                ISimpleMapGridBorder simpleMapGridBorder = new SimpleMapGridBorderClass();           

                ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();

                simpleLineSymbol.Style. = esriSimpleLineStyle.esriSLSSolid;

                simpleLineSymbol.Color = BuildRGB(0, 0, 0);

                simpleLineSymbol.Width = 2;

                simpleMapGridBorder.LineSymbol = simpleLineSymbol as ILineSymbol;          

                pMapGrid.Border = simpleMapGridBorder as IMapGridBorder ;

                pMapGrid.SetTickVisibility(true, true, true, true);

               

                //设置网格的主刻度的样式和可见性

                pMapGrid.TickLength = 15;

                pLineSymbol = new CartographicLineSymbolClass();          

                pLineSymbol.Cap = esriLineCapStyle.esriLCSButt;

                pLineSymbol.Width = 1;

                pLineSymbol.Color = color;

                pMapGrid.TickMarkSymbol = null;  

                pMapGrid.TickLineSymbol = pLineSymbol;

                pMapGrid.SetTickVisibility(true, true, true, true);

                //设置网格的次一级刻度的样式和可见性

                pMapGrid.SubTickCount = 5;

                pMapGrid.SubTickLength = 10;

                pLineSymbol = new CartographicLineSymbolClass();          

                pLineSymbol.Cap = esriLineCapStyle.esriLCSButt;

                pLineSymbol.Width = 0.1;

                pLineSymbol.Color = color;

                pMapGrid.SubTickLineSymbol = pLineSymbol;        

                pMapGrid.SetSubTickVisibility(true, true, true, true);

             

                //设置网格的标签的样式和可见性

                IGridLabel pGridLabel;

                pGridLabel = pMapGrid.LabelFormat;

                pGridLabel.LabelOffset = 15;

               

                stdole.StdFont pFont = new stdole.StdFont();

     

                pFont.Size = 16;

               pMapGrid.LabelFormat.Font = pFont as stdole.IFontDisp;

     

                 //设置网格的可见性

                pMapGrid.Visible = true;

                //创建IMeasuredGrid对象

                IMeasuredGrid pMeasuredGrid;

                pMeasuredGrid = pMapGrid as IMeasuredGrid;

                pMeasuredGrid.FixedOrigin = true;

                pMeasuredGrid.XIntervalSize = 0.5; //meridian interval

                pMeasuredGrid.XOrigin = 109; //shift grid 5

                pMeasuredGrid.YIntervalSize = 0.5; //parallel interval

                pMeasuredGrid.YOrigin = 40; //shift grid 5 

               

                //将网格对象添加到地图控件中     

                pMapGrids.AddMapGrid(pMapGrid);

                //刷新地图

                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);

            }

        public void CreateMeasuredGrid(IPageLayout pPageLayout)

            {

                try

                {

                    //获取MapFrame对象

                    IActiveView pActiveView = pPageLayout as IActiveView;

                    IMap pMap = pActiveView.FocusMap;

                    IGraphicsContainer pGraphicsContainer = pActiveView as IGraphicsContainer;

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

                    IMapGrids pMapGrids = pMapFrame. as IMapGrids; 

                    //创建MeasuredGrid对象             

                    IMeasuredGrid pMeasuredGrid = new MeasuredGrid() as IMeasuredGrid;

                    //设置pMeasuredGrid的投影属性

                    IProjectedGrid pProjectedGrid = (IProjectedGrid)pMeasuredGrid;

                    pProjectedGrid.SpatialReference = Map.SpatialReference;

                    double MaxX,MaxY,MinX,MinY;//动态获取坐标系中的坐标范围,以便设置网格的起始点和间隔

                    pProjectedGrid.SpatialReference.GetDomain(out MinX, out MaxX , out MinY , out MaxY );

                    pMeasuredGrid.FixedOrigin = true;

                    pMeasuredGrid.Units = Map.MapUnits;

                    pMeasuredGrid.XIntervalSize = (MaxX-MinX)/20;

                    pMeasuredGrid.XOrigin = MinX;

                    pMeasuredGrid.YIntervalSize = (MaxY - MinY)/20 ;

                    pMeasuredGrid.YOrigin = MinY;

                    //将pMeasuredGrid赋值个IMapGrid对象

                    IMapGrid pMapGrid = (IMapGrid)pMeasuredGrid;

     

                    //设置网格线的符号样式

                    ICartographicLineSymbol pLineSymbol;

                    pLineSymbol = new CartographicLineSymbolClass();

                    pLineSymbol.Cap = esriLineCapStyle.esriLCSButt;

                    pLineSymbol.Width = 1;

                    IRgbColor rgbColor = new RgbColor();

                    rgbColor.Red = 166;

                    rgbColor.Green = 187;

                    rgbColor.Blue = 208;

                    IColor color = rgbColor as IColor;

                    pLineSymbol.Color = color;

                    pMapGrid.LineSymbol = pLineSymbol;

                    //设置ICalibratedMapGridBorder的属性

                    ICalibratedMapGridBorder pCalibratedBorder = (ICalibratedMapGridBorder)new CalibratedMapGridBorder();

                    IRgbColor gCol = new RgbColor();

                    gCol.Red = 255;

                    gCol.Blue = 255;

                    gCol.Green = 255;

                    pCalibratedBorder.BackgroundColor = gCol;

                    IRgbColor ForeColor = new RgbColor();

                    ForeColor.Red = 0;

                    ForeColor.Blue = 0;

                    ForeColor.Green = 0;

                    pCalibratedBorder.ForegroundColor = ForeColor;

                    pCalibratedBorder.BorderWidth = 2;

                    pCalibratedBorder.Interval = 50;

                    pCalibratedBorder.Alternating = true;

                    pMapGrid.Border = (IMapGridBorder)pCalibratedBorder;

                    //设置网格的主刻度的样式和可见性

                    pMapGrid.TickLength = 15;

                    pLineSymbol = new CartographicLineSymbolClass();

                    pLineSymbol.Cap = esriLineCapStyle.esriLCSButt;

                    pLineSymbol.Width = 1;

                    pLineSymbol.Color = color;

                    pMapGrid.TickMarkSymbol = null;

                    pMapGrid.TickLineSymbol = pLineSymbol;

                    pMapGrid.SetTickVisibility(true, true, true, true);

                    //设置网格的次一级刻度的样式和可见性

                    pMapGrid.SubTickCount = 5;

                    pMapGrid.SubTickLength = 10;

                    pLineSymbol = new CartographicLineSymbolClass();

                    pLineSymbol.Cap = esriLineCapStyle.esriLCSButt;

                    pLineSymbol.Width = 0.1;

                    pLineSymbol.Color = color;

                    pMapGrid.SubTickLineSymbol = pLineSymbol;

                    pMapGrid.SetSubTickVisibility(true, true, true, true);

                    //标签格式设置IGridLabel

                    IGridLabel pGridLabel;

                    pGridLabel = pMapGrid.LabelFormat;

                    pGridLabel.LabelOffset = 15;

                    stdole.StdFont pFont = new stdole.StdFont();

     

                    pFont.Size = 16;

                    pMapGrid.LabelFormat.Font = pFont as stdole.IFontDisp;

          

                    //设置网格的可见性

                    pMapGrid.Visible = true;

                    //添加网格对象到地图控件中       

                    pMapGrids.AddMapGrid(pMapGrid);

                    //刷新地图

                    pActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);

                }

                catch (Exception EX)

                {

                    throw EX;

                }

     

            }

  • 相关阅读:
    Spring ApplicationContext 是如何被注入的
    Spring @Controller和@RestController的区别?
    怎样查看 spring IoC 容器有哪些 bean
    YYKit持续补丁 brave
    iOS如何实现多代理模式OC brave
    iOS 之获取IP地址 以及 判断个人热点是否开启 brave
    CGContext 和 CIContext brave
    android 调用微信QQ的其他应用打开列表中添加自己的应用,并且获取uri brave
    CGContext图形上下文详解 brave
    iOS scrollView如何居中缩放 brave
  • 原文地址:https://www.cnblogs.com/gisoracle/p/15640900.html
Copyright © 2020-2023  润新知