예제 #1
0
        public void OnMapReady(MapboxMap map)
        {
            var uiSettings = map.UiSettings;

            uiSettings.SetAllGesturesEnabled(true);

            var marker = new MarkerOptions();

            marker.SetTitle("Los Angeles");
            marker.SetSnippet("City Hall");
            marker.SetPosition(LOS_ANGELES);

            map.AddMarker(marker);

            marker.SetTitle("New York");
            marker.SetSnippet("City Hall");
            marker.SetPosition(NEW_YORK);

            map.AddMarker(marker);

            var bounds = new LatLngBounds.Builder()
                         .Include(NEW_YORK)
                         .Include(LOS_ANGELES)
                         .Build();

            map.MoveCamera(CameraUpdateFactory.NewLatLngBounds(bounds, 8));
        }
 public void OnMapReady(MapboxMap mapboxMap)
 {
     mapboxMap.AddMarker(new Com.Mapbox.Mapboxsdk.Annotations.MarkerOptions().SetPosition(new LatLng(40.416717, -3.703771)).SetTitle("spain"));
     mapboxMap.AddMarker(new Com.Mapbox.Mapboxsdk.Annotations.MarkerOptions().SetPosition(new LatLng(26.794531, 29.781524)).SetTitle("egypt"));
     mapboxMap.AddMarker(new Com.Mapbox.Mapboxsdk.Annotations.MarkerOptions().SetPosition(new LatLng(50.981488, 10.384677)).SetTitle("germany"));
     mapboxMap.InfoWindowAdapter = new InfoWindowAdapter(_context);
 }
예제 #3
0
        public void OnMapClick(LatLng point)
        {
            if (!running || mapboxMap == null)
            {
                return;
            }

            mapboxMap.AddMarker(Android.Runtime.Extensions.JavaCast <MarkerOptions>(new MarkerOptions().Position(point)));
            mapboxMap.SetOnMapClickListener(null);

            Com.Mapbox.Geojson.Point newDestination = Com.Mapbox.Geojson.Point.FromLngLat(point.Longitude, point.Latitude);
            mockLocationEngine.MoveToLocation(newDestination);
            destination = Com.Mapbox.Geojson.Point.FromLngLat(point.Longitude, point.Latitude);
            tracking    = false;
        }
예제 #4
0
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            mapView             = FindViewById <MapView> (Resource.Id.mapview);
            mapView.AccessToken = GetString(Resource.String.mapboxAccessToken);
            mapView.StyleUrl    = Mapbox.Constants.Style.Emerald;
            mapView.OnCreate(bundle);

            // Get the map instance
            map = await mapView.GetMapAsync();

            map.MarkerClick += async(sender, e) => {
                e.Handled = false;
                Toast.MakeText(this, "Marker Click: " + e.Marker.Title, ToastLength.Short).Show();
            };
            map.InfoWindowClick += async(sender, e) => {
                Toast.MakeText(this, "Info Window Click: " + e.Marker.Title, ToastLength.Short).Show();
            };
            map.AddMarker(new MarkerOptions()
                          .SetTitle("Test Marker")
                          .SetPosition(new LatLng(41.885, -87.679)));

            var position = new CameraPosition.Builder()
                           .Target(new LatLng(41.885, -87.679)) // Sets the new camera position
                           .Zoom(11)                            // Sets the zoom
                           .Build();                            // Creates a CameraPosition from the builder

            map.AnimateCamera(CameraUpdateFactory.NewCameraPosition(position), 3000);
        }
