/// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add OpenMxdCommand.OnClick implementation

            //launch a new OpenFile dialog
            OpenFileDialog pOpenFileDialog = new OpenFileDialog();
            pOpenFileDialog.Filter = "Map Documents (*.mxd)|*.mxd";
            pOpenFileDialog.Multiselect = false;
            pOpenFileDialog.Title = "Open Map Document";
            if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                string docName = pOpenFileDialog.FileName;

                IMapDocument pMapDoc = new MapDocumentClass();
                if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName))
                {

                    pMapControl.LoadMxFile(pOpenFileDialog.FileName, null, null);

                    // set the first map as the active view

                    pMapControl.ActiveView.Refresh();

                    pMapDoc.Close();

                }
            }
        }
예제 #2
0
        /// <summary>
        /// Opens mxd document.
        /// </summary>
        /// <param name="sMxdFilePath">The  MXD file path.</param>
        public static void OpenDocument(string sMxdFilePath)
        {
            IMapDocument mapDocument = new MapDocumentClass();

            if (mapDocument.get_IsPresent(sMxdFilePath) && !mapDocument.get_IsPasswordProtected(sMxdFilePath))
            {
                mapDocument.Open(sMxdFilePath, "");
                try
                {
                    IMap map = mapDocument.get_Map(0);
                    mapDocument.SetActiveView((IActiveView)map);
                    //EnviVars.instance.Synchronizer.PageLayoutControl.PageLayout = mapDocument.PageLayout;
                    //EnviVars.instance.Synchronizer.ReplaceMap(map);
                    EnviVars.instance.MapControl.Map = map;
                    EnviVars.instance.MainForm.Text  = sMxdFilePath;
                }
                catch (Exception ex)
                {
                    //_logger.Log(LogLevel.Error, EventType.UserManagement, null, ex);
                    Log.WriteLog(typeof(MapAPI), ex);
                }
                finally
                {
                    mapDocument.Close();
                }
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add OpenNewMapDocument.OnClick implementation
            //launch a new OpenFile dialog
            System.Windows.Forms.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 pMapDoc = new MapDocumentClass();
                if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName))
                {
                    // 以下3.3.3.1代码

                    /* pMapControl.LoadMxFile(dlg.FileName, null, null);
                     * pMapControl.ActiveView.Refresh();
                     * pMapDoc.Close();                     */
                    // 以下3.3.3.5代码
                    pMapDoc.Open(docName, string.Empty);
                    IMap map = pMapDoc.get_Map(0);
                    pMapDoc.SetActiveView((IActiveView)map);
                    pControlsSynchronizer.PageLayoutControl.PageLayout = pMapDoc.PageLayout;
                    pControlsSynchronizer.ReplaceMap(map);
                    pMapDoc.Close();
                }
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add OpenMxdCommand.OnClick implementation

            //launch a new OpenFile dialog
            OpenFileDialog pOpenFileDialog = new OpenFileDialog();

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

                IMapDocument pMapDoc = new MapDocumentClass();
                if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName))
                {
                    pMapControl.LoadMxFile(pOpenFileDialog.FileName, null, null);

                    // set the first map as the active view

                    pMapControl.ActiveView.Refresh();

                    pMapDoc.Close();
                }
            }
        }
        /// <summary>
        /// 作用:打开TemplateMapDocument
        /// 作者:汪建龙
        /// 编写时间:2016年12月23日11:18:34
        /// </summary>
        /// <returns></returns>
        private IMapDocument OpenTemplateDocument()
        {
            try
            {
                IMapDocument tempMapDocumnet = new MapDocumentClass();
                if (!tempMapDocumnet.get_IsPresent(TemplateMxdFileName) ||
                    !tempMapDocumnet.get_IsMapDocument(TemplateMxdFileName) ||
                    tempMapDocumnet.get_IsPasswordProtected(TemplateMxdFileName) ||
                    tempMapDocumnet.get_IsRestricted(TemplateMxdFileName))
                {
                    var message = string.Format("路径:\"{0}\"下的地图文档不正确,请拷贝该文件到该路径下", _templateMxdFileName);
                    System.Diagnostics.Trace.WriteLine(message);
                    return(null);
                }

                tempMapDocumnet.Open(TemplateMxdFileName, null);

                if (tempMapDocumnet.DocumentVersion == esriMapDocumentVersionInfo.esriMapDocumentVersionInfoFail)
                {
                    var message = string.Format("路径:\"{0}\"下的地图文档版本不正确,请拷贝该文件到该路径下", TemplateMxdFileName);
                    return(null);
                }

                return(tempMapDocumnet);
            }catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex);
                return(null);
            }
        }
