319 lines
11 KiB
C#
319 lines
11 KiB
C#
//-----------------------------------------------------------------------
|
|
// <copyright file="MapModel.cs" company="BTU/IIT">
|
|
// Company copyright tag.
|
|
// </copyright>
|
|
// <author>stubbfel</author>
|
|
// <sience>24.06.2013</sience>
|
|
//----------------------------------------------------------------------
|
|
namespace CampusAppWP8.Model.Campusmap
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media.Imaging;
|
|
using CampusAppWP8.Model.GeoDb;
|
|
|
|
/// <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()
|
|
{
|
|
this.IsReady = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="MapModel" /> class.
|
|
/// </summary>
|
|
/// <param name="placeList">list of places</param>
|
|
public MapModel(List<PlaceModel> placeList)
|
|
{
|
|
this.IsReady = false;
|
|
this.LoadSpatials(placeList);
|
|
this.IsReady = true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Events
|
|
|
|
/// <summary>
|
|
/// Delegate for MapInfo
|
|
/// </summary>
|
|
/// <param name="places">list of places</param>
|
|
public delegate void MapInfos(List<PlaceModel> places);
|
|
|
|
/// <summary>
|
|
/// Event ShowMapInfo
|
|
/// </summary>
|
|
public event MapInfos ShowMapInfos = null;
|
|
|
|
#endregion
|
|
#region Property
|
|
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether the map is ready or not
|
|
/// </summary>
|
|
public bool IsReady { get; protected set; }
|
|
|
|
/// <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; }
|
|
|
|
/// <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 ScaleX { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the Scale (to pixel) of the map
|
|
/// </summary>
|
|
public double ScaleY { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the reference point
|
|
/// </summary>
|
|
public Point RefPoint { get; set; }
|
|
|
|
/// <summary>Gets or sets the spatial of the map.</summary>
|
|
/// <value>The spatial.</value>
|
|
public SpsModel Spatial { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
#region public
|
|
|
|
/// <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)
|
|
{
|
|
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);
|
|
}
|
|
|
|
/// <summary>Method create in image, which can show at a certain position.</summary>
|
|
/// <remarks>Stubbfel, 27.08.2013.</remarks>
|
|
/// <param name="x"> the x- coordinate.</param>
|
|
/// <param name="y"> the y-coordinate.</param>
|
|
/// <param name="type">The type.</param>
|
|
/// <param name="places">list of places</param>
|
|
/// <returns>image of the pin.</returns>
|
|
public Image AddPin(double x, double y, MapPinModel.PinType type, List<PlaceModel> places = null)
|
|
{
|
|
Point position = new Point(x, y);
|
|
return this.AddPin(position, type, places);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method create in image, which can show at a certain position depend of the
|
|
/// <see cref="RefPoint" />
|
|
/// </summary>
|
|
/// <remarks>Stubbfel, 27.08.2013.</remarks>
|
|
/// <param name="x"> the x-coordinate.</param>
|
|
/// <param name="y"> the y-coordinate.</param>
|
|
/// <param name="type">The type.</param>
|
|
/// <param name="places">list of places</param>
|
|
/// <returns>image of the pin.</returns>
|
|
public Image AddPinFromRefPoint(double x, double y, MapPinModel.PinType type, List<PlaceModel> places = null)
|
|
{
|
|
Point position = new Point(this.RefPoint.X + x, this.RefPoint.Y - y);
|
|
return this.AddPin(position, type, places);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method create in image, which can show at a certain position depend of the
|
|
/// <see cref="RefPoint" />
|
|
/// </summary>
|
|
/// <remarks>Stubbfel, 27.08.2013.</remarks>
|
|
/// <param name="position">input point.</param>
|
|
/// <param name="type"> The type.</param>
|
|
/// <param name="places">list of places</param>
|
|
/// <returns>image of the pin.</returns>
|
|
public Image AddPinFromRefPoint(Point position, MapPinModel.PinType type, List<PlaceModel> places = null)
|
|
{
|
|
return this.AddPinFromRefPoint(position.X, position.Y, type, places);
|
|
}
|
|
|
|
/// <summary>Method create in image, which can show at a certain position.</summary>
|
|
/// <remarks>Stubbfel, 27.08.2013.</remarks>
|
|
/// <param name="position">input point.</param>
|
|
/// <param name="type"> The type.</param>
|
|
/// <param name="places">list of places</param>
|
|
/// <returns>image of the pin.</returns>
|
|
public Image AddPin(Point position, MapPinModel.PinType type, List<PlaceModel> places = null)
|
|
{
|
|
Image pinImg = new Image();
|
|
MapPinModel pin = this.CreatePin(type, places, pinImg);
|
|
pin.Position = position;
|
|
if (pin.ImageSource != null)
|
|
{
|
|
pinImg.Source = new BitmapImage(new Uri(pin.ImageSource, UriKind.Relative));
|
|
pinImg.Width = pin.ImageWidth;
|
|
pinImg.Height = pin.ImageHeight;
|
|
}
|
|
|
|
Canvas.SetTop(pinImg, pin.Position.Y);
|
|
Canvas.SetLeft(pinImg, pin.Position.X);
|
|
Canvas.SetZIndex(pinImg, pin.ZIndex);
|
|
return pinImg;
|
|
}
|
|
|
|
/// <summary>Convert a coordinates to coordinates which address pixels.</summary>
|
|
/// <remarks>Stubbfel, 27.08.2013.</remarks>
|
|
/// <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)
|
|
{
|
|
Point p = new Point { X = this.ScaleX * x, Y = this.ScaleY * y };
|
|
return p;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Convert a coordinates to coordinates which address pixels
|
|
/// </summary>
|
|
/// <param name="point">not scaled point</param>d
|
|
/// <returns>Point in pixel-size</returns>
|
|
public Point ConverToPixelPoint(Point point)
|
|
{
|
|
return this.ConverToPixelPoint(point.X, point.Y);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Convert a coordinates to coordinates which address mapPoint
|
|
/// </summary>
|
|
/// <param name="x">the x-coordinate</param>
|
|
/// <param name="y">the y-coordinate</param>
|
|
/// <returns>Point in pixel-size</returns>
|
|
public Point ConverToMapPoint(double x, double y)
|
|
{
|
|
return new Point { X = x - this.GeoOffsetX, Y = y - this.GeoOffsetY };
|
|
}
|
|
|
|
/// <summary>
|
|
/// Convert a coordinates to coordinates which address mapPoint
|
|
/// </summary>
|
|
/// <param name="point">not scaled point</param>
|
|
/// <returns>Point in pixel-size</returns>
|
|
public Point ConverToMapPoint(Point point)
|
|
{
|
|
return this.ConverToMapPoint(point.X, point.Y);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region protected
|
|
|
|
/// <summary>Loads the spatial./</summary>
|
|
/// <remarks>Stubbfel, 19.08.2013.</remarks>
|
|
/// <param name="placeList">list of places</param>
|
|
protected virtual void LoadSpatials(List<PlaceModel> placeList)
|
|
{
|
|
this.Spatial = new SpsModel();
|
|
this.Spatial.AddPlaces(placeList);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region private
|
|
|
|
/// <summary>Creates a pin.</summary>
|
|
/// <remarks>Stubbfel, 27.08.2013.</remarks>
|
|
/// <param name="type">The type.</param>
|
|
/// <param name="places">list of places</param>
|
|
/// <param name="pinImg">image of the pin</param>
|
|
/// <returns>The new pin.</returns>
|
|
private MapPinModel CreatePin(MapPinModel.PinType type, List<PlaceModel> places, Image pinImg)
|
|
{
|
|
MapPinModel pin;
|
|
switch (type)
|
|
{
|
|
case MapPinModel.PinType.CurrentPosition:
|
|
pin = new CurrentPositionPinModel();
|
|
break;
|
|
case MapPinModel.PinType.SearchPlace:
|
|
pin = new SearchPlacePinModel();
|
|
pinImg.MouseLeftButtonDown += new MouseButtonEventHandler(((SearchPlacePinModel)pin).ShowInfo);
|
|
|
|
((SearchPlacePinModel)pin).AssocPlaces = places;
|
|
((SearchPlacePinModel)pin).CallBack = this.ShowMapInfos;
|
|
break;
|
|
case MapPinModel.PinType.InfoPlace:
|
|
pin = new InfoPlacePinModel();
|
|
pinImg.MouseLeftButtonDown += new MouseButtonEventHandler(((InfoPlacePinModel)pin).ShowInfo);
|
|
|
|
((InfoPlacePinModel)pin).AssocPlaces = places;
|
|
((InfoPlacePinModel)pin).CallBack = this.ShowMapInfos;
|
|
break;
|
|
default:
|
|
pin = new HiddenPinPlaceModel();
|
|
break;
|
|
}
|
|
|
|
pinImg.Tag = pin.Tag;
|
|
return pin;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
}
|