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

📄 ddlayerfiles.cpp

📁 这是一个在vxWorks操作系统下的原创电子地图代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
							if(pdx == partIdex[ii])
							{
								MDL_CDrawPloyline(gc, ploylinepnum, pp);
								jj = 0;
								ploylinepnum = 0;
							}
						}
						}*/
						pPoint = pPoint->NextPoint;							
					}while(pPoint != NULL);	
					/*free(partIdex);*/
					/*if(pRecord->NumParts == 1)            /* 04-10-29 noted by yyb
					{
						MDL_CDrawPloyline(gc, pRecord->NumPoints, pp);
					}*/
					/*printf(" drawline\n");*/
					MDL_CDrawPloyline(display, jj, pp);      /*added by yyb 11-10*/
					/*printf("enddrawline\n");*/
					pdx= idx = ii = jj = 0; 
					pRecord = pRecord->NextRecord;
				}while(pRecord!= NULL);
				break;
			case 5:
				headRecord = pthis->firstRecord;
				pRecord = headRecord;
				if(headRecord != NULL)
				do
				{
					headPart = pRecord->firstParts;
					pPart = headPart;
					#ifdef emap_Mdl_Debug
				     		printf("pRecord->NumParts:%d \n", pRecord->NumParts);
				     		#endif
					if(pRecord->NumParts > 1)
					{
					#ifdef emap_Mdl_Debug
				     		printf("pRecord->NumParts:%d \n", pRecord->NumParts);
				     		#endif
					if(headPart !=NULL)
					{
						/*partIdex = (long *)malloc(sizeof(long) * pRecord->NumParts);*/
						
						do
						{
							partIdex[idx] = pPart->PartsIdx;
							idx++;
							pPart = pPart ->NextParts;
						}while(pPart != NULL);					
					}
					}
					
					headPoint = pRecord->firstPoints;
					pPoint = headPoint;
					if(headPoint != NULL)
					do
					{
 						
						if(!vxemap.manyou)
						{
						tmpx1 = (int)(zoom *((pPoint->x - fxmin) * okx));	
						tmpy1 = (int)(zoom*((fymax - pPoint->y)*oky));
						}
						else
						{
						tmpx1 = (int)(zoom *((pPoint->x - fxmin) * okx) + xmove);	
						tmpy1 = (int)(zoom*((fymax - pPoint->y)*oky) + ymove);
						}
						/*#ifdef emap_Mdl_Debug
						printf("x1: %d, y1: %d, x2: %d, y2:%d\n",tmpx1,tmpy1, tmpx2, tmpy2);
						#endif*/
						pp[jj].x = tmpx1; pp[jj].y = tmpy1; 
						ploygpointnum ++;
						pdx ++;
						jj++;
						
						/*if(pRecord->NumParts > 1)  /* noted by yyb 04-11-3
 						{
						for(ii =1; ii< pRecord->NumParts ; ii++)
						{
							if(pdx == partIdex[ii])
							{
								MDL_CDrawPloy(gc, ploygpointnum, pp);
								jj = 0;
								ploygpointnum = 0;
							}
						}
						}*/
						pPoint = pPoint->NextPoint;
					}while(pPoint != NULL);	
					/*free(partIdex);*/
					if(pRecord->NumParts == 1)
					{
						MDL_CDrawPloy(display,pRecord->NumPoints, pp);	
					}
					pdx=idx = ii = jj =0;
					pRecord = pRecord->NextRecord;
					/*if(pRecord->NumPoints < 3) /*2005- 9 -17 by yyb*/
					/*	break;      */
				}while(pRecord != NULL);
				
				#ifdef emap_Mdl_Debug
				printf("this map data dill compeletely\n!");
				#endif
				break;
		}
		pthis->IsDisplay = TRUE; /*04-11-2 added by yyb*/
		return(OK);
	}
	else
	{
		#ifdef emap_Mdl_Debug
			printf("this map layer  showed ERROR\n!");
		#endif
		return(ERROR);
	}
}


STATUS MDL_CDrawPloy(ZafDisplay *display, int pointNum, struct PointInt * points)/*绘制地图多边形*/
{
	
	int j, m, n;
	ZafCoordinate  pptts[6000];

	if((points == UGL_NULL) ||(pointNum < 3) || (pointNum > 3000))
	{
		#ifdef emap_Mdl_Debug
			printf("ploy ponitnum < 3 || no point || too many points ,don't show ployn\n!");
		#endif
		return(ERROR);
	}
	m = pointNum ;
	n = 2 * pointNum + 2;
	for(j=0; j<pointNum; j++){
		pptts[2 * j] = points[j].x; 
		pptts[2 * j +1] = points[j].y;
	}
	display->Polygon(m, pptts, 1, true, true);
//	display->Polygon(m, pptts, 1, true, true);
	#ifdef emap_Mdl_Debug
			printf("polygon draw ok!\n!");
		#endif
	return(OK);
}

STATUS MDL_CDrawPloyline(ZafDisplay *display, int pointNum, struct PointInt *points)
{
	int k, i;
	struct PointInt pts[3000];
	if((points == UGL_NULL) || (pointNum < 2))
	{
		/*printf("no points\n");*/
		return(ERROR);
	}
	for(i = 0; i < pointNum; i++)
	{
		pts[i] = points[i];
	}
	for(k=0; k<pointNum-1; k++)
	{
		/*if((vxemap.MapLeft < points[k].x) &&(points[k].y < vxemap.MapTop) &&
			(vxemap.MapLeft < points[k +1].x) &&(points[k +1].y < vxemap.MapTop))*/
		/*printf("point to point\n");*/
		display->Line(pts[k].x, pts[k].y, pts[k+1].x, pts[k+1].y);
	}
	return(OK);
}



int MDL_doxcoordinate(int x)
{
	int xresult;
	xresult = (int) (x * vxemap.mzoom + vxemap.mxmove);
	return xresult;
}

int MDL_doycoordinate(int y)
{
	int xresult;
	xresult = (int)(y * vxemap.mzoom + vxemap.mymove);
	return xresult;
}

int MDL_dofxcoordinate(double fx)
{
	int xresult;
	xresult = (int)(fx* vxemap.mzoom + vxemap.mxmove);
	return xresult;
}

int MDL_dofycoordinate(double fy)
{
	int xresult;
	xresult = (int)(fy * vxemap.mzoom + vxemap.mxmove);
	return xresult;
}



STATUS MSL_showMapLayer(ZafDisplay *display,	int layernumber )/*显示某一图层*/
{
	
	if(MDL_drawMapLayer( display, MapLayerNum[layernumber]) !=OK)
	{
		#ifdef emap_Msl_Debug
			printf("the map cann't  be showed maplayer %d !\n", layernumber);
		#endif
		return(ERROR);
	}
	else 
		{
		#ifdef emap_Msl_Debug
			printf("the map  showed maplayer %d  ok!\n", layernumber);
		#endif
		return(OK);
		}
}

ZafIChar* GetGBCode(char* str)
{
	int length=0;
	//ZafIChar string[100];
	
	for(int k=0;k<strlen(str);k++)
		{
			short unsigned int s=str[k];
			if(s>0x00a0)
			{
				//*string=*str;
				GBstring[length]=(str[k+1]<<8)+(str[k]&0x00ff);
				k++;				
			}
			else
			{
				GBstring[length]=str[k];
			}
			length++;
		}
	GBstring[length]=0x0000;
	return GBstring;
}
STATUS MSL_ShowMapText(ZafDisplay *display)
{
	int i, tmpx1, tmpy1;
	double fxmax, fxmin, fymax, fymin, fxwidth, fyheight;
	double okx, oky, zoom = 1, xmove = 0 , ymove = 0;
	struct Label *pt;

	if(vxemap.mzoom <1.30)
		return(ERROR);
	fxmin = vxemap.board.Left;	fxmax = vxemap.board.Width;		
	fymin = vxemap.board.Top;  fymax = vxemap.board.Height;
	zoom = vxemap.mzoom; xmove = vxemap.mxmove; ymove = vxemap.mymove;
	/*fxwidth = pthis->Board.Width; fyheight = pthis->Board.Height;*/	/*2005 - 10-10 by yb*/
	okx = vxemap.MapWidth/ (fxmax - fxmin); oky = vxemap.MapHeight/(fymax - fymin);
	if(okx < oky)
		oky = okx;
	else  okx = oky;
	display->SetFont(ZAF_FNT_SYSTEM);
	for(i = 0; i<3; i++)
	{
		pt = MapLabel[i];
		while(pt !=NULL)
		{
			tmpx1 =(int)(zoom *((pt->point->x - fxmin) * okx) + xmove);	
			tmpy1 =(int)(zoom*((fymax - pt->point->y)*oky) + ymove);
			//uglTextDrawW(gc, tmpx1, tmpy1, pt->length, pt->name);
			display->Text(tmpx1, tmpy1,GetGBCode(pt->name));
			pt = pt->NextLabel;
		}	
	}
	return(OK);	
}
STATUS MSL_draw1Round(ZafDisplay *display, int x, int y, int r)/*绘制一个标签圆,自定义属性*/
{
	int px =0, py= 0;
	
	px = MDL_doxcoordinate(x);
	py = MDL_doycoordinate(y);
//	uglEllipse(gc, px - r, py - r, px + r, py + r, 0, 0, 0, 0);
	return(OK);
}

