private void LoadPins(object sender)
        {
            if (Control != null)
            {
                var formsMap = (ExtendedMap)sender;

                NativeMap.Clear();
                if (formsMap.ItemsSource != null)
                {
                    var formsPins = formsMap.ItemsSource;

                    foreach (var formsPin in formsPins)
                    {
                        var markerWithIcon = new MarkerOptions();

                        markerWithIcon.SetPosition(new LatLng(formsPin.Latitude, formsPin.Longitude));
                        markerWithIcon.SetTitle(formsPin.Name);
                        markerWithIcon.SetSnippet(formsPin.Description);
                        markerWithIcon.SetIcon(BitmapDescriptorFactory.FromResource(GetPinIcon()));

                        NativeMap.AddMarker(markerWithIcon);
                    }
                }
            }
        }
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName.Equals("VisibleRegion") && !isDrawn)
            {
                NativeMap.Clear();
                NativeMap.InfoWindowClick += OnInfoWindowClick;
                NativeMap.SetInfoWindowAdapter(this);

                // for route
                //var polylineOptions = new PolylineOptions();
                //polylineOptions.InvokeColor(0x66FF0000);

                //foreach (var position in routeCoordinates)
                //{
                //	polylineOptions.Add(new LatLng(position.Latitude, position.Longitude));
                //}

                //NativeMap.AddPolyline(polylineOptions);

                // for pins
                foreach (var pin in customPins)
                {
                    var marker = new MarkerOptions();
                    marker.SetPosition(new LatLng(pin.Pin.Position.Latitude, pin.Pin.Position.Longitude));
                    marker.SetTitle(pin.Pin.Label);
                    marker.SetSnippet(pin.Pin.Address);
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.pin));

                    NativeMap.AddMarker(marker);
                }
                isDrawn = true;
            }
        }
예제 #3
0
        protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(CustomMap.RouteCoordinatesProperty) ||
                e.PropertyName == nameof(CustomMap.LocationsProperty) ||
                e.PropertyName == nameof(CustomMap.IsRouteVisibleProperty))
            {
                if (_isRendering)
                {
                    return;
                }
                _isRendering = true;
                NativeMap.Clear();

                _map.UpdatePins();
                _map.FocusPins();

                if (_map.IsRouteVisible)
                {
                    DrawRoute();
                }
                else
                {
                    ClearRoute();
                }
                _isRendering = false;
            }
        }
예제 #4
0
        private void OnUpdateFeatures()
        {
            _polygons.Clear();
            var mapView = (UI.Controls.MapView)Element;

            if (mapView == null || NativeMap == null || !_mapReady)
            {
                _polygonsQueued = true;
                return;
            }

            _polygonsQueued = false;

            FormsMapView = mapView;

            NativeMap.Clear();

            List <Feature> features = mapView?.Features?.Features;

            if (features == null || features.Count() == 0)
            {
                return;
            }

            foreach (Feature feature in mapView.Features.Features)
            {
                CreatePolygonAndReturnCoordinatesFor(feature);
            }
        }
예제 #5
0
        private void ShowRouteOverview()
        {
            NativeMap.Clear();

            PolylineOptions selectedRoutePolyline = new PolylineOptions();

            selectedRoutePolyline.InvokeColor(Resource.Color.colorPrimaryDark);
            selectedRoutePolyline.InvokeWidth(20f);

            LatLng[] allRoutePoints = _xamap.SelectedRoute.Legs
                                      .SelectMany(leg => leg.Points)
                                      .Select(point => new LatLng(point.Latitude, point.Longitude))
                                      .ToArray();

            selectedRoutePolyline.Add(allRoutePoints);
            NativeMap.AddPolyline(selectedRoutePolyline);

            LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
            LatLngBounds         routeBounds   = allRoutePoints
                                                 .Aggregate(boundsBuilder, (builder, latLng) => builder.Include(latLng))
                                                 .Build();

            CameraUpdate routeOverviewMapUpdate = CameraUpdateFactory.NewLatLngBounds(routeBounds, 50);

            NativeMap.AnimateCamera(routeOverviewMapUpdate);
        }
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            //System.Console.WriteLine("THis is customPins count: " + customPins.Count);

            if (e.PropertyName.Equals("VisibleRegion") && !isDrawn)
            {
                var formsMap = (CustomMap)Element;
                NativeMap.Clear();
                NativeMap.InfoWindowClick += OnInfoWindowClick;
                NativeMap.SetInfoWindowAdapter(this);

                foreach (var pin in formsMap.CustomPins)
                {
                    var marker = new MarkerOptions();
                    marker.SetPosition(new LatLng(pin.Pin.Position.Latitude, pin.Pin.Position.Longitude));
                    marker.SetTitle(pin.Pin.Label);
                    marker.SetSnippet(pin.Pin.Address);
                    //marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.pin));

                    NativeMap.AddMarker(marker);
                }
                isDrawn = true;
            }
        }
예제 #7
0
        protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName.Equals("VisibleRegion") && !isDrawn)
            {
                NativeMap.UiSettings.ZoomControlsEnabled     = false;
                NativeMap.UiSettings.MyLocationButtonEnabled = false;
                NativeMap.UiSettings.RotateGesturesEnabled   = false;


                NativeMap.Clear();

                foreach (var pin in customPins)
                {
                    var marker = new MarkerOptions();
                    marker.SetPosition(new LatLng(pin.Pin.Position.Latitude, pin.Pin.Position.Longitude));
                    marker.SetTitle(pin.Pin.Label);
                    marker.SetSnippet(pin.Pin.Address);
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.custompin));
                    NativeMap.AddMarker(marker);

                    DrawCircles(new Point(pin.Pin.Position.Latitude, pin.Pin.Position.Longitude));
                }
                isDrawn = true;
            }
        }
예제 #8
0
        public void OnMapClick(LatLng point)
        {
            NativeMap.AnimateCamera(CameraUpdateFactory.NewLatLng(point));
            var marker = new MarkerOptions();

            marker.SetPosition(new LatLng(point.Latitude, point.Longitude));
            marker.SetTitle("New Title");
            marker.SetSnippet("Latitude:" + point.Latitude + " Longitude:" + point.Latitude);
            marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.pin));
            NativeMap.AddMarker(marker);

            NativeMap.Clear();
            var pin = new CustomPin
            {
                Pin = new Pin
                {
                    Type     = PinType.Place,
                    Position = new Position(point.Latitude, point.Longitude),
                    Label    = "Xamarin San Francisco Office",
                    Address  = "394 Pacific Ave, San Francisco CA"
                },
                Id  = "Xamarin",
                Url = "http://xamarin.com/about/"
            };

            customPins.Add(pin);
            //cMap.an
            // map.animateCamera(CameraUpdateFactory.newLatLng(arg0));
            // NewCameraPosition
        }
        private void UpdatePins()
        {
            var mapTile = (MapTile)Element;

            NativeMap.Clear();

            var pinItems = mapTile.PinList;

            foreach (var pinItem in pinItems)
            {
                var imageBytes = pinItem.PrimaryCategory.GetIconThemeBytes();
                var icon       = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);

                var marker = new MarkerOptions();
                marker.SetPosition(new LatLng(pinItem.Latitude, pinItem.Longitude));
                marker.SetSnippet(pinItem.Id);
                marker.SetIcon(BitmapDescriptorFactory.FromBitmap(icon));

                NativeMap.AddMarker(marker);
            }

            if (LocationMarkerOptions.Position != null)
            {
                LocationMarker = NativeMap.AddMarker(LocationMarkerOptions);
            }

            UpdateLocationPinPosition();
        }
예제 #10
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName.Equals("VisibleRegion") && !isDrawn)
            {
                NativeMap.Clear();
                NativeMap.InfoWindowClick += OnInfoWindowClick;
                NativeMap.SetInfoWindowAdapter(this);

                foreach (var pin in customPins)
                {
                    var marker = new MarkerOptions();
                    marker.SetPosition(new LatLng(pin.Pin.Position.Latitude, pin.Pin.Position.Longitude));
                    marker.SetTitle(pin.Pin.Label);
                    marker.SetSnippet(pin.Pin.Address);
                    if (pin.Estado == true)
                    {
                        marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.pin));
                    }
                    else
                    {
                        marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.pin2));
                    }
                    NativeMap.AddMarker(marker);
                }
                isDrawn = true;
            }
        }
예제 #11
0
        private void MarcarUbicacionActual(CustomMap mapCustom)
        {
            var ubicacion = mapCustom.UbicacionActual;

            if (ubicacion != null)
            {
                NativeMap.Clear();
                MarkerOptions miUbicacion = new MarkerOptions();
                miUbicacion.SetPosition(new LatLng(ubicacion.Latitud.Value, ubicacion.Longitud.Value));
                NativeMap.AddMarker(miUbicacion);
            }
        }
예제 #12
0
        private void DrawPolyLine()
        {
            var polyLineOptions = new PolylineOptions();

            polyLineOptions.InvokeColor(0x66FF0000);

            foreach (var position in _routeCoordinates)
            {
                polyLineOptions.Add(new LatLng(position.Latitude, position.Longitude));
            }
            NativeMap.Clear();
            NativeMap.AddPolyline(polyLineOptions);
        }
예제 #13
0
        public void update()
        {
            try
            {
                NativeMap.Clear();


                var polylineOptions = new PolylineOptions();
                polylineOptions.InvokeColor(0x66FF0000);
                foreach (var pin in ((CustomMap)Element).CustomPins)
                {
                    BitmapDescriptor icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.driver);
                    if (pin.Id == "1")
                    {
                        icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.customer);
                    }
                    else if (pin.Id == "Xamarin")
                    {
                        icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.driver);
                    }
                    else
                    {
                        icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.shopPin);
                    }


                    var marker = new MarkerOptions();
                    marker.SetPosition(new LatLng(pin.Pin.Position.Latitude, pin.Pin.Position.Longitude));
                    marker.SetTitle(pin.Pin.Label);
                    marker.SetSnippet(pin.Pin.Address);
                    marker.SetIcon(icon);
                    if (pin.Id != "1")
                    {
                        MoveAble_Marker = NativeMap.AddMarker(marker);
                    }
                    else
                    {
                        NativeMap.AddMarker(marker);
                    }
                }

                //foreach (var position in ((CustomMap)Element).RouteCoordinates)
                //{
                //    polylineOptions.Add(new LatLng(position.Latitude, position.Longitude));
                //}
                //NativeMap.AddPolyline(polylineOptions);
            }
            catch { }
        }
예제 #14
0
        protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs <Map> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                NativeMap.InfoWindowClick -= OnInfoWindowClick;
            }

            if (e.NewElement != null)
            {
                var formsMap = (CustomMap)e.NewElement;
                customPins = formsMap.CustomPins;


                // Register a command to clear the pins.
                MessagingCenter.Subscribe <CrimesNearMeView>(this, "Clear", (sender) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (customPins != null)
                        {
                            customPins.Clear();
                        }
                        NativeMap.Clear();
                    });
                });
                // Register a command to add a droid pin to the map
                MessagingCenter.Subscribe <CrimesNearMeView, CustomPin>(this, "DroidPin", (sender, pin) =>
                {
                    // do something whenever the "DroidPin" message is sent
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        AddDroidPin(pin);
                    });
                });
                MessagingCenter.Subscribe <SearchResultsMap, CustomPin>(this, "DroidPin", (sender, pin) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        AddDroidPin(pin);
                    });
                });

                ((MapView)Control).GetMapAsync(this);
            }
        }
예제 #15
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            if (!e.PropertyName.Equals("VisibleRegion") || IsPinMarkersUpdated)
            {
                return;
            }
            NativeMap.Clear();

            IEnumerable <MarkerOptions> MarkerOptionsList = Pins.Select(entity => ToMarkerOptions(entity));

            foreach (MarkerOptions options in MarkerOptionsList)
            {
                NativeMap.AddMarker(options);
            }
            IsPinMarkersUpdated = true;
        }
