using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Maps.MapControl.WPF;

namespace BingMapsWinForm
{
    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    public partial class MapUserControl : UserControl
    {
        public MapUserControl()
        {
            InitializeComponent();
        }
        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            double panX = 0.0; double panY = -0.14;

            changePosition(panX, panY);
        }
        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            double panX = -0.14; double panY = 0.0;

            changePosition(panX, panY);
        }

        private void Button3_Click(object sender, RoutedEventArgs e)
        {
            double panX = +0.14; double panY = 0.0;

            changePosition(panX, panY);
        }
        private void Button4_Click(object sender, RoutedEventArgs e)
        {
            double panX = 0.0; double panY = +0.14;

            changePosition(panX, panY);
        }

        private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            Map.ZoomLevel = slider.Value; 
        }
        void changePosition(double panX, double panY)
        {
            Location center = Map.TargetCenter;
            double zoomLevel = Map.TargetZoomLevel;

            if (panX != 0 || panY != 0)
            {
                double panDelta = Map.ViewportSize.Width / 2.0;
                Location newCenter;
                if (Map.TryViewportPointToLocation(new Point(Map.ViewportSize.Width / 2 + panX * panDelta,
                                                               Map.ViewportSize.Height / 2 + panY * panDelta), out newCenter))
                {
                    center = newCenter;
                }
                Map.SetView(center, zoomLevel);
            }
        }
    }
}
