In this topic
- Synchronizing MapControl and PageLayoutControl
Synchronizing MapControl and PageLayoutControl
A common task for an ArcGIS Engine developer is to synchronize (in the same application) a map used by the MapControl with the focus map of the PageLayoutControl. For example, an application can have one tab containing a MapControl and one tab containing a PageLayoutControl, with both displaying the same map data. Any changes made to a map in one control must be reflected in the other control when its tab is activated.
Differences between ArcMap and ArcGIS Engine controls
Consider the following differences between ArcMap and ArcGIS Engine controls:
- ArcMap has two views (that is, page layout view and data frame view, also known as, map view). These views share the same map object. For example, if some features are selected in map view, the same feature selection is visible on the map in page layout view; however, the map object can only be active in one view, the IActiveView is on a PageLayout or map.
- ArcGIS Engine MapControl and PageLayoutControl do not automatically know about each other in an application since they do not share the same map object. For example, if the map extent is changed in the MapControl, the new map extent is not reflected on the focus map of the PageLayoutControl.
The synchronization that ArcMap provides can be implemented with the MapControl and PageLayoutControl as follows:
- Listen to the events fired by a map object when it is changed on the MapControl and PageLayoutControl, and make the same change in the other control. For example, the IActiveViewEvents.itemAdded event is fired when a new layer is added to the map in the MapControl. When the event is fired, the same layer needs to be programmatically added to the focus map within the PageLayoutControl. This method of synchronization is not recommended due to the number of events that need to be listened to for trapping all possible changes that can be made to a map object.
- If a change is made to the focus map of the PageLayoutControl, the ObjectCopy object can be used to copy (deep clone) the map object and the resulting map copy can be set into the MapControl. Each map contained in the PageLayout encapsulated by the PageLayoutControl, resides in a separate MapFrame and therefore, has its IMap.isFramed() method set to true. A map contained within the MapControl does not reside within a MapFrame. As such, before overwriting the MapControl's map, the IMap.isFramed() method must be set to false. (Failure to do this leads to corrupted map documents saved containing the contents of the MapControl.) This method of synchronization is recommended when copying a map from the PageLayoutControl into the MapControl, but not when copying a map from the MapControl into the PageLayoutControl. The PageLayoutControl encapsulates the PageLayout object that manages both MapFrame objects containing map objects and objects implementing IMapSurround, such as north arrows and scale bars. Each map surround contains a pointer to the map. If the map is replaced with a map copied from the MapControl, the map surround frames no longer point to a valid map, which can lead to application errors.
- The recommended method of synchronization to ensure the MapControl and PageLayoutControl reference the same map instance, is to call IPageLayout.replaceMaps on the PageLayoutControl or set IMapControlDefault.setMapByRef() on the MapControl. The IPageLayout.replaceMaps method expects an object implementing IMaps. Since there is no object in ArcGIS Engine that implements IMaps, create your class to implement IMaps. To ensure there is only one ActiveView, call IActiveView.deactivate() on the control losing focus and IActiveView.activate() on the control gaining focus in the application. Failure to do this results in the flickering of the MapControl or PageLayoutControl.
See Also:Sample: Copy focus map
|Development licensing||Deployment licensing|
|Engine Developer Kit||ArcGIS for Desktop Basic|
|ArcGIS for Desktop Standard|
|ArcGIS for Desktop Advanced|