diff --git a/CampusAppWP8/CampusAppWP8/Assets/testmap.png b/CampusAppWP8/CampusAppWP8/Assets/testmap.png new file mode 100644 index 00000000..a2cdfad3 Binary files /dev/null and b/CampusAppWP8/CampusAppWP8/Assets/testmap.png differ diff --git a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj index 7e2ee55c..fdc628fd 100644 --- a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj +++ b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj @@ -97,6 +97,8 @@ App.xaml + + @@ -289,6 +291,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest diff --git a/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs b/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs new file mode 100644 index 00000000..11d1b322 --- /dev/null +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs @@ -0,0 +1,177 @@ +//----------------------------------------------------------------------- +// +// Company copyright tag. +// +// stubbfel +// 24.06.2013 +//---------------------------------------------------------------------- +namespace CampusAppWP8.Model.Campusmap +{ + using System; + 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; } + + /// + /// 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; } + + #endregion + + #region Methods + + /// + /// Method calculate the coordinates of ScrollToOffsets point + /// + /// input point + /// point (in pixel) + public Point GetScrollPoint(Point point) + { + 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); + } + + /// + /// 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) + { + Point position = new Point(x, y); + return this.AddPin(position); + } + + /// + /// 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) + { + Point position = new Point(this.RefPoint.X + x, this.RefPoint.Y - y); + return this.AddPin(position); + } + + /// + /// 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) + { + 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 new file mode 100644 index 00000000..8e9b131a --- /dev/null +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapPinModel.cs @@ -0,0 +1,106 @@ +//----------------------------------------------------------------------- +// +// 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; } + + /// + /// Gets or sets the ImageOffsetX of the pin + /// + public double PinImageOffsetX { 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 7919009f..007f88af 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml +++ b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml @@ -35,17 +35,33 @@ + - - + + + - + + + + + + + + + + + + + diff --git a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs index 9e4cd703..2c6d8535 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs @@ -7,18 +7,45 @@ using System.Windows.Controls; using System.Windows.Navigation; using Microsoft.Phone.Controls; using Microsoft.Phone.Shell; +using System.Windows.Media; +using CampusAppWP8.Model.Campusmap; +using System.Windows.Media.Imaging; namespace CampusAppWP8.Pages.Campusmap { public partial class CampusMapPage : PhoneApplicationPage { + private MapModel map; public CampusMapPage() { InitializeComponent(); + 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; + } private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e) { } + + /// + /// Methods overrides the OnNavigatedTo-Method + /// + /// some NavigationEventArgs + protected override void OnNavigatedTo(NavigationEventArgs e) + { + base.OnNavigatedTo(e); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + 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); + + } } } \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Properties/WMAppManifest.xml b/CampusAppWP8/CampusAppWP8/Properties/WMAppManifest.xml index f4b319d3..856d2330 100644 --- a/CampusAppWP8/CampusAppWP8/Properties/WMAppManifest.xml +++ b/CampusAppWP8/CampusAppWP8/Properties/WMAppManifest.xml @@ -13,7 +13,7 @@ - +