www.pudn.com > HPMapx.rar > gpsset.cpp


// gpsset.cpp 
 
#include "stdafx.h" 
#include "gpsset.h" 
#include "../HPMapx.h" 
 
const int   NZOOM	= 2; 
 
CGpsSet::CGpsSet() 
{ 
	m_dCX		= 0; 
	m_dCY		= 0; 
	m_nFeaID	= 0; 
	m_dSpeed	= 0; 
	m_dDirection	= 0; 
} 
 
void CGpsSet::OnSize(UINT nType, int cx, int cy)  
{ 
	CWnd::OnSize(nType, cx, cy); 
	 
	if (	cx != 0 && cy != 0 &&  
		m_ctrlMapX.GetSafeHwnd()) 
 
	m_ctrlMapX.MoveWindow(0,0,cx,cy,TRUE); 
} 
 
void CGpsSet::OnSetFocus(CWnd* pO) 
{	 
	CWnd::OnSetFocus(pO); 
 
	if(m_ctrlMapX.GetSafeHwnd()) 
	m_ctrlMapX.SetFocus(); 
} 
 
BOOL CGpsSet::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)  
{ 
	CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext); 
 
	TRY 
	{ 
		if( !m_ctrlMapX.Create(NULL,WS_VISIBLE,CRect(0,0,0,0),this ,IDC_MAP) ) 
		{ 
			MessageBox(_T("应用程序错误,请联系开发单位"),_T("错误"),MB_ICONSTOP|MB_OK); 
			return false; 
		} 
		 
		m_ctrlMapX.SetGeoSet( _T("\\Program Files\\MapInfo\\HPMapx\\Maps\\Qingdao22.gst") ); 
		m_ctrlMapX.GetTitle().SetVisible(FALSE); 
		OnPan(); 
		OnViewScalebar(); 
		m_ctrlMapX.SetAutoRedraw(TRUE); 
		m_ctrlMapX.CreateCustomTool(MY_INFOTOOL, miToolTypePoint,miInfoCursor ); 
		m_ctrlMapX.CreateCustomTool(MAP_DISTANCE,miToolTypePoly, miCrossCursor); 
		m_ctrlMapX.CreateCustomTool(ADD_TARGET,  miToolTypePoly, miCrossCursor); 
		m_ctrlMapX.SetPreferCompactLegends(TRUE); 
	} 
	CATCH (COleDispatchException,e)  
	{ 
		MessageBox(_T("应用程序错误,请联系开发单位"),_T("错误"),MB_ICONSTOP|MB_OK); 
		return FALSE; 
	} 
	AND_CATCH (COleException,e)  
	{ 
		MessageBox(_T("应用程序错误,请联系开发单位"),_T("错误"),MB_ICONSTOP|MB_OK); 
		return FALSE; 
	} 
	END_CATCH 
 
	return TRUE; 
} 
 
void CGpsSet::ZoomTo() 
{ 
	TRY 
	{ 
		float sX,sY,scnX,scnY; 
		 
		double x = m_ctrlMapX.GetCenterX(); 
		double y = m_ctrlMapX.GetCenterY(); 
 
		double ScreenX = m_ctrlMapX.GetMapScreenWidth() /3; 
		double ScreenY = m_ctrlMapX.GetMapScreenHeight() /3; 
 
		m_ctrlMapX.ConvertCoord(&sX,&sY,&m_dCX,&m_dCY,miMapToScreen); 
		m_ctrlMapX.ConvertCoord(&scnX,&scnY,&x,&y,miMapToScreen); 
 
		if(	fabs( sX - scnX ) > ScreenX ||  
			fabs( sY - scnY ) > ScreenY ) 
			m_ctrlMapX.ZoomTo(m_ctrlMapX.GetZoom() ,m_dCX,m_dCY); 
	} 
	CATCH (COleDispatchException,e)  
	{ 
	} 
	AND_CATCH (COleException,e)  
	{ 
	} 
	END_CATCH 
} 
 
