//添加比例尺
private void AddScaleBar_Click(object sender, EventArgs e)
{
pActiveView = axPageLayoutControl1.PageLayout as IActiveView;
pMap = pActiveView.FocusMap as IMap;
pGraphicsContainer = pActiveView as IGraphicsContainer;
pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
//设置比例尺样式
IMapSurround pMapSurround;
IScaleBar pScaleBar;
pScaleBar = new ScaleLineClass();
pScaleBar.Units = pMap.MapUnits;
pScaleBar.Divisions = 2;
pScaleBar.Subdivisions = 4;
pScaleBar.DivisionsBeforeZero = 0;
pScaleBar.UnitLabel = ChangeMapUniteToChinese(pMap.MapUnits);
pScaleBar.LabelPosition = esriVertPosEnum.esriBelow;
pScaleBar.LabelGap = 3.6;
pScaleBar.LabelFrequency = esriScaleBarFrequency.esriScaleBarDivisionsAndFirstMidpoint;
pMapSurround = pScaleBar;
pMapSurround.Name = "ScaleBar";
//定义UID
UID uid = new UIDClass();
uid.Value = "esriCarto.ScaleLine";
//定义MapSurroundFrame对象
IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(uid, null);
pMapSurroundFrame.MapSurround = pMapSurround;
//定义Envelope设置Element摆放的位置
IEnvelope pEnvelope = new EnvelopeClass();
pEnvelope.PutCoords(1, 1, 10, 2);
IElement pElement = pMapSurroundFrame as IElement;
pElement.Geometry = pEnvelope;
pGraphicsContainer.AddElement(pElement, 0);
}
//添加指北针
private void AddNorthArrow_Click(object sender, EventArgs e)
{
pActiveView = axPageLayoutControl1.PageLayout as IActiveView;
pMap = pActiveView.FocusMap as IMap;
pGraphicsContainer = pActiveView as IGraphicsContainer;
pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
IMapSurround pMapSurround;
INorthArrow pNorthArrow;
pNorthArrow = new MarkerNorthArrowClass();
pMapSurround = pNorthArrow;
pMapSurround.Name = "NorthArrow";
//定义UID
UID uid = new UIDClass();
uid.Value = "esriCarto.MarkerNorthArrow";
//定义MapSurroundFrame对象
IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(uid, null);
pMapSurroundFrame.MapSurround = pMapSurround;
//定义Envelope设置Element摆放的位置
IEnvelope pEnvelope = new EnvelopeClass();
pEnvelope.PutCoords(10,10,10,10);
IElement pElement = pMapSurroundFrame as IElement;
pElement.Geometry = pEnvelope;
pGraphicsContainer.AddElement(pElement, 0);
}
本文介绍如何在地图布局中添加比例尺和指北针。通过设置样式、位置等属性实现元素的有效展示。

344

被折叠的 条评论
为什么被折叠?



