1. 程式人生 > >AE新增設定點要素,並新增

AE新增設定點要素,並新增

接以前做的東西,在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);