#include "stdafx.h"
#include "MapViewView.h"
#include "GpsSet.h"
#include "math.h"
#include "Mapx.h"
/////////////////////////////////////////////////////////////////////////////
// CGpsSet
CGpsSet::CGpsSet()
{
//StartX=0.0;
//StartY=0.0;
//dSpeed=2000;
//dDirectory=0;
m_dCX=0;
m_dCY=0;
m_dOldCX = 0;//上一次位置X坐标
m_dOldCY = 0;//上一次位置Y坐标
m_nFeaID=-1;
m_nUnitID=-1;
}
CGpsSet::~CGpsSet()
{
}
/////////////////////////////////////////////////////////////////////////////
// CGpsSet
CGpsSet::CGpsSet(CGpsSet& temp)
{
this->m_dCX = temp.m_dCX;
this->m_dCY = temp.m_dCY;
this->m_dOldCX = temp.m_dOldCX;
this->m_dOldCY = temp.m_dOldCY;
this->m_dDirectory = temp.m_dDirectory;
this->m_nFeaID = temp.m_nFeaID;
this->m_nUnitID = temp.m_nUnitID;
}
//CGpsSet& operator = (const CGpsSet &temp);
CGpsSet& CGpsSet::operator = (const CGpsSet &temp)
{
if (this == &temp)
{
return *this;
}
this->m_dCX = temp.m_dCX;
this->m_dCY = temp.m_dCY;
this->m_dOldCX = temp.m_dOldCX;
this->m_dOldCY = temp.m_dOldCY;
this->m_dDirectory = temp.m_dDirectory;
this->m_nFeaID = temp.m_nFeaID;
this->m_nUnitID = temp.m_nUnitID;
return *this;
}
//void CGpsSet::SetStartXY(double X, double Y)
//{
// StartX=X;
// StartY=Y;
//}
void CGpsSet::UpdateGraph(CMapXLayer &layer)
{
if (m_nFeaID == -1)
{
//AddFeature()
return;
}
else
{
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);
m_dOldCX = m_dCX;
m_dOldCY = m_dCY;
feature.SetPoint(point.m_lpDispatch);
feature.Update();
CMapXStyle style=feature.GetStyle();
if(style.GetSymbolFontRotation()!=(short)m_dDirectory)
{
style.SetSymbolFontRotation((short)m_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)
{
CMapXFeature mapxFeature;
CMapXPoint pnt;
COleVariant pntVt;
CMapXStyle tempStyle;
COleVariant tempStyleVt;
pnt.CreateDispatch(pnt.GetClsid());
tempStyle.CreateDispatch(tempStyle.GetClsid());
tempStyle = pMapX->GetDefaultStyle();
//double temp = m_ctrlMapX.GetCenterY();
pnt.Set(m_dCX,m_dCY);
pntVt.vt = VT_DISPATCH;
pntVt.pdispVal = pnt.m_lpDispatch;
pntVt.pdispVal->AddRef();
CY fontSize;
fontSize.int64 =720000;
mapxFeature.CreateDispatch(mapxFeature.GetClsid());
mapxFeature.Attach(pMapX->GetDispatch());
mapxFeature.SetType(miFeatureTypeSymbol);
//mapxFeature.SetStyle(tempStyle);
CString strFontName;
strFontName = tempStyle.GetSymbolFont().GetName();
short sFontIndex;
sFontIndex = tempStyle.GetSymbolCharacter();
tempStyle.GetSymbolFont().SetName(strFontName);
tempStyle.GetSymbolFont().SetSize(fontSize);
tempStyle.SetSymbolFontRotation((short)m_dDirectory);//tempStyle.SetSymbolFontRotation()
tempStyle.SetSymbolFontColor(255);
tempStyle.SetSymbolCharacter(sFontIndex+1);
//style.SetSymbolFontRotation((short)dDirectory);
tempStyleVt.vt = VT_DISPATCH;
tempStyleVt.pdispVal = tempStyle.m_lpDispatch;
tempStyleVt.pdispVal->AddRef();
mapxFeature = pMapX->GetFeatureFactory().CreateSymbol (pntVt,tempStyleVt);
mapxFeature = layer.AddFeature( mapxFeature );
m_nFeaID = mapxFeature.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_objGpsSetList.Add(target);
}
CGpsSet CGpsSetArray::GetTarget(int nIndex)
{
return m_objGpsSetList.GetAt(nIndex);
}
void CGpsSetArray::SetTarget(int nIndex,CGpsSet target)
{
m_objGpsSetList.SetAt(nIndex,target);
}
int CGpsSetArray::GetTargetIndexByUnitID(int nUnitID)
{
//return (CGpsSet*)m_ObjectList[nUnitID];
int nSize = m_objGpsSetList.GetSize();
for(int i=0;i<nSize;i++)
{
CGpsSet temp = m_objGpsSetList.GetAt(i);
if (temp.m_nUnitID == nUnitID)
return i;
}
return -1;
}
void CGpsSetArray::DeleteAllTarget()
{
//for(int i=0;i<m_ObjectList.GetSize();i++)
// delete m_ObjectList[i];
m_objGpsSetList.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_objGpsSetList.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;
//}