本文共 10998 字,大约阅读时间需要 36 分钟。
1
link: http://blog.csdn.net/gm316/archive/2007/10/07/1813634.aspx
void CagGeometrys::AddTrack(CMapControlDefault &mc, hdcGeometryType gt,long button, long shift, long x, long y, double mapX, double mapY)
{
switch(gt)
{
case gt_Polyline:
{ /*
IPolylinePtr pl=mc.TrackLine();
IGeometryPtr *g=new IGeometryPtr;
(*g)=pl;
e_geos.insert(e_geos.end(),g);
*/
IActiveViewPtr av;
IScreenDisplayPtr sd;
av=mc.GetActiveView();
av->get_ScreenDisplay(&sd);
ISymbolPtr sym;
IGeometryPtr *geo=new IGeometryPtr;
IRubberBandPtr rp(__uuidof(RubberLine));
rp->TrackNew(sd,sym,&(*geo)); //应该可以在track就有symbol效果
e_geos.insert(e_geos.end(),geo);
//转换用QI,应该ok
//IPolylinePtr line;
//line=*geo;
}
break;
case gt_Circle:
{
case gt_Polygon:
{
case gt_Text_Point:
{
textInfo *ti=new textInfo;
IPointPtr pt(CLSID_Point);
pt->PutCoords(mapX,mapY);
ti->geo=pt;
IGetStringDialogPtr gsd(__uuidof(GetStringDialog));
short res;
gsd->DoModal(L"title",L"label",L"",NULL,&res);
CComBSTR bstr;
CString str;
gsd->get_Value(&bstr);
str=bstr;
strcpy(ti->text,str);
e_texts.insert(e_texts.end(),ti);
}
break;
case gt_Text_Polyline:
{
IGetStringDialogPtr gsd(__uuidof(GetStringDialog));
short res;
gsd->DoModal(L"title",L"label",L"",NULL,&res);
CComBSTR bstr;
CString str;
gsd->get_Value(&bstr);
str=bstr;
strcpy(ti->text,str);
e_texts.insert(e_texts.end(),ti);
}
break;
case gt_Text_Polygon:
{
textInfo *ti=new textInfo;
ti->geo=mc.TrackPolygon(); //可以模拟圆形,矩形等
IGetStringDialogPtr gsd(__uuidof(GetStringDialog));
short res;
gsd->DoModal(L"title",L"label",L"",NULL,&res);
CComBSTR bstr;
CString str;
gsd->get_Value(&bstr);
str=bstr;
strcpy(ti->text,str);
e_texts.insert(e_texts.end(),ti);
}
break;
}
IActiveViewPtr av=mc.GetActiveView();
av->Refresh();
}
void CagGeometrys::Draw(CMapControlDefault &mc)
{
{
IActiveViewPtr av=mc.GetActiveView();
IScreenDisplayPtr sd;
av->get_ScreenDisplay(&sd);
IEnvelopePtr env;
count=e_sels.size();
for(i=0;i<count;i++)
{
//文本
count=e_texts.size();
for(i=0;i<count;i++)
{
void CagGeometrys::HitTest(double x, double y)
{
IPointPtr qp(__uuidof(Point));
qp->PutCoords(x,y);
IPointPtr hp(__uuidof(Point));
double hd;
long hpi,hs;
short rs,h;
ht->HitTest(qp,5.0,esriGeometryPartBoundary,hp,&hd,&hpi,&hs,&rs,&h);
if(h==-1)
{
IPointPtr qp(__uuidof(Point));
qp->PutCoords(x,y);
IPointPtr hp(__uuidof(Point));
double hd;
long hpi,hs;
short rs,h;
ht->HitTest(qp,5.0,esriGeometryPartBoundary,hp,&hd,&hpi,&hs,&rs,&h);
if(h==-1)
{
case esriGeometryEnvelope:
case esriGeometryPolygon:
{
IRelationalOperatorPtr ro;
ro=e_geos[i];
short yes;
ro->Contains(qp,&yes);
if(yes==-1)
{
}
long CagGeometrys::GetSelectCount()
{
void CagGeometrys::ClearSelect()
{
BOOL CagGeometrys::DeleteSelect()
{
return TRUE;
}
void CagGeometrys::Move(CMapControlDefault &mc)
{
IScreenDisplayPtr sd;
av->get_ScreenDisplay(&sd);
ISymbolPtr sym;
IGeometryPtr geo=(*e_sels[0]);
IRubberBandPtr rb;
short c;
esriGeometryType gt;
// long i,count=e_sels.size();
// for(i=0;i<count;i++) 每次只可以移动一个shape
{
case esriGeometryEnvelope:
rb.CreateInstance(CLSID_RubberEnvelope); //移动后图形消失
// rb.CreateInstance(CLSID_RubberPolygon);//无效果
break;
case esriGeometryPolygon: //包括了circle
rb.CreateInstance(CLSID_RubberPolygon);
break;
}
}
if(rb!=NULL)
rb->TrackExisting(sd,sym,geo,&c);
av->Refresh();
}
BOOL CagGeometrys::AddImportPoint(CString sPathFile)
{
IPointCollectionPtr pc(__uuidof(Multipoint));
IPointPtr pt;
double x,y;
while(1)
{
if(e_bUnique)
e_geos.clear();
IGeometryPtr *g=new IGeometryPtr;
(*g)=pc;
e_geos.insert(e_geos.end(),g);
return TRUE;
}
BOOL CagGeometrys::AddImportPolyline(CString sPathFile)
{
double x,y;
IPointPtr pt;
IPointCollectionPtr pts(CLSID_Polyline);
while(1)
{
if(e_bUnique)
e_geos.clear();
IGeometryPtr *g=new IGeometryPtr;
(*g)=pts;
e_geos.insert(e_geos.end(),g);
return TRUE;
}
BOOL CagGeometrys::AddImportPolygon(CString sPathFile)
{
IPolygonPtr pg(CLSID_Polygon);
double x,y;
IPointPtr pt;
IPointCollectionPtr pts(__uuidof(Ring));
while(1)
{
IRingPtr r=pts;
r->Close();
IGeometryCollectionPtr gc=pg;
gc->AddGeometry(r);
if(e_bUnique)
e_geos.clear();
IGeometryPtr *g=new IGeometryPtr;
(*g)=pg;
e_geos.insert(e_geos.end(),g);
return TRUE;
}
BOOL CagGeometrys::AddPoint(double x, double y)
{
IPointPtr pt(__uuidof(Point));
pt->PutCoords(x,y);
IGeometryPtr *g=new IGeometryPtr;
(*g)=pt;
e_geos.insert(e_geos.end(),g);
return TRUE;
}
BOOL CagGeometrys::AddCircle(double x, double y, double r)
{
IPointPtr pt(__uuidof(Point));
IConstructCircularArcPtr cca(__uuidof(CircularArc));
pt->PutCoords(x,y);
cca->ConstructCircle(pt,r,-1);
IGeometryPtr *g=new IGeometryPtr;
(*g)=cca;
e_geos.insert(e_geos.end(),g);
return TRUE;
}
2 绘制一条polyline
可以使用AE里面的 IRubberBand 接口画在MapControl上:
IRubberBand rubberLine = new RubberLineClass();
IPolyline polyLine = (IPolyline)rubberLine.TrackNew(pActiveView.ScreenDisplay, null);
//设置图形的样式
m_Symbol = SetDisplaySymbol(polyLine);
//画出图形
pActiveView.ScreenDisplay.StartDrawing(m_QueryMap.ActiveView.ScreenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
pActiveView.ScreenDisplay.DrawPolyline(pGeometry);
pActiveView.Refresh();
pActiveView.ScreenDisplay.FinishDrawing();
通过point构造Segment,再构造path,再构造polyline
用到ISegmentCollection,IPointCollection等接口,帮助里有个例子
The following subs are demonstrating how to create valid polylines efficiently.
A. Geometry type: Polyline
1. createMultipartPolylinePathSegmentCollection: Create a multipart polyline using path via ISegmentCollection.
2. createMultipartPolylinePathPointCollection: Create a multipart polyline using path via IPointCollection.