地图测距和测面积的简单实现
在silverlight api中测距和测面积有多种实现方式,
第一种,使用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)
{
this.Graphics.Add(new Graphic()
{
Geometry = e.Geometry,
Symbol = new SimpleLineSymbol() { Color = new SolidColorBrush(Colors.Red), Width = 2 },
});
this.Graphics.Add(new Graphic()
{
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)
{
this.Graphics.Add(new Graphic()
{
Geometry = e.Geometry,
Symbol = new SimpleFillSymbol() { Fill = new SolidColorBrush(AppColorManager.HtmlToColor("#22FF0000")), BorderBrush = new SolidColorBrush(Colors.Red), BorderThickness = 2 }
});
this.Graphics.Add(new Graphic()
{
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 },
});
}
}
转载自:https://blog.csdn.net/zxian610/article/details/9817245