# 地图测距和测面积的简单实现

1498人阅读 评论(0)

第一种，使用GeometryServer服务；

第二种，使用行为动作MeasureAction；

第三种，使用ESRI.ArcGIS.Client.Geometry.Euclidian类；

	private Draw _DrawTool;
private EventHandler<DrawEventArgs> _DrawComplete;

//测距
public void Ranging(EventHandler<DrawEventArgs> drawComplete = null)
{
if (drawComplete == null) drawComplete = Ranging_Complete;
CreateFreeBursh(drawComplete);
_DrawTool.DrawMode = DrawMode.Polyline;
OpenFreeBursh();
}
private void Ranging_Complete(object sender, DrawEventArgs e)
{
double length = Math.Abs(ESRI.ArcGIS.Client.Geometry.Euclidian.Length(e.Geometry as Polyline));
if (length > 0)
{
{
Geometry = e.Geometry,
Symbol = new SimpleLineSymbol() { Color = new SolidColorBrush(Colors.Red), Width = 2 },
});
{
Geometry = (e.Geometry as Polyline).Paths.LastOrDefault().LastOrDefault(),
Symbol = new TextSymbol() { Text = string.Format("{0:F} km", length / 1000), FontFamily = new FontFamily("SimSun"), FontSize = 13 },
});
}
}

//测面积
public void Polygon(EventHandler<DrawEventArgs> drawComplete = null)
{
if (drawComplete == null) drawComplete = Polygon_Complete;
CreateFreeBursh(drawComplete);
_DrawTool.DrawMode = DrawMode.Polygon;
OpenFreeBursh();
}
private void Polygon_Complete(object sender, DrawEventArgs e)
{
double area = Math.Abs(ESRI.ArcGIS.Client.Geometry.Euclidian.Area(e.Geometry as Polygon));
if (area > 0)
{
{
Geometry = e.Geometry,
Symbol = new SimpleFillSymbol() { Fill = new SolidColorBrush(AppColorManager.HtmlToColor("#22FF0000")), BorderBrush = new SolidColorBrush(Colors.Red), BorderThickness = 2 }
});
{
Geometry = (e.Geometry as Polygon).Rings.LastOrDefault().FirstOrDefault(),
Symbol = new TextSymbol() { Text = string.Format("{0:F} km2", area / 1000000), FontFamily = new FontFamily("SimSun"), FontSize = 13 },
});
}
}

个人资料
等级：
访问量： 2万+
积分： 645
排名： 7万+
最新评论