This document is archived and information here might be outdated.  Recommended version.


Using the MapControl (ArcObjects .NET 10.4 SDK)

Using the MapControl


Summary
This topic discusses the MapControl and highlights working with map layers, the map display, and loading and saving map documents.

In this topic


About using the MapControl

The MapControl corresponds to the data view of the ArcMap application and encapsulates the Map object. Map documents preauthored with ArcMap, can be loaded into the MapControl, eliminating the need to programmatically compose the cartography. See the following screen shot:

Loading map documents

The map document can be set at design time though the MapControl property pages (in development environments that support property page capability), and the MapControl can be set to link or contain the map document.
  • When linking, the MapControl reads the map document when the MapControl is created on the container, and displays the most recent updates to the map document.
  • When containing, the MapControl copies the contents of the map document into the MapControl but does not display further updates made to the map document from that point forward. Containing increases the size of the application's executable containing the MapControl.
Alternatively, a map document can be loaded into the MapControl programmatically using the CheckMxFile method to determine whether the document is valid and the LoadMxFile method to load the map document.
The ReadMxMaps method can be used in conjunction with the LoadMxFile method to load a specific Map from a map document into the MapControl. See the following code example:
[C#]
string filePath=@"C:\Temp\myDocument.mxd";
if (axMapControl1.CheckMxFile(filePath))
    axMapControl1.LoadMxFile(filePath, Type.Missing, Type.Missing);
[VB.NET]
Dim sFilePath As String
sFilePath="C:\Temp\myDocument.mxd"
If AxMapControl1.CheckMxFile(sFilePath) Then AxMapControl1.LoadMxFile(sFilePath, "", "")

Saving map documents

In addition to reading map documents, the MapControl can also write map documents (*.mxd). The MapControl implements IMxdContents, which enables the MapDocument object to write the contents of the MapControl to a new map document.

Managing layers

The MapControl provides shortcuts to frequently used members of the Map object, such as, AddLayer, DeleteLayer, and ClearLayers; and helper members, such as, AddLayerFromFile, AddShapefile, and MoveLayerTo, to manage the individual layers within the map.

Altering the display

The MapControl's display area can be altered by using the VisibleRegion property to change the shape of the display area and the Rotation property to alter the angle at which data is drawn on the display.
Helper methods, such as, TrackRectangle, TrackPolygon, TrackLine, and TrackCircle exist on the MapControl for tracking or "rubber banding" shapes on the display. For example, to zoom in on the display, set the Envelope returned from the TrackRectangle method into the Extent property.
Shapes can be drawn on the display with the DrawShape, DrawText, and FlashShape methods, typically in the IMapControlEvents2.OnAfterDraw event.


See Also:

Controls library overview
Working with the map
Working with the map display
How to get started with the MapControl property pages
How to load a password-protected document
How to enable arrow key and mouse wheel navigation of the map display
How to rotate the MapControl display
How to drop data onto the MapControl
How to display MapControl and ToolbarControl information on a status bar
Samples:




Development licensing Deployment licensing
Engine Developer Kit Engine
ArcGIS for Desktop Basic
ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced