using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Shapes;
using SilverlightApplication2;
namespace SilverlightAirlines
{
/// <summary>
/// Map of cities that displays flights
/// </summary>
[XamlResource("SilverlightAirlines.Map.Map.xaml")]
public class Map : MixControl
{
Point lastMousePos = new Point();
double _zoom = 1;
bool mouseButtonPressed = false;
bool mouseIsDragging = false;
Point dragOffset;
Point currentPosition;
double c1left = 1;
double c1top = 1;
public double ZoomFactor
{
get { return _zoom; }
set { _zoom = value; }
}
/// <summary>
/// Name of the container Canvas in the template
/// </summary>
private const string ContainerName = "Container";
/// <summary>
/// Name of the ScaleTransform in the template
/// </summary>
private const string ScaleTransformName = "ScaleTransform";
private MapPointCollection _points;
private City _selectedOrigin;
private MapPoint _origin;
private City _selectedDestination;
private MapPoint _destination;
private Canvas _pointContainer;
/// <summary>
/// Collection of MapPoints shown on the map
/// </summary>
public MapPointCollection Points
{
get
{
return _points;
}
}
/// <summary>
/// Origin of the currently drawn flight
/// </summary>
public City Origin
{
get
{
return _selectedOrigin;
}
}
/// <summary>
/// Destination of the currently drawn flight
/// </summary>
public City Destination
{
get
{
return _selectedDestination;
}
}
/// <summary>
/// Container to display the points
/// </summary>
internal Canvas PointContainer
{
get
{
if (_pointContainer == null)
{
Update();
}
return _pointContainer;
}
}
/// <summary>
/// Event raised when a destination is selected (or when a destination was
/// selected but no longer is)
/// </summary>
public event EventHandler DestinationSelected;
/// <summary>
/// Constructor
/// </summary>
public Map()
: base()
{
// Page.Root.SetupMap(this);
_points = new MapPointCollection(this);
_path = new List<MapPathSegment>();
Root.MouseLeave += new MouseEventHandler(Root_MouseLeave);
// Create the map points
foreach (City city in FlightService.GetDestinations())
{
Points.Add(city);
}
// Create the selection line
_selection = new MapSelection();
_selection.SetValue(Canvas.ZIndexProperty, 5);
_selection.Visibility = Visibility.Collapsed;
_pointContainer.Children.Add(_selection);