测量面积

在页面上添加测量工具的图标:

<esri:Tool ClientAction="Polygon" JavaScriptFile="" Name="AreaPolygon" DefaultImage="Images/MapTool/MeasurePoly1.gif"
HoverImage="Images/MapTool/MeasurePoly2.gif" SelectedImage="Images/MapTool/MeasurePoly2.gif"
Text="面积" ToolTip="面积" ServerActionAssembly="App_Code" ServerActionClass="IdentifyArea" />

在app_code里面添加IdentifyArea方法,代码如下:

/// <summary>
///IdentifyArea 的摘要说明 计算面积
/// </summary>
public class IdentifyArea : IMapServerToolAction
{
public IdentifyArea()
{
//
//TODO: 在此处添加构造函数逻辑
//
}

void IMapServerToolAction.ServerAction(ToolEventArgs args)
{
Map MapControl = args.Control as Map;//得到地图资源
MapPolygonEventArgs MyPolygonArg = (MapPolygonEventArgs)args;//得到地图中的线对象
System.Drawing.Point[] screen_points = MyPolygonArg.Vectors;//得到线的点集合
Double X1 = 0, Y1 = 0, X2 = 0, Y2 = 0;
Double XD = 0.0;
Double YD = 0.0;
Double AllArea = 0.0;
Double TempArea = 0.0;

//起始点
ESRI.ArcGIS.ADF.Web.Geometry.Point Point1 = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_points[0], MapControl.Extent, (Int32)MapControl.Width.Value, (Int32)MapControl.Height.Value);

X1 = Point1.X;
Y1 = Point1.Y;

for (int i = 1; i < screen_points.Length; i++)
{
//得到与起始点的距离
ESRI.ArcGIS.ADF.Web.Geometry.Point Point2 = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_points[i], MapControl.Extent, (Int32)MapControl.Width.Value, (Int32)MapControl.Height.Value);

X2 = Point2.X;
Y2 = Point2.Y;

XD = X2 - X1;
YD = Y2 - Y1;
TempArea = X1 * YD - Y1 * XD;
AllArea += TempArea;

Point1 = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_points[0], MapControl.Extent, (Int32)MapControl.Width.Value, (Int32)MapControl.Height.Value);

X1 = Point1.X;
Y1 = Point1.Y;


}
AllArea = Math.Abs(AllArea) / 2;
AllArea = Math.Round(AllArea, 2);


string jstext = "alert('总计:" + AllArea.ToString() + "平方米');";
CallbackResult cr_lei = new CallbackResult(null, null, "javascript", jstext);

MapControl.CallbackResults.Add(cr_lei);

}

原文地址:https://www.cnblogs.com/lff255356/p/2741003.html