예제 #5
0
        protected override void OnStart()
        {
            int i = 0;

            base.OnStart();
            // this.AttachEvents();
            this.mapView.OnStart();
            if (this.firstLoad)
            {
                this.firstLoad = false;
                this.performOperatoinOnMap((map) =>
                {
                    this.Map = map;
                    this.Map.UiSettings.RotateGesturesEnabled = false;
                    this.Map.SetOnMapClickListener(this);
                    //this.Map.SetOnMarkerClickListener(this);
                    this.Map.SetOnScrollListener(this);
                    this.ZoomToDefaultView();
                    var position = new CameraPosition.Builder()
                                   .Target(new LatLng(28.60831, 77.36114))
                                   .Zoom(8)
                                   .Build();


                    foreach (var item in lstLatLng)
                    {
                        markerViewOptions = new MarkerViewOptions();
                        markerViewOptions.InvokeIcon(StoppedIcon);
                        markerViewOptions.InvokePosition(item);
                        markerViewOptions.InvokeRotation((float)item.Latitude);
                        markerViewOptions.InvokeSnippet("Well come to RSystem");
                        markerViewOptions.InvokeTitle("RSystem");
                        Map.AddMarker(markerViewOptions);
                        // lstMarker.Add(markerViewOptions);

                        polylineOptions.Add(item);
                        polylineOptions.InvokeWidth(5);
                        if (i % 2 == 0)
                        {
                            polylineOptions.InvokeColor(Color.Red);
                        }
                        else
                        {
                            polylineOptions.InvokeColor(Color.Green);
                        }
                        // lstPolyline.Add(polylineOptions);
                        //  Map.AddPolyline(polylineOptions);
                        i++;
                    }

                    // Map.AddPolylines(lstPolyline);

                    this.Map.MoveCamera(CameraUpdateFactory.NewCameraPosition(position));
                });
            }
        }
 private void SetCurrentMarkerPosition(LatLng position)
 {
     if (position != null)
     {
         if (currentMarker == null)
         {
             var markerViewOptions = new MarkerViewOptions().InvokePosition(position);
             currentMarker = mapboxMap.AddMarker(Android.Runtime.Extensions.JavaCast <MarkerViewOptions>(markerViewOptions));
         }
         else
         {
             currentMarker.Position = (position);
         }
     }
 }
예제 #7
0
        void DefaultPins_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (DefaultPin pin in e.NewItems)
                {
                    nMap.AddMarker(new MarkerOptions().SetPosition(pin.Position.toNativeLatLng()).SetTitle(pin.Title));
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                //nMap.RemoveMarker();
                break;

            case NotifyCollectionChangedAction.Reset:
                nMap.Markers.All((arg) => { nMap.RemoveMarker(arg); return(true); });
                break;
            }
        }
        public void OnMapReady(MapboxMap map)
        {
            var uiSettings = map.UiSettings;

            uiSettings.SetAllGesturesEnabled(true);

            map.AddMarker(new MarkerOptions()
                          .SetTitle("Austin")
                          .SetSnippet("Texas, Baby")
                          .SetPosition(new LatLng(30.266461, -97.748630)));

            var bounds = new LatLngBounds.Builder()
                         .Include(new LatLng(30.266461, -97.748630))
                         .Include(new LatLng(30, -97))
                         .Build();

            map.InfoWindowClick += Map_InfoWindowClick;
            map.CameraChange    += Map_CameraChange;

            map.MoveCamera(CameraUpdateFactory.NewLatLngBounds(bounds, 8));
        }
        public async void OnMapReady(MapboxMap mapBoxMap)
        {
            Toast.MakeText(_context, "Mapready invoked", ToastLength.Short).Show();
            _mapBoxMap = mapBoxMap;
            _mapBoxMap.SetStyle(Style.MapboxStreets);
            if (Connectivity.NetworkAccess != NetworkAccess.Internet)
            {
                //Getting the last downloaded definition to move the camera so that we see something when the map is loaded.
                var definition = await GetDefinition();

                _mapBoxMap.AnimateCamera(CameraUpdateFactory.NewCameraPosition(new CameraPosition.Builder()
                                                                               .Target(definition.Bounds.Center)
                                                                               .Zoom(definition.MaxZoom).Build()));
            }
            else
            {
                var position = new CameraPosition.Builder()
                               .Target(new LatLng(13.0664, 80.2844))
                               .Zoom(15)
                               .Build();
                _mapBoxMap.AnimateCamera(CameraUpdateFactory.NewCameraPosition(position));

                Toast.MakeText(_context,
                               $"Camera location pointed to Anna square, Chennai Lat : 13.0664 / Long: 80.2844",
                               ToastLength.Short)
                .Show();

                var markerOptions = new MarkerOptions();
                markerOptions.SetPosition(new LatLng(13.0664, 80.2844));
                markerOptions.SetTitle("Anna square");
                markerOptions.SetIcon(IconFactory.GetInstance(_context)
                                      .FromResource(Resource.Drawable.mapbox_marker_icon_default));

                _mapBoxMap.AddMarker(markerOptions);
            }
        }
예제 #10
0
        protected override void OnCreate(Bundle bundle)
        {
            int i = 0;

            //lstMarker.Add(new MarkerOptions().SetPosition(new LatLng(28.6026, 77.3769)).SetTitle("RSystem").SetSnippet("Well come to RSystem").SetIcon(StoppedIcon));
            //lstMarker.Add(new MarkerOptions().SetPosition(new LatLng(28.628454, 77.376945)).SetTitle("RSystem").SetSnippet("Well come to RSystem").SetIcon(StoppedIcon));
            //lstMarker.Add(new MarkerOptions().SetPosition(new LatLng(28.5996, 77.3736)).SetTitle("RSystem").SetSnippet("Well come to RSystem").SetIcon(StoppedIcon));
            //lstMarker.Add(new MarkerOptions().SetPosition(new LatLng(28.5974, 77.3827)).SetTitle("RSystem").SetSnippet("Well come to RSystem").SetIcon(StoppedIcon));
            base.OnCreate(bundle);
            btnZoomOut        = (Button)this.FindViewById <Button>(Resource.Id.zoomOutButton);
            btnZoomOut.Click += BtnZoomOut_Click;

            btnInOut        = this.FindViewById <Button>(Resource.Id.zoomInButton);
            btnInOut.Click += BtnInOut_Click;


            mapSwitcherImg        = this.FindViewById <ImageView>(Resource.Id.mapSwitcher);
            mapSwitcherImg.Click += MapSwitcherImg_Click;

            Com.Mapbox.Mapboxsdk.Mapbox.GetInstance(this, "pk.eyJ1Ijoic2FjaGluLXNhaW5pIiwiYSI6ImNqbzAyNHd5YTE5eHQzcW8wa3ptOWhiaXkifQ.jYVRdAzrjIGfsWVt34CB7w");

            mapView = FindViewById <MapView>(Resource.Id.mapView);
            mapView.SetStyleUrl(Style.MapboxStreets);
            mapView.OnCreate(bundle);
            this.performOperatoinOnMap((map) =>
            {
                this.Map     = map;
                var position = new CameraPosition.Builder()
                               .Target(new LatLng(28.60831, 77.36114))
                               .Zoom(8)
                               .Build();
                Map.AddMarker(new MarkerOptions().SetPosition(new LatLng(28.6208, 77.3639)).SetTitle("RSystem").SetSnippet("Well come to RSystem"));
                this.Map.MoveCamera(CameraUpdateFactory.NewCameraPosition(position));
            });
            //  SupportActionBar.SetDisplayHomeAsUpEnabled(false);
        }
예제 #11
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);
        }
