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

1438人阅读 评论(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 },
});
}
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：25723次
• 积分：596
• 等级：
• 排名：千里之外
• 原创：34篇
• 转载：5篇
• 译文：0篇
• 评论：7条
评论排行
最新评论