mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 12:56:30 +00:00
add gps matcher service
This commit is contained in:
@@ -11,6 +11,7 @@ using Azaion.Common.Database;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.DTO.Config;
|
||||
using Azaion.Common.Extensions;
|
||||
using Azaion.Common.Services;
|
||||
using GMap.NET;
|
||||
using GMap.NET.MapProviders;
|
||||
using GMap.NET.WindowsPresentation;
|
||||
@@ -22,17 +23,19 @@ public partial class MapMatcher : UserControl
|
||||
{
|
||||
private AppConfig _appConfig;
|
||||
List<MediaFileInfo> _allMediaFiles;
|
||||
private Dictionary<string, Annotation> _annotations;
|
||||
private Dictionary<int, Annotation> _annotations;
|
||||
private string _currentDir;
|
||||
private IGpsMatcherService _gpsMatcherService;
|
||||
|
||||
public MapMatcher()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void Init(AppConfig appConfig)
|
||||
public void Init(AppConfig appConfig, IGpsMatcherService gpsMatcherService)
|
||||
{
|
||||
_appConfig = appConfig;
|
||||
_gpsMatcherService = gpsMatcherService;
|
||||
GoogleMapProvider.Instance.ApiKey = appConfig.MapConfig.ApiKey;
|
||||
SatelliteMap.MapProvider = GMapProviders.GoogleSatelliteMap;
|
||||
SatelliteMap.Position = new PointLatLng(48.295985271707664, 37.14477539062501);
|
||||
@@ -44,7 +47,7 @@ public partial class MapMatcher : UserControl
|
||||
private async Task OpenGpsLocation(int gpsFilesIndex)
|
||||
{
|
||||
var media = GpsFiles.Items[gpsFilesIndex] as MediaFileInfo;
|
||||
var ann = _annotations.GetValueOrDefault(Path.GetFileNameWithoutExtension(media.Name));
|
||||
var ann = _annotations.GetValueOrDefault(gpsFilesIndex);
|
||||
GpsImageEditor.Background = new ImageBrush
|
||||
{
|
||||
ImageSource = await Path.Combine(_currentDir, ann.Name).OpenImage()
|
||||
@@ -91,70 +94,63 @@ public partial class MapMatcher : UserControl
|
||||
Path = x.FullName,
|
||||
MediaType = MediaTypes.Image
|
||||
}).ToList();
|
||||
// var allFiles = videoFiles.Concat(imageFiles).ToList();
|
||||
//
|
||||
|
||||
// var labelsDict = await _dbFactory.Run(async db => await db.Annotations
|
||||
// .GroupBy(x => x.Name.Substring(0, x.Name.Length - 7))
|
||||
// .Where(x => allFileNames.Contains(x.Key))
|
||||
// .ToDictionaryAsync(x => x.Key, x => x.Key));
|
||||
//
|
||||
// foreach (var mediaFile in allFiles)
|
||||
// mediaFile.HasAnnotations = labelsDict.ContainsKey(mediaFile.FName);
|
||||
//
|
||||
// AllMediaFiles = new ObservableCollection<MediaFileInfo>(allFiles);
|
||||
|
||||
_allMediaFiles = mediaFiles;
|
||||
GpsFiles.ItemsSource = new ObservableCollection<MediaFileInfo>(_allMediaFiles);
|
||||
var annotations = SetFromCsv(mediaFiles);
|
||||
Cursor = Cursors.Wait;
|
||||
await Task.Delay(TimeSpan.FromSeconds(10));
|
||||
SetMarkers(annotations);
|
||||
Cursor = Cursors.Arrow;
|
||||
await OpenGpsLocation(0);
|
||||
}
|
||||
|
||||
private Dictionary<string, Annotation> SetFromCsv(List<MediaFileInfo> mediaFiles)
|
||||
{
|
||||
_annotations = mediaFiles.Select(x => new Annotation
|
||||
_annotations = mediaFiles.Select((x, i) => (i, new Annotation
|
||||
{
|
||||
Name = x.Name,
|
||||
OriginalMediaName = x.Name
|
||||
}).ToDictionary(x => Path.GetFileNameWithoutExtension(x.OriginalMediaName));
|
||||
})).ToDictionary(x => x.i, x => x.Item2);
|
||||
|
||||
var csvResults = GpsCsvResult.ReadFromCsv(Constants.CSV_PATH);
|
||||
var initialLat = double.Parse(TbLat.Text);
|
||||
var initialLon = double.Parse(TbLon.Text);
|
||||
|
||||
await _gpsMatcherService.RunGpsMatching(dir.FullName, initialLat, initialLon, async res => await SetMarker(res));
|
||||
}
|
||||
|
||||
private async Task SetMarker(GpsMatchResult result)
|
||||
{
|
||||
await Dispatcher.Invoke(async () =>
|
||||
{
|
||||
var marker = new GMapMarker(new PointLatLng(result.Latitude, result.Longitude));
|
||||
var ann = _annotations[result.Index];
|
||||
marker.Shape = new CircleVisual(marker, System.Windows.Media.Brushes.Blue)
|
||||
{
|
||||
Text = ann.Name
|
||||
};
|
||||
SatelliteMap.Markers.Add(marker);
|
||||
ann.Lat = result.Latitude;
|
||||
ann.Lon = result.Longitude;
|
||||
SatelliteMap.Position = new PointLatLng(result.Latitude, result.Longitude);
|
||||
SatelliteMap.ZoomAndCenterMarkers(null);
|
||||
});
|
||||
}
|
||||
|
||||
private async Task SetFromCsv(List<MediaFileInfo> mediaFiles)
|
||||
{
|
||||
|
||||
var csvResults = GpsMatchResult.ReadFromCsv(Constants.CSV_PATH);
|
||||
var csvDict = csvResults
|
||||
.Where(x => x.MatchType == "stitched")
|
||||
.ToDictionary(x => x.Image);
|
||||
.ToDictionary(x => x.Index);
|
||||
foreach (var ann in _annotations)
|
||||
{
|
||||
var csvRes = csvDict.GetValueOrDefault(ann.Key);
|
||||
if (csvRes == null)
|
||||
continue;
|
||||
|
||||
ann.Value.Lat = csvRes.Latitude;
|
||||
ann.Value.Lon = csvRes.Longitude;
|
||||
await SetMarker(csvRes);
|
||||
}
|
||||
return _annotations;
|
||||
}
|
||||
|
||||
private void SetMarkers(Dictionary<string, Annotation> annotations)
|
||||
private async void TestGps(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!annotations.Any())
|
||||
if (string.IsNullOrEmpty(TbGpsMapFolder.Text))
|
||||
return;
|
||||
|
||||
var firstAnnotation = annotations.FirstOrDefault();
|
||||
SatelliteMap.Position = new PointLatLng(firstAnnotation.Value.Lat, firstAnnotation.Value.Lon);
|
||||
foreach (var ann in annotations.Where(x => x.Value.Lat != 0 && x.Value.Lon != 0))
|
||||
{
|
||||
var marker = new GMapMarker(new PointLatLng(ann.Value.Lat, ann.Value.Lon));
|
||||
var circle = new CircleVisual(marker, System.Windows.Media.Brushes.Blue)
|
||||
{
|
||||
Text = " "
|
||||
};
|
||||
marker.Shape = circle;
|
||||
SatelliteMap.Markers.Add(marker);
|
||||
}
|
||||
SatelliteMap.ZoomAndCenterMarkers(null);
|
||||
var initialLat = double.Parse(TbLat.Text);
|
||||
var initialLon = double.Parse(TbLon.Text);
|
||||
await _gpsMatcherService.RunGpsMatching(TbGpsMapFolder.Text, initialLat, initialLon, async res => await SetMarker(res));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user