Mapx开发实例---vc++ gps跟踪

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;

    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;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值