📄 public_tgisview.cpp
字号:
// 申请资源
m_pNearestDlg = new CNearestDlg();
if(m_pNearestDlg)
{
// 创建对话框
BOOL ret = m_pNearestDlg->Create(IDD_DIALOG_NEARESTNAME, this);
if(!ret)
{
AfxMessageBox("创建对话框失败!");
return;
}
// 显示为一非模态对话框
m_pNearestDlg->ShowWindow(SW_SHOW);
}
else
AfxMessageBox("创建对话框失败!");
}
else
{
// 显示为一非模态对话框
m_pNearestDlg->ShowWindow(SW_SHOW);
}
}
void CPublic_TGISView::OnMapNameindex()
{
// TODO: Add your command handler code here
CNameIndexDlg NameIndexDlg;
NameIndexDlg.DoModal();
}
int CPublic_TGISView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFormView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_nTimer = SetTimer(1, 100, 0);
return 0;
}
void CPublic_TGISView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(m_map.m_hWnd == NULL)
return;
if(m_map.GetMousePointer() != moArrow)
return;
if (m_x == m_lastX && m_y == m_lastY)
{
CMoRecordset recs;
recs = DoSearch();
if (!recs)
{
// 如果没有对应的地名,则隐藏标签倥件
m_NameLabel.ModifyStyle(WS_VISIBLE, 0,0);
}
else
{
if(recs.GetEof())
{
m_NameLabel.ModifyStyle(WS_VISIBLE, 0,0); // 隐藏标签倥件
return;
}
CString szText = recs.GetFields().Item(
COleVariant("名称")).GetValueAsString();
if (szText != "")
{
// 设置标签控件的显示内容与位置
m_NameLabel.SetWindowText(szText);
CRect rect;
m_NameLabel.GetWindowRect(&rect);
CSize sizeText;
CClientDC dc((CWnd*)&m_NameLabel);
// 得到文本在当前显示模式下的大小
sizeText = dc.GetTextExtent(szText);
// 设置标签控件的位置与大小
m_NameLabel.SetWindowPos(&CWnd::wndTop,
(int)(m_x + 20), // 标签控件左上点的X坐标
(int)(m_y + 11), // 标签控件左上点的Y坐标
sizeText.cx, // 标签控件的长度
sizeText.cy, // 标签控件的高度
SWP_SHOWWINDOW);
m_NameLabel.ModifyStyle(0, WS_VISIBLE, 0);
}
}
}
else
{
m_lastX = m_x;
m_lastY = m_y;
}
// 如果用户在进行其他操作,则不执行快速地名显示
CFormView::OnTimer(nIDEvent);
}
//----------------------------------------------------------------------------------------------
// 搜索某点处的地名
CMoRecordset CPublic_TGISView::DoSearch()
{
CMoRecordset rst;
if(!m_map.m_hWnd)
{
return rst;
}
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
CMoPoint pt;
pt = m_map.ToMapPoint((float)m_x,(float)m_y);
double dScale = pMainWnd->m_environment.CalcScale(&m_map);
dScale = dScale/10000;
dScale = dScale / 5000;
for (int i=pMainWnd->m_environment.m_nLayerNum - 1; i >= 0 ; i --)
{
if (pMainWnd->m_environment.m_layerInfos[i].layer.GetVisible()
&& pMainWnd->m_environment.m_layerInfos[i].bCanSelected
&& pMainWnd->m_environment.m_layerInfos[i].layer.GetShapeType() == moShapeTypePoint)
rst = pMainWnd->m_environment.m_layerInfos[i].layer.SearchByDistance(pt,dScale,"");
if (rst)
{
rst.MoveFirst();
if (!rst.GetEof())
return rst;
}
}
for ( i = 0; i <pMainWnd->m_environment.m_nLayerNum; i ++)
{
if (pMainWnd->m_environment.m_layerInfos[i].bVisible
&& pMainWnd->m_environment.m_layerInfos[i].bCanSelected
&& pMainWnd->m_environment.m_layerInfos[i].layer.GetShapeType() == moShapeTypeLine)
rst = pMainWnd->m_environment.m_layerInfos[i].layer.SearchByDistance(pt,dScale,"");
if (rst)
{
rst.MoveFirst();
if (!rst.GetEof())
return rst;
}
}
for ( i = 0; i<pMainWnd->m_environment.m_nLayerNum; i ++)
{
if (pMainWnd->m_environment.m_layerInfos[i].bVisible
&& pMainWnd->m_environment.m_layerInfos[i].bCanSelected
&& pMainWnd->m_environment.m_layerInfos[i].layer.GetShapeType() == moShapeTypePolygon)
rst = pMainWnd->m_environment.m_layerInfos[i].layer.SearchByDistance(pt,dScale,"");
if (rst)
{
rst.MoveFirst();
if (!rst.GetEof())
return rst;
}
}
return rst;
}
HBRUSH CPublic_TGISView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// 判断是否为目标控件
if (pWnd->GetDlgCtrlID() == IDC_MAPTIP_STATIC)
{
// 将文本颜色设置为红色
pDC->SetTextColor(RGB(255, 0, 0));
// 将背景颜色设置为黄色
pDC->SetBkColor(RGB(255,255,0));
}
return hbr;
}
//////////////////////////////////////////
void CPublic_TGISView::OnMapLinemearsure()
{
// TODO: Add your command handler code here
if(m_nCurTool == ID_MAP_LINEMEASURE)
{
m_nCurTool = NULL;
m_map.SetMousePointer(moArrow);
}
else
{
m_nCurTool = ID_MAP_LINEMEASURE;
m_map.SetMousePointer(moCross);
}
}
void CPublic_TGISView::OnUpdateMapLinemearsure(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nCurTool == ID_MAP_LINEMEASURE);
}
void CPublic_TGISView::OnMapAreameasure()
{
// TODO: Add your command handler code here
if(m_nCurTool == ID_MAP_AREAMEASURE)
{
m_nCurTool = NULL;
m_map.SetMousePointer(moArrow);
}
else
{
m_nCurTool = ID_MAP_AREAMEASURE;
m_map.SetMousePointer(moCross);
}
}
void CPublic_TGISView::OnUpdateMapAreameasure(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nCurTool == ID_MAP_AREAMEASURE);
}
void CPublic_TGISView::OnMapOutput()
{
// TODO: Add your command handler code here
CString szFilters = "位图(*.bmp)|*.bmp|增强的图元格式文件(*.emf)|*.emf|";
szFilters += "Jpeg文件(*.jpg)|*.jpg;*.jpeg||";
CFileDialog fileDlg(FALSE, "map", "*.bmp", OFN_FILEMUSTEXIST| OFN_HIDEREADONLY,
szFilters, this);
if( fileDlg.DoModal ()== IDOK)
{
CString ext = fileDlg.GetFileExt();
if(ext == "bmp")
{
m_map.ExportMap(moExportBMP, fileDlg.GetPathName(), 1);
}
else if(ext == "emf")
{
m_map.ExportMap(moExportEMF, fileDlg.GetPathName(), 1);
}
else
{
m_map.ExportMapToJpeg(fileDlg.GetPathName(), 100, TRUE, 1,
moLineSymbolsNotScaled);
}
}
}
void CPublic_TGISView::OnMapPrint()
{
// TODO: Add your command handler code here
m_map.PrintMap("地图", "武汉市公共交通GIS", TRUE);
}
void CPublic_TGISView::OnMapHelp()
{
// TODO: Add your command handler code here
CString www = GetModulePath() + "\\帮助\\系统简介.htm";
ShellExecute(m_hWnd, "open", www,0,0,SW_SHOW);
}
BOOL CPublic_TGISView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TODO: Add your message handler code here and/or call default
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
if (zDelta > 0 )
{
CMoRectangle r(m_map.GetExtent());
ASSERT(LPDISPATCH(r));
r.ScaleRectangle(2.0/3.0);
m_map.SetExtent(r);
}
else if (zDelta < 0)
{
CMoRectangle r(m_map.GetExtent());
ASSERT(LPDISPATCH(r));
r.ScaleRectangle(3.0/2.0);
m_map.SetExtent(r);
}
ReLabelLayers();
ReShowLayers();
CHawkView* pHawkView = (CHawkView*)(pMainWnd->
m_wndSplitter2.GetPane(1,0));
pHawkView->m_HawkMap.SetExtent(pHawkView->m_HawkMap.GetExtent());
return CFormView::OnMouseWheel(nFlags, zDelta, pt);
}
void CPublic_TGISView::OnButton32805()
{
// TODO: Add your command handler code here
}
void CPublic_TGISView::OnButton32806()
{
// TODO: Add your command handler code here
}
void CPublic_TGISView::OnMapMusic()
{
// TODO: Add your command handler code here
AfxBeginThread((AFX_THREADPROC)sound,NULL,THREAD_PRIORITY_NORMAL);
}
UINT CPublic_TGISView::sound(LPVOID pParam)
{
HINSTANCE h=AfxGetInstanceHandle();
HRSRC hr=FindResource(h,"IDW","WAVE");
HGLOBAL hg=LoadResource(h,hr);
LPSTR lp=(LPSTR)LockResource(hg);
sndPlaySound(lp,SND_MEMORY|SND_SYNC);
hg=LoadResource(h,hr);
lp=(LPSTR)LockResource(hg);
sndPlaySound(lp,SND_MEMORY|SND_SYNC);
FreeResource(hg);
return 0;
}
void CPublic_TGISView::LineNavigation()
{
navigation = true;
Invalidate(true);
}
void CPublic_TGISView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
if(true == navigation)
{
CMoTrackingLayer tLayer(m_map.GetTrackingLayer());
VARIANT va;
VariantInit(&va);
tLayer.Refresh(true, va);
navigation = false;
}
}
void CPublic_TGISView::OnAfterTrackingLayerDrawMap1(long hDC)
{
// TODO: Add your control notification handler code here
if(true == navigation)
{
CMainFrame* pMainWnd = (CMainFrame*)AfxGetMainWnd();
CHawkView* pHawkView = (CHawkView*)(pMainWnd->m_wndSplitter2.GetPane(1,0));
long dScale = (long)pMainWnd->m_environment.CalcScale(&m_map); //地图比例尺
// 绘画公交车站
if (pMainWnd->m_environment.m_buses != NULL && dScale < 200000)
{
HPEN tempPen = CreatePen(PS_SOLID, 7, RGB(0, 255, 255));
SelectObject((HDC)hDC, tempPen);
// SelectObject(hDC, tempPen);
// 先统计有效点的个数
int nCount = 0;
for (int i=0; i<pMainWnd->m_environment.m_buses->nNum; i ++)
{
if (pMainWnd->m_environment.m_buses->pts[i].x < 0 ||
pMainWnd->m_environment.m_buses->pts[i].y < 0)
continue;
else
nCount ++;
}
POINT* pts = new POINT[nCount];
int nTemp = 0;
for (i=0; i<pMainWnd->m_environment.m_buses->nNum; i ++)
{
if (pMainWnd->m_environment.m_buses->pts[i].x < 0 ||
pMainWnd->m_environment.m_buses->pts[i].y < 0)
continue;
MPoint pt = pMainWnd->m_environment.FromMapPoint(&m_map,
pMainWnd->m_environment.m_buses->pts[i].x,
pMainWnd->m_environment.m_buses->pts[i].y);
pts[nTemp].x = (long) pt.x;
pts[nTemp].y = (long) pt.y;
if(0 == nTemp)
{
m_map.CenterAt(pts[0].x, pts[0].y);
pHawkView->m_HawkMap.SetExtent(pHawkView->m_HawkMap.GetExtent());
RECT rect;
rect.top = pts[0].y - 55;
rect.left= pts[0].x - 25;
rect.bottom = pts[0].y - 20;
rect.right = pts[0].x + 25;
DrawText((HDC)hDC,"起点站", -1, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
}
if(nTemp > 0)
{
m_map.CenterAt(pts[nTemp].x, pts[nTemp].y);
pHawkView->m_HawkMap.SetExtent(pHawkView->m_HawkMap.GetExtent());
::Polyline((HDC)hDC, pts, nTemp+1);
RECT rect;
if(nTemp != pMainWnd->m_environment.m_buses->nNum-1)
{
rect.top = pts[nTemp].y - 20;
rect.left= pts[nTemp].x - 8;
rect.bottom = pts[nTemp].y - 10;
rect.right = pts[nTemp].x + 8;
char str[10] = "";
itoa(nTemp, str, 10);
DrawText((HDC)hDC, str , -1, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
}
else
{
rect.top = pts[nTemp].y - 55;
rect.left= pts[nTemp].x - 25;
rect.bottom = pts[nTemp].y - 20;
rect.right = pts[nTemp].x + 25;
DrawText((HDC)hDC, "终点站" , -1, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
}
Sleep(1200);
}
nTemp ++;
}
delete pts;
pts = NULL;
}
}
}
//为系统添加右键菜单
void CPublic_TGISView::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
CMenu menuPopup;
if(menuPopup.CreatePopupMenu())
{
menuPopup.AppendMenu(MF_STRING, ID_MAP_ZOOMIN, "放大");
menuPopup.AppendMenu(MF_STRING, ID_MAP_ZOOMOUT, "缩小");
menuPopup.AppendMenu(MF_STRING, ID_MAP_FULLEXTENT, "全局地图");
menuPopup.AppendMenu(MF_STRING, ID_MAP_POINTSEL, "选择");
menuPopup.AppendMenu(MF_STRING, ID_MAP_QUERY, "信息工具");
menuPopup.AppendMenu(MF_STRING, ID_MAP_OUTPUT, "输出地图");
menuPopup.AppendMenu(MF_STRING, ID_MAP_HELP, "帮助");
//显示弹出式菜单,并对用户选择的菜单项作出反应
menuPopup.TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -