private void RefreshMap() { //added by jin try { cboActiveMap.Items.Clear(); // MessageBox.Show("Map is replaced"); //Method 1: Open MapDocument file to get information about maps // m_mapDocument.Open(m_mapDocuemntName, ""); //Method 2: Get information about maps from MapControl3 m_mapDocument.Open(m_mapControl.DocumentFilename, ""); for (int i = 0; i < m_mapDocument.MapCount; i++) { string item = m_mapDocument.get_Map(i).Name; cboActiveMap.Items.Add(item); } //Initialization cboActiveMap.Text = m_mapDocument.get_Map(0).Name; //The exception will be throwed,but it runes successfully in Exercise 5, may be a trouble for thread running //axMapControl1.Map = m_mapDocument.get_Map(0); //axMapControl1.Map = m_mapDocument.ActiveView.FocusMap; m_mapDocument.Close(); // axMapControl1.Refresh(); // axTOCControl1.Update(); AddLayersToComboBox(); } catch (StackOverflowException se) { Console.WriteLine(se.Message); } }
//新建地图文档 public void NewMapDoc(AxMapControl axMapControl1) { DialogResult dialogResult = MessageBox.Show("保存文件?", "关闭文件", MessageBoxButtons.YesNoCancel); if (dialogResult == DialogResult.Yes) { SaveDocument(axMapControl1); SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Title = "新建地图文档"; saveFileDialog1.Filter = "地图文档(*.mxd)|*.mxd"; saveFileDialog1.ShowDialog(); string filePath = saveFileDialog1.FileName; //地图文档路径 mapDocument.New(filePath); //新建 mapDocument.Open(filePath, ""); //打开 axMapControl1.Map = mapDocument.get_Map(0); } if (dialogResult == DialogResult.No) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Title = "新建地图文档"; saveFileDialog1.Filter = "地图文档(*.mxd)|*.mxd"; saveFileDialog1.ShowDialog(); string filePath = saveFileDialog1.FileName; //地图文档路径 mapDocument.New(filePath); //新建 mapDocument.Open(filePath, ""); //打开 axMapControl1.Map = mapDocument.get_Map(0); } if (dialogResult == DialogResult.Cancel) { return; } }
/// <summary> /// 获取网络数据集 /// </summary> /// <param name="pFeatureClass"></param> public void getNetWorkData(ref IFeatureClass pFeatureClass) { Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); pMapDcument = new MapDocumentClass(); IFeatureLayer pFeatureLayer; try { string NetWorkData = xml.GetElement("MapDocument", "RoadNetData"); //将数据载入pMapDocument并与map控件联系起来 NetWorkData = System.Windows.Forms.Application.StartupPath + NetWorkData; pMapDcument.Open(NetWorkData, ""); for (int index = 0; index < pMapDcument.get_Map(0).LayerCount; index++) { if (pMapDcument.get_Map(0).get_Layer(index).Name == "实验区路网数据") { pFeatureLayer = pMapDcument.get_Map(0).get_Layer(index) as IFeatureLayer; pFeatureClass = pFeatureLayer.FeatureClass; } else { continue; } } } catch (Exception ex) { throw (ex); } finally { xml = null; } }
/// <summary> /// 加载网络数据集 /// </summary> public void LoadNetWorkDataSet() { Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); pMapDcument = new MapDocumentClass(); try { string NetWorkData = xml.GetElement("MapDocument", "RoadNetData"); //将数据载入pMapDocument并与map控件联系起来 NetWorkData = System.Windows.Forms.Application.StartupPath + NetWorkData; pMapDcument.Open(NetWorkData, ""); int i; for (i = 0; i <= pMapDcument.MapCount - 1; i++) { //一个IMapDocument对象中可能有多个Map对象,遍历每个map对象 mapControl.Map = pMapDcument.get_Map(i); } mapControl.Refresh(); } catch (Exception ex) { throw (ex); } finally { xml = null; } }
//加载地图文档 private void loadMapDoc() { mapDocument = new ESRI.ArcGIS.Carto.MapDocumentClass(); try { System.Windows.Forms.OpenFileDialog openFileDialog; openFileDialog = new OpenFileDialog(); openFileDialog.Title = "打开地图文档"; openFileDialog.Filter = "map documents(*.mxd)|*.mxd"; if (openFileDialog.ShowDialog() == DialogResult.OK) { string filePath = openFileDialog.FileName; mapDocument.Open(filePath, ""); for (int i = 0; i < mapDocument.MapCount; i++) { axMapControl1.Map = mapDocument.get_Map(i); } axMapControl1.Refresh(); } else { mapDocument = null; } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
/// <summary> /// 打开mxd地图文档 /// </summary> public void LoadMapDocument() { Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); pDcument = new MapDocumentClass(); try { string mxdData = xml.GetElement("MapDocument", "mxd"); //将数据载入pDocument并与map控件联系起来 mxdData = System.Windows.Forms.Application.StartupPath + mxdData; pDcument.Open(mxdData, ""); //Load the same pre-authored map document into the MapControl. mapControl.LoadMxFile(mxdData, null, null); //Set the extent of the MapControl to the full extent of the data. mapControl.Extent = mapControl.FullExtent; //int i; //for (i = 0; i <= pDcument.MapCount - 1; i++) //{ // //一个IMapDocument对象中可能有多个Map对象,遍历每个map对象 // mapControl.Map = pDcument.get_Map(i); //} mapControl.Refresh(); } catch (Exception ex) { throw (ex); } finally { xml = null; } }
private void LoadMxdFile(string filename) { if (axPageLayoutControl1.CheckMxFile(filename)) { //ESRI.ArcGIS.Framework.IDocument doc = new ESRI.ArcGIS.ArcMapUI.MxDocumentClass(); //m_application = doc.Parent; //m_application.Visible = false; //mxdocument = m_application.Document as IMxDocument; mapdocument = new MapDocument(); mapdocument.Open(filename); map = mapdocument.Map[0]; mapdocument.SetActiveView((IActiveView)map); m_pageLayoutControl = (IPageLayoutControl2)axPageLayoutControl1.Object; m_pageLayoutControl.PageLayout = mapdocument.PageLayout; //axPageLayoutControl1.LoadMxFile(filename); this.Text = mapdocument.DocumentFilename; saveAsToolStripMenuItem.Enabled = true; saveToolStripMenuItem.Enabled = true; printToolStripMenuItem.Enabled = true; } else { MessageBox.Show("The Selected file is not suppoted !!!"); } }
/// <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); } }
public frmAddProjectLayers(IMap map2, esriDatasetType dType) { InitializeComponent(); if (map2 == null) { OpenFileDialog ofdMxd = new OpenFileDialog(); ofdMxd.Filter = "Map Doc|*.mxd"; ofdMxd.Multiselect = false; DialogResult rslt = ofdMxd.ShowDialog(); if (rslt == DialogResult.OK) { mapDoc = new MapDocumentClass(); mapDoc.Open(ofdMxd.FileName, ""); map = mapDoc.get_Map(0); } else { MessageBox.Show("A map document must be selected to work. Shutting down"); this.Close(); } } else { map = map2; } if (dType == esriDatasetType.esriDTAny) { dType = esriDatasetType.esriDTFeatureClass; } switch (dType) { case esriDatasetType.esriDTTable: this.Text = "Add Table"; label1.Text = "Select Table"; break; case esriDatasetType.esriDTRasterDataset: this.Text = "Add Raster"; label1.Text = "Select Raster"; break; default: this.Text = "Add Feature"; label1.Text = "Select Feature"; break; } mapserviceutility msUtil = new mapserviceutility(); prjDatabase = msUtil.LcCacheDb; if (prjDatabase == "") { msUtil.changeLocalDatabase(); prjDatabase = msUtil.LcCacheDb; } this.cmbLayers.Items.Clear(); foreach (string s in getNames(dType)) { lyrDic.Add(s, prjDatabase + "\\" + s); cmbLayers.Items.Add(s); } this.Refresh(); }
private ESRI.ArcGIS.Carto.IMap PrivateCreateMxd(string sPathToMXDToSave) { try { _pMapDocument = new MapDocumentClass(); //Copy the MXD System.IO.File.Copy(_sMxdTemplate, sPathToMXDToSave, true); _sNewDocument = sPathToMXDToSave; if (_pMapDocument.get_IsMapDocument(_sNewDocument)) { _pMapDocument.Open(_sNewDocument, null); IMap pMap; pMap = _pMapDocument.get_Map(0); return(pMap); } return(null); } catch (Exception ex) { throw ex; } }
private void button1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog { InitialDirectory = @"C:\", Title = "Browse .mxd Files", CheckFileExists = true, CheckPathExists = true, DefaultExt = "txt", Filter = "mxd files (*.mxd)|*.mxd", FilterIndex = 2, RestoreDirectory = true, ReadOnlyChecked = true, ShowReadOnly = true }; if (openFileDialog1.ShowDialog() == DialogResult.OK) { textBox1.Text = openFileDialog1.FileName; mdoc.Open(openFileDialog1.FileName, ""); for (int i = 0; i < mdoc.MapCount; i++)// loop ageeb el dataframes eli 3ndi w a7otha f combobox { comboBox1.Items.Add(mdoc.get_Map(i).Name); } comboBox1.SelectedItem = comboBox1.Items[0]; map = mdoc.get_Map(0); //awel map 3ndi axMapControl1.Map = map; axMapControl1.Refresh(); // sa3at mesh bysht3'al mn 3'erha } }
// 检查地图文档有效性并打开 private void CheckAndOpenMxd(string mxdPath) { if (m_pMapC2.CheckMxFile(mxdPath)) { m_pMapDoc.Open(mxdPath); m_pMapC2.Map = m_pMapDoc.Map[0]; } }
/// <summary> /// 打开Mxd文档 /// </summary> /// <param name="sFilePath">文档路径</param> private void OpenDocument(string sFilePath) { if (m_MapDocument != null) { m_MapDocument.Close(); } m_MapDocument = new MapDocumentClass(); m_MapDocument.Open(sFilePath, ""); }
private void Window_Loaded(object sender, RoutedEventArgs e) { m_mapDoc.Open("E:\\Student\\IPAN\\Exercise07\\Rendering.mxd"); this.cbxActiveMap.Items.Clear(); for (int i = 0; i < m_mapDoc.MapCount; i++) { m_map = m_mapDoc.get_Map(i); this.cbxActiveMap.Items.Add(m_map.Name); } }
// 加载地图文档 private void LoadMxd() { string filename = debugDir + "\\AirQuality\\空气质量状况.mxd"; if (m_pMapC2.CheckMxFile(filename)) { m_pMapDoc.Open(filename); m_pMapC2.Map = m_pMapDoc.Map[0]; } }
public bool LoadMap() { try { openFileDialog1 = new OpenFileDialog(); openFileDialog1.Title = "Browse Mxd Files"; openFileDialog1.DefaultExt = "mxd"; openFileDialog1.Filter = "mxd Diles (*.mxd)|*.mxd"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { Path = openFileDialog1.FileName; if (Dic.ContainsKey(Path) == true) { checkedListBox1.Items.Clear(); Map = Dic[Path]; axMapControl1.Map = Map.get_Map(0); axMapControl1.Refresh(); } else { checkedListBox1.Items.Clear(); Map.Open(Path); axMapControl1.Map = Map.get_Map(0); axMapControl1.Refresh(); Dic.Add(Path, Map); } comboBox1.Items.Clear(); for (int i = 0; i < Map.MapCount; i++) { comboBox1.Items.Add(Map.get_Map(i).Name); } comboBox1.Text = comboBox1.Items[0].ToString(); toolStripStatusLabel2.Text = "Scale: " + axMapControl1.MapScale.ToString(); groupBox1.Enabled = true; groupBox2.Enabled = true; groupBox3.Enabled = true; groupBox6.Enabled = true; groupBox7.Enabled = true; groupBox8.Enabled = true; groupBox4.Enabled = true; groupBox5.Enabled = true; return(true); } } catch { return(false); } return(true); }
public static void LoadMxd(string mxdPath) { if (m_pMapC2.CheckMxFile(mxdPath)) { m_pMapDoc.Open(mxdPath); m_pMapC2.Map = m_pMapDoc.Map[0]; } else { MessageBox.Show(String.Format("地图文档【{0}】无法打开", mxdPath)); } }
public static void LoadMxd(string mxdPath) { if (m_pMapC2.CheckMxFile(mxdPath)) { m_pMapDoc.Open(mxdPath); m_pMapC2.Map = m_pMapDoc.ActiveView.FocusMap; } else { MessageBox.Show(String.Format("无法打开地图文档【{0}】", mxdPath)); } }
// 加载Mxd地图文档 private void LoadMxdFromFilename(string filename) { if (m_pMapC2.CheckMxFile(filename)) { m_pMapDoc.Open(filename); m_pMapC2.Map = m_pMapDoc.get_Map(0); } else { MessageBox.Show(String.Format("加载【{0}】地图文档失败", filename)); } }
private void openMap() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "ArcGIS Files |*.mxd|All Files (*.*)|*.*"; if (ofd.ShowDialog() != DialogResult.Cancel) { _mapDoc = new MapDocument(); _mapDoc.Open(ofd.FileName); imap = _mapDoc.get_Map(0); MapWorkspace.currentMap.Model.Map = imap; } }
public static bool LoadMxd(string mxdPath) { if (m_pMapC2.CheckMxFile(mxdPath)) { m_pMapDoc.Open(mxdPath); m_pMapC2.Map = m_pMapDoc.ActiveView.FocusMap; return(true); } else { return(false); } }
private void setMxd() { string sMxdPath = String.Format(@"{0}\{1}", WORKDIR, "Map.mxd"); if (m_pMapC2.CheckMxFile(sMxdPath)) { m_pMapDoc.Open(sMxdPath); //m_pMapC2.LoadMxFile(sMxdPath); m_pMapC2.Map = m_pMapDoc.get_Map(0); } m_pMapC2.AddShapeFile(WORKDIR, "BOUA.shp"); // 添加矢量数据 m_pMapC2.AddShapeFile(WORKDIR, "RIVER_3J.shp"); m_pMapC2.AddShapeFile(WORKDIR, "BOUP.shp"); }
private void Save_btn_Click(object sender, EventArgs e) { if (axMapControl1.DocumentFilename == null) { SaveMapAs(); } if (m_bDocModified == false) { return; } try { if (axMapControl1.Map.LayerCount == 0) { return; } if (axMapControl1.DocumentFilename != null && axMapControl1.CheckMxFile(axMapControl1.DocumentFilename)) { if (m_pMapDocument != null) { m_pMapDocument.Close(); m_pMapDocument = null; } m_pMapDocument = new MapDocumentClass(); //实例化 m_pMapDocument.Open(axMapControl1.DocumentFilename, ""); //必须的一步,用于将AxMapControl的实例的DocumentFileName传递给pMapDoc的 if (m_pMapDocument.get_IsReadOnly(m_pMapDocument.DocumentFilename)) //判断是否只读 { MessageBox.Show("文件只读!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Stop); m_pMapDocument.Close(); return; } m_pMapDocument.ReplaceContents((IMxdContents)axMapControl1.Map); //重置 IObjectCopy lip_ObjCopy = new ObjectCopyClass(); //使用Copy,避免共享引用 axMapControl1.Map = (IMap)lip_ObjCopy.Copy(m_pMapDocument.get_Map(0)); lip_ObjCopy = null; m_pMapDocument.Save(m_pMapDocument.UsesRelativePaths, true); axMapControl1.DocumentFilename = m_pMapDocument.DocumentFilename; this.Text = this.Text + " - " + axMapControl1.DocumentFilename; m_bDocModified = false; FileInfo fi = new FileInfo(m_pMapDocument.DocumentFilename); Global.m_sMxdPath = fi.GetDirectory(); MessageBox.Show("保存完成!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void InitMap() { m_pMapC2 = axMapControl_main.Object as IMapControl2; m_pMapDoc = new MapDocumentClass(); string sMxdPath = String.Format(@"{0}\{1}", WORKDIR, "Map.mxd"); if (m_pMapC2.CheckMxFile(sMxdPath)) { m_pMapDoc.Open(sMxdPath); // m_pMapC2.LoadMxFile(sMxdPath); m_pMapC2.Map = m_pMapDoc.get_Map(0); } //m_pMapC2.AddShapeFile(WORKDIR, "BOUA.shp"); // 添加矢量数据 //m_pMapC2.AddShapeFile(WORKDIR, "RIVER_3J.shp"); //m_pMapC2.AddShapeFile(WORKDIR, "BOUP.shp"); }
private void btn_openMxd_Click(object sender, EventArgs e) { OpenFileDialog ofg = new OpenFileDialog() { Title = "打开地图文档", Filter = "地图文档 (*.mxd)|*.mxd" }; if (ofg.ShowDialog() == DialogResult.OK) { string filename = ofg.FileName; if (m_pMapC2.CheckMxFile(filename)) { m_pMapDoc.Open(filename); m_pMapC2.Map = m_pMapDoc.Map[0]; } } }
private void barButtonItem101_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (this.mainMapControl.LayerCount > 0) { DialogResult result = MessageBox.Show("是否保存当前地图?", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.Cancel) { return; } //if (result == DialogResult.Yes) this.btnSaveDoc_Click(null, null); } this.openFileDialog.Title = "请选择地图文件"; this.openFileDialog.Filter = "MXD地图文件|*.mxd"; this.openFileDialog.Multiselect = false; this.openFileDialog.RestoreDirectory = true; if (this.openFileDialog.ShowDialog() == DialogResult.OK) { Application.DoEvents(); string docName = this.openFileDialog.FileName; try { this.pMapDocument = new MapDocumentClass(); if (pMapDocument.get_IsPresent(docName) && !pMapDocument.get_IsPasswordProtected(docName)) { pMapDocument.Open(docName, null); IMap pMap = pMapDocument.get_Map(0); m_controlsSynchronizer.ReplaceMap(pMap); this.mainMapControl.DocumentFilename = docName; this.Text = System.IO.Path.GetFileName(this.openFileDialog.FileName) + " - " + "LinGIS - LinInfo"; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(this.pMapDocument); Application.DoEvents(); this.pMapDocument = null; } } }
public frmTileImageServiceLayer(IActiveView acV) { InitializeComponent(); if (acV == null) { OpenFileDialog oFd = new OpenFileDialog(); oFd.Filter = "Map Document|*.mxd"; oFd.Multiselect = false; DialogResult dR = oFd.ShowDialog(); if (dR == System.Windows.Forms.DialogResult.OK) { mapDoc = new MapDocumentClass(); mapDoc.Open(oFd.FileName); acV = mapDoc.ActiveView; } } av = acV; }
private void 打开地图文档ToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofg = new OpenFileDialog() { Title = "打开地图文档对话框", Filter = "地图文档 (*.mxd)|*.mxd", InitialDirectory = Application.StartupPath }; if (ofg.ShowDialog() == DialogResult.OK) { string mxdPath = ofg.FileName; if (m_pMapC2.CheckMxFile(mxdPath)) { m_pMapDoc.Open(mxdPath); // or m_pMapC2.LoadMxFile(mxdPath); m_pMapC2.Map = m_pMapDoc.Map[0]; } } }
private void OpenDoc_btn_Click(object sender, EventArgs e) { axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerHourglass; m_pMapDocument = new MapDocumentClass(); try { OpenFileDialog dlgOpen = new OpenFileDialog(); dlgOpen.Title = "打开文档"; dlgOpen.Filter = "ArcMap Document(*.mxd)|*.mxd"; string sFilePath = null; if (dlgOpen.ShowDialog() == DialogResult.OK) { sFilePath = dlgOpen.FileName; } else { return; } if (sFilePath == "") { MessageBox.Show("文件路径错误!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } //将数据载入pMapDocument并与map控件联系起来 m_pMapDocument.Open(sFilePath, ""); //IMapDocument对象中可能有多个Map对象,遍历每个map对象 for (int i = 0; i < m_pMapDocument.MapCount; i++) { axMapControl1.Map = m_pMapDocument.get_Map(i); } axMapControl1.DocumentFilename = m_pMapDocument.DocumentFilename; this.Text = this.Text + " - " + axMapControl1.DocumentFilename; axMapControl1.Refresh(); FileInfo fi = new FileInfo(m_pMapDocument.DocumentFilename); Global.m_sMxdPath = fi.GetDirectory(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "失败", MessageBoxButtons.OK, MessageBoxIcon.Stop); } axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerDefault; }
private void loadMapDoc() { mapDoc = new MapDocumentClass(); try { System.Windows.Forms.OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "打开地图文档"; openFileDialog.Filter = "map documents (*.mxd)|*.mxd"; openFileDialog.ShowDialog(); string filePath = openFileDialog.FileName; mapDoc.Open(filePath, ""); for (int i = 0; i < mapDoc.MapCount; i++)// { axMapControl1.Map = mapDoc.get_Map(i); } axMapControl1.Refresh(); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
private void LoadMap(string arcMapPath) { mapDoc.Open(arcMapPath); this.cbxActiveMap.Items.Clear(); for (int i = 0; i < mapDoc.MapCount; i++) { this.cbxActiveMap.Items.Add(mapDoc.get_Map(i).Name); } this.cbxActiveMap.SelectedIndex = 0; m_toolbar.AddItem("esriControls.ControlsMapNavigationToolbar"); //添加行政区划分 this.districtList.Items.Clear(); initData(); // this.districtList.SelectedIndex = 0; m_map.Map = mapDoc.get_Map(0); m_toc.SetBuddyControl(m_map); m_toolbar.SetBuddyControl(m_map); m_toolbar.AddItem("esriControls.ControlsMapNavigationToolbar"); }
private void open_Click(object sender, EventArgs e) { mapDocument = new MapDocumentClass(); try { System.Windows.Forms.OpenFileDialog openFileDialog; openFileDialog = new OpenFileDialog(); openFileDialog.Title = "打开图层文件"; openFileDialog.Filter = "map documents(*.mxd)|*.mxd"; openFileDialog.ShowDialog(); string filePath = openFileDialog.FileName; mapDocument.Open(filePath, ""); for (int i = 0; i < mapDocument.MapCount; i++) { mainMapControl.Map = mapDocument.get_Map(i); } mainMapControl.Refresh(); } catch (Exception ex) { MessageBox.Show("加载失败" + ex.ToString()); } }
private void btnOpenDoc_Click(object sender, EventArgs e) { if (this.mainMapControl.LayerCount > 0) { DialogResult result = MessageBox.Show("是否保存当前地图?", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.Cancel) return; if (result == DialogResult.Yes) this.btnSaveDoc_Click(null, null); } this.openFileDialog.Title = "请选择地图文件"; this.openFileDialog.Filter = "MXD地图文件|*.mxd"; this.openFileDialog.Multiselect = false; this.openFileDialog.RestoreDirectory = true; if (this.openFileDialog.ShowDialog() == DialogResult.OK) { Application.DoEvents(); string docName = this.openFileDialog.FileName; try { this.pMapDocument = new MapDocumentClass(); if (pMapDocument.get_IsPresent(docName) && !pMapDocument.get_IsPasswordProtected(docName)) { pMapDocument.Open(docName, null); IMap pMap = pMapDocument.get_Map(0); m_controlsSynchronizer.ReplaceMap(pMap); this.mainMapControl.DocumentFilename = docName; this.Text = System.IO.Path.GetFileName(this.openFileDialog.FileName) + " - " + "LinGIS - LinInfo"; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(this.pMapDocument); Application.DoEvents(); this.pMapDocument = null; } } }
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; } }
public MXD(string mxdPath) { path = mxdPath; // GUIDs finden: http://support.esri.com/index.cfm?fa=knowledgebase.techarticles.articleShow&d=31115 LayerTypeUIDs[0] = "{EDAD6644-1810-11D1-86AE-0000F8751720}"; LayerTypeUIDs[1] = "{5CEAE408-4C0A-437F-9DB3-054D83919850}"; LayerTypeUIDs[2] = "{DBCA59AC-6771-4408-8F48-C7D53389440C}"; LayerTypeUIDs[3] = "{D02371C7-35F7-11D2-B1F2-00C04F8EDEFF}"; LayerTypeUIDs[4] = "{605BC37A-15E9-40A0-90FB-DE4CC376838C}"; LayerTypeUIDs[5] = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; LayerTypeUIDs[6] = ""; if (InitializeLicense() == esriLicenseStatus.esriLicenseCheckedOut) { mapDoc = new MapDocumentClass(); if (mapDoc.get_IsPresent(path)) { if (mapDoc.get_IsMapDocument(path)) { mapDoc.Open(path, null); if (mapDoc.DocumentType == esriMapDocumentType.esriMapDocumentTypeMxd) { activateMapDocument(); // alle Layer holen layerList = getLayerList(null); // alle GroupLayer holen processLayer(LayerTypes.GroupLayer); // alle AnnotationLayer holen processLayer(LayerTypes.AnnotationLayer); // alle AnnotationSubLayer holen processLayer(LayerTypes.AnnotationSubLayer); // alle RasterLayer holen processLayer(LayerTypes.RasterLayer); // alle RasterCatalogLayer holen processLayer(LayerTypes.RasterCatalogLayer); // alle FeatureLayer holen processLayer(LayerTypes.FeatureLayer); // übrige Layer holen foreach (ILayer lyr in layerList) { if (!processedLayers.Contains(lyr)) { LayerInfo lyrInfo = new LayerInfo(mapDoc); lyrInfo.processOtherLayer(lyr); lyrInfos.Add(lyrInfo); processedLayers.Add(lyr); } } // Resultate ausgeben foreach (LayerInfo info in lyrInfos) { Console.WriteLine(info.writeCSV()); } // Dokument schliessen mapDoc.Close(); } else { Console.Error.WriteLine("FEHLER: kein gültiges MXD-File"); } } else { Console.Error.WriteLine("FEHLER: kein gültiges MXD-File"); } } else { Console.Error.WriteLine("FEHLER: Angegebenes File nicht gefunden"); } } else { Console.Error.WriteLine("FEHLER: Keine ArcView-Lizenz verfügbar"); } // Lizenz zurückgeben TerminateLicense(); }
private ESRI.ArcGIS.Carto.IMap PrivateCreateMxd(string sPathToMXDToSave) { try { _pMapDocument = new MapDocumentClass(); //Copy the MXD System.IO.File.Copy(_sMxdTemplate, sPathToMXDToSave, true); _sNewDocument = sPathToMXDToSave; if (_pMapDocument.get_IsMapDocument(_sNewDocument)) { _pMapDocument.Open(_sNewDocument, null); IMap pMap; pMap = _pMapDocument.get_Map(0); return pMap; } return null; } catch (Exception ex) { throw ex; } }
//加载地图文档 private void loadMapDoc() { mapDocument = new ESRI.ArcGIS.Carto.MapDocumentClass(); try { System.Windows.Forms.OpenFileDialog openFileDialog; openFileDialog = new OpenFileDialog(); openFileDialog.Title = "打开地图文档"; openFileDialog.Filter = "map documents(*.mxd)|*.mxd"; if (openFileDialog.ShowDialog() == DialogResult.OK) { string filePath = openFileDialog.FileName; mapDocument.Open(filePath, ""); for (int i = 0; i < mapDocument.MapCount; i++) { axMapControl1.Map = mapDocument.get_Map(i); } axMapControl1.Refresh(); } else { mapDocument = null; } } catch (Exception e) { MessageBox.Show(e.ToString()); } }