예제 #16
0
        protected override void OnMapReady(GoogleMap map)
        {
            base.OnMapReady(map);

            NativeMap.UiSettings.ZoomControlsEnabled = false;
            NativeMap.InfoWindowClick += OnInfoWindowClick;
            NativeMap.MarkerClick     += OnMarkerClicked;
            NativeMap.SetInfoWindowAdapter(this);
            NativeMap.CameraChange += Map_CameraChange;
            Device.StartTimer(TimeSpan.FromSeconds(1), () =>
            {
                if (DateTime.Now.Subtract(TimeSpan.FromSeconds(1)) >= mapDraggedTime && !CanFetch && !customMap.OnSelect && Constants.OnInit)
                {
                    NativeMap.Clear();
                    customMap.getplace(lat, lng, 0);
                    CanFetch = true;
                    marketList.Clear();

                    CancelPinAnimation();
                }
                return(true);
            });
            //Device.StartTimer(TimeSpan.FromSeconds(20), () =>
            //{
            //    Device.BeginInvokeOnMainThread(() =>
            //    {
            //        foreach (var item in marketList)
            //        {
            //            //System.Diagnostics.Debug.WriteLine("ctr = {0}", ctr++);
            //            //Marker marker = (Marker)item.Value;
            //            //marker.Remove();
            //            //marker.Visible = false;
            //            //item.Value.Dispose();
            //            //var marker = new MarkerOptions();
            //            //marker.SetPosition(new LatLng(item.Value.Position.Latitude, item.Value.Position.Longitude));
            //            //marker.SetTitle(item.Key.Label);
            //            //marker.SetSnippet(item.Key.Address);
            //            //marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.heart_eyes));
            //            //NativeMap.AddMarker(marker);
            //        }
            //    });
            //    return false;
            //});
        }
        private void UpdatePins()
        {
            var mapTile  = (MapTile)Element;
            var pinItems = mapTile.PinList;

            ClusterManager.ClearItems();
            NativeMap.Clear();

            var clusterItems = pinItems.Select(i => new ClusterItem(i)).ToList();

            ClusterManager.AddItems(clusterItems);

            ClusterManager.Cluster();

            if (LocationMarkerOptions.Position != null)
            {
                LocationMarker = NativeMap.AddMarker(LocationMarkerOptions);
            }

            UpdateLocationPinPosition();
        }
예제 #18
0
 /// <summary>
 /// Function to update the GoogleMap with the new
 /// position of the rider marker.
 /// </summary>
 public void UpdateMarker()
 {
     lock (nativeMapLock)
     {
         Device.BeginInvokeOnMainThread(() =>
         {
             try
             {
                 NativeMap.Clear();
                 riderPin = KCPin.CreateRiderPin(new Position(KCApi.Properties.CurrentRide.ClientLat,
                                                              KCApi.Properties.CurrentRide.ClientLong));
                 MarkerOptions mo = riderPin.CreateMarker();
                 NativeMap.AddMarker(mo);
             }
             catch (Exception e)
             {
                 KCApi.OutputException(e);
             }
         });
     }
 }
예제 #19
0
 private void DrawElements()
 {
     if (((ExtendedMap)Element).MapPositionOption != Data.PositionInfo.PositionOption.Pin)
     {
         NativeMap.Clear();
         _shapeCoordinates = ((ExtendedMap)Element).TempShapeCoordinates;
         if (_shapeCoordinates.Count > 0)
         {
             DrawPolygon();
         }
         _routeCoordinates = ((ExtendedMap)Element).TempRouteCoordinates;
         if (_routeCoordinates.Count > 0)
         {
             DrawPolyline();
         }
     }
     else
     {
         _polyline?.Remove();
         _polygon?.Remove();
     }
 }
예제 #20
0
        void OnMarkerClicked(object sender, GoogleMap.MarkerClickEventArgs e)
        {
            CancelPinAnimation();

            customMap.OnSelect = true;
            var pintoadd   = new PinModel();
            var customView = e.Marker;

            System.Diagnostics.Debug.WriteLine("Position of marker: {0}, {1}", customView.Position.Latitude, customView.Position.Longitude);

            foreach (X.Models.PinModel pin in customMap.CustomPin)
            {
                System.Diagnostics.Debug.WriteLine("Custom pin position: {0}, {1}", pin.Position.Latitude, pin.Position.Longitude);
                System.Diagnostics.Debug.WriteLine("\tdLat = {0}", Math.Abs(pin.Position.Latitude - customView.Position.Latitude));
                System.Diagnostics.Debug.WriteLine("\tdLon = {0}", Math.Abs(pin.Position.Longitude - customView.Position.Longitude));
                if (customView.Snippet.Equals(pin.Id))
                {
                    pintoadd = pin;
                    break;
                }
            }
            VisibleRegion visibleRegion = NativeMap.Projection.VisibleRegion;

            NativeMap.Clear();
            marketList.Clear();

            //var dMeters = 0.004 * NativeMap.Projection.VisibleRegion.;
            //var dLat = dMeters / 111.11;
            var bounds = NativeMap.Projection.VisibleRegion.LatLngBounds;
            var dLat   = 0.01 * (bounds.Northeast.Latitude - bounds.Southwest.Latitude);

            LatLng latlng = new LatLng(pintoadd.Position.Latitude - dLat, pintoadd.Position.Longitude);

            NativeMap.MoveCamera(CameraUpdateFactory.NewLatLng(latlng));
            //pintoadd.Emojis.Clear();
            NativeMap.AddMarker(CreateMarker(pintoadd));
            customMap.showInfoBox(pintoadd.Id);
        }
예제 #21
0
        private void CreateNativePins(CustomMap customMap)
        {
            if (NativeMap != null)
            {
                NativeMap.Clear();
                if (customMap.CustomPins?.Count > 0)
                {
                    for (int i = 0; i < customMap.CustomPins.Count; i++)
                    {
                        var marker = new MarkerOptions();
                        marker.SetPosition(new LatLng(customMap.CustomPins[i].Location.Latitude, customMap.CustomPins[i].Location.Longitude));
                        marker.SetTitle(customMap.CustomPins[i].Title);
                        marker.SetSnippet(customMap.CustomPins[i].Description);

                        float[] hsv = new float[3];
                        Android.Graphics.Color.ColorToHSV(customMap.CustomPins[i].Color.ToAndroid(), hsv);
                        var bitmap = BitmapDescriptorFactory.DefaultMarker(hsv[0]);
                        marker.SetIcon(bitmap);
                        NativeMap.AddMarker(marker);
                    }
                }
            }
        }
예제 #22
0
        private void DrawGrid()
        {
            System.Diagnostics.Debug.Write("@@@@@ DrawGrid");

            customMap.GenerateGrid();

            if (customMap.GridLines == null)
            {
                return;
            }

            //smaže vše na mapě
            NativeMap.Clear();

            RedrawLoggedPositions();
            //drawnPositionsIndices.Clear();

            foreach (GridLine line in customMap.GridLines)
            {
                PolylineOptions lineOptions = GetLine();

                lineOptions.Add(new LatLng(line.start.Latitude, line.start.Longitude));
                lineOptions.Add(new LatLng(line.end.Latitude, line.end.Longitude));

                NativeMap.AddPolyline(lineOptions);
            }

            CircleOptions gridCenterCircle = new CircleOptions();

            gridCenterCircle.InvokeCenter(new LatLng(customMap.activeLocation.Center.Latitude, customMap.activeLocation.Center.Longitude));
            gridCenterCircle.InvokeRadius(50);
            gridCenterCircle.InvokeFillColor(Android.Graphics.Color.DarkSlateBlue);
            gridCenterCircle.InvokeStrokeColor(0X66FF0000);
            gridCenterCircle.InvokeStrokeWidth(2);

            NativeMap.AddCircle(gridCenterCircle);
        }
 private void DibujaPines()
 {
     if (!isDrawn)
     {
         NativeMap.Clear();
         foreach (var pin in formsMap.Pins)
         {
             var marker = new MarkerOptions();
             marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
             marker.SetTitle(pin.Label);
             marker.SetSnippet(pin.Address);
             if (pin.Label == "Ud esta aqui")
             {
                 marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.pinaqui));
             }
             else
             {
                 marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.ecobici));
             }
             NativeMap.AddMarker(marker);
         }
     }
     isDrawn = true;
 }
        private void OnUpdateHighlight()
        {
            var highlightableMap = (HighlightableMap)Element;

            if (highlightableMap == null || NativeMap == null)
            {
                return;
            }

            NativeMap.Clear();

            if (highlightableMap?.Highlight == null)
            {
                return;
            }

            var fillColor       = highlightableMap.Highlight.FillColor.ToAndroid().ToArgb();
            var strokeColor     = highlightableMap.Highlight.StrokeColor.ToAndroid().ToArgb();
            var strokeThickness = highlightableMap.Highlight.StrokeThickness;

            foreach (var polygon in highlightableMap.Highlight.Polygons)
            {
                var polygonOptions = new PolygonOptions();

                polygonOptions.InvokeFillColor(fillColor);
                polygonOptions.InvokeStrokeColor(strokeColor);
                polygonOptions.InvokeStrokeWidth(strokeThickness);

                foreach (var position in polygon.Positions)
                {
                    polygonOptions.Add(new LatLng(position.Latitude, position.Longitude));
                }

                NativeMap.AddPolygon(polygonOptions);
            }
        }
