finish testmap
This commit is contained in:
@@ -1,62 +1,177 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="LectureActivity.cs" company="BTU/IIT">
|
||||
// <copyright file="MapModel.cs" company="BTU/IIT">
|
||||
// Company copyright tag.
|
||||
// </copyright>
|
||||
// <author>stubbfel</author>
|
||||
// <sience>20.06.2013</sience>
|
||||
// <sience>24.06.2013</sience>
|
||||
//----------------------------------------------------------------------
|
||||
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;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This Class manage the properties of a Map
|
||||
/// </summary>
|
||||
public class MapModel
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MapModel" /> class.
|
||||
/// </summary>
|
||||
public MapModel()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Property
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ImageSource of the map
|
||||
/// </summary>
|
||||
public string ImageSource { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ImageWidth of the map
|
||||
/// </summary>
|
||||
public double ImageWidth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ImageHeight of the map
|
||||
/// </summary>
|
||||
public double ImageHeight { get; set; }
|
||||
|
||||
public double MapOffsetX { get; set; }
|
||||
public double MapOffsetY { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the ImageOffsetX of the map
|
||||
/// </summary>
|
||||
public double MapImageOffsetX { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ImageOffsetY of the map
|
||||
/// </summary>
|
||||
public double MapImageOffsetY { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the GeoOffsetX of the map
|
||||
/// </summary>
|
||||
public double GeoOffsetX { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the GeoOffsetY of the map
|
||||
/// </summary>
|
||||
public double GeoOffsetY { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Scale (to pixel) of the map
|
||||
/// </summary>
|
||||
public double Scale { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the reference point
|
||||
/// </summary>
|
||||
public Point RefPoint { get; set; }
|
||||
|
||||
public Point GetMapPoint(double x, double y)
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Method calculate the coordinates of ScrollToOffsets point
|
||||
/// </summary>
|
||||
/// <param name="point">input point</param>
|
||||
/// <returns>point (in pixel)</returns>
|
||||
public Point GetScrollPoint(Point point)
|
||||
{
|
||||
x += this.MapOffsetX;
|
||||
y += this.MapOffsetY;
|
||||
return this.GetScrollPoint(point.X, point.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method calculate the coordinates of ScrollToOffsets point
|
||||
/// </summary>
|
||||
/// <remarks>the input-point will be shown in the center</remarks>
|
||||
/// <param name="x">x - coordinate</param>
|
||||
/// <param name="y">y - coordinate</param>
|
||||
/// <returns>point (in pixel)</returns>
|
||||
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)
|
||||
/// <summary>
|
||||
/// Method create in image, which can show at a certain position
|
||||
/// </summary>
|
||||
/// <param name="x">the x- coordinate</param>
|
||||
/// <param name="y">the y-coordinate</param>
|
||||
/// <returns>image of the pin</returns>
|
||||
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)
|
||||
/// <summary>
|
||||
/// Method create in image, which can show at a certain position depend of the <see cref="RefPoint" />
|
||||
/// </summary>
|
||||
/// <param name="x">the x-coordinate</param>
|
||||
/// <param name="y">the y-coordinate</param>
|
||||
/// <returns>image of the pin</returns>
|
||||
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)
|
||||
/// <summary>
|
||||
/// Method create in image, which can show at a certain position depend of the <see cref="RefPoint" />
|
||||
/// </summary>
|
||||
/// <param name="position">input point</param>
|
||||
/// <returns>image of the pin</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method create in image, which can show at a certain position
|
||||
/// </summary>
|
||||
/// <param name="position">input point</param>
|
||||
/// <returns>image of the pin</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a coordinates to coordinates which address pixels
|
||||
/// </summary>
|
||||
/// <param name="x">the x-coordinate</param>
|
||||
/// <param name="y">the y-coordinate</param>
|
||||
/// <returns>Point in pixel-size</returns>
|
||||
public Point ConverToPixelPoint(double x, double y)
|
||||
{
|
||||
return new Point { X = this.Scale * x, Y = this.Scale * y };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a coordinates to coordinates which address pixels
|
||||
/// </summary>
|
||||
/// <param name="point">not scaled point</param>
|
||||
/// <returns>Point in pixel-size</returns>
|
||||
public Point ConverToPixelPoint(Point point)
|
||||
{
|
||||
return this.ConverToPixelPoint(point.X, point.Y);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="MapPinModel.cs" company="BTU/IIT">
|
||||
// Company copyright tag.
|
||||
// </copyright>
|
||||
// <author>stubbfel</author>
|
||||
// <sience>24.06.2013</sience>
|
||||
//----------------------------------------------------------------------
|
||||
namespace CampusAppWP8.Model.Campusmap
|
||||
{
|
||||
using System.Windows;
|
||||
|
||||
/// <summary>
|
||||
/// This Class manage the properties of a MapPin
|
||||
/// </summary>
|
||||
public class MapPinModel
|
||||
{
|
||||
#region Member
|
||||
|
||||
/// <summary>
|
||||
/// Variable of the actual position of the pin
|
||||
/// </summary>
|
||||
private Point position;
|
||||
|
||||
#endregion
|
||||
#region Constructor
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MapPinModel" /> class.
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ImageSource of the pin
|
||||
/// </summary>
|
||||
public string ImageSource { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ImageWidth of the pin
|
||||
/// </summary>
|
||||
public double ImageWidth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ImageHeight of the pin
|
||||
/// </summary>
|
||||
public double ImageHeight { get; set; }
|
||||
|
||||
public double MapOffsetX { get; set; }
|
||||
public double MapOffsetY { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the ImageOffsetX of the pin
|
||||
/// </summary>
|
||||
public double PinImageOffsetX { get; set; }
|
||||
|
||||
public Point Position { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the ImageOffsetY of the pin
|
||||
/// </summary>
|
||||
public double PinImageOffsetY { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets position of the pin
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,11 +35,13 @@
|
||||
<Grid Grid.Row="0">
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Grid.Column="0" />
|
||||
<Button Grid.Column="1" Click="Button_Click">
|
||||
<TextBox Name="XPoint" Grid.Column="0" />
|
||||
<TextBox Name="YPoint" Grid.Column="1" />
|
||||
<Button Grid.Column="2" Click="Button_Click">
|
||||
<Image Source="/Assets/icons/search_159_dark.png" Width="60"/>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user