private static void OnPinsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        BindableMap map = (BindableMap)d;

        //If the pin collection changes, then reset the map view.
        map.ClearMapPoints();
        map.SubscribeToCollectionChanged();
    }
Пример #2
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)
            {
                formsMap   = (BindableMap)e.NewElement;
                customPins = formsMap.MapPins;
                Control.GetMapAsync(this);
            }
        }
Пример #3
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                var nativeMap = Control as MKMapView;
                if (nativeMap != null)
                {
                    //rendering for route
                    nativeMap.RemoveOverlays(nativeMap.Overlays);
                    nativeMap.OverlayRenderer = null;
                    polylineRenderer          = null;

                    //rendering for annotations (pins)
                    nativeMap.RemoveAnnotations(nativeMap.Annotations);
                    nativeMap.GetViewForAnnotation = null;
                }
            }

            if (e.NewElement != null)
            {
                BindableMap formsMap  = (BindableMap)e.NewElement;
                var         nativeMap = Control as MKMapView;
                nativeMap.OverlayRenderer = GetOverlayRenderer;

                CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.RouteCoordinates.Count];
                int index = 0;
                foreach (var position in formsMap.RouteCoordinates)
                {
                    coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                    index++;
                }

                var routeOverlay = MKPolyline.FromCoordinates(coords);
                nativeMap.AddOverlay(routeOverlay);

                //var mypins = formsMap.Pins;

                nativeMap.GetViewForAnnotation = GetViewForAnnotation;
            }
        }