MeasureArea() public method

根据地图名称、二维地理坐标点、量算单位进行面积量算。
public MeasureArea ( string mapName, List point2Ds, Unit unit ) : MeasureAreaResult
mapName string 地图名称。【必设参数】
point2Ds List 二维地理坐标点数组。【必设参数】
unit Unit 返回结果的单位。
return SuperMap.Connector.Utility.MeasureAreaResult
        public override void OnMapMouseMove(object sender, MouseEventArgs e)
        {
            if (!_start) return;
            PointLatLng currentPoint = this._gMapControl.FromLocalToLatLng(e.X, e.Y);

            if (flag)
            {
                _points.RemoveAt(_points.Count - 1);
            }
            if (!flag) flag = true;
            _points.Add(currentPoint);
            _polygon = new GMapPolygonExtension("", _points, 2.0F,
               System.Drawing.Color.FromArgb(100, 0, 0, 255), System.Drawing.Color.FromArgb(25, 0, 0, 255));

            if (_point2Ds.Count > 1)
            {
                List<Point2D> tempPoints = new List<Point2D>();
                tempPoints.AddRange(_point2Ds);
                double mercatorX, mercatorY;
                Helper.LonLat2Mercator(currentPoint.Lng, currentPoint.Lat, out mercatorX, out mercatorY);
                Point2D point2D = new Point2D(mercatorX, mercatorY);
                tempPoints.Add(point2D);
                Map map = new Map(_mapUrl);
                MeasureAreaResult areaResult = map.MeasureArea(_mapName, tempPoints, Unit.KILOMETER);
                if (_resultMarker == null || _gMapOverlay.Markers.Count < 1)
                {
                    _resultMarker = new GMapMarkerExtension(currentPoint);
                    _resultMarker.ToolTipMode = MarkerTooltipMode.Always;
                    _gMapOverlay.Markers.Add(_resultMarker);
                }
                _resultMarker.Position = currentPoint;
                _resultMarker.ToolTipText = string.Format("{0:f1}平方千米", areaResult.Area);
            }
            if (_gMapOverlay.Polygons.Count > 0)
            {
                _gMapOverlay.Polygons[0] = _polygon;
            }
            else
            {
                _gMapOverlay.Polygons.Add(_polygon);
            }
        }
Beispiel #2
0
        public void MeasureAreaResultTest_point2DsISNULL()
        {
            Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");

            MeasureAreaResult areaResult = null;
            try
            {
                areaResult = map.MeasureArea("世界地图", null, Unit.KILOMETER);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual(e.Message, "参数不能为空。\r\n参数名: point2Ds");
            }
        }
Beispiel #3
0
        public void MeasureAreaResultTest_mapNameISNULL()
        {
            Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");

            List<Point2D> point2Ds = new List<Point2D>();
            Point2D point1 = new Point2D(23.00, 34.00);
            Point2D point2 = new Point2D(53.55, 12.66);
            Point2D point3 = new Point2D(73.88, 12.6);
            point2Ds.Add(point1);
            point2Ds.Add(point2);
            point2Ds.Add(point3);
            MeasureAreaResult areaResult = null;
            try
            {
                areaResult = map.MeasureArea(string.Empty, point2Ds, Unit.KILOMETER);
            }
            catch (ArgumentNullException e)
            {
                Assert.AreEqual(e.Message, "参数不能为空。\r\n参数名: mapName");
            }
        }
Beispiel #4
0
 public void MeasureAreaResultTest_point2DsISEmply()
 {
     Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");
     List<Point2D> point2Ds = new List<Point2D>();
     MeasureAreaResult areaResult = null;
     try
     {
         areaResult = map.MeasureArea("世界地图", point2Ds, Unit.KILOMETER);
     }
     catch (ArgumentException e)
     {
         Assert.AreEqual(e.Message, "参数 point2Ds 不合法,必须至少包含三个二维点。");
     }
 }
Beispiel #5
0
 public void MeasureAreaResultTest_KILOMETER()
 {
     Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest");
     string mapName = "World Map";
     List<Point2D> point2Ds = new List<Point2D>();
     Point2D point1 = new Point2D(23.00, 34.00);
     Point2D point2 = new Point2D(53.55, 12.66);
     Point2D point3 = new Point2D(73.88, 12.6);
     point2Ds.Add(point1);
     point2Ds.Add(point2);
     point2Ds.Add(point3);
     MeasureAreaResult areaResult = map.MeasureArea(mapName, point2Ds, Unit.KILOMETER);
     Assert.AreEqual(areaResult.Area, 3157590.9302391531);
     Assert.AreEqual(areaResult.Unit.ToString(), "KILOMETER");
 }