C#鹰眼_带拖动
结合help中给的例子,又使用DisPlayFeedBack,实现在鹰眼中拖动。拖动过程中小边框的显示问题解决的不是很好,还望大家多多指教。
实现如下:
两个MapControl控件:axMapControl1和axMapControl2,axMapControl2存放鹰眼地图。
主要变量有:
private IEnvelope m_Envelope; //The envelope drawn on the small MapControl---axMapControl2.
private System.Object m_FillSymbol; //The symbol used to draw the envelope on the small MapControl
//axMapControl1中的事件
private void CreateOverviewSymbol() //create the symbol used in the small MapControl ,自定义函数
{
//Get the IRGBColor interface.
IRgbColor color = new RgbColorClass();
//Set the color properties.
color.RGB = 255;
//Get the ILine symbol interface.
ILineSymbol outline = new SimpleLineSymbolClass();
//Set the line symbol properties.
outline.Width = 1.5;
outline.Color = color;
//Get the IFillSymbol interface.
ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
//Set the fill symbol properties.
simpleFillSymbol.Outline = outline;
simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;
m_FillSymbol = simpleFillSymbol;
}
private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e) //更新axMapControl1地图时装载鹰眼地图
{
axMapControl2.LoadMxFile(axMapControl1.DocumentFilename);
axMapControl2.Extent=axMapControl1.FullExtent;
m_Envelope = axMapControl1.ActiveView.Extent;
}
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
{ //axMapControl1的范围变化时,设置鹰眼小边框m_Envelope 的大小
axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);
m_Envelope = e.newEnvelope as IEnvelope;
}
private void axMapControl1_OnAfterDraw(object sender, IMapControlEvents2_OnAfterDrawEvent e)
{
if (m_Envelope == null) return;
//If the foreground phase has drawn.
esriViewDrawPhase viewDrawPhase = (esriViewDrawPhase)e.viewDrawPhase;
if (viewDrawPhase == esriViewDrawPhase.esriViewForeground)
{
axMapControl2.DrawShape(m_Envelope as IGeometry, ref m_FillSymbol);
}
}
几个变量:
private IMoveEnvelopeFeedback pSmallViewerEnvelope;//鹰眼小地图的红框
private IPoint pSmallViewerMouseDownPt;//拖动时鼠标落点
private bool isTrackingSmallViewer = false; //标识是否在拖动
static int moveCount = 0;//记录移动的个数,为移动过程中显示红框用。权宜之计,望高手提出更好解决方案
//axMapControl2中的事件
private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)//鹰眼互动
{
//IPoint pt = new PointClass();
pSmallViewerMouseDownPt = new PointClass();
pSmallViewerMouseDownPt.PutCoords(e.mapX, e.mapY);
axMapControl1.CenterAt(pSmallViewerMouseDownPt);
isTrackingSmallViewer = true;
if (pSmallViewerEnvelope == null)
{
pSmallViewerEnvelope = new MoveEnvelopeFeedbackClass();
pSmallViewerEnvelope.Display = axMapControl2.ActiveView.ScreenDisplay;
pSmallViewerEnvelope.Symbol = (ISymbol)m_FillSymbol;
}
pSmallViewerEnvelope.Start(m_Envelope, pSmallViewerMouseDownPt);
}
private void axMapControl2_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
if (isTrackingSmallViewer)
{
moveCount++;
if (moveCount % 4 == 0)//因为一刷新,红框就没了。所以每移动4次就刷新一下,保持红框的连续性。
axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);
pSmallViewerMouseDownPt.PutCoords(e.mapX, e.mapY);
pSmallViewerEnvelope.MoveTo(pSmallViewerMouseDownPt);
}
}
private void axMapControl2_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
{
if (pSmallViewerEnvelope != null)
{
m_Envelope = pSmallViewerEnvelope.Stop();
axMapControl1.Extent = m_Envelope;
isTrackingSmallViewer = false;
}
}
实现如下:
两个MapControl控件:axMapControl1和axMapControl2,axMapControl2存放鹰眼地图。
主要变量有:
private IEnvelope m_Envelope; //The envelope drawn on the small MapControl---axMapControl2.
private System.Object m_FillSymbol; //The symbol used to draw the envelope on the small MapControl
//axMapControl1中的事件
private void CreateOverviewSymbol() //create the symbol used in the small MapControl ,自定义函数
{
//Get the IRGBColor interface.
IRgbColor color = new RgbColorClass();
//Set the color properties.
color.RGB = 255;
//Get the ILine symbol interface.
ILineSymbol outline = new SimpleLineSymbolClass();
//Set the line symbol properties.
outline.Width = 1.5;
outline.Color = color;
//Get the IFillSymbol interface.
ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
//Set the fill symbol properties.
simpleFillSymbol.Outline = outline;
simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;
m_FillSymbol = simpleFillSymbol;
}
private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e) //更新axMapControl1地图时装载鹰眼地图
{
axMapControl2.LoadMxFile(axMapControl1.DocumentFilename);
axMapControl2.Extent=axMapControl1.FullExtent;
m_Envelope = axMapControl1.ActiveView.Extent;
}
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
{ //axMapControl1的范围变化时,设置鹰眼小边框m_Envelope 的大小
axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);
m_Envelope = e.newEnvelope as IEnvelope;
}
private void axMapControl1_OnAfterDraw(object sender, IMapControlEvents2_OnAfterDrawEvent e)
{
if (m_Envelope == null) return;
//If the foreground phase has drawn.
esriViewDrawPhase viewDrawPhase = (esriViewDrawPhase)e.viewDrawPhase;
if (viewDrawPhase == esriViewDrawPhase.esriViewForeground)
{
axMapControl2.DrawShape(m_Envelope as IGeometry, ref m_FillSymbol);
}
}
几个变量:
private IMoveEnvelopeFeedback pSmallViewerEnvelope;//鹰眼小地图的红框
private IPoint pSmallViewerMouseDownPt;//拖动时鼠标落点
private bool isTrackingSmallViewer = false; //标识是否在拖动
static int moveCount = 0;//记录移动的个数,为移动过程中显示红框用。权宜之计,望高手提出更好解决方案
//axMapControl2中的事件
private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)//鹰眼互动
{
//IPoint pt = new PointClass();
pSmallViewerMouseDownPt = new PointClass();
pSmallViewerMouseDownPt.PutCoords(e.mapX, e.mapY);
axMapControl1.CenterAt(pSmallViewerMouseDownPt);
isTrackingSmallViewer = true;
if (pSmallViewerEnvelope == null)
{
pSmallViewerEnvelope = new MoveEnvelopeFeedbackClass();
pSmallViewerEnvelope.Display = axMapControl2.ActiveView.ScreenDisplay;
pSmallViewerEnvelope.Symbol = (ISymbol)m_FillSymbol;
}
pSmallViewerEnvelope.Start(m_Envelope, pSmallViewerMouseDownPt);
}
private void axMapControl2_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
if (isTrackingSmallViewer)
{
moveCount++;
if (moveCount % 4 == 0)//因为一刷新,红框就没了。所以每移动4次就刷新一下,保持红框的连续性。
axMapControl2.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewForeground, null, null);
pSmallViewerMouseDownPt.PutCoords(e.mapX, e.mapY);
pSmallViewerEnvelope.MoveTo(pSmallViewerMouseDownPt);
}
}
private void axMapControl2_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
{
if (pSmallViewerEnvelope != null)
{
m_Envelope = pSmallViewerEnvelope.Stop();
axMapControl1.Extent = m_Envelope;
isTrackingSmallViewer = false;
}
}
分类:
ArcEngine
, ArcGIS Object
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?