//add route to listBox and routeStopsList private async void addRoute(int timetable_id) { RouteStops tempRouteStopData = await GetRouteStops.API_Call(timetable_id.ToString()); RoutesListBox.Items.Add(tempRouteStopData.route.long_name); routeStopsList.Add(tempRouteStopData); }
//list box event listener private void RoutesListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { //if no route has been made if (!madeRoute) { RouteStops foundRoute = new RouteStops(); //loop through routeStops list for (int i = 0; i < routeStopsList.Count; i++) { //find selected route if ((string)RoutesListBox.SelectedItem == routeStopsList[i].route.long_name) { madeRoute = true; foundRoute = routeStopsList[i]; //pass route stops into makePolyLine makePolyLine(foundRoute); break; } } } else { if ((string)RoutesListBox.SelectedItem == "Delete Route") { //remove polyline MyMap.MapElements.Remove(polyline); madeRoute = false; } } }
//make polyline. Adapted from: https://blogs.windows.com/buildingapps/2016/04/18/map-apis-and-controls-adding-external-elements/#2E3O6xjTJS6xIQHT.97 private void makePolyLine(RouteStops routeStops) { List <List <Stops> > allStops = routeStops.stops; //loop through allStops for (int i = 0; i < allStops.Count; i++) { List <Stops> theStops = allStops.ElementAt(i); polyline = new MapPolyline(); //define line polyline.StrokeColor = Colors.OrangeRed; polyline.StrokeThickness = 2; polyline.StrokeDashed = true; //create path List <BasicGeoposition> geoPositions = new List <BasicGeoposition>(); //loop through theStops for (int j = 0; j < theStops.Count(); j++) { //find a stop Stops aStop = theStops.ElementAt(j); //add geoPositions to path geoPositions.Add(new BasicGeoposition() { Latitude = aStop.latitude, Longitude = aStop.longitude }); } polyline.Path = new Geopath(geoPositions); //add polyline to map MyMap.MapElements.Add(polyline); } }