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

📄 gpsset.cpp

📁 用VC开发的GPS监控跟踪软件,已经调试过,并在实际中使用,现与大家共享
💻 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(dx<OFFSETTEST&&dy<OFFSETTEST) return TRUE;
	else return FALSE;

}

/////////////////////////////////////////////////////////////////////////////
// CGpsSetArray

IMPLEMENT_DYNCREATE(CGpsSetArray, CCmdTarget)

CGpsSetArray::CGpsSetArray()
{
}

CGpsSetArray::~CGpsSetArray()
{
}


BEGIN_MESSAGE_MAP(CGpsSetArray, CCmdTarget)
	//{{AFX_MSG_MAP(CGpsSetArray)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGpsSetArray message handlers

void CGpsSetArray::AddTarget(CGpsSet *target)
{
	m_ObjectList.Add((CObject*)target);

}

CGpsSet* CGpsSetArray::GetTarget(int nIndex)
{
   return (CGpsSet*)m_ObjectList[nIndex];
}

void CGpsSetArray::DeleteAllTarget()
{
	for(int i=0;i<m_ObjectList.GetSize();i++)
		 delete m_ObjectList[i];

	m_ObjectList.RemoveAll();

}

void CGpsSetArray::Run()
{
		for(int i=0;i<m_ObjectList.GetSize();i++)
		{
			CGpsSet* pTarget=GetTarget(i);
			pTarget->Run();
		}
}

void CGpsSetArray::UpdateGraph(CMapXLayer &layer)
{
		for(int i=0;i<m_ObjectList.GetSize();i++)
		{
			CGpsSet* pTarget=GetTarget(i);
			pTarget->UpdateGraph(layer);
		}

}


CGpsSet* CGpsSetArray::HitTest(double X, double Y,CMapX* pMapX)
{
		for(int i=0;i<m_ObjectList.GetSize();i++)
		{
			CGpsSet* pTarget=GetTarget(i);
			if(pTarget->HitTest(X,Y,pMapX))
				return pTarget;
		}
		return NULL;
}

void CGpsSetArray::SetActiveTarget(CGpsSet *pTarget)
{
	m_pActiveTarget=pTarget;

}

CGpsSet* CGpsSetArray::GetActiveTarget()
{
    return m_pActiveTarget;
}

⌨️ 快捷键说明

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