⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapcontrolview.cpp

📁 程序编写环境为Visual Studio.NET 2002
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				hSecChildItem = m_LayerTreeView.GetChildItem(hChildItem);
				while ( hSecChildItem != NULL)
				{
					m_LayerTreeView.SetCheck(hSecChildItem, !bChecked);
					// 得到第3层的第一个节点
					hThdChildItem = m_LayerTreeView.GetChildItem(hSecChildItem);
					while (hThdChildItem != NULL)
					{
						m_LayerTreeView.SetCheck(hThdChildItem, !bChecked);
						// 得到该节点显示的名称(即地物类型名称)
						szName = m_LayerTreeView.GetItemText(hThdChildItem);
						// 根据地物类型名称得到图层的索引
						int nIndex = pMainWnd->m_environment.
							        GetLayerIndexByName(szName);
						// 设置图层的可见性
						if (nIndex >=0)
						{
							pMainWnd->m_environment.m_layerInfos[nIndex].
								                         bVisible = true;
							//判断是否在显示比例之内
							double dScale = pMainWnd->m_environment.CalcScale
								                      (&(pMapView->m_Map));
							if (dScale<pMainWnd->
								       m_environment.m_layerInfos[nIndex].dShowScale)
								pMainWnd->m_environment.m_layerInfos[nIndex].layer.
								                                  SetVisible(TRUE);
						}
                        
						// 得到下一个节点
						hNextItem = m_LayerTreeView.GetNextItem(
							                       hThdChildItem, TVGN_NEXT);					
						hThdChildItem = hNextItem;
					}

					// 得到第3层的下一个节点
					hSecChildItem = m_LayerTreeView.GetNextItem(
						                           hSecChildItem, TVGN_NEXT);
				}

				// 得到第2层的下一个节点
				hChildItem = m_LayerTreeView.GetNextItem(
					                               hChildItem, TVGN_NEXT);
			}
			break;
		case 1:
			hCurrent = pNMTreeView->itemNew.hItem;
			m_LayerTreeView.SetCheck(hCurrent, !bChecked);
			// 得到第2层的第一个节点
			hChildItem = m_LayerTreeView.GetChildItem(hCurrent);
			while (hChildItem != NULL)
			{				
				m_LayerTreeView.SetCheck(hChildItem, !bChecked);
				// 得到第3层的第一个节点
				hSecChildItem = m_LayerTreeView.GetChildItem(hChildItem);
				while ( hSecChildItem != NULL)
				{
					m_LayerTreeView.SetCheck(hSecChildItem, !bChecked);
					// 得到该节点显示的名称(即地物类型名称)
					szName = m_LayerTreeView.GetItemText(hSecChildItem);
					// 根据地物类型名称得到图层的索引
					int nIndex = pMainWnd->m_environment.GetLayerIndexByName(szName);
					// 设置图层的可见性
					if (nIndex >=0)
					{
						pMainWnd->m_environment.m_layerInfos[nIndex].bVisible = true;
						//判断是否在显示比例之内
						double dScale = pMainWnd->m_environment.CalcScale(&(pMapView->m_Map));
						if (dScale< pMainWnd->m_environment.m_layerInfos[nIndex].dShowScale)
							pMainWnd->m_environment.m_layerInfos[nIndex].layer.SetVisible(TRUE);
					}
                    
					// 得到下一个节点
					hNextItem = m_LayerTreeView.GetNextItem(hSecChildItem, TVGN_NEXT);					
					hSecChildItem = hNextItem;
				}

				// 得到第2层的下一个节点
				hChildItem = m_LayerTreeView.GetNextItem(hChildItem, TVGN_NEXT);
			}
			break;
		case 2:
			hCurrent = pNMTreeView->itemNew.hItem;
			m_LayerTreeView.SetCheck(hCurrent, !bChecked);
			// 得到第3层的第一个节点
			hChildItem = m_LayerTreeView.GetChildItem(hCurrent);
			while (hChildItem != NULL)
			{				
				m_LayerTreeView.SetCheck(hChildItem, !bChecked);
				// 得到该节点显示的名称(即地物类型名称)
				szName = m_LayerTreeView.GetItemText(hChildItem);
				// 根据地物类型名称得到图层的索引
				int nIndex = pMainWnd->m_environment.GetLayerIndexByName(szName);
                // 设置图层的可见性
				if (nIndex >=0)
				{
					pMainWnd->m_environment.m_layerInfos[nIndex].bVisible = true;
					//判断是否在显示比例之内
					double dScale = pMainWnd->m_environment.CalcScale(&(pMapView->m_Map));
					if (dScale< pMainWnd->m_environment.m_layerInfos[nIndex].dShowScale)
						pMainWnd->m_environment.m_layerInfos[nIndex].layer.SetVisible(TRUE);
				}

				// 得到下一个节点
				hNextItem = m_LayerTreeView.GetNextItem(hChildItem, TVGN_NEXT);					
				hChildItem = hNextItem;
			}
			break;
		case 3:
			{
				int nIndex = pMainWnd->m_environment.GetLayerIndexByName(szName);
				if (nIndex >=0)
				{
					pMainWnd->m_environment.m_layerInfos[nIndex].bVisible = true;
					//判断是否在显示比例之内
					double dScale = pMainWnd->m_environment.CalcScale(&(pMapView->m_Map));
					if (dScale< pMainWnd->m_environment.m_layerInfos[nIndex].dShowScale)
						pMainWnd->m_environment.m_layerInfos[nIndex].layer.SetVisible(TRUE);
				}
			}
			break;
		}
	}

	// 最后刷新地图的显示
	pMapView->m_Map.SetExtent(pMapView->m_Map.GetExtent());
}
//-----------------------------------------------------------------------------------------
int CMapControlView::GetNodeLevel(HTREEITEM hItem)
{
	int nLevel = 0;

	// 循环寻找父节点
	while (m_LayerTreeView.GetParentItem(hItem))
	{
		hItem = m_LayerTreeView.GetParentItem(hItem);
		nLevel ++;
	}
    
	return nLevel;
}
//-----------------------------------------------------------------------------------------
void CMapControlView::OnTvnSelchangedMapindex(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMTREEVIEW pNMTreeView; 
	pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);	
	*pResult = 0;

	CString StartupPath = GetModulePath();
	HTREEITEM hCurrent = m_MapIndexTreeView.GetNextItem(TVI_ROOT, TVGN_CARET);
	TVITEM item;
	TCHAR szText[1024];
	item.hItem = hCurrent;
	item.mask = TVIF_TEXT | TVIF_HANDLE;
	item.pszText = szText;
	item.cchTextMax = 1024;
    
	BOOL bWorked = m_MapIndexTreeView.GetItem(&item);

	CString szMapName = item.pszText;
  
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CNameGisView* pMapView = (CNameGisView*)(pMainWnd->m_wndSplitter.GetPane(0,0));
	CHawkView* pHawkView = (CHawkView*)(((CMainFrame*)pMainWnd)->m_wndSplitter2.GetPane(1,0));

	bool		bIndex = false;
	CString		szIndex = "";

	if (m_MapIndexTreeView.GetNextItem(pNMTreeView->itemNew.hItem, TVGN_PARENT) != NULL)
	{
		szIndex = szMapName; 
		bIndex = true;
	}

	// 根据地图名称得到当前地图在地图集合中的索引
	int nIndex = pMainWnd->m_environment.GetMapIndex(szMapName);
	if ((nIndex != pMainWnd->m_environment.m_nCurrMapIndex) 
		&& (nIndex >= 0))
	{
		pMainWnd->m_environment.m_nCurrMapIndex = nIndex;

		if (nIndex == 0)
			pMainWnd->m_environment.m_szSDBPath = StartupPath + "\\电子地图\\";
		else
			pMainWnd->m_environment.m_szSDBPath = StartupPath + "\\电子地图\\";

		pMainWnd->LoadLayerInfos(pMainWnd->m_environment.m_nCurrMapIndex);
		pMainWnd->InitialLayerCtrlView(); 
		pMapView->LoadLayers();
		pHawkView->LoadLayersForEagleEye();
	}

	if (bIndex)
	{
		for (int i=0; i<pMainWnd->m_environment.m_nIndexNum; i ++)
		{
			if (szIndex == pMainWnd->m_environment.m_indexInfos[i].szName)  
			{
				pMapView->m_Map.SetExtent(pMainWnd->m_environment.m_indexInfos[i].m_extent);
				// 重新注记图层
				pMapView->ReLabelLayers(); 
				// 重新显示图层
				pMapView->ReShowLayers();
			}
		}

		pHawkView->m_HawkMap.SetExtent(pHawkView->m_HawkMap.GetExtent());
	}
}
//-----------------------------------------------------------------------------------------
// 功能:将选中的地名名称显示在output窗口
void CMapControlView::OutputResult()
{
	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();

	// 首先清空列表框
	m_ResultListBox.ResetContent();
	for (int i=0; i<pMainWnd->m_environment.m_nLayerNum; i ++)
	{
		if (!pMainWnd->m_environment.m_layerInfos[i].bVisible)
			continue;
        
		CString szFieldName = "名称";
		CMoRecordset rs;
		rs = pMainWnd->m_environment.m_layerInfos[i].rsSel;
		
		if (rs != NULL)
		{
			// 移动到第一条记录
			rs.MoveFirst();
            
			while (!rs.GetEof())
			{
				COleVariant var;
				var = rs.GetFields().Item(COleVariant(szFieldName)).GetValue();				
				if (var)
				{
					CString szName = CString(var.bstrVal); 
                    
					if (szName !="")
					{
						// 加入该名称
						m_ResultListBox.AddString(szName);  						
					}
				}
                
				// 移动到下一条记录
				rs.MoveNext(); 
			}
		}
	}
}
//-----------------------------------------------------------------------------------------
void CMapControlView::OnBnClickedButtonContent()
{
	int nIndex = m_ResultListBox.GetCurSel();
	if (nIndex < 0)
		return;

	CString szName;
	m_ResultListBox.GetText(nIndex, szName);
	if ("" == szName)  
		return;

	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	CString szTable = pMainWnd->m_environment.GetTableName(szName, "地名索引");	
	if ("" == szTable)
	{
		AfxMessageBox("数据库中无此地名!"); 
		return;
	}

	CContentDlg ContentDlg (pMainWnd);
	ContentDlg.m_szName = szName; 
	ContentDlg.DoModal();
}
//-----------------------------------------------------------------------------------------
void CMapControlView::OnBnClickedButtonPositing()
{
	int nIndex = m_ResultListBox.GetCurSel();
	if (nIndex < 0)
		return;

	CString szName;
	m_ResultListBox.GetText(nIndex, szName);
	if ("" == szName)  
		return;

	CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
	pMainWnd->Position(szName);
}
//-----------------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -