鹰眼同步功能

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#region 鹰眼的实现及同步
private void mainMapControl_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
{
SynchronizeEagleEye();
}

private void SynchronizeEagleEye()
{
if (yerCount > 0)
{
EagleEyeMapControl.ClearLayers();
}
//设置鹰眼和主地图的坐标系统一致
EagleEyeMapControl.SpatialReference = mainMapControl.SpatialReference;
for (int i = yerCount - 1; i >= 0; i--)
{
//使鹰眼视图与数据视图的图层上下顺序保持一致
ILayer pLayer = mainMapControl.get_Layer(i);
if (pLayer is IGroupLayer || pLayer is ICompositeLayer)
{
ICompositeLayer pCompositeLayer = (ICompositeLayer)pLayer;
for (int j = pCompositeLayer.Count - 1; j >= 0; j--)
{
ILayer pSubLayer = pCompositeLayer.get_Layer(j);
IFeatureLayer pFeatureLayer = pSubLayer as IFeatureLayer;
if (pFeatureLayer != null)
{
//由于鹰眼地图较小,所以过滤点图层不添加
if (pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPoint
&& pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryMultipoint)
{
EagleEyeMapControl.AddLayer(pLayer);
}
}
}
}
else
{
IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
if (pFeatureLayer != null)
{
if (pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPoint
&& pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryMultipoint)
{
EagleEyeMapControl.AddLayer(pLayer);
}
}
}
//设置鹰眼地图全图显示
EagleEyeMapControl.Extent = mainMapControl.FullExtent;
pEnv = mainMapControl.Extent as IEnvelope;
DrawRectangle(pEnv);
EagleEyeMapControl.ActiveView.Refresh();
}
}

private void EagleEyeMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
if (yerCount > 0)
{
//按下鼠标左键移动矩形框
if (e.button == 1)
{
//如果指针落在鹰

眼的矩形框中,标记可移动
if (e.mapX > pEnv.XMin && e.mapY > pEnv.YMin && e.mapX < pEnv.XMax && e.mapY < pEnv.YMax)
{
bCanDrag = true;
}
pMoveRectPoint = new PointClass();
pMoveRectPoint.PutCoords(e.mapX, e.mapY); //记录点击的第一个点的坐标
}
//按下鼠标右键绘制矩形框
else if (e.button == 2)
{
IEnvelope pEnvelope = EagleEyeMapControl.TrackRectangle();

IPoint pTempPoint = new PointClass();
pTempPoint.PutCoords(pEnvelope.XMin + pEnvelope.Width / 2, pEnvelope.YMin + pEnvelope.Height / 2);
mainMapControl.Extent = pEnvelope;
//矩形框的高宽和数据试图的高宽不一定成正比,这里做一个中心调整
mainMapControl.CenterAt(pTempPoint);
}
}
}

//移动矩形框
private void EagleEyeMapControl_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
if (e.mapX > pEnv.XMin && e.mapY > pEnv.YMin && e.mapX < pEnv.XMax && e.mapY < pEnv.YMax)
{
//如果鼠标移动到矩形框中,鼠标换成小手,表示可以拖动
EagleEyeMapControl.MousePointer = esriControlsMousePointer.esriPointerHand;
if (e.button == 2) //如果在内部按下鼠标右键,将鼠标演示设置为默认样式
{
EagleEyeMapControl.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
}
else
{
//在其他位置将鼠标设为默认的样式
EagleEyeMapControl.MousePointer = esriControlsMousePointer.esriPointerDefault;
}

if (bCanDrag)
{
double Dx, Dy; //记录鼠标移动的距离
Dx = e.mapX - pMoveRectPoint.X;
Dy = e.mapY - pMoveRectPoint.Y;
pEnv.Offset(Dx, Dy); //根据偏移量更改 pEnv 位置
pMoveRectPoint.PutCoords(e.mapX, e.mapY);
DrawRectangle(pEnv);
mainMapControl.Extent = pEnv;
}
}

private void EagleEyeMapControl_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
{
if (e.button == 1 && pMoveRectPoint!=null)
{
if (e.mapX == pMoveRectPoint.X && e.mapY == pMoveRectPoint.Y)
{
mainMapControl.CenterAt(pMoveRectPoint);
}
bCanDrag = false;
}
}

//绘制矩形框
private void mainMapControl_OnExtentUpdated(object sender, IMapControlEvents2_OnExtent

UpdatedEvent e)
{
//得到当前视图范围
pEnv = (IEnvelope)e.newEnvelope;
DrawRectangle(pEnv);
}

//在鹰眼地图上面画矩形框
private void DrawRectangle(IEnvelope pEnvelope)
{
//在绘制前,清除鹰眼中之前绘制的矩形框
IGraphicsContainer pGraphicsContainer = EagleEyeMapControl.Map as IGraphicsContainer;
IActiveView pActiveView = pGraphicsContainer as IActiveView;
pGraphicsContainer.DeleteAllElements();
//得到当前视图范围
IRectangleElement pRectangleElement = new RectangleElementClass();
IElement pElement = pRectangleElement as IElement;
pElement.Geometry = pEnvelope;
//设置矩形框(实质为中间透明度面)
IRgbColor pColor = new RgbColorClass();
pColor = GetRgbColor(255, 0, 0);
pColor.Transparency = 255;
ILineSymbol pOutLine = new SimpleLineSymbolClass();
pOutLine.Width = 2;
pOutLine.Color = pColor;

IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
pColor = new RgbColorClass();
pColor.Transparency = 0;
pFillSymbol.Color = pColor;
pFillSymbol.Outline = pOutLine;
//向鹰眼中添加矩形框
IFillShapeElement pFillShapeElement = pElement as IFillShapeElement;
pFillShapeElement.Symbol = pFillSymbol;
pGraphicsContainer.AddElement((IElement)pFillShapeElement, 0);
//刷新
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
#endregion

相关文档
最新文档