From 51a8e4e515f0d00b087ab4abc254f72d25a09dcf Mon Sep 17 00:00:00 2001 From: stubbfel Date: Mon, 19 Aug 2013 15:39:19 +0200 Subject: [PATCH] add placesearch --- .../CampusAppWP8/Api/GeoApi/CampusSpsApi.cs | 1 + CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj | 2 + .../Model/Campusmap/CBMainMapModel.cs | 31 ++++++++++ .../CampusAppWP8/Model/Campusmap/MapModel.cs | 11 ++++ .../Model/GeoDb/PlaceInformation.cs | 26 +++++++++ .../CampusAppWP8/Model/GeoDb/PlaceModel.cs | 51 ++++++++++++++++ .../CampusAppWP8/Model/GeoDb/PlaceService.cs | 32 ++++++++++ .../CampusAppWP8/Model/GeoDb/SpsModel.cs | 54 +++++++++++++++++ .../Pages/Campusmap/CampusMapPage.xaml | 10 +++- .../Pages/Campusmap/CampusMapPage.xaml.cs | 58 +++++++++++++++++-- .../Pages/Mensa/MensaPage.xaml.cs | 20 ++++--- .../Resources/Constants.Designer.cs | 9 +++ .../CampusAppWP8/Resources/Constants.resx | 3 + 13 files changed, 291 insertions(+), 17 deletions(-) create mode 100644 CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceInformation.cs create mode 100644 CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceService.cs diff --git a/CampusAppWP8/CampusAppWP8/Api/GeoApi/CampusSpsApi.cs b/CampusAppWP8/CampusAppWP8/Api/GeoApi/CampusSpsApi.cs index 06311c97..3502c684 100644 --- a/CampusAppWP8/CampusAppWP8/Api/GeoApi/CampusSpsApi.cs +++ b/CampusAppWP8/CampusAppWP8/Api/GeoApi/CampusSpsApi.cs @@ -14,6 +14,7 @@ namespace CampusAppWP8.Feed.GeoApi using CampusAppWP8.Model.Utility; using CampusAppWP8.Resources; using CampusAppWP8.Utility; + using System.Device.Location; /// /// Class for SPSAPI diff --git a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj index 49f9a372..1df934e5 100644 --- a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj +++ b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj @@ -105,7 +105,9 @@ + + diff --git a/CampusAppWP8/CampusAppWP8/Model/Campusmap/CBMainMapModel.cs b/CampusAppWP8/CampusAppWP8/Model/Campusmap/CBMainMapModel.cs index 6360352a..f10d1056 100644 --- a/CampusAppWP8/CampusAppWP8/Model/Campusmap/CBMainMapModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/CBMainMapModel.cs @@ -7,7 +7,9 @@ //----------------------------------------------------------------------------- namespace CampusAppWP8.Model.Campusmap { + using System.Collections.ObjectModel; using System.Windows; + using CampusAppWP8.Model.GeoDb; /// /// Class for the MapModel of the mainCampus of cottbus @@ -30,5 +32,34 @@ namespace CampusAppWP8.Model.Campusmap this.GeoOffsetX = 14.327159; this.GeoOffsetY = 51.766548; } + + /// Loads the spatial./. + /// Stubbfel, 19.08.2013. + protected override void LoadSpatials() + { + ObservableCollection places = new ObservableCollection(); + ObservableCollection infos = new ObservableCollection(); + + infos.Add(new PlaceInformation() { InformationName = "name", InformationValue = "Campus Cottbus Mitte" }); + infos.Add(new PlaceInformation() { InformationName = "type", InformationValue = "campus" }); + places.Add(new PlaceModel() { PlaceId = "1", RefPoint = "POINT(14.324056352976152 51.76737987049448)", Informations = infos }); + + infos = new ObservableCollection(); + infos.Add(new PlaceInformation() { InformationName = "name", InformationValue = "MZG" }); + infos.Add(new PlaceInformation() { InformationName = "type", InformationValue = "Mehrzweck" }); + places.Add(new PlaceModel() { PlaceId = "5", ParentId = "1", RefPoint = "POINT(14.321714914733889 51.76608468494122)", Informations = infos }); + + infos = new ObservableCollection(); + infos.Add(new PlaceInformation() { InformationName = "name", InformationValue = "BTU Mensa" }); + infos.Add(new PlaceInformation() { InformationName = "type", InformationValue = "restaurant" }); + places.Add(new PlaceModel() { PlaceId = "145280193", ParentId = "1", RefPoint = "POINT(14.326168833333334 51.76649038666667)", Informations = infos }); + + if (this.Spatial == null) + { + this.Spatial = new SpsModel(); + } + + this.Spatial.Places = places; + } } } diff --git a/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs b/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs index c015d99f..38e1ef38 100644 --- a/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/Campusmap/MapModel.cs @@ -11,6 +11,7 @@ namespace CampusAppWP8.Model.Campusmap using System.Windows; using System.Windows.Controls; using System.Windows.Media.Imaging; + using CampusAppWP8.Model.GeoDb; /// /// This Class manage the properties of a Map @@ -24,6 +25,7 @@ namespace CampusAppWP8.Model.Campusmap /// public MapModel() { + this.LoadSpatials(); } #endregion @@ -80,6 +82,10 @@ namespace CampusAppWP8.Model.Campusmap /// public Point RefPoint { get; set; } + /// Gets or sets the spatial of the map. + /// The spatial. + public SpsModel Spatial { get; set; } + #endregion #region Methods @@ -199,6 +205,11 @@ namespace CampusAppWP8.Model.Campusmap return this.ConverToMapPoint(point.X, point.Y); } + /// Loads the spatial./ + /// Stubbfel, 19.08.2013. + protected virtual void LoadSpatials() + { + } #endregion } } diff --git a/CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceInformation.cs b/CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceInformation.cs new file mode 100644 index 00000000..ee09ea34 --- /dev/null +++ b/CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceInformation.cs @@ -0,0 +1,26 @@ +//----------------------------------------------------------------------- +// +// Company copyright tag. +// +// stubbfel +// 19.08.2013 +//---------------------------------------------------------------------- +namespace CampusAppWP8.Model.GeoDb +{ + using System.Xml.Serialization; + + /// Information about the place. + /// Stubbfel, 19.08.2013. + public class PlaceInformation + { + /// Gets or sets the name of the information. + /// The name of the information. + [XmlElement("placeInformationName")] + public string InformationName { get; set; } + + /// Gets or sets the information value. + /// The information value. + [XmlText] + public string InformationValue { get; set; } + } +} diff --git a/CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceModel.cs b/CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceModel.cs index 68acbbbe..876a7701 100644 --- a/CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceModel.cs @@ -8,7 +8,14 @@ namespace CampusAppWP8.Model.GeoDb { + using System; + using System.Collections.ObjectModel; + using System.Device.Location; + using System.Globalization; + using System.Text.RegularExpressions; using System.Xml.Serialization; + using CampusAppWP8.Resources; + using CampusAppWP8.Utility; /// /// Model for a place of the SPSService @@ -32,5 +39,49 @@ namespace CampusAppWP8.Model.GeoDb /// [XmlAttribute("refpoint")] public string RefPoint { get; set; } + + /// Gets the geo reference point. + /// The geo reference point. + public GeoCoordinate GeoRefPoint + { + get + { + string refstring = this.RefPoint; + Regex rx = new Regex(Constants.Regex_Coordinate); + MatchCollection matches = rx.Matches(refstring); + if (matches.Count != 1) + { + return null; + } + + string[] values = matches[0].ToString().Split(' '); + + if (values.Length != 2) + { + return null; + } + + // create the GeoCoordirate + try + { + return new GeoCoordinate(double.Parse(values[1], CultureInfo.InvariantCulture), double.Parse(values[0], CultureInfo.InvariantCulture)); + } + catch (Exception ex) + { + Logger.LogException(ex); + return null; + } + } + } + + /// Gets or sets the information. + /// The information. + [XmlElement("placeInformation")] + public ObservableCollection Informations { get; set; } + + /// Gets or sets the services. + /// The services. + [XmlElement("placeService")] + public ObservableCollection Services { get; set; } } } diff --git a/CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceService.cs b/CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceService.cs new file mode 100644 index 00000000..f0a22000 --- /dev/null +++ b/CampusAppWP8/CampusAppWP8/Model/GeoDb/PlaceService.cs @@ -0,0 +1,32 @@ +//----------------------------------------------------------------------------- +// +// Company copyright tag. +// +// stubbfel +// 19.08.2013 +//----------------------------------------------------------------------------- + +namespace CampusAppWP8.Model.GeoDb +{ + using System.Xml.Serialization; + + /// Place service. + /// Stubbfel, 19.08.2013. + public class PlaceService + { + /// Gets or sets the name of the service. + /// The name of the service. + [XmlAttribute("placeServiceName")] + public string ServiceName { get; set; } + + /// Gets or sets the SAP of an service. + /// The sap. + [XmlElement("sap")] + public string SAP { get; set; } + + /// Gets or sets the request for a place. + /// The request. + [XmlElement("request")] + public string Request { get; set; } + } +} diff --git a/CampusAppWP8/CampusAppWP8/Model/GeoDb/SpsModel.cs b/CampusAppWP8/CampusAppWP8/Model/GeoDb/SpsModel.cs index 0b4fea86..2970ee95 100644 --- a/CampusAppWP8/CampusAppWP8/Model/GeoDb/SpsModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/GeoDb/SpsModel.cs @@ -8,7 +8,9 @@ namespace CampusAppWP8.Model.GeoDb { + using System.Collections.Generic; using System.Collections.ObjectModel; + using System.Linq; using System.Xml.Serialization; /// @@ -22,5 +24,57 @@ namespace CampusAppWP8.Model.GeoDb /// [XmlElement("place")] public ObservableCollection Places { get; set; } + + /// Gets places by information. + /// Stubbfel, 19.08.2013. + /// The query. + /// (Optional) the ignore cases. + /// (Optional) name of the information. + /// The places by information. + public List GetPlacesByInformation(string query, bool ignoreCases = true, string informationName = null) + { + string querryLow = string.Empty; + IEnumerable resultplaces = null; + + // select correct statement + if (ignoreCases && informationName == null) + { + querryLow = query.ToLower(); + resultplaces = from place in this.Places + from info in place.Informations + where info.InformationValue.ToLower().Contains(querryLow) + select place; + } + else if (ignoreCases && informationName != null) + { + querryLow = query.ToLower(); + resultplaces = from place in this.Places + from info in place.Informations + where info.InformationValue.ToLower().Contains(querryLow) && info.InformationName.Equals(informationName) + select place; + } + else if (!ignoreCases && informationName == null) + { + resultplaces = from place in this.Places + from info in place.Informations + where info.InformationValue.Contains(querryLow) + select place; + } + else if (!ignoreCases && informationName != null) + { + resultplaces = from place in this.Places + from info in place.Informations + where info.InformationValue.Contains(querryLow) && info.InformationName.Equals(informationName) + select place; + } + + // null assert + if (resultplaces == null) + { + return null; + } + + return resultplaces.ToList(); + } } } diff --git a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml index fc512ed1..cf91d39f 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml +++ b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml @@ -35,11 +35,11 @@ - + - + + + + + diff --git a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs index 42ce2b8b..ddc82665 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Campusmap/CampusMapPage.xaml.cs @@ -8,11 +8,14 @@ namespace CampusAppWP8.Pages.Campusmap { using System; + using System.Collections.Generic; + using System.Device.Location; using System.Globalization; using System.Threading; using System.Windows; using System.Windows.Navigation; using CampusAppWP8.Model.Campusmap; + using CampusAppWP8.Model.GeoDb; using CampusAppWP8.Resources; using CampusAppWP8.Utility; using Microsoft.Phone.Controls; @@ -39,7 +42,9 @@ namespace CampusAppWP8.Pages.Campusmap protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); - this.ShowCurrentPositionDispatcher(); + MapCanvas.Children.Clear(); + this.AddPins(this.SearchPlaces("campus")); + this.ShowCurrentPositionDispatcher(); } /// Button click method. @@ -48,7 +53,48 @@ namespace CampusAppWP8.Pages.Campusmap /// some EventArgs. private void Button_Click(object sender, RoutedEventArgs e) { - this.AddPin(double.Parse(XPoint.Text), double.Parse(YPoint.Text)); + // this.AddPin(double.Parse(XPoint.Text), double.Parse(YPoint.Text)); + } + + /// 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)); + } + + /// Searches for the first places. + /// Stubbfel, 19.08.2013. + /// The query. + /// The found places. + private List SearchPlaces(string query) + { + return this.map.Spatial.GetPlacesByInformation(query); + } + + /// Adds the pins. + /// Stubbfel, 19.08.2013. + /// The places. + private void AddPins(List places) + { + foreach (PlaceModel place in places) + { + GeoCoordinate coor = place.GeoRefPoint; + if (coor != null) + { + this.AddPin(coor.Longitude, coor.Latitude); + } + } } /// Add Pin to an certain position. @@ -57,15 +103,15 @@ namespace CampusAppWP8.Pages.Campusmap /// latitude parameter. private void AddPin(double x, double y) { - MapCanvas.Children.Clear(); Point scrollPoint = this.map.GetScrollPoint(this.map.ConverToPixelPoint(this.map.ConverToMapPoint(x, y))); MapCanvas.Children.Add(this.map.AddPinFromRefPoint(this.map.ConverToPixelPoint(this.map.ConverToMapPoint(x, y)))); MapScroller.UpdateLayout(); MapScroller.ScrollToVerticalOffset(scrollPoint.Y); MapScroller.ScrollToHorizontalOffset(scrollPoint.X); - XPoint.Text = x.ToString(); - YPoint.Text = y.ToString(); + + // XPoint.Text = x.ToString(); + // YPoint.Text = y.ToString(); } /// On clicking the update button in the ApplicationBar. @@ -74,7 +120,7 @@ namespace CampusAppWP8.Pages.Campusmap /// some EventArgs. private void UpdateButtonAppBar_Click(object sender, System.EventArgs e) { - this.ShowCurrentPositionDispatcher(); + this.ShowCurrentPositionDispatcher(); } /// execute ShowCurrentPosition-Method via Dispatcher. diff --git a/CampusAppWP8/CampusAppWP8/Pages/Mensa/MensaPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Mensa/MensaPage.xaml.cs index 234d15b4..b1931f73 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Mensa/MensaPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Mensa/MensaPage.xaml.cs @@ -15,6 +15,7 @@ namespace CampusAppWP8.Pages.Mensa using CampusAppWP8.Resources; using CampusAppWP8.Utility.Lui.MessageBoxes; using Microsoft.Phone.Controls; + using System.Threading; /// /// Class for the MensaPage @@ -99,7 +100,14 @@ namespace CampusAppWP8.Pages.Mensa /// private void SpsApiIsReady() { - this.InitializeFeed(this.campusApi.GetCampus()); + if (this.Dispatcher != null) + { + this.Dispatcher.BeginInvoke(new Action(() => this.InitializeFeed(this.campusApi.GetCampus()))); + } + else + { + this.InitializeFeed(this.campusApi.GetCampus()); + } } /// @@ -153,14 +161,8 @@ namespace CampusAppWP8.Pages.Mensa { if (Settings.AppSetting.GeoWatchEnable) { - if (this.Dispatcher != null) - { - this.Dispatcher.BeginInvoke(new Action(() => this.DeterminCurrentCampusAndLoadFeed())); - } - else - { - this.DeterminCurrentCampusAndLoadFeed(); - } + Thread thread = new Thread(new ThreadStart( this.DeterminCurrentCampusAndLoadFeed)); + thread.Start(); } else { diff --git a/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs b/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs index 8509b945..b0d84d4e 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs +++ b/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs @@ -645,6 +645,15 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die [+-]{0,1}[0-9]+[.,]{0,1}[0-9]+[\s][+-]{0,1}[0-9]+[.,]{0,1}[0-9]+ ähnelt. + /// + public static string Regex_Coordinate { + get { + return ResourceManager.GetString("Regex_Coordinate", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die 767 ähnelt. /// diff --git a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx index 7463f1be..4366a89a 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx +++ b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx @@ -408,4 +408,7 @@ /Pages/Campusmap/CampusMapPage.xaml + + [+-]{0,1}[0-9]+[.,]{0,1}[0-9]+[\s][+-]{0,1}[0-9]+[.,]{0,1}[0-9]+ + \ No newline at end of file