⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maptestview.cpp

📁 GIS地理信息系统开发。大名鼎鼎的MAPX+C++软件开发
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// MapTestView.cpp : implementation of the CMapTestView class
//
/*
 * This sample application and corresponding sample code is provided for 
 * example purposes only.  It has not undergone rigorous testing and as 
 * such should not be shipped as part of a final application without 
 * extensive testing on the part of the organization releasing the 
 * end-user product. 
 */

#include "stdafx.h"
#include "MapTest.h"

#include "MapTestDoc.h"
#include "MapTestView.h"
#include "Mapx.h"
#include "CustDlg.h"
#include "ThemeDlg.h"
#include "BufferDlg.h"

#include <direct.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define IDC_MAP 100
#define CUST_INFO 1

/////////////////////////////////////////////////////////////////////////////
// CMapTestView

IMPLEMENT_DYNCREATE(CMapTestView, CView)

BEGIN_MESSAGE_MAP(CMapTestView, CView)
	//{{AFX_MSG_MAP(CMapTestView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_SETFOCUS()
	ON_COMMAND(ID_MAP_TOOL_CENTER, OnMapToolCenter)
	ON_COMMAND(ID_MAP_TOOL_PAN, OnMapToolPan)
	ON_COMMAND(ID_MAP_TOOL_ZOOMIN, OnMapToolZoomin)
	ON_COMMAND(ID_MAP_TOOL_ZOOMOUT, OnMapToolZoomout)
	ON_COMMAND(ID_VIEW_LAYERCONTROL, OnViewLayercontrol)
	ON_COMMAND(ID_VIEW_PROPERTIES, OnViewProperties)
	ON_UPDATE_COMMAND_UI(ID_MAP_TOOL_ARROW, OnUpdateMapToolArrow)
	ON_UPDATE_COMMAND_UI(ID_MAP_TOOL_CENTER, OnUpdateMapToolCenter)
	ON_UPDATE_COMMAND_UI(ID_MAP_TOOL_PAN, OnUpdateMapToolPan)
	ON_UPDATE_COMMAND_UI(ID_MAP_TOOL_ZOOMIN, OnUpdateMapToolZoomin)
	ON_UPDATE_COMMAND_UI(ID_MAP_TOOL_ZOOMOUT, OnUpdateMapToolZoomout)
	ON_COMMAND(ID_MAP_TOOL_ARROW, OnMapToolArrow)
	ON_COMMAND(ID_MAP_TOOL_INFOTOOL, OnMapToolInfotool)
	ON_UPDATE_COMMAND_UI(ID_MAP_TOOL_INFOTOOL, OnUpdateMapToolInfotool)
	ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
	ON_COMMAND(ID_INFO_TOOL, OnInfoTool)
	ON_UPDATE_COMMAND_UI(ID_INFO_TOOL, OnUpdateInfoTool)
	ON_COMMAND(ID_MAP_ADDCUSTOMERLAYER, OnMapAddcustomerlayer)
	ON_UPDATE_COMMAND_UI(ID_MAP_ADDCUSTOMERLAYER, OnUpdateMapAddcustomerlayer)
	ON_COMMAND(ID_MAP_REMOVECUSTOMERLAYER, OnMapRemovecustomerlayer)
	ON_UPDATE_COMMAND_UI(ID_MAP_REMOVECUSTOMERLAYER, OnUpdateMapRemovecustomerlayer)
	ON_COMMAND(ID_MAP_ADDDATASETFROMLAYER, OnMapAdddatasetfromlayer)
	ON_UPDATE_COMMAND_UI(ID_MAP_ADDDATASETFROMLAYER, OnUpdateMapAdddatasetfromlayer)
	ON_COMMAND(ID_MAP_ADDTHEME, OnMapAddtheme)
	ON_UPDATE_COMMAND_UI(ID_MAP_ADDTHEME, OnUpdateMapAddtheme)
	ON_COMMAND(ID_MAP_ADDOUTLETLAYER, OnMapAddoutletlayer)
	ON_UPDATE_COMMAND_UI(ID_MAP_ADDOUTLETLAYER, OnUpdateMapAddoutletlayer)
	ON_COMMAND(ID_MAP_REMOVEOUTLETLAYER, OnMapRemoveoutletlayer)
	ON_UPDATE_COMMAND_UI(ID_MAP_REMOVEOUTLETLAYER, OnUpdateMapRemoveoutletlayer)
	ON_COMMAND(ID_MAP_BUFFERS_BUFFERTHECUSTOMERS, OnMapBuffersBufferthecustomers)
	ON_UPDATE_COMMAND_UI(ID_MAP_BUFFERS_BUFFERTHECUSTOMERS, OnUpdateMapBuffersBufferthecustomers)
	ON_COMMAND(ID_MAP_BUFFERS_BUFFERTHEOUTLETS, OnMapBuffersBuffertheoutlets)
	ON_UPDATE_COMMAND_UI(ID_MAP_BUFFERS_BUFFERTHEOUTLETS, OnUpdateMapBuffersBuffertheoutlets)
	ON_COMMAND(ID_MAP_BUFFERS_REMOVECUSTOMERBUFFER, OnMapBuffersRemovecustomerbuffer)
	ON_UPDATE_COMMAND_UI(ID_MAP_BUFFERS_REMOVECUSTOMERBUFFER, OnUpdateMapBuffersRemovecustomerbuffer)
	ON_COMMAND(ID_MAP_BUFFERS_REMOVETHEOUTLETSBUFFERS, OnMapBuffersRemovetheoutletsbuffers)
	ON_UPDATE_COMMAND_UI(ID_MAP_BUFFERS_REMOVETHEOUTLETSBUFFERS, OnUpdateMapBuffersRemovetheoutletsbuffers)
	//}}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()

