region 主视图事件.
//同步鹰眼视图和主视图.
private void map_main_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e)
{
map_view.ClearLayers();
for (int i = 0; i < map_main.LayerCount; i++) map_view.AddLayer(map_main.get_Layer(i));
map_view.Extent = map_main.FullExtent;
map_main.Refresh();
}
//画轮廓.
private void map_main_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e)
{
ESRI.ArcGIS.Geometry.IEnvelope enNew = (ESRI.ArcGIS.Geometry.IEnvelope)e.newEnvelope;
ESRI.ArcGIS.Carto.IGraphicsContainer hawkGC = (ESRI.ArcGIS.Carto.IGraphicsContainer)map_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 = enNew;
//轮廓线颜色.
ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
rgbColor.RGB = 255;
rgbColor.Transparency = 255;
ESRI.ArcGIS.Display.ISimpleLineSymbol outLine = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
outLine.Color = rgbColor;
outLine.Width = 2;
//填充颜色.
rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
rgbColor.RGB = 255;
rgbColor.Transparency = 0;
//填充样式.
ESRI.ArcGIS.Display.ISimpleFillSymbol fillSym = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
fillSym.Color = rgbColor;
fillSym.Outline = outLine;
ESRI.ArcGIS.Carto.IFillShapeElement fillShape = (ESRI.ArcGIS.Carto.IFillShapeElement)recEle;
fillShape.Symbol = fillSym;
hawkGC.AddElement((ESRI.ArcGIS.Carto.IElement)fillShape, 0);
aView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics, null, null);
}
#endregion
#region 鹰眼事件.
private void map_view_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
if (map_main.LayerCount < 0) return;
if (e.button == 1)
{ //点选.
ESRI.ArcGIS.Geometry.IPoint ptNew = new ESRI.ArcGIS.Geometry.PointClass();
ptNew.PutCoords(e.mapX, e.mapY);
map_main.CenterAt(ptNew);
}
else if (e.button == 2) //右键框选.
{
map_main.Extent = map_view.TrackRectangle();
}
map_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 == 1)
{
ESRI.ArcGIS.Geometry.IPoint ptNew = new ESRI.ArcGIS.Geometry.PointClass();
ptNew.PutCoords(e.mapX, e.mapY);
map_main.CenterAt(ptNew);
map_main.ActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, null, null);
}
}
#endregion
这代码基本上都是copy的,网上的代码也都差不多,找不到不一样的.
我现在想实现的功能是,鼠标拖动的时候,不实时更新,鼠标方框的时候才更新.
但是问题是,拖动的过程,我想让我画的轮廓跟着鼠标. 这个实现不了...
网上的代码都是copy的,闪动的原因是鼠标拖动过程都进行更新.
如果你看过别人实现鹰眼的代码就知道了.我的思路是拖动过程不更新.鼠标放开才更新.
但是拖动的过程,照样在鹰眼的MapControl中时时更新画的轮廓.
就那么简单.