📄 maptestview.cpp
字号:
pDoc->m_pDefaultBitmap = (CBitmap*)pDoc->m_pMemDC->SelectObject(pDoc->m_pBitmap);
pDoc->m_pMemDC->BitBlt(0, 0, cx, cy, NULL, 0, 0, WHITENESS);//清空BITMAP
pDoc->m_nViewWidth = cx;
pDoc->m_nVeiwHeight = cy;
}
//
//////////////////自加
ReleaseDC(pDC);//释放DC资源
}
void CMapTestView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
::ClipCursor(NULL);//释放鼠标锁定(LButtonDown()中锁定)
CMapTestDoc* pDoc = GetDocument();
if( !pDoc->m_aLayers.GetSize() )
{//未打开地图
return;
}
switch(m_nMouseMode)
{
case ID_Pan:
m_bMapMoving = false;
pDoc->MoveOffset(point - m_ptOldPoint);
pDoc->DrawMap(pDoc->m_pMemDC);//重绘地图
Invalidate(false);//更新显示
break;
///////////////////
case ID_ARROW:
/*::ClipCursor(NULL);//释放鼠标锁定
m_bDrawing = false;//停止绘图
SetCursor(m_hcurArrow);//恢复光标显示
::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_hcurArrow);
Invalidate();//刷新视图*/
break;
}
CView::OnLButtonUp(nFlags, point);
}
void CMapTestView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMapTestDoc* pDoc = GetDocument();
CDC* pDC = GetDC();//申请DC
if(m_bMapMoving)//漫游
{
CPoint pt = point - m_ptOldPoint;//计算偏移量
//清空显示区其他区域
if(pt.x<0)
{//pt.x<0,图像左移,清空右侧
pDC->BitBlt(pDoc->m_nViewWidth + pt.x, 0, -pt.x, pDoc->m_nVeiwHeight,
NULL, 0, 0, WHITENESS);
}
else if(pt.x>0)
{//pt.x>0,图像右移,清空左侧
pDC->BitBlt(0, 0, pt.x, pDoc->m_nVeiwHeight,
NULL, 0, 0, WHITENESS);
}
if(pt.y<0)
{//pt.y<0,图像上移,清空下侧
pDC->BitBlt(0, pDoc->m_nVeiwHeight + pt.y, pDoc->m_nViewWidth, -pt.y,
NULL, 0, 0, WHITENESS);
}
else if(pt.y>0)
{//pt.y>0,图像下移,清空上侧
pDC->BitBlt(0, 0, pDoc->m_nViewWidth, pt.y,
NULL, 0, 0, WHITENESS);
}
pDC->BitBlt(pt.x, pt.y, pDoc->m_nViewWidth, pDoc->m_nVeiwHeight,
pDoc->m_pMemDC, 0, 0, SRCCOPY);//复制图像(BITMAP)
}
else
{
pDoc->DisplayJW(point);
}
ReleaseDC(pDC);//释放DC资源
CView::OnMouseMove(nFlags, point);
}
void CMapTestView::OnConvFile()
{
// TODO: Add your command handler code here
CMapTestDoc* pDoc = GetDocument();
CMapLayer *pMapLaer;
for(int n=0;n<No;n++)
{
CString strLayerPath,strMidPath;
strLayerPath=path[n];
int len=strLayerPath.GetLength();
strMidPath=strLayerPath;
strMidPath.SetAt(len-1,'D');
//读取mif文件
CFile layerFile(strLayerPath,CFile::modeRead); //CFile 文件操作类 CFile <对象名>(文件名,方式)
CArchive ar(&layerFile, CArchive::load); //CArchive使用缓冲区作为临时数据存储地,读写都先依次排列到此缓冲区,当缓冲区满或用户要求时,将此段整理后的数据读写到指定的存储介质。 好比火车货场装运零散的货物被收集,当总量到达火车运量的时候,由火车装运走。
// pMapLaer = new CMapLayer(pDoc, ar);
//读取MID文件
CFile midFile(strMidPath,CFile::modeRead); //CFile 文件操作类 CFile <对象名>(文件名,方式)
CArchive br(&midFile, CArchive::load); //CArchive使用缓冲区作为临时数据存储地,读写都先依次排列到此缓冲区,当缓冲区满或用户要求时,将此段整理后的数据读写到指定的存储介质。 好比火车货场装运零散的货物被收集,当总量到达火车运量的时候,由火车装运走。
//if(AfxMessageBox("选择导出文件的格式,/n 选择确定导出文本",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
// {
//运行保存对话框
static char BASED_CODE szCtlFilter[]="地图文件(*.GPS)|*.GPS||";
CFileDialog dlg(false,"GPS","*.GPS",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szCtlFilter,this);
if(dlg.DoModal()==IDCANCEL) return;
CString strMapName;
CFile cfile;
strMapName=dlg.GetPathName();
// pDoc->m_strMapName=strMapName;
CArchive wr(&cfile, CArchive::store);//file和wr关联
if(cfile.Open(LPCTSTR(strMapName), CFile::modeCreate | CFile::modeWrite))
{
CString str,str1,str2,zb;
while(ar.ReadString(str))
{
str1 = pMapLaer->GetFirstPara(str); //读取对象名称字符串
if(str1=="Point")
{
wr.WriteString("P");//输入一个点标志
wr.WriteString(" "); //输入一个空格
br.ReadString(str2); //在mid中读取对应的行
wr.WriteString(str2);
wr.WriteString(_T("\r\n"));
CMapPoint* pMapPoint=new CMapPoint(pDoc,ar,str);
zb.Format("%.6f",pMapPoint->m_fMinX);//对象坐标。格式化输出,%.6f表示有六个小数
wr.WriteString (zb);
wr.WriteString(" ");
zb.Format("%.6f",pMapPoint->m_fMinY);//对象坐标
wr.WriteString (zb);
// wr.WriteString(" "); //
wr.WriteString(_T("\r\n"));
}
else if(str1=="Pline")
{
int i,j;
double jing, wei;
wr.WriteString("PL");
wr.WriteString(" ");
j=pMapLaer->GetSecondPara(str);
zb.Format("%d",j);//对象坐标。格式化输出,%.6f表示有六个小数
wr.WriteString (zb);
// wr.WriteString(" ");
wr.WriteString(_T("\r\n")); //输入回车 换行
CMapPLine* PL = new CMapPLine(pDoc, ar,j);
double* jw= PL->m_pData ;
for(i=0;i<j;i++)
{
jing = *(jw + i*2);
wei = *(jw + i*2 + 1);
zb.Format("%.6f",jing);//对象坐标。格式化输出,%.6f表示有六个小数
wr.WriteString (zb);
wr.WriteString(" ");
zb.Format("%.6f",wei);//对象坐标
wr.WriteString (zb);
wr.WriteString(" "); //
wr.WriteString(_T("\r\n")); //输入回车 换行
}
zb.Format("%d",PL->m_nColor);//对象坐标。格式化输出,%d表示为整数
wr.WriteString (zb);
wr.WriteString(_T("\r\n")); //输入回车 换行
}
else if(str1=="Region") //转出区域
{
int i,j,k;
double jing, wei;
CString strR;
wr.WriteString("Rg");
wr.WriteString(" ");
j=pMapLaer->GetSecondPara(str);
zb.Format("%d",j);//对象坐标。格式化输出,%d表示为整数
wr.WriteString (zb);
// wr.WriteString(" ");
wr.WriteString(_T("\r\n")); //输入回车 换行
ar.ReadString(strR);
k = atoi(LPCTSTR(strR));//读当前多边形端点数
zb.Format("%d",k-1);//对象坐标。格式化输出,%d表示为整数
wr.WriteString (zb);
wr.WriteString(_T("\r\n")); //输入回车 换行
CMapRegion* Rg = new CMapRegion(pDoc,ar,k);
double* jw= Rg->m_pData ;
for(i=0;i<k-1;i++)
{
jing = *(jw + i*2);
wei = *(jw + i*2 + 1);
zb.Format("%.6f",jing);//对象坐标。格式化输出,%.6f表示有六个小数
wr.WriteString (zb);
wr.WriteString(" ");
zb.Format("%.6f",wei);//对象坐标
wr.WriteString (zb);
wr.WriteString(" "); //
wr.WriteString(_T("\r\n")); //输入回车 换行
}
zb.Format("%d",Rg->m_nColor);//对象坐标。格式化输出,%d表示为整数
wr.WriteString (zb);
wr.WriteString(_T("\r\n")); //输入回车 换行
}
}
}
wr.Close();
cfile.Close();
// }
// else //导出为ACCESS数据库
// {
// HRESULT hr;
// {
// hr=m_pConnection.CreateInstance("ADODB.Connection");
// if(SUCCEEDED(hr))
// {
// m_pConnection->ConnectionTimeout=5;
// hr=m_pConnection->Open("Data Source=info.mdb;UID=;PWD=;","","",adModeUnknown);
// }
// }
// }
}}
void CMapTestView::OnOpenData()
{
// TODO: Add your command handler code here
CDC* pDC = GetDC();//申请DC
CString strDataPath;
CMapTestDoc* pDoc = GetDocument();
char filterstr[]="MapInfo 文件(*.GPS)|*.GPS||";
CFileDialog dlg(true,"GPS",NULL,OFN_HIDEREADONLY,filterstr,this);
// dlg.m_ofn.Flags |= OFN_ALLOWMULTISELECT;//允许多选
if(dlg.DoModal()==IDCANCEL) return;
pDoc->mif_gps =false;//判断打开的是GPS文件
//读取GPS文件中的全部内容
strDataPath=dlg.GetPathName();
CFile layerFile(strDataPath,CFile::modeRead); //CFile 文件操作类 CFile <对象名>(文件名,方式)
CArchive map(&layerFile, CArchive::load); //CArchive使用缓冲区作为临时数据存储地,读写都先依次排列到此缓冲区,当缓冲区满或用户要求时,将此段整理后的数据读写到指定的存储介质。 好比火车货场装运零散的货物被收集,当总量到达火车运量的时候,由火车装运走。
pMapLaer = new CMapLayer(pDoc, map);
pDoc->m_aLayers.Add(pMapLaer); //添加图层
///////////////////////////////////////
map.Close();
layerFile.Close();
pDoc->m_nMaxPoint = pDoc->m_nMaxPoint > pMapLaer->m_nMaxPoint ? pDoc->m_nMaxPoint : pMapLaer->m_nMaxPoint;
pDoc->m_fMapjw[0] = pDoc->m_fMinX ;
pDoc->m_fMapjw[1] = pDoc->m_fMaxX ;
pDoc->m_fMapjw[2] = pDoc->m_fMaxY ; //上
pDoc->m_fMapjw[3] = pDoc->m_fMinY ;//下
double dx,dy;
dx=pDoc->m_fMaxX-pDoc->m_fMinX ;
dy=pDoc->m_fMaxY-pDoc->m_fMinY;
pDoc->SetMapReach(dx,dy); //设置地图显示区域的大小,dx dy为地图的实际大小
pDoc->m_pData = new long[pDoc->m_nMaxPoint*2];//申请计算用临时内存
pDoc->DrawMap(pDoc->m_pMemDC);//在位图上绘制地图
Invalidate();
ReleaseDC(pDC);
}
void CMapTestView::OnFindPath() //寻找路径
{
// TODO: Add your command handler code here
::SetClassLong(GetSafeHwnd(), GCL_HCURSOR, (LONG)m_hcurCross);
m_nMouseMode=ID_FindPath;
}
void CMapTestView::OnUpdateFindPath(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CMapTestView::OnMapClose()
{
CMapTestDoc* pDoc = GetDocument();
if(AfxMessageBox("确定要清空地图吗?",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
{
// TODO: Add your command handler code here
pDoc->InitData();//初始化用户数据
pDoc->DrawMap(pDoc->m_pMemDC);//刷新海图
Invalidate(false);//更新显示
pDoc->OnNewDocument();//关闭“文档”。必须关闭,否则下次无法打开同一个文档
}
}
void CMapTestView::onContextMenu(CWnd* Wnd, CPoint point)
{
CMenu menuPopup;
if(menuPopup.CreatePopupMenu())
{
//向菜单 menuPopup 中添加菜单项
menuPopup.AppendMenu(MF_STRING,ID_ZoomIn,"放大\tCtrl+A");
menuPopup.AppendMenu(MF_STRING,ID_ZoomOut,"缩小\tCtrl+B");
//显示弹出式菜单,并对用户选择的菜单项作出反应
menuPopup.TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -