你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
朱新颖
赞同来自: Danranhutu 、石羽
赞同来自: 石头
Danranhutu - 爱知乎,爱AE开发
赞同来自:
using System; using System.Windows.Forms; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geometry; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void axLicenseControl1_Enter(object sender, EventArgs e) { } private void axToolbarControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IToolbarControlEvents_OnMouseDownEvent e) { } private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e) { if (this.axMapControl1.LayerCount > 0) { this.axMapControl2.Map=new MapClass(); for (int i = 0; i <= (axMapControl1.Map.LayerCount - 1); i++) { axMapControl2.AddLayer(axMapControl1.get_Layer(i)); } axMapControl2.Extent = axMapControl1.Extent; axMapControl2.Refresh(); } } private void axMapControl2_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) { if (axMapControl2.Map.LayerCount > 0) { if (e.button == 1) { IPoint pPoint = new PointClass(); pPoint.PutCoords(e.mapX, e.mapY); axMapControl1.CenterAt(pPoint); this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } else if (e.button == 2) { IEnvelope pEnv = axMapControl2.TrackRectangle(); axMapControl1.Extent = pEnv; this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } } } private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e) { //得到新范围 IEnvelope pEnvelope = (IEnvelope)e.newEnvelope; IGraphicsContainer pGraphicsContainer =this.axMapControl2.Map as IGraphicsContainer; IActiveView pActiveView = pGraphicsContainer as IActiveView; //在绘制前,清除axMapControl2中的任何图形元素 pGraphicsContainer.DeleteAllElements(); IRectangleElement pRectangleEle =new RectangleElementClass(); IElement pElement = pRectangleEle as IElement; pElement.Geometry = pEnvelope; //设置鹰眼图中的红线框 IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 255; //产生一个线符号对象 ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Width = 1; 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 = pElement as IFillShapeElement; pFillShapeEle.Symbol=pFillSymbol; pGraphicsContainer.AddElement((IElement)pFillShapeEle,0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null); } private void axMapControl2_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e) { if (e.button == 1) { IPoint pPoint = new PointClass(); pPoint.PutCoords(e.mapX, e.mapY); this.axMapControl1.CenterAt(pPoint); this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } } } }
xiaoyaoyeren
要回复问题请先登录或注册
爱知乎,爱AE开发
8 个回复
朱新颖
赞同来自: Danranhutu 、石羽
IActiveViewEvents_Event events = axMapControl1.ActiveView as IActiveViewEvents_Event;
events.ItemAdded += new IActiveViewEvents_ItemAddedEventHandler(ItemAdded);
然后在ItemAdded方法中执行同步:
private void ItemAdded(System.Object Item)
{
// TODO: Add your code here
if (this.axMapControl1.LayerCount > 0)
{
axMapControl2.AddLayer(Item as ILayer);
axMapControl2.Extent = axMapControl1.Extent;
axMapControl2.Refresh();
}
}
注意,新添加的图层需要与mxd的已有图层能同时显示出来,也就是说空间参考一致
朱新颖
赞同来自: 石头
可以尝试添加IActiveViewEvents.ItemAdded事件,在该事件的处理函数中执行
Danranhutu - 爱知乎,爱AE开发
赞同来自:
xiaoyaoyeren
赞同来自:
Danranhutu - 爱知乎,爱AE开发
赞同来自:
要回复问题请先登录或注册
发起人
爱知乎,爱AE开发
相关问题
问题状态