请问在ArcEngine中比例尺工具如何添加

请问在ArcEngine中比例尺工具如何添加,第1张

/// 比例尺

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void btnScaleBar_Click(object sender, EventArgs e)

{

AddScalebar(axPageLayoutControl1.PageLayout, axPageLayoutControl1.ActiveView.FocusMap)

}

public void AddScalebar(IPageLayout pageLayout, IMap map)

{

if (pageLayout == null || map == null)

{

return

}

IEnvelope envelope = new EnvelopeClass()

envelope.PutCoords(1, 1, 15, 2.5)// Specify the location and size of the scalebar

IUID uid = new UIDClass()

uid.Value = "esriCarto.AlternatingScaleBar"

// Create a Surround. Set the geometry of the MapSurroundFrame to give it a location

// Activate it and add it to the PageLayout's graphics container

IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer// Dynamic Cast

IActiveView activeView = pageLayout as IActiveView// Dynamic Cast

IFrameElement frameElement = graphicsContainer.FindFrame(map)

IMapFrame mapFrame = frameElement as IMapFrame// Dynamic Cast

IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as UID, null)// Dynamic Cast

IElement element = mapSurroundFrame as IElement// Dynamic Cast

element.Geometry = envelope

element.Activate(activeView.ScreenDisplay)

graphicsContainer.AddElement(element, 0)

IMapSurround mapSurround = mapSurroundFrame.MapSurround

IScaleBar markerScaleBar = ((IScaleBar)(mapSurround))

markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow

markerScaleBar.UseMapSettings()

}

#endregion

把对应的元素写成函数调用就行了。

/// <summary>

/// 添加默认固定指北针

/// </summary>

/// <param name="pageLayout"></param>

public static void AddNorthArrow(IPageLayout pageLayout)

{

IGraphicsContainer container = pageLayout as IGraphicsContainer

IActiveView activeView = pageLayout as IActiveView

// 获得MapFrame

IFrameElement frameElement = container.FindFrame(activeView.FocusMap)

IMapFrame mapFrame = frameElement as IMapFrame

//根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround

UID uid = new UIDClass()

uid.Value = "esriCarto.MarkerNorthArrow"

IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null)

//设置MapSurroundFrame中指北针的点符号

IMapSurround mapSurround = mapSurroundFrame.MapSurround

IMarkerNorthArrow markerNorthArrow = mapSurround as IMarkerNorthArrow

IMarkerSymbol markerSymbol = markerNorthArrow.MarkerSymbol

markerSymbol.Size = 30

markerNorthArrow.MarkerSymbol = markerSymbol

//QI,确定mapSurroundFrame的位置

IElement element = mapSurroundFrame as IElement

IEnvelope envelope = new EnvelopeClass()

envelope.PutCoords(19.7, 27, 29,37 )

element.Geometry = envelope

//使用IGraphicsContainer接口添加显示

container.AddElement(element, 0)

activeView.Refresh()

}

/// <summary>

/// 添加固定比例尺

/// </summary>

/// <param name="pageLayout"></param>

public static void AddScalebar(IPageLayout pageLayout)

{

IGraphicsContainer container = pageLayout as IGraphicsContainer

IActiveView activeView = pageLayout as IActiveView

// 获得MapFrame

IFrameElement frameElement = container.FindFrame(activeView.FocusMap)

IMapFrame mapFrame = frameElement as IMapFrame

//根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround

UID uid = new UIDClass()

uid.Value = "esriCarto.AlternatingScaleBar"

IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null)

//设置MapSurroundFrame中比例尺的样式

IMapSurround mapSurround = mapSurroundFrame.MapSurround

IScaleBar markerScaleBar = (IScaleBar)mapSurround

markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow

markerScaleBar.UseMapSettings()

//QI,确定mapSurroundFrame的位置

IElement element = mapSurroundFrame as IElement

IEnvelope envelope = new EnvelopeClass()

envelope.PutCoords(1.3, 1.3, 5, 2)

element.Geometry = envelope

//使用IGraphicsContainer接口添加显示

container.AddElement(element, 0)

activeView.Refresh()

}

/// <summary>

/// 添加固定图例

/// </summary>

/// <param name="axPageLayoutControl1"></param>

public static void AddLegend(AxPageLayoutControl axPageLayoutControl1)

{

IPageLayout pageLayout = axPageLayoutControl1.PageLayout

IGraphicsContainer container = pageLayout as IGraphicsContainer

IActiveView activeView = pageLayout as IActiveView

// 获得MapFrame

IFrameElement frameElement = container.FindFrame(activeView.FocusMap)

//IMapFrame mapFrame = container.FindFrame(activeView.FocusMap) as IMapFrame

IMapFrame mapFrame = frameElement as IMapFrame

//根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround

UID uid = new UIDClass()

uid.Value = "esriCarto.Legend"

IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null)

//设置MapSurroundFrame背景

ISymbolBackground pSymbolBackground = new SymbolBackgroundClass()

ILineSymbol pLineSymbol = new SimpleLineSymbolClass()

pLineSymbol.Color = GetRgbColor(0, 0, 0)

IFillSymbol pFillSymbol = new SimpleFillSymbolClass()

pFillSymbol.Color = GetRgbColor(240, 240, 240)

pFillSymbol.Outline = pLineSymbol

pSymbolBackground.FillSymbol = pFillSymbol

mapSurroundFrame.Background = pSymbolBackground

//设置图例的Title

ILegend2 legend = mapSurroundFrame.MapSurround as ILegend2

legend.Title = "地图图例"

//新图层加载时自动更新

legend.AutoAdd = true

ILegendFormat format = new LegendFormatClass()

ITextSymbol symbol = new TextSymbolClass()

symbol.Size = 0.3

format.TitleSymbol = symbol

legend.Format = format

//QI,确定mapSurroundFrame的位置

IElement element = mapSurroundFrame as IElement

IEnvelope envelope = new EnvelopeClass()

envelope.PutCoords(17.7, 1, 20, 9)

element.Geometry = envelope

//使用IGraphicsContainer接口添加显示

container.AddElement(element, 0)

activeView.Refresh()

}

/// <summary>

/// 添加title

/// </summary>

/// <param name="pageLayout"></param>

/// <param name="s"></param>

public static void AddTitle(AxPageLayoutControl mainPageLayoutControl1, String s)

{

//找到PageLayout

IPageLayout pPageLayout = mainPageLayoutControl1.PageLayout

//找到元素容器

IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer

//创建元素

ITextElement pTextElement = new TextElementClass()

pTextElement.Text = s

ITextSymbol pTextSymbol = new TextSymbolClass()//Text的符号样式

IRgbColor color = new RgbColorClass()

color.Green = 255

color.Blue = 255

color.Red = 0

pTextSymbol.Color = color as ESRI.ArcGIS.Display.IColor

pTextSymbol.Size = 20

pTextSymbol.Color = GetRgbColor(0, 0, 0)

pTextElement.Symbol = pTextSymbol

//设置位置

IElement pElement = pTextElement as IElement

IEnvelope envelope = new EnvelopeClass()

envelope.PutCoords(9, 27.3, 13, 30)

pElement.Geometry = envelope

//pElement.Geometry = mainPageLayoutControl1.TrackRectangle()

//将元素添加到容器中

pGraphicsContainer.AddElement(pElement, 0)

//刷新

mainPageLayoutControl1.Refresh()

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11703268.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存