private async void MeasureButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                pauseButton.IsEnabled            = true;
                pauseButton.Icon                 = new SymbolIcon(Symbol.Pause);
                pauseButton.Label                = "Suspend";
                MyMapView.SketchEditor.IsEnabled = true;
                measurementOutput.Text           = "Click the map to begin the measure";
                var geometry = await MyMapView.SketchEditor.StartAsync(Esri.ArcGISRuntime.UI.SketchCreationMode.Polyline);

                var polyline = geometry as Polyline;
                if (polyline != null && polyline.Parts != null && polyline.Parts.Count > 0)
                {
                    var result      = new StringBuilder();
                    var totalLength = GeometryEngine.LengthGeodetic(polyline);
                    result.AppendFormat("Total Length\t:\t{0:0} m\n", totalLength);
                    var polygon = new Polygon(polyline.Parts, polyline.SpatialReference);
                    var area    = GeometryEngine.AreaGeodetic(polygon);
                    result.AppendFormat("Area\t\t:\t{0:0} m²\n", area);
                    measurementOutput.Text = result.ToString();
                }
            }
            catch (TaskCanceledException)
            {
            }
            catch (Exception ex)
            {
                measurementOutput.Text = ex.Message;
            }
            pauseButton.IsEnabled = false;
            pauseButton.Icon      = new SymbolIcon(Symbol.Play);
        }
        private void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs geoViewInputEventArgs)
        {
            // Get the tapped point, projected to WGS84.
            MapPoint destination = (MapPoint)GeometryEngine.Project(geoViewInputEventArgs.Location, SpatialReferences.Wgs84);

            // Update the destination graphic.
            _endLocationGraphic.Geometry = destination;

            // Get the points that define the route polyline.
            PointCollection polylinePoints = new PointCollection(SpatialReferences.Wgs84)
            {
                (MapPoint)_startLocationGraphic.Geometry,
                destination
            };

            // Create the polyline for the two points.
            Polyline routeLine = new Polyline(polylinePoints);

            // Densify the polyline to show the geodesic curve.
            Geometry pathGeometry = GeometryEngine.DensifyGeodetic(routeLine, 1, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);

            // Apply the curved line to the path graphic.
            _pathGraphic.Geometry = pathGeometry;

            // Calculate and show the distance.
            double distance = GeometryEngine.LengthGeodetic(pathGeometry, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);

            _distanceLabel.Text = $"{(int) distance} kilometers";
        }
Esempio n. 3
0
 private void MySceneView_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     if (type == "line" && mapPoint_list.Count != 0)
     {
         BorderContentText.Visibility = Visibility.Visible;
         var boatPositions = new PolylineBuilder(SpatialReferences.Wgs84);
         for (var i = 0; i < mapPoint_list.Count; i++)
         {
             boatPositions.AddPoint(new MapPoint(mapPoint_list[i].X, mapPoint_list[i].Y));
         }
         var boatRoute = boatPositions.ToGeometry();
         _mapViewModel.Line(boatRoute, "line");
         LineText.Text = "Line Length: " + GeometryEngine.LengthGeodetic(boatRoute).ToString("N2") + " meters";
     }
     else if (type == "area" && mapPoint_list.Count != 0)
     {
         BorderContentText.Visibility = Visibility.Visible;
         var boatPositions = new PolygonBuilder(SpatialReferences.Wgs84);
         for (var i = 0; i < mapPoint_list.Count; i++)
         {
             boatPositions.AddPoint(new MapPoint(mapPoint_list[i].X, mapPoint_list[i].Y));
         }
         var boatRoute = boatPositions.ToGeometry();
         _mapViewModel.Area(boatRoute);
         AreaText.Text = "Area Size: " + GeometryEngine.AreaGeodetic(boatRoute).ToString("N2") + "  square meters";
     }
     mapPoint_list.Clear();
 }
        private void SketchEditor_GeometryChanged(object sender, Esri.ArcGISRuntime.UI.GeometryChangedEventArgs e)
        {
            var polyline    = e.NewGeometry as Polyline;
            var result      = new StringBuilder();
            var totalLength = GeometryEngine.LengthGeodetic(polyline);

            result.AppendFormat("Total Length\t:\t{0:0} m\n", totalLength);
            var polygon = new Polygon(polyline.Parts, polyline.SpatialReference);
            var area    = GeometryEngine.AreaGeodetic(polygon);

            result.AppendFormat("Area\t\t:\t{0:0} m²\n", area);
            measurementOutput.Text = result.ToString();
        }
        /// <summary>
        /// Displays the measurement result
        /// </summary>
        /// <param name="geometry">geometry to measure</param>
        private void DisplayResult(Geometry.Geometry geometry = null)
        {
            if (_measureResultTextBlock != null)
            {
                double measurement = 0;
                if (geometry == null)
                {
                    switch (Mode)
                    {
                    case MeasureToolbarMode.Line:
                    {
                        geometry = LineSketchEditor.Geometry;
                        break;
                    }

                    case MeasureToolbarMode.Area:
                    {
                        geometry = AreaSketchEditor.Geometry;
                        break;
                    }

                    case MeasureToolbarMode.Feature:
                    {
                        geometry = _measureFeatureResultOverlay.Graphics.FirstOrDefault()?.Geometry;
                        break;
                    }
                    }
                }

                if (geometry is Polyline)
                {
                    measurement = GeometryEngine.LengthGeodetic(geometry, SelectedLinearUnit, GeodeticCurveType.ShapePreserving);
                }
                else if (geometry is Polygon || geometry is Envelope)
                {
                    measurement = GeometryEngine.AreaGeodetic(geometry, SelectedAreaUnit, GeodeticCurveType.ShapePreserving);
                }

                if (geometry == null)
                {
                    var instruction = Mode == MeasureToolbarMode.None ?
                                      "Toggle a measure mode" : (Mode == MeasureToolbarMode.Feature ? "Tap a feature" : "Tap to sketch");
                    _measureResultTextBlock.Text = instruction;
                }
                else
                {
                    _measureResultTextBlock.Text = string.Format("{0:0,0.00}", measurement);
                }
            }
        }
        /// <summary>
        /// Gets a point a certain distance down a polyline
        /// </summary>
        /// <param name="dist">Distance in meters along the line</param>
        /// <param name="course"></param>
        /// <returns></returns>
        private double[] PointAlongLine(double dist, out double course)
        {
            double accDist = 0;

            course = double.NaN;
            if (dist > lineLength)             //reached end - move to next direction, or start over
            {
                directionIndex++;
                Route currDir;
                if (directionIndex >= m_route.Routes.Count)
                {
                    directionIndex = 0;
                }
                currDir       = m_route.Routes[directionIndex];
                lineLength    = GeometryEngine.LengthGeodetic(currDir.RouteGeometry);
                totalDistance = 0;
                drivePath     = currDir.RouteGeometry as Polyline;
                course        = 0; dist = 0;
            }
            //else
            {
                var parts = drivePath.Parts.Select(p => p.Points).ToList();
                for (int j = 0; j < parts.Count; j++)
                {
                    var part = parts[j].ToList();
                    for (int i = 0; i < part.Count - 1; i++)
                    {
                        var p1 = part[i];
                        var p2 = part[i + 1];
                        if (p1.X == p2.X && p2.Y == p2.Y)
                        {
                            continue;
                        }
                        var    result         = GeometryEngine.DistanceGeodetic(p1, p2, LinearUnits.Meters, AngularUnits.Degrees, GeodeticCurveType.Geodesic);
                        double distToWaypoint = result.Distance;
                        if (dist < accDist + distToWaypoint)
                        {
                            var    distAlongSegment = dist - accDist;
                            double fraction         = distAlongSegment / distToWaypoint;
                            course = GetTrueBearingGeodesic(p1.X, p1.Y, p2.X, p2.Y);
                            return(GetPointFromHeadingGeodesic(new double[] { p1.X, p1.Y }, distAlongSegment, course));
                        }
                        accDist += distToWaypoint;
                    }
                }
            }
            return(null);
        }
Esempio n. 7
0
        private void UpdateFollow(double speed)
        {
            // Get the current maneuver
            var maneuver = GetCurrentManeuver();

            if (maneuver == null)
            {
                return;
            }

            var maneuverLine = maneuver.Geometry as Polyline;

            if (maneuverLine == null)
            {
                return;
            }

            var maneuverLength = GeometryEngine.LengthGeodetic(maneuverLine);

            //var moveProgress = _maneuverProgress + move;

            // Have we reached the end?
            if (_maneuverProgress + speed >= maneuverLength)
            {
                if (_maneuverIndex + 1 >= _route.DirectionManeuvers.Count)
                {
                    var point1 = _location;
                    var point2 = maneuverLine.Parts[0].EndPoint;

                    // Snap to the end of the maneuver
                    _course           = GeometryHelpers.BearingGeodetic(point1, point2);
                    _location         = new MapPoint(point2.X, point2.Y, point1.SpatialReference);
                    _maneuverProgress = 0;
                }
                else
                {
                    // Snap to front of next maneuver
                    var maneuver2 = GetNextManeuver();

                    var maneuver2Line = maneuver2.Geometry as Polyline;
                    if (maneuver2Line == null)
                    {
                        return;
                    }

                    var point1 = _location;
                    var point2 = maneuver2Line.Parts[0].StartPoint;

                    _course           = GeometryHelpers.BearingGeodetic(point1, point2);
                    _location         = new MapPoint(point2.X, point2.Y, point1.SpatialReference);
                    _maneuverProgress = 0;
                }
            }
            else
            {
                // Find the next point along the current maneuver
                var point1 = _location;
                var point2 = GeometryHelpers.CreatePointAlongGeodetic(maneuverLine, _maneuverProgress + speed);

                // Update progress along maneuver
                _maneuverProgress += speed;

                // Determine whether we've reached the end of the maneuver
                if (point2 != null)
                {
                    _course   = GeometryHelpers.BearingGeodetic(point1, point2);
                    _location = point2;
                }
                else
                {
                    // Move to the next maneuver (otherwise it waits a tick to move)
                    UpdateFollow(speed);
                }
            }
        }