11using System . Collections . Generic ;
2+ using System . Drawing ;
3+ using System . Linq ;
24using Shared . Dtos ;
35using Tracked . Contexts ;
6+ using Tracked . Models ;
7+ using Tracked . Utilities ;
48using Xamarin . Forms . Maps ;
59
610namespace Tracked . Screens . Rides {
711 public class MapScreenViewModel : RideMapViewModelBase {
812 private readonly RideDto ride ;
9- private Polyline selectedTrailLine ;
13+ private MapPolyline selectedTrailLine ;
1014
1115 public MapScreenViewModel ( MainContext context , RideDto ride )
1216 : base ( context ) {
@@ -19,28 +23,25 @@ public MapScreenViewModel(MainContext context, RideDto ride)
1923 public IList < TrailAttemptDto > TrailAttempts => ride . TrailAttempts ;
2024
2125 public void HighlightTrail ( TrailAttemptDto attempt ) {
22- // if (selectedTrailLine != null) {
23- // Map.MapElements.Remove (selectedTrailLine);
24- // }
26+ if ( selectedTrailLine != null ) {
27+ RemovePolyline ( selectedTrailLine ) ;
28+ }
2529
26- //selectedTrailLine = new Polyline();
30+ selectedTrailLine = new MapPolyline {
31+ StrokeColor = Color . Blue ,
32+ StrokeWidth = 20f ,
33+ ZIndex = 0 ,
34+ Positions = ride . Locations
35+ . Where ( i => i . Timestamp >= attempt . StartUtc )
36+ . Where ( i => i . Timestamp <= attempt . EndUtc )
37+ . ToList ( ) ,
38+ } ;
2739
28- //var latLngs = ride.Locations
29- // .Where(i => i.Timestamp >= attempt.StartUtc)
30- // .Where(i => i.Timestamp <= attempt.EndUtc);
40+ CreatePolyline ( selectedTrailLine ) ;
3141
42+ var midpoint = selectedTrailLine . Positions . Midpoint ( ) ;
3243
33- //foreach (var latLng in latLngs) {
34- // selectedTrailLine.Geopath.Add(new Position(latLng.Latitude, latLng.Longitude));
35- //}
36-
37- //selectedTrailLine.StrokeColor = Color.Blue;
38- //selectedTrailLine.StrokeWidth = 20f;
39-
40- //Map.MapElements.Add(selectedTrailLine);
41-
42- //var centre = latLngs.Midpoint();
43- //Map.MoveToRegion(MapSpan.FromCenterAndRadius(centre, Distance.FromMiles(.25)));
44+ GoToLocation ( midpoint , Distance . FromMiles ( .25 ) ) ;
4445 }
4546 }
4647}
0 commit comments