Added support for multiple images

This commit is contained in:
2015-12-22 23:48:18 +01:00
parent 711675e389
commit 7ad8e3251a
33 changed files with 382 additions and 460 deletions
-127
View File
@@ -1,127 +0,0 @@
using NavCityBreda.Model;
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NavCityBreda.Helpers
{
class JSONParser
{
public static Route LoadRoute(string foldername)
{
if (!Directory.Exists("Routes/" + foldername))
throw new FileNotFoundException("The route folder does not exist: " + foldername);
string datafile = "Routes/" + foldername + "/data.json";
if (!File.Exists(datafile))
throw new FileNotFoundException("The route data file does not exist.");
string json = File.ReadAllText(datafile);
JObject o = JObject.Parse(json);
string error;
if (!ValidateRouteObject(o, out error))
throw new FileLoadException("Invalid Route information in " + datafile + ", " + error);
Route r = new Route((string)o["name"], (string)o["description"], (string)o["landmarks"], foldername);
JToken[] waypoints = o["waypoints"].ToArray();
int count = 0;
foreach(JToken t in waypoints)
{
if(!ValidateWaypointObject(t, out error))
throw new FileLoadException("Invalid Waypoint information in " + datafile + ", " + error);
Waypoint w;
if ((bool)t["landmark"])
w = new Landmark((double)t["latitude"], (double)t["longitude"], (string)t["name"], (string)t["description"], count, t["image"].NullOrEmpty() ? "" : (string)t["image"]);
else
w = new Waypoint((double)t["latitude"], (double)t["longitude"], (string)t["name"], count);
r.Add(w);
count++;
}
return r;
}
private static bool ValidateRouteObject(JObject o, out string error)
{
bool valid = true;
error = "Success";
if (o["name"].NullOrEmpty())
{
valid = false;
error = "Name missing";
}
if (o["description"].NullOrEmpty())
{
valid = false;
error = "Description missing";
}
if (o["landmarks"].NullOrEmpty())
{
valid = false;
error = "Landmarks missing";
}
if (o["waypoints"].NullOrEmpty())
{
valid = false;
error = "Waypoints missing or empty";
}
return valid;
}
private static bool ValidateWaypointObject(JToken o, out string error)
{
bool valid = true;
error = "Success";
if (o["name"].NullOrEmpty())
{
valid = false;
error = "Name missing";
}
if (o["landmark"].NullOrEmpty())
{
valid = false;
error = "Landmark missing";
}
if (o["latitude"].NullOrEmpty())
{
valid = false;
error = "Latitude missing";
}
if (o["longitude"].NullOrEmpty())
{
valid = false;
error = "Longitude missing";
}
if( valid && (bool)o["landmark"])
{
if (o["description"].NullOrEmpty())
{
valid = false;
error = "Description missing";
}
}
return valid;
}
}
}
+27
View File
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.ViewManagement;
namespace NavCityBreda.Model
{
public class Image
{
public string Source { get; private set; }
public Image(string source)
{
Source = source;
}
public double Width
{
get
{
return ApplicationView.GetForCurrentView().VisibleBounds.Width;
}
}
}
}
+15 -13
View File
@@ -17,7 +17,7 @@ namespace NavCityBreda.Model
private string _desckey;
public string Description { get { return Util.Loader.GetString(_desckey); } }
public string Image { get; private set; }
public List<Image> Images { get; private set; }
private bool _visited;
public bool Visited
@@ -26,7 +26,7 @@ namespace NavCityBreda.Model
set
{
_visited = value;
UpdateIconImage();
UpdateIcon();
}
}
@@ -34,34 +34,36 @@ namespace NavCityBreda.Model
public MapIcon Icon { get; set; }
public Landmark(Geopoint p, string name, string desc, int num, string image_loc = "default.jpg") : base (p, name, num)
public Landmark(Geopoint p, string name, int num, string desc, List<Image> images) : base (p, name, num)
{
Create(Location, name, desc, num, image_loc);
Create(name, desc, num, images);
}
public Landmark(double la, double lo, string name, string desc, int num, string image_loc = "default.jpg") : base(la, lo, name, num)
public Landmark(double la, double lo, string name, int num, string desc, List<Image> images) : base(la, lo, name, num)
{
Create(Location, name, desc, num, image_loc);
Create(name, desc, num, images);
}
private void Create(Geopoint p, string name, string desc, int num, string image_loc)
private void Create(string name, string desc, int num, List<Image> images)
{
_visited = false;
_desckey = desc;
if (image_loc == "" || !File.Exists(App.RouteImagesFolder + image_loc))
image_loc = "default.jpg";
Image = "/" + App.RouteImagesFolder + image_loc;
Id = Name + "_" + Order;
Images = images;
Id = _namekey + "_" + Order;
Icon = new MapIcon();
Icon.Location = Location;
Icon.NormalizedAnchorPoint = new Point(0.5, 1.0);
Icon.Title = Name;
Icon.ZIndex = 10;
Icon.ZIndex = 500;
}
public void UpdateIconImage()
public void UpdateIcon()
{
Icon.Title = Name;
if(_visited)
Icon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/LandmarkVisited.png"));
else

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

@@ -2,16 +2,14 @@
"name": "RouteName",
"description": "RouteDescription",
"landmarks": "RouteLandmarks",
"waypoints": [
{
"waypoints": [{
"name": "VVVName",
"landmark": true,
"description": "VVVDescription",
"image": "historische_kilometer_1.jpg",
"image": [ "historische_kilometer_1.jpg", "historische_kilometer_2.jpg"],
"latitude": 51.594112,
"longitude": 4.779417
},
{
"name": "LZName",
"landmark": true,
@@ -83,10 +81,10 @@
"longitude": 4.775
},
{
"name": "Huis van Brecht",
"name": "HBName",
"landmark": true,
"description": "Het Huis van Brecht is een van de meer historyse gebouwen in Breda.",
"image": "historische_kilometer_7.jpg",
"description": "HBDescription",
"image": ["historische_kilometer_7.jpg", "historische_kilometer_14.jpg", "historische_kilometer_21.jpg", "historische_kilometer_22.jpg"],
"latitude": 51.590028,
"longitude": 4.774362
},
@@ -172,7 +170,7 @@
"latitude": 51.58875,
"longitude": 4.776112
},
{ // corordinaten
{
"name": "terug naar de grote markt",
"landmark": false,
"latitude": 51.587972,
@@ -314,9 +312,5 @@
"description": "Einde stadswandeling",
"latitude": 51.5895,
"longitude": 4.77625
}
]
}]
}

