Arigis for WPF 標繪 箭頭 ArcGISPlotSilverlightAPI ...
這兩天有個需求,在地圖上做標繪箭頭,效果如下圖。
Arcgis for WPF 10.2.5.0版本,然而官方文檔中沒有這種API,自己去寫一個呢,又感覺無從下手。無奈去網上搜索了一下,發現一篇好文: http://blog.csdn.net/zdw_wym/article/details/49407215 即ArcGISPlotSilverlightAPI.dll。雖然很適合我要的結果,但是下載dll後,發現並不適用WPF版本。 使用IL反編譯以後,發現該dll引用ESRI.ArcGIS.Client.dll,但是版本號比較低,而且可能是silverlight版的: 考慮替換為適合我用的WPF版本的ESRI.ArcGIS.Client.dll,然後把這些代碼全部複製出來,重新編譯一個動態鏈接庫,為我所用。 打開VS,添加類庫項目,命名還是ArcGISPlotSilverlightAPI,然後添加引用WPF版本的ESRI.ArcGIS.Client.dll, 新建各種類,複製代碼。。。完成後編譯,出現一些編譯錯誤,排除後,編譯成功! 至於另外一個DLL文件:Matrix.dll呢,完全沒有用到,就先不用管它了。。 在ArcGIS for WPF的項目中,引用剛纔編譯出來的dll文件:public partial class MainWindow : Window { private EditGeometry _editGeometry; private GraphicsLayer _gGraphicsLayer1; private bool _isEdit; private bool _isFinish; private PlotDraw _plotDraw; private long _pointCount; private TailedArrow _tArraw; private Graphic selectedPointGraphic; public MainWindow() { InitializeComponent(); Init(); } public void Init() { this._pointCount = 0L; this._gGraphicsLayer1 = new GraphicsLayer(); this._isFinish = true; this._plotDraw = new PlotDraw(mainMap); EditGeometry geometry = new EditGeometry { Map=this.mainMap,IsEnabled=true,EditVerticesEnabled=false}; this._editGeometry = geometry; this.mainMap.Layers.Add(this._gGraphicsLayer1); this._gGraphicsLayer1.MouseLeftButtonDown += _gGraphicsLayer1_MouseLeftButtonDown; this._isEdit = true; this._plotDraw.DrawEnd += _plotDraw_DrawEnd; this._plotDraw.setPlotDrawMode(PlotDrawMode.TailedArrow); } void _gGraphicsLayer1_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e) { //throw new NotImplementedException(); if (this._isEdit) { e.Handled = true; if (e.Graphic.Geometry is MapPoint) { e.Graphic.Selected = true; this.selectedPointGraphic = e.Graphic; } else { this._editGeometry.StartEdit(e.Graphic); } } } void _plotDraw_DrawEnd(ESRI.ArcGIS.Client.Geometry.Polygon polygon) { //throw new NotImplementedException(); Symbol symbol = App.Current.Resources["DrawFillSymbol"] as Symbol; Graphic item = new Graphic { Geometry = polygon, Symbol = symbol }; this._gGraphicsLayer1.Graphics.Add(item ); } }
運行,可以用滑鼠在地圖上做標繪了!