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等数字网格

转载于:https://www.cnblogs.com/ganb/archive/2012/09/14/ae_mapgrid.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值