ArcGIS Engine中地图整饰要素属于MapSurround对象,包括比例尺、指北针、图例等,MapSurround对象由MapSurroundFrame对象管理。
指北针
添加指北针主要用到INorthArrow接口、IElement接口
private void addNorthArrow(IEnvelope pEnvelope,INorthArrow pNorthArrow)
{
IMap pMap = axPageLayoutControl1.ActiveView.FocusMap;
IMapFrame pMapFrame = (IMapFrame)axPageLayoutControl1.ActiveView.GraphicsContainer.FindFrame(pMap);
IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();
pMapSurroundFrame.MapFrame = pMapFrame;
pMapSurroundFrame.MapSurround = (IMapSurround)pNorthArrow;
IElement pElement = (IElement)pMapSurroundFrame;
pElement.Geometry = pEnvelope;
axPageLayoutControl1.ActiveView.GraphicsContainer.AddElement(pElement, 0);
axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
图例
添加图例主要用到ILegend接口、ILegendItem接口、ILegend类、IElement接口
ILegend pLegend = new Legend();
for(int i = 0; i < axPageLayoutControl1.ActiveView.FocusMap.LayerCount; i++)
{
ILegendItem pLegendItem = new HorizontalLegendItemClass();
pLegendItem.Layer = axPageLayoutControl1.ActiveView.FocusMap.Layer[i];
pLegend.AddItem(pLegendItem);
}
//将图例添加到显示
IMap pMap = axPageLayoutControl1.ActiveView.FocusMap;
IMapFrame pMapFrame = (IMapFrame)axPageLayoutControl1.ActiveView.GraphicsContainer.FindFrame(pMap);
IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();
pMapSurroundFrame.MapFrame = pMapFrame;
pMapSurroundFrame.MapSurround = pLegend;
IElement pElement = pMapSurroundFrame as IElement;
pElement.Geometry = pEnv;
axPageLayoutControl1.ActiveView.GraphicsContainer.AddElement(pElement, 0);
axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);