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

📄 gpsdrawmap.cpp

📁 用VC写的监控中心后台程序。 代码全
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	POSITION	pos;

	CarPath += GetCarByDirection(Course);
	CarMap.LoadFromFile(CarPath);

//refresh Prev Car...
	pos = mSaveRecePointList.GetHeadPosition();
	if(pos != NULL) {
		mSaveRecePointList.GetNext(pos);
		if(pos != NULL) {
			pPoint = (CGpsPoint*)mSaveRecePointList.GetNext(pos);
			if(pPoint != NULL) {
				cRect.left	 = pPoint->m_lx - CarMap.Width () / 2;
				cRect.right	 = pPoint->m_lx + CarMap.Width () / 2;
				cRect.top	 = pPoint->m_ly - CarMap.Height() / 2;
				cRect.bottom = pPoint->m_ly + CarMap.Height() / 2;
				RedrawInvalidRect(cRect,pDC,false);
			}
		}
	}

//Draw Car...
	pPoint = (CGpsPoint*)mSaveRecePointList.GetHead();
	if(pPoint != NULL) {
		cRect.left	 = pPoint->m_lx - CarMap.Width () / 2;
		cRect.right	 = pPoint->m_lx + CarMap.Width () / 2;
		cRect.top	 = pPoint->m_ly - CarMap.Height() / 2;
		cRect.bottom = pPoint->m_ly + CarMap.Height() / 2;

		RedrawInvalidRect(cRect,pDC,true);

		CarMap.DrawTransparentInRect(*pDC,0,&cRect,NULL,0);		//装入汽车位图
		CPoint	point;
		point.x	= pPoint->m_lx;
		point.y	= pPoint->m_ly;
		DrawStr(pDC,point,strVehicleNO);
	}
	CarMap.Clear();
#else
	CString		CarName,CarPath;
	CBmpProc	CarMap;
	CGpsPoint	*pPoint = NULL;
	CRect		cRect;
	POSITION	pos;

	CarPath += GetCarByDirection(Course);
	CarMap.LoadFromFile(CarPath);

//refresh Prev Car...
/*	pos = mSaveRecePointList.GetHeadPosition();
	if(pos != NULL) {
		mSaveRecePointList.GetNext(pos);
		if(pos != NULL) {
			pPoint = (CGpsPoint*)mSaveRecePointList.GetNext(pos);
			if(pPoint != NULL) {
				ErasePrevPoint(pDC,pPoint->m_lx,pPoint->m_ly);
			}
		}
	}
*/
//Draw Car...
	pos  = mSaveRecePointList.GetTailPosition();
	while(pos != NULL) {
		pPoint = (CGpsPoint*)mSaveRecePointList.GetPrev(pos);
		if(pPoint != NULL) {
			cRect.left	 = pPoint->m_lx - CarMap.Width () / 2;
			cRect.right	 = pPoint->m_lx + CarMap.Width () / 2;
			cRect.top	 = pPoint->m_ly - CarMap.Height() / 2;
			cRect.bottom = pPoint->m_ly + CarMap.Height() / 2;

			RedrawInvalidRect(cRect,pDC,true);

			CarMap.DrawTransparentInRect(*pDC,0,&cRect,NULL,0);		//装入汽车位图
			CPoint	point;
			point.x	= pPoint->m_lx;
			point.y	= pPoint->m_ly;
			if(!pPoint->m_sVehicleNO.IsEmpty()) {
				DrawStr(pDC,point,pPoint->m_sVehicleNO);
			}
		}
	}
	CarMap.Clear();
#endif
}

void CGpsDrawMap::MoveScrollBar(long x,long y)
{
	CGpsSCView		*pView = ((CGpsSCView*)m_pCurrView);
	CSize			scrollsize = pView->GetTotalSize();
	int				hscrollpos[5],vscrollpos[4];

	for(int i=0;i<5;i++)
		hscrollpos[i] =	scrollsize.cx/5*(i+1);// - scrollsize.cx/15;
	for(i=0;i<4;i++)
		vscrollpos[i]=	scrollsize.cy/4*(i+1);// - scrollsize.cy/15 ;

	if(x>=hscrollpos[0]&& x<=hscrollpos[1])
		pView->SetScrollPos(SB_HORZ,hscrollpos[0],TRUE);
	else if(x>hscrollpos[1]&& x<=hscrollpos[2])
		pView->SetScrollPos(SB_HORZ,hscrollpos[1],TRUE);
	else if(x>hscrollpos[2]&& x<=hscrollpos[3])
		pView->SetScrollPos(SB_HORZ,hscrollpos[2],TRUE);
	else if(x>hscrollpos[3]&& x<=hscrollpos[4])
		pView->SetScrollPos(SB_HORZ,hscrollpos[3],TRUE);
	else if(x>hscrollpos[4]&& x<=hscrollpos[5])
		pView->SetScrollPos(SB_HORZ,hscrollpos[4],TRUE);
	else
		pView->SetScrollPos(SB_HORZ,0,TRUE);

	if(y>=vscrollpos[0] && y<=vscrollpos[1])
		pView->SetScrollPos(SB_VERT,vscrollpos[0]);
	else if(y>vscrollpos[1] && y<=vscrollpos[2])
		pView->SetScrollPos(SB_VERT,vscrollpos[1]);
	else if(y>vscrollpos[2] && y<=vscrollpos[3])
		pView->SetScrollPos(SB_VERT,vscrollpos[2]);
	else if(y>vscrollpos[3] && y<=vscrollpos[4])
		pView->SetScrollPos(SB_VERT,vscrollpos[3]);
	else
		pView->SetScrollPos(SB_VERT,0,TRUE);
}

/***********Draw icon***********/
void CGpsDrawMap::DrawIcon(CDC *pDC,CPoint point,CString IconName)
{
	CRect		cRect;
	CString		IconPath;
	CBmpProc	IconMap;

	IconMap.LoadFromFile(IconName);

	cRect.top	 = point.y - IconMap.Height() / 2;
	cRect.bottom = point.y + IconMap.Height() / 2;
	cRect.left	 = point.x - IconMap.Width () / 2;
	cRect.right	 = point.x + IconMap.Width () / 2;
	
	IconMap.DrawTransparentInRect(*pDC,0,&cRect,NULL,0);		//装入标志物图标
}

//在NE中国范围内即为有效
BYTE CGpsDrawMap::IsValidNE(double gx,double gy)
{
	double		MinN,MinE,MaxN,MaxE;
	BYTE		Invalid = 0;

	MinN	= 7310.0000;	MinE	= 6060.0080;
	MaxN	= 13530.0000;	MaxE	= 1810.0000;
	if(((gx - MinN >= 0.0) && (gx - MaxN <= 0.0)) &&
	   ((gy - MinE <= 0.0) && (gy - MaxE >= 0.0))) {
		Invalid = 1;
	}

	return Invalid;
}

void CGpsDrawMap::GetView(CView *pView)
{
	m_pCurrView = pView;
}

void CGpsDrawMap::FreshWnd()
{
	((CGpsSCView*)m_pCurrView)->Invalidate();
}

BYTE CGpsDrawMap::CheckMapIsChange(double gx,double gy)
{
	CGpsLinkStruct	cLink;
	BYTE			IsChange;

	if(!IsValidNE(gx,gy))	return 0;
	if(!GetCurrLinkLib(&mLinkList,&cLink,gx,gy))	return 0;

	if(CompareTwoArr(cLink.m_LinkLibName,m_cCurrMapInfo.m_LinkFileName) != 1) {
		IsChange = 1;
		GetCurrMapInfo(&cLink,&m_cCurrMapInfo);

		((CGpsSCView*)m_pCurrView)->m_bMapIsDrawed = false;
		((CGpsSCView*)m_pCurrView)->Invalidate();
	}
	else {
		IsChange = 0;
		((CGpsSCView*)m_pCurrView)->Invalidate();
	}

	return IsChange;
}

void CGpsDrawMap::ClearSaveInvalidRectColor()
{
	BYTE	i,j;

	for(i = 0; i < 40; i++) {
		for(j = 0; j < 40; j++) {
			SaveInvalidRectColor[i][j] = 0;
		}
	}
}

void CGpsDrawMap::ReCalcPointXY(CObList *PointList)
{
	CGpsPoint	*pPoint = NULL;
	POSITION	pos;

	pos = PointList->GetTailPosition();
	while(pos != NULL) {
		pPoint = (CGpsPoint*)PointList->GetPrev(pos);
		CovertNEXY(pPoint, m_cCurrMapInfo.CoeffNE_XY, true);
	}
}

//Draw Fat Map ...
void CGpsDrawMap::DrawFatMap(CDC *pDC)
{
	CGpsLinkStruct	cLink;

	RefreshMapWnd();

	if(!GetDataLib(m_cCurrMapInfo.m_DataFileName))	return ;
	m_cCurrMapInfo.ClearSignList();
	GetSignLib(m_cCurrMapInfo.m_SignFileName,&m_cCurrMapInfo.lCurrSignList);

	ReDraw(pDC);

//	ClearPointList(&mSaveRecePointList);
	ReCalcPointXY(&mSaveRecePointList);
	ClearSaveInvalidRectColor();
}

