Using the MapControl


The MapControl corresponds to the ‘data’ view of the ArcMap desktop application and encapsulates the Map object. Map documents preauthored with the ArcMap application can be loaded into the MapControl eliminating the need to programmatically compose the cartography.

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 will read the map document whenever the MapControl is created on the container and display the most recent updates to the map document. When containing, the MapControl will copy the contents of the map document into the MapControl but will not display any further updates made to the map document from that point onwards. Containing increases the size of the application 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 in the map document. The ReadMxMaps can be used in conjunction with the LoadMxFile method to load a specific Map from a map document into the MapControl.

Saving map documents

As well as reading map documents, the MapControl can also write map documents (*.mxd). The MapControl implements the IMxdContents interface that enables the MapDocument object to write the contents of the MapControl to a new map document.

Layers

The MapControl provides shortcuts to frequently used members on 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.

Display

The display area of the MapControl 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 TrackRectangle method into the Extent property. Shapes can be drawn on the display with the DrawShape, DrawText, and FlashShape methods typically in the IMapControl2::OnAfterDraw event.






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