![](/img/trans.png)
[英]using XAML Map Control to add a heatmap layer on a map based on OpenStreetMap from C# VS2013 WPF
[英]MapControl using XAML Island in WPF: default map layer is shown over custom tile layer
我已使用此指令將MapControl
添加到我的 WPF 應用程序中。 我想向其中添加自定義地圖圖層,因此我使用此指令添加了OpenStreetMap
切片圖層。 我想完全刪除默認地圖,但它不起作用。
我已經在 UWP 應用程序中測試了原始MapControl
並且它可以工作。
我在 WPF 中的代碼:
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls"
Title="MainWindow" Height="450" Width="800">
<Grid>
<controls:MapControl x:Name="mapControl" />
</Grid>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
HttpMapTileDataSource dataSource = new HttpMapTileDataSource("http://c.tile.openstreetmap.org/{zoomlevel}/{x}/{y}.png");
MapTileSource tileSource = new MapTileSource(dataSource);
tileSource.Visible = true;
tileSource.Layer = MapTileLayer.BackgroundReplacement;
tileSource.IsFadingEnabled = false;
mapControl.Style = Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.MapStyle.None;
mapControl.TileSources.Add(tileSource);
}
}
這是 WPF 應用程序。 它在頂部顯示OpenStreetMap
圖層和默認的Bing
地圖圖層:
這是 UWP 應用程序,僅完美顯示OpenStreetMap
:
有什么解決方案可以在 WPF 中修復它嗎?
更新
我發現這條線應用不正確,並導致了錯誤:
mapControl.Style = Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.MapStyle.None;
最后我找到了解決方案。 將這些行添加到初始化代碼中:
Windows.UI.Xaml.Controls.Maps.MapControl originalMapControl =
mapControl.GetUwpInternalObject() as Windows.UI.Xaml.Controls.Maps.MapControl;
if (originalMapControl != null)
{
originalMapControl.Style = MapStyle.None;
}
它修復了缺陷。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.