Exemple #1
0
        private void New_Click(object sender, EventArgs e)
        {
            //询问是否保存当前地图
            DialogResult res = MessageBox.Show("是否保存当前地图?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (res == DialogResult.Yes)
            {
                //如果要保存,调用另存为对话框
                ICommand command = new ControlsSaveAsDocCommandClass();
                if (m_mapControl != null)
                {
                    command.OnCreate(m_controlsSynchronizer.MapControl.Object);
                }
                else
                {
                    command.OnCreate(m_controlsSynchronizer.PageLayoutControl.Object);
                }
                command.OnClick();
            }
            //创建新的地图实例
            IMap map = new MapClass();

            map.Name = "Map";
            m_controlsSynchronizer.MapControl.DocumentFilename = string.Empty;
            //更新新建地图实例的共享地图文档
            m_controlsSynchronizer.ReplaceMap(map);
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add OpenNewMapDocument.OnClick implementation
            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);
                    IMap map = mapDoc.get_Map(0);
                    m_controlsSynchronizer.ReplaceMap(map);
                    mapDoc.Close();
                }
            }
        }