ArcGISPlotSilverlightAPI For WPF


這兩天有個需求,在地圖上做標繪箭頭,效果如下圖。

Arcgis for WPF 10.2.5.0版本,然而官方文檔中沒有這種API,自己去寫一個呢,又感覺無從下手。無奈去網上搜索了一下,發現一篇好文:
即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 ); 
        }
}

 

 
 
運行,可以用鼠標在地圖上做標繪了!
 
下面是連接:http://pan.baidu.com/s/1o8vlKWM


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM