ArcGIS API for Silverlight 使用GeometryService求解线与线的交点
///画线
void btn_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Button btn = sender as Button;
var geometry = btn.Tag as ESRI.ArcGIS.Client.Geometry.Polyline;
//存储线要素的集合
List<ESRI.ArcGIS.Client.Geometry.Polyline> polyLineListGrid = new List<ESRI.ArcGIS.Client.Geometry.Polyline>();
List<ESRI.ArcGIS.Client.Geometry.Polyline> polyLineListriver = new List<ESRI.ArcGIS.Client.Geometry.Polyline>();
polyLineListGrid.Add(geometry as ESRI.ArcGIS.Client.Geometry.Polyline);
geometryService.TrimExtendAsync(polyLineListGrid, CenterGraphic.Geometry as ESRI.ArcGIS.Client.Geometry.Polyline, CurveExtension.DefaultCurveExtension);
geometryService.TrimExtendCompleted += geometryService_TrimExtendCompleted;
}
///执行分析
void geometryService_TrimExtendCompleted(object sender, GraphicsEventArgs e)
{
MapPoint point = null;
foreach (Graphic g in e.Results)
{
if (g.Geometry.Extent != null)
{
glayer.Graphics.Clear();
layer.Graphics.Clear();
var pline = g.Geometry as ESRI.ArcGIS.Client.Geometry.Polyline;
//Graphic gg = new Graphic()
//{
// Geometry = pline,
// Symbol = new LoadMapResource().GetSymbolByKey("DrawObjectLineSymbol") as LineSymbol
//};
//glayer.Graphics.Add(gg);
var gline = CenterGraphic.Geometry as ESRI.ArcGIS.Client.Geometry.Polyline;
var len1 = GetMinDistance(gline.Paths[0][0], gline.Paths[0][gline.Paths[0].Count - 1], pline.Paths[0][0]);
var len2 = GetMinDistance(gline.Paths[0][0], gline.Paths[0][gline.Paths[0].Count - 1], pline.Paths[0][pline.Paths[0].Count - 1]);
if (len1 > len2)
{
point = CreateMapPoint(pline.Paths[0][pline.Paths[0].Count - 1].X, pline.Paths[0][pline.Paths[0].Count - 1].Y);
}
else
{
point = CreateMapPoint(pline.Paths[0][0].X, pline.Paths[0][0].Y);
}
AddPointGraphic(point);
}
}
}
//由X,Y构造一个点
public MapPoint CreateMapPoint(double x, double y)
{
return new MapPoint(x, y);
}
//将一个点添加到Layer中
public void AddPointGraphic(ESRI.ArcGIS.Client.Geometry.MapPoint point)
{
Graphic g = new Graphic()
{
Geometry = point,
Symbol = new LoadMapResource().GetSymbolByKey("DrawObjectPointSymbol") as MarkerSymbol,
};
glayer.Graphics.Add(g);
}