C#制作鹰眼的详细全过程(带注释)实例代码
axmapcontrol1是主控件,axmapcontrol2是鹰眼控件
要看清楚事件响应
1.鹰眼地图资源载入
privatevoid axmapcontrol1_onmapreplaced(object sender, imapcontrolevents2_onmapreplacedevent e)
{
//当主地图显示控件的地图更换时,鹰眼中的地图也跟随更换
axmapcontrol2.loadmxfile(axmapcontrol1.documentfilename);
axmapcontrol2.extent = axmapcontrol2.fullextent;
}
2.绘制鹰眼矩形框
private void axmapcontrol1_onextentupdated(object sender, imapcontrolevents2_onextentupdatedevent e)
{
// 得到新范围
ienvelope penv = (ienvelope)e.newenvelope;
igraphicscontainer pgra = axmapcontrol2.map as igraphicscontainer;
iactiveview pav = pgra as iactiveview;
//在绘制前,清除axmapcontrol2中的任何图形元素
pgra.deleteallelements();
irectangleelement prectangleele = new rectangleelementclass();
ielement pele = prectangleele as ielement;
pele.geometry = penv;
//设置鹰眼图中的红线框
irgbcolor pcolor = new rgbcolorclass();
pcolor.red = 255;
pcolor.green = 0;
pcolor.blue = 0;
pcolor.transparency = 255;
//产生一个线符号对象
ilinesymbol poutline = new simplelinesymbolclass();
poutline.width = 2;
poutline.color = pcolor;
//设置颜色属性
pcolor = new rgbcolorclass();
pcolor.red = 255;
pcolor.green = 0;
pcolor.blue = 0;
pcolor.transparency = 0;
//设置填充符号的属性
ifillsymbol pfillsymbol = new simplefillsymbolclass();
pfillsymbol.color = pcolor;
pfillsymbol.outline = poutline;
ifillshapeelement pfillshapeele = pele as ifillshapeelement;
pfillshapeele.symbol = pfillsymbol;
pgra.addelement((ielement)pfillshapeele, 0);
pav.partialrefresh(esriviewdrawphase.esriviewgraphics, null, null);
}
3. 实现互动
private void axmapcontrol2_onmousedown(object sender, imapcontrolevents2_onmousedownevent e)
{
ipoint ppt=new pointclass ();
ppt.putcoords (e.mapx ,e.mapy );
//改变主控件的视图范围
axmapcontrol1 .centerat (ppt );
}