Exemple #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            // For XAML Previewer or FormsGoogleMaps.Init not called.
            if (!FormsGoogleMaps.IsInitialized)
            {
                var label = new UILabel()
                {
                    Text            = "Xamarin.Forms.GoogleMaps",
                    BackgroundColor = Color.Teal.ToUIColor(),
                    TextColor       = Color.Black.ToUIColor(),
                    TextAlignment   = UITextAlignment.Center
                };
                SetNativeControl(label);
                return;
            }

            var oldMapView = (MapView)Control;

            if (e.OldElement != null)
            {
                _cameraLogic.Unregister();
            }

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

                if (Control == null)
                {
                    SetNativeControl(new MapView(RectangleF.Empty));
                    var mkMapView = (MapView)Control;
                    mkMapView.CameraPositionChanged += CameraPositionChanged;
                    mkMapView.CoordinateTapped      += CoordinateTapped;
                    mkMapView.CoordinateLongPressed += CoordinateLongPressed;
                    mkMapView.DidTapMyLocationButton = DidTapMyLocation;
                }

                _cameraLogic.Register(Map, NativeMap);

                _cameraLogic.MoveCamera(mapModel.InitialCameraUpdate);

                UpdateMapType();
                UpdateIsShowingUser();
                UpdateHasScrollEnabled();
                UpdateHasZoomEnabled();
                UpdateHasRotationEnabled();
                UpdateIsTrafficEnabled();
                UpdatePadding();

                foreach (var logic in _logics)
                {
                    logic.Register(oldMapView, (Map)e.OldElement, NativeMap, Map);
                    logic.RestoreItems();
                    logic.OnMapPropertyChanged(new PropertyChangedEventArgs(Map.SelectedPinProperty.PropertyName));
                }
            }
        }
        void UpdateVisibleRegion()
        {
            if (Control == null || Element == null)
            {
                return;
            }

            if (!_firstZoomLevelChangeFired)
            {
                _cameraLogic.MoveCamera(Map.InitialCameraUpdate);

                _firstZoomLevelChangeFired = true;
                return;
            }

            try
            {
                var boundingBox = GetBounds(this.Control);
                if (boundingBox != null)
                {
                    var center         = new Position(boundingBox.Center.Latitude, boundingBox.Center.Longitude);
                    var latitudeDelta  = Math.Abs(center.Latitude - boundingBox.NorthwestCorner.Latitude);
                    var longitudeDelta = Math.Abs(center.Longitude - boundingBox.NorthwestCorner.Longitude);
                    Element.VisibleRegion = new MapSpan(center, latitudeDelta, longitudeDelta);
                }
            }
            catch (Exception)
            {
                //couldnt update visible region
            }
        }
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);

            // For XAML Previewer or FormsGoogleMaps.Init not called.
            if (!FormsGoogleMaps.IsInitialized)
            {
                return;
            }

            _onLayout = true;

            if (_ready && _onLayout)
            {
                InitializeLogic();
            }
            else if (changed && NativeMap != null)
            {
                UpdateVisibleRegion(NativeMap.CameraPosition.Target);
                _cameraLogic.MoveCamera(Map.InitialCameraUpdate);
            }
        }
        void InitializeLogic()
        {
            _cameraLogic.MoveCamera(Map.InitialCameraUpdate);

            foreach (var logic in Logics)
            {
                if (logic.Map != null)
                {
                    logic.RestoreItems();
                    logic.OnMapPropertyChanged(new PropertyChangedEventArgs(MapBase.SelectedPinProperty.PropertyName));
                }
            }

            _ready    = false;
            _onLayout = false;
        }
Exemple #5
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            // For XAML Previewer or FormsGoogleMaps.Init not called.
            if (!FormsGoogleMaps.IsInitialized)
            {
                return;
            }

            if (_shouldUpdateRegion && !_ready)
            {
                _cameraLogic.MoveCamera(((Map)Element).InitialCameraUpdate);
                _ready = true;
                _shouldUpdateRegion = false;
            }
        }
Exemple #6
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            // For XAML Previewer or GoogleMapsSystem.Init not called.
            if (!GoogleMapsSystem.IsInitialized)
            {
                return;
            }

            if (_shouldUpdateRegion && !_ready)
            {
                _cameraLogic.MoveCamera(((MapBase)Element).InitialCameraUpdate);
                _ready = true;
                _shouldUpdateRegion = false;
                UpdateMyLocationEnabled();
            }
        }
Exemple #7
0
        void UpdateVisibleRegion()
        {
            if (Control == null || Element == null)
            {
                return;
            }

            if (!_firstZoomLevelChangeFired)
            {
                _cameraLogic.MoveCamera(Map.InitialCameraUpdate);

                _firstZoomLevelChangeFired = true;
                return;
            }

            try
            {
                var boundingBox = GetBounds(this.Control);
                if (boundingBox != null)
                {
                    //Hack 1
                    //Begin
                    var center         = new Position(boundingBox.Center.Latitude, boundingBox.Center.Longitude);
                    var latitudeDelta  = Math.Abs(center.Latitude - boundingBox.NorthwestCorner.Latitude);
                    var longitudeDelta = Math.Abs(center.Longitude - boundingBox.NorthwestCorner.Longitude);
                    Element.VisibleRegion = new MapSpan(center, latitudeDelta, longitudeDelta);
                    //End

                    //Could it replace Hack 1?
                    //Element.Region = new MapRegion(new Position(boundingBox.NorthwestCorner.Latitude, boundingBox.SoutheastCorner.Longitude), boundingBox.SoutheastCorner.ToPosition(), boundingBox.NorthwestCorner.ToPosition(), new Position(boundingBox.SoutheastCorner.Latitude, boundingBox.NorthwestCorner.Longitude));

                    // Simone Marra
                    UpdateCornersBounds(this.Control);
                    // End Simone Marra
                }
            }
            catch (Exception)
            {
                //couldnt update visible region
            }
        }