void CGpsDrawMap::DrawSignLib(CDC *pDC)
{
	CGpsSignObject	*pSign;
	POSITION		pos;
	CString			SignName;
	CPoint			point;

	pos  = m_cCurrMapInfo.lCurrSignList.GetTailPosition();
	while(pos != NULL) {
		pSign  = (CGpsSignObject*)m_cCurrMapInfo.lCurrSignList.GetPrev(pos);
		if((pSign->m_bySignType == m_ShowSign.bShowBuilding) ||
		   (pSign->m_bySignType == m_ShowSign.bShowHotel)    ||
	       (pSign->m_bySignType == m_ShowSign.bShowCompany)  ||
		   (pSign->m_bySignType == m_ShowSign.bShowAmuse)    ||
		   (pSign->m_bySignType == m_ShowSign.bShowPlaceName)||
		   (pSign->m_bySignType == m_ShowSign.bShowGovern)   ||
		   (pSign->m_bySignType == m_ShowSign.bShowTraffic)  ||
		   (pSign->m_bySignType == m_ShowSign.bShowShopping) ||
		   (pSign->m_bySignType == m_ShowSign.bShowEducation)||
		   (pSign->m_bySignType == m_ShowSign.bShowHospital) ||
		   (pSign->m_bySignType == m_ShowSign.bShowBureau)   ||
		   (pSign->m_bySignType == m_ShowSign.bShowOil)) {
//			if(!pSign->m_bDraw)	continue;
			SignName = pSign->m_pSignObjectName;
			point.x = pSign->m_lx;	point.y = pSign->m_ly;
			DrawIcon(pDC,point,pSign->m_sIconName);
			DrawStr(pDC,point,SignName);
		}
	}
}


void CGpsDrawMap::DrawOneSignPoint(CDC *pDC)
{
//	if(pDispOneSign == NULL)	return;

	CString			SignName;
	CPoint			point;

	SignName = pDispOneSign.m_pSignObjectName;
	point.x = pDispOneSign.m_lx;	point.y = pDispOneSign.m_ly;

	DrawIcon(pDC,point,pDispOneSign.m_sIconName);
	DrawStr(pDC,point,SignName);
}

void CGpsDrawMap::ReDraw(CDC *pDC)
{
	DrawColorBlock(&m_cCurrMapInfo.lCurrColorBList,pDC);

	DrawRoad(&m_cCurrMapInfo.lCurrRoadList,pDC);

	DrawRoadName(&m_cCurrMapInfo.lCurrRoadList,pDC);
}


void CGpsDrawMap::SwapTwoVar(long &a, long &b)
{
	long	SwapVar;

	SwapVar = a;
	a = b;
	b = SwapVar;
}

BYTE CGpsDrawMap::PointOnLineNE(long SY, long SX, long EY, long EX, long NY, long NX, long K)
{
    long		W, H;
    long		MaxN, MaxE, MinN, MinE;

    W = abs(SX - EX);
    H = abs(SY - EY);

    if (H > W)	{
		/* Y-majored */
		MaxN = Max(SY, EY);
		MinN = Min(SY, EY);
		MaxE = Max(SX, EX) + K;
		MinE = Min(SX, EX) - K;
    }
    else {
		/* X-majored */
		MaxN = Max(SY, EY) + K;
		MinN = Min(SY, EY) - K;
		MaxE = Max(SX, EX);
		MinE = Min(SX, EX);
    }

    return (NX > MinE && NX < MaxE && NY > MinN && NY < MaxN);
}

long CGpsDrawMap::DistanceToLine(long SY, long SX, long EY, long EX, long NY, long NX)
{
    long		W, H, Ha, dY, f;

    /*
     ** always draws from small X to large X
     */


    if (SX > EX) {
		SwapTwoVar(SX, EX);
		SwapTwoVar(SY, EY);
    }

    /*
     ** we might want to clip the line here
     */
    W = (EX - SX);
    H = (EY - SY);
    Ha = (H < 0) ? -H : H;
    dY = (H < 0) ? -1 : 1;

    if (Ha > W) {
		if (NY > Max(SY, EY) || NY < Min(SY, EY))	return GPS_INFINITE;
    }
    else {
		if (NX > Max(SX, EX) || NX < Min(SX, EX))	return GPS_INFINITE;
    }

    if (Ha > W)	{
	/* Y-majored */
		f = 0;
		while (1) {
			if (SY == NY) {
				return ((long)abs(SX - NX));
			}
			if (SY == EY)
				break;
			if ((f += W) >= Ha)	{
				f -= Ha;
				SX++;
			}
			SY += dY;
		}
    }
	else {
		/* X-majored */
		f = 0;
		while (1) {
			if (SX == NX) {
				return ((long)abs(SY - NY));
			}
			if (SX == EX)
				break;
			if ((f += Ha) >= W)	{
				f -= W;
				SY += dY;
			}
			SX++;
		}
    }

    return GPS_INFINITE;
}

