?? gpspointdlg.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 + -