Before

Width:  |  Height:  |  Size: 332 KiB

After

Width:  |  Height:  |  Size: 332 KiB

Before

Width:  |  Height:  |  Size: 229 KiB

After

Width:  |  Height:  |  Size: 229 KiB

Before

Width:  |  Height:  |  Size: 238 KiB

After

Width:  |  Height:  |  Size: 238 KiB

Before

Width:  |  Height:  |  Size: 385 KiB

After

Width:  |  Height:  |  Size: 385 KiB

Before

Width:  |  Height:  |  Size: 276 KiB

After

Width:  |  Height:  |  Size: 276 KiB

Before

Width:  |  Height:  |  Size: 284 KiB

After

Width:  |  Height:  |  Size: 284 KiB

Before

Width:  |  Height:  |  Size: 273 KiB

After

Width:  |  Height:  |  Size: 273 KiB

Before

Width:  |  Height:  |  Size: 262 KiB

After

Width:  |  Height:  |  Size: 262 KiB

Before

Width:  |  Height:  |  Size: 295 KiB

After

Width:  |  Height:  |  Size: 295 KiB

Before

Width:  |  Height:  |  Size: 360 KiB

After

Width:  |  Height:  |  Size: 360 KiB

Before

Width:  |  Height:  |  Size: 303 KiB

After

Width:  |  Height:  |  Size: 303 KiB

Before

Width:  |  Height:  |  Size: 347 KiB

After

Width:  |  Height:  |  Size: 347 KiB

Before

Width:  |  Height:  |  Size: 415 KiB

After

Width:  |  Height:  |  Size: 415 KiB

Before

Width:  |  Height:  |  Size: 335 KiB

After

Width:  |  Height:  |  Size: 335 KiB

Before

Width:  |  Height:  |  Size: 299 KiB

After

Width:  |  Height:  |  Size: 299 KiB

Before

Width:  |  Height:  |  Size: 230 KiB

After

Width:  |  Height:  |  Size: 230 KiB

Before

Width:  |  Height:  |  Size: 662 KiB

After

Width:  |  Height:  |  Size: 662 KiB

Before

Width:  |  Height:  |  Size: 457 KiB

After

Width:  |  Height:  |  Size: 457 KiB

Before

Width:  |  Height:  |  Size: 256 KiB

After

Width:  |  Height:  |  Size: 256 KiB

Before

Width:  |  Height:  |  Size: 467 KiB

After

Width:  |  Height:  |  Size: 467 KiB

Before

Width:  |  Height:  |  Size: 339 KiB

After

Width:  |  Height:  |  Size: 339 KiB

Before

Width:  |  Height:  |  Size: 385 KiB

After

Width:  |  Height:  |  Size: 385 KiB

Before

Width:  |  Height:  |  Size: 307 KiB

After

Width:  |  Height:  |  Size: 307 KiB

Before

Width:  |  Height:  |  Size: 373 KiB

After

Width:  |  Height:  |  Size: 373 KiB

Before

Width:  |  Height:  |  Size: 330 KiB

After

Width:  |  Height:  |  Size: 330 KiB

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

+4 -2
View File
@@ -7,6 +7,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
namespace NavCityBreda.ViewModels
{
@@ -39,11 +41,11 @@ namespace NavCityBreda.ViewModels
}
}
public string Image
public List<Image> Images
{
get
{
return landmark.Image;
return landmark.Images;
}
}
+25 -1
View File
@@ -19,7 +19,31 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Source="{Binding Image}" Grid.Row="0" />
<ListView Grid.Row="0" ItemsSource="{Binding Images}"
ScrollViewer.HorizontalScrollMode="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollMode="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Padding" Value="0"/>
<Setter Property="Margin" Value="0"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate x:Name="ListViewDataTemplate">
<Image Source="{Binding Source}" Height="{Binding Width}" Width="{Binding Width}" Stretch="UniformToFill"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<!--<Image Source="{Binding Image}" Grid.Row="0" />-->
<Grid Grid.Row="1" Margin="10">
<Grid.ColumnDefinitions>