arcgis接口参考

来源:互联网 发布:软件需求最佳实践 编辑:程序博客网 时间:2024/06/09 05:22

引用论文:基于Arcgis Engine的水下地形等高线断线连接技术的研究和发展  http://www.docin.com/p-301562226.html 科技在线



 

http://hi.baidu.com/giswoduxing/blog/item/12a6f388a2fb38b90e244445.html

一,新建一个单文档工程命名为:鹰眼.在向导最后,改View类为CFromView.
二,向工程中导入库

三,向工程中添加一个Toolbar控件,一个TOCControl控件,二个MapControl控件.分别命名

为:m_ToolBar,m_TOCControl,m_MapControl1,m_Control2。再添加二个View类的全局变量:IMapPtr

m_Map1;IMapPtr m_Map2 。向CMOnInitialUpdate函数中添加代码如下:
void CMyView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();

CRect windowrect;
GetWindowRect(windowrect);

//设定三个控件的位置
if(m_ToolBar)
   m_ToolBar.SetWindowPos(this,5,0,windowrect.Width(),20,SWP_NOZORDER);
if(m_TOCControl)
   m_TOCControl.SetWindowPos(this,5,25,(windowrect.Width()-15)/5,
   (windowrect.Height()-35)*3/5,SWP_NOZORDER);
if(m_MapControl1)
   m_MapControl1.SetWindowPos(this,(windowrect.Width()-15)/5+10,25,
   (windowrect.Width()-15)*4/5,windowrect.Height()-35,SWP_NOZORDER);
if(m_MapControl2)
   m_MapControl2.SetWindowPos(this,5,(windowrect.Height()-35)*3/5+30,
   (windowrect.Width()-15)/5,(windowrect.Height()-35)*2/5,SWP_NOZORDER);

//设置伙伴关系
LPUNKNOWN lpUK=m_MapControl1.GetControlUnknown();
LPDISPATCH lpDis=0;
lpUK->QueryInterface(IID_IDispatch,(void**)&lpDis);
m_ToolBar.SetBuddyControl(lpDis);
m_TOCControl.SetBuddyControl(lpDis);

m_Map1=m_MapControl1.GetMap();
m_Map2=m_MapControl2.GetMap();
long i,layercount;
ILayerPtr layer;
m_Map1->get_LayerCount(&layercount);
for(i=0;i<layercount;i++)
{
   m_Map1->get_Layer(i,&layer);
   m_Map2->AddLayer(layer);
}
}
向View类添加WM_SIZE消息响应事件,代码如下:
void CMyView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);

// TODO: Add your message handler code here
CRect windowrect;
GetWindowRect(windowrect);

if(m_ToolBar)
   m_ToolBar.SetWindowPos(this,5,0,windowrect.Width(),20,SWP_NOZORDER);
if(m_TOCControl)
   m_TOCControl.SetWindowPos(this,5,25,(windowrect.Width()-15)/5,
   (windowrect.Height()-35)*3/5,SWP_NOZORDER);
if(m_MapControl1)
   m_MapControl1.SetWindowPos(this,(windowrect.Width()-15)/5+10,25,
   (windowrect.Width()-15)*4/5,windowrect.Height()-35,SWP_NOZORDER);
if(m_MapControl2)
   m_MapControl2.SetWindowPos(this,5,(windowrect.Height()-35)*3/5+30,
   (windowrect.Width()-15)/5,(windowrect.Height()-35)*2/5,SWP_NOZORDER);
}

四,为MapControl1控件添加OnAfterScreenDraw事件响应函数,代码如下:
void CMyView::OnOnAfterScreenDrawMapcontrol1(long hdc)
{
// TODO: Add your control notification handler code here
IActiveViewPtr ipActive(m_Map2);
IGraphicsContainerPtr ipGraphics(ipActive);
//清除MapControl2的Element
ipGraphics->DeleteAllElements();
//给MapControl2添加与MapControl1相同的图层
m_MapControl2.ClearLayers();
long i,layercount;
ILayerPtr layer;
m_Map1->get_LayerCount(&layercount);
for(i=0;i<layercount;i++)
{
   m_Map1->get_Layer(i,&layer);
   m_Map2->AddLayer(layer);
}

//设置在MapControl2中显示的范围框
IRgbColorPtr ipRgb(CLSID_RgbColor);
ipRgb->put_Blue(0);
ipRgb->put_Green(0);
ipRgb->put_Red(255);
IColorPtr ipColor(ipRgb);

IEnvelopePtr ipEnvelope;
ipEnvelope=m_MapControl1.GetExtent();

ISimpleLineSymbolPtr ipSimpleLineSymbol(CLSID_SimpleLineSymbol);
ipSimpleLineSymbol->put_Color(ipColor);
ipSimpleLineSymbol->put_Width(1);
ipSimpleLineSymbol->put_Style(esriSLSSolid);
ILineSymbolPtr ipLineSymbol(ipSimpleLineSymbol);

ISimpleFillSymbolPtr ipSimpleFillSymbol(CLSID_SimpleFillSymbol);
ipColor->put_Transparency(0);
ipSimpleFillSymbol->put_Color(ipColor);
ipSimpleFillSymbol->put_Outline(ipLineSymbol);


IRectangleElementPtr ipRectangleElement(CLSID_RectangleElement);
IGeometryPtr ipGeometry(ipEnvelope);

IFillSymbolPtr ipFillSymbol(ipSimpleFillSymbol);
IFillShapeElementPtr ipFillShape(ipRectangleElement);
ipFillShape->put_Symbol(ipFillSymbol);
IElementPtr ipElement(ipFillShape);
ipElement->put_Geometry(ipGeometry);
ipGraphics->AddElement(ipElement,0);

}
五,为MapControl2添加OnMouseDown事件响应函数,代码如下:
void CMyView::OnOnMouseDownMapcontrol2(long button, long shift, long X, long Y, double mapX, double

mapY)
{
// TODO: Add your control notification handler code here
IEnvelopePtr ipEnvelope(CLSID_Envelope);
ipEnvelope=m_MapControl1.GetExtent();
IPointPtr ipPoint(CLSID_Point);
ipPoint->PutCoords(mapX,mapY);
ipEnvelope->CenterAt(ipPoint);
m_MapControl1.SetExtent(ipEnvelope);//此时为激活OnOnAfterScreenDrawMapcontrol1函数
}