BEGIN_EVENTSINK_MAP(CMapTestView, CView)
//	ON_EVENT(CMapTestView, IDC_MAP, DISPID_MOUSEMOVE, OnMouseMove_Map, VTS_I2 VTS_I2 VTS_XPOS_PIXELS VTS_YPOS_PIXELS)
//	ON_EVENT(CMapTestView, IDC_MAP, DISPID_CLICK, OnClick_Map, VTS_NONE)
//	ON_EVENT(CMapTestView, IDC_MAP, DISPID_DBLCLICK, OnDblClick_Map, VTS_NONE)
//	ON_EVENT(CMapTestView, IDC_MAP, DISPID_ERROREVENT, OnError_Map, VTS_I2 VTS_PBSTR VTS_I4 VTS_BSTR VTS_BSTR VTS_I4 VTS_PBOOL)
//	ON_EVENT(CMapTestView, IDC_MAP, DISPID_KEYDOWN, OnKeyDown_Map, VTS_PI2 VTS_I2)
//	ON_EVENT(CMapTestView, IDC_MAP, DISPID_KEYPRESS, OnKeyPress_Map, VTS_PI2)
//	ON_EVENT(CMapTestView, IDC_MAP, DISPID_KEYUP, OnKeyUp_Map, VTS_PI2 VTS_I2)
//	ON_EVENT(CMapTestView, IDC_MAP, DISPID_MOUSEDOWN, OnMouseDown_Map, VTS_PI2 VTS_PI2 VTS_PR4 VTS_PR4)
	ON_EVENT(CMapTestView, IDC_MAP, DISPID_MOUSEUP, OnMouseUp_Map, VTS_I2 VTS_I2 VTS_XPOS_PIXELS VTS_YPOS_PIXELS)
//	ON_EVENT(CMapTestView, IDC_MAP, MAPX_DISPID_SELECTION_CHANGED, OnSelectionChanged, VTS_NONE)
//	ON_EVENT(CMapTestView, IDC_MAP, MAPX_DISPID_RESOLVEDATABIND, OnResolveDataBind, VTS_I2 VTS_I2 VTS_VARIANT VTS_PI2 VTS_PBOOL)
//	ON_EVENT(CMapTestView, IDC_MAP, MAPX_DISPID_REQUESTDATA, OnRequestData, VTS_BSTR VTS_I4 VTS_I2 VTS_PVARIANT VTS_PBOOL)
//	ON_EVENT(CMapTestView, IDC_MAP, MAPX_DISPID_DATAMISMATCH, OnDataMismatch, VTS_BSTR VTS_I4 VTS_PBSTR)
//	ON_EVENT(CMapTestView, IDC_MAP, MAPX_DISPID_MAPVIEWCHANGED, OnMapViewChanged, VTS_NONE)
//	ON_EVENT(CMapTestView, IDC_MAP, MAPX_DISPID_ANNOTATIONADDED, OnAnnotationAdded, VTS_DISPATCH)
//	ON_EVENT(CMapTestView, IDC_MAP, MAPX_DISPID_ANNOTATIONCHANGED, OnAnnotationChanged, VTS_I2 VTS_DISPATCH VTS_PBOOL)
	ON_EVENT(CMapTestView, IDC_MAP, MAPX_DISPID_THEMEMODIFYREQUESTED, OnThemeModifyRequested, VTS_DISPATCH)
