Beispiel #1
0
        private void bindStartSelectButtonDelegates(Button start, Button select,
                                                    AutoCompleteTextView originBox, AutoCompleteTextView destinationBox)
        {
            select.Click += async delegate
            {
                //Gets the coordinates for the origin and destination points
                double[] originCoords      = mbi.ConvertAddressToGpsCoordinates(originBox.Text, map.MyLocation.Latitude, map.MyLocation.Longitude);
                double[] destinationCoords = mbi.ConvertAddressToGpsCoordinates(destinationBox.Text, map.MyLocation.Latitude, map.MyLocation.Longitude)
                ;
                //Clears old routes
                Tools.clearRoutes(map);

                //Asks Otp for response based on the origin and destination
                otpResponse = await OtpAPI.Query(originCoords, destinationCoords);

                //Plots the first two routes in the response
                Tools.plotRoute(otpResponse, map, 2, colors);

                //Sets the camera to show the overall route
                Tools.setRoutingCamera(originCoords, destinationCoords, map);

                //Parses the itinerary, uses it to create an adapter for a recycler view
                Itinerary itin    = OtpAPI.ParseItinerary(otpResponse["plan"]["itineraries"][0]);
                var       adapter = new RouteSummaryRowAdapter(itin);

                //Binds the adapter to the recyclerView
                var rv = FindViewById <RecyclerView>(Resource.Id.slidingRecycler);
                rv.SetAdapter(adapter);

                //Sets the start button to be fully opaque and clickable
                start.Alpha     = 1;
                start.Clickable = true;

                //Slides up the bottom panel to show the route summary
                FindViewById <SlidingUpPanelLayout>(Resource.Id.sliding_layout).SetPanelState(SlidingUpPanelLayout.PanelState.Expanded);
            };
            start.Click += delegate {
                //Reconfigures the ui for the navigation mode, now that the user wants to start navigation
                reconfigureUiForNavigation(0);
            };
        }
Beispiel #2
0
        /**Turn By Turn Navigation Ui**/

        private void reconfigureUiForNavigation(int itineraryIndex)
        {
            //Disable the actv layout, and route/start buttons
            FindViewById <LinearLayout>(Resource.Id.actvLayout).Visibility = ViewStates.Gone;
            FindViewById <Button>(Resource.Id.startButton).Visibility      = ViewStates.Gone;
            FindViewById <Button>(Resource.Id.routeButton).Visibility      = ViewStates.Gone;

            //Binds a variable to the recyclerView
            RecyclerView recyclerView = FindViewById <RecyclerView>(Resource.Id.slidingRecycler);

            //Parses the itinerary selected
            Itinerary itin = OtpAPI.ParseItinerary(otpResponse["plan"]["itineraries"][itineraryIndex]);

            //Binds a variable to a configured recycler view
            recyclerView = Tools.configureRecyclerViewForNavigation(itin, recyclerView);

            //Sets up the turn by turn ui (the upper section)
            initializeUpperNavigationUi(itin, recyclerView);

            //Sets the first row in the recyclerView to be highlighted
            ((StepRowAdapter)recyclerView.GetAdapter()).HighlightedRow = 0;

            //Hides the recentering button when navigating
            Tools.toggleVisibility(FindViewById <FloatingActionButton>(Resource.Id.recenterOnUserActionButton));

            //Binds the backToRoutingButton to go back to the routing screen
            Button backToRoutingButton = FindViewById <Button>(Resource.Id.backToRoutingButton);

            backToRoutingButton.Click += delegate
            {
                //TODO: implement reverse screen reconfiguration
                reconfigureUiForRouting();
            };

            //Configures the station image thumbnail with the sample image
            configureStationImage();

            //Starts turn by turn tracking for stepping through the steps
            initializeTurnByTurnTracking(itin, recyclerView);
        }
Beispiel #3
0
        //Plots routes on the map
        public static void plotRoute(JObject response, MapboxMap map, int count, int[] colors)
        {
            //Parses the routes from the response into a list of points, stores all routes in a list
            List <List <double[]> > routes = OtpAPI.GetRoutePoints(response);

            //Handles case in which there are no routes to the destination
            if (routes.Count() == 0)
            {
                //TODO: Show message to user that no routes are possible
            }

            //Iterates over the routes in the response, plotting each one in a different color.
            //The first route is plotted with full opacity, while the rest are 50% transparent.
            for (int i = 0; i < Math.Min(routes.Count(), count); i++)
            {
                //Sets up a new polyline options object to be plotted on the map
                var polylineOpts = new PolylineOptions();
                //Adds each point in the route to the polyline
                foreach (double[] point in routes[i])
                {
                    polylineOpts.Add(new LatLng(point[0], point[1]));
                }
                //Set a dark thick line if it's the primary route
                if (i == 0)
                {
                    polylineOpts.SetAlpha(1F);
                    polylineOpts.SetWidth(5F);
                }
                //Set a lighter, thinner, line if it's a secondary one
                else
                {
                    polylineOpts.SetAlpha(.5F);
                    polylineOpts.SetWidth(3F);
                }
                //Sets the color according to the set in the colors field
                polylineOpts.SetColor(colors[i % 3]);
                //Plots the polyline on the map
                map.AddPolyline(polylineOpts);
            }
        }