• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
bobird的学习笔记
博客园    首页    新随笔    联系   管理    订阅  订阅
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等数字网格 

 

posted on 2013-07-08 11:23  bobird  阅读(283)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3