MapView.cpp
上传用户:jc6688
上传日期:2013-05-06
资源大小:344k
文件大小:37k
源码类别:

GPS编程

开发平台:

Visual C++

  1. // MapView.cpp : implementation of the CMapView class
  2. //
  3. #include "stdafx.h"
  4. #include "MapDemo.h"
  5. #include "MapDemoDoc.h"
  6. #include "MapView.h"
  7. #include "MapFormView.h"
  8. #include "MainFrm.h"
  9. #include "GeoSetDlg.h"
  10. #include "MapXSetDlg.h"
  11. #include "SelDlg.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. #define IDC_MAP 100
  18. #define MYTOOL_INFO 1
  19. #define MYTOOL_DISTANCE 2
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CMapView
  22. IMPLEMENT_DYNCREATE(CMapView, CView)
  23. BEGIN_MESSAGE_MAP(CMapView, CView)
  24. //{{AFX_MSG_MAP(CMapView)
  25. ON_WM_SIZE()
  26. ON_WM_CREATE()
  27. ON_COMMAND(ID_FILE_OPENGEOSET, OnFileOpengeoset)
  28. ON_COMMAND(ID_VIEW_SYSOPTION, OnViewSysoption)
  29. ON_COMMAND(ID_MAP_TOOL_SELECT, OnMapToolSelect)
  30. ON_COMMAND(ID_MAP_TOOL_ZOOMIN, OnMapToolZoomin)
  31. ON_COMMAND(ID_MAP_TOOL_ZOOMOUT, OnMapToolZoomout)
  32. ON_COMMAND(ID_MAP_TOOL_PAN, OnMapToolPan)
  33. ON_COMMAND(ID_MAP_TOOL_RADIUSSELECT, OnMapToolRadiusselect)
  34. ON_COMMAND(ID_MAP_TOOL_RECTANGLESELECT, OnMapToolRectangleselect)
  35. ON_COMMAND(ID_MAP_TOOL_INFORMATION, OnMapToolInformation)
  36. ON_COMMAND(ID_VIEW_LAYERCONTROL, OnViewLayercontrol)
  37. ON_COMMAND(ID_VIEW_SCALEBAR, OnViewScalebar)
  38. ON_UPDATE_COMMAND_UI(ID_VIEW_SCALEBAR, OnUpdateViewScalebar)
  39. ON_COMMAND(ID_TOOL_UNSELECTALL, OnToolUnselectall)
  40. ON_COMMAND(ID_MAPEDIT_SELETTABLE, OnMapeditSelettable)
  41. ON_COMMAND(ID_MAPEDIT_ADDTEXT, OnMapeditAddtext)
  42. ON_COMMAND(ID_MAPEDIT_ADDSYMBOL, OnMapeditAddsymbol)
  43. ON_UPDATE_COMMAND_UI(ID_MAPEDIT_ADDTEXT, OnUpdateMapeditAddtext)
  44. ON_UPDATE_COMMAND_UI(ID_MAPEDIT_ADDSYMBOL, OnUpdateMapeditAddsymbol)
  45. ON_COMMAND(ID_MAPEDIT_ADDLINE, OnMapeditAddline)
  46. ON_UPDATE_COMMAND_UI(ID_MAPEDIT_ADDLINE, OnUpdateMapeditAddline)
  47. ON_COMMAND(ID_MAPEDIT_ADDPOLYGON, OnMapeditAddpolygon)
  48. ON_UPDATE_COMMAND_UI(ID_MAPEDIT_ADDPOLYGON, OnUpdateMapeditAddpolygon)
  49. ON_COMMAND(ID_MAPEDIT_ADDRECT, OnMapeditAddrect)
  50. ON_UPDATE_COMMAND_UI(ID_MAPEDIT_ADDRECT, OnUpdateMapeditAddrect)
  51. ON_COMMAND(ID_MAPEDIT_ADDEPPLISE, OnMapeditAddepplise)
  52. ON_UPDATE_COMMAND_UI(ID_MAPEDIT_ADDEPPLISE, OnUpdateMapeditAddepplise)
  53. ON_COMMAND(IDD_MAPEDIT_ADDARC, OnMapeditAddarc)
  54. ON_UPDATE_COMMAND_UI(IDD_MAPEDIT_ADDARC, OnUpdateMapeditAddarc)
  55. ON_WM_DESTROY()
  56. ON_COMMAND(ID_ADD_TARGET, OnAddTarget)
  57. ON_COMMAND(ID_EDIT_TARGET, OnEditTarget)
  58. ON_COMMAND(ID_START_GPS, OnStartGps)
  59. ON_UPDATE_COMMAND_UI(ID_START_GPS, OnUpdateStartGps)
  60. ON_COMMAND(ID_END_GPS, OnEndGps)
  61. ON_UPDATE_COMMAND_UI(ID_END_GPS, OnUpdateEndGps)
  62. ON_UPDATE_COMMAND_UI(ID_ADD_TARGET, OnUpdateAddTarget)
  63. ON_UPDATE_COMMAND_UI(ID_EDIT_TARGET, OnUpdateEditTarget)
  64. ON_COMMAND(ID_GPS_CHANGESYMBOL, OnGpsChangesymbol)
  65. ON_UPDATE_COMMAND_UI(ID_GPS_CHANGESYMBOL, OnUpdateGpsChangesymbol)
  66. ON_WM_TIMER()
  67. ON_COMMAND(ID_CHANGE_SYMBOL, OnChangeSymbol)
  68. ON_UPDATE_COMMAND_UI(ID_CHANGE_SYMBOL, OnUpdateChangeSymbol)
  69. ON_COMMAND(ID_LINE_CHANGE, OnLineChange)
  70. ON_COMMAND(ID_REAGION_CHANGE, OnReagionChange)
  71. ON_COMMAND(ID_MAPX_PROPERTY, OnMapxProperty)
  72. ON_COMMAND(ID_DATABIND_NORMAL, OnDatabindNormal)
  73. ON_UPDATE_COMMAND_UI(ID_DATABIND_NORMAL, OnUpdateDatabindNormal)
  74. ON_COMMAND(ID_BINDDATA_ODBC, OnBinddataOdbc)
  75. ON_UPDATE_COMMAND_UI(ID_BINDDATA_ODBC, OnUpdateBinddataOdbc)
  76. ON_COMMAND(ID_BINDDATA_ARRAY, OnBinddataArray)
  77. ON_UPDATE_COMMAND_UI(ID_BINDDATA_ARRAY, OnUpdateBinddataArray)
  78. ON_COMMAND(ID_BINDDATA_NOBIND, OnBinddataNobind)
  79. ON_UPDATE_COMMAND_UI(ID_BINDDATA_NOBIND, OnUpdateBinddataNobind)
  80. ON_COMMAND(ID_THEME_REANGE, OnThemeReange)
  81. ON_UPDATE_COMMAND_UI(ID_THEME_REANGE, OnUpdateThemeReange)
  82. ON_COMMAND(ID_THEME_DOT, OnThemeDot)
  83. ON_UPDATE_COMMAND_UI(ID_THEME_DOT, OnUpdateThemeDot)
  84. ON_COMMAND(ID_THEME_PIE, OnThemePie)
  85. ON_UPDATE_COMMAND_UI(ID_THEME_PIE, OnUpdateThemePie)
  86. ON_COMMAND(ID_THEME_SYMBOL, OnThemeSymbol)
  87. ON_UPDATE_COMMAND_UI(ID_THEME_SYMBOL, OnUpdateThemeSymbol)
  88. ON_COMMAND(ID_THEME_INDIV, OnThemeIndiv)
  89. ON_UPDATE_COMMAND_UI(ID_THEME_INDIV, OnUpdateThemeIndiv)
  90. ON_COMMAND(ID_THEME_BAR, OnThemeBar)
  91. ON_UPDATE_COMMAND_UI(ID_THEME_BAR, OnUpdateThemeBar)
  92. //}}AFX_MSG_MAP
  93. // Standard printing commands
  94. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  95. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  96. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  97. END_MESSAGE_MAP()
  98. ////////////////////////////////////////////////////////
  99. //MapX事件响应函数
  100. //使用用户自定义图层
  101. BEGIN_EVENTSINK_MAP(CMapView, CView)
  102. ON_EVENT(CMapView, IDC_MAP, MAPX_DISPID_DRAWUSERLAYER, OnDrawUserLayer, VTS_DISPATCH VTS_I4 VTS_I4 VTS_DISPATCH VTS_DISPATCH)
  103. ON_EVENT(CMapView, IDC_MAP, MAPX_DISPID_TOOLUSED, OnToolUsed, VTS_I2 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_R8 VTS_BOOL VTS_BOOL VTS_PBOOL)                                                                                        
  104. ON_EVENT(CMapView, IDC_MAP, MAPX_DISPID_POLYTOOLUSED, OnPolyToolUsedMap, VTS_I2 VTS_I4 VTS_DISPATCH VTS_BOOL VTS_BOOL VTS_PBOOL)
  105. ON_EVENT(CMapView, IDC_MAP, -605 /* MouseDown */, OnMouseDownMap, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
  106. ON_EVENT(CMapView, IDC_MAP, DISPID_MOUSEUP, OnMouseUpInMap, VTS_I2 VTS_I2 VTS_XPOS_PIXELS VTS_YPOS_PIXELS)
  107. ON_EVENT(CMapView, IDC_MAP, DISPID_MOUSEMOVE, OnMouseMoveInMap, VTS_I2 VTS_I2 VTS_XPOS_PIXELS VTS_YPOS_PIXELS)
  108. END_EVENTSINK_MAP()
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CMapView construction/destruction
  111. CMapView::CMapView()
  112. {
  113. m_dPrevZoom = 0;
  114. m_dCurZoom = 0;
  115. m_bScaleBar = FALSE;
  116. //m_bODBCDynamic = FALSE;
  117. m_strEditLayer="";
  118. m_bIsStartGps=FALSE;
  119. m_nGpsOperation=GPS_NOOPERATION;
  120. m_bIsAutoLable=FALSE;
  121. m_pTarget=NULL;
  122. }
  123. CMapView::~CMapView()
  124. {
  125. }
  126. BOOL CMapView::PreCreateWindow(CREATESTRUCT& cs)
  127. {
  128. // TODO: Modify the Window class or styles here by modifying
  129. //  the CREATESTRUCT cs
  130. return CView::PreCreateWindow(cs);
  131. }
  132. /////////////////////////////////////////////////////////////////////////////
  133. // CMapView drawing
  134. void CMapView::OnDraw(CDC* pDC)
  135. {
  136. CMapDemoDoc* pDoc = GetDocument();
  137. ASSERT_VALID(pDoc);
  138. // TODO: add draw code for native data here
  139. }
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CMapView printing
  142. BOOL CMapView::OnPreparePrinting(CPrintInfo* pInfo)
  143. {
  144. // default preparation
  145. return DoPreparePrinting(pInfo);
  146. }
  147. void CMapView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  148. {
  149. // TODO: add extra initialization before printing
  150. }
  151. void CMapView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  152. {
  153. // TODO: add cleanup after printing
  154. }
  155. /////////////////////////////////////////////////////////////////////////////
  156. // CMapView diagnostics
  157. #ifdef _DEBUG
  158. void CMapView::AssertValid() const
  159. {
  160. CView::AssertValid();
  161. }
  162. void CMapView::Dump(CDumpContext& dc) const
  163. {
  164. CView::Dump(dc);
  165. }
  166. CMapDemoDoc* CMapView::GetDocument() // non-debug version is inline
  167. {
  168. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMapDemoDoc)));
  169. return (CMapDemoDoc*)m_pDocument;
  170. }
  171. #endif //_DEBUG
  172. /////////////////////////////////////////////////////////////////////////////
  173. // CMapView message handlers
  174. void CMapView::OnSize(UINT nType, int cx, int cy) 
  175. {
  176. CView::OnSize(nType, cx, cy);
  177. if (cx != 0 && cy != 0)
  178. m_ctrlMapX.MoveWindow(0,0,cx,cy,TRUE);
  179. }
  180. BOOL CMapView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
  181. {
  182. // TODO: Add your specialized code here and/or call the base class
  183. return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
  184. }
  185. int CMapView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  186. {
  187. if (CView::OnCreate(lpCreateStruct) == -1)
  188. return -1;
  189.     // 使用缺省尺寸创建一个地图
  190. // 在OnSize函数里改变地图控件的大小,使之缩放到屏幕尺寸
  191. m_ctrlMapX.Create(NULL, WS_VISIBLE, CRect(0,0,100,100), this, IDC_MAP);
  192. // 创建距离工具
  193. try {
  194. // create some custom tools for object drawing
  195. m_ctrlMapX.CreateCustomTool(MYTOOL_DISTANCE, miToolTypePoly, miCrossCursor);
  196. m_ctrlMapX.CreateCustomTool(MYTOOL_INFO, miToolTypePoint, miCrossCursor);
  197.         //绘图工具 
  198.         m_ctrlMapX.CreateCustomTool(CUSTOM_DRAW_TEXT_TOOL,miToolTypePoint,miCrossCursor);
  199. m_ctrlMapX.CreateCustomTool(CUSTOM_DRAW_SYMBOL_TOOL,miToolTypePoint,miCrossCursor);
  200. m_ctrlMapX.CreateCustomTool(CUSTOM_DRAW_LINE_TOOL,miToolTypeLine,miCrossCursor);
  201. m_ctrlMapX.CreateCustomTool(CUSTOM_DRAW_ELLIPSE_TOOL,miToolTypeMarquee,miCrossCursor);
  202. m_ctrlMapX.CreateCustomTool(CUSTOM_DRAW_RECT_TOOL,miToolTypeMarquee,miCrossCursor);
  203. m_ctrlMapX.CreateCustomTool(CUSTOM_DRAW_REGION_TOOL,miToolTypePoly,miCrossCursor);
  204. m_ctrlMapX.CreateCustomTool(CUSTOM_DRAW_ARC_TOOL,miToolTypeLine,miCrossCursor);
  205.     //GPS工具
  206. m_ctrlMapX.CreateCustomTool(GPS_ADDTARGET,miToolTypePoint,miArrowCursor);
  207. m_ctrlMapX.CreateCustomTool(GPS_EDITTARGET,miToolTypePoint,miArrowCursor);
  208. }
  209. catch (COleDispatchException *e) {
  210. e->ReportError();
  211. e->Delete();
  212. }
  213. catch (COleException *e) {
  214. e->ReportError();
  215. e->Delete();
  216. }
  217. SetTitleVisible(FALSE);
  218.     OnViewScalebar();
  219. return 0;
  220. }
  221. void CMapView::NotifyQueryNewPalette()
  222. {
  223. // we don't care, but our embedded control might
  224. m_ctrlMapX.SendMessage(WM_QUERYNEWPALETTE);
  225. }
  226. void CMapView::NotifyPaletteChanged(CWnd* pFocusWnd)
  227. {
  228. // we don't care, but our embedded control might
  229. m_ctrlMapX.SendMessage(WM_PALETTECHANGED, (WPARAM)(pFocusWnd->m_hWnd));
  230. }
  231. void CMapView::OnFileOpengeoset() 
  232. {
  233. CGeoSetDlg geoDlg(&m_ctrlMapX);
  234. geoDlg.DoModal();
  235. }
  236. void CMapView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
  237. {
  238. }
  239. void CMapView::OnViewSysoption() 
  240. {
  241. MapXSetDlg dlg(&m_ctrlMapX);
  242. dlg.DoModal();
  243. }
  244. void CMapView::OnMapToolSelect() 
  245. {
  246. m_ctrlMapX.SetCurrentTool(miSelectTool);
  247. }
  248. void CMapView::OnMapToolZoomin() 
  249. {
  250. m_ctrlMapX.SetCurrentTool(miZoomInTool);
  251. }
  252. void CMapView::OnMapToolZoomout() 
  253. {
  254. m_ctrlMapX.SetCurrentTool(miZoomOutTool);
  255. }
  256. void CMapView::OnMapToolPan() 
  257. {
  258. m_ctrlMapX.SetCurrentTool(miPanTool);
  259. }
  260. void CMapView::OnMapToolRadiusselect() 
  261. {
  262. m_ctrlMapX.SetCurrentTool(miRadiusSelectTool);
  263. }
  264. void CMapView::OnMapToolRectangleselect() 
  265. {
  266. m_ctrlMapX.SetCurrentTool(miRectSelectTool);
  267. }
  268. void CMapView::OnMapToolInformation() 
  269. {
  270. m_ctrlMapX.SetCurrentTool(miRectSelectTool);
  271. }
  272. void CMapView::OnToolUnselectall() 
  273. {
  274.     CMapXLayers layers=m_ctrlMapX.GetLayers();
  275. for(int i=0;i<layers.GetCount();i++)
  276. {
  277. CMapXLayer layer=layers.Item(i+1);
  278. if(layer.GetSelectable())
  279. {
  280. CMapXSelection select=layer.GetSelection();
  281. if(select.GetCount()>0) 
  282. select.ClearSelection();
  283.         }
  284.     }
  285. }
  286. // Draw the Scalebar layer whenever this event is called
  287. // we could check the Layer.Name property if we needed to handle
  288. // more than 1 user draw layer
  289. void CMapView::OnDrawUserLayer(LPDISPATCH Layer, long hOutputDC, long hAttributeDC, LPDISPATCH RectFull, LPDISPATCH RectInvalid)
  290. {
  291. CDC dc;
  292. dc.Attach((HDC)hOutputDC);
  293. dc.SetAttribDC((HDC)hAttributeDC);
  294. DrawScaleBar(&dc);
  295. }
  296. void CMapView::OnViewLayercontrol() 
  297. {
  298. try {
  299. VARIANT vHelpFile, vHelpID; // mark as optional since we don't have a helpfile
  300. vHelpFile.vt = VT_ERROR;
  301. vHelpFile.scode = DISP_E_PARAMNOTFOUND;
  302. vHelpID.vt = VT_ERROR;
  303. vHelpID.scode = DISP_E_PARAMNOTFOUND;
  304. CMapXLayers layers = m_ctrlMapX.GetLayers();
  305. layers.LayersDlg(vHelpFile, vHelpID);
  306. }
  307. catch (COleDispatchException *e) {
  308. e->ReportError();
  309. e->Delete();
  310. }
  311. catch (COleException *e) {
  312. e->ReportError();
  313. e->Delete();
  314. }
  315. }
  316. //用户自定义图层绘制比例尺
  317. void CMapView::OnViewScalebar() 
  318. {
  319. try {
  320. if(m_bScaleBar)
  321. {
  322. m_ctrlMapX.GetLayers().Remove("ScaleBar");
  323. m_bScaleBar = FALSE;
  324. }
  325. else
  326. {
  327. m_ctrlMapX.GetLayers().AddUserDrawLayer("ScaleBar", 1);
  328. m_bScaleBar = TRUE;
  329. }
  330. }
  331. catch (COleDispatchException *e) {
  332. e->ReportError();
  333. e->Delete();
  334. }
  335. catch (COleException *e) {
  336. e->ReportError();
  337. e->Delete();
  338. }
  339. }
  340. void CMapView::OnUpdateViewScalebar(CCmdUI* pCmdUI) 
  341. {
  342. pCmdUI->SetCheck(m_bScaleBar);
  343. }
  344. void CMapView::DrawScaleBar(CDC *pDC)
  345. {
  346. float barWidth =(float)0.5, barHeight =(float)0.08;
  347. float startX =(float).3, startY =(float).3;
  348. long x1, y1;
  349. int i;
  350. // attach to dc that mapx passed us so we can use 
  351. // mfc CDC object. (we will detach before exiting this method
  352. CPen pen;
  353. CBrush brushRed, brushWhite, *pOldBrush;
  354. CFont *pOldFont;
  355. pen.CreatePen(0,1,(COLORREF)0);
  356. brushRed.CreateSolidBrush(255);
  357. brushWhite.CreateSolidBrush(16777215);
  358. //Set map mode to HI-English
  359. pDC->SetMapMode(MM_HIENGLISH);
  360. //Set pen to black
  361. CPen *pOldPen = pDC->SelectObject(&pen);
  362. pOldBrush = pDC->SelectObject(&brushRed);
  363. //convert to HiEnglish, Conversion needed because one HIENGLISH unit is .001 inch
  364. x1=(long)(startX*1000);
  365. y1=(long)(startY*1000);
  366. barWidth*=1000;
  367. barHeight*=1000;
  368. for (i=0; i<=1; i++) {
  369. long x2 =(long)(barWidth+x1);
  370. long y2 =(long)(barHeight+y1);
  371. /*** First Section  ***/
  372. if (i==0) {
  373. pDC->SelectObject(&brushRed); //Red
  374. }
  375. else {
  376. pDC->SelectObject(&brushWhite); //White
  377. }
  378. // with mapMode HIENGLISH, positive is x to the right, positive y is up
  379. pDC->Rectangle(x1, -y1, x2, -y2);
  380. /*** Second Section ***/
  381. x1=x2;
  382. x2=(long)(barWidth+x1);
  383. if (i==0) {
  384. pDC->SelectObject(&brushWhite); //White
  385. }
  386. else {
  387. pDC->SelectObject(&brushRed); //Red
  388. }
  389. pDC->Rectangle(x1, -y1, x2, -y2);
  390. /*** Third Section ***/
  391. x1=x2;
  392. x2=(long)(barWidth*2+x1);
  393. if (i==0) {
  394. pDC->SelectObject(&brushRed); //Red
  395. }
  396. else {
  397. pDC->SelectObject(&brushWhite); //White
  398. }
  399. pDC->Rectangle(x1, -y1, x2, -y2);
  400. /*** Reset Values for bottom bar pass***/
  401. x1=(long)(startX*1000);
  402. y1=y2;
  403. }  // End For
  404. // Calculate Pixels Per Inch
  405. CPoint pt(1000, 1000); // In HIENGLISH 1000 units = 1 inch
  406. pDC->LPtoDP(&pt);  // Convert inch to pixel
  407. long lPixPerInch = pt.x;
  408. CRect rc;
  409. CView::GetClientRect(&rc);
  410. float screenX, screenY;
  411. double mapX1, mapY1;
  412. // subtract lPixPerInch from center to get 1 inch to left of Center
  413. screenX = (float)(rc.right/2-lPixPerInch);
  414. screenY = (float)(rc.bottom/2);
  415. try { 
  416. m_ctrlMapX.ConvertCoord(&screenX, &screenY, &mapX1, &mapY1, miScreenToMap);
  417. }
  418. catch (COleDispatchException *e) {
  419. e->ReportError();
  420. e->Delete();
  421. }
  422. catch (COleException *e) {
  423. e->ReportError();
  424. e->Delete();
  425. }
  426. double mapX2, mapY2;
  427. // add lPixPerInch to center to get 1 inch to right of Center
  428. screenX = (float)(rc.right/2+lPixPerInch);
  429. screenY = (float)(rc.bottom/2);
  430. try {
  431. m_ctrlMapX.ConvertCoord(&screenX, &screenY, &mapX2, &mapY2, miScreenToMap);
  432. }
  433. catch (COleDispatchException *e) {
  434. e->ReportError();
  435. e->Delete();
  436. }
  437. catch (COleException *e) {
  438. e->ReportError();
  439. e->Delete();
  440. }
  441. CFont font;
  442. font.CreatePointFont(100, "Arial", pDC);
  443. pOldFont = pDC->SelectObject(&font);
  444. pDC->SetTextColor(0); //Black
  445. pDC->SetBkMode(TRANSPARENT);
  446. // Output ScaleBar start Label = 0
  447. x1=(long)(startX*1000);
  448. y1=(long)((startY-.2)*1000);
  449. pDC->TextOut(x1,-y1,"0");
  450. // Output label for distance of 1 inch
  451. x1=(long)(barWidth*2+startX*1000);
  452. CString str;
  453. str.Format("%.0f",m_ctrlMapX.Distance(mapX1, mapY1, mapX2, mapY2)/2);
  454. // Need to center text over center line.  will move it 60 units for each character
  455. int iCenterAdjustment = 60*str.GetLength();
  456. pDC->TextOut(x1-iCenterAdjustment,-y1,str);
  457. // Output label for distance of 2 inches
  458. x1=(long)(barWidth*4+startX*1000);
  459. str.Format("%.0f",m_ctrlMapX.Distance(mapX1, mapY1, mapX2, mapY2));
  460. // Need to center text over end line.  will move it 60 units for each character
  461. iCenterAdjustment = 60*str.GetLength();
  462. pDC->TextOut(x1-iCenterAdjustment,-y1,str);
  463. // Output label for Units "Miles"
  464. x1=(long)(barWidth*2+startX*1000);
  465. y1=(long)((startY+.2)*1000);
  466. // Need to center text over center line.  will move it 60 units for each character
  467. str.Format("Miles");
  468. iCenterAdjustment = 60*str.GetLength();
  469. pDC->TextOut(x1-iCenterAdjustment,-y1,str);
  470. pDC->SelectObject(pOldBrush);
  471. pDC->SelectObject(pOldPen);
  472. pDC->SelectObject(pOldFont);
  473. // detach dc so destructore won't call Release it
  474. pDC->ReleaseAttribDC();
  475. pDC->Detach();
  476. }
  477. ///标题控制
  478. void CMapView::SetTitle(CString str)
  479. {
  480.    m_ctrlMapX.SetTitleText(str); 
  481. }
  482. void CMapView::SetTitleVisible(BOOL bState)
  483. {
  484.    m_ctrlMapX.GetTitle().SetVisible(bState);
  485. }
  486. ////////////////////////////////////
  487. void CMapView::OnMapeditSelettable() 
  488. {
  489. CSelLayerDlg LayerDlg(&m_ctrlMapX);
  490. LayerDlg.SetEditLayerName(m_strEditLayer);
  491. if(LayerDlg.DoModal()==IDOK)
  492. m_strEditLayer=LayerDlg.GetEditLayerName();
  493. }
  494. BOOL CMapView::FindLayer(CString strLayerName)
  495. {
  496. CMapXLayers layers=m_ctrlMapX.GetLayers();
  497.     for(int i=0;i<layers.GetCount();i++)
  498. {
  499. CMapXLayer layer=layers.Item(i+1);
  500. if(layer.GetName()==strLayerName) return TRUE;
  501. }
  502. return FALSE;
  503. }
  504. BOOL CMapView::FindLayer(CString strLayerName,CMapXLayer& layer)
  505. {
  506. CMapXLayers layers=m_ctrlMapX.GetLayers();
  507.     for(int i=0;i<layers.GetCount();i++)
  508. {
  509. layer=layers.Item(i+1);
  510. if(layer.GetName()==strLayerName) 
  511. return TRUE;
  512. }
  513. return FALSE;
  514. }
  515. /////////////////////////////////////////////
  516. void CMapView::OnPolyToolUsedMap(short ToolNum, long Flags, LPDISPATCH Points, BOOL bShift, BOOL bCtrl, BOOL FAR* EnableDefault) 
  517. {
  518. // see CSampleDlg for example on usage on creating polygons or lines
  519. // calc distance so far
  520. if (ToolNum == MYTOOL_DISTANCE) {
  521. CMapXPoints pts;
  522. long n;
  523. long i;
  524. try {
  525. pts.AttachDispatch(Points, FALSE); // don't auto release
  526. double dDistanceTot = 0.0;
  527. n = pts.GetCount();
  528. for (i=1; i<n; i++) {
  529. CMapXPoint pt1 = pts.Item(i);
  530. CMapXPoint pt2 = pts.Item(i+1);
  531. double d = m_ctrlMapX.Distance(pt1.GetX(), pt1.GetY(), pt2.GetX(), pt2.GetY());
  532. dDistanceTot += d;
  533. }
  534. CString str;
  535. str.Format("Distance Tot: %f", dDistanceTot);
  536. ((CMainFrame *)AfxGetMainWnd())->m_wndStatusBar.SetPaneText(0, str);
  537. }
  538. catch (COleDispatchException *e) {
  539. e->ReportError();
  540. e->Delete();
  541. }
  542. catch (COleException *e) {
  543. e->ReportError();
  544. e->Delete();
  545. }
  546. }
  547. else if(Flags==miPolyToolEnd&&ToolNum==CUSTOM_DRAW_REGION_TOOL)
  548. {
  549. CMapXFeatureFactory cFactory=m_ctrlMapX.GetFeatureFactory();
  550.         CMapXLayer layer; 
  551. if(m_strEditLayer!="")
  552. layer=m_ctrlMapX.GetLayers().Item(m_strEditLayer);
  553.         else {
  554.     AfxMessageBox("你没有选择可编辑图层,请选择编辑图层");
  555.             return; 
  556.         }
  557. CMapXFeature feature;
  558. CMapXPoints points;
  559. points.AttachDispatch(Points, FALSE); // don't auto release
  560. COleVariant vtPoints;
  561. vtPoints.vt = VT_DISPATCH;
  562. vtPoints.pdispVal = points.m_lpDispatch;
  563. vtPoints.pdispVal->AddRef();
  564. feature=cFactory.CreateRegion(vtPoints); 
  565. layer.AddFeature(feature);
  566. }
  567. }
  568. void CMapView::OnToolUsed(short ToolNum, double X1, double Y1, double X2, double Y2, double Distance, BOOL Shift, BOOL Ctrl, BOOL* EnableDefault)
  569. {
  570. CString str;
  571. str.Format("Tool=%d, [%f,%f] [%f, %f], dist=%f, %s %sn",
  572. ToolNum, X1,Y1,X2,Y2,Distance, (Shift)?"Shift":"",(Ctrl)?"Ctrl":"");
  573. TRACE(str);
  574. //AfxMessageBox(str);
  575. // this info tool will pop up a modal dlg 
  576. // with info from the dataset(1)
  577. // Note that we are only getting info from the MapX Dataset
  578. // you could use the SourceRows collection to get back
  579. // to the source data to display info from dao, odbc or whatever
  580. if (ToolNum == MYTOOL_INFO) {
  581. OnInfoToolUsed(m_ctrlMapX);
  582. }
  583. if(ToolNum>=CUSTOM_DRAW_TEXT_TOOL&&ToolNum <= CUSTOM_DRAW_ARC_TOOL) 
  584.     {
  585. CMapXFeatureFactory cFactory=m_ctrlMapX.GetFeatureFactory();
  586.         CMapXLayer layer; 
  587. if(m_strEditLayer!="")
  588. layer=m_ctrlMapX.GetLayers().Item(m_strEditLayer);
  589.         else {
  590.     AfxMessageBox("你没有选择可编辑图层,请选择编辑图层");
  591.             return; 
  592.         }
  593. CMapXPoint point;
  594. point.CreateDispatch(point.GetClsid()); //Creates a dispatch for the point
  595. CMapXFeature feature;
  596. CMapXPoints points;
  597. points.CreateDispatch(points.GetClsid());
  598. CMapXRectangle rect;
  599. rect.CreateDispatch(rect.GetClsid());
  600.         switch(ToolNum)
  601. {
  602. case CUSTOM_DRAW_TEXT_TOOL:
  603.             {
  604. point.Set(X1,Y1);
  605. COleVariant vtPoint;
  606. vtPoint.vt = VT_DISPATCH;
  607. vtPoint.pdispVal = point.m_lpDispatch;
  608. vtPoint.pdispVal->AddRef();
  609. feature=cFactory.CreateText(vtPoint,"测试文档  gg"); 
  610.                 CMapXStyle style=feature.GetStyle();
  611. style.PickText();
  612. feature.SetStyle(style.m_lpDispatch);  
  613. layer.AddFeature(feature);
  614.             } 
  615. break;
  616.         case CUSTOM_DRAW_LINE_TOOL:
  617. {
  618.                 points.AddXY(X1,Y1);
  619. points.AddXY(X2,Y2);
  620. COleVariant vtPoints;
  621. vtPoints.vt = VT_DISPATCH;
  622. vtPoints.pdispVal = points.m_lpDispatch;
  623. vtPoints.pdispVal->AddRef();
  624. feature=cFactory.CreateLine(vtPoints); 
  625. layer.AddFeature(feature);
  626. }
  627. break;
  628. case CUSTOM_DRAW_RECT_TOOL:
  629. {
  630.     VARIANT scx,scy;
  631. m_ctrlMapX.ConvertCoordV(&scx,&scy,COleVariant(X1),COleVariant(Y1),miMapToScreen);
  632.                 VARIANT scx1,scy1;
  633. m_ctrlMapX.ConvertCoordV(&scx1,&scy1,COleVariant(X2),COleVariant(Y2),miMapToScreen);
  634. VARIANT mapx1,mapy1,mapx2,mapy2;
  635. m_ctrlMapX.ConvertCoordV(&scx,&scy1,&mapx1,&mapy1,miScreenToMap);
  636. m_ctrlMapX.ConvertCoordV(&scx1,&scy,&mapx2,&mapy2,miScreenToMap);
  637. double x2,y2,x4,y4;
  638. //mapx1.ChangeType(VT_R8);
  639. x2= mapx1.dblVal;
  640. //mapy1.ChangeType(VT_R8);
  641. y2=mapy1.dblVal;
  642. //mapx2.ChangeType(VT_R8);
  643. x4=mapx2.dblVal;
  644. //mapy2.ChangeType(VT_R8*;
  645. y4=mapy2.dblVal;
  646. points.AddXY(X1,Y1);
  647. points.AddXY(x2,y2);
  648. points.AddXY(X2,Y2);
  649. points.AddXY(x4,y4);
  650. COleVariant vtPoints;
  651. vtPoints.vt = VT_DISPATCH;
  652. vtPoints.pdispVal = points.m_lpDispatch;
  653. vtPoints.pdispVal->AddRef();
  654. feature=cFactory.CreateRegion(vtPoints); 
  655. layer.AddFeature(feature);
  656. }
  657.             break;
  658.    case CUSTOM_DRAW_ARC_TOOL:
  659.    {
  660. points.AddXY(X1,Y1);
  661. points.AddXY(X2,Y2);
  662. feature=cFactory.CreateArc(points.Item(1).m_lpDispatch,points.Item(2).m_lpDispatch); 
  663. layer.AddFeature(feature);
  664.    }
  665.    break;
  666.        case CUSTOM_DRAW_ELLIPSE_TOOL:
  667. {
  668. rect.Set(X1,Y1,X2,Y2);
  669.              feature=cFactory.CreateEllipticalRegion(rect.m_lpDispatch , 0, 30); 
  670. layer.AddFeature(feature);
  671. }
  672. break;
  673. /* Select Case ToolNum
  674.             Case 
  675.                 ptItem.Set x1, y1
  676.                 Set ftrItem = ftrFactory.CreateText(ptItem, "TEXT", _
  677.                     miPositionCC, Map1.DefaultStyle)
  678.                 lyrEdit.AddFeature ftrItem
  679.                 Set ftrItem = Nothing
  680.             Case CUSTOM_DRAW_SYMBOL_TOOL
  681.                 ptItem.Set x1, y1
  682.                 Set ftrItem = ftrFactory.CreateSymbol(ptItem, Map1.DefaultStyle)
  683.                 lyrEdit.AddFeature ftrItem
  684.                 Set ftrItem = Nothing
  685.             Case CUSTOM_DRAW_LINE_TOOL
  686.                 ptsItem.AddXY x1, y1
  687.                 ptsItem.AddXY x2, y2, 2
  688.                 Set ftrItem = ftrFactory.CreateLine(ptsItem, Map1.DefaultStyle)
  689.                 lyrEdit.AddFeature ftrItem
  690.                 Set ftrItem = Nothing
  691.             Case CUSTOM_DRAW_ELLIPSE_TOOL
  692.                 rctItem.Set x1, y1, x2, y2
  693.                 Set ftrItem = ftrFactory.CreateEllipticalRegion(rctItem, 0, 30, Map1.DefaultStyle)
  694.                 lyrEdit.AddFeature ftrItem
  695.                 Set ftrItem = Nothing
  696.         End Select
  697.     Ed If*/
  698. }
  699. }
  700. void CMapView::OnInfoToolUsed(CMapX &cMapX)
  701. {
  702. /* try {
  703. if (cMapX.GetDatasets().GetCount() == 0) {
  704. AfxMessageBox("This info tool requires that a dataset be added.");
  705. return;
  706. }
  707. CMapXPoint pt;
  708. CMapXFeatures fs;
  709. CMapXFeature f;
  710. CMapXDataset ds;
  711. pt.CreateDispatch(pt.GetClsid());
  712. pt.Set(X1,Y1);
  713. fs = cMapX.GetLayers().Item("USA").SearchAtPoint(pt);
  714. // just use first feature from collection. Since usa is a layer of
  715. // all regions, we will not get back > 1 feature in the collection
  716. // because there are no overlapping regions
  717. if (fs.GetCount() != 1) {
  718. return;
  719. }
  720. f = fs.Item(1);
  721. ds = cMapX.GetDatasets().Item(1);
  722. CInfoDlg dlg;
  723. COleVariant vRow;
  724. COleVariant vVal;
  725. vRow.vt = VT_DISPATCH;
  726. vRow.pdispVal = f.m_lpDispatch;
  727. vRow.pdispVal->AddRef();
  728. vVal = ds.GetValue(vRow, COleVariant(2L));
  729. vVal.ChangeType(VT_BSTR);
  730. dlg.m_strState = vVal.bstrVal;
  731. vVal = ds.GetValue(vRow, COleVariant(3L));
  732. vVal.ChangeType(VT_R8);
  733. dlg.m_dTotal = vVal.dblVal;
  734. vVal = ds.GetValue(vRow, COleVariant(4L));
  735. vVal.ChangeType(VT_R8);
  736. dlg.m_dFemale = vVal.dblVal;
  737. vVal = ds.GetValue(vRow, COleVariant(5L));
  738. vVal.ChangeType(VT_R8);
  739. dlg.m_dMale = vVal.dblVal;
  740. dlg.DoModal();
  741. }
  742. catch (COleDispatchException *e) {
  743. e->ReportError();
  744. e->Delete();
  745. }
  746. catch (COleException *e) {
  747. e->ReportError();
  748. e->Delete();
  749. }*/
  750. }
  751. void CMapView::OnMapeditAddtext() 
  752. {
  753. //m_ctrlMapX.SetCurrentTool(miTextTool);
  754. m_ctrlMapX.SetCurrentTool(CUSTOM_DRAW_TEXT_TOOL);
  755. }
  756. void CMapView::OnUpdateMapeditAddtext(CCmdUI* pCmdUI) 
  757. {
  758. pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==miTextTool);
  759. }
  760. void CMapView::OnMapeditAddsymbol() 
  761. {
  762.     m_ctrlMapX.SetCurrentTool(miSymbolTool);
  763. }
  764. void CMapView::OnUpdateMapeditAddsymbol(CCmdUI* pCmdUI) 
  765. {
  766. pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==miSymbolTool);
  767. }
  768. void CMapView::OnMapeditAddline() 
  769. {
  770. m_ctrlMapX.SetCurrentTool(CUSTOM_DRAW_LINE_TOOL);
  771. }
  772. void CMapView::OnUpdateMapeditAddline(CCmdUI* pCmdUI) 
  773. {
  774. pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==CUSTOM_DRAW_LINE_TOOL);
  775. }
  776. void CMapView::OnMapeditAddpolygon() 
  777. {
  778. m_ctrlMapX.SetCurrentTool(CUSTOM_DRAW_REGION_TOOL);
  779. }
  780. void CMapView::OnUpdateMapeditAddpolygon(CCmdUI* pCmdUI) 
  781. {
  782. pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==CUSTOM_DRAW_REGION_TOOL);
  783. }
  784. void CMapView::OnMapeditAddrect() 
  785. {
  786. m_ctrlMapX.SetCurrentTool(CUSTOM_DRAW_RECT_TOOL);
  787. }
  788. void CMapView::OnUpdateMapeditAddrect(CCmdUI* pCmdUI) 
  789. {
  790. pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==CUSTOM_DRAW_RECT_TOOL);
  791. }
  792. void CMapView::OnMapeditAddepplise() 
  793. {
  794. m_ctrlMapX.SetCurrentTool(CUSTOM_DRAW_ELLIPSE_TOOL);
  795. }
  796. void CMapView::OnUpdateMapeditAddepplise(CCmdUI* pCmdUI) 
  797. {
  798. pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==CUSTOM_DRAW_ELLIPSE_TOOL);
  799. }
  800. void CMapView::OnMapeditAddarc() 
  801. {
  802. m_ctrlMapX.SetCurrentTool(CUSTOM_DRAW_ARC_TOOL);
  803. }
  804. void CMapView::OnUpdateMapeditAddarc(CCmdUI* pCmdUI) 
  805. {
  806. pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==CUSTOM_DRAW_ARC_TOOL);
  807. }
  808. void CMapView::OnInitialUpdate() 
  809. {
  810. CView::OnInitialUpdate();
  811. CMainFrame* pFrame=((CMainFrame*)AfxGetMainWnd());
  812. pFrame->m_pMapView=this;
  813. }
  814. void CMapView::OnDestroy() 
  815. {
  816. ClearAllTarget();
  817. CView::OnDestroy();
  818. CMainFrame* pFrame=((CMainFrame*)AfxGetMainWnd());
  819. pFrame->m_pMapView=NULL;
  820. }
  821. void CMapView::OnAddTarget() 
  822. {
  823. m_ctrlMapX.SetCurrentTool(GPS_ADDTARGET);
  824. }
  825. void CMapView::OnUpdateAddTarget(CCmdUI* pCmdUI) 
  826. {
  827. pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==GPS_ADDTARGET);
  828. }
  829. void CMapView::OnEditTarget() 
  830. {
  831. m_ctrlMapX.SetCurrentTool(GPS_EDITTARGET);
  832. }
  833. void CMapView::OnUpdateEditTarget(CCmdUI* pCmdUI) 
  834. {
  835.   pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==GPS_EDITTARGET);
  836. }
  837. void CMapView::OnStartGps() 
  838. {
  839. SetTimer(100,1500,NULL);
  840. m_bIsStartGps=TRUE;
  841. //SetAnimationLayer();
  842. }
  843. void CMapView::OnUpdateStartGps(CCmdUI* pCmdUI) 
  844. {
  845. pCmdUI->Enable(!m_bIsStartGps);
  846. }
  847. void CMapView::OnEndGps() 
  848. {
  849. KillTimer(100);
  850. m_bIsStartGps=FALSE;
  851. }
  852. void CMapView::OnUpdateEndGps(CCmdUI* pCmdUI) 
  853. {
  854. pCmdUI->Enable(m_bIsStartGps);
  855. }
  856. //鼠标操作
  857. void CMapView::OnMouseDownMap(short Button, short Shift, float X, float Y) 
  858. {
  859. if(Button==1){
  860.    m_nGpsOperation=m_ctrlMapX.GetCurrentTool();
  861.    switch(m_nGpsOperation)
  862.    {
  863.    case GPS_ADDTARGET:{
  864.   
  865.   double lonX,latY;
  866.   m_ctrlMapX.ConvertCoord(&X,&Y,&lonX,&latY,miScreenToMap);
  867.   
  868.   //gpsTarget.SetStartXY(lonX,latY);
  869.   
  870.   
  871.   m_pTarget=new CGpsSet;
  872.   m_pTarget->SetStartXY(lonX,latY);
  873.   
  874.   CTargetSet dlg(*m_pTarget);   
  875.   if(dlg.DoModal()==IDOK)
  876.   dlg.GetGpsData(*m_pTarget);
  877.           else return;
  878.   if(!FindLayer("gps"))
  879.   m_ctrlMapX.GetLayers().Add("gps.tab");
  880.           CMapXLayer layer;
  881.   if(FindLayer("gps",layer))
  882.   {
  883.       m_pTarget->AddFeature(&m_ctrlMapX,layer);
  884.   gpsTargetArray.AddTarget(m_pTarget);
  885.   }
  886.   else
  887.   {
  888. MessageBox("不能发现移动图层");
  889.   }
  890. }break;
  891.        case GPS_EDITTARGET:
  892. {
  893.   
  894.   gpsTargetArray.SetActiveTarget(gpsTargetArray.HitTest(X, Y,&m_ctrlMapX));
  895.   
  896.   if(gpsTargetArray.m_pActiveTarget==NULL) return;
  897.   CTargetSet dlg(*gpsTargetArray.m_pActiveTarget);   
  898.   if(dlg.DoModal()==IDOK)
  899.   dlg.GetGpsData(*gpsTargetArray.m_pActiveTarget);
  900.           else return;
  901. }break;
  902.            
  903.        }    
  904. }
  905. }
  906. BOOL CMapView::OnMouseUpInMap(short Button, short Shift, OLE_XPOS_PIXELS x, OLE_YPOS_PIXELS y)
  907. {
  908. return TRUE;
  909. }
  910. // you could use this to display the lat/long values on the status bar
  911. BOOL CMapView::OnMouseMoveInMap(short Button, short Shift, OLE_XPOS_PIXELS x, OLE_YPOS_PIXELS y)
  912. {
  913. return TRUE;
  914. }
  915. //选择目标样式
  916. void CMapView::OnGpsChangesymbol() 
  917. {
  918. if(!FindLayer("gps"))
  919. m_ctrlMapX.GetLayers().Add("gps.tab");
  920.         CMapXLayer layer;
  921. if(FindLayer("gps",layer))
  922. {
  923. CMapXStyle style=layer.GetStyle();
  924. style.PickSymbol();
  925. layer.SetStyle(style.m_lpDispatch);
  926.        
  927.         } 
  928. else
  929. {
  930. MessageBox("不能发现移动图层");
  931. }
  932. }
  933. void CMapView::OnUpdateGpsChangesymbol(CCmdUI* pCmdUI) 
  934. {
  935. // TODO: Add your command update UI handler code here
  936. }
  937. void CMapView::OnTimer(UINT nIDEvent) 
  938. {
  939. gpsTargetArray.Run();
  940. UpdateSense();
  941. CView::OnTimer(nIDEvent);
  942. }
  943. void CMapView::UpdateSense()
  944. {
  945. CMapXLayer layer;
  946. if(FindLayer("gps",layer))
  947. gpsTargetArray.UpdateGraph(layer);
  948. layer.Refresh();
  949. }
  950. void CMapView::SetAnimationLayer()
  951. {
  952. if(!FindLayer("gps"))
  953. m_ctrlMapX.GetLayers().Add("gps.tab");
  954.         CMapXLayer layer;
  955. if(FindLayer("gps",layer))
  956. m_ctrlMapX.GetLayers().SetAnimationLayer(layer.m_lpDispatch);
  957. }
  958. void CMapView::ClearAllTarget()
  959. {
  960. CMapXLayer layer;
  961. if(FindLayer("gps",layer))
  962. {
  963. CMapXFeatures features=layer.AllFeatures();
  964. for(int i=1;i<=features.GetCount();i++)
  965.    layer.DeleteFeature(features.Item(i));
  966. gpsTargetArray.DeleteAllTarget();
  967. }
  968. }
  969. BOOL CMapView::DestroyWindow() 
  970. {
  971. return CView::DestroyWindow();
  972. }
  973. void CMapView::OnChangeSymbol() 
  974. {
  975. m_bIsAutoLable=!m_bIsAutoLable;
  976. CMapXLayer layer;
  977. if(FindLayer("gps",layer))
  978. {
  979. /*  CString str1=m_strEditLayer; 
  980. CMapXDataset dataSet;
  981. if(!IsInDataSet(m_strEditLayer))
  982.  dataSet=m_pCtrlMapX->GetDatasets().Add(miDataSetLayer, vtLayer, str1);*/
  983. layer.SetAutoLabel(m_bIsAutoLable);
  984. }
  985. }
  986. void CMapView::OnUpdateChangeSymbol(CCmdUI* pCmdUI) 
  987. {
  988. pCmdUI->SetCheck(m_bIsAutoLable);
  989. }
  990. void CMapView::OnLineChange() 
  991. {
  992. CMapXStyle style=m_ctrlMapX.GetDefaultStyle();
  993. style.PickLine();
  994. }
  995. void CMapView::OnReagionChange() 
  996. {
  997. CMapXStyle style=m_ctrlMapX.GetDefaultStyle();
  998. style.PickRegion();
  999. }
  1000. void CMapView::OnMapxProperty() 
  1001. {
  1002. m_ctrlMapX.PropertyPage();
  1003. }
  1004. void CMapView::OnDatabindNormal() 
  1005. {
  1006. try {
  1007. CMapXLayer layer = m_ctrlMapX.GetLayers().Item("USA");
  1008. VARIANT vtLayer;
  1009. vtLayer.vt = VT_DISPATCH;
  1010. vtLayer.pdispVal = layer.m_lpDispatch;
  1011. CMapXDataset dataSet = m_ctrlMapX.GetDatasets().Add(miDataSetLayer, vtLayer, "USA Layer");
  1012. }
  1013. catch (COleDispatchException *e) {
  1014. e->ReportError();
  1015. e->Delete();
  1016. }
  1017. catch (COleException *e) {
  1018. e->ReportError();
  1019. e->Delete();
  1020. }
  1021. }
  1022. void CMapView::OnUpdateDatabindNormal(CCmdUI* pCmdUI) 
  1023. {
  1024. // TODO: Add your command update UI handler code here
  1025. }
  1026. void CMapView::OnBinddataOdbc() 
  1027. {
  1028. // TODO: Add your command handler code here
  1029. }
  1030. void CMapView::OnUpdateBinddataOdbc(CCmdUI* pCmdUI) 
  1031. {
  1032. // TODO: Add your command update UI handler code here
  1033. }
  1034. void CMapView::OnBinddataArray() 
  1035. {
  1036. // TODO: Add your command handler code here
  1037. }
  1038. void CMapView::OnUpdateBinddataArray(CCmdUI* pCmdUI) 
  1039. {
  1040. // TODO: Add your command update UI handler code here
  1041. }
  1042. void CMapView::OnBinddataNobind() 
  1043. {
  1044. // TODO: Add your command handler code here
  1045. }
  1046. void CMapView::OnUpdateBinddataNobind(CCmdUI* pCmdUI) 
  1047. {
  1048. // TODO: Add your command update UI handler code here
  1049. }
  1050. void CMapView::OnThemeReange() 
  1051. {
  1052. VARIANT Type; 
  1053. VARIANT Name;
  1054. VARIANT Field;
  1055. VARIANT Item;
  1056. // long FieldNums =4;  // theme field numbers
  1057. long FieldNums[3] = { 3, 4, 5};  // theme field numbers
  1058. int n=3;
  1059.     
  1060. // construct a safearray of column numbers (could use names instead)
  1061. /*SAFEARRAY FAR* psa=NULL; 
  1062. SAFEARRAYBOUND rgsabound[1]; 
  1063. long ix;
  1064. rgsabound[0].lLbound = 1; 
  1065. rgsabound[0].cElements = n; 
  1066. psa = SafeArrayCreate(VT_I4, 1, rgsabound); 
  1067. if(psa == NULL){ 
  1068. return;
  1069. }
  1070. for (int i=0; i< n; i++) {
  1071. ix=i+1;
  1072. SafeArrayPutElement(psa, &ix, &FieldNums[i]);
  1073. }*/
  1074. // put array in field param
  1075. Field.vt = /*VT_ARRAY |*/ VT_I4;
  1076. //Field.parray = psa;
  1077. Field.lVal = 5;
  1078. Type.vt = VT_I4;
  1079. Type.lVal = miThemeRanged; //auto choose theme type
  1080. Name.vt = VT_ERROR; // use default name
  1081. Name.scode = DISP_E_PARAMNOTFOUND;
  1082. //miThemeRanged = 0,
  1083. //miThemeBarChart = 1,
  1084. //miThemePieChart = 2,
  1085. //miThemeGradSymbol = 3,
  1086. //miThemeDotDensity = 4,
  1087. //miThemeIndividualValue = 5,
  1088. //miThemeAuto = 6,
  1089. //miThemeNone = 9,
  1090. try {
  1091. // get themes collection
  1092. CMapXThemes objThemes = m_ctrlMapX.GetDatasets()[1L].GetThemes();
  1093. // want to see full legend
  1094. m_ctrlMapX.SetPreferCompactLegends(FALSE);
  1095. // add theme - will be visible by default
  1096. CMapXTheme thm = objThemes.Add(Type, Field, Name);
  1097. thm.ThemeDlg();
  1098. //CMapXThemeProperties themeDlg=thm.GetThemeProperties();
  1099. //CMapXRangeCategories cate=themeDlg.GetRangeCategories();
  1100. //cate.GetProperty();
  1101. }
  1102. catch (COleDispatchException *e) {
  1103. e->ReportError();
  1104. e->Delete();
  1105. }
  1106. catch (COleException *e) {
  1107. e->ReportError();
  1108. e->Delete();
  1109. }
  1110. }
  1111. void CMapView::OnUpdateThemeReange(CCmdUI* pCmdUI) 
  1112. {
  1113. // TODO: Add your command update UI handler code here
  1114. }
  1115. void CMapView::OnThemeDot() 
  1116. {
  1117. // TODO: Add your command handler code here
  1118. }
  1119. void CMapView::OnUpdateThemeDot(CCmdUI* pCmdUI) 
  1120. {
  1121. // TODO: Add your command update UI handler code here
  1122. }
  1123. void CMapView::OnThemePie() 
  1124. {
  1125. // TODO: Add your command handler code here
  1126. }
  1127. void CMapView::OnUpdateThemePie(CCmdUI* pCmdUI) 
  1128. {
  1129. // TODO: Add your command update UI handler code here
  1130. }
  1131. void CMapView::OnThemeSymbol() 
  1132. {
  1133. // TODO: Add your command handler code here
  1134. }
  1135. void CMapView::OnUpdateThemeSymbol(CCmdUI* pCmdUI) 
  1136. {
  1137. // TODO: Add your command update UI handler code here
  1138. }
  1139. void CMapView::OnThemeIndiv() 
  1140. {
  1141. // TODO: Add your command handler code here
  1142. }
  1143. void CMapView::OnUpdateThemeIndiv(CCmdUI* pCmdUI) 
  1144. {
  1145. // TODO: Add your command update UI handler code here
  1146. }
  1147. void CMapView::OnThemeBar() 
  1148. {
  1149. VARIANT Type; 
  1150. VARIANT Name;
  1151. VARIANT Field;
  1152. VARIANT Item;
  1153. long FieldNums[3] = { 4, 5, 6};  // theme field numbers
  1154. int n=3;
  1155. Type.vt = VT_I4;
  1156. Type.lVal = miThemeBarChart; //auto choose theme type
  1157. Name.vt = VT_ERROR; // use default name
  1158. Name.scode = DISP_E_PARAMNOTFOUND;
  1159. Item.vt = VT_I4; // for getting first dataset
  1160. Item.lVal = 1;
  1161. // construct a safearray of column numbers (could use names instead)
  1162. SAFEARRAY FAR* psa=NULL; 
  1163. SAFEARRAYBOUND rgsabound[1]; 
  1164. long ix;
  1165. rgsabound[0].lLbound = 1; 
  1166. rgsabound[0].cElements = n; 
  1167. psa = SafeArrayCreate(VT_I4, 1, rgsabound); 
  1168. if(psa == NULL){ 
  1169. return;
  1170. }
  1171. for (int i=0; i< n; i++) {
  1172. ix=i+1;
  1173. SafeArrayPutElement(psa, &ix, &FieldNums[i]);
  1174. }
  1175. // put array in field param
  1176. Field.vt = VT_ARRAY | VT_I4;
  1177. Field.parray = psa;
  1178. try {
  1179. // get themes collection
  1180. CMapXThemes objThemes = m_ctrlMapX.GetDatasets()[1L].GetThemes();
  1181. // want to see full legend
  1182. m_ctrlMapX.SetPreferCompactLegends(FALSE);
  1183. // add theme - will be visible by default
  1184. CMapXTheme thm = objThemes.Add(Type, Field, Name);
  1185. }
  1186. catch (COleDispatchException *e) {
  1187. e->ReportError();
  1188. e->Delete();
  1189. }
  1190. catch (COleException *e) {
  1191. e->ReportError();
  1192. e->Delete();
  1193. }
  1194. // clean up fields array
  1195. if (psa)
  1196. SafeArrayDestroy(psa);
  1197. }
  1198. void CMapView::OnUpdateThemeBar(CCmdUI* pCmdUI) 
  1199. {
  1200. // TODO: Add your command update UI handler code here
  1201. }