Пример #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                var mapModel = (Map)e.OldElement;
                MessagingCenter.Unsubscribe <Map, MapSpan>(this, "MapMoveToRegion");
                ((ObservableCollection <Pin>)mapModel.Pins).CollectionChanged -= OnCollectionChanged;
            }

            if (e.NewElement != null)
            {
                var mapModel = (Map)e.NewElement;

                if (Control == null)
                {
                    SetNativeControl(new MKMapView(RectangleF.Empty));
                    var mkMapView   = (MKMapView)Control;
                    var mapDelegate = new MapDelegate(mapModel);
                    mkMapView.GetViewForAnnotation = mapDelegate.GetViewForAnnotation;
                    mkMapView.RegionChanged       += MkMapViewOnRegionChanged;
                }

                MessagingCenter.Subscribe <Map, MapSpan>(this, "MapMoveToRegion", (s, a) => MoveToRegion(a), mapModel);
                if (mapModel.LastMoveToRegion != null)
                {
                    MoveToRegion(mapModel.LastMoveToRegion, false);
                }

                UpdateMapType();
                UpdateIsShowingUser();
                UpdateHasScrollEnabled();
                UpdateHasZoomEnabled();

                ((ObservableCollection <Pin>)mapModel.Pins).CollectionChanged += OnCollectionChanged;

                OnCollectionChanged(((Map)Element).Pins, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }
Пример #2
0
		protected override void OnElementChanged(ElementChangedEventArgs<View> e)
		{
			base.OnElementChanged(e);

			if (e.OldElement != null)
			{
				var mapModel = (Map)e.OldElement;
				MessagingCenter.Unsubscribe<Map, MapSpan>(this, "MapMoveToRegion");
				((ObservableCollection<Pin>)mapModel.Pins).CollectionChanged -= OnCollectionChanged;
			}

			if (e.NewElement != null)
			{
				var mapModel = (Map)e.NewElement;

				if (Control == null)
				{
					SetNativeControl(new MKMapView(RectangleF.Empty));
					var mkMapView = (MKMapView)Control;
					var mapDelegate = new MapDelegate(mapModel);
					mkMapView.GetViewForAnnotation = mapDelegate.GetViewForAnnotation;
					mkMapView.RegionChanged += MkMapViewOnRegionChanged;
				}

				MessagingCenter.Subscribe<Map, MapSpan>(this, "MapMoveToRegion", (s, a) => MoveToRegion(a), mapModel);
				if (mapModel.LastMoveToRegion != null)
					MoveToRegion(mapModel.LastMoveToRegion, false);

				UpdateMapType();
				UpdateIsShowingUser();
				UpdateHasScrollEnabled();
				UpdateHasZoomEnabled();

				((ObservableCollection<Pin>)mapModel.Pins).CollectionChanged += OnCollectionChanged;

				OnCollectionChanged(((Map)Element).Pins, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
			}
		}