protected override void OnElementChanged(ElementChangedEventArgs <MapView> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement != null)
            {
                e.OldElement.AnnotationChanged          -= Element_AnnotationChanged;
                e.OldElement.TakeSnapshotFunc           -= TakeMapSnapshot;
                e.OldElement.GetFeaturesAroundPointFunc -= GetFeaturesAroundPoint;
                if (map != null)
                {
                    RemoveMapEvents();
                }
            }

            if (e.NewElement == null)
            {
                return;
            }
            e.NewElement.AnnotationChanged += Element_AnnotationChanged;
            if (Control == null)
            {
                var activity = (AppCompatActivity)Context;
                var view     = new Android.Widget.FrameLayout(activity)
                {
                    Id = GenerateViewId()
                };

                SetNativeControl(view);

                fragment = new MapViewFragment();

                activity.SupportFragmentManager.BeginTransaction()
                .Replace(view.Id, fragment)
                .CommitAllowingStateLoss();
                fragment.GetMapAsync(this);
                currentCamera = new Position();

                if (mapReady)
                {
                    if (Element.Annotations != null)
                    {
                        AddAnnotations(Element.Annotations.ToArray());
                        if (Element.Annotations is INotifyCollectionChanged notifyCollection)
                        {
                            notifyCollection.CollectionChanged -= OnAnnotationsCollectionChanged;
                            notifyCollection.CollectionChanged += OnAnnotationsCollectionChanged;
                        }
                    }

                    OnMapRegionChanged();
                }
            }
        }
예제 #2
0
        protected override void OnElementChanged(
            ElementChangedEventArgs <MapView> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                if (e.OldElement?.TakeSnapshotFunc != null)
                {
                    // ReSharper disable once DelegateSubtraction
                    e.OldElement.TakeSnapshotFunc -= TakeMapSnapshot;
                }
                if (e.OldElement?.GetFeaturesAroundPointFunc != null)
                {
                    // ReSharper disable once DelegateSubtraction
                    e.OldElement.GetFeaturesAroundPointFunc -= GetFeaturesAroundPoint;
                }
            }

            if (e.NewElement == null)
            {
                return;
            }

            if (Control != null)
            {
                return;
            }

            var activity = (AppCompatActivity)Context;
            var view     = new Android.Widget.FrameLayout(activity)
            {
                Id = GenerateViewId()
            };

            SetNativeControl(view);

            _fragment = new MapViewFragment();

            activity.SupportFragmentManager.BeginTransaction()
            .Replace(view.Id, _fragment)
            .Commit();

            _fragment.GetMapAsync(this);
            _currentCamera = new Position();
        }
예제 #3
0
        protected override void OnElementChanged(ElementChangedEventArgs <MapView> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement != null)
            {
                e.OldElement.AnnotationsChanged -= Element_AnnotationsChanged;
                e.OldElement.Functions           = null;

                if (map != null)
                {
                    RemoveMapEvents();
                }
            }

            if (e.NewElement == null)
            {
                return;
            }

            if (Control == null)
            {
                var activity = (AppCompatActivity)Context.GetActivity();
                var view     = new Android.Widget.FrameLayout(activity)
                {
                    Id = GenerateViewId()
                };

                SetNativeControl(view);

                fragment = MapViewFragment.Create(Element, Context);

                activity.SupportFragmentManager
                .BeginTransaction()
                .Replace(view.Id, fragment)
                .CommitAllowingStateLoss();

                fragment.GetMapAsync(this);
                currentCamera = new NxLatLng();
            }
        }
예제 #4
0
        protected override void Dispose(bool disposing)
        {
            if (fragment != null)
            {
                RemoveMapEvents();

                if (fragment.StateSaved)
                {
                    var activity = (AppCompatActivity)Context;
                    var fm       = activity.SupportFragmentManager;

                    fm.BeginTransaction()
                    .Remove(fragment)
                    .Commit();
                }

                fragment.Dispose();
                fragment = null;
            }

            base.Dispose(disposing);
        }
        protected override void Dispose(bool disposing)
        {
            RemoveMapEvents();
            Element.Functions = null;

            if (fragment != null)
            {
                if (fragment.StateSaved)
                {
                    var activity = (AndroidX.Fragment.App.FragmentActivity)Context;
                    var fm       = activity.SupportFragmentManager;

                    fm.BeginTransaction()
                    .Remove(fragment)
                    .CommitAllowingStateLoss();
                }

                fragment.Dispose();
                fragment = null;
            }

            base.Dispose(disposing);
        }
예제 #6
0
        protected override void Dispose(bool disposing)
        {
            if (_fragment != null)
            {
                RemoveMapEvents();
                _notifyCollectionChanged.CollectionChanged -= OnAnnotationsCollectionChanged;

                if (_fragment.StateSaved)
                {
                    var activity = (AppCompatActivity)Context;
                    var fm       = activity.SupportFragmentManager;

                    fm.BeginTransaction()
                    .Remove(_fragment)
                    .Commit();
                }

                _fragment.Dispose();
                _fragment = null;
            }

            base.Dispose(disposing);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <MapView> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement != null)
            {
                e.OldElement.AnnotationChanged          -= Element_AnnotationChanged;
                e.OldElement.TakeSnapshotFunc           -= TakeMapSnapshot;
                e.OldElement.GetFeaturesAroundPointFunc -= GetFeaturesAroundPoint;
                if (map != null)
                {
                    RemoveMapEvents();
                }
            }

            if (e.NewElement == null)
            {
                return;
            }

            e.NewElement.AnnotationChanged += Element_AnnotationChanged;

            if (Control == null)
            {
                var activity = (AppCompatActivity)Context;

                if (e.NewElement.InsideFragment)
                {
                    var view = new Android.Widget.FrameLayout(activity)
                    {
                        Id = GenerateViewId()
                    };

                    SetNativeControl(view);

                    fragment = new MapViewFragment();

                    activity.SupportFragmentManager.BeginTransaction()
                    .Replace(view.Id, fragment)
                    .CommitAllowingStateLoss();
                    fragment.GetMapAsync(this);
                    currentCamera = new Position();
                }
                else
                {
                    this.mapView = new Sdk.Maps.MapView(activity);
                    this.mapView.SetStyleUrl(this.GetDefaultStyle());

                    // TODO: Call these lifecycle events in the correct place. They should be called from the
                    // Activity's respective methods, not from here. Idk what problems this could cause.
                    // Note: this is why the renderer originally used Fragments. They have their own lifecycles
                    // that are not tied to the main activity (which we only have one of because of Forms).
                    this.mapView.OnCreate(null);
                    this.mapView.OnStart();
                    this.mapView.OnResume();

                    this.SetNativeControl(this.mapView);
                    this.mapView.AddOnMapChangedListener(this);
                    this.mapView.GetMapAsync(this);
                }

                if (mapReady)
                {
                    if (Element.Annotations != null)
                    {
                        AddAnnotations(Element.Annotations.ToArray());
                        if (Element.Annotations is INotifyCollectionChanged notifyCollection)
                        {
                            notifyCollection.CollectionChanged -= OnAnnotationsCollectionChanged;
                            notifyCollection.CollectionChanged += OnAnnotationsCollectionChanged;
                        }
                    }

                    OnMapRegionChanged();
                }
            }
        }