mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
WmtsTileSource factory method
This commit is contained in:
parent
7cb7d81f15
commit
dd738c85a4
|
|
@ -24,7 +24,7 @@ namespace MapControl
|
|||
private static readonly XNamespace xlink = "http://www.w3.org/1999/xlink";
|
||||
|
||||
public string Layer { get; private set; }
|
||||
public WmtsTileSource TileSource { get; private set; }
|
||||
public string UriTemplate { get; private set; }
|
||||
public List<WmtsTileMatrixSet> TileMatrixSets { get; private set; }
|
||||
|
||||
public static async Task<WmtsCapabilities> ReadCapabilitiesAsync(Uri capabilitiesUri, string layer)
|
||||
|
|
@ -117,7 +117,7 @@ namespace MapControl
|
|||
return new WmtsCapabilities
|
||||
{
|
||||
Layer = layer,
|
||||
TileSource = new WmtsTileSource { UriTemplate = urlTemplate },
|
||||
UriTemplate = urlTemplate,
|
||||
TileMatrixSets = tileMatrixSets
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,8 @@ namespace MapControl
|
|||
|
||||
public Dictionary<string, WmtsTileMatrixSet> TileMatrixSets { get; } = new Dictionary<string, WmtsTileMatrixSet>();
|
||||
|
||||
protected virtual WmtsTileSource CreateTileSource(string uriTemplate) => new WmtsTileSource { UriTemplate = uriTemplate };
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
foreach (var layer in ChildLayers)
|
||||
|
|
@ -104,7 +106,26 @@ namespace MapControl
|
|||
}
|
||||
else if (UpdateChildLayers(tileMatrixSet))
|
||||
{
|
||||
await LoadTiles(tileMatrixSet);
|
||||
var cacheName = SourceName;
|
||||
|
||||
if (TileSource is WmtsTileSource tileSource)
|
||||
{
|
||||
tileSource.TileMatrixSet = tileMatrixSet;
|
||||
|
||||
if (!string.IsNullOrEmpty(cacheName))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Layer))
|
||||
{
|
||||
cacheName += "/" + Layer.Replace(':', '_');
|
||||
}
|
||||
|
||||
cacheName += "/" + tileMatrixSet.Identifier.Replace(':', '_');
|
||||
}
|
||||
}
|
||||
|
||||
var tiles = ChildLayers.SelectMany(layer => layer.Tiles);
|
||||
|
||||
await LoadTiles(tiles, cacheName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -164,30 +185,6 @@ namespace MapControl
|
|||
return tilesChanged;
|
||||
}
|
||||
|
||||
private Task LoadTiles(WmtsTileMatrixSet tileMatrixSet)
|
||||
{
|
||||
var cacheName = SourceName;
|
||||
|
||||
if (TileSource is WmtsTileSource tileSource)
|
||||
{
|
||||
tileSource.TileMatrixSet = tileMatrixSet;
|
||||
|
||||
if (!string.IsNullOrEmpty(cacheName))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Layer))
|
||||
{
|
||||
cacheName += "/" + Layer.Replace(':', '_');
|
||||
}
|
||||
|
||||
cacheName += "/" + tileMatrixSet.Identifier.Replace(':', '_');
|
||||
}
|
||||
}
|
||||
|
||||
var tiles = ChildLayers.SelectMany(layer => layer.Tiles);
|
||||
|
||||
return LoadTiles(tiles, cacheName);
|
||||
}
|
||||
|
||||
private async void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Loaded -= OnLoaded;
|
||||
|
|
@ -206,7 +203,7 @@ namespace MapControl
|
|||
}
|
||||
|
||||
Layer = capabilities.Layer;
|
||||
TileSource = capabilities.TileSource;
|
||||
TileSource = CreateTileSource(capabilities.UriTemplate);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
<PropertyGroup>
|
||||
<TargetFramework>net8.0-windows10.0.17763.0</TargetFramework>
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<UseWinUI>true</UseWinUI>
|
||||
<DefineConstants>WINUI</DefineConstants>
|
||||
<RootNamespace>MapControl</RootNamespace>
|
||||
|
|
|
|||
Loading…
Reference in a new issue