public bool OnMarkerClick(Marker marker) { Pin clickedMarker = _SharedControl.Pins.FirstOrDefault(p => (string)p.Id == marker.Id); SKPin drawableMarker = clickedMarker as SKPin; return(drawableMarker?.Clickable ?? false); }
internal async void UpdateImage() { SKPin pin = _SkiaAnnotation?.SharedPin; UIImage image; CancellationTokenSource renderCts = new CancellationTokenSource(); _imageUpdateCts?.Cancel(); _imageUpdateCts = renderCts; try { image = await RenderPinAsync(pin, renderCts.Token).ConfigureAwait(false); renderCts.Token.ThrowIfCancellationRequested(); Device.BeginInvokeOnMainThread(() => { if (!renderCts.IsCancellationRequested) { Image = image; Bounds = new CGRect(CGPoint.Empty, new CGSize(pin.Width, pin.Height)); } }); } catch (OperationCanceledException) { // Ignore } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Failed to render pin annotation: \n" + e); } }
private void OnPinInvalidateRequested(object sender, SKPin.MapMarkerInvalidateEventArgs args) { SKPin pin = sender as SKPin; Marker marker = GetMarkerForPin(pin); UpdateMarkerIcon(pin, marker); }
public SKPinAnnotation(SKPin pin) { SharedPin = pin; Title = pin.Label; Subtitle = pin.Address; Coordinate = pin.Position.ToLocationCoordinate(); }
private void UpdateAnnotationIcon(SKPin pin) { IMKAnnotation annotation = FindAnnotationForPin(pin); MKAnnotationView view = _NativeControl.ViewForAnnotation(annotation); SKPinAnnotationView skPinView = view as SKPinAnnotationView; skPinView?.UpdateImage(); skPinView?.UpdateAnchor(); }
private void OnPinInvalidateRequested(object sender, SKPin.MapMarkerInvalidateEventArgs args) { SKPin pin = sender as SKPin; if (pin != null) { UpdateAnnotationIcon(pin); } }
private void OnPinPropertyChanged(object sender, PropertyChangedEventArgs args) { Pin pin = sender as Pin; SKPin skiaPin = pin as SKPin; MKPointAnnotation annotation = FindAnnotationForPin(pin) as MKPointAnnotation; if (skiaPin != null) { if (args.PropertyName == SKPin.WidthProperty.PropertyName || args.PropertyName == SKPin.HeightProperty.PropertyName) { UpdateAnnotationIcon(skiaPin); } else if (args.PropertyName == SKPin.AnchorXProperty.PropertyName || args.PropertyName == SKPin.AnchorYProperty.PropertyName) { MKAnnotationView view = _NativeControl.ViewForAnnotation(annotation); SKPinAnnotationView skPinView = view as SKPinAnnotationView; skPinView?.UpdateAnchor(); } else if (args.PropertyName == SKPin.IsVisibleProperty.PropertyName) { MKAnnotationView view = _NativeControl.ViewForAnnotation(annotation); if (view != null) { view.Hidden = !skiaPin.IsVisible; } } else if (args.PropertyName == SKPin.ClickableProperty.PropertyName) { MKAnnotationView view = _NativeControl.ViewForAnnotation(annotation); if (view != null) { view.Enabled = !skiaPin.Clickable; } } } if (pin != null && annotation != null) { if (args.PropertyName == Pin.LabelProperty.PropertyName) { annotation.Title = pin.Label; } else if (args.PropertyName == Pin.AddressProperty.PropertyName) { annotation.Subtitle = pin.Address; } else if (args.PropertyName == Pin.PositionProperty.PropertyName) { annotation.Coordinate = pin.Position.ToLocationCoordinate(); } } }
private SKPixmap DrawMarker(SKPin sharedMarker) { double bitmapWidth = sharedMarker.Width * Context.Resources.DisplayMetrics.Density; double bitmapHeight = sharedMarker.Height * Context.Resources.DisplayMetrics.Density; SKSurface surface = SKSurface.Create((int)bitmapWidth, (int)bitmapHeight, SKColorType.Rgba8888, SKAlphaType.Premul); surface.Canvas.Clear(SKColor.Empty); sharedMarker.DrawPin(surface); return(surface.PeekPixels()); }
protected override MarkerOptions CreateMarker(Pin pin) { MarkerOptions options = base.CreateMarker(pin); if (pin is SKPin) { SKPin sharedMarker = pin as SKPin; SKPixmap markerBitmap = DrawMarker(sharedMarker); options.SetIcon(BitmapDescriptorFactory.FromBitmap(markerBitmap.ToBitmap())) .Visible(sharedMarker.IsVisible); options.Anchor((float)sharedMarker.AnchorX, (float)sharedMarker.AnchorY); } return(options); }
private Task <UIImage> RenderPinAsync(SKPin pin, CancellationToken token = default(CancellationToken)) { return(Task.Run(() => { double bitmapWidth = pin.Width * _screenDensity; double bitmapHeight = pin.Height * _screenDensity; using (SKSurface surface = SKSurface.Create((int)bitmapWidth, (int)bitmapHeight, SKColorType.Rgba8888, SKAlphaType.Premul)) { surface.Canvas.Clear(SKColor.Empty); pin.DrawPin(surface); return surface.PeekPixels().ToUIImage(); } }, token)); }
private MKAnnotationView GetViewForPin(MKMapView mapView, IMKAnnotation annotation) { SKPinAnnotation skiaAnnotation = annotation as SKPinAnnotation; if (skiaAnnotation != null) { SKPin pin = skiaAnnotation.SharedPin; SKPinAnnotationView pinView = mapView.DequeueReusableAnnotation(SKPinAnnotationView.ViewIdentifier) as SKPinAnnotationView ?? CreateAnnotationView(skiaAnnotation); pinView.Annotation = skiaAnnotation; pinView.UpdateImage(); pinView.UpdateAnchor(); pinView.Hidden = !pin.IsVisible; pinView.Enabled = !pin.Clickable; return(pinView); } return(null); }
private void OnPinPropertyChanged(object sender, PropertyChangedEventArgs args) { SKPin pin = sender as SKPin; Marker marker = GetMarkerForPin(pin); if (pin != null) { if (args.PropertyName == SKPin.WidthProperty.PropertyName || args.PropertyName == SKPin.HeightProperty.PropertyName) { UpdateMarkerIcon(pin, marker); } else if (args.PropertyName == SKPin.AnchorXProperty.PropertyName || args.PropertyName == SKPin.AnchorYProperty.PropertyName) { marker.SetAnchor((float)pin.AnchorX, (float)pin.AnchorY); } else if (args.PropertyName == SKPin.IsVisibleProperty.PropertyName) { marker.Visible = pin.IsVisible; } } }
private void UpdateMarkerIcon(SKPin pin, Marker marker) { SKPixmap markerBitmap = DrawMarker(pin); marker.SetIcon(BitmapDescriptorFactory.FromBitmap(markerBitmap.ToBitmap())); }