m_pageLayoutControl.PageLayout.ReplaceMaps(maps); //assign the new map to the MapControl //把新的map赋给MapControl m_mapControl.Map = newMap;
//reset the active tools //重设active tools
m_pageLayoutActiveTool = null; m_mapActiveTool = null;
//make sure that the last active control is activated //确定最后活动的control被激活 if (activateMapFirst) this.ActivateMap(); else
this.ActivatePageLayout(); }
///
///by passing the application's toolbars and TOC to the synchronization class, it saves you the
///management of the buddy control each time the active control changes. This method ads the framework
///control to an array; once the active control changes, the class iterates through the array and
///calles SetBuddyControl on each of the stored framework control. ///
///
public void AddFrameworkControl(object control) {
if (control == null) throw new Exception(\control is not initialized!\
m_frameworkControls.Add(control); }
///
/// Remove a framework control from the managed list of controls ///
///
public void RemoveFrameworkControl(object control) {
if (control == null) throw new Exception(\to be removed is not initialized!\
m_frameworkControls.Remove(control); }
///
/// Remove a framework control from the managed list of controls by specifying its index in the list
///
///
public void RemoveFrameworkControlAt(int index) {
if (m_frameworkControls.Count < index) throw new Exception(\
m_frameworkControls.RemoveAt(index); }
///
/// when the active control changes, the class iterates through the array of the framework controls
/// and calles SetBuddyControl on each of the controls. ///
///
try {
if (buddy == null)
throw new Exception(\Buddy Control is not initialized!\
foreach (object obj in m_frameworkControls) {
if (obj is IToolbarControl) {
((IToolbarControl)obj).SetBuddyControl(buddy); }
else if (obj is ITOCControl) {
((ITOCControl)obj).SetBuddyControl(buddy); } } }
catch (Exception ex) {
throw
Exception(string.Format(\ } }
#endregion } }
new
2、新建Maps类
在同步类中,要用到Maps类,用于管理地图对象。与新建同步类ControlsSynchronizer类似,我们新建一Maps类,其所有代码如下所示:
using System;
using System.Collections;
using System.Collections.Generic; using System.Text;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.Carto;
namespace _sdnMap {
[Guid(\ [ClassInterface(ClassInterfaceType.None)] [ProgId(\
public class Maps : IMaps, IDisposable {
//class member - using internally an ArrayList to manage the Maps collection private ArrayList m_array = null;
#region class constructor public Maps() {
m_array = new ArrayList(); }
#endregion
#region IDisposable Members
///
/// Dispose the collection ///
public void Dispose() {
if (m_array != null) {
m_array.Clear(); m_array = null; } }
#endregion
#region IMaps Members
///
/// Remove the Map at the given index ///
///
if (Index > m_array.Count || Index < 0)
throw new Exception(\
m_array.RemoveAt(Index); }
///
/// Reset the Maps array /// public void Reset() {
m_array.Clear(); }
///
/// Get the number of Maps in the collection /// public int Count {
get {
return m_array.Count; } }
///
/// Return the Map at the given index ///
///
public IMap get_Item(int Index) {
if (Index > m_array.Count || Index < 0)
throw new Exception(\
return m_array[Index] as IMap; }
///
/// Remove the instance of the given Map ///
///
m_array.Remove(Map); }
///
/// Create a new Map, add it to the collection and return it to the caller ///
///
IMap newMap = new MapClass(); m_array.Add(newMap);
return newMap; }
///
/// Add the given Map to the collection ///
///
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库ArcGIS Engine+C# 初学者实例代码(4)在线全文阅读。
相关推荐: