📄 mappershape.cpp
字号:
}
//text
SMsfShapeInfo msi;
mhi.iTexts=m_oaTexts.GetSize();
for(i=0;i<mhi.iTexts;i++)
{
msi.shape=7;
msi.color=m_oaTexts[i]->color;
msi.height=m_oaTexts[i]->height;
strcpy(msi.text,m_oaTexts[i]->text);
CMoPoints pts=m_oaTexts[i]->line->GetParts().Item(COleVariant((short)0));
msi.pts=pts.GetCount();
f.Write(&msi,sizeof(SMsfShapeInfo));
for(j=0;j<msi.pts;j++)
{
CMoPoint pt=pts.Item(COleVariant(j));;
mp.x=pt.GetX();
mp.y=pt.GetY();
f.Write(&mp,sizeof(SMapperPoint));
}
}
f.SeekToBegin();
f.Write(&mhi,sizeof(SMsfShapeInfo));
f.Close();
return TRUE;
}
BOOL CMapperShape::Read(CString sPathFile)
{
//sPathFile无后缀
CFile f;
if(f.Open(sPathFile,CFile::modeRead)!=IDOK)
{
AfxMessageBox("读文件失败!");
return FALSE;
}
short i,j;
SMapperPoint mp;
SMsfHeadInfo mhi;
mhi.mapper=20030701;
f.Read(&mhi,sizeof(SMsfHeadInfo));
if(mhi.mapper!=20030701)
{
AfxMessageBox("不是合法文件!");
return FALSE;
}
//point
for(i=0;i<mhi.iPoints;i++)
{
f.Read(&m_tPointInfo,sizeof(SMsfShapeInfo));
f.Read(&mp,sizeof(SMapperPoint));
//creat
CMoPoint* point = new CMoPoint();
point->CreateDispatch(TEXT("MapObjects2.Point"));
point->SetX(mp.x);
point->SetY(mp.y);
if (LPDISPATCH(point))
m_oaPoints.Add(point);
}
//line
for(i=0;i<mhi.iLines;i++)
{
f.Read(&m_tLineInfo,sizeof(SMsfShapeInfo));
CMoPoints pts;
pts.CreateDispatch(TEXT("MapObjects2.Points"));
for(j=0;j<m_tLineInfo.pts;j++)
{
f.Read(&mp,sizeof(SMapperPoint));
CMoPoint pt;
pt.CreateDispatch(TEXT("MapObjects2.Point"));
pt.SetX(mp.x);
pt.SetY(mp.y);
pts.Add(pt);
pt.ReleaseDispatch();
}
//create
CMoLine* line = new CMoLine();
line->CreateDispatch(TEXT("MapObjects2.Line"));
line->GetParts().Add(pts);
if (LPDISPATCH(line))
m_oaLines.Add(line);
pts.ReleaseDispatch();
}
//rect
for(i=0;i<mhi.iRects;i++)
{
f.Read(&m_tRectInfo,sizeof(SMsfShapeInfo));
CMoRectangle* rect = new CMoRectangle();
rect->CreateDispatch(TEXT("MapObjects2.Rectangle"));
f.Read(&mp,sizeof(SMapperPoint));
rect->SetLeft(mp.x);
rect->SetTop(mp.y);
f.Read(&mp,sizeof(SMapperPoint));
rect->SetRight(mp.x);
rect->SetBottom(mp.y);
if (LPDISPATCH(rect))
m_oaRects.Add(rect);
}
//Circle
for(i=0;i<mhi.iCircles;i++)
{
f.Read(&m_tCircleInfo,sizeof(SMsfShapeInfo));
CMoEllipse* circle = new CMoEllipse();
circle->CreateDispatch(TEXT("MapObjects2.Ellipse"));
f.Read(&mp,sizeof(SMapperPoint));
circle->SetLeft(mp.x);
circle->SetTop(mp.y);
f.Read(&mp,sizeof(SMapperPoint));
circle->SetRight(mp.x);
circle->SetBottom(mp.y);
if (LPDISPATCH(circle))
m_oaCircles.Add(circle);
}
//Ellipse
for(i=0;i<mhi.iEllipses;i++)
{
f.Read(&m_tEllipseInfo,sizeof(SMsfShapeInfo));
CMoEllipse* ellipse = new CMoEllipse();
ellipse->CreateDispatch(TEXT("MapObjects2.Ellipse"));
f.Read(&mp,sizeof(SMapperPoint));
ellipse->SetLeft(mp.x);
ellipse->SetTop(mp.y);
f.Read(&mp,sizeof(SMapperPoint));
ellipse->SetRight(mp.x);
ellipse->SetBottom(mp.y);
if (LPDISPATCH(ellipse))
m_oaEllipses.Add(ellipse);
}
//poly
for(i=0;i<mhi.iPolys;i++)
{
f.Read(&m_tPolyInfo,sizeof(SMsfShapeInfo));
CMoPoints pts;
pts.CreateDispatch(TEXT("MapObjects2.Points"));
for(j=0;j<m_tPolyInfo.pts;j++)
{
f.Read(&mp,sizeof(SMapperPoint));
CMoPoint pt;
pt.CreateDispatch(TEXT("MapObjects2.Point"));
pt.SetX(mp.x);
pt.SetY(mp.y);
pts.Add(pt);
pt.ReleaseDispatch();
}
//create
CMoPolygon* poly = new CMoPolygon();
poly->CreateDispatch(TEXT("MapObjects2.Polygon"));
poly->GetParts().Add(pts);
if (LPDISPATCH(poly))
m_oaPolys.Add(poly);
pts.ReleaseDispatch();
}
//text
SMsfShapeInfo msi;
for(i=0;i<mhi.iTexts;i++)
{
f.Read(&msi,sizeof(SMsfShapeInfo));
CMoPoints pts;
pts.CreateDispatch(TEXT("MapObjects2.Points"));
for(j=0;j<msi.pts;j++)
{
f.Read(&mp,sizeof(SMapperPoint));
CMoPoint pt;
pt.CreateDispatch(TEXT("MapObjects2.Point"));
pt.SetX(mp.x);
pt.SetY(mp.y);
pts.Add(pt);
pt.ReleaseDispatch();
}
SMapperTextInfo *text;
text=new SMapperTextInfo;
text->line=new CMoLine();
text->line->CreateDispatch(TEXT("MapObjects2.Line"));
text->line->GetParts().Add(pts);
text->color=msi.color;
text->height=msi.height;
strcpy(text->text,msi.text);
if (LPDISPATCH(text->line))
m_oaTexts.Add(text);
pts.ReleaseDispatch();
}
f.Close();
return TRUE;
}
BOOL CMapperShape::AddFromQuery(CMoMapLayer &layer,CMoRecordset &rs)
{
//保证rs有效
long type=layer.GetShapeType();
//可能有多个记录
rs.MoveFirst();
while(!rs.GetEof())
{
switch(type)
{
case moPoint:
{
CMoFields fields=rs.GetFields();
CMoField field(fields.Item(COleVariant(TEXT("SHAPE"))));
CMoPoint *pt=new CMoPoint;
pt->AttachDispatch(field.Get_Value().pdispVal);
if (LPDISPATCH(pt))
m_oaPoints.Add(pt);
}
break;
case moLine:
{
CMoFields fields=rs.GetFields();
CMoField field(fields.Item(COleVariant(TEXT("SHAPE"))));
CMoLine *line=new CMoLine;
line->AttachDispatch(field.Get_Value().pdispVal);
if (LPDISPATCH(line))
m_oaLines.Add(line);
}
break;
case moPolygon:
{
CMoFields fields=rs.GetFields();
CMoField field(fields.Item(COleVariant(TEXT("SHAPE"))));
CMoPolygon *poly=new CMoPolygon;
poly->AttachDispatch(field.Get_Value().pdispVal);
if (LPDISPATCH(poly))
m_oaPolys.Add(poly);
}
break;
}
rs.MoveNext();
}
return TRUE;
}
void CMapperShape::Pan(double dx, double dy)
{
if((m_tSel.type==-1)||(m_tSel.index==-1))
return;
switch(m_tSel.type)
{
case 1://
{
m_oaPoints[m_tSel.index]->SetX(m_oaPoints[m_tSel.index]->GetX()+dx);
m_oaPoints[m_tSel.index]->SetY(m_oaPoints[m_tSel.index]->GetY()+dy);
}
break;
case 2://
{
short i;
long j;
SMapperPoint mp;
CArray<SMapperPoint,SMapperPoint> m_taPoint;
for(i=0;i<m_oaLines[m_tSel.index]->GetParts().GetCount();i++)
{
CMoPoints pts=m_oaLines[m_tSel.index]->GetParts().Item(COleVariant(i));
for(j=0;j<pts.GetCount();j++)
{
mp.x=pts.Item(COleVariant(j)).GetX();
mp.y=pts.Item(COleVariant(j)).GetY();
m_taPoint.Add(mp);
}
}
//删除原来对象,重新建立
m_oaLines[m_tSel.index]->ReleaseDispatch();
delete m_oaLines[m_tSel.index];
m_oaLines.RemoveAt(m_tSel.index);
//新建立对象有两个位置可以放置:原始位置,需要插入;末尾,需要设置选择索引
//原位置
CMoLine* line = new CMoLine();
line->CreateDispatch(TEXT("MapObjects2.Line"));
CMoPoint pt;
CMoPoints pts;
pt.CreateDispatch(TEXT("MapObjects2.Point"));
pts.CreateDispatch(TEXT("MapObjects2.Points"));
for(j=0;j<m_taPoint.GetSize();j++)
{
pt.SetX(m_taPoint[j].x+dx);
pt.SetY(m_taPoint[j].y+dy);
pts.Add(pt);
}
line->GetParts().Add(pts);
if (LPDISPATCH(line))
m_oaLines.InsertAt(m_tSel.index,line);
}
break;
case 3:
{
double m_dX=m_oaRects[m_tSel.index]->GetLeft();
double m_dY=m_oaRects[m_tSel.index]->GetTop();
double m_dWidth=m_oaRects[m_tSel.index]->GetWidth();
double m_dHeight=m_oaRects[m_tSel.index]->GetHeight();
//删除原来对象,重新建立
m_oaRects[m_tSel.index]->ReleaseDispatch();
delete m_oaRects[m_tSel.index];
m_oaRects.RemoveAt(m_tSel.index);
//新建立对象有两个位置可以放置:原始位置,需要插入;末尾,需要设置选择索引
//原位置
CMoRectangle* rect= new CMoRectangle();
rect->CreateDispatch(TEXT("MapObjects2.Rectangle"));
rect->SetLeft(m_dX+dx);
rect->SetTop(m_dY+dy);
rect->SetRight(m_dX+dx+m_dWidth);
rect->SetBottom(m_dY+dy-m_dHeight); //数据轴向上
if (LPDISPATCH(rect))
m_oaRects.InsertAt(m_tSel.index,rect);
}
break;
case 4:
{
double m_dX=m_oaCircles[m_tSel.index]->GetLeft();
double m_dY=m_oaCircles[m_tSel.index]->GetTop();
double m_dWidth=m_oaCircles[m_tSel.index]->GetWidth();
double m_dHeight=m_oaCircles[m_tSel.index]->GetHeight();
//删除原来对象,重新建立
m_oaCircles[m_tSel.index]->ReleaseDispatch();
delete m_oaCircles[m_tSel.index];
m_oaCircles.RemoveAt(m_tSel.index);
//新建立对象有两个位置可以放置:原始位置,需要插入;末尾,需要设置选择索引
//原位置
CMoEllipse* circle= new CMoEllipse();
circle->CreateDispatch(TEXT("MapObjects2.Ellipse"));
circle->SetLeft(m_dX+dx);
circle->SetTop(m_dY+dy);
circle->SetRight(m_dX+dx+m_dWidth);
circle->SetBottom(m_dY+dy-m_dWidth); //数据轴向上
if (LPDISPATCH(circle))
m_oaCircles.InsertAt(m_tSel.index,circle);
}
break;
case 5:
{
double m_dX=m_oaEllipses[m_tSel.index]->GetLeft();
double m_dY=m_oaEllipses[m_tSel.index]->GetTop();
double m_dWidth=m_oaEllipses[m_tSel.index]->GetWidth();
double m_dHeight=m_oaEllipses[m_tSel.index]->GetHeight();
//删除原来对象,重新建立
m_oaEllipses[m_tSel.index]->ReleaseDispatch();
delete m_oaEllipses[m_tSel.index];
m_oaEllipses.RemoveAt(m_tSel.index);
//新建立对象有两个位置可以放置:原始位置,需要插入;末尾,需要设置选择索引
//原位置
CMoEllipse* ellipse= new CMoEllipse();
ellipse->CreateDispatch(TEXT("MapObjects2.Ellipse"));
ellipse->SetLeft(m_dX+dx);
ellipse->SetTop(m_dY+dy);
ellipse->SetRight(m_dX+dx+m_dWidth);
ellipse->SetBottom(m_dY+dy-m_dHeight); //数据轴向上
if (LPDISPATCH(ellipse))
m_oaEllipses.InsertAt(m_tSel.index,ellipse);
}
break;
case 6:
{
short i;
long j;
SMapperPoint mp;
CArray<SMapperPoint,SMapperPoint> m_taPoint;
for(i=0;i<m_oaPolys[m_tSel.index]->GetParts().GetCount();i++)
{
CMoPoints pts=m_oaPolys[m_tSel.index]->GetParts().Item(COleVariant(i));
for(j=0;j<pts.GetCount();j++)
{
mp.x=pts.Item(COleVariant(j)).GetX();
mp.y=pts.Item(COleVariant(j)).GetY();
m_taPoint.Add(mp);
}
}
//删除原来对象,重新建立
m_oaPolys[m_tSel.index]->ReleaseDispatch();
delete m_oaPolys[m_tSel.index];
m_oaPolys.RemoveAt(m_tSel.index);
//新建立对象有两个位置可以放置:原始位置,需要插入;末尾,需要设置选择索引
//原位置
CMoPolygon* poly= new CMoPolygon();
poly->CreateDispatch(TEXT("MapObjects2.Polygon"));
CMoPoint pt;
CMoPoints pts;
pt.CreateDispatch(TEXT("MapObjects2.Point"));
pts.CreateDispatch(TEXT("MapObjects2.Points"));
for(j=0;j<m_taPoint.GetSize();j++)
{
pt.SetX(m_taPoint[j].x+dx);
pt.SetY(m_taPoint[j].y+dy);
pts.Add(pt);
}
poly->GetParts().Add(pts);
if (LPDISPATCH(poly))
m_oaPolys.InsertAt(m_tSel.index,poly);
}
break;
case 7:
{
SMapperPoint mp;
CArray<SMapperPoint,SMapperPoint> m_taPoint;
CMoPoints pts=m_oaTexts[m_tSel.index]->line->GetParts().Item(COleVariant((short)0));
mp.x=pts.Item(COleVariant((short)0)).GetX();
mp.y=pts.Item(COleVariant((short)0)).GetY();
m_taPoint.Add(mp);
mp.x=pts.Item(COleVariant((short)1)).GetX();
mp.y=pts.Item(COleVariant((short)1)).GetY();
m_taPoint.Add(mp);
//删除原来对象,重新建立
m_oaTexts[m_tSel.index]->line->ReleaseDispatch();
delete m_oaTexts[m_tSel.index]->line;
//新建立对象有两个位置可以放置:原始位置,需要插入;末尾,需要设置选择索引
//原位置
m_oaTexts[m_tSel.index]->line= new CMoLine();
m_oaTexts[m_tSel.index]->line->CreateDispatch(TEXT("MapObjects2.Line"));
CMoPoint pt;
pt.CreateDispatch(TEXT("MapObjects2.Point"));
CMoPoints pts1;
pts1.CreateDispatch(TEXT("MapObjects2.Points"));
pt.SetX(m_taPoint[0].x+dx);
pt.SetY(m_taPoint[0].y+dy);
pts1.Add(pt);
pt.SetX(m_taPoint[1].x+dx);
pt.SetY(m_taPoint[1].y+dy);
pts1.Add(pt);
m_oaTexts[m_tSel.index]->line->GetParts().Add(pts1);
}
break;
}
}
BOOL CMapperShape::QueryFromShape(CMap1 &map,CMoMapLayer &layer, CMoRecordset &rs)
{
if((m_tSel.type==-1)||(m_tSel.index==-1))
{
AfxMessageBox("需要选择一个图形对象!");
return FALSE;
}
switch(m_tSel.type)
{
case 1:
rs=layer.SearchByDistance(*m_oaPoints[m_tSel.index] ,0.0, TEXT(""));
break;
case 2:
rs= layer.SearchShape(*m_oaLines[m_tSel.index], moAreaIntersect, TEXT(""));
break;
case 3:
rs= layer.SearchShape(*m_oaRects[m_tSel.index], moAreaIntersect, TEXT(""));
break;
case 4:
// rs= layer.SearchShape(*m_oaCircles[m_tSel.index], moAreaIntersect, TEXT(""));
// break;
// case 5:
// rs= layer.SearchShape(*m_oaEllipses[m_tSel.index], moAreaIntersect, TEXT(""));
AfxMessageBox("不支持此类型对象查询!");
return FALSE;
break;
case 6:
rs= layer.SearchShape(*m_oaPolys[m_tSel.index], moAreaIntersect, TEXT(""));
break;
}
VARIANT va;
VariantInit(&va);
va.vt = VT_NULL;
map.GetTrackingLayer().Refresh(true,va);
return TRUE;
}
BOOL CMapperShape::HadSel()
{
if((m_tSel.type==-1)||(m_tSel.index==-1))
return FALSE;
else
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -