protected override void Dispose(bool disposing) { if (disposing) { if (_MapView != null) { _MapView.Dispose(); _MapView = null; } if (GeocodeAnnotation != null) { GeocodeAnnotation.Dispose(); GeocodeAnnotation = null; } } base.Dispose(disposing); }
/// ------------------------------------------------------------------------------------------------ /// protected override void OnElementChanged(Xamarin.Forms.Platform.iOS.ElementChangedEventArgs <View> e) { try { base.OnElementChanged(e); if (e.OldElement != null) { if (formsMap == null) { formsMap = (CustomMap)e.NewElement; } this.MapViewInstance().GetViewForAnnotation = null; customPins.Clear(); } if (e.NewElement != null) { if (formsMap == null) { formsMap = (CustomMap)e.NewElement; } var customView = Control as CustomMKAnnotationView; if (Control != null) { Control.RemoveGestureRecognizer(_tapRecogniser); } base.OnElementChanged(e); if (Control != null) { Control.AddGestureRecognizer(_tapRecogniser); } if (customPins == null) { customPins = new List <CustomPin>(); } else if (customPins != null && customPins.Count != 0) { customPins.Clear(); } var singlePin = MapViewModel.GetCurrentPin(); if (singlePin != null) { formsMap.Pins.Add(singlePin.Pin); customPins.Add(singlePin); } formsMap.ClearPins = () => { if (customPins != null) { formsMap?.Pins.Clear(); customPins.Clear(); } }; formsMap.LoadPins = Pins => { if (Pins != null) { customPins.Clear(); formsMap.Pins.Clear(); foreach (var pin in Pins) { formsMap.CustomPins = Pins; formsMap.Pins.Add(pin.Pin); customPins.Add(pin); } } }; this.MapViewInstance().GetViewForAnnotation = GetViewForAnnotation; formsMap.DisposeMapControl = () => { try { // annotationView?.RemoveFromSuperview(); annotationView?.Dispose(); // _nativeMap?.RemoveFromSuperview(); _nativeMap?.Delegate?.Dispose(); _nativeMap.Delegate = null; _nativeMap?.Dispose(); // NativeView?.RemoveFromSuperview(); NativeView?.Dispose(); // formsMap = null; customPins = null; singlePin = null; // customView?.RemoveFromSuperview(); customView?.Dispose(); // Control?.RemoveFromSuperview(); Control?.Dispose(); // } catch (ObjectDisposedException ex) { } catch (Exception ex) { } }; } } catch (Exception ex) { } }