Arcgisengine AE 出图生成专题图插入要素总结

时间:2013-7-26    作者:悬浮的青春    分类: gis二次开发


一、前言

    在地图出图中插入文字、指北针、比例尺、图例





插入普通文字要素ITextElement



public override void OnMouseDown(int Button, int Shift, int X, int Y)

        {

            frmSymbology3 frmSymbologyNew = new frmSymbology3();

            frmSymbologyNew.SymbolType = EnumSymbolType.stTextSymbol;

            frmSymbologyNew.InitialSymbol = MethodSymbol.GetInitialRandomSymbol(EnumSymbolType.stTextSymbol);

            object pSymbol = null;

            if (frmSymbologyNew.ShowDialog() == DialogResult.OK)

            {

                pSymbol = frmSymbologyNew.SelectedSymbol;

            }



            if (pSymbol == null)

                return;

            ITextElement pTextElement = new TextElementClass();

            pTextElement.ScaleText = false;

            pTextElement.Symbol = pSymbol as ITextSymbol;

            pTextElement.Text = (pSymbol as ITextSymbol).Text;



            IPoint pPoint = this.m_HookHelperJP.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

            IElement element = pTextElement as IElement;

            element.Geometry = pPoint;

            this.m_HookHelperJP.MapService.PageLayoutControl.GraphicsContainer.AddElement(element, 0);

            IGraphicsContainerSelect pGraphicsContainerSelect = this.m_HookHelperJP.MapService.PageLayout as IGraphicsContainerSelect;

            pGraphicsContainerSelect.UnselectAllElements();

            pGraphicsContainerSelect.SelectElement(element);

            this.m_HookHelperJP.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

            //this.m_HookHelperJP.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, element, null);

            this.m_HookHelperJP.MapService.CurrentTool = null;

        }


插入气泡式文本符号

气泡式符号ICallout 
默认情况下冲AE符号库中获取的文字符号在插入时没有设置AnchorPoint,需要进行
如下设置,才能达到效果。 
IFormattedTextSymbol pFormattedTextSymbol = pSymbol as IFormattedTextSymbol;   

          if (pFormattedTextSymbol.Background != null)             


                if (pFormattedTextSymbol.Background is ICallout)   

              { 
                    ICallout pCallout = pFormattedTextSymbol.Background as ICallout;  

                   pCallout.AnchorPoint = pPoint; 
                } 







插入图框式文本符号
图框文字符号IMarkerTextBackground 
需要设置ITextBackground.TextSymbol的样式,默认获取的文字符号是没有这个设置的,只有设置了才能达到如图的效果。 如下: 
IFormattedTextSymbol pFormattedTextSymbol = pSymbol as IFormattedTextSymbol;            

if (pFormattedTextSymbol.Background != null)           

  { 
                if (pFormattedTextSymbol.Background is IMarkerTextBackground)       

          { 
                    IMarkerTextBackground pMarkerTextBackground = pFormattedTextSymbol.Background as IMarkerTextBackground;                    

 pMarkerTextBackground.ScaleToFit = true; 


                    pMarkerTextBackground.TextSymbol = 
MethodSymbol.GetInitialRandomSymbol(EnumSymbolType.stTextSymbol) as ITextSymbol;       

          } 
            

}



插入指北针


public void AddNorthArrow(ESRI.ArcGIS.Carto.IPageLayout pageLayout, ESRI.ArcGIS.Carto.IMap map)
{
  
  if(pageLayout == null || map == null)
  {
    return;
  }
  ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
  envelope.PutCoords(0.2, 0.2, 5, 5); //  Specify the location and size of the north arrow

  ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
  uid.Value = "esriCarto.MarkerNorthArrow";

  // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location
  // Activate it and add it to the PageLayout's graphics container
  ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer; // Dynamic Cast
  ESRI.ArcGIS.Carto.IActiveView activeView = pageLayout as ESRI.ArcGIS.Carto.IActiveView; // Dynamic Cast
  ESRI.ArcGIS.Carto.IFrameElement frameElement = graphicsContainer.FindFrame(map);
  ESRI.ArcGIS.Carto.IMapFrame mapFrame = frameElement as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast
  ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast
  ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast
  element.Geometry = envelope;
  element.Activate(activeView.ScreenDisplay);
  graphicsContainer.AddElement(element, 0);
  ESRI.ArcGIS.Carto.IMapSurround mapSurround = mapSurroundFrame.MapSurround;

  // Change out the default north arrow
  ESRI.ArcGIS.Carto.IMarkerNorthArrow markerNorthArrow = mapSurround as ESRI.ArcGIS.Carto.IMarkerNorthArrow; // Dynamic Cast
  ESRI.ArcGIS.Display.IMarkerSymbol markerSymbol = markerNorthArrow.MarkerSymbol;
  ESRI.ArcGIS.Display.ICharacterMarkerSymbol characterMarkerSymbol = markerSymbol as ESRI.ArcGIS.Display.ICharacterMarkerSymbol; // Dynamic Cast
  characterMarkerSymbol.CharacterIndex = 200; // change the symbol for the North Arrow
  markerNorthArrow.MarkerSymbol = characterMarkerSymbol;
}



