void CalculatePathDistance() { DrivePathDistance = 0; if (routePath != null) { MapUnit?lastPoint = null; foreach (GeoPoint node in routePath) { if (lastPoint != null) { MapUnit currentPoint = this.Navigator.RouteLayer.GeoPointToMapUnit(node); DrivePathDistance += DriveModel.DistanceBetweenPoints(currentPoint, lastPoint.Value); lastPoint = currentPoint; } else { lastPoint = this.Navigator.RouteLayer.GeoPointToMapUnit(node); } } } }
bool Advance() { if (routeNodeIndex < (routePath.Count - 1)) { routeNodeIndex++; InformationLayer routeLayer = parentModel.Navigator.RouteLayer; baseLocation = targetLocation; currentPoint = routeLayer.GeoPointToMapUnit(baseLocation); targetLocation = routePath[routeNodeIndex]; basePoint = routeLayer.GeoPointToMapUnit(baseLocation); targetPoint = routeLayer.GeoPointToMapUnit(targetLocation); distance = DriveModel.DistanceBetweenPoints(targetPoint, basePoint); currentDistance = 0; drivePath.Points[drivePath.Points.Count - 1] = baseLocation; drivePath.Points.Add(baseLocation); CheckItinerary(); CheckRoutePushpins(baseLocation); if (!animationTimer.IsEnabled) { animationTimer.Start(); } return(true); } else { if (routePushpins.Count > 0) { routePushpins[routePushpins.Count - 1].Brush = parentModel.Navigator.DriveBrush; } if (animationTimer.IsEnabled) { animationTimer.Stop(); } drivePushpin.Visible = false; return(false); } }
void AnimationTimer(object sender, EventArgs e) { double scaledTime = driveTimeQuant * parentModel.TimeScale; while (scaledTime > 0.0) { double quant = Math.Min(scaledTime, driveTimeQuant); double excess = Update(quant * DriveModel.KilometerPerHourToMapUnitsPerSecond(driveSpeed)); if (excess > 0.0) { if (!Advance()) { CheckItinerary(); PlaceItems(); return; } excess = Update(excess); } PlaceItems(); CheckItinerary(); scaledTime -= quant; } }