mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
MapTileLayer/WmtsTileLayer
This commit is contained in:
parent
bec830c6ec
commit
e7aaa2ba22
|
|
@ -115,37 +115,29 @@ namespace MapControl
|
||||||
return finalSize;
|
return finalSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateTiles(bool resetTiles)
|
protected override void UpdateTileCollection(bool reset)
|
||||||
{
|
{
|
||||||
if (ParentMap == null || !SupportedCrsIds.Contains(ParentMap.MapProjection.CrsId))
|
if (ParentMap == null || !SupportedCrsIds.Contains(ParentMap.MapProjection.CrsId))
|
||||||
{
|
{
|
||||||
TileMatrix = null;
|
TileMatrix = null;
|
||||||
Children.Clear();
|
Children.Clear();
|
||||||
|
|
||||||
CancelLoadTiles();
|
CancelLoadTiles();
|
||||||
}
|
}
|
||||||
else if (SetTileMatrix() || resetTiles)
|
else if (SetTileMatrix() || reset)
|
||||||
{
|
{
|
||||||
SetRenderTransform();
|
UpdateRenderTransform();
|
||||||
|
UpdateTiles(reset);
|
||||||
if (resetTiles)
|
|
||||||
{
|
|
||||||
Tiles.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateTiles();
|
|
||||||
BeginLoadTiles(Tiles, SourceName);
|
BeginLoadTiles(Tiles, SourceName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SetRenderTransform()
|
protected override void UpdateRenderTransform()
|
||||||
{
|
{
|
||||||
if (TileMatrix != null)
|
if (TileMatrix != null)
|
||||||
{
|
{
|
||||||
// Tile matrix origin in pixels.
|
// Tile matrix origin in pixels.
|
||||||
//
|
//
|
||||||
var tileMatrixOrigin = new Point(TileSize * TileMatrix.XMin, TileSize * TileMatrix.YMin);
|
var tileMatrixOrigin = new Point(TileSize * TileMatrix.XMin, TileSize * TileMatrix.YMin);
|
||||||
|
|
||||||
var tileMatrixScale = MapBase.ZoomLevelToScale(TileMatrix.ZoomLevel);
|
var tileMatrixScale = MapBase.ZoomLevelToScale(TileMatrix.ZoomLevel);
|
||||||
|
|
||||||
((MatrixTransform)RenderTransform).Matrix =
|
((MatrixTransform)RenderTransform).Matrix =
|
||||||
|
|
@ -158,7 +150,6 @@ namespace MapControl
|
||||||
// Add 0.001 to avoid rounding issues.
|
// Add 0.001 to avoid rounding issues.
|
||||||
//
|
//
|
||||||
var tileMatrixZoomLevel = (int)Math.Floor(ParentMap.ZoomLevel - ZoomLevelOffset + 0.001);
|
var tileMatrixZoomLevel = (int)Math.Floor(ParentMap.ZoomLevel - ZoomLevelOffset + 0.001);
|
||||||
|
|
||||||
var tileMatrixScale = MapBase.ZoomLevelToScale(tileMatrixZoomLevel);
|
var tileMatrixScale = MapBase.ZoomLevelToScale(tileMatrixZoomLevel);
|
||||||
|
|
||||||
// Bounds in tile pixels from view size.
|
// Bounds in tile pixels from view size.
|
||||||
|
|
@ -185,12 +176,17 @@ namespace MapControl
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateTiles()
|
private void UpdateTiles(bool reset)
|
||||||
{
|
{
|
||||||
var tiles = new TileCollection();
|
var tiles = new TileCollection();
|
||||||
|
|
||||||
if (TileSource != null && TileMatrix != null)
|
if (TileSource != null && TileMatrix != null)
|
||||||
{
|
{
|
||||||
|
if (reset)
|
||||||
|
{
|
||||||
|
Tiles.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
var maxZoomLevel = Math.Min(TileMatrix.ZoomLevel, MaxZoomLevel);
|
var maxZoomLevel = Math.Min(TileMatrix.ZoomLevel, MaxZoomLevel);
|
||||||
|
|
||||||
if (maxZoomLevel >= MinZoomLevel)
|
if (maxZoomLevel >= MinZoomLevel)
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public static readonly DependencyProperty TileSourceProperty =
|
public static readonly DependencyProperty TileSourceProperty =
|
||||||
DependencyPropertyHelper.Register<MapTilePyramidLayer, TileSource>(nameof(TileSource), null,
|
DependencyPropertyHelper.Register<MapTilePyramidLayer, TileSource>(nameof(TileSource), null,
|
||||||
(layer, oldValue, newValue) => layer.Update(true));
|
(layer, oldValue, newValue) => layer.UpdateTiles(true));
|
||||||
|
|
||||||
public static readonly DependencyProperty SourceNameProperty =
|
public static readonly DependencyProperty SourceNameProperty =
|
||||||
DependencyPropertyHelper.Register<MapTilePyramidLayer, string>(nameof(SourceName));
|
DependencyPropertyHelper.Register<MapTilePyramidLayer, string>(nameof(SourceName));
|
||||||
|
|
@ -67,7 +67,7 @@ namespace MapControl
|
||||||
loadingProgress = new Progress<double>(p => SetValue(LoadingProgressProperty, p));
|
loadingProgress = new Progress<double>(p => SetValue(LoadingProgressProperty, p));
|
||||||
|
|
||||||
updateTimer = new UpdateTimer { Interval = UpdateInterval };
|
updateTimer = new UpdateTimer { Interval = UpdateInterval };
|
||||||
updateTimer.Tick += (s, e) => Update(false);
|
updateTimer.Tick += (s, e) => UpdateTiles();
|
||||||
|
|
||||||
MapPanel.SetRenderTransform(this, new MatrixTransform());
|
MapPanel.SetRenderTransform(this, new MatrixTransform());
|
||||||
#if WPF
|
#if WPF
|
||||||
|
|
@ -205,25 +205,25 @@ namespace MapControl
|
||||||
ClearValue(LoadingProgressProperty);
|
ClearValue(LoadingProgressProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void SetRenderTransform();
|
protected abstract void UpdateRenderTransform();
|
||||||
|
|
||||||
protected abstract void UpdateTiles(bool resetTiles);
|
protected abstract void UpdateTileCollection(bool reset);
|
||||||
|
|
||||||
private void Update(bool resetTiles)
|
private void UpdateTiles(bool reset = false)
|
||||||
{
|
{
|
||||||
updateTimer.Stop();
|
updateTimer.Stop();
|
||||||
UpdateTiles(resetTiles);
|
UpdateTileCollection(reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
|
private void OnViewportChanged(object sender, ViewportChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.TransformCenterChanged || e.ProjectionChanged || Children.Count == 0)
|
if (e.TransformCenterChanged || e.ProjectionChanged || Children.Count == 0)
|
||||||
{
|
{
|
||||||
Update(false); // update immediately
|
UpdateTiles(); // update immediately
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetRenderTransform();
|
UpdateRenderTransform();
|
||||||
updateTimer.Run(!UpdateWhileViewportChanging);
|
updateTimer.Run(!UpdateWhileViewportChanging);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,15 +100,14 @@ namespace MapControl
|
||||||
return finalSize;
|
return finalSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateTiles(bool resetTiles)
|
protected override void UpdateTileCollection(bool reset)
|
||||||
{
|
{
|
||||||
// resetTiles is ignored here because it is always false.
|
// 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))
|
||||||
{
|
{
|
||||||
Children.Clear();
|
Children.Clear();
|
||||||
|
|
||||||
CancelLoadTiles();
|
CancelLoadTiles();
|
||||||
}
|
}
|
||||||
else if (UpdateChildLayers(tileMatrixSet))
|
else if (UpdateChildLayers(tileMatrixSet))
|
||||||
|
|
@ -134,11 +133,11 @@ namespace MapControl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SetRenderTransform()
|
protected override void UpdateRenderTransform()
|
||||||
{
|
{
|
||||||
foreach (var layer in ChildLayers)
|
foreach (var layer in ChildLayers)
|
||||||
{
|
{
|
||||||
layer.SetRenderTransform(ParentMap.ViewTransform);
|
layer.UpdateRenderTransform(ParentMap.ViewTransform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -182,7 +181,7 @@ namespace MapControl
|
||||||
tilesChanged = true;
|
tilesChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
layer.SetRenderTransform(ParentMap.ViewTransform);
|
layer.UpdateRenderTransform(ParentMap.ViewTransform);
|
||||||
|
|
||||||
Children.Add(layer);
|
Children.Add(layer);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ namespace MapControl
|
||||||
|
|
||||||
public TileCollection Tiles { get; private set; } = [];
|
public TileCollection Tiles { get; private set; } = [];
|
||||||
|
|
||||||
public void SetRenderTransform(ViewTransform viewTransform)
|
public void UpdateRenderTransform(ViewTransform viewTransform)
|
||||||
{
|
{
|
||||||
// Tile matrix origin in pixels.
|
// Tile matrix origin in pixels.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue