基于ArcEngine与C#的鹰眼地图实现
鷹眼圖是對全局地圖的一種概略表達,具有與全局地圖的空間參考和空間范圍。為了更好起到空間提示和導航作用,有些還具備全局地圖中重要地理要素,如主要河流、道路等的概略表達。通過兩個axMapControl控件,主控件axMapControl 1和鷹眼控件axMapControl 2。要實現鷹眼功能,關鍵技術有兩點,一是如何讓兩個控件使用的數據保持一致,另一點是如何繪制鷹眼控件中的顯示方框。
一、數據共享,使用axMapControl1的控件的OnMapReplaced事件。OnMapReplace事件發生MapControl的地圖被替換后,即IMapControl2::Map被另一個地圖替換時(如IMapControl2::LoadMxFile方法被調用時或map屬性被明確替換時)觸發該事件。用這個事件來保持與當前圖層同步。
1 private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e) 2 { 3 if (axMapControl1.Map.LayerCount > 0) 4 { 5 for (int i = 0; i <= axMapControl1.Map.LayerCount - 1; i++) 6 { 7 axMapControl2.AddLayer(axMapControl1.get_Layer(i)); 8 } 9 axMapControl2.Extent=axMapControl1.Extent; 10 axMapControl2.Refresh(); 11 } 12 }?
二、顯示方框的繪制。在鷹眼控件axMapControl2中使用鼠標拖曳視圖時,鷹眼控件axMapControl2中出現紅色矩形框。
1)axMapControl1控件的OnExtentUpdated事件。OnExtentUpdated事件在MapControl的可視化范圍發生變化后發生,即當IMapControl2::Extent屬性發生變化時被觸發。改變MapControl中可視化范圍的途徑包括精確設置范圍、縮放、漫游或使用IMapControl2::CenterAt方法等。
1 private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e) 2 { 3 //獲得一個新范圍 4 IEnvelope pEnvelope = (IEnvelope)e.newEnvelope; 5 IGraphicsContainer pGrahicsContainer = axMapControl2.Map as IGraphicsContainer; 6 IActiveView pActiveView = pGrahicsContainer as IActiveView; 7 //在繪制前清除axMapControl2中所有圖層 8 pGrahicsContainer.DeleteAllElements(); 9 IRectangleElement pRectangleElement = new RectangleElementClass(); 10 IElement pElement = pRectangleElement as IElement; 11 pElement.Geometry = pEnvelope; 12 //設置鷹眼圖中的紅線框 13 IRgbColor pColor = new RgbColorClass(); 14 pColor.Red = 255; 15 pColor.Green = 0; 16 pColor.Blue = 0; 17 pColor.Transparency = 255; 18 //產生一個線符號對象 19 ILineSymbol pOutline = new SimpleLineSymbolClass(); 20 pOutline.Width = 3; 21 pOutline.Color = pColor; 22 //設置填充符號顏色 23 pColor = new RgbColorClass(); 24 pColor.Red = 255; 25 pColor.Green = 0; 26 pColor.Blue = 0; 27 pColor.Transparency = 0; 28 //設置填充符號 29 IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); 30 pFillSymbol.Color = pColor; 31 pFillSymbol.Outline = pOutline; 32 33 IFillShapeElement pFillShapeEle = pElement as IFillShapeElement; 34 pFillShapeEle.Symbol = pFillSymbol; 35 pGrahicsContainer.AddElement((IElement)pFillShapeEle, 0); 36 pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); 37 38 }?
2)axMapControl2控件的OnMouseDown事件。當在MapControl上點擊鼠標任何鍵時觸發OnMouseDown事件。
1 private void axMapControl2_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) 2 { 3 if (axMapControl2.Map.LayerCount > 0) 4 { 5 if (e.button == 1) 6 { 7 IPoint pPoint = new PointClass(); 8 pPoint.PutCoords(e.mapX, e.mapY); 9 axMapControl1.CenterAt(pPoint); 10 axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); 11 } 12 else if (e.button == 2) 13 { 14 IEnvelope pEnv = axMapControl2.TrackRectangle(); 15 axMapControl1.Extent = pEnv; 16 axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); 17 } 18 } 19 }?
3)axMapControl2控件的OnMouseMove事件。當在MapControl上移動鼠標時不斷地觸發OnMouseMove事件。
1 private void axMapControl2_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e) 2 { 3 if (e.button == 1) 4 { 5 IPoint pPoint = new PointClass(); 6 pPoint.PutCoords(e.mapX, e.mapY); 7 axMapControl1.CenterAt(pPoint); 8 axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); 9 } 10 }三、結論
當axMapControl1中的數據被替換時,axMapControl2中的數據會自動加載axMapControl1的所有圖層,實現兩者的數據統一。在axMapControl2控件中拖曳或移動地圖時,axMapControl1中的地圖也在隨時變化。
參考文獻:基于ArcGIS Engine與C#.net的地圖鷹眼功能的實現 南峰
????????????? 《ArcGIS Engine 10 開發手冊》
????????????? 《ArcObjects二次開發教程》傅仲良 主編
????????????? 《ArcObjects Developer Help》
???????????
?
轉載于:https://www.cnblogs.com/vegetable/p/4101844.html
總結
以上是生活随笔為你收集整理的基于ArcEngine与C#的鹰眼地图实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 点云数据处理_概述 | 点云数
- 下一篇: Unity设置为中文