您的位置:首页 > 移动开发 > Objective-C

小菜的ArcObjects学习之路------操作Map Surrounds

2012-07-26 17:09 337 查看
操作Map Surrounds

Map Surrounds是地图对象伴随的特殊元素。指北针是一个好的例子介绍Map Surrounds和他们的功能。指北针是内置的Map Surrounds,使他们能够响应地图轮换。地图旋转时,其指北针旋转相同的程度。

本主题中的第一个代码示例添加了一个Legend的页面布局。指北针和Legend是Map Surround的类型。所有的Map Surrounds在MapSurroundFrame容器持有,一个元素对象,这个框架是涉及到MapFrame。这种关系可以,例如,旋转其相关的地图指北针自动旋转,告诉包含图层和符号地图的Legend。第二个代码示例演示如何通过MapSurroundFrame访问Map Surrounds。

下面的代码示例显示了如何添加MapSurroundFrame到一个给定的地图页面布局:

[C#]

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

//该值决定添加MapSurroundFrame的类型。

elementUID.Value = "esriCarto.Legend";

// CreateSurroundFrame的方法需要元素的UID和一个可选的风格。

mapSurroundFrame = mapFrame.CreateSurroundFrame(elementUID, null);

mapSurroundFrame.MapSurround.Name = "Legend";

// MapSurroundFrame可以被转换成元素的,因此它可以被插入到页面布局。

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

}

下面的代码示例演示如何查找和访问MapSurroundFrame:

public void ReportMapSurrounds(IPageLayout pageLayout)

{

//获取页面布局作为一个图形容器。

IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;

graphicsContainer.Reset();

IElement element = graphicsContainer.Next();



//通过图形容器的枚举,寻找所有MapSurroundFrames。

while (element != null)

{

if (element is IMapSurroundFrame)

{

IMapSurroundFrame mapSurroundFrame = element as IMapSurroundFrame;

IMapSurround mapSurround = mapSurroundFrame.MapSurround;

IMap map = mapSurround.Map;

//如果SurroundFrame发现,报告Surroud名称与它相关的地图的名称。

string mapSurroundName = mapSurround.Name;

string mapName = map.Name;

MessageBox.Show("Found mapsurround " + mapSurroundName +

" associated with map " + mapName);

}

element = graphicsContainer.Next();

}

}

Working with map surrounds

About working with map surrounds

Map surrounds are specific types of elements that are associated with a Map object. A good example of a map surround and its capabilities is the north arrow. North arrows are built as map surrounds so that they can respond to map rotation. When a map is rotated,
its north arrow is rotated the same degree.

The first code example in this topic adds a legend to the page layout. North arrows and legends are types of map surrounds. All map surrounds are held in a MapSurroundFrame container, an element object, and this frame is related to a MapFrame. This relationship
enables, for example, north arrows to automatically rotate when their related map is rotated, and it tells the legends which layers and symbology a map contains. The second code example shows how to access the map surrounds through the MapSurroundFrame.

The following code example shows how to add a MapSurroundFrame to a given map and page layout:

[C#]

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

}

The following code example shows how to find and access the MapSurroundFrame:

[C#]

publicvoid ReportMapSurrounds(IPageLayout pageLayout)

{

//Get the page layout as a graphics container.

IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;

graphicsContainer.Reset();

IElement element = graphicsContainer.Next();

//Enumerate through the graphics container, finding all MapSurroundFrames.while (element != null)

{

if (element is IMapSurroundFrame)

{

IMapSurroundFrame mapSurroundFrame = element as IMapSurroundFrame;

IMapSurround mapSurround = mapSurroundFrame.MapSurround;

IMap map = mapSurround.Map;

//If a SurroundFrame is found, report the name of the surround and//the name of the map with which it is associated. string mapSurroundName = mapSurround.Name;

string mapName = map.Name;

MessageBox.Show("Found mapsurround " + mapSurroundName +

" associated with map " + mapName);

}

element = graphicsContainer.Next();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: