Пример #1
0
        //另存地图文档
        public void SaveAsDocument(AxMapControl axMapControl1)
        {
            mapDocument.Open(axMapControl1.DocumentFilename, "");
            SaveFileDialog SaveFileDialog2 = new SaveFileDialog();

            SaveFileDialog2.Title  = "另存为地图文档";
            SaveFileDialog2.Filter = "地图文档(*.mxd)|*.mxd"; //设置要保存的地图文档的类型
            SaveFileDialog2.ShowDialog();
            String sFilePath = SaveFileDialog2.FileName;  //获取文件路径

            if (sFilePath == "")
            {
                return;
            }
                                              //路径为空,则返回
            //判断文件路径是否改变,如果没有改变保存当前修改,改变则另存
            if (sFilePath == mapDocument.DocumentFilename)
            {
                SaveDocument(axMapControl1);
            }
            else
            {
                mapDocument.SaveAs(sFilePath, true, true);
            }
        }
Пример #2
0
        /// <summary>
        /// 另存为
        /// </summary>
        /// <param name="axMapControl"></param>
        public void saveAsDocument(AxMapControl axMapControl)
        {
            if (axMapControl.DocumentFilename == null)//空地图为null
            {
                MessageBox.Show("没有地图文档!");
                return;
            }
            mapDocument.Open(axMapControl.DocumentFilename, "");//必须的一步,用于将AxMapControl的实例的DocumentFileName传递给pMapDoc的
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Title    = "保存地图文档";
            saveFileDialog1.Filter   = "地图文档(*.mxd)|*.mxd";           //设置过滤属性
            saveFileDialog1.FileName = axMapControl.DocumentFilename; //给定一个初始保存路为原路径
            if (saveFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;                                 //未选择文件return
            }
            string filePath = saveFileDialog1.FileName; //获取到文件路径

            if (filePath == "")
            {
                return;
            }
            if (filePath == mapDocument.DocumentFilename)//判断路径是否改变,如果没有改变保存当前修改,改变则另存为
            {
                saveDocument();
            }
            else
            {
                mapDocument.SaveAs(filePath, true, true);
            }
        }
Пример #3
0
 private void saveAsDocument()
 {
     if (mapDocument == null)
     {
         MessageBox.Show("地图文档对象为空,请先加载地图文档");
     }
     else
     {
         if (mapDocument.get_IsReadOnly(mapDocument.DocumentFilename) == true)
         {
             MessageBox.Show("地图文档是只读的无法保存");
         }
         else
         {
             string fileSavePath = @"E:\World\newword2.mxd";
             try
             {
                 mapDocument.SaveAs(fileSavePath, true, true);
                 MessageBox.Show("另存地图文档成功");
             }
             catch (Exception e)
             {
                 MessageBox.Show("另存地图文档失败!!!" + e.ToString());
             }
         }
     }
 }
Пример #4
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string filter = "Map document (*.mxd)|*.mxd";

            saveFileDialog1.Filter = filter;
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string filename = saveFileDialog1.FileName;
                //mxdocument = new MxDocumentClass();
                mapdocument = new MapDocument();
                mapdocument.New(filename);
                mapdocument.SaveAs(filename);
                mapdocument.Close();
                LoadMxdFile(filename);
            }
        }
Пример #5
0
    public static void OperateMapDoc(AxMapControl axMapControl1, AxMapControl axMapControl2, string strOperateType)
    {
        OpenFileDialog OpenFileDialog = new OpenFileDialog();
        SaveFileDialog SaveFileDialog = new SaveFileDialog();
        OpenFileDialog.Filter = "地图文档文件(*.mxd)|*.mxd";
        SaveFileDialog.Filter = "地图文档文件(*.mxd)|*.mxd";
        string strDocFileN = string.Empty;
        pMapDocument = new MapDocumentClass();
        switch (strOperateType)
        {
            case "NewDoc":
                {
                    SaveFileDialog.Title = "输入需要新建地图文档的名称";
                    SaveFileDialog.ShowDialog();
                    strDocFileN = SaveFileDialog.FileName;
                    if (strDocFileN == string.Empty)
                        return;
                    pMapDocument.New(strDocFileN);
                    pMapDocument.Open(strDocFileN, "");
                    axMapControl1.Map = pMapDocument.get_Map(0);
                    break;
                }
            case "OpenDoc":
                {
                    OpenFileDialog.Title = "输入需要加载的地图文档";
                    OpenFileDialog.ShowDialog();
                    strDocFileN = OpenFileDialog.FileName;
                    if (strDocFileN == string.Empty)
                        return;
                    pMapDocument.Open(strDocFileN, "");
                    for (int i = 0; i < pMapDocument.MapCount; i++)
                    {
                        axMapControl1.Map = pMapDocument.get_Map(i);
                        //axMapControl2.Map = pMapDocument.get_Map(i);
                    }
                    axMapControl1.Refresh();

                    break;
                }
            case "SaveDoc":
                {
                    if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true)
                    {
                        MessageBox.Show("此地图为只读文档", "信息提示");
                        return;
                    }
                    pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                    MessageBox.Show("保存成功!", "信息提示");
                    break;
                }
            case "SaveDocAS":
                {
                    SaveFileDialog.Filter = "地图文档另存";
                    SaveFileDialog.ShowDialog();
                    strDocFileN = SaveFileDialog.FileName;
                    if (strDocFileN == string.Empty)
                        return;
                    if (strDocFileN == pMapDocument.DocumentFilename)
                    {
                        pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                        MessageBox.Show("保存成功!", "信息提示");
                        break;
                    }
                    else
                    {
                        pMapDocument.SaveAs(strDocFileN, true, true);
                        MessageBox.Show("保存成功", "信息提示");
                    }
                    break;
                }
            default:
                break;
        }
    }
Пример #6
0
    public static void OperateMapDoc(AxMapControl axMapControl1, AxMapControl axMapControl2, string strOperateType)
    {
        OpenFileDialog OpenFileDialog = new OpenFileDialog();
        SaveFileDialog SaveFileDialog = new SaveFileDialog();

        OpenFileDialog.Filter = "地图文档文件(*.mxd)|*.mxd";
        SaveFileDialog.Filter = "地图文档文件(*.mxd)|*.mxd";
        string strDocFileN = string.Empty;

        pMapDocument = new MapDocumentClass();
        switch (strOperateType)
        {
        case "NewDoc":
        {
            SaveFileDialog.Title = "输入需要新建地图文档的名称";
            SaveFileDialog.ShowDialog();
            strDocFileN = SaveFileDialog.FileName;
            if (strDocFileN == string.Empty)
            {
                return;
            }
            pMapDocument.New(strDocFileN);
            pMapDocument.Open(strDocFileN, "");
            axMapControl1.Map = pMapDocument.get_Map(0);
            break;
        }

        case "OpenDoc":
        {
            OpenFileDialog.Title = "输入需要加载的地图文档";
            OpenFileDialog.ShowDialog();
            strDocFileN = OpenFileDialog.FileName;
            if (strDocFileN == string.Empty)
            {
                return;
            }
            pMapDocument.Open(strDocFileN, "");
            for (int i = 0; i < pMapDocument.MapCount; i++)
            {
                axMapControl1.Map = pMapDocument.get_Map(i);
                //axMapControl2.Map = pMapDocument.get_Map(i);
            }
            axMapControl1.Refresh();

            break;
        }

        case "SaveDoc":
        {
            if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true)
            {
                MessageBox.Show("此地图为只读文档", "信息提示");
                return;
            }
            pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
            MessageBox.Show("保存成功!", "信息提示");
            break;
        }

        case "SaveDocAS":
        {
            SaveFileDialog.Filter = "地图文档另存";
            SaveFileDialog.ShowDialog();
            strDocFileN = SaveFileDialog.FileName;
            if (strDocFileN == string.Empty)
            {
                return;
            }
            if (strDocFileN == pMapDocument.DocumentFilename)
            {
                pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                MessageBox.Show("保存成功!", "信息提示");
                break;
            }
            else
            {
                pMapDocument.SaveAs(strDocFileN, true, true);
                MessageBox.Show("保存成功", "信息提示");
            }
            break;
        }

        default:
            break;
        }
    }