public override BMKAnnotationView ViewForAnnotation(BMKMapView mapView, BMKAnnotation annotation)
            {
                if (typeof(BMKPointAnnotation) == annotation.GetType())
                {
                    Pin ann = map.Map.Pins.Find(annotation);
                    if (null != ann)
                    {
                        BMKPinAnnotationView annotationView = new BMKPinAnnotationView(annotation, "myAnnotation");
                        annotationView.PinColor     = BMKPinAnnotationColor.Purple;
                        annotationView.AnimatesDrop = ann.Animate;
                        annotationView.Draggable    = ann.Draggable;
                        // 开启后动态设置Image会导致pin图片拉伸
                        //annotationView.Enabled3D = ann.Enabled3D;

                        // 防止空白气泡弹出
                        annotationView.CanShowCallout = !string.IsNullOrEmpty(ann.Title);

                        if (null != ann.Image)
                        {
                            annotationView.Image = ann.Image.ToNative();
                        }

                        return(annotationView);
                    }
                }

                Debug.WriteLine("MapViewViewForAnnotation: " + annotation.GetType());
                return(null);
            }
Example #2
0
        protected override void OnItemPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            Pin item = (Pin)sender;
            BMKPointAnnotation native = (BMKPointAnnotation)item?.NativeObject;

            if (null == native)
            {
                return;
            }

            if (Annotation.CoordinateProperty.PropertyName == e.PropertyName)
            {
                native.Coordinate = item.Coordinate.ToNative();
                return;
            }

            if (Annotation.TitleProperty.PropertyName == e.PropertyName)
            {
                native.Title = string.IsNullOrEmpty(item.Title) ? "" : item.Title;

                // 防止空白气泡弹出
                BMKPinAnnotationView view = (BMKPinAnnotationView)NativeMap.ViewForAnnotation(native);
                if (view != null)
                {
                    view.CanShowCallout = !string.IsNullOrEmpty(item.Title);
                }

                return;
            }

            if (Pin.ImageProperty.PropertyName == e.PropertyName)
            {
                BMKPinAnnotationView view = (BMKPinAnnotationView)NativeMap.ViewForAnnotation(native);
                if (view != null)
                {
                    view.Image = item.Image.ToNative();
                }

                return;
            }

            if (Pin.DraggableProperty.PropertyName == e.PropertyName)
            {
                BMKPinAnnotationView view = (BMKPinAnnotationView)NativeMap.ViewForAnnotation(native);
                if (view != null)
                {
                    view.Draggable = item.Draggable;
                }

                return;
            }
        }