码迷,mamicode.com
首页 > 其他好文 > 详细

Arcgis Engine - 鹰眼(减少闪烁)

时间:2014-10-23 09:25:08      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   for   sp   div   on   

  网上看到的代码,都是一个模样,经过不断调试,无意中效果就可以了.主要是在"鼠标拖动的时候",网上的代码的鹰眼效果,感觉坑爹死了,闪烁超级严重.主要原因是鼠标拖动的时候,进行时时更新.

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

  主视图:

#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

   辅助方法:

 1 /// <summary>
 2         /// 返回颜色.
 3         /// </summary>
 4         /// <param name="rgb">rgb的值</param>
 5         /// <param name="transparency">透明度[0,255](0为全透明)</param>
 6         /// <returns>颜色对象.</returns>
 7         ESRI.ArcGIS.Display.IRgbColor ColorPaint(int rgb, byte transparency) {
 8             ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
 9             rgbColor.RGB = rgb;
10             rgbColor.Transparency = transparency;
11             return rgbColor;
12         }
13 
14         /// <summary>
15         /// 画轮廓.
16         /// </summary>
17         /// <param name="sender"></param>
18         /// <param name="e">根据IEnvelope对象画轮廓.</param>
19         void DrawSymbol(object sender, ESRI.ArcGIS.Geometry.IEnvelope e) {
20             ESRI.ArcGIS.Carto.IGraphicsContainer hawkGC = (ESRI.ArcGIS.Carto.IGraphicsContainer)mapCtrl_view.Map;
21             ESRI.ArcGIS.Carto.IActiveView aView = (ESRI.ArcGIS.Carto.IActiveView)hawkGC;
22             hawkGC.DeleteAllElements();
23 
24             ESRI.ArcGIS.Carto.IElement recEle = (ESRI.ArcGIS.Carto.IElement)new ESRI.ArcGIS.Carto.RectangleElementClass();
25             recEle.Geometry = e;
26             ESRI.ArcGIS.Display.ISimpleLineSymbol outLine = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
27             outLine.Color = ColorPaint(255, 255);
28             outLine.Width = 2;
29 
30             //填充样式.
31             ESRI.ArcGIS.Display.ISimpleFillSymbol fillSym = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
32             fillSym.Color = ColorPaint(255, 0);
33             fillSym.Outline = outLine;
34 
35             ESRI.ArcGIS.Carto.IFillShapeElement fillShape = (ESRI.ArcGIS.Carto.IFillShapeElement)recEle;
36             fillShape.Symbol = fillSym;
37             hawkGC.AddElement((ESRI.ArcGIS.Carto.IElement)fillShape, 0);
38             aView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics, null, null);
39         }

  鹰眼视图:

 1 #region 鹰眼事件.
 2 private void map_view_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) {
 3     if (mapCtrl_main.LayerCount < 0) return;
 4     if (e.button == 1) { //点选.
 5     ESRI.ArcGIS.Geometry.IPoint ptNew = new ESRI.ArcGIS.Geometry.PointClass();
 6     ptNew.PutCoords(e.mapX, e.mapY);
 7     }
 8     else if (e.button == 2) //右键框选.
 9     {
10     interEnvelope = mapCtrl_view.TrackRectangle();
11     //记录感兴趣区.
12     mapCtrl_main.Extent = interEnvelope;
13     }
14     mapCtrl_main.ActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, null, null);
15 }
16 
17 private void map_view_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e) {
18     if (e.button == 1 && interEnvelope != null) {
19     //鼠标移动,轮廓跟着变,但是主视图不更新,直到鼠标放开.
20     interEnvelope.PutCoords(e.mapX - interEnvelope.Width / 2, e.mapY - interEnvelope.Height / 2, e.mapX + interEnvelope.Width / 2, e.mapY + interEnvelope.Height / 2);
21     DrawSymbol(sender, interEnvelope);
22     }
23 }
24 
25 private void map_view_OnMouseUp(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseUpEvent e) {
26     //鼠标放开时同步更新主视图,和map_view_OnMouseMove搭配.
27     ESRI.ArcGIS.Geometry.IPoint ptNew = new ESRI.ArcGIS.Geometry.PointClass();
28     ptNew.PutCoords(e.mapX, e.mapY);
29     mapCtrl_main.CenterAt(ptNew);
30     mapCtrl_main.ActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, null, null);
31 }
32 #endregion

 

Arcgis Engine - 鹰眼(减少闪烁)

标签:style   blog   color   io   ar   for   sp   div   on   

原文地址:http://www.cnblogs.com/listened/p/4044855.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!