www.pudn.com > vectormap.rar > MapAppView.cpp


// MapAppView.cpp : implementation of the CMapAppView class 
// 
 
#include "stdafx.h" 
#include "MapApp.h" 
 
#include "MapAppDoc.h" 
#include "MapAppView.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CMapAppView 
 
IMPLEMENT_DYNCREATE(CMapAppView, CView) 
 
BEGIN_MESSAGE_MAP(CMapAppView, CView) 
	//{{AFX_MSG_MAP(CMapAppView) 
		// NOTE - the ClassWizard will add and remove mapping macros here. 
		//    DO NOT EDIT what you see in these blocks of generated code! 
	//}}AFX_MSG_MAP 
//网上数据接收 
	ON_MESSAGE (WM_USER_RECEIVE_DATA,OnReceiveData) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CMapAppView construction/destruction 
 
CMapAppView::CMapAppView() 
{ 
	// TODO: add construction code here 
 
} 
 
CMapAppView::~CMapAppView() 
{ 
	char str[256]; 
	if (m_hWindowHwnd) //地图窗口存在 
	{ 
		sprintf(str,"Close Window %lu",m_lWindowid); 
		mapinfo.Do(str); 
		m_hWindowHwnd = NULL; 
		m_lWindowid = 0L; 
		mapinfo.Do("Commit Table plane");//保存实时航迹表 
	} 
 
} 
 
BOOL CMapAppView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CMapAppView drawing 
 
void CMapAppView::OnDraw(CDC* pDC) 
{ 
	CMapAppDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	// TODO: add draw code for native data here 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CMapAppView diagnostics 
 
#ifdef _DEBUG 
void CMapAppView::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CMapAppView::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
CMapAppDoc* CMapAppView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMapAppDoc))); 
	return (CMapAppDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CMapAppView message handlers 
 
void CMapAppView::OnInitialUpdate()  
{ 
	CView::OnInitialUpdate(); 
	 
	char str[256]; 
	///创建航显底图 
    mapinfo.Do("Open Table \"E:\\Province.tab\" ReadOnly Interactive"); 
    mapinfo.Do("Open Table \"E:\\Capitals.tab\" ReadOnly Interactive"); 
    mapinfo.Do("Open Table \"E:\\China.tab\" ReadOnly Interactive"); 
	sprintf(str,"Set Next Document Parent %lu Style 2 ",(long)(UINT)m_hWnd); 
	mapinfo.Do(str);//创建地图窗口 
/*设置地图窗口的图层,由最上一层开始是中国疆域,各省疆域,省会城市,并标注上省会城市的名字*/ 
	mapinfo.Do("Map From Capitals, Province, China"); 
	mapinfo.Do("Set Map Layer 1 Label With Capital_Character_Name Parallel On Auto On Visibility On"); 
 
//获取地图窗口的ID号和句柄 
	m_lWindowid = atol(mapinfo.Eval("WindowID(0)"));	//窗口ID 
	sprintf(str,"WindowInfo(0, %u)", WIN_INFO_WND);	//窗口HWND 
	m_hWindowHwnd = (HWND)atol(mapinfo.Eval(str)); 
//调整地图窗口尺寸,将地图窗口放置在右半屏上 
	sprintf(str, 
		"Set Window %lu Position (8.3,0) Width 8.4 Height 6.05  ScrollBars Off SysMenuClose Off", m_lWindowid); 
	mapinfo.Do(str); 
//调整地图窗口视野和中心点 
	double m_dView_center_x=113.35;	//地图窗口中心点,经纬度 
	double m_dView_center_y=35.04; 
	double 	m_dView_zoom = 4000.0;	//地图窗口视野,"km" 
	sprintf(str,"Set Map Window %lu Zoom %lf Units \"km\" Center (%lf,%lf) XY Units \"degree\"",  m_lWindowid,m_dView_zoom,m_dView_center_x,m_dView_center_y); 
	mapinfo.Do(str);//设置地图窗口中心点窗口视野 
//设置地图窗口漫游缩放的右键菜单 
	mapinfo.Do("Create Menu \"MapshellShortcut\" ID 17 as \"漫游\" calling 1702,\"缩小\" calling 1706, \"放大\" calling 1705 ,\"(-\""); 
//创建实时航迹显示图层 
	mapinfo.Do("Create Table plane (ID Integer) File \"E:\\plane.tab\" "); 
	mapinfo.Do("Create Map For plane"); 
	sprintf(str,"Add Map Window %lu Layer plane Animate",m_lWindowid); 
	mapinfo.Do(str);			 //实时航迹图层设置为快速刷新 
 
	/////////////////定义mapinfo中所用的变量 
	mapinfo.Do("Dim obj1 As Object");	//飞机图标点对象 
	mapinfo.Do("Dim Line1 As Object");	//航迹线对象 
	global_num = 0;			//接收目标数据计数初始化为0 
	 
} 
 
void CMapAppView::OnReceiveData(WPARAM m_Wparam, LPARAM m_lparam) 
{ 
//接收数据处理 
	 
	NETDATA *m_pxy = (NETDATA *)m_lparam; 
 
	global_long_last = global_long;//上一点经度 
	global_lat_last = global_lat; 
 
	global_long = m_pxy->x;//经度,当前点 
	global_lat= m_pxy->y;//纬度 
	ShowMapLine(); 
} 
 
void CMapAppView::ShowMapLine()  
{ 
	char str[256]; 
//画飞机图标 
	double m_angle = COPI*atan2((global_lat - global_lat_last), 
			(global_long - global_long_last))-90;//目标角度 
	sprintf(str, 
		"Create Point Into Variable obj1 (%lf,%lf) Symbol (85,255,30,\"MapInfo Transportation\",0,%lf)",	 
		global_long, global_lat, m_angle); 	//设置飞机目标显示的样式 
	mapinfo.Do(str);	//创建目标图标对象 
	if (global_num >0 ) 
	{/*收到的第一点,在plane表中插入第一条记录,后面的点都是更新第一条记录*/ 
		sprintf(str,  
			"Update plane Set Obj = obj1 Where RowID = %lu",1);} 
	else {  
		sprintf(str, 
			"Inset Into plane (ID,Obj) Values (%lu,Line1) ", global_num); 
	} 
	mapinfo.Do(str);//用obj1对象更新表中的记录 
//画各设备的航迹 
	sprintf(str, 
		"Create Line Into  Variable Line1 (%lf,%lf) (%lf,%lf) Pen MakePen(2,2,255)", 
		global_long_last,	global_lat_last	,	global_long,		global_lat); 
	mapinfo.Do(str);//创建line1对象 
	if (global_num >0 ) 
	{//第一个点不画航迹 
		sprintf(str,"Fetch Last From plane"); 
		mapinfo.Do(str); 
		//插入line1到表中 
		sprintf(str,"Insert Into plane (ID,Obj) Values (%lu,Line1)",global_num); 
		mapinfo.Do(str); 
	} 
	global_num ++; 
}