Exemple #1
0
 private async void OnBoundsCalculated(object sender, BoundsCalculatedEventArgs e)
 {
     await map.AnimateCamera(
         cameraUpdate : CameraUpdateFactory.NewBounds(e.Bounds, 50),
         duration : TimeSpan.FromSeconds(1.5)
         );
 }
Exemple #2
0
        private async void ShowMeMyCameraUpdate(Services.Map.Bounds bounds)
        {
            var          Southwest    = new Position(bounds.Southwest.Lat, bounds.Southwest.Lng);
            var          Northeast    = new Position(bounds.Northeast.Lat, bounds.Northeast.Lng);
            Bounds       googleBounds = new Bounds(Southwest, Northeast);
            CameraUpdate update       = CameraUpdateFactory.NewBounds(googleBounds, 50);

            Map.InitialCameraUpdate = update;
            await Map.AnimateCamera(update);
        }
Exemple #3
0
        public CameraPage()
        {
            InitializeComponent();

            var pinMelbourne = new Pin()
            {
                Label = "Melbourne", Position = new Position(-37.971237, 144.492697)
            };
            var pinNewyork = new Pin()
            {
                Label = "New york", Position = new Position(40.705311, -74.2581874)
            };
            var pinLisboa = new Pin()
            {
                Label = "Lisboa", Position = new Position(38.7436057, -13.6426275)
            };
            var pinParis = new Pin()
            {
                Label = "Paris", Position = new Position(48.8588377, 2.2775173)
            };
            var pinTokyo = new Pin()
            {
                Label = "Tokyo", Position = new Position(35.7104, 139.8093)
            };

            map.Pins.Add(pinMelbourne);
            map.Pins.Add(pinNewyork);
            map.Pins.Add(pinLisboa);
            map.Pins.Add(pinParis);
            map.Pins.Add(pinTokyo);

            // CameraChanged is obsolete, please use CameraIdled
            map.CameraChanged += (sender, e) =>
            {
                var p    = e.Position;
                var text = $"CameraChanged:Lat={p.Target.Latitude:0.00}, Long={p.Target.Longitude:0.00}, Zoom={p.Zoom:0.00}, Bearing={p.Bearing:0.00}, Tilt={p.Tilt:0.00}";
                labelStatus.Text = text;
                Debug.WriteLine(text);
            };

            map.CameraMoveStarted += (sender, e) =>
            {
                var text = $"CameraMoveStarted:IsGesture={e.IsGesture}";
                labelStatus.Text = text;
                Debug.WriteLine(text);
            };

            map.CameraMoving += (sender, e) =>
            {
                var p    = e.Position;
                var text = $"CameraMoving:Lat={p.Target.Latitude:0.00}, Long={p.Target.Longitude:0.00}, Zoom={p.Zoom:0.00}, Bearing={p.Bearing:0.00}, Tilt={p.Tilt:0.00}";
                labelStatus.Text = text;
                Debug.WriteLine(text);
            };

            map.CameraIdled += (sender, e) =>
            {
                var p    = e.Position;
                var text = $"CameraIdled:Lat={p.Target.Latitude:0.00}, Long={p.Target.Longitude:0.00}, Zoom={p.Zoom:0.00}, Bearing={p.Bearing:0.00}, Tilt={p.Tilt:0.00}";
                labelStatus.Text = text;
                Debug.WriteLine(text);

                UpdateCornerPins();
            };

            // MoveToCamera with Position
            buttonMoveToPosition.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewPosition(
                                         pinMelbourne.Position)); // Melbourne
            };

            // MoveToCamera with Position and Zoom
            buttonMoveToPositionZoom.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewPositionZoom(
                                         pinNewyork.Position, 16d)); // New york
            };

            // MoveToCamera with Bounds
            buttonMoveToBounds.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewBounds(
                                         new Bounds(pinLisboa.Position, // Lisboa
                                                    pinParis.Position), // Paris
                                         50));                          // 50px
            };

            // MoveToCamera with CameraPosition
            buttonMoveToCameraPosition.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewCameraPosition(
                                         new CameraPosition(
                                             pinTokyo.Position, // Tokyo
                                             17d,               // zoom
                                             45d,               // bearing(rotation)
                                             60d                // tilt
                                             )));
            };

            // AnimateToCamera with Position
            buttonAnimateToPosition.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewPosition(
                                                            pinMelbourne.Position)); // Melbourne

                Debug.WriteLine($"Animate with Position result = {animState}");
            };

            // AnimateToCamera with Position and Zoom
            buttonAnimateToPositionZoom.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewPositionZoom(
                                                            pinNewyork.Position, 16d), TimeSpan.FromSeconds(1)); // New york

                Debug.WriteLine($"Animate with Position and Zoom result = {animState}");
            };

            // AnimateToCamera with Bounds
            buttonAnimateToBounds.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewBounds(
                                                            new Bounds(pinLisboa.Position, // Lisboa
                                                                       pinParis.Position), // Paris
                                                            50), TimeSpan.FromSeconds(3)); // 50px

                Debug.WriteLine($"Animate with Bounds result = {animState}");
            };

            // AnimateToCamera with CameraPosition
            buttonAnimateToCameraPosition.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewCameraPosition(
                                                            new CameraPosition(
                                                                pinTokyo.Position, // Tokyo
                                                                17d,               // zoom
                                                                45d,               // bearing(rotation)
                                                                60d)),             // tilt
                                                        TimeSpan.FromSeconds(5));

                Debug.WriteLine($"Animate with CameraPosition result = {animState}");
            };

            // Padding for Map
            entryPadding.TextChanged += (sender, e) =>
            {
                try
                {
                    var converter = new ThicknessTypeConverter();
                    var padding   = (Thickness)converter.ConvertFromInvariantString(entryPadding.Text);
                    map.Padding = padding;
                }
                catch (Exception)
                {
                }
            };
            map.Padding = new Thickness(0, 0, 0, 0);
        }
        public Shapes2Page()
        {
            InitializeComponent();
            pickerZIndex.Items.Add("Red");
            pickerZIndex.Items.Add("Yellow");
            pickerZIndex.Items.Add("Green");

            // Add Polygons
            var polygon1 = new Polygon();

            polygon1.Positions.Add(new Position(35.65, 139.83));
            polygon1.Positions.Add(new Position(35.75, 139.93));
            polygon1.Positions.Add(new Position(35.85, 139.83));
            polygon1.Positions.Add(new Position(35.65, 139.83));
            polygon1.StrokeWidth = 1f;
            polygon1.StrokeColor = Color.Red;
            polygon1.FillColor   = Color.Red;
            map.Polygons.Add(polygon1);
            map.Polygons.Add(CreateShiftedPolygon(polygon1, 0d, 0.05d, Color.Yellow));
            map.Polygons.Add(CreateShiftedPolygon(polygon1, 0d, 0.10d, Color.Green));

            // Add Polylines
            var polyline1 = new Polyline();

            polyline1.StrokeWidth = 10f;
            polyline1.StrokeColor = Color.Red;
            polyline1.Positions.Add(new Position(36.00, 139.83));
            polyline1.Positions.Add(new Position(36.10, 139.93));
            polyline1.Positions.Add(new Position(36.00, 140.03));
            map.Polylines.Add(polyline1);
            map.Polylines.Add(CreateShiftedPolyline(polyline1, 0d, 0.05d, Color.Yellow));
            map.Polylines.Add(CreateShiftedPolyline(polyline1, 0d, 0.10d, Color.Green));

            // Add Circles
            var circle1 = new Circle();

            circle1.StrokeWidth = 10f;
            circle1.StrokeColor = Color.Red;
            circle1.FillColor   = Color.Red;
            circle1.Center      = new Position(35.85, 140.23);
            circle1.Radius      = Distance.FromKilometers(8);
            map.Circles.Add(circle1);
            map.Circles.Add(CreateShiftedCircle(circle1, 0d, 0.05d, Color.Yellow));
            map.Circles.Add(CreateShiftedCircle(circle1, 0d, 0.10d, Color.Green));

            // Fit to all shapes
            var bounds = Xamarin.Forms.GoogleMaps.Bounds.FromPositions(map.Polygons.SelectMany(poly => poly.Positions));

            bounds = bounds.Including(Xamarin.Forms.GoogleMaps.Bounds.FromPositions(map.Polylines.SelectMany(poly => poly.Positions)));
            bounds = bounds.Including(Xamarin.Forms.GoogleMaps.Bounds.FromPositions(map.Circles.Select(cir => cir.Center)));

            // Move to Front
            pickerZIndex.SelectedIndexChanged += (sender, e) =>
            {
                var i = pickerZIndex.SelectedIndex;
                map.Polylines[i].ZIndex = map.Polylines.Max(p => p.ZIndex) + 1;
                map.Polygons[i].ZIndex  = map.Polygons.Max(p => p.ZIndex) + 1;
                map.Circles[i].ZIndex   = map.Circles.Max(p => p.ZIndex) + 1;
            };
            pickerZIndex.SelectedIndex = 0;

            map.InitialCameraUpdate = CameraUpdateFactory.NewBounds(bounds, 5);
        }
        public CameraPage()
        {
            InitializeComponent();

            var pinMelbourne = new Pin()
            {
                Label = "Melbourne", Position = new Position(-37.971237, 144.492697)
            };
            var pinNewyork = new Pin()
            {
                Label = "New york", Position = new Position(40.705311, -74.2581874)
            };
            var pinLisboa = new Pin()
            {
                Label = "Lisboa", Position = new Position(38.7436057, -13.6426275)
            };
            var pinParis = new Pin()
            {
                Label = "Paris", Position = new Position(48.8588377, 2.2775173)
            };
            var pinTokyo = new Pin()
            {
                Label = "Tokyo", Position = new Position(35.7104, 139.8093)
            };

            map.Pins.Add(pinMelbourne);
            map.Pins.Add(pinNewyork);
            map.Pins.Add(pinLisboa);
            map.Pins.Add(pinParis);
            map.Pins.Add(pinTokyo);

            map.CameraChanged += (sender, e) =>
            {
                var p = e.Position;
                labelStatus.Text = $"Lat={p.Target.Latitude:0.00}, Long={p.Target.Longitude:0.00}, Zoom={p.Zoom:0.00}, Bearing={p.Bearing:0.00}, Tilt={p.Tilt:0.00}";
            };

            // MoveToCamera with Position
            buttonMoveToPosition.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewPosition(
                                         pinMelbourne.Position)); // Melbourne
            };

            // MoveToCamera with Position and Zoom
            buttonMoveToPositionZoom.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewPositionZoom(
                                         pinNewyork.Position, 16d)); // New york
            };

            // MoveToCamera with Bounds
            buttonMoveToBounds.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewBounds(
                                         new Bounds(pinLisboa.Position, // Lisboa
                                                    pinParis.Position), // Paris
                                         50));                          // 50px
            };

            // MoveToCamera with CameraPosition
            buttonMoveToCameraPosition.Clicked += async(sender, e) =>
            {
                await map.MoveCamera(CameraUpdateFactory.NewCameraPosition(
                                         new CameraPosition(
                                             pinTokyo.Position, // Tokyo
                                             45d,               // bearing(rotation)
                                             60d,               // tilt
                                             17d)));
            };

            // AnimateToCamera with Position
            buttonAnimateToPosition.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewPosition(
                                                            pinMelbourne.Position)); // Melbourne

                Debug.WriteLine($"Animate with Position result = {animState}");
            };

            // AnimateToCamera with Position and Zoom
            buttonAnimateToPositionZoom.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewPositionZoom(
                                                            pinNewyork.Position, 16d), TimeSpan.FromSeconds(1)); // New york

                Debug.WriteLine($"Animate with Position and Zoom result = {animState}");
            };

            // AnimateToCamera with Bounds
            buttonAnimateToBounds.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewBounds(
                                                            new Bounds(pinLisboa.Position, // Lisboa
                                                                       pinParis.Position), // Paris
                                                            50), TimeSpan.FromSeconds(3)); // 50px

                Debug.WriteLine($"Animate with Bounds result = {animState}");
            };

            // AnimateToCamera with CameraPosition
            buttonAnimateToCameraPosition.Clicked += async(sender, e) =>
            {
                var animState = await map.AnimateCamera(CameraUpdateFactory.NewCameraPosition(
                                                            new CameraPosition(
                                                                pinTokyo.Position, // Tokyo
                                                                45d,               // bearing(rotation)
                                                                60d,               // tilt
                                                                17d)),
                                                        TimeSpan.FromSeconds(5));

                Debug.WriteLine($"Animate with CameraPosition result = {animState}");
            };
        }