/// <summary> /// Draws the route's polyline on the map and lays down map markers which correspond to the route's stops. /// </summary> private void DrawRouteAndItsStopsOnMap(Route route) { // Clear out anything else, otherwise we end up with one ugly map. RouteMap.MapElements.Clear(); DrawRoutePolyline(route); var stopsInRoute = route.Path.Select(p => StopLookup[p]); var routeCenter = new BasicGeoposition() { // Best attempt to center the route on the page is to average Lat/Longs Latitude = stopsInRoute.Select(s => s.Lat).Average(), Longitude = stopsInRoute.Select(s => s.Long).Average() }; Task.Run(() => RouteMap.TrySetViewAsync(new Geopoint(routeCenter), 14, 0, 0, MapAnimationKind.Bow)); foreach (var stopId in route.Path) { var pin = new MapIcon() { Location = new Geopoint(new BasicGeoposition() { Latitude = StopLookup[stopId].Lat, Longitude = StopLookup[stopId].Long }) }; RouteMap.MapElements.Add(pin); } }
/// <summary> /// Draws the route's GoogleMaps polyline on the map. /// </summary> private void DrawRoutePolyline(Route route) { var polyLine = new MapPolyline(); polyLine.Path = new Geopath(route.PolyLinePositions); // Taken from here: http://stackoverflow.com/a/5800540 uint argb = uint.Parse(route.Color.Replace("#", ""), NumberStyles.HexNumber); byte r = (byte)((argb & 0xff0000) >> 0x10); byte g = (byte)((argb & 0xff00) >> 8); byte b = (byte)(argb & 0xff); polyLine.StrokeColor = Color.FromArgb(/* Just make it 100% */ 0xAA, r, g, b); polyLine.StrokeThickness = 5; RouteMap.MapElements.Add(polyLine); }
/// <summary> /// Handles displaying a route on a map when one of the routes is clicked in the Nav Menu. /// </summary> private void NavMenuList_ItemInvoked(object sender, ListViewItem e) { var list = sender as NavMenuListView; if (list == null) { // Sweep this problem under the rug by failing silently. return; } var route = (sender as NavMenuListView)?.ItemFromContainer(e) as Route; if (route == null) { // Sweep this problem under the rug by failing silently. return; } SelectedRoute = route; if (route.Path != null && route.Path.Any()) { DrawRouteAndItsStopsOnMap(route); } }