/// <summary> /// The simulator moves to the start of the route. /// </summary> public void SeekStart() { // Snap to the closest point on route 0 if (State != SimulationState.Seeking) { var route0 = GeometryHelpers.Flatten(_route.RouteGeometry); var result = GeometryEngine.NearestCoordinate(route0, _location); _target = result.Coordinate; State = SimulationState.Seeking; } }
private void UpdateWander(double speed) { if (_location == null) { return; } // Find closest point on the route var nearestResult = GeometryEngine.NearestCoordinate(_route.RouteGeometry, _location); var nearest = nearestResult.Coordinate; // Move away from the nearest coordinate var bearingToward = GeometryHelpers.BearingGeodetic(_location, nearest); var bearing = GeometryHelpers.NormalizeBearing(bearingToward + 180); // directly away // Keep on moving _course = bearing; _location = GeometryHelpers.CreatePointAlongGeodetic(_location, bearing, speed); }
private void UpdateSeek(double speed) { if (_location == null || _target == null) { return; } // Determine distance between current location and target location var distanceResult = GeometryEngine.DistanceGeodetic(_location, _target, LinearUnits.Meters, AngularUnits.Degrees, GeodeticCurveType.Geodesic); var distance = distanceResult.Distance; if (speed <= distance) { // Move toward the point if we're not "close enough" _course = GeometryHelpers.BearingGeodetic(_location, _target); _location = GeometryHelpers.CreatePointAlongGeodetic(_location, _course, speed); } else { // We've reached the point, start following the route State = SimulationState.Following; } }
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); } } }