using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using Comal.Classes;
using InABox.Clients;
using InABox.Core;
using InABox.Wpf;
using Syncfusion.UI.Xaml.Maps;
using Syncfusion.Windows.PdfViewer;
using Syncfusion.XlsIO.Implementation.PivotTables;
using Point = System.Windows.Point;
namespace PRSDesktop.Forms
{
///
/// Interaction logic for MapForm.xaml
///
public partial class MapForm : ThemableWindow
{
private double _zoom = 18.0;
public MapForm(double latitude, double longitude, GeoFenceDefinition? geofence = null, DateTime? timestamp = null)
{
InitializeComponent();
var geopoint = new GeoPoint(latitude, longitude);
if (geofence?.Coordinates.Any() == true)
Polygon.Points = new ObservableCollection(geofence.Coordinates.Select(p => new Point(p.Latitude, p.Longitude)));
else
{
var circle = new MapCircle();
circle.Center = new Point(latitude, longitude);
circle.Radius = 25;
circle.Fill = new SolidColorBrush(Colors.Red) { Opacity = 0.5 };
subLayer.MapElements.Add(circle);
}
// var fences = Client.Query().ToArray();
// foreach (var fence in fences)
// {
// var def = Serialization.Deserialize(fence.Geofence) ?? new GeoFenceDefinition();
// if (def.Contains(geopoint))
// {
// Polygon.Points = new ObservableCollection(def.Coordinates.Select(p => new Point(p.Latitude, p.Longitude)));
// break;
// }
// }
if (timestamp.HasValue)
TimeStamp.Content = $"Last Updated {timestamp:dd MMM yyy hh:mm:ss tt}";
else
TimeStamp.Visibility = Visibility.Collapsed;
ImageryLayer.Center = new Point(latitude,longitude);
}
private void ZoomIn_OnClick(object sender, RoutedEventArgs e)
{
Map.MaxZoom = Math.Min(20, Map.ZoomLevel + 1);
Map.ZoomLevel = Math.Min(20, Map.ZoomLevel + 1);
}
private void ZoomOut_OnClick(object sender, RoutedEventArgs e)
{
Map.MinZoom= Math.Max(5, Map.ZoomLevel - 1);
Map.ZoomLevel = Math.Max(5, Map.ZoomLevel - 1);
}
}
}