给单文档添加地图的方法 创建单文档后,在程序的目录文件里面考入两个类的头文件和源文件:yimaenc和yimaenchead还有授权的lib文件。哦,对了,还有例子里面的3个文件夹。 一:CMainFrame头文件添加public控件对象: CYimaEnc m_yimaEncCtrl; 莫要忘记包含头文件:#include "yimaenc.h" #include "yimaenchead.h" 二:CMainFrame::OnCreate里面创建控件 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"); //读入自定义海图数据文件 三:在view类里添加消息响应:WM_SETFOCUS 并在头文件里添加 CYimaEnc* m_pYimaEncCtrl; 在新增函数OnSetFocus里添加下列代码 if (m_pYimaEncCtrl == NULL) { CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
if (pFrame != NULL) { m_pYimaEncCtrl = &pFrame->m_yimaEncCtrl;
RECT clientRect; GetClientRect(&clientRect);
// RefreshDrawer 在初始化屏幕 或 改变海图屏幕大小时应该被调用 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: 注意!! 由于地理坐标值可能接近4字节 long 型变量的上限(但不会超出),所以在做加法或乘法时需要转换为float型 以防止溢出!*/ }
m_pYimaEncCtrl->FocusLibMap(0); } } } 动态添加新函数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 在初始化屏幕 或 改变海图屏幕大小时应该被调用 m_pYimaEncCtrl->RefreshDrawer((long)m_hWnd, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top, 0, 0);
CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
动态添加函数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); } } |
|