예제 #25
0
        private void NativeMap_MapClick(object sender, GoogleMap.MapClickEventArgs e)
        {
            if (DeliveryAddressPopUp.DeliveryAddresscheck == 0)
            {
                ShopListPage.Lat1 = e.Point.Latitude.ToString();
                ShopListPage.Lng1 = e.Point.Longitude.ToString();

                MessagingCenter.Send(
                    new LoggedInUser {
                }, "test");
            }
            if (DeliveryAddressPopUp.DeliveryAddresscheck == 1)
            {
                DeliveryAddressPopUp.Lat = e.Point.Latitude.ToString();
                DeliveryAddressPopUp.Lng = e.Point.Longitude.ToString();

                MessagingCenter.Send(
                    new LoggedInUser {
                }, "test");
            }
            try
            {
                NativeMap.Clear();

                BitmapDescriptor icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.customer);
                var marker            = new MarkerOptions();
                marker.SetPosition(new LatLng(e.Point.Latitude, e.Point.Longitude));
                marker.SetIcon(icon);

                MoveAble_Marker = NativeMap.AddMarker(marker);
                isDrawn         = true;
            }
            catch (Exception)
            {
            }
        }
 private void ClearPushPins(MapView mapView)
 {
     NativeMap.Clear();
 }
예제 #27
0
        private void drawMarkers(int markerSize)
        {
            LatLngBounds.Builder bounds = new LatLngBounds.Builder();
            NativeMap.Clear();
            List <LatLng> latLngList = new List <LatLng>();

            foreach (var point in customMap.Points)
            {
                var latlng = new LatLng(point.Latitude, point.Longitude);
                latLngList.Add(latlng);

                /*var marker = new MarkerOptions();
                 * marker.Anchor(0.5f, 0.5f);
                 * marker.SetPosition(latlng);
                 * BitmapDescriptor pic = null;
                 * if (!string.IsNullOrEmpty(point.PathToPicture))
                 * {
                 *  Bitmap bm = BitmapFactory.DecodeFile(point.PathToPicture);
                 *  if (bm != null)
                 *  {
                 *      var croppedBitmap = getCroppedBitmap(bm, markerSize);
                 *      pic = BitmapDescriptorFactory.FromBitmap(croppedBitmap);
                 *      bm = null;
                 *      croppedBitmap = null;
                 *  }
                 * }
                 *
                 * if (pic == null)
                 * {
                 *  pic = BitmapDescriptorFactory.FromResource(Resource.Drawable.place_unknown);
                 * }
                 *
                 * marker.SetIcon(pic);
                 * NativeMap.AddMarker(marker);
                 * bounds.Include(latlng);*/
            }
            List <PatternItem> pattern_lines = new List <PatternItem>();

            pattern_lines.Add(new Gap(10));
            //pattern_lines.Add(new Dash(20));
            PolylineOptions lineOptions = new PolylineOptions();

            foreach (var point in latLngList)
            {
                lineOptions.Add(point);
            }
            //lineOptions.InvokePattern(pattern_lines);
            lineOptions.InvokeWidth(10);
            NativeMap.AddPolyline(lineOptions);
            if (customMap.Points.Count > 1)
            {
                try
                {
                    NativeMap.MoveCamera(CameraUpdateFactory.NewLatLngBounds(bounds.Build(), 100));
                }
                catch (Java.Lang.Exception)
                {
                }
            }
            bounds.Dispose();
        }