STATUS MSL_setGcProperty(ZafDisplay *display, ZafLogicalColor fcolor, 
	ZafLogicalColor bcolor, ZafLogicalLineStyle linestyle)/*设置将要绘制的图形的属性,如前景色,背景色等等*/
{
	ZafLogicalColor pfcolor, pbcolor;
	ZafLogicalLineStyle  plinestyle;

	pfcolor = fcolor; pbcolor = bcolor; plinestyle = linestyle;

	if(pfcolor != -11)
		display->SetForeground(pfcolor);
	if(pbcolor != -11)
		display->SetBackground(pbcolor);
	if(plinestyle != -11)
		display->SetLineStyle(plinestyle);
//	if(plineWidth != -11)
//		uglLineWidthSet(gc, plineWidth);
	return(OK);
}

 STATUS MSL_ClearScreen(ZafDisplay *display, ZafRegionStruct windRec, ZafLogicalColor forColor, ZafLogicalColor backColor)
{
    display->SetBackground(backColor);
    display->SetForeground(forColor);
    /*uglLineStyleSet(gc, UGL_LINE_STYLE_SOLID);*/
    display->SetLineStyle(ZAF_LINE_SOLID);

    display->Rectangle(windRec.left, windRec.top , windRec.right , windRec.bottom, 4, true);
    return(OK);
}

STATUS MSL_DrawText(UGL_ID gc, int x, int y, int textlength, UGL_WCHAR * text)
{
	int px, py;
	
	px = MDL_doxcoordinate( x);
	py = MDL_doycoordinate( y);
//	uglTextDrawW(gc, px, py, textlength, text);
	return (OK);
}

void SetEmapViewRec(ZafRegionStruct windRec)
{
	vxemap.MapLeft = windRec.left;
	vxemap.MapTop = windRec.top;
	vxemap.MapWidth = windRec.right +100;
	vxemap.MapHeight = windRec.bottom +100;
}

void SetEmapView(int left, int top, int width, int height)
{
	vxemap.MapLeft = left;
	vxemap.MapTop = top;
	vxemap.MapWidth = width;
	vxemap.MapHeight = height;
}
void InitializeEmapLib(char *filePath)
{
    DDL_initMapGlobal();
    DDL_readMapFiles(filePath);
    DDL_readDbfFile(filePath);
    DDL_readLabelPoint(filePath);
}

void RedrawEmap(ZafDisplay * display, ZafRegionStruct windRec)
{
	int 		currentLayerNum = 0;
	currentLayerNum = MDL_getCurrentMapLayer();
	SetEmapViewRec(windRec);
	MSL_ClearScreen(display, windRec, ZAF_CLR_WHITE, ZAF_CLR_WHITE);
	if( (-1< currentLayerNum) && (currentLayerNum < 7) )
	{
		MSL_setGcProperty( display, ZAF_CLR_BROWN,ZAF_CLR_LIGHTCYAN ,ZAF_LINE_SOLID);
		MSL_showMapLayer(display, currentLayerNum);
	}
	else if (currentLayerNum == 7){
			 
			 MSL_setGcProperty( display, ZAF_CLR_MAGENTA, ZAF_CLR_WHITE, ZAF_LINE_SOLID);
			 MSL_showMapLayer(display, 0);
			 
			 MSL_setGcProperty( display, ZAF_CLR_RED, ZAF_CLR_YELLOW, ZAF_LINE_SOLID);
			 MSL_showMapLayer(display, 1);
			 
			 MSL_setGcProperty( display, ZAF_CLR_BROWN,ZAF_CLR_LIGHTCYAN ,-11);
			 MSL_showMapLayer(display, 2);

			 MSL_setGcProperty( display, ZAF_CLR_WHITE, ZAF_CLR_WHITE, ZAF_LINE_SOLID);
			 MSL_showMapLayer(display, 3);

			 MSL_setGcProperty( display, ZAF_CLR_WHITE, ZAF_CLR_WHITE, -11);
	 	 	 MSL_showMapLayer(display, 4);
			 
			 MSL_setGcProperty( display, ZAF_CLR_BROWN, ZAF_CLR_BLUE, -11);
			 MSL_showMapLayer(display, 5);

			 MSL_setGcProperty( display, ZAF_CLR_WHITE, ZAF_CLR_WHITE, -11);
			 MSL_showMapLayer(display, 6);
			 MSL_setGcProperty( display, ZAF_CLR_BLACK, ZAF_CLR_BLACK, ZAF_LINE_DASHED);
			 MSL_showMapLayer(display, 6);
			 //MSL_setGcProperty( display, ZAF_CLR_GREEN, ZAF_CLR_WHITE, ZAF_LINE_SOLID);
			 //MSL_ShowMapText(display);	
		}
	taskDelay(1);
}

/*关闭,,释放所有资源 */
STATUS EmapDestroy()
{
	int 		iii ;
	
	for(iii = 0;  iii++; iii < 7)
	{
		if(MapLayerNum[iii] != NULL)
		{
			DDL_destroyMapLayer(MapLayerNum[iii]);
		}			
	}

	for(iii = 0; iii++; iii < 3)
	{
		if(MapLabel[iii] != NULL)
		{
			DDL_destroyLabel(MapLabel[iii]);
		}
	}
	return 1;
}


}/*extern "C"*/



⌨️ 快捷键说明

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