예제 #6
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>
        /// Occurs when this command is clicked
        /// </summary>
        public void OnClickAutomatic(string docName)
        {
            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();
            }
        }
예제 #8
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public void OnClickAutomatic(string docName)
        {
            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();
            }


            //"C:\\Study\\Data\\Morphing Data\\Administrative Boundary\\Hunan\\Hunan.mxd"
        }
예제 #9
0
        /// <summary>
        /// Occurs when this tool is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add OpenTool.OnClick implementation
            OpenFileDialog OpenMXD = new OpenFileDialog(); //可实例化类

            OpenMXD.Title       = "打开地图";                  // OpenFileDialog类的属性Title
            OpenMXD.Multiselect = false;
            OpenMXD.Filter      = "Map Documents (*.mxd)|*.mxd";
            if (OpenMXD.ShowDialog() == DialogResult.OK) //ShowDialog是类的方法
            {
                string       docName = OpenMXD.FileName;
                IMapDocument pMapDoc = new MapDocumentClass();
                if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName))
                {
                    pMapControl.LoadMxFile(OpenMXD.FileName, null, null);
                    pMapControl.ActiveView.Refresh();
                    pMapDoc.Close();
                }
            }
        }
        /// <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();
                }
            }
        }
예제 #11
0
        /// <summary>
        /// 作用:MapControl加载mxd文件
        /// 作者:汪建龙
        /// 编写时间:2016年12月26日09:49:25
        /// </summary>
        /// <param name="mapControl"></param>
        /// <param name="mxdFile"></param>
        public static void Load(this IMapControl2 mapControl, string mxdFile)
        {
            try
            {
                if (System.IO.File.Exists(mxdFile) == false)
                {
                    return;
                }

                IMapDocument mapDocument = new MapDocumentClass();
                if (!mapDocument.get_IsPresent(mxdFile) ||
                    !mapDocument.get_IsMapDocument(mxdFile) ||
                    mapDocument.get_IsPasswordProtected(mxdFile) ||
                    mapDocument.get_IsRestricted(mxdFile))
                {
                    string message = string.Format("路径:\"{0}\"下的地图文档不正确,请拷贝文件到该路径下。", mxdFile);
                    System.Diagnostics.Trace.WriteLine(message);
                }
                else
                {
                    mapDocument.Open(mxdFile, null);
                    if (mapDocument.DocumentVersion == esriMapDocumentVersionInfo.esriMapDocumentVersionInfoFail)
                    {
                        string message = string.Format("路径:\"{0}\"下的地图文档版本不正确,请拷贝该文件到该路径下。", mxdFile);
                        System.Diagnostics.Trace.WriteLine(message);
                    }
                    else if (mapDocument.MapCount > 0)
                    {
                        IMap map = mapDocument.get_Map(0);
                        mapControl.Map = map;
                    }
                }
            }catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex);
            }
        }
    /// <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;
        }
      }
    }
예제 #13
0
        protected void OpenPastureMapDoc(Pasture pasture)
        {
            IMapDocument mapDoc = new MapDocumentClass();
            if (mapDoc.get_IsPresent(pasture.strMapDoc) &&
                !mapDoc.get_IsPasswordProtected(pasture.strMapDoc))
            {
                mapDoc.Open(pasture.strMapDoc, string.Empty);

                // set the first map as the active view
                m_pastureMap = mapDoc.get_Map(0);
                mapDoc.SetActiveView((IActiveView)m_pastureMap);
                mapDoc.Close();
            }
        }
