Skip to content

Commit 75c545b

Browse files
committed
[CORE-164] AppContextHelper.SetCustomTileProvider method to DRY the code.
1 parent 62ba582 commit 75c545b

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

src/MW5.Plugins/Helpers/AppContextHelper.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using MW5.Plugins.Interfaces;
2+
using MW5.Plugins.Model;
23

34
namespace MW5.Plugins.Helpers
45
{
@@ -31,5 +32,12 @@ internal static void ActivatePanel(this IAppContext context, string dockPanelKey
3132
panel.Activate();
3233
}
3334
}
35+
36+
public static bool SetCustomTileProvider(this IAppContext context, TmsProvider provider)
37+
{
38+
var providers = context.Map.Tiles.Providers;
39+
providers.Clear(false);
40+
return providers.AddCustom(provider.Id, provider.Name, provider.Url, provider.Projection, provider.MinZoom, provider.MaxZoom);
41+
}
3442
}
3543
}

src/MW5.Services/Concrete/ProjectLoader.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using MW5.Api.Legend;
99
using MW5.Api.Legend.Abstract;
1010
using MW5.Plugins.Events;
11+
using MW5.Plugins.Helpers;
1112
using MW5.Plugins.Interfaces;
1213
using MW5.Plugins.Services;
1314
using MW5.Services.Controls;
@@ -94,11 +95,7 @@ private void RestoreTmsProvider(int providerId)
9495
var provider = _context.Repository.TmsProviders.FirstOrDefault(p => p.Id == providerId);
9596
if (provider != null)
9697
{
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);
98+
_context.SetCustomTileProvider(provider);
10299
}
103100
else
104101
{

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using MW5.Data.Repository;
2020
using MW5.Data.Views;
2121
using MW5.Plugins.Concrete;
22+
using MW5.Plugins.Helpers;
2223
using MW5.Plugins.Interfaces;
2324
using MW5.Plugins.Model;
2425
using MW5.Plugins.Mvp;
@@ -254,11 +255,7 @@ private void AddTmsProviderToMap(bool update)
254255
if (provider.IsCustom)
255256
{
256257
// in case of custom provider we need to add definition to the list
257-
var providers = _context.Map.Tiles.Providers;
258-
providers.Clear(false);
259-
260-
if (!providers.AddCustom(provider.Id, provider.Name, provider.Url, provider.Projection, provider.MinZoom,
261-
provider.MaxZoom))
258+
if (!_context.SetCustomTileProvider(provider))
262259
{
263260
MessageService.Current.Info("Failed to add custom TMS provider.");
264261
return;

0 commit comments

Comments
 (0)