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

调用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视图上的坐标点,然后在该坐标点处生成图名。图名可以由用户输入来确定。

生成图名的代码如下:

public void AddTextElement(AxPageLayoutControl PageLayoutControl,double x,double y,string textName)
{
    IPageLayout pPageLayout;
    IActiveView pAV;
    IGraphicsContainer pGraphicsContainer;
    IPoint pPoint;
    ITextElement pTextElement;
    IElement pElement;
    ITextSymbol pTextSymbol;
    IRgbColor pColor;
    pPageLayout = PageLayoutControl.PageLayout;
    pAV = (IActiveView)pPageLayout;
    pGraphicsContainer = (IGraphicsContainer)pPageLayout;
    pTextElement = new TextElementClass();

    IFontDisp pFont = new StdFontClass() as IFontDisp;
    pFont.Bold = true;
    pFont.Name = "宋体";
    pFont.Size = 13;

    pColor = new RgbColorClass();
    pColor.Red = 255;

    pTextSymbol = new TextSymbolClass();
    pTextSymbol.Color = (IColor)pColor;
    pTextSymbol.Font = pFont;

    pTextElement.Text = textName;
    pTextElement.Symbol = pTextSymbol;

    pPoint = new PointClass();
    pPoint.X = x;
    pPoint.Y = y;

    pElement = (IElement)pTextElement;
    pElement.Geometry = (IGeometry)pPoint;
    pGraphicsContainer.AddElement(pElement, 0);

    pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}

添加指北针、比例尺和比例文本,可以调用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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值