插入比例尺

插入文本比例尺

      public void addScaleText()

        {

            

                IEnvelope envelope = new EnvelopeClass();

                envelope.PutCoords(16, 0.6, 16, 1);

            #region 选项

            IScaleText pScaleText = new ScaleTextClass();

            pScaleText.Map = this.axPageLayoutControl1.ActiveView.FocusMap;

            //当设置esriScaleTextStyleEnum.esriScaleTextAbsolute时不用设置单位

            //pScaleText.MapUnits = this.this.axPageLayoutControl1.ActiveView.FocusMap.MapUnits;

            //string sMapUnitLabel = Enum.GetName(typeof(EnumDisplayUnits), (int)this.axPageLayoutControl1.ActiveView.FocusMap.MapUnits);

            //pScaleText.MapUnitLabel = sMapUnitLabel;

            //pScaleText.PageUnits = this.axPageLayoutControl1.ActiveView.FocusMap.MapUnits;

            //pScaleText.PageUnitLabel = sMapUnitLabel;

            pScaleText.Name = "比例尺";

            pScaleText.Style = esriScaleTextStyleEnum.esriScaleTextAbsolute;

            ITextSymbol pTextSymbol = MethodSymbol.GetInitialRandomSymbol(EnumSymbolType.stTextSymbol) as ITextSymbol;

            pTextSymbol.Size = 20;

            pTextSymbol.Font.Bold = true;

            pScaleText.Symbol = pTextSymbol;



            //数字样式设置

            INumericFormat pNumberFormat = new NumericFormatClass();

            pNumberFormat.AlignmentOption = esriNumericAlignmentEnum.esriAlignLeft;

            pNumberFormat.AlignmentWidth = 12;

            pNumberFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfSignificantDigits;

            //pNumberFormat.RoundingValue = 0;

            pNumberFormat.UseSeparator = true;

            pNumberFormat.ShowPlusSign = false;

            pNumberFormat.ZeroPad = false;

            pScaleText.NumberFormat = pNumberFormat as INumberFormat;

            #endregion



            IMapFrame mapFrame = (IMapFrame)axPageLayoutControl1.ActiveView.GraphicsContainer.FindFrame(this.axPageLayoutControl1.ActiveView.FocusMap);

            IMapSurroundFrame mapSurroundFrame = new MapSurroundFrameClass();

            mapSurroundFrame.MapFrame = mapFrame;

            mapSurroundFrame.MapSurround = pScaleText;



            IElement element = mapSurroundFrame as IElement;

            element.Geometry = envelope;

          IGraphicsContainer pGraphicsContainer = this.axPageLayoutControl1.PageLayout as IGraphicsContainer;

            pGraphicsContainer .AddElement(element, 0);

            

            this.axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

        

           

        }


插入比例尺bar




IMap pMap = this.axPageLayoutControl1.ActiveView.FocusMap;

            IGraphicsContainer pGraphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer;

            IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;

            UID pUID = new UIDClass();

            pUID.Value = "{6589F146-F7F7-11d2-B872-00600802E603}";

            IMapSurroundFrame pScaleLine = pMapFrame.CreateSurroundFrame(pUID, null);

            IEnvelope pMarkEnvelope = new EnvelopeClass();

            double xMin, yMin, xMax, yMax;


            IEnvelope pMapFrameEnvelope;
            
            pMapFrame.ExtentType = esriExtentTypeEnum.esriExtentScale;
            IElement pMapFrameElement = pMapFrame as IElement;
            pMapFrameEnvelope = pMapFrameElement.Geometry.Envelope;
            pMapFrameEnvelope.QueryCoords(out xMin, out yMin, out xMax, out yMax);
            pMarkEnvelope.PutCoords(xMax - 6, yMin + 1, xMax, yMin + 3);

            IStyleSelector pStyleselector;
            pStyleselector = new ScaleBarSelectorClass();
            bool ok;
            ok = pStyleselector.DoModal(0);
            if (!ok) return;

            IScaleBar pScarbar = pStyleselector.GetStyle(0) as IScaleBar;
            pScarbar.BarHeight = 1;
            pScarbar.Division = 0;
            pScarbar.Subdivisions = 0;
            pScarbar.UnitLabelGap = 0;
            pScarbar.UnitLabel = "千米";
            pScarbar.Units = esriUnits.esriMeters;
            pScarbar.LabelPosition = esriVertPosEnum.esriBelow;

            ITextSymbol pTextsymbol = new TextSymbolClass();
            pTextsymbol.Size = 1;
            stdole.StdFont pFont = new stdole.StdFontClass();
            pFont.Size = 1;
            pFont.Name = "Arial";
            pTextsymbol.Font = pFont as stdole.IFontDisp;


            pTextsymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
            pScarbar.UnitLabelSymbol = pTextsymbol;
            pScarbar.LabelSymbol = pTextsymbol;

            INumericFormat pNumericFormat = new NumericFormatClass();
            pNumericFormat.AlignmentWidth = 0;
            pNumericFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfSignificantDigits;
            pNumericFormat.RoundingValue = 0;
            pNumericFormat.UseSeparator = true;
            pNumericFormat.ShowPlusSign = false;

            INumberFormat pNumberFormat = pNumericFormat as INumberFormat;
            pScarbar.NumberFormat = pNumberFormat;

            IMapSurround pMapSurround = pScarbar as IMapSurround;
            pScaleLine.MapSurround = pMapSurround;


            this.axPageLayoutControl1.AddElement(pScaleLine as IElement, pMarkEnvelope, Type.Missing, Type.Missing, 0);
             this.axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);




五、插入图例


public void AddMapSurround(IPageLayout pageLayout, IActiveView activeView)
{
    IMap map = activeView.FocusMap;
    IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;
    IFrameElement frameElement = graphicsContainer.FindFrame(map);
    IMapFrame mapFrame = (IMapFrame)frameElement;
    IMapSurroundFrame mapSurroundFrame = new MapSurroundFrameClass();
    UID elementUID = new UIDClass();

    //The value determines the type of MapSurroundFrame being added.
    elementUID.Value = "esriCarto.Legend";

    //The CreateSurroundFrame method takes the UID of the element and an optional style.
    mapSurroundFrame = mapFrame.CreateSurroundFrame(elementUID, null);
    mapSurroundFrame.MapSurround.Name = "Legend";

    //Cast the MapSurroundFrame as an element so it can be inserted into the page layout.
    IElement doc_Element = mapSurroundFrame as IElement;
    IElement mainMap_Element = mapFrame as IElement;
    IGeometry geometry = mainMap_Element.Geometry;
    IEnvelope mainMap_Envelope = geometry.Envelope;
    IEnvelope envelope = new EnvelopeClass();
    double xMin = mainMap_Envelope.XMax + 1.5;
    double yMin = mainMap_Envelope.YMin + 1.5;
    double xMax = mainMap_Envelope.XMax - 1.5;
    double yMax = mainMap_Envelope.YMax - 1.5;
    envelope.PutCoords(xMin, yMin, xMax, yMax);

    doc_Element.Geometry = envelope as IGeometry;
    doc_Element.Activate(activeView.ScreenDisplay);
    graphicsContainer.AddElement(doc_Element, 0);

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


标签: arcgis二次开发 arcgis

WRITTEN BY

avatar


评论:

安子熙 2013-08-20 14:52
AcrGIS Engine在哪里可以下载到呀?我找了很多都不能用,如果方便能发我邮箱吗?397113513@qq.com,谢谢了
悬浮的青春 2013-08-23 13:52
@安子熙:好的。已经发送。