From 5c1891459be72ef75a2b3442d803eff67cb96f9a Mon Sep 17 00:00:00 2001 From: stubbfel Date: Tue, 24 Sep 2013 16:21:26 +0200 Subject: [PATCH] extend campusmap --- CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj | 2 + .../CampusAppWP8/File/Places/PlacesFile.cs | 2 +- .../Model/Campusmap/CBMainMapModel.cs | 13 +- .../Model/Campusmap/CampusMapModel.cs | 29 +- .../Model/Campusmap/ClickAblePlacePinModel.cs | 40 +++ .../Campusmap/CurrentPositionPinModel.cs | 1 + .../Model/Campusmap/HiddenPinPlaceModel.cs | 5 + .../Model/Campusmap/InfoPlacePinModel.cs | 30 ++ .../CampusAppWP8/Model/Campusmap/MapModel.cs | 27 +- .../Model/Campusmap/MapPinModel.cs | 65 ++++- .../Model/Campusmap/SearchPlacePinModel.cs | 31 +- .../Pages/Campusmap/CampusMapPage.xaml | 14 +- .../Pages/Campusmap/CampusMapPage.xaml.cs | 273 ++++++++++++++---- .../CampusAppWP8/Pages/Dev/NFC.xaml.cs | 25 +- 14 files changed, 443 insertions(+), 114 deletions(-) create mode 100644 CampusAppWP8/CampusAppWP8/Model/Campusmap/ClickAblePlacePinModel.cs create mode 100644 CampusAppWP8/CampusAppWP8/Model/Campusmap/InfoPlacePinModel.cs diff --git a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj index 3b770275..a3775697 100644 --- a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj +++ b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj @@ -114,8 +114,10 @@ + + diff --git a/CampusAppWP8/CampusAppWP8/File/Places/PlacesFile.cs b/CampusAppWP8/CampusAppWP8/File/Places/PlacesFile.cs index 382547bb..58991d42 100644 --- a/CampusAppWP8/CampusAppWP8/File/Places/PlacesFile.cs +++ b/CampusAppWP8/CampusAppWP8/File/Places/PlacesFile.cs @@ -51,7 +51,7 @@ namespace CampusAppWP8.File.Places /// /// Method load OfflineMap as Fallback /// - private void FallBackLoad() + public void FallBackLoad() { SpsModel fallBackModel = XmlManager.DeserializationFileToModel(Constants.FileMap_OfflineMap); this.Model = fallBackModel; diff --git a/CampusAppWP8/CampusAppWP8/Model/Campusmap/CBMainMapModel.cs b/CampusAppWP8/CampusAppWP8/Model/Campusmap/CBMainMapModel.cs index a0d6976c..ebb66894 100644 --- a/CampusAppWP8/CampusAppWP8/Model/Campusmap/CBMainMapModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/CBMainMapModel.cs @@ -11,6 +11,7 @@ namespace CampusAppWP8.Model.Campusmap using CampusAppWP8.File.Places; using CampusAppWP8.Model.GeoDb; using CampusAppWP8.Resources; + using System.Collections.Generic; /// /// Class for the MapModel of the mainCampus of cottbus @@ -29,7 +30,7 @@ namespace CampusAppWP8.Model.Campusmap /// /// Initializes a new instance of the class. /// - public CBMainMapModel() + public CBMainMapModel(List placeList) : base (placeList,CBMainMapModel.Campus) { this.ImageSource = Constants.FileMap_CBMainMap; this.ImageWidth = 2000; @@ -41,19 +42,11 @@ namespace CampusAppWP8.Model.Campusmap this.ScaleY = 197648.8919266073; this.GeoOffsetX = 14.327159; this.GeoOffsetY = 51.766548; - this.CampusId = CBMainMapModel.Campus; } #endregion - #region Method - - /// Loads the spatial./. - /// Stubbfel, 19.08.2013. - protected override void LoadSpatials() - { - - } + #region Method #endregion } diff --git a/CampusAppWP8/CampusAppWP8/Model/Campusmap/CampusMapModel.cs b/CampusAppWP8/CampusAppWP8/Model/Campusmap/CampusMapModel.cs index 812a8d78..20a4012b 100644 --- a/CampusAppWP8/CampusAppWP8/Model/Campusmap/CampusMapModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/CampusMapModel.cs @@ -1,4 +1,5 @@ -using System; +using CampusAppWP8.Model.GeoDb; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,6 +9,32 @@ namespace CampusAppWP8.Model.Campusmap { public class CampusMapModel : MapModel { + public string CampusId { get; protected set; } + + public CampusMapModel(List placeList,string campusId) + { + this.CampusId = campusId; + this.LoadSpatials(placeList); + this.IsReady = true; + } + + /// Loads the spatial./. + /// Stubbfel, 19.08.2013. + protected override void LoadSpatials(List placeList) + { + List campusPlaces = new List(); + this.Spatial = new SpsModel(); + + foreach (PlaceModel place in placeList) + { + if (place.ParentId.Equals(this.CampusId) || place.PlaceId.Equals(this.CampusId)) + { + campusPlaces.Add(place); + } + + } + this.Spatial.AddPlaces(campusPlaces); + } } } diff --git a/CampusAppWP8/CampusAppWP8/Model/Campusmap/ClickAblePlacePinModel.cs b/CampusAppWP8/CampusAppWP8/Model/Campusmap/ClickAblePlacePinModel.cs new file mode 100644 index 00000000..bb47a8fa --- /dev/null +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/ClickAblePlacePinModel.cs @@ -0,0 +1,40 @@ +using CampusAppWP8.Model.GeoDb; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CampusAppWP8.Model.Campusmap +{ + public abstract class ClickAblePlacePinModel : MapPinModel + { + #region property + + /// + /// Gets or sets Callback Function, to show place information of the Pin + /// + public MapModel.MapInfos CallBack { get; set; } + + /// + /// Gets or sets place which are associative with this pin + /// + public List AssocPlaces { get; set; } + + #endregion + + #region Method + + /// + /// Show Information of this pin places + /// + /// sender of the Event + /// MouseButtonEvent Arguments + public void ShowInfo(object sender, System.Windows.Input.MouseButtonEventArgs e) + { + this.CallBack(this.AssocPlaces); + } + + #endregion + } +} diff --git a/CampusAppWP8/CampusAppWP8/Model/Campusmap/CurrentPositionPinModel.cs b/CampusAppWP8/CampusAppWP8/Model/Campusmap/CurrentPositionPinModel.cs index 0e9b0552..e23d03bb 100644 --- a/CampusAppWP8/CampusAppWP8/Model/Campusmap/CurrentPositionPinModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/CurrentPositionPinModel.cs @@ -26,6 +26,7 @@ namespace CampusAppWP8.Model.Campusmap this.ImageHeight = 60; this.PinImageOffsetX = -25; this.PinImageOffsetY = -34; + this.Tag = MapPinModel.CurrendPositionPlacePinString; } #endregion diff --git a/CampusAppWP8/CampusAppWP8/Model/Campusmap/HiddenPinPlaceModel.cs b/CampusAppWP8/CampusAppWP8/Model/Campusmap/HiddenPinPlaceModel.cs index e684b3d9..f33d715b 100644 --- a/CampusAppWP8/CampusAppWP8/Model/Campusmap/HiddenPinPlaceModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/HiddenPinPlaceModel.cs @@ -11,5 +11,10 @@ namespace CampusAppWP8.Model.Campusmap /// Stubbfel, 27.08.2013. public class HiddenPinPlaceModel : MapPinModel { + + public HiddenPinPlaceModel() + { + this.Tag = MapPinModel.HiddenPlacePinString; + } } } diff --git a/CampusAppWP8/CampusAppWP8/Model/Campusmap/InfoPlacePinModel.cs b/CampusAppWP8/CampusAppWP8/Model/Campusmap/InfoPlacePinModel.cs new file mode 100644 index 00000000..699f8a9e --- /dev/null +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/InfoPlacePinModel.cs @@ -0,0 +1,30 @@ +using CampusAppWP8.Resources; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CampusAppWP8.Model.Campusmap +{ + public class InfoPlacePinModel : ClickAblePlacePinModel + { + #region Constructor + + /// + /// Initializes a new instance of the class. + /// + /// Stubbfel, 27.08.2013. + public InfoPlacePinModel() + { + this.ImageSource = Icons.Info; + this.ImageWidth = 60; + this.ImageHeight = 60; + this.PinImageOffsetX = -25; + this.PinImageOffsetY = -27; + this.Tag = MapPinModel.PinTypeToString(PinType.InfoPlace); + } + + #endregion + } +} diff --git a/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs b/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs index 40c97791..601f84bb 100644 --- a/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs @@ -22,12 +22,20 @@ namespace CampusAppWP8.Model.Campusmap { #region Constructors + + public MapModel() + { + this.IsReady = false; + } + /// /// Initializes a new instance of the class. /// - public MapModel() + public MapModel(List placeList) { - this.LoadSpatials(); + this.IsReady = false; + this.LoadSpatials(placeList); + this.IsReady = true; } #endregion @@ -48,6 +56,8 @@ namespace CampusAppWP8.Model.Campusmap #endregion #region Property + public bool IsReady { get; protected set; } + /// /// Gets or sets the ImageSource of the map /// @@ -246,8 +256,10 @@ namespace CampusAppWP8.Model.Campusmap /// Loads the spatial./ /// Stubbfel, 19.08.2013. - protected virtual void LoadSpatials() + protected virtual void LoadSpatials(List placeList) { + this.Spatial = new SpsModel(); + this.Spatial.AddPlaces(placeList); } #endregion @@ -275,11 +287,18 @@ namespace CampusAppWP8.Model.Campusmap ((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; } diff --git a/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapPinModel.cs b/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapPinModel.cs index 44cc5451..8c08f497 100644 --- a/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapPinModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapPinModel.cs @@ -17,6 +17,17 @@ namespace CampusAppWP8.Model.Campusmap { #region Member + private static string infoPlacePinString = MapPinModel.PinTypeToString(PinType.InfoPlace); + + + private static string hiddenPlacePinString = MapPinModel.PinTypeToString(PinType.Hidden); + + + private static string searchPlacePinString = MapPinModel.PinTypeToString(PinType.SearchPlace); + + + private static string currendPositionPlacePinString = MapPinModel.PinTypeToString(PinType.CurrentPosition); + /// /// Variable of the actual position of the pin /// @@ -46,7 +57,10 @@ namespace CampusAppWP8.Model.Campusmap SearchPlace = 1, /// An enum constant representing the current position option. - CurrentPosition = 2 + CurrentPosition = 2, + + /// An enum constant representing the info place option. + InfoPlace = 3 } #endregion @@ -114,6 +128,55 @@ namespace CampusAppWP8.Model.Campusmap } } } + + public object Tag { get; set; } + + public static string CurrendPositionPlacePinString + { + get { return MapPinModel.currendPositionPlacePinString; } + } + public static string SearchPlacePinString + { + get { return MapPinModel.searchPlacePinString; } + } + + public static string HiddenPlacePinString + { + get { return MapPinModel.hiddenPlacePinString; } + } + + public static string InfoPlacePinString + { + get { return MapPinModel.infoPlacePinString; } + } + #endregion + + #region Method + + public static string PinTypeToString(PinType type) + { + string result = null; + + switch (type) + { + case PinType.CurrentPosition: + result = "CurrentPositionPin"; + break; + case PinType.Hidden: + result = "HiddenPin"; + break; + case PinType.InfoPlace: + result = "InfoPin"; + break; + case PinType.SearchPlace: + result = "SearchPlacePin"; + break; + default: + result = string.Empty; + break; + } + return result; + } #endregion } } diff --git a/CampusAppWP8/CampusAppWP8/Model/Campusmap/SearchPlacePinModel.cs b/CampusAppWP8/CampusAppWP8/Model/Campusmap/SearchPlacePinModel.cs index 15b62fc3..77ea478a 100644 --- a/CampusAppWP8/CampusAppWP8/Model/Campusmap/SearchPlacePinModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/SearchPlacePinModel.cs @@ -14,7 +14,7 @@ namespace CampusAppWP8.Model.Campusmap /// Search pin place model. /// Stubbfel, 27.08.2013. - public class SearchPlacePinModel : MapPinModel + public class SearchPlacePinModel : ClickAblePlacePinModel { #region Constructor @@ -29,34 +29,7 @@ namespace CampusAppWP8.Model.Campusmap this.ImageHeight = 60; this.PinImageOffsetX = -25; this.PinImageOffsetY = -27; - } - - #endregion - - #region property - - /// - /// Gets or sets Callback Function, to show place information of the Pin - /// - public MapModel.MapInfos CallBack { get; set; } - - /// - /// Gets or sets place which are associative with this pin - /// - public List AssocPlaces { get; set; } - - #endregion - - #region Method - - /// - /// Show Information of this pin places - /// - /// sender of the Event - /// MouseButtonEvent Arguments - public void ShowInfo(object sender, System.Windows.Input.MouseButtonEventArgs e) - { - this.CallBack(this.AssocPlaces); + this.Tag = MapPinModel.SearchPlacePinString; } #endregion diff --git a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml index d9c8457e..29065130 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml +++ b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml @@ -39,21 +39,10 @@ - - @@ -74,6 +63,7 @@ + diff --git a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs index 88447227..88f0cfa9 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs @@ -26,6 +26,7 @@ namespace CampusAppWP8.Pages.Campusmap using Microsoft.Phone.Shell; using Windows.Networking.Proximity; using CampusAppWP8.File.Places; + using System.Windows.Controls; /// Class for the campusMap page. /// Stubbfel, 19.08.2013. @@ -63,9 +64,7 @@ namespace CampusAppWP8.Pages.Campusmap public CampusMapPage() { this.InitializeComponent(); - this.campusMap = new CBMainMapModel(); - this.MapCanvas.DataContext = this.campusMap; - this.campusMap.ShowMapInfos += new CBMainMapModel.MapInfos(this.ShowMapInfo); + ApplicationBarMenuItem menuItem1 = ApplicationBar.MenuItems[0] as ApplicationBarMenuItem; ApplicationBarMenuItem menuItem2 = ApplicationBar.MenuItems[1] as ApplicationBarMenuItem; @@ -91,6 +90,15 @@ namespace CampusAppWP8.Pages.Campusmap #endregion + #region Events + + public delegate void LoadingPlace(string args); + + public event LoadingPlace OnLoadingPlace; + private string lastQuery; + private bool buildInfoEnable; + #endregion + #region Method #region protected @@ -101,26 +109,22 @@ namespace CampusAppWP8.Pages.Campusmap protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); - if (this.campusMap.Spatial == null) - { - return; - } if (e.NavigationMode == NavigationMode.New) { - MapCanvas.Children.Clear(); + this.ClearMap(); bool scroll = true; - string alias = "campus"; + if (NavigationContext.QueryString.ContainsKey(Constants.ParamModelMap_SearchTermAlias)) { - alias = NavigationContext.QueryString[Constants.ParamModelMap_SearchTermAlias]; - this.AddPins(this.SearchPlaces(alias), MapPinModel.PinType.SearchPlace); + string alias = NavigationContext.QueryString[Constants.ParamModelMap_SearchTermAlias]; + this.ShowPlacesByQueryAsSearchPin(alias); scroll = false; } else { - this.AddPins(this.SearchPlaces(alias), MapPinModel.PinType.Hidden); + this.ShowPlacesByQueryAsHiddenPin("campus"); } this.ShowCurrentPositionDispatcher(scroll); @@ -134,7 +138,7 @@ namespace CampusAppWP8.Pages.Campusmap string searchPid = Wp8StringManager.FilterPlaceIdinQRResultString(qrcodeResult); if (searchPid != null) { - this.AddPinsByPids(new List() { searchPid }, MapPinModel.PinType.SearchPlace); + this.ShowAllPlacesByPlaceIdAsSearchPin(searchPid); } } } @@ -143,23 +147,182 @@ namespace CampusAppWP8.Pages.Campusmap #region private - private void FileIsReady() + private void SetLastQuery(string query, Action action) { - + this.lastQuery = query; + this.OnLoadingPlace = new CampusMapPage.LoadingPlace(action); } + private void ShowPlacesByQueryAsHiddenPin(string query) + { + if (!this.IsMapReady()) + { + this.SetLastQuery(query, this.ShowPlacesByQueryAsHiddenPin); + } + else + { + this.ShowPlacesByQuery(query, MapPinModel.PinType.Hidden, false); + } + } + + private void ShowPlacesByQueryAsSearchPin(string query) + { + + if (!this.IsMapReady()) + { + this.SetLastQuery(query, this.ShowPlacesByQueryAsSearchPin); + } + else + { + bool allPlaces = false; + if (Wp8StringManager.IsDigitsOnly(query)) + { + allPlaces = true; + } + this.ShowPlacesByQuery(query, MapPinModel.PinType.SearchPlace, allPlaces); + } + + } + + private void ShowPlacesByQuery(string query, MapPinModel.PinType pintype, bool allPlaces) + { + this.AddPins(this.SearchPlaces(query, allPlaces), pintype); + } + + private void showPlacesByPlaceId(string placeId, MapPinModel.PinType pintype, bool allPlaces) + { + this.AddPinsByPids(new List() { placeId }, pintype, false, allPlaces); + } + + private void ShowAllPlacesByPlaceIdAsSearchPin(string placeId) + { + if (!this.IsMapReady()) + { + this.SetLastQuery(placeId, this.ShowAllPlacesByPlaceIdAsSearchPin); + } + else + { + this.showPlacesByPlaceId(placeId, MapPinModel.PinType.SearchPlace, true); + } + } + + private void ShowPlacesByPlaceIdAsSearchPin(string placeId) + { + if (!this.IsMapReady()) + { + this.SetLastQuery(placeId, this.ShowPlacesByPlaceIdAsSearchPin); + } + else + { + this.showPlacesByPlaceId(placeId, MapPinModel.PinType.SearchPlace, false); + } + } + + private void ShowAllCampusBuilding(string placeId) + { + if (!this.IsMapReady()) + { + this.SetLastQuery(placeId, ShowAllCampusBuilding); + } + else + { + this.AddPins(this.campusMap.Spatial.Places.ToList(), MapPinModel.PinType.InfoPlace, false); + } + } + + private bool IsMapReady() + { + if (this.campusMap == null || !campusMap.IsReady) + { + return false; + } + return true; + } + private void FileIsReady() + { + this.campusMap = new CBMainMapModel(this.file.Model.Places.ToList()); + this.MapCanvas.DataContext = this.campusMap; + this.campusMap.ShowMapInfos += new CBMainMapModel.MapInfos(this.ShowMapInfo); + if (this.OnLoadingPlace != null) + { + this.OnLoadingPlace(this.lastQuery); + } + } + + /// Button click method. + /// Stubbfel, 19.08.2013. + /// caller object. + /// some EventArgs. + private void SearchByText(object sender, RoutedEventArgs e) + { + string query = QString.Text.Trim(); + + if (query.Equals(string.Empty)) + { + return; + } + + this.ClearMap(new List() { MapPinModel.SearchPlacePinString }); + this.ShowPlacesByQueryAsSearchPin(query); + } + + private void ShowBuildingsInformation(object sender, EventArgs e) + { + if (!this.buildInfoEnable) + { + this.ShowAllCampusBuilding(""); + this.buildInfoEnable = true; + } + else + { + this.ClearMap(new List() { MapPinModel.InfoPlacePinString }); + this.buildInfoEnable = false; + } + } + + private void ClearMap(List removeTags = null) + { + + if (removeTags == null) + { + MapCanvas.Children.Clear(); + } + else + { + List childs = MapCanvas.Children.ToList(); + foreach (UIElement child in childs) + { + Image childImg = child as Image; + if (childImg == null) + { + continue; + } + + string imgTag = childImg.Tag.ToString().Trim(); + if (removeTags.Contains(imgTag)) + { + MapCanvas.Children.Remove(child); + } + } + } + + } /// /// Method adds pin to the map by given list of placeId /// /// list of placeId /// type of pin /// (optional) if its true, clear canvas before adding - private void AddPinsByPids(List pidList, MapPinModel.PinType pinType, bool clearCanvas = true) + private void AddPinsByPids(List pidList, MapPinModel.PinType pinType, bool clearCanvas = true, bool allPlaces = false) { // clear canvas if (clearCanvas) { - MapCanvas.Children.Clear(); + this.ClearMap(); + } + else + { + this.ClearMap(new List() { MapPinModel.PinTypeToString(pinType) }); } // null and empty list assert @@ -170,10 +333,19 @@ namespace CampusAppWP8.Pages.Campusmap List placeList = new List(); PlaceModel tmpPlace; + SpsModel spatial; + if (allPlaces) + { + spatial = this.file.Model; + } + else + { + spatial = this.campusMap.Spatial; + } foreach (string pid in pidList) { - tmpPlace = this.campusMap.Spatial.GetPlaceById(pid); + tmpPlace = spatial.GetPlaceById(pid); if (tmpPlace != null) { placeList.Add(tmpPlace); @@ -243,11 +415,11 @@ namespace CampusAppWP8.Pages.Campusmap // add pins to map if (this.Dispatcher != null) { - this.Dispatcher.BeginInvoke(new Action(() => this.AddPinsByPids(new List() { searchPid }, MapPinModel.PinType.SearchPlace))); + this.Dispatcher.BeginInvoke(new Action(() => this.ShowAllPlacesByPlaceIdAsSearchPin(searchPid))); } else { - this.AddPinsByPids(new List() { searchPid }, MapPinModel.PinType.SearchPlace); + this.ShowAllPlacesByPlaceIdAsSearchPin(searchPid); } } else @@ -273,33 +445,26 @@ namespace CampusAppWP8.Pages.Campusmap } } - /// Button click method. - /// Stubbfel, 19.08.2013. - /// caller object. - /// some EventArgs. - private void Button_Click2(object sender, RoutedEventArgs e) - { - string query = QString.Text.Trim(); - - if (query.Equals(string.Empty)) - { - return; - } - - MapCanvas.Children.Clear(); - this.AddPins(this.SearchPlaces(query), MapPinModel.PinType.SearchPlace); - } - /// Searches for the first places. /// Stubbfel, 19.08.2013. /// The query. /// The found places. - private List SearchPlaces(string query) + private List SearchPlaces(string query, bool allPlaces = false) { + SpsModel spatial; + if (allPlaces) + { + spatial = this.file.Model; + } + else + { + spatial = this.campusMap.Spatial; + } + // if query is an id if (Wp8StringManager.IsDigitsOnly(query)) { - return new List() { this.campusMap.Spatial.GetPlaceById(query) }; + return new List() { spatial.GetPlaceById(query) }; } if (this.informationsNames == null) @@ -310,7 +475,8 @@ namespace CampusAppWP8.Pages.Campusmap this.informationsNames.Add(Constants.PisInformationName_ShortName); } - return this.campusMap.Spatial.GetPlacesByInformation(query, true, this.informationsNames); + + return spatial.GetPlacesByInformation(query, true, this.informationsNames); } /// Adds the pins. @@ -322,6 +488,10 @@ namespace CampusAppWP8.Pages.Campusmap { foreach (PlaceModel place in places) { + if (place == null) + { + continue; + } GeoCoordinate coor = place.GeoRefPoint; if (coor != null) { @@ -350,9 +520,6 @@ namespace CampusAppWP8.Pages.Campusmap MapScroller.ScrollToVerticalOffset(scrollPoint.Y); MapScroller.ScrollToHorizontalOffset(scrollPoint.X); } - - // XPoint.Text = x.ToString(); - // YPoint.Text = y.ToString(); } /// On clicking the update button in the ApplicationBar. @@ -480,15 +647,15 @@ namespace CampusAppWP8.Pages.Campusmap if (place.ParentId.Equals(this.campusMap.CampusId) && this.HasRooms(place.PlaceId)) { - MessageBoxResult msgResult = MessageBoxes.ShowPlaceInfoOkCancelMessageBox("Für " + place.GetInformationsValue((Constants.PisInformationName_Name)) + " gibt es eine Raumübersicht. Soll diese angezeigt werden"); - if (msgResult.Equals(MessageBoxResult.OK)) - { - string urlString = Constants.PathCampusmap_RoomListPage; - urlString += "?" + Constants.ParamBuildingId+ "=" + place.PlaceId; - Uri url = new Uri(urlString as string, UriKind.Relative); - this.NavigationService.Navigate(url); - return; - } + MessageBoxResult msgResult = MessageBoxes.ShowPlaceInfoOkCancelMessageBox("Für " + place.GetInformationsValue((Constants.PisInformationName_Name)) + " gibt es eine Raumübersicht. Soll diese angezeigt werden"); + if (msgResult.Equals(MessageBoxResult.OK)) + { + string urlString = Constants.PathCampusmap_RoomListPage; + urlString += "?" + Constants.ParamBuildingId + "=" + place.PlaceId; + Uri url = new Uri(urlString as string, UriKind.Relative); + this.NavigationService.Navigate(url); + return; + } } } } @@ -500,7 +667,7 @@ namespace CampusAppWP8.Pages.Campusmap /// true, if the place has got rooms, otherwise false private bool HasRooms(string placeId) { - foreach (PlaceModel place in this.campusMap.Spatial.Places) + foreach (PlaceModel place in this.file.Model.Places) { if (place.ParentId.Equals(placeId)) { diff --git a/CampusAppWP8/CampusAppWP8/Pages/Dev/NFC.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Dev/NFC.xaml.cs index ec98d2bc..3a883526 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Dev/NFC.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Dev/NFC.xaml.cs @@ -10,6 +10,7 @@ namespace CampusAppWP8.Pages.Dev { using System; using System.Collections.Generic; + using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using System.Windows; using System.Windows.Navigation; @@ -18,6 +19,7 @@ namespace CampusAppWP8.Pages.Dev using CampusAppWP8.Utility.NDEF; using Microsoft.Phone.Controls; using Windows.Networking.Proximity; + using CampusAppWP8.File.Places; /// Nfc page. /// Stubbfel, 22.08.2013. @@ -34,6 +36,8 @@ namespace CampusAppWP8.Pages.Dev /// List of ndefs. private List ndefList; + private PlacesFile file; + #endregion #region Constructor @@ -43,14 +47,30 @@ namespace CampusAppWP8.Pages.Dev public NFC() { this.InitializeComponent(); + + if (this.file == null) + { + this.file = new PlacesFile(); + } + + this.file.OnLoaded += new PlacesFile.OnIO(this.FileIsReady); + this.file.LoadData(); + + + + this.actNDEFIndex = 0; + } + + private void FileIsReady() + { this.ndefList = new List(); - MapModel map = new CBMainMapModel(); + MapModel map = new CBMainMapModel(this.file.Model.Places.ToList()); foreach (PlaceModel place in map.Spatial.Places) { this.ndefList.Add(new NDEFMessage(place.ToNfcString(), NDEFMessage.TYPEVAL.TEXT)); } - this.actNDEFIndex = 0; + this.Writecontent.Text = this.ndefList[this.actNDEFIndex].GetContent(); } #endregion @@ -65,7 +85,6 @@ namespace CampusAppWP8.Pages.Dev protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); - this.Writecontent.Text = this.ndefList[this.actNDEFIndex].GetContent(); } #endregion