Skip to content

Commit

Permalink
Added setting of default base point on maps depending on user locale
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Norseman committed Nov 1, 2024
1 parent 40e26d5 commit abd6a56
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 44 deletions.
30 changes: 30 additions & 0 deletions locales/locales.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- Locale: 'af-ZA'
MapBasePoint: 'South Africa, Pretoria'
- Locale: 'be-BY'
MapBasePoint: 'Беларусь, Мінск'
- Locale: 'cs-CZ'
MapBasePoint: 'Czechia, Prague'
- Locale: 'es-ES'
MapBasePoint: 'Spain, Madrid'
- Locale: 'hu-HU'
MapBasePoint: 'Hungary, Budapest'
- Locale: 'is-IS'
MapBasePoint: 'Iceland, Reykjavík'
- Locale: 'it-IT'
MapBasePoint: 'Italy, Rome'
- Locale: 'ja-JP'
MapBasePoint: 'Japan, Tokyo'
- Locale: 'kk-KZ'
MapBasePoint: 'Kazakhstan, Astana'
- Locale: 'nl-NL'
MapBasePoint: 'Netherlands, Amsterdam'
- Locale: 'pt-PT'
MapBasePoint: 'Portugal, Lisbon'
- Locale: 'ru-RU'
MapBasePoint: 'Российская Федерация, Москва'
- Locale: 'sr-Latn-RS'
MapBasePoint: 'Serbia, Belgrade'
- Locale: 'zh-CN'
MapBasePoint: 'China, Beijing'
...
7 changes: 7 additions & 0 deletions projects/GKCore/GKCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,13 @@
<Compile Include="GKCore\Lists\URefsListModel.cs" />
<Compile Include="GKCore\Lists\RepositoryCitationsListModel.cs" />
<Compile Include="GKCore\Lists\CallNumbersListModel.cs" />
<Compile Include="GKCore\LocalesCollection.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GKMap\GKMap.Core\GKMap.Core.csproj">
<Project>{D0C39D9D-BED0-418B-9A5E-713176CAF40C}</Project>
<Name>GKMap.Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project="GKCore.props" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
4 changes: 4 additions & 0 deletions projects/GKCore/GKCore.nstd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\GKMap\GKMap.Core\GKMap.Core.nstd.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
Expand Down
17 changes: 17 additions & 0 deletions projects/GKCore/GKCore/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public abstract class AppHost : IHost, ISingleInstanceEnforcer
private ITimer fAutosaveTimer;
private string[] fCommandArgs;
private int fLoadingCount;
private LocalesCollection fLocalesCollection;


public static AppHost Instance
Expand All @@ -93,6 +94,11 @@ public IList<WidgetInfo> ActiveWidgets
get { return fActiveWidgets; }
}

public LocalesCollection LocalesCollection
{
get { return fLocalesCollection; }
}


protected AppHost()
{
Expand All @@ -102,6 +108,7 @@ protected AppHost()
fInternalClipboard = new List<object>();
fRunningForms = new List<IWindow>();
fTips = new StringList();
fLocalesCollection = new LocalesCollection();
}

protected virtual void ApplicationExit()
Expand Down Expand Up @@ -168,6 +175,7 @@ public virtual async void StartupWork()

ProcessHolidays();
ProcessTips();
ProcessLocales();

await EndLoading();
} finally {
Expand Down Expand Up @@ -916,6 +924,15 @@ public async Task<int> ReloadRecentBases()
return result;
}

public void ProcessLocales()
{
try {
fLocalesCollection.Load(GKUtils.GetLangsPath() + "locales.yaml");
} catch (Exception ex) {
Logger.WriteError("AppHost.ProcessLocales()", ex);
}
}

public void ProcessHolidays()
{
try {
Expand Down
35 changes: 35 additions & 0 deletions projects/GKCore/GKCore/Controllers/MapsViewerWinController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using BSLib;
using GDModel;
using GDModel.Providers.GEDCOM;
Expand All @@ -29,6 +30,8 @@
using GKCore.Interfaces;
using GKCore.Maps;
using GKCore.Options;
using GKMap;
using GKMap.MapProviders;

namespace GKCore.Controllers
{
Expand Down Expand Up @@ -57,6 +60,38 @@ public MapsViewerWinController(IMapsViewerWin view, List<GDMRecord> selectedPers
fSearchPlacesWithoutCoords = GlobalOptions.Instance.SearchPlacesWithoutCoords;
}

public override void Init(IBaseWindow baseWin)
{
base.Init(baseWin);

CultureInfo culture = CultureInfo.CurrentCulture;
string basePoint = AppHost.Instance.LocalesCollection.GetMapBasePoint(culture.Name);

// add start location
PointLatLng? pos = null;
GeocoderStatusCode status = GeocoderStatusCode.Unknown;

if (!string.IsNullOrEmpty(basePoint)) {
//GMapProvider.LanguageStr = culture.TwoLetterISOLanguageName;
//pos = GMapProviders.GoogleMap.GetPoint(basePoint, out status);

var pointsList = new List<GeoPoint>();
PlacesCache.Instance.GetPlacePoints(basePoint, pointsList);
if (pointsList.Count > 0) {
var pt = pointsList[0];
pos = new PointLatLng(pt.Latitude, pt.Longitude);
status = GeocoderStatusCode.Success;
}
}

if (pos == null || status != GeocoderStatusCode.Success) {
pos = new PointLatLng(-15.950278, -5.683056);
}

fView.MapBrowser.TargetPosition = pos.Value;
fView.MapBrowser.MapControl.ZoomAndCenterMarkers(null);
}

public void ShowFixedPoints(IEnumerable<GeoPoint> points)
{
var mapBrowser = fView.MapBrowser;
Expand Down
4 changes: 4 additions & 0 deletions projects/GKCore/GKCore/Design/Controls/IMapBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using System.Collections.Generic;
using GKCore.Maps;
using GKMap;

namespace GKCore.Design.Controls
{
Expand All @@ -28,9 +29,12 @@ namespace GKCore.Design.Controls
/// </summary>
public interface IMapBrowser : IBaseControl
{
IMapControl MapControl { get; }

bool ShowPoints { get; set; }
bool ShowLines { get; set; }
IList<GeoPoint> MapPoints { get; }
PointLatLng TargetPosition { get; set; }

int AddPoint(double latitude, double longitude, string hint);
int AddPoint(GeoPoint pt);
Expand Down
67 changes: 67 additions & 0 deletions projects/GKCore/GKCore/LocalesCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.IO;
using System.Linq;

namespace GKCore
{
public sealed class LocaleInfo
{
public string Locale;
public string MapBasePoint;
}


/// <summary>
///
/// </summary>
public sealed class LocalesCollection
{
private LocaleInfo[] fList;

public LocalesCollection()
{
fList = new LocaleInfo[0];
}

public void Load(string fileName)
{
if (!File.Exists(fileName))
return;

try {
using (var reader = new StreamReader(fileName)) {
string content = reader.ReadToEnd();
fList = YamlHelper.Deserialize<LocaleInfo[]>(content);
}
} catch (Exception ex) {
Logger.WriteError("LocalesCollection.Load()", ex);
}
}

public string GetMapBasePoint(string locale)
{
var locInfo = fList.FirstOrDefault((x) => x.Locale == locale);
return (locInfo == null) ? null : locInfo.MapBasePoint;
}
}
}
10 changes: 7 additions & 3 deletions projects/GKMap/GKMap.Core/IMapControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ namespace GKMap
public delegate void RouteEnter(MapRoute item);
public delegate void RouteLeave(MapRoute item);

internal interface IMapControl
public interface IMapControl
{
string CacheLocation { get; set; }

MapCore Core { get; }

GMapProvider MapProvider { get; set; }

int MaxZoom { get; set; }
Expand Down Expand Up @@ -79,4 +77,10 @@ internal interface IMapControl

#endregion
}


internal interface IMapControlEx : IMapControl
{
MapCore Core { get; }
}
}
4 changes: 2 additions & 2 deletions projects/GKMap/GKMap.Core/MapObjects/MapOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace GKMap.MapObjects
/// </summary>
public abstract class MapOverlay : IDisposable
{
private IMapControl fControl;
private IMapControlEx fControl;
private bool fDisposed;
private bool fIsHitTestVisible = true;
private bool fIsVisible = true;
Expand Down Expand Up @@ -97,7 +97,7 @@ public bool IsZoomSignificant
/// </summary>
public ObservableCollectionThreadSafe<MapPolygon> Polygons { get; private set; }

internal IMapControl Control
internal IMapControlEx Control
{
get {
return fControl;
Expand Down
11 changes: 5 additions & 6 deletions projects/GKMap/GKMap.Core/MapProviders/GMapProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,15 @@ protected GMapProvider()
/// </summary>
public bool InvertedAxisY = false;

/// <summary>
/// map language
/// </summary>
public static string LanguageStr
{
get {
return fLanguageStr;
}
get { return fLanguageStr; }
set { fLanguageStr = value; }
}

/// <summary>
/// map language
/// </summary>
public static LanguageType Language
{
get {
Expand Down
4 changes: 2 additions & 2 deletions projects/GKMap/GKMap.EtoForms/GMapControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace GKMap.EtoForms
/// <summary>
/// GKMap control for Windows Forms
/// </summary>
public class GMapControl : Drawable, IMapControl
public class GMapControl : Drawable, IMapControlEx
{
public static readonly bool IsDesignerHosted = LicenseManager.UsageMode == LicenseUsageMode.Designtime;

Expand Down Expand Up @@ -76,7 +76,7 @@ public string CacheLocation
}
}

MapCore IMapControl.Core { get { return fCore; } }
MapCore IMapControlEx.Core { get { return fCore; } }

/// <summary>
/// stops immediate marker/route/polygon invalidation;
Expand Down
4 changes: 2 additions & 2 deletions projects/GKMap/GKMap.WinForms/GMapControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace GKMap.WinForms
/// <summary>
/// GKMap control for Windows Forms
/// </summary>
public class GMapControl : UserControl, IMapControl
public class GMapControl : UserControl, IMapControlEx
{
public static readonly bool IsDesignerHosted = LicenseManager.UsageMode == LicenseUsageMode.Designtime;

Expand Down Expand Up @@ -83,7 +83,7 @@ public string CacheLocation
}
}

MapCore IMapControl.Core { get { return fCore; } }
MapCore IMapControlEx.Core { get { return fCore; } }

/// <summary>
/// stops immediate marker/route/polygon invalidation;
Expand Down
4 changes: 2 additions & 2 deletions projects/GKMap/GKMap.Xamarin/GMapControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace GKMap.Xamarin
/// <summary>
/// GKMap control for Windows Forms
/// </summary>
public class GMapControl : SKCanvasView, IMapControl
public class GMapControl : SKCanvasView, IMapControlEx
{
private MapCore fCore;
private bool fIsMouseOverMarker;
Expand Down Expand Up @@ -66,7 +66,7 @@ public string CacheLocation
}
}

MapCore IMapControl.Core { get { return fCore; } }
MapCore IMapControlEx.Core { get { return fCore; } }

/// <summary>
/// stops immediate marker/route/polygon invalidation;
Expand Down
Loading

0 comments on commit abd6a56

Please sign in to comment.