[ArcEngine地图制图系列]—添加图例
来源:互联网 发布:mac 网页原型设计工具 编辑:程序博客网 时间:2024/05/11 22:40
private void AddLegend(IActiveView pActiveView, IEnvelope pEnv)
{
IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer;
UID pID = new UID();
pID.Value = "esriCarto.Legend";
IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame;
IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pID, null);//根据唯一标示符,创建与之对应MapSurroundFrame
IElement pDeletElement = axPageControl.FindElementByName("Legend");//获取PageLayout中的图例元素
if (pDeletElement != null)
{
pGraphicsContainer.DeleteElement(pDeletElement); //如果已经存在图例,删除已经存在的图例
}
//设置MapSurroundFrame背景
ISymbolBackground pSymbolBackground = new SymbolBackgroundClass();
ILineSymbol pLineSymbol = new SimpleLineSymbolClass();
pLineSymbol.Color = ColorUtilty.GetRgbColor(0, 0, 0);
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
pFillSymbol.Color = ColorUtilty.GetRgbColor(240, 240, 240);
pFillSymbol.Outline = pLineSymbol;
pSymbolBackground.FillSymbol = pFillSymbol;
pMapSurroundFrame.Background = pSymbolBackground;
//添加图例
IElement pElement = pMapSurroundFrame as IElement;
pElement.Geometry = pEnv as IGeometry;
IMapSurround pMapSurround = pMapSurroundFrame.MapSurround;
ILegend pLegend = pMapSurround as ILegend;
pLegend.ClearItems();
pLegend.Title = "图例";
for (int i = 0; i < pActiveView.FocusMap.LayerCount; i++)
{
ILayer pLayer = pActiveView.FocusMap.get_Layer(i);
if (pLayer.Visible == true)
{
if (pLayer is IGroupLayer || pLayer is ICompositeLayer)
{
ICompositeLayer pCompositeLayer = (ICompositeLayer)pLayer;
for (int j = pCompositeLayer.Count - 1; j >= 0; j--)
{
ILayer pSubLayer = pCompositeLayer.get_Layer(j);
ILegendItem pItem = SetItemStyle(pSubLayer);
pLegend.AddItem(pItem);//添加图例内容
}
}
else
{
ILegendItem pItem = SetItemStyle(pLayer);
pLegend.AddItem(pItem);//添加图例内容
}
}
}
pGraphicsContainer.AddElement(pElement, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
private ILegendItem SetItemStyle(ILayer layer)
{
StdFont myFont = new stdole.StdFontClass();
myFont.Name = "宋体";
myFont.Size = 10;
ITextSymbol txtSymbol = new TextSymbolClass();
txtSymbol.Font = (IFontDisp)myFont;
ILegendItem pLegendItem = new HorizontalLegendItemClass();
pLegendItem.Layer = layer;//获取添加图例关联图层
pLegendItem.ShowDescriptions = false;
pLegendItem.Columns = 1;
pLegendItem.LayerNameSymbol = txtSymbol;
pLegendItem.ShowHeading = true;
pLegendItem.ShowLabels = true;
return pLegendItem;
}
{
IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer;
UID pID = new UID();
pID.Value = "esriCarto.Legend";
IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame;
IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pID, null);//根据唯一标示符,创建与之对应MapSurroundFrame
IElement pDeletElement = axPageControl.FindElementByName("Legend");//获取PageLayout中的图例元素
if (pDeletElement != null)
{
pGraphicsContainer.DeleteElement(pDeletElement); //如果已经存在图例,删除已经存在的图例
}
//设置MapSurroundFrame背景
ISymbolBackground pSymbolBackground = new SymbolBackgroundClass();
ILineSymbol pLineSymbol = new SimpleLineSymbolClass();
pLineSymbol.Color = ColorUtilty.GetRgbColor(0, 0, 0);
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
pFillSymbol.Color = ColorUtilty.GetRgbColor(240, 240, 240);
pFillSymbol.Outline = pLineSymbol;
pSymbolBackground.FillSymbol = pFillSymbol;
pMapSurroundFrame.Background = pSymbolBackground;
//添加图例
IElement pElement = pMapSurroundFrame as IElement;
pElement.Geometry = pEnv as IGeometry;
IMapSurround pMapSurround = pMapSurroundFrame.MapSurround;
ILegend pLegend = pMapSurround as ILegend;
pLegend.ClearItems();
pLegend.Title = "图例";
for (int i = 0; i < pActiveView.FocusMap.LayerCount; i++)
{
ILayer pLayer = pActiveView.FocusMap.get_Layer(i);
if (pLayer.Visible == true)
{
if (pLayer is IGroupLayer || pLayer is ICompositeLayer)
{
ICompositeLayer pCompositeLayer = (ICompositeLayer)pLayer;
for (int j = pCompositeLayer.Count - 1; j >= 0; j--)
{
ILayer pSubLayer = pCompositeLayer.get_Layer(j);
ILegendItem pItem = SetItemStyle(pSubLayer);
pLegend.AddItem(pItem);//添加图例内容
}
}
else
{
ILegendItem pItem = SetItemStyle(pLayer);
pLegend.AddItem(pItem);//添加图例内容
}
}
}
pGraphicsContainer.AddElement(pElement, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
private ILegendItem SetItemStyle(ILayer layer)
{
StdFont myFont = new stdole.StdFontClass();
myFont.Name = "宋体";
myFont.Size = 10;
ITextSymbol txtSymbol = new TextSymbolClass();
txtSymbol.Font = (IFontDisp)myFont;
ILegendItem pLegendItem = new HorizontalLegendItemClass();
pLegendItem.Layer = layer;//获取添加图例关联图层
pLegendItem.ShowDescriptions = false;
pLegendItem.Columns = 1;
pLegendItem.LayerNameSymbol = txtSymbol;
pLegendItem.ShowHeading = true;
pLegendItem.ShowLabels = true;
return pLegendItem;
}
0 0
- [ArcEngine地图制图系列]—添加图例
- [ArcEngine地图制图系列]—添加比例尺
- [ArcEngine地图制图系列]—添加网格
- [ArcEngine地图制图系列]—添加地图标题
- [ArcEngine地图制图系列]—添加地图指北针
- [ArcEngine地图制图系列]—添加比例文本
- AE二次开发-添加制图图例
- ArcEngine添加指北针、比例尺、图例(注意UID值)
- 地图制图
- ArcEngine 图例C#源码:
- ArcGIS制图技巧系列(3)—让地图更有立体感
- ArcGIS制图,图例详细修改
- 【地图整饰】ArcMap添加地图标题及ArcEngine实现
- ArcEngine中设置添加图层的图例显示为水平一行的样式的方法
- 【地图整饰】ArcMap添加图框及ArcEngine实现
- 【ArcEngine入门与提高】专题制图
- Arcengine制图表达的一些理解
- ArcEngine中制图表达的相关接口
- leetcode 之 Reverse Linked List
- Leetcode Sort List 链表排序
- 远程接入移动办公产品nuosai炉石
- 添加对话框左上角小图标
- oracle的分析函数over 及开窗函数
- [ArcEngine地图制图系列]—添加图例
- 服务器同时安装了两个版本的sql,如果分别连接不同版本的sql上的数据库
- proguard.ParseException: Expecting keyword 'class', 'interface', or 'enum' before '-libraryjars' in
- web--jmeter重要组件
- 绚丽的一个loading动画
- QT下GPS数据读取与处理!!!
- 中国最酷、最美的女明星不是王菲,而是她!
- SQLITE3 使用总结
- 微信公众平台开发(71)OAuth2.0网页授权