• AE中pagelayout里绘制经纬网


    来自:http://hi.baidu.com/chaisy/blog/item/ad639b584fafbed79c8204b9.html
    AE中pagelayout里绘制经纬网

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    using ESRI.ArcGIS.Carto;
    using ESRI.ArcGIS.Controls;
    using ESRI.ArcGIS.Display;
    using ESRI.ArcGIS.Geometry;
    using ESRI.ArcGIS.ADF.BaseClasses;
    using ESRI.ArcGIS.ADF.CATIDs;
    using ESRI.ArcGIS.esriSystem;
    using System.Runtime.InteropServices;
    using System.Drawing;
    
    namespace TMM.MapSurrounds
    {
    /// <summary>
    /// 向Pagelayout上添加格网
    /// </summary>
    public class AddGrid : BaseCommand
    {
    
           /// <summary>
           ///   操作的对象
           /// </summary>
           private IPageLayoutControl3 _pageLayout;
    
    
           /// <summary>
           /// 构造函数 添加格网
           /// </summary>
           public AddGrid()
           {
             //设置一些属性
             base.m_caption = "添加格网";
             base.m_toolTip = "添加格网";
           }
    
    
           /// <summary>
           /// 创建
           /// </summary>
           /// <param name="hook">钩子</param>
           public override void OnCreate(object hook)
           {
             IToolbarControl2 myToolBar = (IToolbarControl2)hook;
             this._pageLayout = (IPageLayoutControl3)myToolBar.Buddy;
           }
    
    
           /// <summary>
           /// 鼠标点击按钮
           /// </summary>
           public override void OnClick()
           {
             this._pageLayout.MousePointer = esriControlsMousePointer.esriPointerHourglass;
    
             //创建一个经纬格网 并设置其相关属性
             IMapGrid myMapGrid;
             IMeasuredGrid myMeasuredGrid = new MeasuredGridClass();
             myMeasuredGrid.FixedOrigin = true;
             myMeasuredGrid.Units = this._pageLayout.ActiveView.FocusMap.MapUnits;
             myMeasuredGrid.XIntervalSize = 100;
             myMeasuredGrid.XOrigin = -300;
             myMeasuredGrid.YIntervalSize = 100;
             myMeasuredGrid.YOrigin = -300;
             myMapGrid = (IMapGrid)myMeasuredGrid;
    
             //设置投影属性
             IProjectedGrid myProjectedGrid = (IProjectedGrid)myMeasuredGrid;
             myProjectedGrid.SpatialReference = this._pageLayout.ActiveView.FocusMap.SpatialReference;
             myMapGrid.Name = "经纬格网";
    
    
             //创建边线并设置其属性
             ICalibratedMapGridBorder myMapGridBorder = new CalibratedMapGridBorderClass();
             IColor myColor=new RgbColorClass ();
             myColor.RGB = Convert.ToInt32(16711680);
             myMapGridBorder.BackgroundColor = myColor;
             myColor = new RgbColorClass();
             myColor.RGB = Convert.ToInt32(16711680);
             myMapGridBorder.ForegroundColor = myColor;
             myMapGridBorder.BorderWidth = 3;
             myMapGridBorder.Interval = 72;
             myMapGridBorder.Alternating = true;
             myMapGrid.Border =(IMapGridBorder) myMapGridBorder;
    
             //创建标签,并设置其属性
             IFormattedGridLabel myMapFormattedGridLabel = new FormattedGridLabelClass();
             IGridLabel myGridLabel = (IGridLabel)myMapFormattedGridLabel;
             stdole.StdFont myFont = new stdole.StdFontClass();
             myFont.Name = "Arial";
             myFont.Size = 16;
             myGridLabel.Font = (stdole .IFontDisp)myFont;
             myColor = new RgbColorClass();
             myColor.RGB = Convert.ToInt32(16711680);
             myGridLabel.LabelOffset = 2;
             myGridLabel.set_LabelAlignment(esriGridAxisEnum.esriGridAxisLeft, false);
             myGridLabel.set_LabelAlignment(esriGridAxisEnum.esriGridAxisRight, false);
    
             INumericFormat myNumericFormat = new NumericFormatClass();
             myNumericFormat.AlignmentOption = esriNumericAlignmentEnum.esriAlignRight;
             myNumericFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals;
             myNumericFormat.RoundingValue = 2;
             myNumericFormat.ShowPlusSign = false;
             myNumericFormat.UseSeparator = true;
             myMapFormattedGridLabel.Format =(INumberFormat) myNumericFormat;
    
             myMapGrid.LabelFormat = myGridLabel;
    
             //添加mapGrid到版式视图
             IMapGrids myMapGrids = (IMapGrids)this._pageLayout.ActiveView.GraphicsContainer.FindFrame(this._pageLayout.ActiveView.FocusMap);
    
             myMapGrids.AddMapGrid(myMapGrid);
    
             this._pageLayout.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
    
             this._pageLayout.MousePointer = esriControlsMousePointer.esriPointerArrow;
    
           }
    
    
    
       }
    }
    
    

     
    这是做一个命令按钮   在ToolBarControl加上就行
    其实得到的结果是一个 数字为100等数字网格

  • 相关阅读:
    格式布局
    tp框架之文件上传
    tp框架之验证码
    tp框架之自动验证表单
    tp框架之留言板练习
    tp框架之session
    tp框架之登录验证
    tp框架之函数调用
    tp框架之分页与第三方类的应用
    tp框架之AJAX
  • 原文地址:https://www.cnblogs.com/ganb/p/ae_mapgrid.html
Copyright © 2020-2023  润新知