製圖模式和地圖模式下用的地圖是同一份地圖,那麼在製圖模式下若是須要對地圖進行操做(例如地圖的拉框放大,縮小),那麼該如何操做呢,地圖範圍視圖變化在製圖模式下該如何監聽呢,下面主要介紹PIE SDK如何在製圖模式下如何對地圖進行操做。spa
製圖模式用的是製圖控件PageLayoutControl,製圖控件裏面的又包含了一個Map,這個Map中的數據和地圖模式控件MapControl的Map的數據是同一份,獲取地圖模式的地圖咱們能夠寫成MapControl.ActiveView.FocusMap或者MapControl.FocusMap;那麼製圖模式中的地圖也是同理,即PageLayoutControl.ActivewView.FocusMap或者PageLayoutControl.FocusMap;code
對製圖模式下地圖範圍的監聽,就須要對製圖模式的視圖變化進行監聽,那麼就須要PIE SDK中IActiveViewEvents事件接口,IactiveViewEvents接口下有不少關於地圖的事件,如地圖添加,刪除,範圍更新,空間參考發生變化等,下面以地圖視圖範圍發生變化爲例講述如何使用該接口orm
1 /// <summary> 2 /// 製圖模式下對地圖範圍變化的監聽 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="e"></param> 6 private void tbn_MapExtentListening_Click(object sender, EventArgs e) 7 { 8 IActiveViewEvents activeViewEvents = pageLayoutControl1.ActiveView.FocusMap as IActiveViewEvents; 9 activeViewEvents.OnViewRefreshed += FormMain_OnViewRefreshed; 10 } 11 12 /// <summary> 13 /// 監聽事件 14 /// </summary> 15 void FormMain_OnViewRefreshed() 16 { 17 string spatialRefence = pageLayoutControl1.FocusMap.SpatialReference.Name; MessageBox.Show(string.Format("地圖範圍刷新變化,當前地圖的參考座標爲:{0}", spatialRefence)); 18 }
在製圖模式下,通常狀況須要對地圖進行控制,通常都是範圍控制,主要考慮兩個方面,一個是對製圖控件進行控制,二是對製圖下的地圖進行控制。視頻
如對地圖的拉框放大功能,須要鼠標與地圖進行交互, 鼠標按下後移動繪製拉框的過程是顯示在在製圖控件上的,可是鼠標彈起時效果倒是要製圖控件的框不變,將框內的地圖範圍進行改變,鼠標按下觸發MouseDown事件,移動觸發MouseMove事件,當鼠標彈起觸發MouseUp事件後拉框繪製完成,將拉框的範圍設置爲地圖的顯示範圍,這樣就完成一次拉框放大操做。blog
1 /// 標識 2 private int m_Flag = 0; 3 /// 開始點 4 private IPoint m_StartPoint; 5 /// 結束點 6 private IPoint m_EndPoint; 7 /// 是否鎖定(判斷當前鼠標移動時是不是鼠標按下未擡起狀態) 8 private bool m_Lock = false; 9 /// 製圖模式下地圖ActiveView 10 private IActiveView m_PageMapActiveView = null; 11 能夠寫在地圖初始化裏面: 12 PageMapActiveView= pageLayoutControl1.FocusMap as IActiveView; 13 /// <summary> 14 /// 製圖模式下對地圖範圍的操做(以地圖放大爲例) 15 /// </summary> 16 /// <param name="sender"></param> 17 /// <param name="e"></param> 18 private void tbn_MapZoomInControl_Click(object sender, EventArgs e) 19 { 20 m_Flag = 1;//m_Flag是全局變量 21 } 22 23 /// <summary> 24 /// 製圖模式下鼠標按下事件 25 /// </summary> 26 /// <param name="sender"></param> 27 /// <param name="e"></param> 28 private void pageLayoutControl1_MouseDown(object sender, MouseEventArgs e) 29 { 30 if (m_Flag == 1) 31 { 32 m_StartPoint = m_PageMapActiveView.DisplayTransformation.ToMapPoint(e.X, e.Y); 33 m_Lock = true; 34 } 35 } 36 /// <summary> 37 /// 製圖模式下鼠標彈起事件 38 /// </summary> 39 /// <param name="sender"></param> 40 /// <param name="e"></param> 41 private void pageLayoutControl1_MouseUp(object sender, MouseEventArgs e) 42 { 43 if (m_StartPoint == null) return; 44 m_Lock = false; 45 IEnvelope envelop = new Envelope(); 46 47 m_EndPoint = m_PageMapActiveView.DisplayTransformation.ToMapPoint(e.X, e.Y);//將製圖模式的屏幕座標轉換成地圖座標 48 System.Drawing.Point point = m_PageMapActiveView.DisplayTransformation.FromMapPoint(m_StartPoint.X, m_StartPoint.Y); 49 IPoint startPoint = m_PageMapActiveView.DisplayTransformation.ToMapPoint(point.X, point.Y); 50 envelop.PutCoords(startPoint.X, startPoint.Y, m_EndPoint.X, m_EndPoint.Y); 51 52 m_PageMapActiveView.Extent = envelop; 53 pageLayoutControl1.PartialRefresh(ViewDrawPhaseType.ViewAll); 54 m_StartPoint = null; 55 } 56 /// <summary> 57 /// 製圖模式下鼠標移動事件 58 /// </summary> 59 /// <param name="sender"></param> 60 /// <param name="e"></param> 61 private void pageLayoutControl1_MouseMove(object sender, MouseEventArgs e) 62 { 63 if (m_StartPoint == null || e.Button != MouseButtons.Left) return; 64 if (m_Lock == true)//鼠標拉框按下未擡起 65 { 66 //將座標轉換成製圖模式地圖的座標 67 System.Drawing.Point point = m_PageMapActiveView.DisplayTransformation.FromMapPoint(m_StartPoint.X, m_StartPoint.Y); 68 IPoint startPoint = pageLayoutControl1.ActiveView.DisplayTransformation.ToMapPoint(point);//屏幕座標轉換成製圖座標(不是製圖中的地圖座標) 69 m_EndPoint = pageLayoutControl1.ActiveView.DisplayTransformation.ToMapPoint(e.X, e.Y); 70 //空間範圍 71 IPointCollection polygon = new Polygon(); 72 polygon.AddPoint(startPoint.X, startPoint.Y); 73 polygon.AddPoint(m_EndPoint.X, startPoint.Y); 74 polygon.AddPoint(m_EndPoint.X, m_EndPoint.Y); 75 polygon.AddPoint(startPoint.X, m_EndPoint.Y); 76 polygon.AddPoint(startPoint.X, startPoint.Y); 77 78 //符號樣式 79 ILineSymbol lineSymbol = new SimpleLineSymbol(); 80 lineSymbol.Color = System.Drawing.Color.Red; 81 lineSymbol.Width = 1; 82 83 IFillSymbol fillSymbol = new SimpleFillSymbol(); 84 fillSymbol.OutlineSymbol = lineSymbol; 85 fillSymbol.Color = Color.FromArgb(20, Color.Yellow);//alpha參數爲透明度 86 //繪製圖形 87 pageLayoutControl1.ActiveView.StartDrawing(); 88 pageLayoutControl1.ActiveView.DrawGeometry(fillSymbol, polygon as IGeometry); 89 pageLayoutControl1.ActiveView.FinishDrawing(); 90 } 91 } 92 93 /// <summary> 94 /// 製圖模式下地圖縮小 95 /// </summary> 96 /// <param name="sender"></param> 97 /// <param name="e"></param> 98 private void tbn_MapZoomOut_Click(object sender, EventArgs e) 99 { 100 IEnvelope envelop = m_PageMapActiveView.Extent; 101 envelop.Expand(2, 2, true);//縮放參數小於1時,是地圖放大,反之,地圖縮小 102 m_PageMapActiveView.Extent = envelop; 103 pageLayoutControl1.PartialRefresh(ViewDrawPhaseType.ViewAll); 104 }
接口/類教程 |
方法/屬性接口 |
說明事件 |
PIE.Carto.IActiveViewEventsci |
OnViewRefreshedstring |
視圖更新 |
PIE.Carto.IActiveView |
Extent |
視圖範圍 |
ToMapPoint |
將屏幕座標轉換陳過地圖座標 |
|
FromMapPoint |
將地圖座標轉換成屏幕座標 |
|
StartDrawing |
開始繪製 |
|
FinishDrawing |
結束繪製 |
|
DrawGeometry |
繪製圖形 |
項目路徑 |
百度雲盤地址下/PIE示例程序/09.專題製圖/ 07製圖模式下地圖操做 |
視頻位置 |
百度雲盤地址下/PIE視頻教程/09.專題製圖/ 07製圖模式下地圖操做.avi |
對地圖範圍的監聽:
拉框繪製前:
拉框繪製後: