示例#1
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);
            }
        }