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

📄 gpspointdlg.cpp

📁 mapx 加地图vc mapx添加图元信息,地址翻译
💻 CPP
字号:
// GpsPointDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GpsPoint.h"
#include "GpsPointDlg.h"
#include "MapX.h"
#include "CommFunc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGpsPointDlg dialog

CGpsPointDlg::CGpsPointDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGpsPointDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGpsPointDlg)
	m_Latitude = _T("");
	m_Longitude = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGpsPointDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGpsPointDlg)
	DDX_Control(pDX, IDC_BTN_Func, m_Func);
	DDX_Control(pDX, IDC_BUTTON3, m_Pan);
	DDX_Control(pDX, IDC_BTN_ZommOut, m_Zommout);
	DDX_Control(pDX, IDC_BTN_ZommIn, m_ZommIN);
	DDX_Control(pDX, IDC_MAP, m_Map);
	DDX_Text(pDX, IDC_lat, m_Latitude);
	DDX_Text(pDX, IDC_lon, m_Longitude);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGpsPointDlg, CDialog)
	//{{AFX_MSG_MAP(CGpsPointDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BTN_Func, OnFunc)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGpsPointDlg message handlers

BOOL CGpsPointDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	//定义加载所用的地图信息
	CString szLog;
	szLog.Format("加载地图数据.(%s)",g_CommFunc.GetCurrentPath()+"Map//china.gst");
	try
	{
		m_Map.SetGeoSet((g_CommFunc.GetCurrentPath()+"Map//china.GST"));
		m_Map.SetTitleText("我日");
		NodeLay	= m_Map.GetLayers().Add(g_CommFunc.GetCurrentPath()+"Map//Node.tab");
		NodeLay.SetEditable(TRUE);
		NodeLay.SetSelectable(TRUE);
		NodeLay.SetAutoLabel(TRUE);
		PoiLay = m_Map.GetLayers().Add(g_CommFunc.GetCurrentPath()+"Map//POI.tab");
		PoiLay.SetEditable(TRUE);
		PoiLay.SetSelectable(TRUE);
		PoiLay.SetAutoLabel(TRUE);
		RoadLay = m_Map.GetLayers().Add(g_CommFunc.GetCurrentPath()+"Map//Road.tab");
		RoadLay.SetEditable(TRUE);
		RoadLay.SetSelectable(TRUE);
		//m_Map.GetTitle().SetVisible(FALSE);
		
	}
	catch (COleDispatchException *e)
	{
		e->Delete();
		return 0;
		// TODO: Add extra initialization here
	}
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CGpsPointDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CGpsPointDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CGpsPointDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CGpsPointDlg::OnFunc() 
{
	//this->Road(m_Map);
	this->Point(m_Map);
	//this->Node(m_Map,a,b);
	// TODO: Add your control notification handler code here
}

BOOL CGpsPointDlg::Point(CMapX &map)
{
	double longitude = 121.440809;
	double	latitude = 31.192247;
	CMapXFeatures fs;
	VARIANT vtLayer;
	vtLayer.vt = VT_DISPATCH;
	fs = m_Map.GetLayers().Item("POI").AllFeatures();	
	int iCount = fs.GetCount();
	//得到交叉点层的地图信息
	double xmin,ymin,xmax,ymax;
	CMapXRectangle rect;
	CMapXFeature fetu;	//地物
	//lay = map.GetLayers().Item(layername);
	rect = PoiLay.GetBounds();	//得交叉点图层的界限
	xmin = rect.GetXMin();	//最小的点位信息
	ymin = rect.GetYMin();
	xmax = rect.GetXMax();	//最大的点位信息
	ymax = rect.GetYMax();
	
	if (longitude < xmin || longitude > xmax || latitude <ymin || latitude >ymax)
	{
		AfxMessageBox("此点不在中国内");
		return FALSE;
	}
	//定义一个区域得到这个区域内的交叉点
	double areaX=longitude+0.01;
	double areaY=latitude+0.01;
	double mareaX=longitude-0.01;
	double mareaY=latitude-0.01;
	fs=PoiLay.AllFeatures();
	int count = fs.GetCount();
	
	if (longitude > areaX || latitude >areaY || longitude <mareaX || latitude <mareaY)
	{
		AfxMessageBox("此点不在此区的地图内");
		return FALSE;	
	}
	for (int b=0;b<count;b++)
	{	
		fetu = fs.Item(b+1);			//fs为一定范围里的交叉点与已知点距离集合,XX为一定范围里的交叉点与已知点距离集合的总个数
		double lon=fetu.GetCenterX();
		double lat=fetu.GetCenterY();
		if (lon < areaX && lat <areaY && lon >mareaX &&  lat >mareaY)//得到一定的范围里交叉点信息(变量)
		{
			map.SetMapUnit(miUnitMeter);
			double z=map.Distance(longitude,latitude,lon,lat);//算到距离
			int cc=int(z);
			if (cc<100)
			{
				///////////////////////////////////////////////////////////////
				try 
				{
					dataSet=m_Map.GetDatasets().Add(miDataSetLayer,vtLayer,"POI");
					dataSet.GetRowValues(1);
					pntsVt=dataSet.GetValue(5,_T("Address"));
					//终于得到mapinfo某一个图层表的某个字段的值了
				}
				catch (COleDispatchException *e) {
					e->ReportError();
					e->Delete();
				}
				catch (COleException *e) {
					e->ReportError();
					e->Delete();
				}
				////////////////////////////////////////////////////////////////
				CString str =(BSTR)pntsVt.pbstrVal; 
				AfxMessageBox(str);	
			}
			//////////////////////////////////////////////////////////////////////	
		}
	}
	return TRUE;
}

⌨️ 快捷键说明

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