mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Moved TileSource property to MapTileLayer
This commit is contained in:
parent
733c3d1266
commit
286926e1ea
|
|
@ -29,6 +29,10 @@ namespace MapControl
|
||||||
private static readonly Point MapTopLeft = new(-180d * MapProjection.Wgs84MeterPerDegree,
|
private static readonly Point MapTopLeft = new(-180d * MapProjection.Wgs84MeterPerDegree,
|
||||||
180d * MapProjection.Wgs84MeterPerDegree);
|
180d * MapProjection.Wgs84MeterPerDegree);
|
||||||
|
|
||||||
|
public static readonly DependencyProperty TileSourceProperty =
|
||||||
|
DependencyPropertyHelper.Register<MapTileLayer, TileSource>(nameof(TileSource), null,
|
||||||
|
(layer, oldValue, newValue) => layer.UpdateTileCollection(true));
|
||||||
|
|
||||||
public static readonly DependencyProperty MinZoomLevelProperty =
|
public static readonly DependencyProperty MinZoomLevelProperty =
|
||||||
DependencyPropertyHelper.Register<MapTileLayer, int>(nameof(MinZoomLevel), 0);
|
DependencyPropertyHelper.Register<MapTileLayer, int>(nameof(MinZoomLevel), 0);
|
||||||
|
|
||||||
|
|
@ -59,6 +63,15 @@ namespace MapControl
|
||||||
|
|
||||||
public ICollection<ImageTile> Tiles { get; private set; } = [];
|
public ICollection<ImageTile> Tiles { get; private set; } = [];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides the ImagesSource or image request Uri for map tiles.
|
||||||
|
/// </summary>
|
||||||
|
public TileSource TileSource
|
||||||
|
{
|
||||||
|
get => (TileSource)GetValue(TileSourceProperty);
|
||||||
|
set => SetValue(TileSourceProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Minimum zoom level supported by the MapTileLayer. Default value is 0.
|
/// Minimum zoom level supported by the MapTileLayer. Default value is 0.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -129,20 +142,30 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateTileCollection(bool reset)
|
protected override void UpdateTileCollection()
|
||||||
{
|
{
|
||||||
if (ParentMap == null || !SupportedCrsIds.Contains(ParentMap.MapProjection.CrsId))
|
UpdateTileCollection(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateTileCollection(bool tileSourceChanged)
|
||||||
|
{
|
||||||
|
if (TileSource == null || ParentMap == null || !SupportedCrsIds.Contains(ParentMap.MapProjection.CrsId))
|
||||||
{
|
{
|
||||||
CancelLoadTiles();
|
CancelLoadTiles();
|
||||||
Children.Clear();
|
Children.Clear();
|
||||||
Tiles.Clear();
|
Tiles.Clear();
|
||||||
TileMatrix = null;
|
TileMatrix = null;
|
||||||
}
|
}
|
||||||
else if (SetTileMatrix() || reset)
|
else if (SetTileMatrix() || tileSourceChanged)
|
||||||
{
|
{
|
||||||
|
if (tileSourceChanged)
|
||||||
|
{
|
||||||
|
Tiles.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
UpdateRenderTransform();
|
UpdateRenderTransform();
|
||||||
UpdateTiles(reset);
|
UpdateTiles();
|
||||||
BeginLoadTiles(Tiles, SourceName);
|
BeginLoadTiles(Tiles, TileSource, SourceName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -177,15 +200,9 @@ namespace MapControl
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateTiles(bool reset)
|
private void UpdateTiles()
|
||||||
{
|
{
|
||||||
var tiles = new ImageTileList();
|
var tiles = new ImageTileList();
|
||||||
|
|
||||||
if (reset)
|
|
||||||
{
|
|
||||||
Tiles.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
var maxZoomLevel = Math.Min(TileMatrix.ZoomLevel, MaxZoomLevel);
|
var maxZoomLevel = Math.Min(TileMatrix.ZoomLevel, MaxZoomLevel);
|
||||||
|
|
||||||
if (maxZoomLevel >= MinZoomLevel)
|
if (maxZoomLevel >= MinZoomLevel)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
#if WPF
|
#if WPF
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
|
@ -19,7 +18,6 @@ using Microsoft.UI.Xaml.Hosting;
|
||||||
using Microsoft.UI.Xaml.Media;
|
using Microsoft.UI.Xaml.Media;
|
||||||
#elif AVALONIA
|
#elif AVALONIA
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Media;
|
|
||||||
using Brush = Avalonia.Media.IBrush;
|
using Brush = Avalonia.Media.IBrush;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -27,10 +25,6 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public abstract class TilePyramidLayer : Panel, IMapLayer
|
public abstract class TilePyramidLayer : Panel, IMapLayer
|
||||||
{
|
{
|
||||||
public static readonly DependencyProperty TileSourceProperty =
|
|
||||||
DependencyPropertyHelper.Register<TilePyramidLayer, TileSource>(nameof(TileSource), null,
|
|
||||||
(layer, oldValue, newValue) => layer.UpdateTiles(true));
|
|
||||||
|
|
||||||
public static readonly DependencyProperty SourceNameProperty =
|
public static readonly DependencyProperty SourceNameProperty =
|
||||||
DependencyPropertyHelper.Register<TilePyramidLayer, string>(nameof(SourceName));
|
DependencyPropertyHelper.Register<TilePyramidLayer, string>(nameof(SourceName));
|
||||||
|
|
||||||
|
|
@ -83,15 +77,6 @@ namespace MapControl
|
||||||
set => tileImageLoader = value;
|
set => tileImageLoader = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides map tile URIs or images.
|
|
||||||
/// </summary>
|
|
||||||
public TileSource TileSource
|
|
||||||
{
|
|
||||||
get => (TileSource)GetValue(TileSourceProperty);
|
|
||||||
set => SetValue(TileSourceProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Name of the tile source that is used as component of a tile cache key.
|
/// Name of the tile source that is used as component of a tile cache key.
|
||||||
/// Tile images are not cached when SourceName is null or empty.
|
/// Tile images are not cached when SourceName is null or empty.
|
||||||
|
|
@ -190,12 +175,9 @@ namespace MapControl
|
||||||
|
|
||||||
public abstract IReadOnlyCollection<string> SupportedCrsIds { get; }
|
public abstract IReadOnlyCollection<string> SupportedCrsIds { get; }
|
||||||
|
|
||||||
protected void BeginLoadTiles(IEnumerable<Tile> tiles, string cacheName)
|
protected void BeginLoadTiles(IEnumerable<Tile> tiles, TileSource tileSource, string cacheName)
|
||||||
{
|
{
|
||||||
if (TileSource != null && tiles != null && tiles.Any(tile => tile.IsPending))
|
TileImageLoader.BeginLoadTiles(tiles, tileSource, cacheName, loadingProgress);
|
||||||
{
|
|
||||||
TileImageLoader.BeginLoadTiles(tiles, TileSource, cacheName, loadingProgress);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void CancelLoadTiles()
|
protected void CancelLoadTiles()
|
||||||
|
|
@ -206,12 +188,12 @@ namespace MapControl
|
||||||
|
|
||||||
protected abstract void UpdateRenderTransform();
|
protected abstract void UpdateRenderTransform();
|
||||||
|
|
||||||
protected abstract void UpdateTileCollection(bool reset);
|
protected abstract void UpdateTileCollection();
|
||||||
|
|
||||||
private void UpdateTiles(bool reset = false)
|
private void UpdateTiles()
|
||||||
{
|
{
|
||||||
updateTimer.Stop();
|
updateTimer.Stop();
|
||||||
UpdateTileCollection(reset);
|
UpdateTileCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
|
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"Invalid Capabilities URI: {uri}");
|
throw new ArgumentException($"Invalid Capabilities Uri: {uri}");
|
||||||
}
|
}
|
||||||
|
|
||||||
using var stream = xmlStream;
|
using var stream = xmlStream;
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,10 @@ namespace MapControl
|
||||||
private static ILogger Logger => logger ??= ImageLoader.LoggerFactory?.CreateLogger(typeof(WmtsTileLayer));
|
private static ILogger Logger => logger ??= ImageLoader.LoggerFactory?.CreateLogger(typeof(WmtsTileLayer));
|
||||||
|
|
||||||
public static readonly DependencyProperty CapabilitiesUriProperty =
|
public static readonly DependencyProperty CapabilitiesUriProperty =
|
||||||
DependencyPropertyHelper.Register<WmtsTileLayer, Uri>(nameof(CapabilitiesUri), null,
|
DependencyPropertyHelper.Register<WmtsTileLayer, Uri>(nameof(CapabilitiesUri));
|
||||||
(layer, oldValue, newValue) => layer.TileMatrixSets.Clear());
|
|
||||||
|
public static readonly DependencyProperty TileUriTemplateProperty =
|
||||||
|
DependencyPropertyHelper.Register<WmtsTileLayer, string>(nameof(TileUriTemplate));
|
||||||
|
|
||||||
public static readonly DependencyProperty LayerProperty =
|
public static readonly DependencyProperty LayerProperty =
|
||||||
DependencyPropertyHelper.Register<WmtsTileLayer, string>(nameof(Layer));
|
DependencyPropertyHelper.Register<WmtsTileLayer, string>(nameof(Layer));
|
||||||
|
|
@ -50,7 +52,18 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Identifier of the Layer that should be displayed. If not set, the first Layer is displayed.
|
/// The Uri template string used for the UriTemplate property of WmtsTileSource instances.
|
||||||
|
/// Usually set internally from WmtsCapabilities requested by a Loaded event handler.
|
||||||
|
/// </summary>
|
||||||
|
public string TileUriTemplate
|
||||||
|
{
|
||||||
|
get => (string)GetValue(TileUriTemplateProperty);
|
||||||
|
set => SetValue(TileUriTemplateProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Identifier of the Layer that should be displayed.
|
||||||
|
/// If not set, the value is defined by WmtsCapabilities.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Layer
|
public string Layer
|
||||||
{
|
{
|
||||||
|
|
@ -108,10 +121,8 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateTileCollection(bool reset)
|
protected override void UpdateTileCollection()
|
||||||
{
|
{
|
||||||
// reset parameter is ignored here because it is always false.
|
|
||||||
|
|
||||||
if (ParentMap == null ||
|
if (ParentMap == null ||
|
||||||
!TileMatrixSets.TryGetValue(ParentMap.MapProjection.CrsId, out WmtsTileMatrixSet tileMatrixSet))
|
!TileMatrixSets.TryGetValue(ParentMap.MapProjection.CrsId, out WmtsTileMatrixSet tileMatrixSet))
|
||||||
{
|
{
|
||||||
|
|
@ -120,7 +131,11 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
else if (UpdateChildLayers(tileMatrixSet))
|
else if (UpdateChildLayers(tileMatrixSet))
|
||||||
{
|
{
|
||||||
((WmtsTileSource)TileSource).TileMatrixSet = tileMatrixSet;
|
var tileSource = new WmtsTileSource
|
||||||
|
{
|
||||||
|
UriTemplate = TileUriTemplate,
|
||||||
|
TileMatrixSet = tileMatrixSet
|
||||||
|
};
|
||||||
|
|
||||||
var cacheName = SourceName;
|
var cacheName = SourceName;
|
||||||
|
|
||||||
|
|
@ -137,7 +152,7 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BeginLoadTiles(ChildLayers.SelectMany(layer => layer.Tiles), cacheName);
|
BeginLoadTiles(ChildLayers.SelectMany(layer => layer.Tiles), tileSource, cacheName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -216,7 +231,9 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
|
|
||||||
Layer = capabilities.Layer;
|
Layer = capabilities.Layer;
|
||||||
TileSource = new WmtsTileSource { UriTemplate = capabilities.UriTemplate };
|
TileUriTemplate = capabilities.UriTemplate;
|
||||||
|
|
||||||
|
UpdateTileCollection();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue