ArcEngine添加指北针、比例尺、图例(注意UID值)

来源:互联网 发布:自己画装修设计图软件 编辑:程序博客网 时间:2024/06/05 10:23


    指北针

C#代码  收藏代码
  1. public void AddNorthArrow(IPageLayout pageLayout)  
  2.        {  
  3.             IGraphicsContainer container = pageLayout as IGraphicsContainer;   
  4.             IActiveView activeView = pageLayout as IActiveView;   
  5.             // 获得MapFrame  
  6.             IFrameElement frameElement = container.FindFrame(activeView.FocusMap);  
  7.             IMapFrame mapFrame = frameElement as IMapFrame;  
  8.             //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround  
  9.             UID uid = new UIDClass();  
  10.             uid.Value = "esriCarto.MarkerNorthArrow";  
  11.         IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);  
  12.             //设置MapSurroundFrame中指北针的点符号  
  13.             IMapSurround mapSurround = mapSurroundFrame.MapSurround;  
  14.             IMarkerNorthArrow markerNorthArrow = mapSurround as IMarkerNorthArrow;   
  15.             IMarkerSymbol markerSymbol = markerNorthArrow.MarkerSymbol;  
  16.             markerSymbol.Size = 18;  
  17.             markerNorthArrow.MarkerSymbol = markerSymbol;  
  18.             //QI,确定mapSurroundFrame的位置  
  19.             IElement element = mapSurroundFrame as IElement;  
  20.             IEnvelope envelope = new EnvelopeClass();  
  21.             envelope.PutCoords(0.2, 0.2, 5, 5);  
  22.             element.Geometry = envelope;  
  23.             //使用IGraphicsContainer接口添加显示  
  24.             container.AddElement(element, 0);  
  25.             activeView.Refresh();  
  26.  }  

 

   比例尺

C#代码  收藏代码
  1. public void AddScalebar(IPageLayout pageLayout)  
  2.         {  
  3.             IGraphicsContainer container = pageLayout as IGraphicsContainer;   
  4.             IActiveView activeView = pageLayout as IActiveView;  
  5.             // 获得MapFrame  
  6.             IFrameElement frameElement = container.FindFrame(activeView.FocusMap);  
  7.             IMapFrame mapFrame = frameElement as IMapFrame;  
  8.            //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround  
  9.             UID uid = new UIDClass();  
  10.             uid.Value = "esriCarto.AlternatingScaleBar";  
  11.       IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);  
  12.             //设置MapSurroundFrame中比例尺的样式  
  13.             IMapSurround mapSurround = mapSurroundFrame.MapSurround;  
  14.             IScaleBar markerScaleBar = ((IScaleBar)mapSurround);  
  15.             markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow;  
  16.             markerScaleBar.UseMapSettings();  
  17.             //QI,确定mapSurroundFrame的位置  
  18.             IElement element = mapSurroundFrame as IElement;  
  19.             IEnvelope envelope = new EnvelopeClass();  
  20.             envelope.PutCoords(0.2, 0.2, 1, 2);   
  21.             element.Geometry = envelope;  
  22.             //使用IGraphicsContainer接口添加显示  
  23.             container.AddElement(element, 0);  
  24.             activeView.Refresh();  
  25.    }  

 

   图例

C#代码  收藏代码
  1. private void AddLegend(IPageLayout pageLayout)  
  2.        {  
  3.            IActiveView pActiveView = pageLayout as IActiveView;  
  4.            IGraphicsContainer container = pageLayout as IGraphicsContainer;  
  5.            // 获得MapFrame  
  6.        IMapFrame mapFrame = container.FindFrame(pActiveView.FocusMap) as IMapFrame;  
  7.            //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround  
  8.            UID uid = new UIDClass();  
  9.            uid.Value = "esriCarto.Legend";  
  10.        IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);  
  11.            //设置图例的Title  
  12.            ILegend2 legend = mapSurroundFrame.MapSurround as ILegend2;  
  13.            legend.Title = "地图图例";  
  14.            ILegendFormat format = new LegendFormatClass();  
  15.            ITextSymbol symbol = new TextSymbolClass();  
  16.            symbol.Size = 4;  
  17.            format.TitleSymbol = symbol;  
  18.            legend.Format = format;  
  19.            //QI,确定mapSurroundFrame的位置  
  20.            IElement element = mapSurroundFrame as IElement;  
  21.            IEnvelope envelope = new EnvelopeClass();  
  22.            envelope.PutCoords(2, 2, 8, 8);  
  23.            element.Geometry = envelope;  
  24.            //使用IGraphicsContainer接口添加显示  
  25.            container.AddElement(element, 0);  
  26.            pActiveView.Refresh();  
  27.  }  

    指北针

C#代码  收藏代码
  1. public void AddNorthArrow(IPageLayout pageLayout)  
  2.        {  
  3.             IGraphicsContainer container = pageLayout as IGraphicsContainer;   
  4.             IActiveView activeView = pageLayout as IActiveView;   
  5.             // 获得MapFrame  
  6.             IFrameElement frameElement = container.FindFrame(activeView.FocusMap);  
  7.             IMapFrame mapFrame = frameElement as IMapFrame;  
  8.             //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround  
  9.             UID uid = new UIDClass();  
  10.             uid.Value = "esriCarto.MarkerNorthArrow";  
  11.         IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);  
  12.             //设置MapSurroundFrame中指北针的点符号  
  13.             IMapSurround mapSurround = mapSurroundFrame.MapSurround;  
  14.             IMarkerNorthArrow markerNorthArrow = mapSurround as IMarkerNorthArrow;   
  15.             IMarkerSymbol markerSymbol = markerNorthArrow.MarkerSymbol;  
  16.             markerSymbol.Size = 18;  
  17.             markerNorthArrow.MarkerSymbol = markerSymbol;  
  18.             //QI,确定mapSurroundFrame的位置  
  19.             IElement element = mapSurroundFrame as IElement;  
  20.             IEnvelope envelope = new EnvelopeClass();  
  21.             envelope.PutCoords(0.2, 0.2, 5, 5);  
  22.             element.Geometry = envelope;  
  23.             //使用IGraphicsContainer接口添加显示  
  24.             container.AddElement(element, 0);  
  25.             activeView.Refresh();  
  26.  }  

 

   比例尺

C#代码  收藏代码
  1. public void AddScalebar(IPageLayout pageLayout)  
  2.         {  
  3.             IGraphicsContainer container = pageLayout as IGraphicsContainer;   
  4.             IActiveView activeView = pageLayout as IActiveView;  
  5.             // 获得MapFrame  
  6.             IFrameElement frameElement = container.FindFrame(activeView.FocusMap);  
  7.             IMapFrame mapFrame = frameElement as IMapFrame;  
  8.            //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround  
  9.             UID uid = new UIDClass();  
  10.             uid.Value = "esriCarto.AlternatingScaleBar";  
  11.       IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);  
  12.             //设置MapSurroundFrame中比例尺的样式  
  13.             IMapSurround mapSurround = mapSurroundFrame.MapSurround;  
  14.             IScaleBar markerScaleBar = ((IScaleBar)mapSurround);  
  15.             markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow;  
  16.             markerScaleBar.UseMapSettings();  
  17.             //QI,确定mapSurroundFrame的位置  
  18.             IElement element = mapSurroundFrame as IElement;  
  19.             IEnvelope envelope = new EnvelopeClass();  
  20.             envelope.PutCoords(0.2, 0.2, 1, 2);   
  21.             element.Geometry = envelope;  
  22.             //使用IGraphicsContainer接口添加显示  
  23.             container.AddElement(element, 0);  
  24.             activeView.Refresh();  
  25.    }  

 

   图例

C#代码  收藏代码
  1. private void AddLegend(IPageLayout pageLayout)  
  2.        {  
  3.            IActiveView pActiveView = pageLayout as IActiveView;  
  4.            IGraphicsContainer container = pageLayout as IGraphicsContainer;  
  5.            // 获得MapFrame  
  6.        IMapFrame mapFrame = container.FindFrame(pActiveView.FocusMap) as IMapFrame;  
  7.            //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround  
  8.            UID uid = new UIDClass();  
  9.            uid.Value = "esriCarto.Legend";  
  10.        IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);  
  11.            //设置图例的Title  
  12.            ILegend2 legend = mapSurroundFrame.MapSurround as ILegend2;  
  13.            legend.Title = "地图图例";  
  14.            ILegendFormat format = new LegendFormatClass();  
  15.            ITextSymbol symbol = new TextSymbolClass();  
  16.            symbol.Size = 4;  
  17.            format.TitleSymbol = symbol;  
  18.            legend.Format = format;  
  19.            //QI,确定mapSurroundFrame的位置  
  20.            IElement element = mapSurroundFrame as IElement;  
  21.            IEnvelope envelope = new EnvelopeClass();  
  22.            envelope.PutCoords(2, 2, 8, 8);  
  23.            element.Geometry = envelope;  
  24.            //使用IGraphicsContainer接口添加显示  
  25.            container.AddElement(element, 0);  
  26.            pActiveView.Refresh();  
  27.  }  
原创粉丝点击