diff --git a/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs b/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs index e425178e..11d1b322 100644 --- a/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs @@ -1,62 +1,177 @@ //----------------------------------------------------------------------- -// +// // Company copyright tag. // // stubbfel -// 20.06.2013 +// 24.06.2013 //---------------------------------------------------------------------- namespace CampusAppWP8.Model.Campusmap { using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; using System.Windows; + using System.Windows.Controls; + using System.Windows.Media.Imaging; - + /// + /// This Class manage the properties of a Map + /// public class MapModel { + #region Constructors + /// + /// Initializes a new instance of the class. + /// public MapModel() { } + #endregion + + #region Property + + /// + /// Gets or sets the ImageSource of the map + /// public string ImageSource { get; set; } + + /// + /// Gets or sets the ImageWidth of the map + /// public double ImageWidth { get; set; } + + /// + /// Gets or sets the ImageHeight of the map + /// public double ImageHeight { get; set; } - public double MapOffsetX { get; set; } - public double MapOffsetY { get; set; } + /// + /// Gets or sets the ImageOffsetX of the map + /// + public double MapImageOffsetX { get; set; } + /// + /// Gets or sets the ImageOffsetY of the map + /// + public double MapImageOffsetY { get; set; } + + /// + /// Gets or sets the GeoOffsetX of the map + /// + public double GeoOffsetX { get; set; } + + /// + /// Gets or sets the GeoOffsetY of the map + /// + public double GeoOffsetY { get; set; } + + /// + /// Gets or sets the Scale (to pixel) of the map + /// + public double Scale { get; set; } + + /// + /// Gets or sets the reference point + /// public Point RefPoint { get; set; } - public Point GetMapPoint(double x, double y) + #endregion + + #region Methods + + /// + /// Method calculate the coordinates of ScrollToOffsets point + /// + /// input point + /// point (in pixel) + public Point GetScrollPoint(Point point) { - x += this.MapOffsetX; - y += this.MapOffsetY; + return this.GetScrollPoint(point.X, point.Y); + } + + /// + /// Method calculate the coordinates of ScrollToOffsets point + /// + /// the input-point will be shown in the center + /// x - coordinate + /// y - coordinate + /// point (in pixel) + public Point GetScrollPoint(double x, double y) + { + x = this.RefPoint.X + this.MapImageOffsetX + x; + y = this.RefPoint.Y + this.MapImageOffsetY - y; return new Point(x, y); } - public Point GetMapPoint(Point point) + /// + /// Method create in image, which can show at a certain position + /// + /// the x- coordinate + /// the y-coordinate + /// image of the pin + public Image AddPin(double x, double y) { - - return this.GetMapPoint(point.X, point.Y); + Point position = new Point(x, y); + return this.AddPin(position); } - public Point GetMapFromRefPoint(Point point) + /// + /// Method create in image, which can show at a certain position depend of the + /// + /// the x-coordinate + /// the y-coordinate + /// image of the pin + public Image AddPinFromRefPoint(double x, double y) { - - return this.GetMapFromRefPoint(point.X, point.Y); + Point position = new Point(this.RefPoint.X + x, this.RefPoint.Y - y); + return this.AddPin(position); } - public Point GetMapFromRefPoint(double x, double y) + /// + /// Method create in image, which can show at a certain position depend of the + /// + /// input point + /// image of the pin + public Image AddPinFromRefPoint(Point position) { - x += this.RefPoint.X; - x += this.MapOffsetX; - y += this.RefPoint.Y; - y += this.MapOffsetY; - return new Point(x, y); + return this.AddPinFromRefPoint(position.X, position.Y); } + + /// + /// Method create in image, which can show at a certain position + /// + /// input point + /// image of the pin + public Image AddPin(Point position) + { + MapPinModel pin = new MapPinModel() { Position = position }; + Image pinImg = new Image() { Source = new BitmapImage(new Uri(pin.ImageSource, UriKind.Relative)), Width = pin.ImageWidth }; + Canvas.SetTop(pinImg, pin.Position.Y); + Canvas.SetLeft(pinImg, pin.Position.X); + return pinImg; + } + + /// + /// Convert a coordinates to coordinates which address pixels + /// + /// the x-coordinate + /// the y-coordinate + /// Point in pixel-size + public Point ConverToPixelPoint(double x, double y) + { + return new Point { X = this.Scale * x, Y = this.Scale * y }; + } + + /// + /// Convert a coordinates to coordinates which address pixels + /// + /// not scaled point + /// Point in pixel-size + public Point ConverToPixelPoint(Point point) + { + return this.ConverToPixelPoint(point.X, point.Y); + } + + #endregion } } diff --git a/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapPinModel.cs b/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapPinModel.cs index 5f5374a2..8e9b131a 100644 --- a/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapPinModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapPinModel.cs @@ -1,25 +1,106 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; - +//----------------------------------------------------------------------- +// +// Company copyright tag. +// +// stubbfel +// 24.06.2013 +//---------------------------------------------------------------------- namespace CampusAppWP8.Model.Campusmap { + using System.Windows; + + /// + /// This Class manage the properties of a MapPin + /// public class MapPinModel { + #region Member + + /// + /// Variable of the actual position of the pin + /// + private Point position; + + #endregion + #region Constructor + /// + /// Initializes a new instance of the class. + /// public MapPinModel() { + this.ImageSource = "/Assets/icons/search_159_light.png"; + this.ImageWidth = 60; + this.ImageHeight = 60; + this.PinImageOffsetX = -24; + this.PinImageOffsetY = -24; } + #endregion + + #region Property + + /// + /// Gets or sets the ImageSource of the pin + /// public string ImageSource { get; set; } + + /// + /// Gets or sets the ImageWidth of the pin + /// public double ImageWidth { get; set; } + + /// + /// Gets or sets the ImageHeight of the pin + /// public double ImageHeight { get; set; } - public double MapOffsetX { get; set; } - public double MapOffsetY { get; set; } + /// + /// Gets or sets the ImageOffsetX of the pin + /// + public double PinImageOffsetX { get; set; } - public Point Position { get; set; } + /// + /// Gets or sets the ImageOffsetY of the pin + /// + public double PinImageOffsetY { get; set; } + + /// + /// Gets or sets position of the pin + /// + public Point Position + { + get + { + return this.position; + } + + set + { + // null assert + if (value == null) + { + return; + } + + if (this.position == null) + { + this.position = value; + return; + } + + // check the x-value + if (value.X + this.PinImageOffsetX != this.position.X) + { + this.position.X = value.X + this.PinImageOffsetX; + } + + // check the y-value + if (value.Y + this.PinImageOffsetY != this.position.Y) + { + this.position.Y = value.Y + this.PinImageOffsetY; + } + } + } + #endregion } } diff --git a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml index 698435f8..007f88af 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml +++ b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml @@ -35,11 +35,13 @@ + - - diff --git a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs index 570aeca0..2c6d8535 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs @@ -19,19 +19,13 @@ namespace CampusAppWP8.Pages.Campusmap public CampusMapPage() { InitializeComponent(); - this.map = new MapModel() { ImageSource = "/Assets/testmap.png", ImageWidth = 2000, ImageHeight = 2000, MapOffsetX = -228, MapOffsetY = -300, RefPoint = new Point(1000, 1000) }; - MapPinModel pin = new MapPinModel() { ImageSource = "/Assets/icons/search_159_light.png", ImageWidth = 60, ImageHeight = 60, MapOffsetX = -24, MapOffsetY = -24, Position = new Point(1000, 1000) }; - Image pinImg =new Image() { Source = new BitmapImage((new Uri(pin.ImageSource,UriKind.Relative))), Width = pin.ImageWidth}; - // this.MapCanvas.SetLeft(pinImg,500); + this.map = new MapModel() { ImageSource = "/Assets/testmap.png", ImageWidth = 2000, ImageHeight = 2000, MapImageOffsetX = -228, MapImageOffsetY = -300, RefPoint = new Point(1000, 1000), Scale = 20}; this.MapCanvas.DataContext = map; - MapCanvas.Children.Add(pinImg); - Image img = new Image(); } private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e) { - //test.ScrollToVerticalOffset(800); } /// @@ -45,9 +39,13 @@ namespace CampusAppWP8.Pages.Campusmap private void Button_Click(object sender, RoutedEventArgs e) { - Point scrollPoint = map.GetMapFromRefPoint(0,0); + MapCanvas.Children.Clear(); + Point scrollPoint = map.GetScrollPoint(map.ConverToPixelPoint(double.Parse(XPoint.Text), double.Parse(YPoint.Text))); + MapCanvas.Children.Add(map.AddPinFromRefPoint(map.ConverToPixelPoint(double.Parse(XPoint.Text), double.Parse(YPoint.Text)))); + MapScroller.ScrollToVerticalOffset(scrollPoint.Y); - MapScroller.ScrollToHorizontalOffset(scrollPoint.X); + MapScroller.ScrollToHorizontalOffset(scrollPoint.X); + } } } \ No newline at end of file