mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Minor tile layer updates
This commit is contained in:
parent
ea992d3d0f
commit
ddf77441f2
42
MapControl/Shared/BoundingBoxTileSource.cs
Normal file
42
MapControl/Shared/BoundingBoxTileSource.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// © 2020 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public class BoundingBoxTileSource : TileSource
|
||||
{
|
||||
public override Uri GetUri(int x, int y, int zoomLevel)
|
||||
{
|
||||
Uri uri = null;
|
||||
|
||||
if (UriFormat != null)
|
||||
{
|
||||
var tileSize = 360d / (1 << zoomLevel); // tile width in degrees
|
||||
var west = MapProjection.Wgs84MetersPerDegree * (x * tileSize - 180d);
|
||||
var east = MapProjection.Wgs84MetersPerDegree * ((x + 1) * tileSize - 180d);
|
||||
var south = MapProjection.Wgs84MetersPerDegree * (180d - (y + 1) * tileSize);
|
||||
var north = MapProjection.Wgs84MetersPerDegree * (180d - y * tileSize);
|
||||
|
||||
if (UriFormat.Contains("{bbox}"))
|
||||
{
|
||||
uri = new Uri(UriFormat.Replace("{bbox}", string.Format(CultureInfo.InvariantCulture,
|
||||
"{0:F2},{1:F2},{2:F2},{3:F2}", west, south, east, north)));
|
||||
}
|
||||
else
|
||||
{
|
||||
uri = new Uri(UriFormat
|
||||
.Replace("{west}", west.ToString("F2", CultureInfo.InvariantCulture))
|
||||
.Replace("{south}", south.ToString("F2", CultureInfo.InvariantCulture))
|
||||
.Replace("{east}", east.ToString("F2", CultureInfo.InvariantCulture))
|
||||
.Replace("{north}", north.ToString("F2", CultureInfo.InvariantCulture)));
|
||||
}
|
||||
}
|
||||
|
||||
return uri;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -216,7 +216,7 @@ namespace MapControl
|
|||
}
|
||||
}
|
||||
|
||||
protected virtual async Task UpdateImageAsync()
|
||||
protected async Task UpdateImageAsync()
|
||||
{
|
||||
updateTimer.Stop();
|
||||
|
||||
|
|
|
|||
|
|
@ -37,8 +37,7 @@ namespace MapControl
|
|||
{
|
||||
TileSource = new TileSource { UriFormat = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenStreetMap",
|
||||
Description = "© [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)",
|
||||
MaxZoomLevel = 19
|
||||
Description = "© [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -47,7 +46,7 @@ namespace MapControl
|
|||
nameof(MinZoomLevel), typeof(int), typeof(MapTileLayer), new PropertyMetadata(0));
|
||||
|
||||
public static readonly DependencyProperty MaxZoomLevelProperty = DependencyProperty.Register(
|
||||
nameof(MaxZoomLevel), typeof(int), typeof(MapTileLayer), new PropertyMetadata(18));
|
||||
nameof(MaxZoomLevel), typeof(int), typeof(MapTileLayer), new PropertyMetadata(19));
|
||||
|
||||
public MapTileLayer()
|
||||
: this(new TileImageLoader())
|
||||
|
|
@ -73,7 +72,7 @@ namespace MapControl
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maximum zoom level supported by the MapTileLayer. Default value is 18.
|
||||
/// Maximum zoom level supported by the MapTileLayer. Default value is 19.
|
||||
/// </summary>
|
||||
public int MaxZoomLevel
|
||||
{
|
||||
|
|
@ -92,8 +91,6 @@ namespace MapControl
|
|||
|
||||
protected override void UpdateTileLayer()
|
||||
{
|
||||
UpdateTimer.Stop();
|
||||
|
||||
if (ParentMap == null || !ParentMap.MapProjection.IsWebMercator)
|
||||
{
|
||||
TileMatrix = null;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace MapControl
|
|||
|
||||
public static readonly DependencyProperty UpdateIntervalProperty = DependencyProperty.Register(
|
||||
nameof(UpdateInterval), typeof(TimeSpan), typeof(MapTileLayerBase),
|
||||
new PropertyMetadata(TimeSpan.FromSeconds(0.2), (o, e) => ((MapTileLayerBase)o).UpdateTimer.Interval = (TimeSpan)e.NewValue));
|
||||
new PropertyMetadata(TimeSpan.FromSeconds(0.2), (o, e) => ((MapTileLayerBase)o).updateTimer.Interval = (TimeSpan)e.NewValue));
|
||||
|
||||
public static readonly DependencyProperty UpdateWhileViewportChangingProperty = DependencyProperty.Register(
|
||||
nameof(UpdateWhileViewportChanging), typeof(bool), typeof(MapTileLayerBase), new PropertyMetadata(false));
|
||||
|
|
@ -50,6 +50,7 @@ namespace MapControl
|
|||
public static readonly DependencyProperty MapForegroundProperty = DependencyProperty.Register(
|
||||
nameof(MapForeground), typeof(Brush), typeof(MapTileLayerBase), new PropertyMetadata(null));
|
||||
|
||||
private readonly DispatcherTimer updateTimer;
|
||||
private MapBase parentMap;
|
||||
|
||||
protected MapTileLayerBase(ITileImageLoader tileImageLoader)
|
||||
|
|
@ -57,16 +58,19 @@ namespace MapControl
|
|||
RenderTransform = new MatrixTransform();
|
||||
TileImageLoader = tileImageLoader;
|
||||
|
||||
UpdateTimer = new DispatcherTimer { Interval = UpdateInterval };
|
||||
UpdateTimer.Tick += (s, e) => UpdateTileLayer();
|
||||
updateTimer = new DispatcherTimer { Interval = UpdateInterval };
|
||||
|
||||
updateTimer.Tick += (s, e) =>
|
||||
{
|
||||
updateTimer.Stop();
|
||||
UpdateTileLayer();
|
||||
};
|
||||
|
||||
MapPanel.InitMapElement(this);
|
||||
}
|
||||
|
||||
public ITileImageLoader TileImageLoader { get; }
|
||||
|
||||
public DispatcherTimer UpdateTimer { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Provides map tile URIs or images.
|
||||
/// </summary>
|
||||
|
|
@ -145,6 +149,8 @@ namespace MapControl
|
|||
get { return parentMap; }
|
||||
set
|
||||
{
|
||||
updateTimer.Stop();
|
||||
|
||||
if (parentMap != null)
|
||||
{
|
||||
parentMap.ViewportChanged -= OnViewportChanged;
|
||||
|
|
@ -165,20 +171,21 @@ namespace MapControl
|
|||
{
|
||||
if (Children.Count == 0 || e.ProjectionChanged || Math.Abs(e.LongitudeOffset) > 180d)
|
||||
{
|
||||
updateTimer.Stop();
|
||||
UpdateTileLayer(); // update immediately when projection has changed or center has moved across 180° longitude
|
||||
}
|
||||
else
|
||||
{
|
||||
SetRenderTransform();
|
||||
|
||||
if (UpdateTimer.IsEnabled && !UpdateWhileViewportChanging)
|
||||
if (updateTimer.IsEnabled && !UpdateWhileViewportChanging)
|
||||
{
|
||||
UpdateTimer.Stop(); // restart
|
||||
updateTimer.Stop(); // restart
|
||||
}
|
||||
|
||||
if (!UpdateTimer.IsEnabled)
|
||||
if (!updateTimer.IsEnabled)
|
||||
{
|
||||
UpdateTimer.Start();
|
||||
updateTimer.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
#if WINDOWS_UWP
|
||||
using Windows.UI.Xaml.Media;
|
||||
|
|
@ -89,29 +88,4 @@ namespace MapControl
|
|||
return base.GetUri(x, (1 << zoomLevel) - 1 - y, zoomLevel);
|
||||
}
|
||||
}
|
||||
|
||||
public class BoundingBoxTileSource : TileSource
|
||||
{
|
||||
public override Uri GetUri(int x, int y, int zoomLevel)
|
||||
{
|
||||
Uri uri = null;
|
||||
|
||||
if (UriFormat != null)
|
||||
{
|
||||
var tileSize = 360d / (1 << zoomLevel); // tile width in degrees
|
||||
var west = MapProjection.Wgs84MetersPerDegree * (x * tileSize - 180d);
|
||||
var east = MapProjection.Wgs84MetersPerDegree * ((x + 1) * tileSize - 180d);
|
||||
var south = MapProjection.Wgs84MetersPerDegree * (180d - (y + 1) * tileSize);
|
||||
var north = MapProjection.Wgs84MetersPerDegree * (180d - y * tileSize);
|
||||
|
||||
uri = new Uri(UriFormat
|
||||
.Replace("{west}", west.ToString(CultureInfo.InvariantCulture))
|
||||
.Replace("{south}", south.ToString(CultureInfo.InvariantCulture))
|
||||
.Replace("{east}", east.ToString(CultureInfo.InvariantCulture))
|
||||
.Replace("{north}", north.ToString(CultureInfo.InvariantCulture)));
|
||||
}
|
||||
|
||||
return uri;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,8 +90,6 @@ namespace MapControl
|
|||
|
||||
protected override void UpdateTileLayer()
|
||||
{
|
||||
UpdateTimer.Stop();
|
||||
|
||||
if (ParentMap == null ||
|
||||
!TileMatrixSets.TryGetValue(ParentMap.MapProjection.CrsId, out WmtsTileMatrixSet tileMatrixSet))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -59,6 +59,9 @@
|
|||
<Compile Include="..\Shared\BoundingBox.cs">
|
||||
<Link>BoundingBox.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\BoundingBoxTileSource.cs">
|
||||
<Link>BoundingBoxTileSource.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Shared\CenteredBoundingBox.cs">
|
||||
<Link>CenteredBoundingBox.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
|||
|
|
@ -26,18 +26,25 @@ namespace ViewModel
|
|||
{
|
||||
TileSource = new TileSource { UriFormat = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenStreetMap",
|
||||
Description = "© [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)",
|
||||
MaxZoomLevel = 19
|
||||
Description = "© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"OpenStreetMap German",
|
||||
new MapTileLayer
|
||||
{
|
||||
TileSource = new TileSource { UriFormat = "https://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png" },
|
||||
TileSource = new TileSource { UriFormat = "https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenStreetMap German",
|
||||
Description = "© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)",
|
||||
MaxZoomLevel = 19
|
||||
Description = "© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"OpenStreetMap French",
|
||||
new MapTileLayer
|
||||
{
|
||||
TileSource = new TileSource { UriFormat = "https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenStreetMap French",
|
||||
Description = "© [OpenStreetMap France](https://www.openstreetmap.fr/mentions-legales/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -46,10 +53,19 @@ namespace ViewModel
|
|||
{
|
||||
TileSource = new TileSource { UriFormat = "https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png" },
|
||||
SourceName = "OpenTopoMap",
|
||||
Description = "© [OpenTopoMap](https://opentopomap.org/)\n© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)",
|
||||
Description = "© [OpenTopoMap](https://opentopomap.org/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)",
|
||||
MaxZoomLevel = 17
|
||||
}
|
||||
},
|
||||
{
|
||||
"Hike & Bike",
|
||||
new MapTileLayer
|
||||
{
|
||||
TileSource = new TileSource { UriFormat = "https://tiles.wmflabs.org/hikebike/{z}/{x}/{y}.png" },
|
||||
SourceName = "HikeBike",
|
||||
Description = "© [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Seamarks",
|
||||
new MapTileLayer
|
||||
|
|
@ -60,35 +76,6 @@ namespace ViewModel
|
|||
MaxZoomLevel = 18
|
||||
}
|
||||
},
|
||||
{
|
||||
"TopPlusOpen WMTS",
|
||||
new WmtsTileLayer
|
||||
{
|
||||
SourceName = "TopPlusOpen",
|
||||
Description = "© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wmts-topplusopen-wmts-topplus-open.html)",
|
||||
CapabilitiesUri = new Uri("https://sgx.geodatenzentrum.de/wmts_topplus_open/1.0.0/WMTSCapabilities.xml")
|
||||
}
|
||||
},
|
||||
{
|
||||
"TopPlusOpen WMS",
|
||||
new WmsImageLayer
|
||||
{
|
||||
Description = "© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wms-topplusopen-mit-layer-fur-normalausgabe-und-druck-wms-topplus-open.html)",
|
||||
ServiceUri = new Uri("https://sgx.geodatenzentrum.de/wms_topplus_open")
|
||||
}
|
||||
},
|
||||
{
|
||||
"OpenStreetMap WMS",
|
||||
new WmsImageLayer
|
||||
{
|
||||
Description = "© [terrestris GmbH & Co. KG](http://ows.terrestris.de/)\nData © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)",
|
||||
ServiceUri = new Uri("http://ows.terrestris.de/osm/service")
|
||||
}
|
||||
},
|
||||
{
|
||||
"SevenCs ChartServer WMS",
|
||||
new ChartServerLayer()
|
||||
},
|
||||
{
|
||||
"Bing Maps Road",
|
||||
new BingMapsTileLayer
|
||||
|
|
@ -120,6 +107,35 @@ namespace ViewModel
|
|||
MapBackground = new SolidColorBrush(Colors.Black)
|
||||
}
|
||||
},
|
||||
{
|
||||
"TopPlusOpen WMTS",
|
||||
new WmtsTileLayer
|
||||
{
|
||||
SourceName = "TopPlusOpen",
|
||||
Description = "© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wmts-topplusopen-wmts-topplus-open.html)",
|
||||
CapabilitiesUri = new Uri("https://sgx.geodatenzentrum.de/wmts_topplus_open/1.0.0/WMTSCapabilities.xml")
|
||||
}
|
||||
},
|
||||
{
|
||||
"TopPlusOpen WMS",
|
||||
new WmsImageLayer
|
||||
{
|
||||
Description = "© [BKG](https://gdz.bkg.bund.de/index.php/default/webdienste/topplus-produkte/wms-topplusopen-mit-layer-fur-normalausgabe-und-druck-wms-topplus-open.html)",
|
||||
ServiceUri = new Uri("https://sgx.geodatenzentrum.de/wms_topplus_open")
|
||||
}
|
||||
},
|
||||
{
|
||||
"OpenStreetMap WMS",
|
||||
new WmsImageLayer
|
||||
{
|
||||
Description = "© [terrestris GmbH & Co. KG](http://ows.terrestris.de/) © [OpenStreetMap contributors](http://www.openstreetmap.org/copyright)",
|
||||
ServiceUri = new Uri("http://ows.terrestris.de/osm/service")
|
||||
}
|
||||
},
|
||||
{
|
||||
"SevenCs ChartServer WMS",
|
||||
new ChartServerLayer()
|
||||
},
|
||||
};
|
||||
|
||||
private string currentMapLayerName = "OpenStreetMap";
|
||||
|
|
@ -149,7 +165,9 @@ namespace ViewModel
|
|||
{
|
||||
"OpenStreetMap",
|
||||
"OpenStreetMap German",
|
||||
"OpenStreetMap French",
|
||||
"OpenTopoMap",
|
||||
"Hike & Bike",
|
||||
"TopPlusOpen WMTS",
|
||||
"TopPlusOpen WMS",
|
||||
"OpenStreetMap WMS",
|
||||
|
|
|
|||
|
|
@ -174,8 +174,8 @@
|
|||
</map:Pushpin>
|
||||
</map:Map>
|
||||
|
||||
<Border HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#7FFFFFFF">
|
||||
<TextBlock Margin="2" FontSize="10" map:HyperlinkText.InlinesSource="{Binding MapLayer.Description, ElementName=map}"/>
|
||||
<Border HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#AFFFFFFF">
|
||||
<TextBlock Margin="4,2" FontSize="10" map:HyperlinkText.InlinesSource="{Binding MapLayer.Description, ElementName=map}"/>
|
||||
</Border>
|
||||
|
||||
<Grid Grid.Row="1">
|
||||
|
|
|
|||
|
|
@ -21,8 +21,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Shared\MapLayers.cs" Link="MapLayers.cs" />
|
||||
<Compile Include="..\Shared\MapViewModel.cs" Link="MapViewModel.cs" />
|
||||
<Compile Include="..\Shared\*.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
Loading…
Reference in a new issue