//	ON_EVENT(CMapTestView, IDC_MAP, MAPX_DISPID_DRAWUSERLAYER, OnDrawUserLayer, VTS_DISPATCH VTS_I4 VTS_I4 VTS_DISPATCH VTS_DISPATCH)
//	ON_EVENT(CMapTestView, IDC_MAP, MAPX_DISPID_POLYTOOLUSED, OnPolyToolUsed, VTS_I2 VTS_I4 VTS_DISPATCH VTS_BOOL VTS_BOOL VTS_PBOOL)
	ON_EVENT(CMapTestView, 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(CMapTestView, IDC_MAP, MAPX_DISPID_MOUSEWHEEL, OnMouseWheel, VTS_I4 VTS_I2 VTS_PR4 VTS_PR4 VTS_PBOOL)
//	ON_EVENT(CMapTestView, IDC_MAP, MAPX_DISPID_MAPINITIALIZED, OnMapInitialized, VTS_NONE)	
END_EVENTSINK_MAP()


	


/////////////////////////////////////////////////////////////////////////////
// CMapTestView construction/destruction

CMapTestView::CMapTestView()
{
	//TODO Add code here for initialization

}

CMapTestView::~CMapTestView()
{
}

BOOL CMapTestView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMapTestView drawing

void CMapTestView::OnDraw(CDC* pDC)
{
	CMapTestDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CMapTestView printing

BOOL CMapTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMapTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMapTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMapTestView diagnostics

#ifdef _DEBUG
void CMapTestView::AssertValid() const
{
	CView::AssertValid();
}

void CMapTestView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMapTestDoc* CMapTestView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMapTestDoc)));
	return (CMapTestDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMapTestView message handlers

int CMapTestView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if(m_ctrlMapX.Create(NULL, WS_VISIBLE, CRect(0,0,300,300), this, IDC_MAP) == false)
		return -1;

	// create custom info tool
	
	try {
		// create some custom tools for object drawing
		m_ctrlMapX.CreateCustomTool(CUST_INFO, miToolTypePoint, miCrossCursor);

	}
	catch (COleDispatchException *e) {
		e->ReportError();
		e->Delete();
	}
	catch (COleException *e) {
		e->ReportError();
		e->Delete();
	}
	
	return 0;
}


//Resize the map to be the same size as Client Area
void CMapTestView::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);
	
}


//This makes sure that MapX get the focus
void CMapTestView::OnSetFocus(CWnd* pOldWnd) 
{
	CView::OnSetFocus(pOldWnd);
	
	m_ctrlMapX.SetFocus();
	
}


//This sets the current tool to be the centering tool
void CMapTestView::OnMapToolCenter() 
{
	m_ctrlMapX.SetCurrentTool(miCenterTool);
	
}

//This sets the current tool to be the pan tool.
void CMapTestView::OnMapToolPan() 
{
	m_ctrlMapX.SetCurrentTool(miPanTool);
	
}

//This set the current tool to be the zoom in tool
void CMapTestView::OnMapToolZoomin() 
{
	m_ctrlMapX.SetCurrentTool(miZoomInTool);
	
}

//This sets the current tool to be the zoom out tool
void CMapTestView::OnMapToolZoomout() 
{
	m_ctrlMapX.SetCurrentTool(miZoomOutTool);
}


//This section brings up the layer control dialog
void CMapTestView::OnViewLayercontrol() 
{
	try {
		COptionalVariant vHelpFile, vHelpID; // mark as optional since we don't have a helpfile
		m_ctrlMapX.GetLayers().LayersDlg(vHelpFile, vHelpID);
	} catch (COleDispatchException *e) {
		e->ReportError();
		e->Delete();
	} catch (COleException *e) {
		e->ReportError();
		e->Delete();
	}
}

//This section brings up the dialog box.
void CMapTestView::OnViewProperties() 
{
	// easest way to bring up property page
	try {
		m_ctrlMapX.PropertyPage();
	} catch (COleDispatchException *e) {
		e->ReportError();
		e->Delete();
	} catch (COleException *e) {
		e->ReportError();
		e->Delete();
	}
}



void CMapTestView::OnUpdateMapToolArrow(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == miArrowTool);
			//Check the menu item if in use
}

void CMapTestView::OnUpdateMapToolCenter(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == miCenterTool);
			//Check the menu item if in use
}

void CMapTestView::OnUpdateMapToolPan(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == miPanTool);
}			//Check the menu item if in use 

void CMapTestView::OnUpdateMapToolZoomin(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == miZoomInTool);
}			//Check the menu item if in use