#define __D(x) (double)##x 
void CGpsSet::UpdateDirection(CMapXFeature &feature) 
{ 
	double d=m_dDirection; 
	CString strFileName; 
	 
	if( d == __D(0 ) ) 
		return; 
 
	TRY 
	{ 
 
	//	m_ctrlMapX.SetRotation(m_dDirection); 
	//	m_ctrlMapX.SetAutoRedraw(TRUE); 
 
		     if(d > __D(20)  && d < __D( 40) )	strFileName =L"Car120.bmp"; 
		else if(d > __D(50)  && d < __D( 70) )	strFileName =L"Car150.bmp"; 
		else if(d > __D(80)  && d < __D(100) )	strFileName =L"Car180.bmp"; 
		else if(d > __D(110) && d < __D(130) )	strFileName =L"Car210.bmp"; 
		else if(d > __D(140) && d < __D(160) )	strFileName =L"Car240.bmp"; 
		else if(d > __D(170) && d < __D(190) )	strFileName =L"Car270.bmp"; 
		else if(d > __D(200) && d < __D(220) )	strFileName =L"Car300.bmp"; 
		else if(d > __D(230) && d < __D(250) )	strFileName =L"Car330.bmp"; 
		else if(d > __D(260) && d < __D(280) )	strFileName =L"Car0.bmp"; 
		else if(d > __D(290) && d < __D(310) )	strFileName =L"Car30.bmp"; 
		else if(d > __D(320) && d < __D(340) )	strFileName =L"Car60.bmp"; 
		else					strFileName =L"Car90.bmp"; 
 
		feature.GetStyle().SetSymbolBitmapName(strFileName); 
	} 
	CATCH (COleDispatchException,e)  
	{ 
	} 
	AND_CATCH (COleException,e)  
	{ 
	} 
	END_CATCH 
} 
 
void CGpsSet::UpdateFeature(CMapXFeature &feature) 
{ 
	TRY 
	{ 
		UpdateDirection(feature); 
		feature.GetPoint().Set( m_dCX, m_dCY); 
		feature.Update(); 
		ZoomTo(); 
	} 
	CATCH (COleDispatchException,e)  
	{ 
	} 
	AND_CATCH (COleException,e)  
	{ 
	} 
	END_CATCH 
} 
 
void CGpsSet::SetStartXY(double x,double y) 
{ 
	TRY 
	{ 
		int	nxDegree = (int)(x/double(100)), 
			nyDegree = (int)(y/double(100)); 
 
		m_dCX = nxDegree + ( x/double(100) - nxDegree )* 100 / 60; 
		m_dCY = nyDegree + ( y/double(100) - nyDegree )* 100 / 60; 
 
		if(  ! FindLayer( L"CarLayer") ) 
		{ 
			m_ctrlMapX.GetLayers().SetAnimationLayer( 
			m_ctrlMapX.GetLayers().CreateLayer( L"CarLayer",NULL,1) ); 
		} 
 
		if(  ! m_nFeaID ) 
		{ 
			CMapXFeature m_CurFeature; 
			m_CurrentCarLayer.SetEditable(TRUE); 
			m_CurFeature.CreateDispatch(m_CurFeature.GetClsid()); 
			m_CurFeature.Attach( m_ctrlMapX.GetDispatch()); 
			m_CurFeature.GetStyle().SetSymbolType(miSymbolTypeBitmap); 
			m_CurFeature.GetStyle().SetSymbolBitmapSize(16); 
			m_CurFeature.GetStyle().SetSymbolBitmapTransparent(TRUE); 
			m_CurFeature.GetStyle().SetSymbolBitmapName(L"Car.bmp"); 
			m_CurFeature.GetPoint().Set( m_dCX, m_dCY); 
			m_CurFeature = m_CurrentCarLayer.AddFeature(m_CurFeature); 
			m_nFeaID = m_CurFeature.GetFeatureID(); 
			m_ctrlMapX.ZoomTo(NZOOM,m_dCX,m_dCY); 
		} 
	} 
	CATCH (COleDispatchException,e)  
	{ 
		e->ReportError(); 
	} 
	AND_CATCH (COleException,e)  
	{ 
		e->ReportError(); 
	} 
	END_CATCH 
} 
 
bool CGpsSet::FindLayer(CString strLayerName) 
{ 
	TRY 
	{ 
		CMapXLayer  mLayer; 
		CMapXLayers layers= m_ctrlMapX.GetLayers(); 
		for(int i=0;i