private async Task <BitmapDescriptor> DeterminMarkerImage(IMapPin pin, bool selected) { if (pin == null) { return(null); } BitmapDescriptor icon; if (pin.Image != null) { var image = selected && pin.SelectedImage != null ? pin.SelectedImage : pin.Image; icon = BitmapDescriptorFactory.FromBitmap(await image.ToBitmap(Context)); } else { var color = selected ? pin.SelectedColor : pin.Color; icon = color.ToStandardMarkerIcon(); } if (icon == null) { icon = BitmapDescriptorFactory.DefaultMarker(); } return(icon); }
private async Task UpdateMarkerImage(IMapPin pin, Marker mapPin, bool selected) { if (pin == null) { return; } mapPin.SetIcon(await DeterminMarkerImage(pin, selected)); }
private void UpdatePin(MKAnnotationView annotationView, IMapPin customAnnotation, bool selected = false) { if (annotationView is MKPinAnnotationView pinAnnotationView) { var color = selected ? customAnnotation.SelectedColor : customAnnotation.Color; pinAnnotationView.PinTintColor = color.ToUIColor(); pinAnnotationView.Layer.ZPosition = customAnnotation.ZIndex; } }
public void AddPin(IMapPin pin) { if (_googleMap == null) { return; } AddPinAsync(pin).HandleExceptions(); }
public void RemovePin(IMapPin pin) { var pins = Control.Annotations .OfType <UnifiedPointAnnotation>() .Where(point => point.Data == pin) .Cast <IMKAnnotation>() .ToArray(); Control.RemoveAnnotations(pins); }
private void UpdatePinColor(MKAnnotationView annotationView, IMapPin customAnnotation, bool selected = false) { var pinAnnotationView = annotationView as MKPinAnnotationView; if (pinAnnotationView != null) { var color = selected ? customAnnotation.SelectedColor : customAnnotation.Color; pinAnnotationView.PinTintColor = color.ToUIColor(); } }
public void AddPin(IMapPin pin) { var mapPin = new UnifiedPointAnnotation { Data = pin, Title = pin.Title, Subtitle = pin.Snippet, Coordinate = new CLLocationCoordinate2D(pin.Location.Latitude, pin.Location.Longitude) }; // pin.Id = mapPin; Control.AddAnnotation(mapPin); }
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(); } }
public void RemovePin(IMapPin pin) { if (_googleMap == null || pin == null) { return; } Marker marker = null; if (_markers.TryGetValue(pin, out marker)) { marker.Remove(); _markers.Remove(pin); } }
private void UpdateImage(MKAnnotationView annotationView, IMapPin customAnnotation, bool selected = false) { if (customAnnotation.Image != null) { annotationView.Layer.AnchorPoint = new CGPoint(customAnnotation.Anchor.X, customAnnotation.Anchor.Y); var newImage = selected ? customAnnotation.SelectedImage : customAnnotation.Image; newImage.ToImage() .ContinueWith((image) => { Device.BeginInvokeOnMainThread(() => { annotationView.Image = image.Result; }); }); } }