ArcEngine 9.3 学习笔记(五):地图和地图布局(PageLayout对象,Page对象,SnapGrid对象,SnapGuides对象,Element 对象,MapGrid 对象...

3.2 地图布局

3.2.1 PageLayout对象

  PageLayout用于显示地图数据,并通过对地图数据进行整饰以便对地图打印输出满足不同行业对GIS出图功能的需求。
  PageLayout和Map这两个对象看起来非常相似,他们都是视图对象,可以显示地图;也都是图形元素的容器,可以容纳图形元素(Graphics Element)
  区别:PageLayout除了保存图形元素外,还可以保存诸如MapFrame的框架元素(Frame Element)。
  PageLayout控件上的Map对象被PageLayout的MapFrame对象所管理

  PageLayout 类主要实现了IPageLayout接口,它定义了用于修改页面板式(layout)的方法和属性
  IPageLayout的ZoomToWhole方法可以让PageLayout以最大尺寸显示;
  IPageLayout 的ZoomToPercent方法可以按照输入的比例显示;
  IPageLayout的ZoomToWidth方法可以让视图显示的范围匹配控件对象的宽度
  IPageLayout的Page属性用以获取Page对象
  IPageLayout的RulerSettings属性用以获取RulerSettings对象
  IPageLayout的HorizontalSnapGuides和VerticalSnapGuides属性可以获取SnapGuides对象

3.2.2 Page对象
  主要用来管理PageLayout对象中的页面,它用来加载地理数据,但不提供分析和查询功能。
  Page类的主要接口是IPage,它除了用于管理Page的颜色、尺寸和方向,还可以管理边框类型和打印区域。FromID可以设置纸张大小类型

3.2.3 SnapGrid对象
  是PageLayout上用于摆放元素而设置的辅助点。

  以下代码片段演示 如何 设置PageLayout控件上的ISnapGrid

View Code

3.2.4 SnapGuides对象

  SnapGuides对象,是为了更好的放置地图,而在PageLayout上设置的辅助线;同样分为 水平和垂直两种。

  ISnapGuides 的AreVisible设定SnapGuides是否可见。

  ISnapGuides 的GuideCount属性返回一个SnapGuides对象中的Guide的个数。

  而使用ISnapGuides的Guide属性可以按索引值获得某个具体的Guide对象。

  ISnapGuides的AdGuide方法将一个Guide放在指定位置上。

  ISnapGuides的RemoveAllGuides和RemoveGuide方法分别可以清除所有的Guide和按索引值清除Guide。

  以下代码片段演示如何为PageLayout对象添加辅助线:

View Code

 3.2.5 RulerSettings 对象

  标尺对象,它是为了辅助图形元素的放置位置而出现在Pagelayout对象上方和左方的辅助尺;通过IPageLayout的RulerSetting属性可以获得PageLayout上的RulerSetting对象;IRulerSetting接口的SmallestDivision属性用于设置标尺对象的最小刻度值属性。

3.2.6 Element 对象

  在Map对象和Pagelayout对象显示的数据,除了地理数据外,还有 元素数据Element
  Element 是一个非常庞大复杂的对象集合:a 图形元素(GraphicElement)和框架元素(FrameElement)
  图形元素包括:LineElement,MarkerElement,TextElemet,GroupElement,FillshapElement,PictureElement,MultiPatchElement等
  这些元素都是以图形的形式存在,在地图视图或者PageLayout视图上是可见的。
  框架元素包括:MapFrameElement(地图框架元素),MapSurroundElement(地图环绕元素) 等,它们是作为不可见的容器存在的

  Map对象或者Pagelayout对象可以通过IGraphicsContainer 接口来管理这些元素,
  使用IGraphicsContainer接口可以添加、删除和更新位于Map或Pagelayout上的元素
  使用GroupElement对象还可以将多个元素编组为单个实体来给用户使用

  IElement是所有图形元素和框架元素都实现的接口,通过IElement接口可以确定Element对象的Geometry属性;
  同时IElement接口也提供了用于查找和绘制元素的方法。
  注意:IElement 与 ILineElement 以及 ITextElement等 不是父子关系,后者没有Geometry属性

3.2.7 MapGrid 对象

  它是布局视图中的一系列参考线和参考点,用来帮助地图使用者快速的确定地图要素的位置。
  公里格网,MapGridBorder,MapGridLabel,MapGrid等
  MapGrid由MapGrids来管理,一个 MapGrids可以包含多个MapGrid

  MapGrid是一个抽象类,它的子类有MeasuredGrid,IndexGrid,MgrsGrid,Graticule和CustomOverlayGrid五种;

  这些子类的对象由MapGridFactory对象创建。

 1         /// <summary>
 2         /// 为Pagelayout对象添加格网对象
 3         /// </summary>
 4         /// <param name="pPageLayout"></param>
 5         public void AddMeasuredGridToPageLayout(IPageLayout pPageLayout)
 6         {
 7             try
 8             {
 9                 // 获取MapFrame对象
10                 IActiveView pActiveView = pPageLayout as IActiveView;
11                 IMap pMap = pActiveView.FocusMap;
12                 // QI为IGraphicsContainer对象,来管理Pagelayout上的元素
13                 IGraphicsContainer pGraphicsContainer = pActiveView as IGraphicsContainer;
14                 // 从IGraphicsContainer对象中找到指定地图的框架元素
15                 IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
16                 // 将框架元素QI为IMapGrids
17                 IMapGrids pMapGrids = pMapFrame as IMapGrids;
18 
19                 // 自此,我们得到了Pagelayout对象的 参考(参考线和参考点),接下来就开始整它
20 
21                 // 创建一个MeasureGrid对象
22                 IMeasuredGrid pMeasureGrid = new MeasuredGridClass();
23                 IMapGrid pMapGrid = pMeasureGrid as IMapGrid;
24                 pMeasureGrid.FixedOrigin = true;// 固定源
25                 pMeasureGrid.Units = pMap.MapUnits;// 设置测量格网的单位为地图的单位
26                 // 设置间隔尺寸
27                 pMeasureGrid.XIntervalSize = 100;
28                 pMeasureGrid.YIntervalSize = 100;
29                 // 设置原点位置?
30                 pMeasureGrid.XOrigin = -180;
31                 pMeasureGrid.YOrigin = -90;
32                 // 设置MeasuredGride投影属性
33                 IProjectedGrid pProGrid = pMeasureGrid as IProjectedGrid;
34                 pProGrid.SpatialReference = pMap.SpatialReference;
35                 pMapGrid.Name = "Measured Grid";
36                 // 创建一个CalibratedMapGridBorder对象(参考边界校准)并设置为pMapGrid的Border属性   
37                 ICalibratedMapGridBorder pCalibratedBorder = new CalibratedMapGridBorderClass();
38                 pCalibratedBorder.BackgroundColor = GetRgbColor(255,255,255);
39                 pCalibratedBorder.ForegroundColor = GetRgbColor(0, 0, 0);
40                 pCalibratedBorder.BorderWidth = 0.1;
41                 pCalibratedBorder.Interval = 72;
42                 pCalibratedBorder.Alternating = true;
43                 pMapGrid.Border = pCalibratedBorder as IMapGridBorder;
44 
45                 // 创建一个FormattedGridLabel对象(格式化参考标签)
46                 IFormattedGridLabel pFormattedGridLabel = new FormattedGridLabelClass();
47                 IGridLabel pGridLabel = pFormattedGridLabel as IGridLabel;
48 
49                 // 设置标签字体,需要引用类库
50                 //stdole.StdFont pFont = new stdole.StdFont();
51                 //pFont.Name = "Arial";
52                 //pFont.Size = 6;
53                 //pGridLabel.Font = pFont as stdole.IFontDisp;
54 
55                 pGridLabel.Color = GetRgbColor(0, 0, 0);
56                 pGridLabel.LabelOffset = 4;
57                 pGridLabel.set_LabelAlignment(esriGridAxisEnum.esriGridAxisLeft, false);
58                 pGridLabel.set_LabelAlignment(esriGridAxisEnum.esriGridAxisRight, false);
59 
60                 INumericFormat pNumericFormat = new NumericFormatClass();// 数字格式
61                 pNumericFormat.AlignmentOption = esriNumericAlignmentEnum.esriAlignRight;
62                 pNumericFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfSignificantDigits;
63                 pNumericFormat.RoundingValue = 0;
64                 pNumericFormat.ShowPlusSign = false;
65                 pNumericFormat.ZeroPad = true;
66                 pFormattedGridLabel.Format = pNumericFormat as INumberFormat;
67 
68                 // 设置pMapGrid的LabelFormat属性
69                 pMapGrid.LabelFormat = pGridLabel;
70                 // 添加格网
71                 pMapGrids.AddMapGrid(pMapGrid);
72 
73             }
74             catch (Exception)
75             {
76 
77                 throw;
78             }
79         }
View Code

3.2.8 MapSurround对象

  MapSurround 对象是与一个地图对象关联的用于修饰地图的辅助图形元素对象。 比例尺,比例尺文本,图例,指北针。。
  MapSurround对象由MapSurroundFrame对象管理,所有的MapSurround对象添加在布局视图上,每一个MapSurround对象可以
  通过IMap接口的MapSurrounds属性的索引值所获取;也可以通过IMap接口的MapSurroundCount来遍历布局视图上的所有MapSurround对象

  所有的MapSurround对象都实现了IMapSurround接口,使用该接口的Name属性可以获得MapSurround对象的名称,
  通过IMapSurround的FitToBound方法可以设置一个MapSurround对象的大小。
  同时,MapSurround类也实现了IMapSurroundEvents接口,可以用来触发MapSurround相关事件,如:AfterDraw,BeforeDraw,ContensChange

  如下代码演示如何为PageLayout添加Legend:

 1         /// <summary>
 2         /// 为PageLayout对象添加图例对象
 3         /// </summary>
 4         /// <param name="pPageLayout"></param>
 5         /// <param name="pEnvelop">图例添加的位置</param>
 6         private void AddLegendToPageLayout(IPageLayout pPageLayout, IEnvelope pEnvelop)
 7         {
 8             try
 9             {
10                 IActiveView pActiveView = pPageLayout as IActiveView;
11                 IMap pMap = pActiveView.FocusMap;
12                 IGraphicsContainer pGraphicsContainer = pActiveView as IGraphicsContainer;
13                 IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
14                 UID pUID = new UID();
15                 pUID.Value = "{7A3F81E34-B9E3-11D1-8756-000F8751720}";
16                 ISymbolBackground pSymbolBackground = new SymbolBackgroundClass();
17                 IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
18                 ILineSymbol pLineSymbol = new SimpleLineSymbolClass();
19                 pFillSymbol.Color = GetRgbColor(255, 255, 255);
20                 pLineSymbol.Color = GetRgbColor(255, 255, 255);
21                 pFillSymbol.Outline = pLineSymbol;
22                 pSymbolBackground.FillSymbol = pFillSymbol;
23                 IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pUID, null);
24                 pMapSurroundFrame.Background = pSymbolBackground;
25 
26                 IElement pElement = pMapSurroundFrame as IElement;
27                 pElement.Geometry = pEnvelop;
28                 IMapSurround pMapSurround = pMapSurroundFrame.MapSurround;
29                 ILegend pLegend = pMapSurround as ILegend;
30                 pLegend.ClearItems();
31                 pLegend.Title = "图 ☆例";
32                 ITextSymbol pTextSymbol = new TextSymbolClass();
33                 pTextSymbol.Size = 10;
34                 pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
35                 ILegendItem pLegendItem = null;
36 
37                 for (int i = 0; i < pActiveView.FocusMap.LayerCount; i++)
38                 {
39                     ILayer pLayer = pActiveView.FocusMap.get_Layer(i);
40                     if (pLayer is IFeatureLayer)
41                     {
42                         IFeatureLayer pFlayer = pLayer as IFeatureLayer;
43                         IFeatureClass pFeatureClass = pFlayer.FeatureClass;
44                         if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
45                         {
46                             continue;
47                         }
48                         else
49                         {
50                             pLegendItem = new HorizontalBarLegendItemClass();
51                             pLegendItem.Layer = pLayer;
52                             pLegendItem.Columns = 1;
53                             pLegendItem.ShowDescriptions = false;
54                             pLegendItem.ShowHeading = false;
55                             pLegendItem.ShowLabels = true;
56                             pLegendItem.LayerNameSymbol = pTextSymbol;
57                             pLegend.AddItem(pLegendItem);
58                         }
59                     }
60                 }
61             }
62             catch (Exception)
63             {
64 
65                 throw;
66             }
67         }
View Code

程序结果如下图所示:

 

  第三章到此结束。这章的内容是地图和地图布局,所围绕的大都是图形布局对象的操作。

 
 
 
 
 
 
 
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值