ArcGISPlotSilverlightAPI For WPF

时间:2023-03-09 03:29:31
ArcGISPlotSilverlightAPI For WPF

这两天有个需求,在地图上做标绘箭头,效果如下图。

ArcGISPlotSilverlightAPI For WPF

ArcGISPlotSilverlightAPI For WPF

ArcGISPlotSilverlightAPI For WPF
Arcgis for WPF 10.2.5.0版本,然而官方文档中没有这种API,自己去写一个呢,又感觉无从下手。无奈去网上搜索了一下,发现一篇好文:
即ArcGISPlotSilverlightAPI.dll。虽然很适合我要的结果,但是下载dll后,发现并不适用WPF版本。
使用IL反编译以后,发现该dll引用ESRI.ArcGIS.Client.dll,但是版本号比较低,而且可能是silverlight版的:
ArcGISPlotSilverlightAPI For WPF
ArcGISPlotSilverlightAPI For WPF
考虑替换为适合我用的WPF版本的ESRI.ArcGIS.Client.dll,然后把这些代码全部复制出来,重新编译一个动态链接库,为我所用。
打开VS,添加类库项目,命名还是ArcGISPlotSilverlightAPI,然后添加引用WPF版本的ESRI.ArcGIS.Client.dll,
ArcGISPlotSilverlightAPI For WPF
ArcGISPlotSilverlightAPI For WPF
新建各种类,复制代码。。。完成后编译,出现一些编译错误,排除后,编译成功!
ArcGISPlotSilverlightAPI For WPF
 ArcGISPlotSilverlightAPI For WPF
至于另外一个DLL文件:Matrix.dll呢,完全没有用到,就先不用管它了。。
在ArcGIS for WPF的项目中,引用刚才编译出来的dll文件:
 ArcGISPlotSilverlightAPI For WPFArcGISPlotSilverlightAPI For WPF
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