arcgis engine - 添加图例,指北针.

esri帮助提供了使用比例尺的方法: Working with map surrounds

主要代码为:

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);

}

 在实现地图同步后,分别获得IMap和IPageLayout对象,并调用之即可,如

//mapDoc.get_Map(0)

IMap map;

//map = map_Big.ActiveView as IMap;

IPageLayout pageLayout = pageLayoutCtrl.ActiveView as IPageLayout;

AddMapSurround(pageLayout, map_Big.ActiveView);

 

esri也提供使用指北针的方法,主要方法为:

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;

}

 ref: http://blog.csdn.net/freeWayWalker/article/details/25633859

esri: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//00490000004w000000

你可能感兴趣的:(ArcGis Engine)