Inheritance: GMap.NET.WindowsForms.GMapMarker
Ejemplo n.º 1
0
 public override void OnMapMouseDown(object sender, MouseEventArgs e)
 {
     PointLatLng currentPoint = this._gMapControl.FromLocalToLatLng(e.X, e.Y);
     double mercatorX, mercatorY;
     Helper.LonLat2Mercator(currentPoint.Lng, currentPoint.Lat, out mercatorX, out mercatorY);
     Point2D point2D = new Point2D(mercatorX, mercatorY);
     _point2Ds.Add(point2D);
     _points.Add(currentPoint);
     if (_start)
     {
         MeasureDistanceResult result = _map.MeasureDistance(_mapName, _point2Ds, Unit.KILOMETER);
         GMapMarkerExtension mBorders = new GMapMarkerExtension(currentPoint);
         mBorders.ToolTipText = string.Format("{0:f1}千米", result.Distance);
         mBorders.ToolTipMode = MarkerTooltipMode.Always;
         _gMapOverlay.Markers.Add(mBorders);
     }
     _start = true;
 }
Ejemplo n.º 2
0
        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);
            }
        }