예제 #12
0
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            Mapbox.MapboxAccountManager.Start(this, GetString(Resource.String.mapboxAccessToken));

            mapView          = FindViewById <MapView> (Resource.Id.mapview);
            mapView.StyleUrl = Mapbox.Constants.Style.Light;
            mapView.OnCreate(bundle);

            // Get the map instance
            map = await mapView.GetMapAsync();

            map.MarkerClick += async(sender, e) => {
                e.Handled = false;
                Toast.MakeText(this, "Marker Click: " + e.Marker.Title, ToastLength.Short).Show();
            };
            map.InfoWindowClick += async(sender, e) => {
                Toast.MakeText(this, "Info Window Click: " + e.Marker.Title, ToastLength.Short).Show();
            };
            map.AddMarker(new MarkerOptions()
                          .SetTitle("Test Marker")
                          .SetPosition(new LatLng(41.885, -87.679)));

            var origin      = Mapbox.Services.Commons.Models.Position.FromCoordinates(-87.611331, 41.718542);
            var destination = Mapbox.Services.Commons.Models.Position.FromCoordinates(-87.598800, 41.788592);

            // Add origin and destination to the map
            map.AddMarker(new MarkerOptions()
                          .SetPosition(new LatLng(origin.Latitude, origin.Longitude))
                          .SetTitle("Chicago State University"));
            map.AddMarker(new MarkerOptions()
                          .SetPosition(new LatLng(destination.Latitude, destination.Longitude))
                          .SetTitle("University of Chicago"));

            var position = new CameraPosition.Builder()
                           .Target(new LatLng(41.885, -87.679)) // Sets the new camera position
                           .Zoom(9)                             // Sets the zoom
                           .Build();                            // Creates a CameraPosition from the builder

            map.AnimateCamera(CameraUpdateFactory.NewCameraPosition(position), 3000);


            var mdb = new Mapbox.Services.Directions.V5.MapboxDirections.Builder()
                      .SetAccessToken(Mapbox.MapboxAccountManager.Instance.AccessToken)
                      .SetOrigin(origin)
                      .SetDestination(destination)
                      .SetProfile(Mapbox.Services.Directions.V5.DirectionsCriteria.ProfileDriving)
                      .Build();

            var directionsResponse = await mdb.ExecuteCallAsync();

            var route = directionsResponse?.Routes?.FirstOrDefault();

            if (route != null)
            {
                drawRoute(route);
            }
        }
        //Implements the IOnMapReadyCallback interface
        public void OnMapReady(MapboxMap map)
        {
            mapboxMap = map;

            // This will refer to OnStyleLoaded
            map.SetStyle(Style.MapboxStreets, this);
            var title1 = "Chicago";
            var lat1   = 41.897627;
            var lng1   = -87.643526;
            var title2 = "St.Louis";
            var lat2   = 38.742291;
            var lng2   = -90.064928;

            pickupPoint   = new LatLng(lat1, lng1);
            delivertPoint = new LatLng(lat2, lng2);

            bool crossesMeridianOrDateline;

            if ((lng1 > 0.0 && lng2 < 0.0) || (lng1 < 0.0 && lng2 > 0.0))
            {
                crossesMeridianOrDateline = true;
            }
            else
            {
                crossesMeridianOrDateline = false;
            }

            var xDiffPrimeMeridianZero = FindXDiffPrimeMeridianZero(lng1, lng2);
            var xDiffDatelineZero      = FindXDiffDatelineZero(lng1, lng2);

            List <double> xList;
            List <double> lngList;

            if ((Math.Abs(xDiffDatelineZero) > Math.Abs(xDiffPrimeMeridianZero)) && crossesMeridianOrDateline == true)
            {
                var latCenter = (lat1 + lat2) / 2.0;

                // Find center coordinate here
                var    x1      = FindXPrimeMeridianZero(lng1);
                var    xCenter = x1 + (xDiffPrimeMeridianZero / 2.0);
                double lngCenter;

                if (x1 > 180.0)
                {
                    lngCenter = xCenter - 360.0;
                }
                else
                {
                    lngCenter = xCenter;
                }

                var cameraCenter = new CameraPosition.Builder().Target(new LatLng(latCenter, lngCenter)).Zoom(1.5).Build();

                map.AnimateCamera(CameraUpdateFactory.NewCameraPosition(cameraCenter));

                xList   = CreateXList(xDiffPrimeMeridianZero, x1);
                lngList = ConvertToLngsPrimeMeridianZero(xList);
            }
            else
            {
                // find max/min lat/lng here
                // use those to determine the initialBounds

                var latDict = FindLowHigh(lat1, lat2);
                var latHigh = latDict["high"];
                var latLow  = latDict["low"];
                var lngDict = FindLowHigh(lng1, lng2);
                var lngHigh = lngDict["high"];
                var lngLow  = lngDict["low"];

                var latBuffer = (latHigh - latLow) / 4.0;
                var lngBuffer = (lngHigh - lngLow) / 10.0;

                var swLat = latLow - latBuffer;
                var swLng = lngLow - lngBuffer;
                var neLat = latHigh + latBuffer;
                var neLng = lngHigh + lngBuffer;

                var swPoint = new LatLng(swLat, swLng);
                var nePoint = new LatLng(neLat, neLng);

                var latLngBounds = new LatLngBounds.Builder()
                                   .Include(nePoint) // Northeast
                                   .Include(swPoint) // Southwest
                                   .Build();

                mapboxMap.EaseCamera(CameraUpdateFactory.NewLatLngBounds(latLngBounds, 0));

                xList   = CreateXList(xDiffDatelineZero, FindXDatelineZero(lng1));
                lngList = ConvertToLngsDatelineZero(xList);
            }

            var yList = CreateYList(lat1, lat2);

            var latList = ConvertToLats(yList);
            var coords  = ConvertToCoords(latList, lngList);

            CreateDashedLine(coords);

            var marker1 = new MarkerOptions();
            var marker2 = new MarkerOptions();

            marker1.SetPosition(pickupPoint);
            marker1.SetTitle(title1);
            marker2.SetPosition(delivertPoint);
            marker2.SetTitle(title2);
            map.AddMarker(marker1);
            map.AddMarker(marker2);
        }