创建ArcGIS Engine自定义工具类,生成地图元素(转载)

转自:http://blog.csdn.net/freeWayWalker/article/details/25633859

调用ArcObjects对象,创建ArcGIS Engine自定义工具类,来生成地图元素。一些地图元素与数据框中的数据相关。此类元素包括图名、指北针、比例尺、比例文本和图例。

 

ArcObjects中的MapSurround 对象是与一个地图对象关联的,用于修饰地图的辅助图形元素对象。 比如比例尺,比例尺文本,图例,指北针...
MapSurround对象由MapSurroundFrame对象管理。所有的MapSurround对象都被添加在布局视图后,每一个MapSurround对象可以通过IMap接口的MapSurrounds属性的索引值所获取;也可以通过IMap接口的MapSurroundCount来遍历布局视图上的所有MapSurround对象。
所有的MapSurround对象都实现了IMapSurround接口,使用该接口的Name属性可以获得MapSurround对象的名称,通过IMapSurround的FitToBound方法可以设置一个MapSurround对象的大小。同时,MapSurround类也实现了IMapSurroundEvents接口,可以用来触发MapSurround相关事件,如:AfterDraw,BeforeDraw,ContensChange。

 

添加图名,需要捕捉到鼠标点击到pageLayoutControl视图上的坐标点,然后在该坐标点处生成图名。图名可以由用户输入来确定。

生成图名的代码如下:

 

[csharp] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. public void AddTextElement(AxPageLayoutControl PageLayoutControl,double x,double y,string textName)  
  2. {  
  3.     IPageLayout pPageLayout;  
  4.     IActiveView pAV;  
  5.     IGraphicsContainer pGraphicsContainer;  
  6.     IPoint pPoint;  
  7.     ITextElement pTextElement;  
  8.     IElement pElement;  
  9.     ITextSymbol pTextSymbol;  
  10.     IRgbColor pColor;  
  11.     pPageLayout = PageLayoutControl.PageLayout;  
  12.     pAV = (IActiveView)pPageLayout;  
  13.     pGraphicsContainer = (IGraphicsContainer)pPageLayout;  
  14.     pTextElement = new TextElementClass();  
  15.   
  16.     IFontDisp pFont = new StdFontClass() as IFontDisp;  
  17.     pFont.Bold = true;  
  18.     pFont.Name = "宋体";  
  19.     pFont.Size = 13;  
  20.   
  21.     pColor = new RgbColorClass();  
  22.     pColor.Red = 255;  
  23.   
  24.     pTextSymbol = new TextSymbolClass();  
  25.     pTextSymbol.Color = (IColor)pColor;  
  26.     pTextSymbol.Font = pFont;  
  27.   
  28.     pTextElement.Text = textName;  
  29.     pTextElement.Symbol = pTextSymbol;  
  30.   
  31.     pPoint = new PointClass();  
  32.     pPoint.X = x;  
  33.     pPoint.Y = y;  
  34.   
  35.     pElement = (IElement)pTextElement;  
  36.     pElement.Geometry = (IGeometry)pPoint;  
  37.     pGraphicsContainer.AddElement(pElement, 0);  
  38.   
  39.     pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);  
  40. }  

添加指北针、比例尺和比例文本,可以调用ESRI.ServerStyle中的样式文件来进行选择,能够达到自定义样式的效果。

这三种的添加方法具体可以参考下面的链接。

选择指北针样式如下图所示:

 

参考:

Sample: Add map surrounds using the SymbologyControl     http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/000100000455000000.htm

Add North Arrow http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/0049/00490000004w000000.htm

Add Scale Bar    http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/0049/004900000043000000.htm

Add Legend       http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/0049/00490000006w000000.htm

ArcGIS Engine自定义工具类,实现添加图名,比例尺,指北针 http://blog.sina.com.cn/s/blog_6e51df7f010129ka.html

 
0
posted @ 2016-05-16 22:41  焦涛  阅读(594)  评论(0)    收藏  举报