接以前做的东西,在view中添加mousedown函数,添加ISymbolptr m_isymbol私有变量,添加一个checkbox,控制是否添加。
void CAoEx1View::OnMouseDownMapcontrol1(long button, long shift, long X, long Y, double mapX, double mapY)
{
// TODO: 在此处添加消息处理程序代码
IActiveViewPtr iActiveView(m_ipMap);
IScreenDisplayPtr ipScreenDisplay;
if(iActiveView == NULL) return;
iActiveView->get_ScreenDisplay(&ipScreenDisplay);
IGeometryPtr ipGeom;
IElementCollectionPtr m_ipelementcollection(CLSID_ElementCollection);
long a;
HRESULT hr;
m_ipMap->get_LayerCount(&a);
IScreenDisplayPtr pScrD;
iActiveView->get_ScreenDisplay(&pScrD);
if(pScrD == NULL) return;
IPointPtr ipoint(CLSID_Point);
if(ipoint == NULL) return;
ipoint->PutCoords(mapX,mapY);
IRgbColorPtr prgb(CLSID_RgbColor);
prgb->put_Red(0);
prgb->put_Green(205);
prgb->put_Blue(0);
IColorPtr icolor(prgb);
IGeometryPtr iGeometry;
switch(operateStyle)
{
case 1:
{
IMarkerElementPtr imarker(CLSID_MarkerElement);
IMarkerSymbolPtr imarkersymbol(CLSID_SimpleMarkerSymbol);
if(m_isymbol != NULL)
imarkersymbol = m_isymbol;
imarker ->put_Symbol(imarkersymbol);
IElementPtr pMarkElement(imarker);
IGeometryPtr pGeometry(ipoint);
pMarkElement->put_Geometry(pGeometry);
AddCreateElement(pGeometry,iActiveView);
iActiveView->Refresh();
}
break;
}
}
void CAoEx1View::OnMouseUpMapcontrol1(long button, long shift, long X, long Y, double mapX, double mapY)
{
// TODO: 在此处添加消息处理程序代码
}
void CAoEx1View::OnDoubleClickMapcontrol1(long button, long shift, long X, long Y, double mapX, double mapY)
{
// TODO: 在此处添加消息处理程序代码
}
void CAoEx1View::OnTestMarkerStyle()
{
// TODO: 在此添加命令处理程序代码
IActiveViewPtr iActiveView(m_ipMap);
ISymbolSelectorPtr pSymbolSelector(CLSID_SymbolSelector);
ISimpleMarkerSymbolPtr psimpleMarksb(CLSID_SimpleMarkerSymbol);
VARIANT_BOOL bOK;
IUnknownPtr iunknow;
ISymbolPtr isymbol;
if(pSymbolSelector == NULL) return;
isymbol = psimpleMarksb;
pSymbolSelector->AddSymbol(isymbol,&bOK);
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);
IMarkerElementPtr pmarkerelem(CLSID_MarkerElement);
if(pmarkerelem == NULL) return;
IMarkerSymbolPtr imarkerSymbol(m_isymbol);
pmarkerelem->put_Symbol(imarkerSymbol);
IElementPtr pelem(pmarkerelem);
pelem->put_Geometry(pgeomln);
pgracont->AddElement(pelem,0);
}
void CAoEx1View::OnBnClickedCheck1()
{
operateStyle = 1;
// TODO: 在此添加控件通知处理程序代码
}
注意事项:
1、ISymbolSelector需要引用displayui库,即在在 StdAfx.h 中添加: #import "D:/Program Files/ArcGIS/com/esriDisplayUI.olb" raw_interfaces_only raw_native_types no_namespace named_guids exclude("OLE_COLOR", "OLE_HANDLE", "VARTYPE")
2、m_ipmap必须初始化,如果是安装以前做的,用自己写的添加涂层的函数,m_ipmap已经初始化了,如果直接添加的AO的工具条上的添加涂层,则需要初始化m_ipmap,或者使用IActiveViewPtr iActiveView= m_ctrlMap.get_ActiveView();这句化替代 IActiveViewPtr iActiveView(m_ipMap);