基本上与添加点要素相同,只是多加了一个双击的结束响应,和一个mousemove的响应,主要程序如下,
case 1://添加mousedown函数
{
HRESULT hr;
if(m_pNewLineFeedback ==NULL)
{
CoCreateInstance(CLSID_NewLineFeedback,
NULL,CLSCTX_ALL,IID_INewLineFeedback,
(void**)&m_pNewLineFeedback);
ISymbolPtr isymbol;
if(m_pNewLineFeedback == NULL) return;
m_pNewLineFeedback->get_Symbol(&isymbol);
ISimpleLineSymbolPtr pslnsym(isymbol);
if(pslnsym == NULL) return;
IRgbColorPtr prgb(CLSID_RgbColor);
prgb->put_Red(0);
prgb->put_Green(205);
prgb->put_Blue(0);
IColorPtr icolor(prgb);
pslnsym->put_Color(icolor);
pslnsym->put_Style(esriSLSDot);
IScreenDisplayPtr pScrD;
iActiveView->get_ScreenDisplay(&pScrD);
m_pNewLineFeedback->putref_Display(pScrD);
m_pNewLineFeedback->Start(ipoint);
}
else
hr = m_pNewLineFeedback->AddPoint(ipoint);
break;
}
void CAoEx1View::OnDoubleClickMapcontrol1(long button, long shift, long X, long Y, double mapX, double mapY)
{
// TODO: 在此处添加消息处理程序代码
IActiveViewPtr iActiveView(m_ipMap);
switch(m_operateType)
{
case 1:
{
IPolylinePtr ipolyline;
if(m_pNewLineFeedback == NULL) break;
if(m_isymbol != NULL) m_pNewLineFeedback->putref_Symbol(m_isymbol);
m_pNewLineFeedback->Stop(&ipolyline);
m_pgeometry = ipolyline;
if(ipolyline != NULL)
AddCreateElement(m_pgeometry,iActiveView);
m_pNewLineFeedback =NULL;
iActiveView->Refresh();
}break;
}
void CAoEx1View::OnTestMarkerStyle()//打开选择要素类型对话框函数
{
// TODO: 在此添加命令处理程序代码
//IActiveViewPtr iActiveView(m_ipMap);
ISymbolSelectorPtr pSymbolSelector(CLSID_SymbolSelector);//symbol select
VARIANT_BOOL bOK;
if(pSymbolSelector == NULL) return;
switch(m_operateType)
{
case 0:
{
ISimpleMarkerSymbolPtr psimpleMarksb(CLSID_SimpleMarkerSymbol);//simple marker
pSymbolSelector->AddSymbol((ISymbolPtr)psimpleMarksb,&bOK);//将simple marker添加到symbol select中
}
break;
case 1:
{
ISimpleLineSymbolPtr psimpleLinesb(CLSID_SimpleLineSymbol);//simple marker
pSymbolSelector->AddSymbol((ISymbolPtr)psimpleLinesb,&bOK);//将simple marker添加到symbol select中
}
break;
}
HRESULT hr;
hr = pSymbolSelector->SelectSymbol(0,&bOK);
if(FAILED(hr)) return;
if(bOK)
pSymbolSelector->GetSymbolAt(0,&m_isymbol);
void CAoEx1View::AddCreateElement(IGeometryPtr pgeomln, IActiveViewPtr iactiveview)
{
IGraphicsContainerPtr pgracont(iactiveview);
switch(m_operateType)
{
case 0:
{
IMarkerElementPtr pmarkerelem(CLSID_MarkerElement);//创建element对象,是element
if(pmarkerelem == NULL) return;
IMarkerSymbolPtr imarkerSymbol(m_isymbol);//用m_isymbol初始化imarkerSymbol,是symbol
pmarkerelem->put_Symbol(imarkerSymbol);//将symbol添加到element
((IElementPtr)pmarkerelem)->put_Geometry(pgeomln);
pgracont->AddElement((IElementPtr)pmarkerelem,0);
}break;
case 1:
{
ILineElementPtr plineelem(CLSID_LineElement);
if(plineelem ==NULL) break;
if(m_isymbol != NULL)
{
ILineSymbolPtr ilineSymbol(m_isymbol);
plineelem->put_Symbol(ilineSymbol);
}
IElementPtr pelem(plineelem);
pelem->put_Geometry(pgeomln);
pgracont->AddElement(pelem,0);
}break;
}
}
void CAoEx1View::OnMouseMoveMapcontrol1(long button, long shift, long X, long Y, double mapX, double mapY)
{
MapComposer mapComposer;
mapComposer.m_ipMap = m_ctrlMap.get_Map();
mapComposer.ShowMouseCoord(mapX,mapY);
IPointPtr pPoint(CLSID_Point);
pPoint->PutCoords(mapX,mapY);
switch(m_operateType)
{
case 1:
m_ctrlMap.put_MousePointer(2);//esriPointerCrosshair == 2
if(m_pNewLineFeedback != NULL)
m_pNewLineFeedback->MoveTo(pPoint);
break;
}
// TODO: 在此处添加消息处理程序代码
}