Exemplo n.º 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
            NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem(Catalog.GetString("Back"), UIBarButtonItemStyle.Plain, (sender, args) => {
                ctrl.ButtonPressed(null);
                ctrl.RemoveScreen(ScreenType.Map);
            }), false);
            NavigationItem.LeftBarButtonItem.TintColor = Colors.NavBarButton;
            NavigationItem.SetHidesBackButton(false, false);

            // Get zoom factor
            zoom = NSUserDefaults.StandardUserDefaults.FloatForKey("MapZoom");

            // Get heading orientation
            headingOrientation = NSUserDefaults.StandardUserDefaults.BoolForKey("HeadingOrientation");

            if (zoom == 0f)
            {
                zoom = 16f;
            }

            // Create camera position
            CameraPosition camera;
            CoordBounds    bounds;

            if (thing != null && !(thing is Zone) && thing.ObjectLocation != null)
            {
                camera = CameraPosition.FromCamera(thing.ObjectLocation.Latitude, thing.ObjectLocation.Longitude, zoom);
            }
            else
            {
                // Set camera to mylocation, perhaps there is no other position
                camera = CameraPosition.FromCamera(engine.Latitude, engine.Longitude, zoom);
                if (thing != null && thing is Zone)
                {
                    bounds = ((Zone)thing).Bounds;
                    if (bounds != null)
                    {
                        camera = CameraPosition.FromCamera(bounds.Left + (bounds.Right - bounds.Left) / 2.0, bounds.Bottom + (bounds.Top - bounds.Bottom) / 2.0, zoom);
                    }
                }
                else
                {
                    camera = CameraPosition.FromCamera(engine.Latitude, engine.Longitude, zoom);
                }
            }

            // Init MapView
            mapView = MapView.FromCamera(RectangleF.Empty, camera);
            mapView.MyLocationEnabled = true;
            mapView.SizeToFit();
            mapView.AutoresizingMask          = UIViewAutoresizing.All;
            mapView.Frame                     = new RectangleF(0, 0, View.Frame.Width, View.Frame.Height);
            mapView.MyLocationEnabled         = true;
            mapView.Settings.CompassButton    = false;
            mapView.Settings.MyLocationButton = false;
            mapView.Settings.RotateGestures   = false;
            mapView.Settings.TiltGestures     = false;

            mapView.TappedOverlay         += OnTappedOverlay;
            mapView.TappedInfo            += OnTappedInfo;
            mapView.CameraPositionChanged += OnCameraPositionChanged;

            View.AddSubview(mapView);

            if (thing == null)
            {
                // Show all
                bounds = engine.Bounds;
                if (bounds != null)
                {
                    camera         = mapView.CameraForBounds(new CoordinateBounds(new CLLocationCoordinate2D(bounds.Left, bounds.Top), new CLLocationCoordinate2D(bounds.Right, bounds.Bottom)), new UIEdgeInsets(30f, 30f, 30f, 30f));
                    mapView.Camera = camera;
                }
            }

            btnCenter           = UIButton.FromType(UIButtonType.RoundedRect);
            btnCenter.Tag       = 1;
            btnCenter.Frame     = new RectangleF(12f, 12f, 36f, 36f);
            btnCenter.TintColor = UIColor.White;
            btnCenter.SetBackgroundImage(Images.BlueButton, UIControlState.Normal);
            btnCenter.SetBackgroundImage(Images.BlueButtonHighlight, UIControlState.Highlighted);
            btnCenter.SetImage(Images.ButtonCenter, UIControlState.Normal);
            btnCenter.ContentMode    = UIViewContentMode.Center;
            btnCenter.TouchUpInside += OnTouchUpInside;

            View.AddSubview(btnCenter);

            btnOrientation           = UIButton.FromType(UIButtonType.RoundedRect);
            btnOrientation.Tag       = 2;
            btnOrientation.Frame     = new RectangleF(12f, 61f, 36f, 36f);
            btnOrientation.TintColor = UIColor.White;
            btnOrientation.SetBackgroundImage(Images.BlueButton, UIControlState.Normal);
            btnOrientation.SetBackgroundImage(Images.BlueButtonHighlight, UIControlState.Highlighted);
            btnOrientation.SetImage((headingOrientation ? Images.ButtonOrientation : Images.ButtonOrientationNorth), UIControlState.Normal);
            btnOrientation.ContentMode    = UIViewContentMode.Center;
            btnOrientation.TouchUpInside += OnTouchUpInside;

            View.AddSubview(btnOrientation);

            btnMapType                  = UIButton.FromType(UIButtonType.RoundedRect);
            btnMapType.Tag              = 3;
            btnMapType.Frame            = new RectangleF(mapView.Frame.Width - 12f - 36f, 12f, 36f, 36f);
            btnMapType.AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleBottomMargin;
            btnMapType.TintColor        = UIColor.White;
            btnMapType.SetBackgroundImage(Images.BlueButton, UIControlState.Normal);
            btnMapType.SetBackgroundImage(Images.BlueButtonHighlight, UIControlState.Highlighted);
            btnMapType.SetImage(Images.ButtonMapType, UIControlState.Normal);
            btnMapType.ContentMode    = UIViewContentMode.Center;
            btnMapType.TouchUpInside += OnTouchUpInside;

            View.AddSubview(btnMapType);

            webLegacy                          = new UIWebView();
            webLegacy.Frame                    = new RectangleF(mapView.Frame.Width - 2f - 150f, mapView.Frame.Height - 2f - 20f, 150f, 20f);
            webLegacy.AutoresizingMask         = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleWidth;
            webLegacy.BackgroundColor          = UIColor.Clear;
            webLegacy.Opaque                   = false;
            webLegacy.ScrollView.ScrollEnabled = false;
            webLegacy.ScalesPageToFit          = true;
            webLegacy.ShouldStartLoad          = delegate(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType) {
                if (navigationType == UIWebViewNavigationType.LinkClicked)
                {
                    UIApplication.SharedApplication.OpenUrl(request.Url);
                    return(false);
                }
                return(true);
            };

            View.AddSubview(webLegacy);

            // Set map source
            SetMapSource((MapSource)NSUserDefaults.StandardUserDefaults.IntForKey("MapSource"));

            Refresh();
        }