예제 #28
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            string imageURL = null, imageURLAux = null;
            Bitmap imageBitmap = null;

            if (e.PropertyName.Equals("VisibleRegion") && !isDrawn)
            {
                NativeMap.Clear();

                var polylineOptions = new PolylineOptions();
                polylineOptions.InvokeColor(Android.Graphics.Color.Rgb(244, 67, 54));

                foreach (var position in routeCoordinates)
                {
                    polylineOptions.Add(new LatLng(position.Latitude, position.Longitude));
                }

                NativeMap.AddPolyline(polylineOptions);

                if (pinsCoordinates != null && pinsCoordinates.Count > 0)
                {
                    foreach (var pin in pinsCoordinates)
                    {
                        var marker = new MarkerOptions();
                        marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
                        marker.SetTitle(pin.Label);
                        marker.SetSnippet(pin.Address);

                        imageURL = pin.IconUrl;
                        if (imageURL == "" || imageURL == null)
                        {
                            marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.location_pin));
                        }
                        else
                        {
                            if (imageURLAux != imageURL)
                            {
                                // chaca se o arquivo com o ícone ja existe,
                                // é necessário remover as '/' e as '\' por conta do sistema de pastas
                                if (!fileService.CheckFile(pin.IconUrl.Replace("/", "_").Replace("\\", "_"), true))
                                {
                                    fileService.SaveImage(pin.IconUrl.Replace("/", "_").Replace("\\", "_"), pin.IconUrl);
                                    marker.SetIcon(BitmapDescriptorFactory.FromBitmap(fileService.LoadImage(pin.IconUrl.Replace("/", "_").Replace("\\", "_"))));
                                    //marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.location_pin));
                                }
                                else
                                {
                                    marker.SetIcon(BitmapDescriptorFactory.FromBitmap(fileService.LoadImage(pin.IconUrl.Replace("/", "_").Replace("\\", "_"))));
                                }
                            }
                            else
                            {
                                marker.SetIcon(BitmapDescriptorFactory.FromBitmap(imageBitmap));
                            }

                            NativeMap.AddMarker(marker);
                        }
                    }
                    isDrawn = true;
                }
            }
        }
예제 #29
0
 void ClearPushPins(MapView mapView) => NativeMap.Clear();
예제 #30
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            try
            {
                base.OnElementPropertyChanged(sender, e);

                if (e.PropertyName.Equals("VisibleRegion") && !isDrawn)
                {
                    NativeMap.Clear();
                    NativeMap.InfoWindowClick += OnInfoWindowClick;

                    var polylineOptions = new PolylineOptions();
                    polylineOptions.InvokeColor(0x66FF0000);
                    foreach (var pin in ((CustomMap)Element).CustomPins)
                    {
                        BitmapDescriptor icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.driver);
                        if (pin.Id == "1")
                        {
                            icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.customer);
                        }
                        else if (pin.Id == "Xamarin")
                        {
                            icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.driver);
                        }
                        else
                        {
                            icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.shopPin);
                        }

                        var marker = new MarkerOptions();
                        marker.SetPosition(new LatLng(pin.Pin.Position.Latitude, pin.Pin.Position.Longitude));
                        marker.SetTitle(pin.Pin.Label);
                        marker.SetSnippet(pin.Pin.Address);
                        marker.SetIcon(icon);
                        if (pin.Id != "1")
                        {
                            MoveAble_Marker = NativeMap.AddMarker(marker);
                        }
                        else
                        {
                            NativeMap.AddMarker(marker);
                        }
                    }
                    //
                    //foreach (var position in ((CustomMap)Element).RouteCoordinates)
                    //{
                    //    polylineOptions.Add(new LatLng(position.Latitude, position.Longitude));
                    //}
                    //NativeMap.AddPolyline(polylineOptions);

                    isDrawn = true;

                    Device.StartTimer(TimeSpan.FromSeconds(10), () =>
                    {
                        update();

                        return(true);
                    });
                }
            }
            catch { }
        }