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

📄 mapcontrolview.cpp

📁 公交查询系统源代码 是武汉的 提供简单的查询和乘车方案 vc++
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					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 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层的第一个节点
				
					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);
					}
                    
					
				

				// 得到第2层的下一个节点
				hChildItem = m_LayerTreeView.GetNextItem(
					                         hChildItem, TVGN_NEXT);
			}
			break;
		
		case 2:
			hCurrent = pNMTreeView->itemNew.hItem;
			m_LayerTreeView.SetCheck(hCurrent, !bChecked);
			
					
			m_LayerTreeView.SetCheck(hCurrent, !bChecked);
			// 得到该节点显示的名称(即地物类型名称)
			szName = m_LayerTreeView.GetItemText(hCurrent);
			// 根据地物类型名称得到图层的索引
			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());
	FocusOnMain();
}
//-----------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//
int CMapControlView::GetNodeLevel(HTREEITEM hItem)
{
	int nLevel = 0;

	// 循环寻找父节点
	while (m_LayerTreeView.GetParentItem(hItem))
	{
		hItem = m_LayerTreeView.GetParentItem(hItem);
		nLevel ++;
	}
    
	return nLevel;
}
//-------------------------------------------------------------------------

void CMapControlView::OnSelchangedMapindex(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();
	CPublic_TGISView* pMapView = (CPublic_TGISView*)(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());
	}
	FocusOnMain();
}

//-----------------------------------------------------------------------------------------
// 功能:将选中的地名名称显示在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(); 
			}
		}
	}
	FocusOnMain();
}

void CMapControlView::OnButtonContent() 
{
	// TODO: Add your control notification handler code here
	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();
	FocusOnMain();
}

void CMapControlView::OnButtonPositing() 
{
	// TODO: Add your control notification handler code here
	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);
	FocusOnMain();
}



void CMapControlView::FocusOnMain()
{
	CMainFrame* pFrame=(CMainFrame*)GetParentFrame();
	pFrame->SetActiveView((CView*)(pFrame->m_wndSplitter).GetPane(0,0));
}

void CMapControlView::OnSetfocusListResult() 
{
	// TODO: Add your control notification handler code here
	FocusOnMain();
}

void CMapControlView::OnSetFocus(CWnd* pOldWnd) 
{
	CFormView::OnSetFocus(pOldWnd);
	
	// TODO: Add your message handler code here
	FocusOnMain();
}

⌨️ 快捷键说明

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