private void AnimateTank()
        {
            // Return if tank already arrived.
            if (_tankEndPoint == null)
            {
                return;
            }

            // Get current location and distance from the destination.
            MapPoint location = (MapPoint)_tank.Geometry;
            GeodeticDistanceResult distance = GeometryEngine.DistanceGeodetic(
                location, _tankEndPoint, _metersUnit, _degreesUnit, GeodeticCurveType.Geodesic);

            // Move the tank a short distance.
            location = GeometryEngine.MoveGeodetic(new List <MapPoint>()
            {
                location
            }, 1.0, _metersUnit, distance.Azimuth1, _degreesUnit,
                                                   GeodeticCurveType.Geodesic).First();
            _tank.Geometry = location;

            // Rotate to face the destination.
            double heading = (double)_tank.Attributes["HEADING"];

            heading = heading + (distance.Azimuth1 - heading) / 10;
            _tank.Attributes["HEADING"] = heading;

            // Clear the destination if the tank already arrived.
            if (distance.Distance < 5)
            {
                _tankEndPoint = null;
            }
        }
Example #2
0
        private async void AssociatedObject_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
        {
            if (!IsEnabled)
            {
                return;
            }
            e.Handled = true;

            var mapView        = AssociatedObject;
            var screenPosition = e.GetPosition(AssociatedObject);

            if (IsCursorOutsideControl(screenPosition))
            {
                HideTargetScale();
                return;
            }
            _deltas += e.Delta;
            var    direction = GetDirection(_deltas);
            double factor    = (mapView.InteractionOptions.ZoomFactor * Math.Abs(_deltas / 120));
            double scale     = GetNewScale(factor, direction);

            Trace.WriteLine($"{scale}");
            // TODO: stretch or shrink current map image for visual indication of direction/scale
            UpdateTargetScale(scale);

            var delta = _deltas;
            await Task.Delay(400);

            if (delta != _deltas)
            {
                // Accumulate multiple deltas before starting the actual zoom
                return;
            }

            _deltas = 0;
            var screenLocation = mapView.ScreenToLocation(screenPosition);
            var centerLocation = (MapPoint)mapView.GetCurrentViewpoint(ViewpointType.CenterAndScale).TargetGeometry;

            var distance = GeometryEngine.DistanceGeodetic(screenLocation, centerLocation, LinearUnits.Meters, AngularUnits.Degrees,
                                                           GeodeticCurveType.Geodesic);
            double distanceValue = GetNewValue(distance.Distance, factor, direction);

            var targetCenter = GeometryEngine.MoveGeodetic(new[] { screenLocation }, distanceValue, LinearUnits.Meters,
                                                           distance.Azimuth1, distance.AzimuthUnit, GeodeticCurveType.Geodesic)
                               .First();

            await mapView.SetViewpointAsync(
                new Viewpoint(targetCenter, scale), TimeSpan.Zero);

            HideTargetScale();
        }
Example #3
0
        private void OnAddPolylinesCommand()
        {
            var points = GetPoints();

            foreach (var point in points)
            {
                var linePoints = new List <MapPoint>();
                for (int i = 0; i < 30; i++)
                {
                    linePoints.AddRange(GeometryEngine.MoveGeodetic(new[] { point }, 500, LinearUnits.Meters,
                                                                    _random.Next(0, 360),
                                                                    AngularUnits.Degrees, GeodeticCurveType.Geodesic));
                }

                var polyLine = new PolylineBuilder(linePoints, SpatialReferences.Wgs84);
                GraphicsProvider.Publish(new MapObject(polyLine.ToGeometry())
                {
                    LayerId = LayerKeys.Polyline.ToString()
                });
            }
        }
        public void PlotButton_Click(object sender, RoutedEventArgs e)
        {
            azimuthPoint = double.Parse(textAzimuth.Text);

            distancePoint = double.Parse(textDistance.Text);
            //distanceList.Add(distancePoint);


            if (azimuthPoint <= 360)
            {
                if (azimuthPoint <= 180)
                {
                    var result = azimuthPoint;
                    //azimuthList.Add(result);
                    //TraverseData.AzimuthList.Add(result);
                    //azimuthList.Add(result);
                }

                if (azimuthPoint > 180)
                {
                    var result = 180 - (azimuthPoint);
                    //azimuthList.Add(result);
                    //TraverseData.AzimuthList.Add(result);
                    //azimuthList.Add(result);
                }

                textAzimuth.Text  = "";
                textDistance.Text = "";
            }

            double result1;
            double result2;

            //GeodeticDistanceResult distance = GeometryEngine.DistanceGeodetic(start, destination, LinearUnits.Meters, AngularUnits.Degrees, GeodeticCurveType.NormalSection);

            IReadOnlyList <MapPoint> coordinateList = GeometryEngine.MoveGeodetic(mapPoints, distancePoint, LinearUnits.Meters, azimuthPoint, AngularUnits.Degrees, GeodeticCurveType.NormalSection);
            GeodeticDistanceResult   travel         = GeometryEngine.DistanceGeodetic(start, coordinateList[0], LinearUnits.Meters, AngularUnits.Degrees, GeodeticCurveType.NormalSection);



            graphic1.Geometry = coordinateList[0];

            if (travel.Azimuth1 >= 0)
            {
                result1 = travel.Azimuth1;
            }
            else
            {
                result1 = travel.Azimuth1 + 360;
            }
            if (travel.Azimuth2 >= 0)
            {
                result2 = travel.Azimuth2;
            }
            else
            {
                result2 = travel.Azimuth2 + 360;
            }
            textBox.Text = string.Format($"Distance:{travel.Distance} | Azimuth1:{result1} | Azimuth2:{result2} |Initial Point :410175.775805, 552181.881083");


            //textBox.Text = string.Format("{0} kilometers", (int)distance);
            // Get the points that define the route polyline.
            Esri.ArcGISRuntime.Geometry.PointCollection polylinePoints = new Esri.ArcGISRuntime.Geometry.PointCollection(new SpatialReference(3168))
            {
                (MapPoint)_startLocationGraphic.Geometry,
                coordinateList[0]
            };

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


            // Densify the polyline to show the geodesic curve.
            Esri.ArcGISRuntime.Geometry.Geometry pathGeometry = GeometryEngine.DensifyGeodetic(routeLine, 1, LinearUnits.Kilometers, GeodeticCurveType.Geodesic);
            // Apply the curved line to the path graphic.
            _pathGraphic.Geometry = pathGeometry;
        }