ReplaceMap() public method

given a new map, replaces the PageLayoutControl and the MapControl's focus map
public ReplaceMap ( IMap newMap ) : void
newMap IMap
return void
Esempio n. 1
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            //launch a new OpenFile dialog
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter      = "Map Documents (*.mxd)|*.mxd";
            dlg.Multiselect = false;
            dlg.Title       = "Open Map Document";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string docName = dlg.FileName;

                IMapDocument mapDoc = new MapDocumentClass();
                if (mapDoc.get_IsPresent(docName) && !mapDoc.get_IsPasswordProtected(docName))
                {
                    mapDoc.Open(docName, string.Empty);

                    // set the first map as the active view
                    IMap map = mapDoc.get_Map(0);
                    mapDoc.SetActiveView((IActiveView)map);

                    m_controlsSynchronizer.PageLayoutControl.PageLayout = mapDoc.PageLayout;

                    m_controlsSynchronizer.ReplaceMap(map);

                    mapDoc.Close();

                    m_sDocumentPath = docName;
                }
            }
        }
        /// <summary>
        /// New Map document menu event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuNewDoc_Click(object sender, System.EventArgs e)
        {
            //ask the user whether he'd like to save the current doc
            DialogResult res = MessageBox.Show("Would you like to save the current document?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (res == DialogResult.Yes)
            {
                //if yes, launch the SaveAs command
                ICommand command = new ControlsSaveAsDocCommandClass();
                command.OnCreate(m_controlsSynchronizer.PageLayoutControl.Object);
                command.OnClick();
            }

            // switch to map view
            tabControl1.SelectedTab = (TabPage)tabControl1.Controls[0];

            //create a new Map instance
            IMap map = new MapClass();

            map.Name = "Map";
            //replace the shared map with the new Map instance
            m_controlsSynchronizer.ReplaceMap(map);

            m_documentFileName = string.Empty;
        }