MapView.cpp
上传用户:hzwailv
上传日期:2010-01-09
资源大小:405k
文件大小:37k
- // MapView.cpp : implementation of the CMapView class
- //
- #include "stdafx.h"
- #include "MapDemo.h"
- #include "MapDemoDoc.h"
- #include "MapView.h"
- #include "MapFormView.h"
- #include "MainFrm.h"
- #include "GeoSetDlg.h"
- #include "MapXSetDlg.h"
- #include "SelDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define IDC_MAP 100
- #define MYTOOL_INFO 1
- #define MYTOOL_DISTANCE 2
- /////////////////////////////////////////////////////////////////////////////
- // CMapView
- IMPLEMENT_DYNCREATE(CMapView, CView)
- BEGIN_MESSAGE_MAP(CMapView, CView)
- //{{AFX_MSG_MAP(CMapView)
- ON_WM_SIZE()
- ON_WM_CREATE()
- ON_COMMAND(ID_FILE_OPENGEOSET, OnFileOpengeoset)
- ON_COMMAND(ID_VIEW_SYSOPTION, OnViewSysoption)
- ON_COMMAND(ID_MAP_TOOL_SELECT, OnMapToolSelect)
- ON_COMMAND(ID_MAP_TOOL_ZOOMIN, OnMapToolZoomin)
- ON_COMMAND(ID_MAP_TOOL_ZOOMOUT, OnMapToolZoomout)
- ON_COMMAND(ID_MAP_TOOL_PAN, OnMapToolPan)
- ON_COMMAND(ID_MAP_TOOL_RADIUSSELECT, OnMapToolRadiusselect)
- ON_COMMAND(ID_MAP_TOOL_RECTANGLESELECT, OnMapToolRectangleselect)
- ON_COMMAND(ID_MAP_TOOL_INFORMATION, OnMapToolInformation)
- ON_COMMAND(ID_VIEW_LAYERCONTROL, OnViewLayercontrol)
- ON_COMMAND(ID_VIEW_SCALEBAR, OnViewScalebar)
- ON_UPDATE_COMMAND_UI(ID_VIEW_SCALEBAR, OnUpdateViewScalebar)
- ON_COMMAND(ID_TOOL_UNSELECTALL, OnToolUnselectall)
- ON_COMMAND(ID_MAPEDIT_SELETTABLE, OnMapeditSelettable)
- ON_COMMAND(ID_MAPEDIT_ADDTEXT, OnMapeditAddtext)
- ON_COMMAND(ID_MAPEDIT_ADDSYMBOL, OnMapeditAddsymbol)
- ON_UPDATE_COMMAND_UI(ID_MAPEDIT_ADDTEXT, OnUpdateMapeditAddtext)
- ON_UPDATE_COMMAND_UI(ID_MAPEDIT_ADDSYMBOL, OnUpdateMapeditAddsymbol)
- ON_COMMAND(ID_MAPEDIT_ADDLINE, OnMapeditAddline)
- ON_UPDATE_COMMAND_UI(ID_MAPEDIT_ADDLINE, OnUpdateMapeditAddline)
- ON_COMMAND(ID_MAPEDIT_ADDPOLYGON, OnMapeditAddpolygon)
- ON_UPDATE_COMMAND_UI(ID_MAPEDIT_ADDPOLYGON, OnUpdateMapeditAddpolygon)
- ON_COMMAND(ID_MAPEDIT_ADDRECT, OnMapeditAddrect)
- ON_UPDATE_COMMAND_UI(ID_MAPEDIT_ADDRECT, OnUpdateMapeditAddrect)
- ON_COMMAND(ID_MAPEDIT_ADDEPPLISE, OnMapeditAddepplise)
- ON_UPDATE_COMMAND_UI(ID_MAPEDIT_ADDEPPLISE, OnUpdateMapeditAddepplise)
- ON_COMMAND(IDD_MAPEDIT_ADDARC, OnMapeditAddarc)
- ON_UPDATE_COMMAND_UI(IDD_MAPEDIT_ADDARC, OnUpdateMapeditAddarc)
- ON_WM_DESTROY()
- ON_COMMAND(ID_ADD_TARGET, OnAddTarget)
- ON_COMMAND(ID_EDIT_TARGET, OnEditTarget)
- ON_COMMAND(ID_START_GPS, OnStartGps)
- ON_UPDATE_COMMAND_UI(ID_START_GPS, OnUpdateStartGps)
- ON_COMMAND(ID_END_GPS, OnEndGps)
- ON_UPDATE_COMMAND_UI(ID_END_GPS, OnUpdateEndGps)
- ON_UPDATE_COMMAND_UI(ID_ADD_TARGET, OnUpdateAddTarget)
- ON_UPDATE_COMMAND_UI(ID_EDIT_TARGET, OnUpdateEditTarget)
- ON_COMMAND(ID_GPS_CHANGESYMBOL, OnGpsChangesymbol)
- ON_UPDATE_COMMAND_UI(ID_GPS_CHANGESYMBOL, OnUpdateGpsChangesymbol)
- ON_WM_TIMER()
- ON_COMMAND(ID_CHANGE_SYMBOL, OnChangeSymbol)
- ON_UPDATE_COMMAND_UI(ID_CHANGE_SYMBOL, OnUpdateChangeSymbol)
- ON_COMMAND(ID_LINE_CHANGE, OnLineChange)
- ON_COMMAND(ID_REAGION_CHANGE, OnReagionChange)
- ON_COMMAND(ID_MAPX_PROPERTY, OnMapxProperty)
- ON_COMMAND(ID_DATABIND_NORMAL, OnDatabindNormal)
- ON_UPDATE_COMMAND_UI(ID_DATABIND_NORMAL, OnUpdateDatabindNormal)
- ON_COMMAND(ID_BINDDATA_ODBC, OnBinddataOdbc)
- ON_UPDATE_COMMAND_UI(ID_BINDDATA_ODBC, OnUpdateBinddataOdbc)
- ON_COMMAND(ID_BINDDATA_ARRAY, OnBinddataArray)
- ON_UPDATE_COMMAND_UI(ID_BINDDATA_ARRAY, OnUpdateBinddataArray)
- ON_COMMAND(ID_BINDDATA_NOBIND, OnBinddataNobind)
- ON_UPDATE_COMMAND_UI(ID_BINDDATA_NOBIND, OnUpdateBinddataNobind)
- ON_COMMAND(ID_THEME_REANGE, OnThemeReange)
- ON_UPDATE_COMMAND_UI(ID_THEME_REANGE, OnUpdateThemeReange)
- ON_COMMAND(ID_THEME_DOT, OnThemeDot)
- ON_UPDATE_COMMAND_UI(ID_THEME_DOT, OnUpdateThemeDot)
- ON_COMMAND(ID_THEME_PIE, OnThemePie)
- ON_UPDATE_COMMAND_UI(ID_THEME_PIE, OnUpdateThemePie)
- ON_COMMAND(ID_THEME_SYMBOL, OnThemeSymbol)
- ON_UPDATE_COMMAND_UI(ID_THEME_SYMBOL, OnUpdateThemeSymbol)
- ON_COMMAND(ID_THEME_INDIV, OnThemeIndiv)
- ON_UPDATE_COMMAND_UI(ID_THEME_INDIV, OnUpdateThemeIndiv)
- ON_COMMAND(ID_THEME_BAR, OnThemeBar)
- ON_UPDATE_COMMAND_UI(ID_THEME_BAR, OnUpdateThemeBar)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- ////////////////////////////////////////////////////////
- //MapX事件响应函数
- //使用用户自定义图层
- BEGIN_EVENTSINK_MAP(CMapView, CView)
- ON_EVENT(CMapView, IDC_MAP, MAPX_DISPID_DRAWUSERLAYER, OnDrawUserLayer, VTS_DISPATCH VTS_I4 VTS_I4 VTS_DISPATCH VTS_DISPATCH)
- 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)
- ON_EVENT(CMapView, IDC_MAP, MAPX_DISPID_POLYTOOLUSED, OnPolyToolUsedMap, VTS_I2 VTS_I4 VTS_DISPATCH VTS_BOOL VTS_BOOL VTS_PBOOL)
- ON_EVENT(CMapView, IDC_MAP, -605 /* MouseDown */, OnMouseDownMap, VTS_I2 VTS_I2 VTS_R4 VTS_R4)
- ON_EVENT(CMapView, IDC_MAP, DISPID_MOUSEUP, OnMouseUpInMap, VTS_I2 VTS_I2 VTS_XPOS_PIXELS VTS_YPOS_PIXELS)
- ON_EVENT(CMapView, IDC_MAP, DISPID_MOUSEMOVE, OnMouseMoveInMap, VTS_I2 VTS_I2 VTS_XPOS_PIXELS VTS_YPOS_PIXELS)
- END_EVENTSINK_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMapView construction/destruction
- CMapView::CMapView()
- {
- m_dPrevZoom = 0;
- m_dCurZoom = 0;
- m_bScaleBar = FALSE;
- //m_bODBCDynamic = FALSE;
- m_strEditLayer="";
- m_bIsStartGps=FALSE;
- m_nGpsOperation=GPS_NOOPERATION;
- m_bIsAutoLable=FALSE;
- m_pTarget=NULL;
- }
- CMapView::~CMapView()
- {
- }
- BOOL CMapView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMapView drawing
- void CMapView::OnDraw(CDC* pDC)
- {
- CMapDemoDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMapView printing
- BOOL CMapView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CMapView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CMapView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMapView diagnostics
- #ifdef _DEBUG
- void CMapView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CMapView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CMapDemoDoc* CMapView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMapDemoDoc)));
- return (CMapDemoDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMapView message handlers
- void CMapView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
- if (cx != 0 && cy != 0)
- m_ctrlMapX.MoveWindow(0,0,cx,cy,TRUE);
- }
- BOOL CMapView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
- {
- // TODO: Add your specialized code here and/or call the base class
-
- return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
- }
- int CMapView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- // 使用缺省尺寸创建一个地图
- // 在OnSize函数里改变地图控件的大小,使之缩放到屏幕尺寸
- m_ctrlMapX.Create(NULL, WS_VISIBLE, CRect(0,0,100,100), this, IDC_MAP);
- // 创建距离工具
- try {
- // create some custom tools for object drawing
- m_ctrlMapX.CreateCustomTool(MYTOOL_DISTANCE, miToolTypePoly, miCrossCursor);
- m_ctrlMapX.CreateCustomTool(MYTOOL_INFO, miToolTypePoint, miCrossCursor);
- //绘图工具
- m_ctrlMapX.CreateCustomTool(CUSTOM_DRAW_TEXT_TOOL,miToolTypePoint,miCrossCursor);
- m_ctrlMapX.CreateCustomTool(CUSTOM_DRAW_SYMBOL_TOOL,miToolTypePoint,miCrossCursor);
- m_ctrlMapX.CreateCustomTool(CUSTOM_DRAW_LINE_TOOL,miToolTypeLine,miCrossCursor);
- m_ctrlMapX.CreateCustomTool(CUSTOM_DRAW_ELLIPSE_TOOL,miToolTypeMarquee,miCrossCursor);
- m_ctrlMapX.CreateCustomTool(CUSTOM_DRAW_RECT_TOOL,miToolTypeMarquee,miCrossCursor);
- m_ctrlMapX.CreateCustomTool(CUSTOM_DRAW_REGION_TOOL,miToolTypePoly,miCrossCursor);
- m_ctrlMapX.CreateCustomTool(CUSTOM_DRAW_ARC_TOOL,miToolTypeLine,miCrossCursor);
- //GPS工具
- m_ctrlMapX.CreateCustomTool(GPS_ADDTARGET,miToolTypePoint,miArrowCursor);
- m_ctrlMapX.CreateCustomTool(GPS_EDITTARGET,miToolTypePoint,miArrowCursor);
-
-
- }
- catch (COleDispatchException *e) {
- e->ReportError();
- e->Delete();
- }
- catch (COleException *e) {
- e->ReportError();
- e->Delete();
- }
- SetTitleVisible(FALSE);
- OnViewScalebar();
- return 0;
- }
- void CMapView::NotifyQueryNewPalette()
- {
- // we don't care, but our embedded control might
- m_ctrlMapX.SendMessage(WM_QUERYNEWPALETTE);
- }
- void CMapView::NotifyPaletteChanged(CWnd* pFocusWnd)
- {
- // we don't care, but our embedded control might
- m_ctrlMapX.SendMessage(WM_PALETTECHANGED, (WPARAM)(pFocusWnd->m_hWnd));
- }
- void CMapView::OnFileOpengeoset()
- {
- CGeoSetDlg geoDlg(&m_ctrlMapX);
- geoDlg.DoModal();
- }
- void CMapView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
- {
-
-
- }
- void CMapView::OnViewSysoption()
- {
- MapXSetDlg dlg(&m_ctrlMapX);
- dlg.DoModal();
-
- }
- void CMapView::OnMapToolSelect()
- {
- m_ctrlMapX.SetCurrentTool(miSelectTool);
-
- }
- void CMapView::OnMapToolZoomin()
- {
- m_ctrlMapX.SetCurrentTool(miZoomInTool);
-
- }
- void CMapView::OnMapToolZoomout()
- {
- m_ctrlMapX.SetCurrentTool(miZoomOutTool);
- }
- void CMapView::OnMapToolPan()
- {
- m_ctrlMapX.SetCurrentTool(miPanTool);
-
- }
- void CMapView::OnMapToolRadiusselect()
- {
- m_ctrlMapX.SetCurrentTool(miRadiusSelectTool);
-
- }
- void CMapView::OnMapToolRectangleselect()
- {
- m_ctrlMapX.SetCurrentTool(miRectSelectTool);
-
- }
- void CMapView::OnMapToolInformation()
- {
- m_ctrlMapX.SetCurrentTool(miRectSelectTool);
-
- }
- void CMapView::OnToolUnselectall()
- {
-
- CMapXLayers layers=m_ctrlMapX.GetLayers();
- for(int i=0;i<layers.GetCount();i++)
- {
- CMapXLayer layer=layers.Item(i+1);
- if(layer.GetSelectable())
- {
- CMapXSelection select=layer.GetSelection();
- if(select.GetCount()>0)
- select.ClearSelection();
- }
- }
-
- }
- // Draw the Scalebar layer whenever this event is called
- // we could check the Layer.Name property if we needed to handle
- // more than 1 user draw layer
- void CMapView::OnDrawUserLayer(LPDISPATCH Layer, long hOutputDC, long hAttributeDC, LPDISPATCH RectFull, LPDISPATCH RectInvalid)
- {
- CDC dc;
- dc.Attach((HDC)hOutputDC);
- dc.SetAttribDC((HDC)hAttributeDC);
- DrawScaleBar(&dc);
- }
- void CMapView::OnViewLayercontrol()
- {
- try {
- VARIANT vHelpFile, vHelpID; // mark as optional since we don't have a helpfile
- vHelpFile.vt = VT_ERROR;
- vHelpFile.scode = DISP_E_PARAMNOTFOUND;
- vHelpID.vt = VT_ERROR;
- vHelpID.scode = DISP_E_PARAMNOTFOUND;
- CMapXLayers layers = m_ctrlMapX.GetLayers();
- layers.LayersDlg(vHelpFile, vHelpID);
- }
- catch (COleDispatchException *e) {
- e->ReportError();
- e->Delete();
- }
- catch (COleException *e) {
- e->ReportError();
- e->Delete();
- }
-
-
- }
- //用户自定义图层绘制比例尺
- void CMapView::OnViewScalebar()
- {
- try {
- if(m_bScaleBar)
- {
- m_ctrlMapX.GetLayers().Remove("ScaleBar");
- m_bScaleBar = FALSE;
- }
- else
- {
- m_ctrlMapX.GetLayers().AddUserDrawLayer("ScaleBar", 1);
- m_bScaleBar = TRUE;
- }
- }
- catch (COleDispatchException *e) {
- e->ReportError();
- e->Delete();
- }
- catch (COleException *e) {
- e->ReportError();
- e->Delete();
- }
-
- }
- void CMapView::OnUpdateViewScalebar(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_bScaleBar);
-
- }
- void CMapView::DrawScaleBar(CDC *pDC)
- {
-
- float barWidth =(float)0.5, barHeight =(float)0.08;
- float startX =(float).3, startY =(float).3;
- long x1, y1;
- int i;
- // attach to dc that mapx passed us so we can use
- // mfc CDC object. (we will detach before exiting this method
- CPen pen;
- CBrush brushRed, brushWhite, *pOldBrush;
- CFont *pOldFont;
-
- pen.CreatePen(0,1,(COLORREF)0);
- brushRed.CreateSolidBrush(255);
- brushWhite.CreateSolidBrush(16777215);
- //Set map mode to HI-English
- pDC->SetMapMode(MM_HIENGLISH);
- //Set pen to black
- CPen *pOldPen = pDC->SelectObject(&pen);
- pOldBrush = pDC->SelectObject(&brushRed);
- //convert to HiEnglish, Conversion needed because one HIENGLISH unit is .001 inch
- x1=(long)(startX*1000);
- y1=(long)(startY*1000);
- barWidth*=1000;
- barHeight*=1000;
- for (i=0; i<=1; i++) {
- long x2 =(long)(barWidth+x1);
- long y2 =(long)(barHeight+y1);
-
- /*** First Section ***/
- if (i==0) {
- pDC->SelectObject(&brushRed); //Red
- }
- else {
- pDC->SelectObject(&brushWhite); //White
- }
- // with mapMode HIENGLISH, positive is x to the right, positive y is up
- pDC->Rectangle(x1, -y1, x2, -y2);
- /*** Second Section ***/
- x1=x2;
- x2=(long)(barWidth+x1);
- if (i==0) {
- pDC->SelectObject(&brushWhite); //White
- }
- else {
- pDC->SelectObject(&brushRed); //Red
- }
- pDC->Rectangle(x1, -y1, x2, -y2);
- /*** Third Section ***/
- x1=x2;
- x2=(long)(barWidth*2+x1);
- if (i==0) {
- pDC->SelectObject(&brushRed); //Red
- }
- else {
- pDC->SelectObject(&brushWhite); //White
- }
- pDC->Rectangle(x1, -y1, x2, -y2);
-
- /*** Reset Values for bottom bar pass***/
- x1=(long)(startX*1000);
- y1=y2;
- } // End For
- // Calculate Pixels Per Inch
- CPoint pt(1000, 1000); // In HIENGLISH 1000 units = 1 inch
- pDC->LPtoDP(&pt); // Convert inch to pixel
- long lPixPerInch = pt.x;
- CRect rc;
- CView::GetClientRect(&rc);
- float screenX, screenY;
- double mapX1, mapY1;
- // subtract lPixPerInch from center to get 1 inch to left of Center
- screenX = (float)(rc.right/2-lPixPerInch);
- screenY = (float)(rc.bottom/2);
- try {
- m_ctrlMapX.ConvertCoord(&screenX, &screenY, &mapX1, &mapY1, miScreenToMap);
- }
- catch (COleDispatchException *e) {
- e->ReportError();
- e->Delete();
- }
- catch (COleException *e) {
- e->ReportError();
- e->Delete();
- }
-
- double mapX2, mapY2;
- // add lPixPerInch to center to get 1 inch to right of Center
- screenX = (float)(rc.right/2+lPixPerInch);
- screenY = (float)(rc.bottom/2);
- try {
- m_ctrlMapX.ConvertCoord(&screenX, &screenY, &mapX2, &mapY2, miScreenToMap);
- }
- catch (COleDispatchException *e) {
- e->ReportError();
- e->Delete();
- }
- catch (COleException *e) {
- e->ReportError();
- e->Delete();
- }
- CFont font;
- font.CreatePointFont(100, "Arial", pDC);
- pOldFont = pDC->SelectObject(&font);
- pDC->SetTextColor(0); //Black
- pDC->SetBkMode(TRANSPARENT);
- // Output ScaleBar start Label = 0
- x1=(long)(startX*1000);
- y1=(long)((startY-.2)*1000);
- pDC->TextOut(x1,-y1,"0");
- // Output label for distance of 1 inch
- x1=(long)(barWidth*2+startX*1000);
- CString str;
- str.Format("%.0f",m_ctrlMapX.Distance(mapX1, mapY1, mapX2, mapY2)/2);
- // Need to center text over center line. will move it 60 units for each character
- int iCenterAdjustment = 60*str.GetLength();
- pDC->TextOut(x1-iCenterAdjustment,-y1,str);
- // Output label for distance of 2 inches
- x1=(long)(barWidth*4+startX*1000);
- str.Format("%.0f",m_ctrlMapX.Distance(mapX1, mapY1, mapX2, mapY2));
- // Need to center text over end line. will move it 60 units for each character
- iCenterAdjustment = 60*str.GetLength();
- pDC->TextOut(x1-iCenterAdjustment,-y1,str);
- // Output label for Units "Miles"
- x1=(long)(barWidth*2+startX*1000);
- y1=(long)((startY+.2)*1000);
- // Need to center text over center line. will move it 60 units for each character
- str.Format("Miles");
- iCenterAdjustment = 60*str.GetLength();
- pDC->TextOut(x1-iCenterAdjustment,-y1,str);
- pDC->SelectObject(pOldBrush);
- pDC->SelectObject(pOldPen);
- pDC->SelectObject(pOldFont);
- // detach dc so destructore won't call Release it
- pDC->ReleaseAttribDC();
- pDC->Detach();
- }
- ///标题控制
- void CMapView::SetTitle(CString str)
- {
- m_ctrlMapX.SetTitleText(str);
- }
- void CMapView::SetTitleVisible(BOOL bState)
- {
- m_ctrlMapX.GetTitle().SetVisible(bState);
- }
- ////////////////////////////////////
- void CMapView::OnMapeditSelettable()
- {
- CSelLayerDlg LayerDlg(&m_ctrlMapX);
- LayerDlg.SetEditLayerName(m_strEditLayer);
- if(LayerDlg.DoModal()==IDOK)
- m_strEditLayer=LayerDlg.GetEditLayerName();
-
- }
- BOOL CMapView::FindLayer(CString strLayerName)
- {
- CMapXLayers layers=m_ctrlMapX.GetLayers();
- for(int i=0;i<layers.GetCount();i++)
- {
- CMapXLayer layer=layers.Item(i+1);
- if(layer.GetName()==strLayerName) return TRUE;
- }
- return FALSE;
- }
- BOOL CMapView::FindLayer(CString strLayerName,CMapXLayer& layer)
- {
- CMapXLayers layers=m_ctrlMapX.GetLayers();
- for(int i=0;i<layers.GetCount();i++)
- {
- layer=layers.Item(i+1);
- if(layer.GetName()==strLayerName)
- return TRUE;
- }
- return FALSE;
- }
- /////////////////////////////////////////////
- void CMapView::OnPolyToolUsedMap(short ToolNum, long Flags, LPDISPATCH Points, BOOL bShift, BOOL bCtrl, BOOL FAR* EnableDefault)
- {
- // see CSampleDlg for example on usage on creating polygons or lines
- // calc distance so far
- if (ToolNum == MYTOOL_DISTANCE) {
- CMapXPoints pts;
- long n;
- long i;
- try {
- pts.AttachDispatch(Points, FALSE); // don't auto release
- double dDistanceTot = 0.0;
- n = pts.GetCount();
- for (i=1; i<n; i++) {
- CMapXPoint pt1 = pts.Item(i);
- CMapXPoint pt2 = pts.Item(i+1);
- double d = m_ctrlMapX.Distance(pt1.GetX(), pt1.GetY(), pt2.GetX(), pt2.GetY());
- dDistanceTot += d;
- }
- CString str;
- str.Format("Distance Tot: %f", dDistanceTot);
- ((CMainFrame *)AfxGetMainWnd())->m_wndStatusBar.SetPaneText(0, str);
- }
- catch (COleDispatchException *e) {
- e->ReportError();
- e->Delete();
- }
- catch (COleException *e) {
- e->ReportError();
- e->Delete();
- }
- }
- else if(Flags==miPolyToolEnd&&ToolNum==CUSTOM_DRAW_REGION_TOOL)
- {
- CMapXFeatureFactory cFactory=m_ctrlMapX.GetFeatureFactory();
- CMapXLayer layer;
- if(m_strEditLayer!="")
- layer=m_ctrlMapX.GetLayers().Item(m_strEditLayer);
- else {
- AfxMessageBox("你没有选择可编辑图层,请选择编辑图层");
- return;
- }
- CMapXFeature feature;
- CMapXPoints points;
- points.AttachDispatch(Points, FALSE); // don't auto release
- COleVariant vtPoints;
- vtPoints.vt = VT_DISPATCH;
- vtPoints.pdispVal = points.m_lpDispatch;
- vtPoints.pdispVal->AddRef();
- feature=cFactory.CreateRegion(vtPoints);
- layer.AddFeature(feature);
-
- }
- }
- void CMapView::OnToolUsed(short ToolNum, double X1, double Y1, double X2, double Y2, double Distance, BOOL Shift, BOOL Ctrl, BOOL* EnableDefault)
- {
- CString str;
- str.Format("Tool=%d, [%f,%f] [%f, %f], dist=%f, %s %sn",
- ToolNum, X1,Y1,X2,Y2,Distance, (Shift)?"Shift":"",(Ctrl)?"Ctrl":"");
- TRACE(str);
- //AfxMessageBox(str);
- // this info tool will pop up a modal dlg
- // with info from the dataset(1)
- // Note that we are only getting info from the MapX Dataset
- // you could use the SourceRows collection to get back
- // to the source data to display info from dao, odbc or whatever
- if (ToolNum == MYTOOL_INFO) {
- OnInfoToolUsed(m_ctrlMapX);
- }
-
- if(ToolNum>=CUSTOM_DRAW_TEXT_TOOL&&ToolNum <= CUSTOM_DRAW_ARC_TOOL)
- {
-
- CMapXFeatureFactory cFactory=m_ctrlMapX.GetFeatureFactory();
- CMapXLayer layer;
- if(m_strEditLayer!="")
- layer=m_ctrlMapX.GetLayers().Item(m_strEditLayer);
- else {
- AfxMessageBox("你没有选择可编辑图层,请选择编辑图层");
- return;
- }
- CMapXPoint point;
- point.CreateDispatch(point.GetClsid()); //Creates a dispatch for the point
- CMapXFeature feature;
- CMapXPoints points;
- points.CreateDispatch(points.GetClsid());
- CMapXRectangle rect;
- rect.CreateDispatch(rect.GetClsid());
- switch(ToolNum)
- {
- case CUSTOM_DRAW_TEXT_TOOL:
- {
-
- point.Set(X1,Y1);
- COleVariant vtPoint;
- vtPoint.vt = VT_DISPATCH;
- vtPoint.pdispVal = point.m_lpDispatch;
- vtPoint.pdispVal->AddRef();
- feature=cFactory.CreateText(vtPoint,"测试文档 gg");
- CMapXStyle style=feature.GetStyle();
- style.PickText();
- feature.SetStyle(style.m_lpDispatch);
- layer.AddFeature(feature);
- }
- break;
- case CUSTOM_DRAW_LINE_TOOL:
- {
- points.AddXY(X1,Y1);
- points.AddXY(X2,Y2);
- COleVariant vtPoints;
- vtPoints.vt = VT_DISPATCH;
- vtPoints.pdispVal = points.m_lpDispatch;
- vtPoints.pdispVal->AddRef();
- feature=cFactory.CreateLine(vtPoints);
- layer.AddFeature(feature);
- }
- break;
- case CUSTOM_DRAW_RECT_TOOL:
- {
- VARIANT scx,scy;
- m_ctrlMapX.ConvertCoordV(&scx,&scy,COleVariant(X1),COleVariant(Y1),miMapToScreen);
- VARIANT scx1,scy1;
- m_ctrlMapX.ConvertCoordV(&scx1,&scy1,COleVariant(X2),COleVariant(Y2),miMapToScreen);
-
- VARIANT mapx1,mapy1,mapx2,mapy2;
-
- m_ctrlMapX.ConvertCoordV(&scx,&scy1,&mapx1,&mapy1,miScreenToMap);
- m_ctrlMapX.ConvertCoordV(&scx1,&scy,&mapx2,&mapy2,miScreenToMap);
-
- double x2,y2,x4,y4;
- //mapx1.ChangeType(VT_R8);
- x2= mapx1.dblVal;
-
- //mapy1.ChangeType(VT_R8);
- y2=mapy1.dblVal;
- //mapx2.ChangeType(VT_R8);
- x4=mapx2.dblVal;
- //mapy2.ChangeType(VT_R8*;
- y4=mapy2.dblVal;
- points.AddXY(X1,Y1);
- points.AddXY(x2,y2);
- points.AddXY(X2,Y2);
- points.AddXY(x4,y4);
- COleVariant vtPoints;
- vtPoints.vt = VT_DISPATCH;
- vtPoints.pdispVal = points.m_lpDispatch;
- vtPoints.pdispVal->AddRef();
- feature=cFactory.CreateRegion(vtPoints);
- layer.AddFeature(feature);
- }
- break;
- case CUSTOM_DRAW_ARC_TOOL:
- {
- points.AddXY(X1,Y1);
- points.AddXY(X2,Y2);
-
- feature=cFactory.CreateArc(points.Item(1).m_lpDispatch,points.Item(2).m_lpDispatch);
- layer.AddFeature(feature);
- }
- break;
- case CUSTOM_DRAW_ELLIPSE_TOOL:
- {
- rect.Set(X1,Y1,X2,Y2);
- feature=cFactory.CreateEllipticalRegion(rect.m_lpDispatch , 0, 30);
- layer.AddFeature(feature);
- }
- break;
- /* Select Case ToolNum
- Case
- ptItem.Set x1, y1
- Set ftrItem = ftrFactory.CreateText(ptItem, "TEXT", _
- miPositionCC, Map1.DefaultStyle)
- lyrEdit.AddFeature ftrItem
- Set ftrItem = Nothing
- Case CUSTOM_DRAW_SYMBOL_TOOL
- ptItem.Set x1, y1
- Set ftrItem = ftrFactory.CreateSymbol(ptItem, Map1.DefaultStyle)
- lyrEdit.AddFeature ftrItem
- Set ftrItem = Nothing
- Case CUSTOM_DRAW_LINE_TOOL
- ptsItem.AddXY x1, y1
- ptsItem.AddXY x2, y2, 2
- Set ftrItem = ftrFactory.CreateLine(ptsItem, Map1.DefaultStyle)
- lyrEdit.AddFeature ftrItem
- Set ftrItem = Nothing
- Case CUSTOM_DRAW_ELLIPSE_TOOL
- rctItem.Set x1, y1, x2, y2
- Set ftrItem = ftrFactory.CreateEllipticalRegion(rctItem, 0, 30, Map1.DefaultStyle)
- lyrEdit.AddFeature ftrItem
- Set ftrItem = Nothing
- End Select
- Ed If*/
- }
- }
- }
- void CMapView::OnInfoToolUsed(CMapX &cMapX)
- {
- /* try {
- if (cMapX.GetDatasets().GetCount() == 0) {
- AfxMessageBox("This info tool requires that a dataset be added.");
- return;
- }
- CMapXPoint pt;
- CMapXFeatures fs;
- CMapXFeature f;
- CMapXDataset ds;
- pt.CreateDispatch(pt.GetClsid());
- pt.Set(X1,Y1);
-
- fs = cMapX.GetLayers().Item("USA").SearchAtPoint(pt);
- // just use first feature from collection. Since usa is a layer of
- // all regions, we will not get back > 1 feature in the collection
- // because there are no overlapping regions
- if (fs.GetCount() != 1) {
- return;
- }
- f = fs.Item(1);
- ds = cMapX.GetDatasets().Item(1);
-
- CInfoDlg dlg;
- COleVariant vRow;
- COleVariant vVal;
- vRow.vt = VT_DISPATCH;
- vRow.pdispVal = f.m_lpDispatch;
- vRow.pdispVal->AddRef();
- vVal = ds.GetValue(vRow, COleVariant(2L));
- vVal.ChangeType(VT_BSTR);
- dlg.m_strState = vVal.bstrVal;
- vVal = ds.GetValue(vRow, COleVariant(3L));
- vVal.ChangeType(VT_R8);
- dlg.m_dTotal = vVal.dblVal;
- vVal = ds.GetValue(vRow, COleVariant(4L));
- vVal.ChangeType(VT_R8);
- dlg.m_dFemale = vVal.dblVal;
-
- vVal = ds.GetValue(vRow, COleVariant(5L));
- vVal.ChangeType(VT_R8);
- dlg.m_dMale = vVal.dblVal;
- dlg.DoModal();
- }
- catch (COleDispatchException *e) {
- e->ReportError();
- e->Delete();
- }
- catch (COleException *e) {
- e->ReportError();
- e->Delete();
- }*/
- }
- void CMapView::OnMapeditAddtext()
- {
- //m_ctrlMapX.SetCurrentTool(miTextTool);
- m_ctrlMapX.SetCurrentTool(CUSTOM_DRAW_TEXT_TOOL);
-
- }
- void CMapView::OnUpdateMapeditAddtext(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==miTextTool);
-
- }
- void CMapView::OnMapeditAddsymbol()
- {
- m_ctrlMapX.SetCurrentTool(miSymbolTool);
- }
- void CMapView::OnUpdateMapeditAddsymbol(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==miSymbolTool);
-
- }
- void CMapView::OnMapeditAddline()
- {
- m_ctrlMapX.SetCurrentTool(CUSTOM_DRAW_LINE_TOOL);
-
- }
- void CMapView::OnUpdateMapeditAddline(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==CUSTOM_DRAW_LINE_TOOL);
-
- }
- void CMapView::OnMapeditAddpolygon()
- {
- m_ctrlMapX.SetCurrentTool(CUSTOM_DRAW_REGION_TOOL);
-
- }
- void CMapView::OnUpdateMapeditAddpolygon(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==CUSTOM_DRAW_REGION_TOOL);
-
-
- }
-
- void CMapView::OnMapeditAddrect()
- {
-
- m_ctrlMapX.SetCurrentTool(CUSTOM_DRAW_RECT_TOOL);
- }
- void CMapView::OnUpdateMapeditAddrect(CCmdUI* pCmdUI)
- {
-
- pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==CUSTOM_DRAW_RECT_TOOL);
- }
- void CMapView::OnMapeditAddepplise()
- {
- m_ctrlMapX.SetCurrentTool(CUSTOM_DRAW_ELLIPSE_TOOL);
-
- }
- void CMapView::OnUpdateMapeditAddepplise(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==CUSTOM_DRAW_ELLIPSE_TOOL);
- }
- void CMapView::OnMapeditAddarc()
- {
-
- m_ctrlMapX.SetCurrentTool(CUSTOM_DRAW_ARC_TOOL);
-
- }
- void CMapView::OnUpdateMapeditAddarc(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==CUSTOM_DRAW_ARC_TOOL);
-
- }
- void CMapView::OnInitialUpdate()
- {
- CView::OnInitialUpdate();
-
- CMainFrame* pFrame=((CMainFrame*)AfxGetMainWnd());
- pFrame->m_pMapView=this;
- }
- void CMapView::OnDestroy()
- {
- ClearAllTarget();
- CView::OnDestroy();
-
-
- CMainFrame* pFrame=((CMainFrame*)AfxGetMainWnd());
- pFrame->m_pMapView=NULL;
- }
- void CMapView::OnAddTarget()
- {
- m_ctrlMapX.SetCurrentTool(GPS_ADDTARGET);
-
- }
- void CMapView::OnUpdateAddTarget(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==GPS_ADDTARGET);
-
- }
- void CMapView::OnEditTarget()
- {
- m_ctrlMapX.SetCurrentTool(GPS_EDITTARGET);
-
- }
- void CMapView::OnUpdateEditTarget(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool()==GPS_EDITTARGET);
-
- }
- void CMapView::OnStartGps()
- {
- SetTimer(100,1500,NULL);
- m_bIsStartGps=TRUE;
- //SetAnimationLayer();
- }
- void CMapView::OnUpdateStartGps(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!m_bIsStartGps);
-
- }
- void CMapView::OnEndGps()
- {
- KillTimer(100);
- m_bIsStartGps=FALSE;
-
- }
- void CMapView::OnUpdateEndGps(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(m_bIsStartGps);
-
- }
- //鼠标操作
- void CMapView::OnMouseDownMap(short Button, short Shift, float X, float Y)
- {
- if(Button==1){
- m_nGpsOperation=m_ctrlMapX.GetCurrentTool();
- switch(m_nGpsOperation)
- {
- case GPS_ADDTARGET:{
-
- double lonX,latY;
- m_ctrlMapX.ConvertCoord(&X,&Y,&lonX,&latY,miScreenToMap);
-
- //gpsTarget.SetStartXY(lonX,latY);
-
-
- m_pTarget=new CGpsSet;
- m_pTarget->SetStartXY(lonX,latY);
-
- CTargetSet dlg(*m_pTarget);
- if(dlg.DoModal()==IDOK)
- dlg.GetGpsData(*m_pTarget);
- else return;
- if(!FindLayer("gps"))
- m_ctrlMapX.GetLayers().Add("gps.tab");
- CMapXLayer layer;
- if(FindLayer("gps",layer))
- {
- m_pTarget->AddFeature(&m_ctrlMapX,layer);
- gpsTargetArray.AddTarget(m_pTarget);
- }
- else
- {
- MessageBox("不能发现移动图层");
- }
- }break;
- case GPS_EDITTARGET:
- {
-
- gpsTargetArray.SetActiveTarget(gpsTargetArray.HitTest(X, Y,&m_ctrlMapX));
-
- if(gpsTargetArray.m_pActiveTarget==NULL) return;
- CTargetSet dlg(*gpsTargetArray.m_pActiveTarget);
- if(dlg.DoModal()==IDOK)
- dlg.GetGpsData(*gpsTargetArray.m_pActiveTarget);
- else return;
-
-
- }break;
-
- }
-
- }
- }
- BOOL CMapView::OnMouseUpInMap(short Button, short Shift, OLE_XPOS_PIXELS x, OLE_YPOS_PIXELS y)
- {
- return TRUE;
- }
- // you could use this to display the lat/long values on the status bar
- BOOL CMapView::OnMouseMoveInMap(short Button, short Shift, OLE_XPOS_PIXELS x, OLE_YPOS_PIXELS y)
- {
- return TRUE;
- }
- //选择目标样式
- void CMapView::OnGpsChangesymbol()
- {
- if(!FindLayer("gps"))
- m_ctrlMapX.GetLayers().Add("gps.tab");
- CMapXLayer layer;
- if(FindLayer("gps",layer))
- {
- CMapXStyle style=layer.GetStyle();
- style.PickSymbol();
- layer.SetStyle(style.m_lpDispatch);
-
- }
- else
- {
- MessageBox("不能发现移动图层");
- }
-
- }
- void CMapView::OnUpdateGpsChangesymbol(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- }
- void CMapView::OnTimer(UINT nIDEvent)
- {
- gpsTargetArray.Run();
- UpdateSense();
- CView::OnTimer(nIDEvent);
- }
- void CMapView::UpdateSense()
- {
- CMapXLayer layer;
- if(FindLayer("gps",layer))
- gpsTargetArray.UpdateGraph(layer);
- layer.Refresh();
- }
- void CMapView::SetAnimationLayer()
- {
- if(!FindLayer("gps"))
- m_ctrlMapX.GetLayers().Add("gps.tab");
- CMapXLayer layer;
- if(FindLayer("gps",layer))
- m_ctrlMapX.GetLayers().SetAnimationLayer(layer.m_lpDispatch);
- }
- void CMapView::ClearAllTarget()
- {
- CMapXLayer layer;
- if(FindLayer("gps",layer))
- {
- CMapXFeatures features=layer.AllFeatures();
- for(int i=1;i<=features.GetCount();i++)
- layer.DeleteFeature(features.Item(i));
- gpsTargetArray.DeleteAllTarget();
- }
- }
- BOOL CMapView::DestroyWindow()
- {
-
-
- return CView::DestroyWindow();
- }
- void CMapView::OnChangeSymbol()
- {
- m_bIsAutoLable=!m_bIsAutoLable;
- CMapXLayer layer;
- if(FindLayer("gps",layer))
- {
-
- /* CString str1=m_strEditLayer;
- CMapXDataset dataSet;
-
- if(!IsInDataSet(m_strEditLayer))
- dataSet=m_pCtrlMapX->GetDatasets().Add(miDataSetLayer, vtLayer, str1);*/
-
- layer.SetAutoLabel(m_bIsAutoLable);
- }
-
- }
- void CMapView::OnUpdateChangeSymbol(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_bIsAutoLable);
-
- }
- void CMapView::OnLineChange()
- {
- CMapXStyle style=m_ctrlMapX.GetDefaultStyle();
- style.PickLine();
-
- }
- void CMapView::OnReagionChange()
- {
- CMapXStyle style=m_ctrlMapX.GetDefaultStyle();
- style.PickRegion();
-
- }
- void CMapView::OnMapxProperty()
- {
- m_ctrlMapX.PropertyPage();
-
- }
- void CMapView::OnDatabindNormal()
- {
-
- try {
- CMapXLayer layer = m_ctrlMapX.GetLayers().Item("USA");
- VARIANT vtLayer;
- vtLayer.vt = VT_DISPATCH;
- vtLayer.pdispVal = layer.m_lpDispatch;
- CMapXDataset dataSet = m_ctrlMapX.GetDatasets().Add(miDataSetLayer, vtLayer, "USA Layer");
-
-
- }
- catch (COleDispatchException *e) {
- e->ReportError();
- e->Delete();
- }
- catch (COleException *e) {
- e->ReportError();
- e->Delete();
- }
- }
- void CMapView::OnUpdateDatabindNormal(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- }
- void CMapView::OnBinddataOdbc()
- {
- // TODO: Add your command handler code here
-
- }
- void CMapView::OnUpdateBinddataOdbc(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- }
- void CMapView::OnBinddataArray()
- {
- // TODO: Add your command handler code here
-
- }
- void CMapView::OnUpdateBinddataArray(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- }
- void CMapView::OnBinddataNobind()
- {
- // TODO: Add your command handler code here
-
- }
- void CMapView::OnUpdateBinddataNobind(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- }
- void CMapView::OnThemeReange()
- {
- VARIANT Type;
- VARIANT Name;
- VARIANT Field;
- VARIANT Item;
- // long FieldNums =4; // theme field numbers
- long FieldNums[3] = { 3, 4, 5}; // theme field numbers
- int n=3;
-
- // construct a safearray of column numbers (could use names instead)
- /*SAFEARRAY FAR* psa=NULL;
- SAFEARRAYBOUND rgsabound[1];
- long ix;
- rgsabound[0].lLbound = 1;
- rgsabound[0].cElements = n;
- psa = SafeArrayCreate(VT_I4, 1, rgsabound);
- if(psa == NULL){
- return;
- }
- for (int i=0; i< n; i++) {
- ix=i+1;
- SafeArrayPutElement(psa, &ix, &FieldNums[i]);
- }*/
- // put array in field param
- Field.vt = /*VT_ARRAY |*/ VT_I4;
- //Field.parray = psa;
- Field.lVal = 5;
- Type.vt = VT_I4;
- Type.lVal = miThemeRanged; //auto choose theme type
- Name.vt = VT_ERROR; // use default name
- Name.scode = DISP_E_PARAMNOTFOUND;
- //miThemeRanged = 0,
- //miThemeBarChart = 1,
- //miThemePieChart = 2,
- //miThemeGradSymbol = 3,
- //miThemeDotDensity = 4,
- //miThemeIndividualValue = 5,
- //miThemeAuto = 6,
- //miThemeNone = 9,
-
- try {
- // get themes collection
- CMapXThemes objThemes = m_ctrlMapX.GetDatasets()[1L].GetThemes();
- // want to see full legend
- m_ctrlMapX.SetPreferCompactLegends(FALSE);
- // add theme - will be visible by default
- CMapXTheme thm = objThemes.Add(Type, Field, Name);
- thm.ThemeDlg();
- //CMapXThemeProperties themeDlg=thm.GetThemeProperties();
- //CMapXRangeCategories cate=themeDlg.GetRangeCategories();
- //cate.GetProperty();
- }
- catch (COleDispatchException *e) {
- e->ReportError();
- e->Delete();
- }
- catch (COleException *e) {
- e->ReportError();
- e->Delete();
- }
-
- }
- void CMapView::OnUpdateThemeReange(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- }
- void CMapView::OnThemeDot()
- {
- // TODO: Add your command handler code here
-
- }
- void CMapView::OnUpdateThemeDot(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- }
- void CMapView::OnThemePie()
- {
- // TODO: Add your command handler code here
-
- }
- void CMapView::OnUpdateThemePie(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- }
- void CMapView::OnThemeSymbol()
- {
- // TODO: Add your command handler code here
-
- }
- void CMapView::OnUpdateThemeSymbol(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- }
- void CMapView::OnThemeIndiv()
- {
- // TODO: Add your command handler code here
-
- }
- void CMapView::OnUpdateThemeIndiv(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- }
- void CMapView::OnThemeBar()
- {
- VARIANT Type;
- VARIANT Name;
- VARIANT Field;
- VARIANT Item;
- long FieldNums[3] = { 4, 5, 6}; // theme field numbers
- int n=3;
- Type.vt = VT_I4;
- Type.lVal = miThemeBarChart; //auto choose theme type
- Name.vt = VT_ERROR; // use default name
- Name.scode = DISP_E_PARAMNOTFOUND;
- Item.vt = VT_I4; // for getting first dataset
- Item.lVal = 1;
- // construct a safearray of column numbers (could use names instead)
- SAFEARRAY FAR* psa=NULL;
- SAFEARRAYBOUND rgsabound[1];
- long ix;
- rgsabound[0].lLbound = 1;
- rgsabound[0].cElements = n;
- psa = SafeArrayCreate(VT_I4, 1, rgsabound);
- if(psa == NULL){
- return;
- }
- for (int i=0; i< n; i++) {
- ix=i+1;
- SafeArrayPutElement(psa, &ix, &FieldNums[i]);
- }
- // put array in field param
- Field.vt = VT_ARRAY | VT_I4;
- Field.parray = psa;
- try {
- // get themes collection
- CMapXThemes objThemes = m_ctrlMapX.GetDatasets()[1L].GetThemes();
- // want to see full legend
- m_ctrlMapX.SetPreferCompactLegends(FALSE);
- // add theme - will be visible by default
- CMapXTheme thm = objThemes.Add(Type, Field, Name);
- }
- catch (COleDispatchException *e) {
- e->ReportError();
- e->Delete();
- }
- catch (COleException *e) {
- e->ReportError();
- e->Delete();
- }
- // clean up fields array
- if (psa)
- SafeArrayDestroy(psa);
-
- }
- void CMapView::OnUpdateThemeBar(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- }