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

相关文章:

  • 2022-12-23
  • 2021-10-24
  • 2021-12-09
  • 2022-01-12
  • 2022-12-23
  • 2021-07-13
  • 2022-01-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案