📄 map.c
字号:
#include "map.h"
#include<time.h>
#include "gps.h"
EXPORT int widthzoom=1.0;
EXPORT void zoom(double zm)
{
m_fMaxCX*=zm;
m_fMaxCY*=zm;
widthzoom*=zm;
}
void setScope(){
//当前地图最大显示范围(直角坐标)
m_fMaxCX=(m_fMapjw[1]-m_fMapjw[0])*13104.0*4;
m_fMaxCY=(m_fMapjw[2]-m_fMapjw[3])*13104.0*4;
}
void initialize(){
point=NULL;pline=NULL;region=NULL;
m_fMapjw[0]=150.908708;
m_fMapjw[1]=70.917421;
m_fMapjw[2]=20.237505;
m_fMapjw[3]=60.230218;
jingdu=0.0;
weidu=0.0;
}
void setOffset(double x, double y){
long cx,cy;
ConvToXY(x, y, &cx, &cy);
offsetx=cx-160;
offsety=cy-120;
}
void getKeyword1(FILE* file,char* str) {
int n=0;char ch;
while((ch=fgetc(file))!=EOF){
if(isspace(ch))
break;
str[n++]=ch;
}
str[n]='\0';
}
void getMapUnit(char* fileAddr)
{
FILE *file,*mid;char str[128],ch,temp[10];int n,i,j,tmp;POINTDB* points;double x,y;//long cx,cy;
double m_fMinX=0.0,m_fMaxX=0.0,m_fMinY=0.0,m_fMaxY=0.0;
int sl;char* midAddr,*tmp_name;
MAPPOINT* temp_point;
MAPPLINE* temp_pline;
MAPREGION* temp_region;
sl=strlen(fileAddr);
midAddr = (char*)malloc(sizeof(char)*(sl+1));
strcpy(midAddr, fileAddr) ;
midAddr[sl-1]='d';
if((file = fopen(fileAddr,"r"))==NULL)
return;
if((mid = fopen(midAddr,"r"))==NULL)
return;
char_num=20;
tmp_name = (char*)malloc(sizeof(char)*20);
while(!feof(file))
{
getKeyword1(file,str);
//解析PLINE
if(strcmp(str,"Pline")==0){
//int n,i=0,j;double x;char ch,temp[10];int tmp;
temp_pline=(MAPPLINE*)malloc(sizeof(MAPPLINE));
(*temp_pline).next=pline;
getKeyword1(file,str);
n=atoi(str);
(*temp_pline).num=n;
maxpoints = maxpoints > n ? maxpoints : n;
points=(POINTDB*)malloc(sizeof(POINTDB)*n);
(*temp_pline).points=points;
for(i=0;i<n;i++){
getKeyword1(file,str);
getKeyword1(file,str);
x=atof(str);
getKeyword1(file,str);
y=atof(str);
//ConvToXY(x, y, &cx, &cy);
(*points).x=x;
(*points).y=y;
points++;
if(i==0){
m_fMinX = x;
m_fMaxX = x;
m_fMinY = y;
m_fMaxY = y;
}else{
m_fMinX = m_fMinX < x ? m_fMinX : x;
m_fMaxX = m_fMaxX > x ? m_fMaxX : x;
m_fMinY = m_fMinY < y ? m_fMinY : y;
m_fMaxY = m_fMaxY > y ? m_fMaxY : y;
}
}
//给个图元的最小经纬与最大经纬
(*temp_pline).min.x=m_fMinX;
(*temp_pline).min.y=m_fMinY;
(*temp_pline).max.x=m_fMaxX;
(*temp_pline).max.y=m_fMaxY;
//整幅地图最小经纬与最大经纬
m_fMapjw[0] = m_fMapjw[0] < m_fMinX ? m_fMapjw[0] : m_fMinX;
m_fMapjw[1] = m_fMapjw[1] > m_fMaxX ? m_fMapjw[1] : m_fMaxX;
m_fMapjw[2] = m_fMapjw[2] > m_fMaxY ? m_fMapjw[2] : m_fMaxY;
m_fMapjw[3] = m_fMapjw[3] < m_fMinY ? m_fMapjw[3] : m_fMinY;
//-----get pen-------
while(strcmp(str,"Pen")!=0)
getKeyword1(file,str);
getKeyword1(file,str);
i=1,j=0;
while(((ch=str[i])-',')!=0){
temp[j]=ch;
i++;j++;
}
temp[j]='\0';
tmp=atoi(temp);
(*temp_pline).pen.width=tmp;
j=0;i++;
while(((ch=str[i])-',')!=0){
temp[j]=ch;
i++;j++;
}
temp[j]='\0';
tmp=atoi(temp);
(*temp_pline).pen.pattern=tmp;
j=0;i++;
while(((ch=str[i])-')')!=0){
temp[j]=ch;
i++;j++;
}
temp[j]='\0';
tmp=atoi(temp);
(*temp_pline).pen.color=tmp;
//读取mid中内容
if(mid!=NULL){
fgets(tmp_name, char_num,mid);
}
(*temp_pline).name=(char*)malloc(sizeof(char)*20);
strcpy((*temp_pline).name,tmp_name);
pline=temp_pline;
}
//解析POINT
else if(strcmp(str,"Point")==0){
temp_point=(MAPPOINT*)malloc(sizeof(MAPPOINT));
(*temp_point).next=point;
fgetc(file);
getKeyword1(file,str);
x=atof(str);
getKeyword1(file,str);
y=atof(str);
//ConvToXY(x, y, &cx, &cy);
(*temp_point).x=x;
(*temp_point).y=y;
//整幅地图最小经纬与最大经纬
m_fMapjw[0] = m_fMapjw[0] < x ? m_fMapjw[0] : x;
m_fMapjw[1] = m_fMapjw[1] > x ? m_fMapjw[1] : x;
m_fMapjw[2] = m_fMapjw[2] > y ? m_fMapjw[2] : y;
m_fMapjw[3] = m_fMapjw[3] < y ? m_fMapjw[3] : y;
//读取mid中内容
if(mid!=NULL){
fgets(tmp_name, char_num,mid);
}
(*temp_point).name=(char*)malloc(sizeof(char)*20);
strcpy((*temp_point).name,tmp_name);
point=temp_point;
}
//解析REGION
else if(strcmp(str,"Region")==0){
//int n,i=0;double x;int j;char ch,temp[10];int tmp,brush_i;double tmp_xy;
temp_region=(MAPREGION*)malloc(sizeof(MAPREGION));
(*temp_region).next=region;
getKeyword1(file,str);
getKeyword1(file,str);
getKeyword1(file,str);
getKeyword1(file,str);
getKeyword1(file,str);
getKeyword1(file,str);
n=atoi(str);
(*temp_region).num=n;
maxpoints = maxpoints > n ? maxpoints : n;
points=(POINTDB*)malloc(sizeof(POINTDB)*n);
(*temp_region).points=points;
for(i=0;i<n;i++){
getKeyword1(file,str);
getKeyword1(file,str);
x=atof(str);
getKeyword1(file,str);
y=atof(str);
//ConvToXY(x, y, &cx, &cy);
(*points).x=x;
(*points).y=y;
points++;
if(i==0){
m_fMinX = x;
m_fMaxX = x;
m_fMinY = y;
m_fMaxY = y;
}else{
m_fMinX = m_fMinX < x ? m_fMinX : x;
m_fMaxX = m_fMaxX > x ? m_fMaxX : x;
m_fMinY = m_fMinY < y ? m_fMinY : y;
m_fMaxY = m_fMaxY > y ? m_fMaxY : y;
}
}
//给个图元的最小经纬与最大经纬
(*temp_region).min.x=m_fMinX;
(*temp_region).min.y=m_fMinY;
(*temp_region).max.x=m_fMaxX;
(*temp_region).max.y=m_fMaxY;
//整幅地图最小经纬与最大经纬
m_fMapjw[0] = m_fMapjw[0] < m_fMinX ? m_fMapjw[0] : m_fMinX;
m_fMapjw[1] = m_fMapjw[1] > m_fMaxX ? m_fMapjw[1] : m_fMaxX;
m_fMapjw[2] = m_fMapjw[2] > m_fMaxY ? m_fMapjw[2] : m_fMaxY;
m_fMapjw[3] = m_fMapjw[3] < m_fMinY ? m_fMapjw[3] : m_fMinY;
//-----get pen------
while(strcmp(str,"Pen")!=0)
getKeyword1(file,str);
getKeyword1(file,str);
i=1,j=0;
while(((ch=str[i])-',')!=0){
temp[j]=ch;
i++;j++;
}
temp[j]='\0';
tmp=atoi(temp);
//(*region_pen).width=tmp;
(*temp_region).pen.width=tmp;
j=0;i++;
while(((ch=str[i])-',')!=0){
temp[j]=ch;
i++;j++;
}
temp[j]='\0';
tmp=atoi(temp);
//(*region_pen).pattern=tmp;
(*temp_region).pen.pattern=tmp;
j=0;i++;
while(((ch=str[i])-')')!=0){
temp[j]=ch;
i++;j++;
}
temp[j]='\0';
tmp=atoi(temp);
//(*region_pen).color=tmp;
(*temp_region).pen.color=tmp;
//--------get brush--------
while(strcmp(str,"Brush")!=0)
getKeyword1(file,str);
getKeyword1(file,str);
i=1,j=0;
while(((ch=str[i])-',')!=0){
temp[j]=ch;
i++;j++;
}
temp[j]='\0';
tmp=atoi(temp);
//(*region_brush).pattern=tmp;
(*temp_region).brush.pattern=tmp;
j=0;i++;
while(((ch=str[i])-',')!=0){
temp[j]=ch;
i++;j++;
}
temp[j]='\0';
tmp=atoi(temp);
//(*region_brush).forecolor=tmp;
(*temp_region).brush.forecolor=tmp;
j=0;i++;
while(((ch=str[i])-')')!=0){
temp[j]=ch;
i++;j++;
}
temp[j]='\0';
tmp=atoi(temp);
//(*region_brush).backcolor=tmp;
(*temp_region).brush.backcolor=tmp;
//---------get center--------
while(strcmp(str,"Center")!=0)
getKeyword1(file,str);
getKeyword1(file,str);
x=atof(str);
getKeyword1(file,str);
y=atof(str);
(*temp_region).center.x=x;
(*temp_region).center.y=y;
//读取mid中内容
if(mid!=NULL){
fgets(tmp_name, char_num,mid);
}
(*temp_region).name=(char*)malloc(sizeof(char)*20);
strcpy((*temp_region).name,tmp_name);
int len=strlen((*temp_region).name);
(*temp_region).name[len-2]='\0';
region=temp_region;
}
else if(strcmp(str,"Line")==0||strcmp(str,"Arc")==0||
strcmp(str,"Ellipse")==0||strcmp(str,"Text")==0||
strcmp(str,"Rectangle")==0){
//读取mid中内容
if(mid!=NULL){
fgets(tmp_name, char_num,mid);
}
}
}
fclose(file);
setScope();
}
EXPORT void draw_map_line(MAPPLINE* pline,LPOINTSCR apt,BMP *p_bmp )
{
MAPPLINE* tpline=pline;
while(tpline!=NULL)
{
setOffset(jingdu, weidu);
ConvToXYs(apt, (*tpline).points,(*tpline).num);
XYsToDPs(apt,(*tpline).num);
int i;
for(i=0;i<(*tpline).num-1;i++)
{
draw_wide_line(apt[i].x, apt[i].y, apt[i+1].x, apt[i+1].y,(int)(widthzoom*((*tpline).pen.width)), (*tpline).pen.color,p_bmp );
}
tpline=(*tpline).next;
}
}
EXPORT void draw_map_region(MAPREGION* region,LPOINTSCR apt,BMP *p_bmp )
{
MAPREGION *tregion=region;
long x,y;
while(tregion!=NULL)
{
setOffset(jingdu, weidu);
ConvToXYs(apt, (*tregion).points,(*tregion).num);
XYsToDPs(apt,(*tregion).num);
FillPolygon(apt,(*tregion).num,(*tregion).brush.forecolor,p_bmp);
ConvToXY((*tregion).center.x, (*tregion).center.y, &x, &y);
XYsToDP(&x, &y);
drawtex_cn_16((*tregion).name,x,y,255,p_bmp);
tregion=(*tregion).next;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -