博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
添加地图图例 Arcengine+C#
阅读量:6958 次
发布时间:2019-06-27

本文共 3013 字,大约阅读时间需要 10 分钟。

private void MakeLegend(IActiveView activeView,IPageLayout pageLayout)

      {

          //定义图例UID对象

          UID uid = new UIDClass();

          uid.Value="esriCore.Legend";       

          //设置图例存放的坐标位置                

          //定义单位

          pageLayout.Page.Units = esriUnits.esriCentimeters;

          //得到草图容器对象

          IGraphicsContainer container = pageLayout as IGraphicsContainer;

          //得到当前地图的框架

          IMapFrame frameElement = container.FindFrame(activeView.FocusMap) as IMapFrame;

          IElement mapElement = frameElement as IElement;

 

          IEnvelope mapEnv = mapElement.Geometry.Envelope;   

          IEnvelope envelope = new EnvelopeClass();

          //通过当前地图框架得到相对位置

          envelope.PutCoords(mapEnv.XMin, mapEnv.YMin, mapEnv.XMin + 6.5, mapEnv.YMin + 0.8);

          IMapSurroundFrame frame = frameElement.CreateSurroundFrame(uid, null);            

          ILegend legend = frame.MapSurround as ILegend;

          ILegendFormat format = new LegendFormatClass();

          format.TitlePosition = esriRectanglePosition.esriTopSide;

          format.LayerNameGap=0.0;

          format.TextGap=0.0;

          format.TitleGap=0.0;

          format.HeadingGap=0.0;

          format.HorizontalItemGap=0.0;

          format.VerticalItemGap=0.0;

          format.ShowTitle=true;

          ITextSymbol symbol = new TextSymbolClass();

          symbol.Text="图例";

          System.Drawing.Font ft = new System.Drawing.Font("宋体", 5);

          IFontDisp iFontDispFromFont = (IFontDisp)OLE.GetIFontDispFromFont(ft);

          symbol.Font=iFontDispFromFont;

          symbol.Size = 11.5;

      

          IRgbColor color = (IRgbColor)ESRI.ArcGIS.ADF.Converter.ToRGBColor(Color.Black);

          symbol.Color = color;

          //文字水平方向的对齐方式

          symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;     

          format.TitleSymbol=symbol;

          legend.Format=format;

          legend.Title="图例";

          legend.FlowRight = true;

          legend.ClearItems();        

          IMap map = activeView.FocusMap;      

          for (int i = 0; i < map.LayerCount; i++)

          {

              IFeatureLayer layer = (IFeatureLayer)map.get_Layer(i) as IFeatureLayer;

              ILegendItem item = new HorizontalLegendItemClass();              

              item.Columns=(short)map.LayerCount;

              item.NewColumn=true;        

              ITextSymbol symbolItem = new TextSymbolClass();            

              symbolItem.Size = 11.5;

              ILegendClassFormat legClsFormat = new LegendClassFormatClass();

              legClsFormat.LabelSymbol = symbolItem;

              legClsFormat.PatchHeight = 40;

              legClsFormat.PatchWidth = 50;                

              item.LegendClassFormat = legClsFormat;

              item.Layer=layer;

              item.KeepTogether=false;

              legend.AddItem(item);

          }               

          frame.MapSurround.Name="myLegend";

          IFrameProperties properties = frame as IFrameProperties;

          ISymbolBorder border = new SymbolBorderClass();

          border.Gap=0.0;

          border.CornerRounding=0;

          IBorder border2 = border;

          properties.Border=border2;

          IFrameDecoration decoration = new SymbolBackgroundClass();

          IRgbColor color1 = (IRgbColor)ESRI.ArcGIS.ADF.Converter.ToRGBColor(Color.LightSeaGreen);

          color1.Transparency = 50;

          decoration.Color = color1;

          decoration.CornerRounding=0;

          decoration.HorizontalSpacing=0.0;

          decoration.VerticalSpacing=0.0;

          properties.Background=((IBackground)decoration);

          IElement element = frame as IElement;         

          element.Geometry=envelope;

          element.Activate(activeView.ScreenDisplay);

          container.AddElement(element, 0);

          activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

      }

转载于:https://www.cnblogs.com/linhugh/articles/2520875.html

你可能感兴趣的文章
验证码识别
查看>>
Metasploit没有db_autopwn命令的解决办法
查看>>
stage3图书管理系统服务器部署
查看>>
button与submit
查看>>
JMETER JDBC操作
查看>>
关于baseflight cleanflight naze32不能解锁的办法
查看>>
hihoCoder挑战赛28 题目3 : 树的方差
查看>>
第二阶段团队绩效考核报告
查看>>
关于转义字符的意义
查看>>
更改centos 7 的默认启动为命令界面
查看>>
nginx安装目录详解(针对centos)
查看>>
sublime汉化步骤记录
查看>>
Java笔记02——多线程
查看>>
ubuntu下mysql无法启动Couldn't find MySQL server (/usr/bin/mysqld_safe)”
查看>>
sleep函数——Gevent源码分析
查看>>
学习周总结
查看>>
通用窗口类 Inventory Pro 2.1.2 Demo1(下)
查看>>
第零次作业
查看>>
在阿里云服务器windows server2012r iis上部署.net网站
查看>>
为easyui添加多条件验证
查看>>