www.pudn.com > VC+MapX5.0+GPS.rar > GpsSet.cpp


// GpsSet.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "MapDemo.h" 
#include "GpsSet.h" 
#include "math.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CGpsSet 
#define OFFSETTEST   5 
IMPLEMENT_DYNCREATE(CGpsSet, CCmdTarget) 
 
CGpsSet::CGpsSet() 
{ 
	StartX=0.0; 
	StartY=0.0; 
	dSpeed=2000; 
	dDirectory=0; 
	m_dCX=0; 
	m_dCY=0; 
	strName="GPS"; 
	m_nFeaID=0; 
	 
} 
 
CGpsSet::~CGpsSet() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CGpsSet, CCmdTarget) 
	//{{AFX_MSG_MAP(CGpsSet) 
		// NOTE - the ClassWizard will add and remove mapping macros here. 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CGpsSet message handlers 
 
void CGpsSet::Serialize(CArchive& ar)  
{ 
	if (ar.IsStoring()) 
	{	// storing code 
	} 
	else 
	{	// loading code 
	} 
} 
 
void CGpsSet::SetStartXY(double X, double Y) 
{ 
	StartX=X; 
	StartY=Y; 
 
} 
 
void CGpsSet::UpdateGraph(CMapXLayer &layer) 
{ 
	UpdateFeature(layer.GetFeatureByID(m_nFeaID)); 
} 
 
void CGpsSet::UpdateFeature(CMapXFeature &feature) 
{ 
 
	CMapXPoint point; 
	point.CreateDispatch(point.GetClsid());	//Creates a dispatch for the point 
	point.Set(m_dCX,m_dCY);  
	feature.SetPoint(point.m_lpDispatch); 
	feature.Update(); 
	CMapXStyle style=feature.GetStyle(); 
	if(style.GetSymbolFontRotation()!=(short)dDirectory) 
	{ 
		style.SetSymbolFontRotation((short)dDirectory); 
		feature.SetStyle(style.m_lpDispatch); 
		feature.Update(); 
 
	} 
 
} 
 
CMapXFeature CGpsSet::FindFeature(CMapXLayer &layer) 
{ 
	 
 
	return layer.GetFeatureByID(m_nFeaID); 
 
 
} 
 
void CGpsSet::AddFeature(CMapX* pMapX,CMapXLayer &layer) 
{ 
	CMapXPoint point; 
	point.CreateDispatch(point.GetClsid()); 
	CMapXFeatureFactory cFactory=pMapX->GetFeatureFactory(); 
	point.Set(StartX,StartY); 
 
 
	m_dCX=StartX; 
	m_dCY=StartY; 
 
 
	COleVariant vtPoint; 
	vtPoint.vt = VT_DISPATCH; 
	vtPoint.pdispVal = point.m_lpDispatch; 
	vtPoint.pdispVal->AddRef();	 
	 
 
	CMapXStyle style=layer.GetStyle(); 
 
	style.SetSymbolFontRotation((short)dDirectory); 
    COleVariant vtstyle; 
	vtstyle.vt = VT_DISPATCH; 
	vtstyle.pdispVal = style.m_lpDispatch; 
	vtstyle.pdispVal->AddRef();	 
 
	CMapXFeature feature=cFactory.CreateSymbol(vtPoint,vtstyle);  
     
	layer.AddFeature(feature); 
	 
 
	CMapXFeatures features=layer.AllFeatures(); 
 
	CMapXFeature fea=features.Item(features.GetCount()); 
	 
	m_nFeaID=fea.GetFeatureID();  
 
 
    layer.SetKeyField("Name");   
	fea.SetKeyValue(strName);	 
	fea.Update(); 
 
	CString strValue; 
	 
 
 
    layer.SetKeyField("StartX");   
	strValue.Format(_T("%10.5f"),StartX); 
	fea.SetKeyValue(strValue);	 
    fea.Update(); 
	 
	layer.SetKeyField("StartY");   
	strValue.Format(_T("%10.5f"),StartY); 
	fea.SetKeyValue(strValue);	 
    fea.Update(); 
 
	layer.SetKeyField("·½Ïò");   
	strValue.Format(_T("%10.5f"),dDirectory); 
	fea.SetKeyValue(strValue);	 
    fea.Update(); 
 
	layer.SetKeyField("ËÙ¶È");   
	strValue.Format(_T("%10.5f"),dSpeed); 
	fea.SetKeyValue(strValue); 
	fea.Update(); 
 
} 
 
void CGpsSet::Run() 
{ 
	double dx,dy; 
	dx=dSpeed*sin(dDirectory*0.01745329)*3/(3600*60); 
	dy=dSpeed*cos(dDirectory*0.01745329)*3/(3600*60); 
	 
	m_dCX=m_dCX+dx; 
	m_dCY=m_dCY+dy; 
 
} 
 
BOOL CGpsSet::HitTest(double x, double y,CMapX* pMapX) 
  
{ 
     
	float sX,sY; 
	pMapX->ConvertCoord(&sX,&sY,&m_dCX,&m_dCY,miMapToScreen); 
	double dx=fabs((double)sX-x); 
	double dy=fabs((double)sY-y); 
 
	if(dxRun(); 
		} 
} 
 
void CGpsSetArray::UpdateGraph(CMapXLayer &layer) 
{ 
		for(int i=0;iUpdateGraph(layer); 
		} 
 
} 
 
 
CGpsSet* CGpsSetArray::HitTest(double X, double Y,CMapX* pMapX) 
{ 
		for(int i=0;iHitTest(X,Y,pMapX)) 
				return pTarget; 
		} 
		return NULL; 
} 
 
void CGpsSetArray::SetActiveTarget(CGpsSet *pTarget) 
{ 
	m_pActiveTarget=pTarget; 
 
} 
 
CGpsSet* CGpsSetArray::GetActiveTarget() 
{ 
    return m_pActiveTarget; 
}