Exemple #1
0
        void DrawRoute(DirectionsRoute route)
        {
            Java.Util.ArrayList points = new Java.Util.ArrayList();
            IList <Com.Mapbox.Geojson.Point> coords = LineString.FromPolyline(route.Geometry(), Constants.Precision6).Coordinates();

            foreach (Com.Mapbox.Geojson.Point point in coords)
            {
                points.Add(new LatLng(point.Latitude(), point.Longitude()));
            }

            if (points.IsEmpty == false)
            {
                if (polyline != null)
                {
                    mapboxMap.RemovePolyline(polyline);
                }

                // Draw polyline on map
                polyline = mapboxMap
                           .AddPolyline(new PolylineOptions()
                                        .AddAll(points)
                                        .InvokeColor(Color.ParseColor("#4264fb"))
                                        .InvokeWidth(5));
            }
        }
 private void CreateDashedLine(List <LatLng> coords)
 {
     for (var i = 0; i < (coords.Count - 1); i += 2)
     {
         var nextLine = new ArrayList();
         nextLine.Add(coords[i]);
         nextLine.Add(coords[i + 1]);
         var polyline = new PolylineOptions();
         polyline.AddAll(nextLine);
         polyline.InvokeWidth(2);
         polyline.InvokeColor(Color.Gray);
         mapboxMap.AddPolyline(polyline);
     }
 }
Exemple #3
0
        void drawRoute(DirectionsRoute route)
        {
            // Convert LineString coordinates into LatLng[]
            var lineString  = LineString.FromPolyline(route.Geometry, Constants.OsrmPrecisionV5);
            var coordinates = lineString.Coordinates;

            LatLng[] points = new LatLng[coordinates.Count];
            for (int i = 0; i < coordinates.Count; i++)
            {
                points[i] = new LatLng(
                    coordinates[i].Latitude,
                    coordinates[i].Longitude);
            }

            // Draw Points on MapView
            map.AddPolyline(new PolylineOptions()
                            .Add(points)
                            .SetColor(Android.Graphics.Color.Red)
                            .SetWidth(5));
        }
Exemple #4
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);
            }
        }
Exemple #5
0
        private Sdk.Annotations.Annotation AddAnnotation(Annotation at)
        {
            Sdk.Annotations.Annotation options = null;
            if (at is PointAnnotation)
            {
                var marker = new MarkerOptions();
                marker.SetTitle(at.Title);
                marker.SetSnippet(at.Title);
                marker.SetPosition(((PointAnnotation)at).Coordinate.ToLatLng());
                options = map.AddMarker(marker);
            }
            else if (at is PolylineAnnotation)
            {
                var polyline = at as PolylineAnnotation;
                if (polyline.Coordinates?.Count() == 0)
                {
                    return(null);
                }
                var notifyCollection = polyline.Coordinates as INotifyCollectionChanged;
                if (notifyCollection != null)
                {
                    notifyCollection.CollectionChanged += (s, e) =>
                    {
                        if (e.Action == NotifyCollectionChangedAction.Add)
                        {
                            if (_annotationDictionaries.ContainsKey(at.Id))
                            {
                                var poly = _annotationDictionaries[at.Id] as Polyline;
                                poly.AddPoint(polyline.Coordinates.ElementAt(e.NewStartingIndex).ToLatLng());
                            }
                            else
                            {
                                var coords = new ArrayList();
                                for (var i = 0; i < polyline.Coordinates.Count(); i++)
                                {
                                    coords.Add(polyline.Coordinates.ElementAt(i).ToLatLng());
                                }
                                var polylineOpt = new PolylineOptions();
                                polylineOpt.Polyline.Width = Context.ToPixels(1);
                                polylineOpt.Polyline.Color = Android.Graphics.Color.Blue;
                                polylineOpt.AddAll(coords);
                                options = map.AddPolyline(polylineOpt);
                                _annotationDictionaries.Add(at.Id, options);
                            }
                        }
                        else if (e.Action == NotifyCollectionChangedAction.Remove)
                        {
                            if (_annotationDictionaries.ContainsKey(at.Id))
                            {
                                var poly = _annotationDictionaries[at.Id] as Polyline;
                                poly.Points.Remove(polyline.Coordinates.ElementAt(e.OldStartingIndex).ToLatLng());
                            }
                        }
                    };
                }
            }
            else if (at is MultiPolylineAnnotation)
            {
                var polyline = at as MultiPolylineAnnotation;
                if (polyline.Coordinates == null || polyline.Coordinates.Length == 0)
                {
                    return(null);
                }

                var lines = new List <PolylineOptions>();
                for (var i = 0; i < polyline.Coordinates.Length; i++)
                {
                    if (polyline.Coordinates[i].Length == 0)
                    {
                        continue;
                    }
                    var coords = new PolylineOptions();
                    for (var j = 0; j < polyline.Coordinates[i].Length; j++)
                    {
                        coords.Add(new LatLng(polyline.Coordinates[i][j].Lat, polyline.Coordinates[i][j].Long));
                    }
                    lines.Add(coords);
                }
                map.AddPolylines(lines);
            }
            if (options != null)
            {
                if (at.Id != null)
                {
                    _annotationDictionaries.Add(at.Id, options);
                }
            }

            return(options);
        }