//根据书签名字返回书签 和 索引 public void findByName(string bmName, ref ISpatialBookmark outBM, ref int outIndex) { //Get the bookmarks of the focus map IMapBookmarks mapBookmarks = (IMapBookmarks)pMap; //Get bookmarks enumerator IEnumSpatialBookmark enumSpatialBookmarks = mapBookmarks.Bookmarks; enumSpatialBookmarks.Reset(); //Loop through the bookmarks to get bookmark names ISpatialBookmark spatialBookmark = enumSpatialBookmarks.Next(); int bookmarkCount = 0; while (spatialBookmark != null) { //Get the correct bookmark if (spatialBookmark.Name == bmName) { outBM = spatialBookmark; outIndex = bookmarkCount; break; } bookmarkCount = bookmarkCount + 1; spatialBookmark = enumSpatialBookmarks.Next(); } }
private void btnOK_Click(object sender, System.EventArgs e) { IMapBookmarks pBookmarks = m_pMap as IMapBookmarks; if (pBookmarks != null) { bool flag = false; IEnumSpatialBookmark bookmarks = pBookmarks.Bookmarks; ISpatialBookmark pBookmark; bookmarks.Reset(); while ((pBookmark = bookmarks.Next()) != null) { if (pBookmark.Name == txtBookmarkName.Text) { break; } } if (!flag) { frmCreateBookmarkView.nIndex = frmCreateBookmarkView.nIndex + 1; pBookmark = new AOIBookmarkClass() { Name = txtBookmarkName.Text, Location = (m_pMap as IActiveView).Extent }; pBookmarks.AddBookmark(pBookmark); } } }
public int OnPopup(object hook) { m_HookHelper.Hook = hook; //Get the bookmarks of the focus map IMapBookmarks mapBookmarks = (IMapBookmarks)m_HookHelper.FocusMap; //Get bookmarks enumerator IEnumSpatialBookmark enumSpatialBookmarks = mapBookmarks.Bookmarks; enumSpatialBookmarks.Reset(); //Loop through the bookmarks to count them ISpatialBookmark spatialBookmark = enumSpatialBookmarks.Next(); int bookmarkCount = 0; while (spatialBookmark != null) { bookmarkCount = bookmarkCount + 1; spatialBookmark = enumSpatialBookmarks.Next(); } //Return the number of multiitems return(bookmarkCount); }
public string get_ItemCaption(int index) { //Get the bookmarks of the focus map IMapBookmarks mapBookmarks = (IMapBookmarks)m_HookHelper.FocusMap; //Get bookmarks enumerator IEnumSpatialBookmark enumSpatialBookmarks = mapBookmarks.Bookmarks; enumSpatialBookmarks.Reset(); //Loop through the bookmarks to get bookmark names ISpatialBookmark spatialBookmark = enumSpatialBookmarks.Next(); int bookmarkCount = 0; while (spatialBookmark != null) { //Get the correct bookmark if (bookmarkCount == index) { //Return the bookmark name return(spatialBookmark.Name); } bookmarkCount = bookmarkCount + 1; spatialBookmark = enumSpatialBookmarks.Next(); } return(""); }
private void cmb_Bookmark_SelectedIndexChanged(object sender, EventArgs e) { IMapBookmarks bookmarks = mapControl.Map as IMapBookmarks; IEnumSpatialBookmark enumSpatialBookmark = bookmarks.Bookmarks; enumSpatialBookmark.Reset(); ISpatialBookmark spatialBookmark = enumSpatialBookmark.Next(); while (spatialBookmark != null) { string index = cmb_Bookmark.SelectedIndex.ToString(); string bm_name = cmb_Bookmark.Items[Convert.ToInt32(index)].ToString(); //Console.WriteLine(bm_name + " "+ spatialBookmark.Name); if (bm_name == spatialBookmark.Name) { spatialBookmark.ZoomTo((IMap)mapControl.ActiveView); mapControl.ActiveView.Refresh(); break; } spatialBookmark = enumSpatialBookmark.Next(); } btn_bmDEL.Visible = true; but_addbm.Visible = false; }
public void OnItemClick(int index) { //Get the bookmarks of the focus map IMapBookmarks mapBookmarks = (IMapBookmarks)m_HookHelper.FocusMap; //Get bookmarks enumerator IEnumSpatialBookmark enumSpatialBookmarks = mapBookmarks.Bookmarks; enumSpatialBookmarks.Reset(); //Loop through the bookmarks to get bookmark to zoom to ISpatialBookmark spatialBookmark = enumSpatialBookmarks.Next(); int bookmarkCount = 0; while (spatialBookmark != null) { //Get the correct bookmark if (bookmarkCount == index) { //Zoom to the bookmark spatialBookmark.ZoomTo(m_HookHelper.FocusMap); //Refresh the map m_HookHelper.ActiveView.Refresh(); } bookmarkCount = bookmarkCount + 1; spatialBookmark = enumSpatialBookmarks.Next(); } }
private void ToolStripButton2_Click(object sender, EventArgs e) { AddBookmark frmBookMark = new AddBookmark(); frmBookMark.ShowDialog(); string pName = string.Empty; int check = frmBookMark.Check; if (check == 1) { pName = frmBookMark.Bookmark; } if (string.IsNullOrEmpty(pName)) { return; } //书签进行重名判断 IMapBookmarks mapBookmarks = axMapControl1.Map as IMapBookmarks; IEnumSpatialBookmark enumSpatialBookmarks = mapBookmarks.Bookmarks; enumSpatialBookmarks.Reset(); ISpatialBookmark pSpatialBookmark; while ((pSpatialBookmark = enumSpatialBookmarks.Next()) != null) { if (pName == pSpatialBookmark.Name) { DialogResult dr = MessageBox.Show("此书签名已存在!是否替换?", "提示", MessageBoxButtons.YesNoCancel); if (dr == DialogResult.Yes) { mapBookmarks.RemoveBookmark(pSpatialBookmark); } else if (dr == DialogResult.No) { frmBookMark.ShowDialog(); } else { return; } } } //获取当前地图的对象 IActiveView pActiveView = axMapControl1.Map as IActiveView; //创建一个新的书签并设置其位置范围为当前视图的范围 IAOIBookmark pBookmark = new AOIBookmarkClass { Location = pActiveView.Extent, //获得书签名 Name = pName }; //通过IMapBookmarks接口访问当前地图书签集,添加书签到地图的书签集中 IMapBookmarks pMapBookmarks = axMapControl1.Map as IMapBookmarks; pMapBookmarks.AddBookmark(pBookmark); }
private void frmManageBookMarker_Load(object sender, EventArgs e) { IEnumSpatialBookmark bookmarks = (this.imap_0 as IMapBookmarks).Bookmarks; bookmarks.Reset(); for (ISpatialBookmark bookmark2 = bookmarks.Next(); bookmark2 != null; bookmark2 = bookmarks.Next()) { this.listView1.Items.Add(bookmark2.Name).Tag = bookmark2; } }
/// <summary> /// 添加书签 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddBookMark_Click(object sender, EventArgs e) { FormBookmark formBookmark = new FormBookmark(); formBookmark.ShowDialog(); string pName = string.Empty; pName = formBookmark.BookMark; if (!formBookmark.Check || string.IsNullOrEmpty(pName)) { return; } // 书签进行重命名判断 IMapBookmarks mapBookmarks = MainMapControl.Map as IMapBookmarks; IEnumSpatialBookmark enumSpatialBookmark = mapBookmarks.Bookmarks; enumSpatialBookmark.Reset(); ISpatialBookmark spatialBookmark; while ((spatialBookmark = enumSpatialBookmark.Next()) != null) { if (pName == spatialBookmark.Name) { DialogResult dr = MessageBox.Show("书签重命名,时候替换?", "提示", MessageBoxButtons.YesNoCancel); switch (dr) { case DialogResult.Yes: mapBookmarks.RemoveBookmark(spatialBookmark); break; case DialogResult.No: formBookmark.ShowDialog(); break; default: return; } } } // 获取当前地图的对象 IActiveView activeView = MainMapControl.Map as IActiveView; // 创建一个新的书签并设置其位置为当前视图范围 IAOIBookmark pBookmark = new AOIBookmark(); pBookmark.Location = activeView.Extent; // 获得书签名称 pBookmark.Name = pName; // 通过IMapBookmarks访问当前地图书签集,添加书签到地图的书签集中 IMapBookmarks pMapBookmarks = MainMapControl.Map as IMapBookmarks; pMapBookmarks.AddBookmark(pBookmark); }
/// <summary>Exports all bookmarks to PDF files.</summary> /// <param name="directory">The directory that the exported files will be written to.</param> /// <param name="dpi">The resolution of the output files.</param> /// <param name="exportFormat">The format of the exported files.</param> public void ExportBookmarksToFiles(string directory, long dpi, ExportFormat exportFormat) { if (!Directory.Exists(directory)) { throw new DirectoryNotFoundException("Directory not found: " + directory); } IMouseCursor mc = new MouseCursorClass(); const int hourglass = 2; mc.SetCursor(hourglass); IMxDocument mxDoc = _app.Document as IMxDocument; IMapBookmarks bookmarks = (IMapBookmarks)mxDoc.FocusMap; IEnumSpatialBookmark enumBM = bookmarks.Bookmarks; enumBM.Reset(); ISpatialBookmark sbm = enumBM.Next(); ProgressDialogFactoryClass dialogFactory = new ProgressDialogFactoryClass(); var cancelTracker = new CancelTrackerClass(); IStepProgressor stepProgressor = dialogFactory.Create(cancelTracker, _app.hWnd); IProgressDialog2 progDialog = stepProgressor as IProgressDialog2; progDialog.CancelEnabled = true; progDialog.ShowDialog(); stepProgressor.Hide(); stepProgressor.Message = "Exporting..."; // Create a formatting string with the proper extension. (E.g., "{0}.pdf" for PDF files".) string fnFmt = string.Format("{{0}}.{0}", Enum.GetName(typeof(ExportFormat), exportFormat)); try { while (sbm != null) { sbm.ZoomTo(mxDoc.FocusMap); string filename = System.IO.Path.Combine(directory, string.Format(fnFmt, sbm.Name)); ExportPageLayoutToFile(mxDoc.PageLayout, filename, dpi, exportFormat); sbm = enumBM.Next(); } } finally { if (progDialog != null) { progDialog.HideDialog(); ComReleaser.ReleaseCOMObject(progDialog); } } }
/* Function: Load_Bookmark * Usage: load the opening map's bookmark into select-bookmark combobox * Input: sBookmarkName = the name of bookmark introducted * Output: a spatial reference * Author: JL Ding * Time: 2019/03/08 */ private void Load_Bookmark() { IMapBookmarks bookmarks = axMapControl1.Map as IMapBookmarks; //get the map's bookmark through axMapControl1.Map IEnumSpatialBookmark enumSpatialBookmark = bookmarks.Bookmarks; enumSpatialBookmark.Reset(); ISpatialBookmark spatialBookmark = enumSpatialBookmark.Next(); while (spatialBookmark != null) { cbBookmarkList.Items.Add(spatialBookmark.Name); spatialBookmark = enumSpatialBookmark.Next(); } }
private void frmManageBookmark_Load(object sender, EventArgs e) { IMapBookmarks pBookmarks = m_pMap as IMapBookmarks; if (pBookmarks != null) { IEnumSpatialBookmark pEnumSpatialBookmark = pBookmarks.Bookmarks; ISpatialBookmark pBookmark; pEnumSpatialBookmark.Reset(); while ((pBookmark = pEnumSpatialBookmark.Next()) != null) { this.lstBookmarks.Items.Add(pBookmark.Name).Tag = pBookmark; } } }
}//获取空间书签,并对视图初始化 private void InitControl() { mapbookmarks = _currentmap as IMapBookmarks; //获取当前地图的书签集 IEnumSpatialBookmark enumspatialbookmarks = mapbookmarks.Bookmarks; //赋给变量 enumspatialbookmarks.Reset(); ISpatialBookmark pspatialbookmark = enumspatialbookmarks.Next();//选择第一个书签 string sbookmarksname = string.Empty; while (pspatialbookmark != null) //循环,判断是否为空 { sbookmarksname = pspatialbookmark.Name; //书签名字获取 treeView1.Nodes.Add(sbookmarksname); //将其加入到目录树视图 pdictionary.Add(sbookmarksname, pspatialbookmark); //加到索引字典内 pspatialbookmark = enumspatialbookmarks.Next(); //进行下一个书签操作 } }
/// <summary> /// 获取空间书签,对tviewBookmark进行初始化 /// </summary> private void InitControl() { pMapBookmarks = _currentMap as IMapBookmarks; IEnumSpatialBookmark enumSpatialBookmark = pMapBookmarks.Bookmarks; enumSpatialBookmark.Reset(); ISpatialBookmark spatialBookmark = enumSpatialBookmark.Next(); string bookmarkName = string.Empty; while (spatialBookmark != null) { bookmarkName = spatialBookmark.Name; tviewBookMark.Nodes.Add(bookmarkName); pDictionary.Add(bookmarkName, spatialBookmark); spatialBookmark = enumSpatialBookmark.Next(); } }
private void btnZoomTo_Click(object sender, EventArgs e) { //找到用户选中的 ISpatialBookmark m_BookMarks.Reset();//书签指针归零 ISpatialBookmark theBookmark = m_BookMarks.Next(); while (theBookmark != null) { if (theBookmark.Name == listView1.SelectedItems[0].Text) { //调用zoomto theBookmark.ZoomTo(m_AxMapControl.Map); m_AxMapControl.ActiveView.Refresh(); } theBookmark = m_BookMarks.Next(); } }
private void 添加书签ToolStripMenuItem_Click(object sender, EventArgs e) { bookmark frmbookmark = new bookmark(); frmbookmark.ShowDialog(); //初始化一个书签管理窗口 string pName = frmbookmark.Bookmark; //将书签名字赋给pName if (pName == "") { return; } IMapBookmarks mapbookmarks = axMapControl1.Map as IMapBookmarks; //访问当前书签集 IEnumSpatialBookmark enumspatialbookmarks = mapbookmarks.Bookmarks; //将当前的书签集赋给enumspatialbookmarks enumspatialbookmarks.Reset(); ISpatialBookmark pspatialbookmarks; //创建一个空的空间书签 while ((pspatialbookmarks = enumspatialbookmarks.Next()) != null) //循环判断名字是否已经存在 { if (pName == pspatialbookmarks.Name) { DialogResult dr = MessageBox.Show("此书签名已存在!是否替换?", "提示", MessageBoxButtons.YesNoCancel); if (dr == DialogResult.Yes) { mapbookmarks.RemoveBookmark(pspatialbookmarks); } else if (dr == DialogResult.No) { frmbookmark.ShowDialog(); } else { return; } } } IActiveView pactiveview = axMapControl1.Map as IActiveView;//获取当前地图对象 IAOIBookmark pbookmark = new AOIBookmark(); pbookmark.Location = pactiveview.Extent; //创建一个书签并设置其位置为当前视图范围 pbookmark.Name = pName; //获得书签名 IMapBookmarks pmapbookmarks = axMapControl1.Map as IMapBookmarks; //访问当前书签集 pmapbookmarks.AddBookmark(pbookmark); //添加新书签到地图的书签集中 }
//添加书签 private void Button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.textBox1.Text)) { return; } //书签进行重名判断 IMapBookmarks mapBookmarks = mainForm.mainform.mainMapControl.Map as IMapBookmarks; IEnumSpatialBookmark enumSpatialBookmarks = mapBookmarks.Bookmarks; enumSpatialBookmarks.Reset(); ISpatialBookmark pSpatialBookmark; while ((pSpatialBookmark = enumSpatialBookmarks.Next()) != null) { if (this.textBox1.Text == pSpatialBookmark.Name) { DialogResult dr = MessageBox.Show("此书签名已存在!是否替换?", "提示", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { mapBookmarks.RemoveBookmark(pSpatialBookmark); } else if (dr == DialogResult.No) { return; } } } //获取当前地图的对象 IActiveView pActiveView = mainForm.mainform.mainMapControl.Map as IActiveView; //创建一个新的书签并设置其位置范围为当前视图的范围 IAOIBookmark pBookmark = new AOIBookmarkClass(); pBookmark.Location = pActiveView.Extent; //获得书签名 pBookmark.Name = this.textBox1.Text; //通过IMapBookmarks接口访问当前地图书签集,添加书签到地图的书签集中 IMapBookmarks pMapBookmarks = mainForm.mainform.mainMapControl.Map as IMapBookmarks; pMapBookmarks.AddBookmark(pBookmark); this.Close(); }
/// <summary> /// 监听结束书签列表 /// </summary> public Boolean oneBookmark(string name) { IMapBookmarks bookmarks = mapControl.Map as IMapBookmarks; IEnumSpatialBookmark enumSpatialBookmark = bookmarks.Bookmarks; enumSpatialBookmark.Reset(); ISpatialBookmark spatialBookmark = enumSpatialBookmark.Next(); while (spatialBookmark != null) { if (name == spatialBookmark.Name) { return(false); } spatialBookmark = enumSpatialBookmark.Next(); } return(true); }
private void cbBookmarkList_SelectedIndexChanged(object sender, EventArgs e) { IMapBookmarks bookmarks = axMapControl1.Map as IMapBookmarks; IEnumSpatialBookmark enumSpatialBookmark = bookmarks.Bookmarks; enumSpatialBookmark.Reset(); //what's the function? ISpatialBookmark spatialBookmark = enumSpatialBookmark.Next(); while (spatialBookmark != null) { if (spatialBookmark.Name == cbBookmarkList.SelectedItem.ToString()) { spatialBookmark.ZoomTo(axMapControl1.Map); axMapControl1.ActiveView.Refresh(); break; } spatialBookmark = enumSpatialBookmark.Next(); } }
private void InitControl() { mapBookmarks = _currentMap as IMapBookmarks; IEnumSpatialBookmark enumSpatialBookmarks = mapBookmarks.Bookmarks; enumSpatialBookmarks.Reset(); ISpatialBookmark pSpatialBookmark = enumSpatialBookmarks.Next(); string sBookMarkName = string.Empty; while (pSpatialBookmark != null) { sBookMarkName = pSpatialBookmark.Name; //增加树节点 treeView1.Nodes.Add(sBookMarkName); //添加到数据字典 pDictionary.Add(sBookMarkName, pSpatialBookmark); pSpatialBookmark = enumSpatialBookmarks.Next(); } }
private void cbBookmarkList_SelectedIndexChanged(object sender, EventArgs e) { //get bookmark_list IMapBookmarks bookmarks = axMapControl1.Map as IMapBookmarks; IEnumSpatialBookmark enumSpatialBookmark = bookmarks.Bookmarks; // enumSpatialBookmark.Reset(); ISpatialBookmark spatialBookmark = enumSpatialBookmark.Next(); while (spatialBookmark != null) { if (cbBookmarkList.SelectedItem.ToString() == spatialBookmark.Name) { spatialBookmark.ZoomTo((IMap)axMapControl1.ActiveView); axMapControl1.ActiveView.Refresh(); break; } spatialBookmark = enumSpatialBookmark.Next(); } }
private void cbBookmarkList_selectedIndexChanged(object sender, EventArgs e) { // 获取ArcGIS组件的bookmark,并将其转为可枚举值,方便循环 IMapBookmarks bookmark = axMapControl1.Map as IMapBookmarks; IEnumSpatialBookmark enumSpatialBookmark = bookmark.Bookmarks; enumSpatialBookmark.Reset(); ISpatialBookmark spatialBookmark = enumSpatialBookmark.Next(); while (spatialBookmark != null) { if (cbBookmarkList.SelectedItem.ToString() == spatialBookmark.Name) { // 当下拉列表索引指向的名称和bookmark的名称对应时,将保存的bookmark移到视野范围 spatialBookmark.ZoomTo((IMap)axMapControl1.ActiveView); axMapControl1.ActiveView.Refresh(); break; } // 没有命中,继续枚举 spatialBookmark = enumSpatialBookmark.Next(); } }
private void btnOK_Click(object sender, EventArgs e) { IEnumSpatialBookmark bookmarks = (this.imap_0 as IMapBookmarks).Bookmarks; bookmarks.Reset(); ISpatialBookmark bookmark = bookmarks.Next(); while (bookmark != null) { if (bookmark.Name == this.txtBookMarker.Text) { break; } bookmark = bookmarks.Next(); } if (bookmark != null) { if (MessageBox.Show("书签已存在,是否替换!", "书签", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { (bookmark as IAOIBookmark).Location = (this.imap_0 as IActiveView).Extent; base.DialogResult = DialogResult.OK; base.Close(); } } else { nIndex++; bookmark = new AOIBookmarkClass { Name = this.txtBookMarker.Text }; (bookmark as IAOIBookmark).Location = (this.imap_0 as IActiveView).Extent; (this.imap_0 as IMapBookmarks).AddBookmark(bookmark); base.DialogResult = DialogResult.OK; base.Close(); } }