Arcgis Engine - 鹰眼(减少闪烁)

时间:2022-01-22 10:00:48

  网上看到的代码,都是一个模样,经过不断调试,无意中效果就可以了.主要是在"鼠标拖动的时候",网上的代码的鹰眼效果,感觉坑爹死了,闪烁超级严重.主要原因是鼠标拖动的时候,进行时时更新.(该博文的鹰眼可能针对栅格图不起作用,可以参考我的这篇博文(arcgis engine - 鹰眼在栅格图无法显示.)

  我在"天地图"上,它实现的效果也是鼠标拖动放开后才更新.以下是我对网上的代码进行稍微的改动:

  主视图:

#region 主视图事件.
//同步鹰眼视图和主视图.
private void map_main_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e) {
mapCtrl_view.ClearLayers();
for (int i = 0; i < mapCtrl_main.LayerCount; i++) mapCtrl_view.AddLayer(mapCtrl_main.get_Layer(i));
mapCtrl_view.Extent = mapCtrl_main.FullExtent;
mapCtrl_main.Refresh();
}
//画轮廓.
private void map_main_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e) {
DrawSymbol(sender, (ESRI.ArcGIS.Geometry.IEnvelope)e.newEnvelope);
}
#endregion

   辅助方法:

 /// <summary>
/// 返回颜色.
/// </summary>
/// <param name="rgb">rgb的值</param>
/// <param name="transparency">透明度[0,255](0为全透明)</param>
/// <returns>颜色对象.</returns>
ESRI.ArcGIS.Display.IRgbColor ColorPaint(int rgb, byte transparency) {
ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
rgbColor.RGB = rgb;
rgbColor.Transparency = transparency;
return rgbColor;
} /// <summary>
/// 画轮廓.
/// </summary>
/// <param name="sender"></param>
/// <param name="e">根据IEnvelope对象画轮廓.</param>
void DrawSymbol(object sender, ESRI.ArcGIS.Geometry.IEnvelope e) {
ESRI.ArcGIS.Carto.IGraphicsContainer hawkGC = (ESRI.ArcGIS.Carto.IGraphicsContainer)mapCtrl_view.Map;
ESRI.ArcGIS.Carto.IActiveView aView = (ESRI.ArcGIS.Carto.IActiveView)hawkGC;
hawkGC.DeleteAllElements(); ESRI.ArcGIS.Carto.IElement recEle = (ESRI.ArcGIS.Carto.IElement)new ESRI.ArcGIS.Carto.RectangleElementClass();
recEle.Geometry = e;
ESRI.ArcGIS.Display.ISimpleLineSymbol outLine = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
outLine.Color = ColorPaint(, );
outLine.Width = ; //填充样式.
ESRI.ArcGIS.Display.ISimpleFillSymbol fillSym = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
fillSym.Color = ColorPaint(, );
fillSym.Outline = outLine; ESRI.ArcGIS.Carto.IFillShapeElement fillShape = (ESRI.ArcGIS.Carto.IFillShapeElement)recEle;
fillShape.Symbol = fillSym;
hawkGC.AddElement((ESRI.ArcGIS.Carto.IElement)fillShape, );
aView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics, null, null);
}

  鹰眼视图:

 #region 鹰眼事件.
private void map_view_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) {
if (mapCtrl_main.LayerCount < ) return;
if (e.button == ) { //点选.
ESRI.ArcGIS.Geometry.IPoint ptNew = new ESRI.ArcGIS.Geometry.PointClass();
ptNew.PutCoords(e.mapX, e.mapY);
}
else if (e.button == ) //右键框选.
{
interEnvelope = mapCtrl_view.TrackRectangle();
//记录感兴趣区.
mapCtrl_main.Extent = interEnvelope;
}
mapCtrl_main.ActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, null, null);
} private void map_view_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e) {
if (e.button == && interEnvelope != null) {
//鼠标移动,轮廓跟着变,但是主视图不更新,直到鼠标放开.
interEnvelope.PutCoords(e.mapX - interEnvelope.Width / , e.mapY - interEnvelope.Height / , e.mapX + interEnvelope.Width / , e.mapY + interEnvelope.Height / );
DrawSymbol(sender, interEnvelope);
}
} private void map_view_OnMouseUp(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseUpEvent e) {
//鼠标放开时同步更新主视图,和map_view_OnMouseMove搭配.
ESRI.ArcGIS.Geometry.IPoint ptNew = new ESRI.ArcGIS.Geometry.PointClass();
ptNew.PutCoords(e.mapX, e.mapY);
mapCtrl_main.CenterAt(ptNew);
mapCtrl_main.ActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, null, null);
}
#endregion