void CMapTestView::OnUpdateMapToolZoomout(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == miZoomOutTool);
}			//Check the menu item if in use

void CMapTestView::OnMapToolArrow() 
{
	//Set the curren tool to be the arrow tool
	m_ctrlMapX.SetCurrentTool(miArrowTool);
}

void CMapTestView::OnMapToolInfotool() 
{
	try{//Set the current tool to the Custom tool CUST_INFO
		m_ctrlMapX.SetCurrentTool(CUST_INFO);
	} catch (COleDispatchException *e) {
		e->ReportError();
		e->Delete();
	} catch (COleException *e) {
		e->ReportError();
		e->Delete();
	}
}

void CMapTestView::OnMouseUp_Map(short Button, short Shift, long X, long Y) {
	// when the user right clicks on the map, bring up the MapX layers dialog.
	if(Button == 2)
		m_ctrlMapX.GetLayers().LayersDlg();
}

void CMapTestView::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 %s\n",
		ToolNum, X1,Y1,X2,Y2,Distance, (Shift)?"Shift":"",(Ctrl)?"Ctrl":"");
	TRACE(str);

	if (ToolNum == CUST_INFO) {
		try {
			if (!(m_ctrlMapX.GetLayers().Item("Us_custg"))) {
				AfxMessageBox("This info tool requires that the Customer Layer be added.");
				m_ctrlMapX.SetCurrentTool(miArrowTool);
				return;}
			
			CMapXPoint pt;		//This point will be the center of our search
			CMapXFeatures fs;	//This will hold all of the features within our search
			CMapXFeature f;		//This will hold the customer feature we are currently
								//looking at

			pt.CreateDispatch(pt.GetClsid());	//Creates a dispatch for the point
			pt.Set(X1,Y1);						//Sets the coordinates into the point
			
			fs = m_ctrlMapX.GetLayers().Item("Us_custg").SearchAtPoint(pt);
			if(fs.GetCount() == 0)
				return; // do nothing if the user didn't click on a customer

			f = fs.Item(1);		//This section conducts a search at the point where the user
								//clicked.  We set the customer feature "f" equal to the 
								//first item in the "fs" collection.
			


			CCustDlg dlg;//Declare dlg to be of type CCustDlg.  This dialog will present our
						 // customer information

			
			dlg.m_pMap = &m_ctrlMapX;
			dlg.custFtrID = f.GetFeatureID();
			
			//********************************************************************************
			//Since the keyfield is Lname for Us_custg.tab.  Grab
			//out the keyvalue (Last name of customer) and hold it in
			//custLName.  After this, set the last name member variable 
			//of our dialog dlg equal to custLname. Then set the pointer variable
			// of dlg, to point at custLName also.  This will help us in editing the 
			//the correct fields in out .tab file.
			//We need to do this for each field in the .tab file
			//*******************************************************************************
			
			custLName = f.GetKeyValue();	
			dlg.m_Lname = custLName;
			dlg.m_pLname = &custLName;


			//*******************************************************************************
			//This next section steps through the .tab file.  Each time it takes
			// the value in the keyfield and places it into a temporart variable
			// From there it is set into the appropriate edit box on the dialog
			//Customer Information.  At the end we reset the layer "Us_custg"'s keyfield
			// to be LName.
			//*******************************************************************************

			m_ctrlMapX.GetLayers().Item("Us_custg").SetKeyField("Fname"); 
			custFName = f.GetKeyValue();
			dlg.m_Fname = custFName;
			dlg.m_pFname = &custFName;

			m_ctrlMapX.GetLayers().Item("Us_custg").SetKeyField("Terr"); 
			custTerr = f.GetKeyValue();
			dlg.m_Terr = custTerr;
			dlg.m_pTerr = &custTerr;

			m_ctrlMapX.GetLayers().Item("Us_custg").SetKeyField("Company"); 
			custCompany = f.GetKeyValue();
			dlg.m_Company = custCompany;
			dlg.m_pCompany = &custCompany;

			m_ctrlMapX.GetLayers().Item("Us_custg").SetKeyField("City"); 
			custCity = f.GetKeyValue();
			dlg.m_City = custCity;
			dlg.m_pCity = &custCity;

			m_ctrlMapX.GetLayers().Item("Us_custg").SetKeyField("State"); 
			custState = f.GetKeyValue();
			dlg.m_State = custState;
			dlg.m_pState = &custState;

			m_ctrlMapX.GetLayers().Item("Us_custg").SetKeyField("Zip"); 
			custZip = f.GetKeyValue();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -