Skip to content

Commit e2d487e

Browse files
committed
Restoring custom TMS provider on reloading a project.
1 parent d682fba commit e2d487e

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/MW5.Api/Helpers/MapHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace MW5.Api.Helpers
1313
{
1414
public static class MapHelper
1515
{
16-
public static void SetGoogleMeractorProjection(this IMuteMap map)
16+
public static void SetGoogleMercatorProjection(this IMuteMap map)
1717
{
1818
var sr = new SpatialReference();
1919
sr.SetGoogleMercator();

src/MW5.Services/Concrete/ProjectLoader.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public bool Restore(XmlProject project)
4949
_context.Map.Lock();
5050
_context.Legend.Lock();
5151

52-
_context.Map.SetTileProvider(project.Map.TileProviderId);
52+
RestoreTmsProvider(project.Map.TileProviderId);
5353

5454
try
5555
{
@@ -87,6 +87,28 @@ public bool Restore(XmlProject project)
8787
}
8888
}
8989

90+
private void RestoreTmsProvider(int providerId)
91+
{
92+
if (_context.Map.Tiles.Providers.All(p => p.Id != providerId))
93+
{
94+
var provider = _context.Repository.TmsProviders.FirstOrDefault(p => p.Id == providerId);
95+
if (provider != null)
96+
{
97+
var providers = _context.Map.Tiles.Providers;
98+
providers.Clear(false);
99+
100+
providers.AddCustom(provider.Id, provider.Name, provider.Url, provider.Projection, provider.MinZoom,
101+
provider.MaxZoom);
102+
}
103+
else
104+
{
105+
Logger.Current.Warn("Failed to find TMS provider in the repository: " + providerId);
106+
}
107+
}
108+
109+
_context.Map.SetTileProvider(providerId);
110+
}
111+
90112
private void RestoreMapProjection(XmlProject project)
91113
{
92114
var sr = new SpatialReference();

src/Plugins/MW5.Repository/Views/RepositoryPresenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private void UpdateTmsBounds(TmsProvider provider, bool update)
284284

285285
if (projectionIsEmpty)
286286
{
287-
_context.Map.SetGoogleMeractorProjection();
287+
_context.Map.SetGoogleMercatorProjection();
288288
}
289289

290290
var mapProvider = _context.Map.Tiles.Providers.FirstOrDefault(p => p.Id == provider.Id);

0 commit comments

Comments
 (0)