Ejemplo n.º 1
0
        private void menuSaveDoc_Click(object sender, EventArgs e)
        {
            //execute Save Document command
            if (m_mapControl.CheckMxFile(m_mapDocumentName))
            {
                //create a new instance of a MapDocument
                IMapDocument mapDoc = new MapDocumentClass();
                mapDoc.Open(m_mapDocumentName, string.Empty);

                //Make sure that the MapDocument is not readonly
                if (mapDoc.get_IsReadOnly(m_mapDocumentName))
                {
                    MessageBox.Show("Map document is read only!");
                    mapDoc.Close();
                    return;
                }

                //Replace its contents with the current map
                mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map);

                //save the MapDocument in order to persist it
                mapDoc.Save(mapDoc.UsesRelativePaths, false);

                //close the MapDocument
                mapDoc.Close();
            }
        }
Ejemplo n.º 2
0
        private void SaveDocument()
        {
            try
            {
                if (mapControl.CheckMxFile(m_mapDocumentName))
                {
                    //使用MapDocument对象保存文件
                    IMapDocument mapDocument = new MapDocumentClass();
                    mapDocument.Open(m_mapDocumentName, string.Empty);

                    //判断文件是不是只读的
                    if (mapDocument.get_IsReadOnly(m_mapDocumentName))
                    {
                        MessageBox.Show("地图文件是只读的!");
                        mapDocument.Close();
                        return;
                    }
                    //替换已有的文件
                    mapDocument.ReplaceContents((IMxdContents)mapControl.Map);
                    //保存文件
                    mapDocument.Save(mapDocument.UsesRelativePaths, false);
                    mapDocument.Close();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 3
0
 private void menuSaveDoc_Click(object sender, EventArgs e)
 {
     if (null != m_pageLayoutControl.DocumentFilename &&
         m_mapControl.CheckMxFile(m_pageLayoutControl.DocumentFilename))
     {
         IMapDocument mapDoc = new MapDocumentClass();
         mapDoc.Open(m_pageLayoutControl.DocumentFilename, string.Empty);
         mapDoc.ReplaceContents((IMxdContents)m_pageLayoutControl.PageLayout);
         mapDoc.Save(mapDoc.UsesRelativePaths, false);
         mapDoc.Close();
     }
 }
Ejemplo n.º 4
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            //get the MapControl
            m_mapControl = (IMapControl3)axMapControl1.Object;

            //disable the Save menu (since there is no document yet)
            menuSaveDoc.Enabled = false;

            if (m_mapControl.CheckMxFile(mxdPath))
            {
                m_mapControl.LoadMxFile(mxdPath);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 保存地图文档
        /// </summary>
        public void Save()
        {
            //首先确认当前地图文档是否有效
            if (m_MapControl.CheckMxFile(m_MapControl.DocumentFilename))
            {
                ////创建一个新的地图文档实例
                //IMapDocument mapDoc = new MapDocument();
                ////打开当前地图文档
                //mapDoc.Open(m_MapControl.DocumentFilename, string.Empty);

                ////判断地图数据是否只读
                //if (mapDoc.get_IsReadOnly(m_MapControl.DocumentFilename))
                //{
                //    MessageBox.Show("地图文档只读,不能加载!");
                //    mapDoc.Close();
                //    return;
                //}

                ////替换地图目录
                //mapDoc.ReplaceContents((IMxdContents)m_MapControl.Map);

                ////保存地图文档
                //mapDoc.Save(mapDoc.UsesRelativePaths,true);
                //mapDoc.Close();


                System.Data.DataTable dt = new System.Data.DataTable("GIS");
                dt.Columns.Add("name");
                dt.Columns.Add("value");
                dt.Columns.Add("params");
                System.Data.DataRow dr = dt.NewRow();
                string extent          = Math.Round(m_MapControl.Extent.XMax, 2).ToString() + "," + Math.Round(m_MapControl.Extent.XMin, 2).ToString() + "," + Math.Round(m_MapControl.Extent.YMax, 2).ToString() + "," + Math.Round(m_MapControl.Extent.YMin, 2).ToString();
                dr    = dt.NewRow();
                dr[0] = "extent";
                dr[1] = extent;
                dt.Rows.Add(dr);
                string Scale = Math.Round(m_MapControl.MapScale, 0).ToString();
                dr    = dt.NewRow();
                dr[0] = "Scale";
                dr[1] = Scale;
                dt.Rows.Add(dr);
                string ckScale = Math.Round(m_MapControl.ReferenceScale, 0).ToString();
                dr    = dt.NewRow();
                dr[0] = "ckScale";
                dr[1] = ckScale;
                dt.Rows.Add(dr);
                string Rotation = Math.Round(m_MapControl.Rotation, 0).ToString();
                dr    = dt.NewRow();
                dr[0] = "Rotation";
                dr[1] = Rotation;
                dt.Rows.Add(dr);
                for (int i = 0; i < m_MapControl.LayerCount; i++)
                {
                    ILayer player = m_MapControl.get_Layer(i);
                    if (player is IGroupLayer)
                    {
                        dr    = dt.NewRow();
                        dr[0] = "layer";
                        dr[1] = player.Name;
                        dr[2] = player.Visible.ToString();
                        dt.Rows.Add(dr);
                        setgisxml(ref dt, player as IGroupLayer);
                    }
                    else
                    {
                        dr    = dt.NewRow();
                        dr[0] = "layer";
                        dr[1] = player.Name;
                        dr[2] = player.Visible.ToString();
                        dt.Rows.Add(dr);
                    }
                }
                dt.WriteXml(Application.StartupPath + @"\gis.xml");
            }
            //else
            //    this.SaveAs();//新建后m_MapControl.DocumentFilename为空,故调用另存为进行保存
        }