|
給單文檔添加地圖的方法 創(chuàng)建單文檔后,在程序的目錄文件里面考入兩個類的頭文件和源文件:yimaenc和yimaenchead還有授權(quán)的lib文件。哦,對了,還有例子里面的3個文件夾。 一:CMainFrame頭文件添加public控件對象: CYimaEnc m_yimaEncCtrl; 莫要忘記包含頭文件:#include "yimaenc.h" #include "yimaenchead.h" 二:CMainFrame::OnCreate里面創(chuàng)建控件 m_yimaEncCtrl.Create(NULL, NULL, CRect(0, 0, 0, 0), this, ID_YIMAENC_CTRL); TCHAR curWorkDir[1024]; GetCurrentDirectory(1024, curWorkDir); if (!m_yimaEncCtrl.Init(curWorkDir)) //YIMAENC COMMENT: YimaEnc Control interoped! { AfxMessageBox("Failed to init YimaEnc Control, may be the config files are not exits!"); return -1; } m_yimaEncCtrl.tmOpenMapDataFile("MarineMap\\marineMap.ymc"); //讀入自定義海圖數(shù)據(jù)文件 三:在view類里添加消息響應(yīng):WM_SETFOCUS 并在頭文件里添加 CYimaEnc* m_pYimaEncCtrl; 在新增函數(shù)OnSetFocus里添加下列代碼 if (m_pYimaEncCtrl == NULL) { CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
if (pFrame != NULL) { m_pYimaEncCtrl = &pFrame->m_yimaEncCtrl;
RECT clientRect; GetClientRect(&clientRect);
// RefreshDrawer 在初始化屏幕 或 改變海圖屏幕大小時應(yīng)該被調(diào)用 m_pYimaEncCtrl->RefreshDrawer((long)m_hWnd, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top, 0, 0);
bool bTestGetLibMapInfo = false; if (bTestGetLibMapInfo) { float originalScale = 0; long left, right, up, down;
m_pYimaEncCtrl->GetLibMapInfo(0, NULL, NULL, &originalScale, &left, &right, &up, &down, NULL, NULL); //得到海圖庫海圖信息
m_pYimaEncCtrl->SetCurrentScale(originalScale);
m_pYimaEncCtrl->CenterMap( ((float)left + right) / 2, ((float)up + down) / 2);
/* YIMAENC COMMENT: 注意!! 由于地理坐標(biāo)值可能接近4字節(jié) long 型變量的上限(但不會超出),所以在做加法或乘法時需要轉(zhuǎn)換為float型 以防止溢出!*/ }
m_pYimaEncCtrl->FocusLibMap(0); } } } 動態(tài)添加新函數(shù)RefreshScreenMap 并添加代碼 void CText1View::RefreshScreenMap() { if (m_pYimaEncCtrl != NULL) { HDC hdc = ::GetDC(m_hWnd); m_pYimaEncCtrl->DrawMapsInScreen((long)hdc); ::ReleaseDC(m_hWnd, hdc); } } 四:添加WM_SIZE if (m_pYimaEncCtrl != NULL) { RECT clientRect; GetClientRect(&clientRect);
// RefreshDrawer 在初始化屏幕 或 改變海圖屏幕大小時應(yīng)該被調(diào)用 m_pYimaEncCtrl->RefreshDrawer((long)m_hWnd, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top, 0, 0);
CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
動態(tài)添加函數(shù)RefreshScaleStatusBar /***************** 刷新比例尺信息顯示欄 ********************/ void CTextView::RefreshScaleStatusBar() { CStatusBar * pStatusBar = (CStatusBar *)AfxGetApp()->m_pMainWnd-> GetDescendantWindow(AFX_IDW_STATUS_BAR);
if (pStatusBar!=NULL) { float curScale = m_pYimaEncCtrl->GetCurrentScale();
CString strCurScale; strCurScale.Format("比例尺 1 : %d", (int)curScale); pStatusBar->SetPaneText(INDEX_PANE_FOR_SCALE, strCurScale); } } |
|
|