protected override void OnMapReady(GoogleMap googleMap)
        {
            googleMap.UiSettings.ZoomControlsEnabled = false;

            ClusterManager          = new ClusterManager(Context, googleMap);
            ClusterManager.Renderer = new ClusterRenderer(Context, googleMap, ClusterManager);

            var icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.ic_pin_navigation);

            LocationMarkerOptions.SetIcon(icon);
            LocationMarkerOptions.Anchor(0.5f, 0.5f);
            LocationMarkerOptions.InvokeZIndex(1);

            var mapTile = (MapTile)Element;

            mapTile.PinUpdating      += (sender, args) => Functions.SafeCall(UpdatePins);
            mapTile.LocationUpdating += (sender, args) => Functions.SafeCall(UpdateLocationPinPosition);
            mapTile.HeadingUpdating  += (sender, args) => Functions.SafeCall(UpdateLocationPinHeading);

            googleMap.MapClick          += Map_MapClick;
            googleMap.CameraMoveStarted += Map_CameraMoveStarted;
            googleMap.CameraIdle        += Map_CameraPositionIdle;
            googleMap.MarkerClick       += Map_MarkerClick;

            Element.SizeChanged += (sender, args) => SetSafeAreaPadding();

            var minskPosition = new Position(MapTile.MinskLat, MapTile.MinskLong);
            var minskRegion   = MapSpan.FromCenterAndRadius(minskPosition, Distance.FromKilometers(5));

            mapTile.MoveToRegion(minskRegion);

            SetSafeAreaPadding();
        }
Exemplo n.º 2
0
        private async Task AddPinAsync(IMapPin pin)
        {
            if (_markers.ContainsKey(pin))
            {
                return;
            }

            var mapPin = new MarkerOptions();

            mapPin.InvokeZIndex(pin.ZIndex);

            if (!string.IsNullOrWhiteSpace(pin.Title))
            {
                mapPin.SetTitle(pin.Title);
            }

            if (!string.IsNullOrWhiteSpace(pin.Snippet))
            {
                mapPin.SetSnippet(pin.Snippet);
            }

            mapPin.SetPosition(new LatLng(pin.Location.Latitude, pin.Location.Longitude));

            if (pin.Image != null)
            {
                mapPin.Anchor((float)pin.Anchor.X, (float)pin.Anchor.Y);
            }

            var selected = pin.EqualsSafe(Map.SelectedItem);

            mapPin.SetIcon(await DeterminMarkerImage(pin, selected));

            if (_markers.ContainsKey(pin))
            {
                return;
            }

            var markerView = _googleMap.AddMarker(mapPin);

            _markers.Add(pin, markerView);

            if (selected && Map.CanShowCalloutOnTap)
            {
                markerView.ShowInfoWindow();
            }
            else
            {
                markerView.HideInfoWindow();
            }
        }
Exemplo n.º 3
0
        private void AddMarker(Marker marker)
        {
            if (marker is Polyline)
            {
                AddPolyline(marker as Polyline);
                return;
            }

            MarkerOptions options = new MarkerOptions();

            if (marker.ZIndex.HasValue)
            {
                options.InvokeZIndex(marker.ZIndex.Value);
            }
            options.SetPosition(new LatLng(marker.Center.Latitude, marker.Center.Longitude));

            if (!string.IsNullOrEmpty(marker.Icon))
            {
                if (imageResolver != null)
                {
                    System.IO.Stream stream = imageResolver.Resolve(marker.Layer, marker.Icon);
                    if (stream == null)
                    {
                        stream = imageResolver.Resolve(marker);
                    }
                    if (stream != null)
                    {
                        options.SetIcon(BitmapDescriptorFactory.FromBitmap(BitmapFactory.DecodeStream(stream)));
                    }
                }
                else
                {
                    options.SetIcon(BitmapDescriptorFactory.FromResource(ResourceManager.GetDrawableByName(marker.Icon)));
                }
                if (marker.Label != null)
                {
                    CreateLabel(marker);
                }
            }

            options.SetTitle(marker.Title);
            options.SetSnippet(marker.Content);
            options.Draggable(marker.Draggable);

            markers.Add(marker, googleMap.AddMarker(options));

            marker.PropertyChanged += Marker_PropertyChanged;
        }
Exemplo n.º 4
0
        private void CreateLabel(Marker marker)
        {
            if (marker.Label.Text == null)
            {
                return;
            }
            Paint labelTextPaint = new Paint();

            labelTextPaint.Flags    = PaintFlags.AntiAlias;
            labelTextPaint.TextSize = marker.Label.TextSize != 0 ? marker.Label.TextSize : 25.0f;
            labelTextPaint.SetStyle(Paint.Style.Stroke);
            labelTextPaint.Color       = Xamarin.Forms.Color.White.ToAndroid();
            labelTextPaint.StrokeWidth = 8.0f;

            Rect boundsText = new Rect();

            labelTextPaint.GetTextBounds(marker.Label.Text, 0, marker.Label.Text.Length, boundsText);
            MarkerOptions options = new MarkerOptions();

            if (marker.ZIndex.HasValue)
            {
                options.InvokeZIndex(marker.ZIndex.Value - 0.1f);
            }
            options.SetPosition(new LatLng(marker.Center.Latitude, marker.Center.Longitude));
            options.Anchor(marker.Label.AnchorPointX, marker.Label.AnchorPointY);
            Bitmap labelBitmap = Bitmap.CreateBitmap(boundsText.Width(), boundsText.Height() * 2, Bitmap.Config.Argb8888);

            Canvas canvas = new Canvas(labelBitmap);

            canvas.DrawText(marker.Label.Text, 0, boundsText.Height() * 2, labelTextPaint);
            labelTextPaint.SetStyle(Paint.Style.Fill);
            labelTextPaint.Color = global::Android.Graphics.Color.DarkGray;
            canvas.DrawText(marker.Label.Text, 0, boundsText.Height() * 2, labelTextPaint);

            options.SetIcon(BitmapDescriptorFactory.FromBitmap(labelBitmap));
            markers.Add(new Marker()
            {
                Id     = marker.Id + "-Label",
                Center = marker.Center
            }, googleMap.AddMarker(options));
        }
        protected override void OnMapReady(GoogleMap googleMap)
        {
            var icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.ic_pin_navigation);

            LocationMarkerOptions.SetIcon(icon);
            LocationMarkerOptions.Anchor(0.5f, 0.5f);
            LocationMarkerOptions.InvokeZIndex(1);

            var mapTile = (MapTile)Element;

            mapTile.PinUpdating      += (sender, args) => Functions.SafeCall(UpdatePins);
            mapTile.LocationUpdating += (sender, args) => Functions.SafeCall(UpdateLocationPinPosition);
            mapTile.HeadingUpdating  += (sender, args) => Functions.SafeCall(UpdateLocationPinHeading);

            NativeMap.MapClick          += Map_MapClick;
            NativeMap.CameraMoveStarted += Map_CameraMoveStarted;
            NativeMap.CameraIdle        += Map_CameraPositionIdle;
            NativeMap.MarkerClick       += Map_MarkerClick;
            NativeMap.UiSettings.ZoomControlsEnabled = false;

            Element.SizeChanged += (sender, args) => SetSafeAreaPadding();

            SetSafeAreaPadding();
        }