Exemplo n.º 1
0
        public async Task <Polyline> AddRoadPolyline(int MandadoID)
        {
            string serial = await data.GetPolyline(MandadoID);

            Java.Util.ArrayList points = new Java.Util.ArrayList(DecodePolyline(serial));

            PolylineOptions options = new PolylineOptions();

            options.AddAll(points);

            Polyline ans = map.AddPolyline(options);

            return(ans);
        }
 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);
     }
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            startLatlng = new LatLng(Intent.GetDoubleExtra("StartLatitude", 0), Intent.GetDoubleExtra("StartLongitude", 0));
            isLine      = Intent.GetBooleanExtra("isLine", false);
            if (isLine)
            {
                endLatlng = new LatLng(Intent.GetDoubleExtra("EndLatitude", 0), Intent.GetDoubleExtra("EndLongitude", 0));
            }
            SetContentView(Resource.Layout.amap_layout);
            //SetSupportActionBar(new Android.Support.V7.Widget.Toolbar(this));
            var actionBar = SupportActionBar;

            if (actionBar != null)
            {
                actionBar.SetHomeButtonEnabled(true);
                actionBar.SetDisplayHomeAsUpEnabled(true);
            }

            mapView = FindViewById <MapView>(Resource.Id.map);

            //AMapOptions options = new AMapOptions();
            //options.InvokeCamera(new CameraPosition(latlng, 15,  0, 0));
            //mapView = new MapView(this, options);
            mapView.OnCreate(savedInstanceState);

            if (aMap == null)
            {
                aMap = mapView.Map;
                //设置marker
                markerOption = new MarkerOptions().InvokeIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed))
                               .InvokeTitle("施封位置").InvokeSnippet(Intent.GetStringExtra("startAddress")).InvokePosition(startLatlng).Draggable(true);
                aMap.AddMarker(markerOption).ShowInfoWindow();
                if (isLine)
                {
                    //设置中心点
                    var update = CameraUpdateFactory.NewCameraPosition(new CameraPosition(endLatlng, 5, 0, 0));
                    aMap.MoveCamera(update);
                    //设置marker
                    MarkerOptions endMarkerOption = new MarkerOptions().InvokeIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen))
                                                    .InvokeTitle("拆封位置").InvokeSnippet(Intent.GetStringExtra("endAddress")).InvokePosition(endLatlng).Draggable(true);
                    aMap.AddMarker(endMarkerOption).ShowInfoWindow();
                    PolylineOptions polylineOptions = new PolylineOptions();
                    var             laglngs         = new ArrayList();
                    laglngs.Add(startLatlng);
                    laglngs.Add(endLatlng);
                    polylineOptions.AddAll(laglngs);
                    polylineOptions.InvokeWidth(10);
                    polylineOptions.InvokeColor(Color.Argb(255, 0, 205, 205));
                    polylineOptions.Visible(true);
                    var polyline = aMap.AddPolyline(polylineOptions);
                    polyline.Visible = true;
                    var endupdate = CameraUpdateFactory.NewCameraPosition(new CameraPosition(endLatlng, 10, 0, 0));
                    aMap.MoveCamera(update);
                }
                else
                {
                    //设置中心点
                    var update = CameraUpdateFactory.NewCameraPosition(new CameraPosition(startLatlng, 15, 0, 0));
                    aMap.MoveCamera(update);
                }
            }
        }