mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:16:30 +00:00
f58dd3d04f
lat lon -> geopoint correct location for gps if small keypoints number
119 lines
4.0 KiB
C#
119 lines
4.0 KiB
C#
using System.Collections.ObjectModel;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
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 Microsoft.WindowsAPICodePack.Dialogs;
|
|
|
|
namespace Azaion.Annotator.Controls;
|
|
|
|
public partial class MapMatcher : UserControl
|
|
{
|
|
private AppConfig _appConfig = null!;
|
|
List<MediaFileInfo> _allMediaFiles = new();
|
|
public Dictionary<int, Annotation> Annotations = new();
|
|
private string _currentDir = null!;
|
|
private IGpsMatcherService _gpsMatcherService = null!;
|
|
|
|
public MapMatcher()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
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);
|
|
SatelliteMap.MultiTouchEnabled = true;
|
|
|
|
GpsFiles.MouseDoubleClick += async (sender, args) => { await OpenGpsLocation(GpsFiles.SelectedIndex); };
|
|
}
|
|
|
|
private async Task OpenGpsLocation(int gpsFilesIndex)
|
|
{
|
|
//var media = GpsFiles.Items[gpsFilesIndex] as MediaFileInfo;
|
|
var ann = Annotations.GetValueOrDefault(gpsFilesIndex);
|
|
if (ann == null)
|
|
return;
|
|
|
|
GpsImageEditor.Background = new ImageBrush
|
|
{
|
|
ImageSource = await Path.Combine(_currentDir, ann.Name).OpenImage()
|
|
};
|
|
if (ann.Lat != 0 && ann.Lon != 0)
|
|
SatelliteMap.Position = new PointLatLng(ann.Lat, ann.Lon);
|
|
}
|
|
|
|
private void GpsFilesContextOpening(object sender, ContextMenuEventArgs e)
|
|
{
|
|
var listItem = sender as ListViewItem;
|
|
GpsFilesContextMenu.DataContext = listItem!.DataContext;
|
|
}
|
|
|
|
private void OpenContainingFolder(object sender, RoutedEventArgs e)
|
|
{
|
|
var mediaFileInfo = (sender as MenuItem)?.DataContext as MediaFileInfo;
|
|
if (mediaFileInfo == null)
|
|
return;
|
|
|
|
Process.Start("explorer.exe", "/select,\"" + mediaFileInfo.Path +"\"");
|
|
}
|
|
|
|
private async void OpenGpsTilesFolderClick(object sender, RoutedEventArgs e)
|
|
{
|
|
var dlg = new CommonOpenFileDialog
|
|
{
|
|
Title = "Open Video folder",
|
|
IsFolderPicker = true,
|
|
InitialDirectory = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)
|
|
};
|
|
var dialogResult = dlg.ShowDialog();
|
|
|
|
if (dialogResult != CommonFileDialogResult.Ok || string.IsNullOrEmpty(dlg.FileName))
|
|
return;
|
|
|
|
TbGpsMapFolder.Text = dlg.FileName;
|
|
_currentDir = dlg.FileName;
|
|
var dir = new DirectoryInfo(dlg.FileName);
|
|
var mediaFiles = dir.GetFiles(_appConfig.AnnotationConfig.ImageFormats.ToArray())
|
|
.Select(x => new MediaFileInfo
|
|
{
|
|
Name = x.Name,
|
|
Path = x.FullName,
|
|
MediaType = MediaTypes.Image
|
|
}).ToList();
|
|
|
|
_allMediaFiles = mediaFiles;
|
|
GpsFiles.ItemsSource = new ObservableCollection<MediaFileInfo>(_allMediaFiles);
|
|
|
|
Annotations = mediaFiles.Select((x, i) => (i, new Annotation
|
|
{
|
|
Name = x.Name,
|
|
OriginalMediaName = x.Name
|
|
})).ToDictionary(x => x.i, x => x.Item2);
|
|
|
|
var initialLatLon = new GeoPoint(double.Parse(TbLat.Text), double.Parse(TbLon.Text));
|
|
await _gpsMatcherService.RunGpsMatching(dir.FullName, initialLatLon);
|
|
}
|
|
|
|
private async void TestGps(object sender, RoutedEventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(TbGpsMapFolder.Text))
|
|
return;
|
|
|
|
var initialLatLon = new GeoPoint(double.Parse(TbLat.Text), double.Parse(TbLon.Text));
|
|
await _gpsMatcherService.RunGpsMatching(TbGpsMapFolder.Text, initialLatLon);
|
|
}
|
|
}
|