예제 #14
0
        public override bool LoadMap(string filePath)
        {
            IMapDocument mapDoc = new MapDocumentClass();
            if (mapDoc.get_IsPresent(filePath) && !mapDoc.get_IsPasswordProtected(filePath))
            {
                mapDoc.Open(filePath, string.Empty);
                // set the first map as the active view
                IMap map = mapDoc.get_Map(0);
                mapDoc.SetActiveView((IActiveView)map);
                this._axLayoutCtrl.PageLayout = mapDoc.PageLayout;
                this._mapAndLayoutSync.ReplaceMap(map);
                mapDoc.Close();
                this._mapFile = filePath;
                return true;
            }
            else
            {
                return false;
            }

            /*
            if (this._axMapCtrl.CheckMxFile(filePath))
            {
                


                this._axMapCtrl.LoadMxFile(filePath, Type.Missing, Type.Missing);
                this._axMapCtrl.Enabled = true;
                this._mapFile = filePath;
                return true;
            }
            else
            {
                return false;
            }
            */ 
        }
예제 #15
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            IPageLayoutControl3 pPageLayoutControl = null;

            try
            {
                if (m_hookHelper.Hook is IToolbarControl)
                {
                    pPageLayoutControl = (IPageLayoutControl3)((IToolbarControl)m_hookHelper.Hook).Buddy;
                }
                //In case the container is MapControl
                else if (m_hookHelper.Hook is IPageLayoutControl3)
                {
                    pPageLayoutControl = (IPageLayoutControl3)m_hookHelper.Hook;
                }
                else
                {
                    MessageBox.Show("当前界面必须是PageLayoutControl界面!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            try
            {
                if (string.IsNullOrEmpty(m_strDocName))
                {
                    OpenFileDialog dlgFile = new OpenFileDialog();//以对话框选择文档路径
                    dlgFile.Title  = "打开一个地图文档";
                    dlgFile.Filter = "Map Documents(*.mxd)|*.mxd";
                    if (dlgFile.ShowDialog() == DialogResult.OK)
                    {
                        m_strDocName = dlgFile.FileName;
                    }
                }
                IMapDocument mapDoc = new MapDocumentClass(); //地图文档对象
                IMap         map    = null;
                if (mapDoc.get_IsPresent(m_strDocName) && !mapDoc.get_IsPasswordProtected(m_strDocName))
                {
                    mapDoc.Open(m_strDocName, string.Empty);

                    IMaps maps = new Maps();
                    for (int i = 0; i < mapDoc.MapCount; i++)
                    {
                        maps.Add(mapDoc.get_Map(i));
                    }
                    // set the first map as the active view
                    map = mapDoc.get_Map(0);
                    mapDoc.SetActiveView((IActiveView)map);

                    m_controlsSynchronizer.PageLayoutControl.PageLayout       = mapDoc.PageLayout;
                    m_controlsSynchronizer.PageLayoutControl.Printer          = mapDoc.Printer;
                    m_controlsSynchronizer.PageLayoutControl.DocumentFilename = m_strDocName;
                    //m_controlsSynchronizer.ReplaceMap(map);
                    m_controlsSynchronizer.AddNewMaps(maps);

                    mapDoc.Close();

                    m_strDocName = string.Empty;
                }

                /////////////////////////////
                //关闭属性表
                if (m_barTable.Visible == true)
                {
                    if (m_AttributeRemove != null)
                    {
                        m_AttributeRemove.Clear();
                        m_AttributeRemove.Columns.Clear();
                        m_barTable.Visible = false;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "打开地图文档失败");
            }
        }
예제 #16
0
        /// <summary>
        /// Called when the user clicks a command.
        /// </summary>
        /// <remarks>Note to inheritors: override OnClick and use this method to
        ///             perform the actual work of the custom command.</remarks>
        public override void OnClick()
        {
            //Logger logger = new Logger();
            try
            {
                EnviVars.instance.MainForm.UseWaitCursor = true;
                //System.Windows.Forms.Cursor.Current=System.Windows.Forms.Cursors.WaitCursor;
                bool isCurrrentNew = (String.IsNullOrEmpty(EnviVars.instance.MapControl.DocumentFilename) &&
                                      EnviVars.instance.MapControl.LayerCount > 0);
                if ((!String.IsNullOrEmpty(EnviVars.instance.MapControl.DocumentFilename) &&
                     EnviVars.instance.MapControl.CheckMxFile(EnviVars.instance.MapControl.DocumentFilename)) || isCurrrentNew)
                {
                    DialogResult res = XtraMessageBox.Show("保存当前文档?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (res == DialogResult.Yes)
                    {
                        //if yes, launch the Save command
                        //ICommand command = new CmdSaveFile();
                        //command.OnCreate(EnviVars.instance.MapControl.Object);
                        //command.OnClick();
                        IMxdContents mxdContents = EnviVars.instance.MapControl.Map as IMxdContents;
                        MapAPI.SaveMapDocument(mxdContents, EnviVars.instance.MapControl.DocumentFilename.ToString(), false);
                    }
                }
                //logger.Log(LogLevel.Info, EventType.UserManagement, AppMessage.MSG0090, null);
                //launch the OpenMapDoc command

                //ICommand OpenMapDoc = new ControlsOpenDocCommandClass();
                //OpenMapDoc.OnCreate(this.m_hookHelper.Hook);
                //OpenMapDoc.OnClick();

                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter      = "Map Documents (*.mxd)|*.mxd";
                dlg.Multiselect = false;
                dlg.Title       = "打开文档";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    string docName = dlg.FileName;
                    string taskXml = docName.Substring(0, docName.LastIndexOf(".")) + ".xml";
                    if (!File.Exists(taskXml))
                    {
                        XtraMessageBox.Show("任务描述文件不存在!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        return;
                    }

                    if (!Task.ParseTask(taskXml))
                    {
                        return;
                    }
                    EnviVars.instance.CurrentTask = taskXml;
                    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);
                        //EnviVars.instance.PageLayoutControl.PageLayout = mapDoc.PageLayout;
                        //EnviVars.instance.Synchronizer.ReplaceMap(map);
                        //EnviVars.instance.MapControl.Map = map;
                        //mapDoc.Close();
                        EnviVars.instance.MapControl.DocumentFilename = docName;
                        EnviVars.instance.MapControl.LoadMxFile(docName);
                        EnviVars.instance.history.AddTask(docName);

                        //CommandAPI.AddRecentFile(docName, FileType.MXD);
                        //CommandAPI.SaveRecentFilesInfo();
                        //logger.Log(LogLevel.Info, EventType.UserManagement, AppMessage.MSG0090, null);
                    }
                }
            }
            catch (Exception ex)
            {
                //logger.Log(LogLevel.Error, EventType.UserManagement, AppMessage.MSG0090, ex);
                Log.WriteLog(typeof(CmdOpenMxd), ex);
            }
            finally
            {
                EnviVars.instance.MainForm.Text          = EnviVars.instance.MapControl.DocumentFilename;
                EnviVars.instance.MainForm.UseWaitCursor = false;
            }
        }
예제 #17
0
        protected void OpenAdministrativeMapDoc(string adminMapDoc)
        {
            IMapDocument mapDoc = new MapDocumentClass();
            if (mapDoc.get_IsPresent(adminMapDoc) &&
                !mapDoc.get_IsPasswordProtected(adminMapDoc))
            {
                mapDoc.Open(adminMapDoc, string.Empty);

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

                m_mapcontrol.Map = m_adminMap;
            }
        }