long CGpsDrawMap::CalcPointToOneRoadDist(CPoint point,CSmallRoadStruct *pSmall)
{
	CRoadPoint			*pRoadPoint;
	CPoint				sp,ep;
	POSITION			pos;
	long				d,Dist = GPS_INFINITE;
	bool				Flag = false;

	pos	= pSmall->RoadPointList.GetTailPosition();
	while(pos != NULL) {
		pRoadPoint = (CRoadPoint*)pSmall->RoadPointList.GetPrev(pos);
		ep.x	= pRoadPoint->m_lx; ep.y = pRoadPoint->m_ly;
		if(!Flag) {
			Flag = true;
			sp = ep;
			continue;
		}
		if(!PointOnLineNE(sp.y,sp.x,ep.y,ep.x,point.y,point.x,100))	continue;
		d	= DistanceToLine(sp.y,sp.x,ep.y,ep.x,point.y,point.x);
		if(d < Dist) {
			Dist = d;
		}
		sp	= ep;
	}

	return Dist;
}

CString CGpsDrawMap::SearchRoad(const CPoint point,CString &RoadSn)
{
	CSmallRoadStruct	*pSmall;
	CGpsRoadStruct		*pRoad;
	POSITION			pos,pos1;
	CString				RoadName(""),Name;
	long				d,Dist = GPS_INFINITE;

	pos = m_cCurrMapInfo.lCurrRoadList.GetTailPosition();
	while(pos != NULL) {
		pRoad  = (CGpsRoadStruct*)m_cCurrMapInfo.lCurrRoadList.GetPrev(pos);
		pos1   = pRoad->SmallRoadList.GetTailPosition();
		while(pos1 != NULL) {
			pSmall	= (CSmallRoadStruct*)pRoad->SmallRoadList.GetPrev(pos1);
			Name = pSmall->RoadName;
			if(Name.IsEmpty())	continue;
			d = CalcPointToOneRoadDist(point,pSmall);
			if(d < Dist) {
				Dist = d;
				RoadName = Name;
			}
		}
	}

	return RoadName;
}

CString CGpsDrawMap::GetMapInfoByNE(double gx,double gy,BYTE SignType,BYTE InfoType)
{
	CString			RelatedInfo("没有找到相关信息!");

	if(InfoType == 2) {
		return RelatedInfo;
	}

	if(!IsValidNE(gx,gy))	return RelatedInfo;

	CGpsSignObject	*pSign = NULL,*pMin = NULL;
	POSITION		pos;
	CGpsPoint		cPoint;
	CPoint			p1,p2;
	CString			SignName,RoadName,RoadSn;
	long			Dist = GPS_INFINITE,d;
	bool			Flag;

	cPoint.m_dgx	= gx;
	cPoint.m_dgy	= gy;
	CovertNEXY(&cPoint, m_cCurrMapInfo.CoeffNE_XY, true);
	p1.x = cPoint.m_lx;	p1.y = cPoint.m_ly;

	Flag = false;
	pos  = m_cCurrMapInfo.lCurrSignList.GetTailPosition();
	while(pos != NULL) {
		pSign  = (CGpsSignObject*)m_cCurrMapInfo.lCurrSignList.GetPrev(pos);
		if((pSign->m_bySignType != SignType) && (SignType != 0))	continue;
		if((abs(pSign->m_lx - cPoint.m_lx) < 100) && 
		   (abs(pSign->m_ly - cPoint.m_ly) < 100)) {
			p2.x = pSign->m_lx; p2.y = pSign->m_ly;
			d = CalcTwoPointDist(p1,p2);
			if(d < Dist) {
				Dist = d;
				SignName = pSign->m_pSignObjectName;
				Flag = true;
				pMin = pSign;
			}
		}
	}
	if(Flag) pMin->m_bDraw = true;

	RoadName = SearchRoad(p1,RoadSn);

	if(Flag && (!RoadName.IsEmpty())) {
		RelatedInfo.Format("您现在在%s,%s附近!",RoadName,SignName);
	}
	else if(Flag) {
		RelatedInfo.Format("您现在在%s附近!",SignName);
	}
	else if(!RoadName.IsEmpty()) {
		R

⌨️ 快捷键说明

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