[英]MapControl using XAML Island in WPF: default map layer is shown over custom tile layer
I've added a MapControl
using this instruction to my WPF application.我已使用此指令将MapControl
添加到我的 WPF 应用程序中。 I wanted to add custom map layer to it, so I've added a OpenStreetMap
tile layer using this instruction .我想向其中添加自定义地图图层,因此我使用此指令添加了OpenStreetMap
切片图层。 I want to remove the default map at all, but it doesn't work.我想完全删除默认地图,但它不起作用。
I've tested the original MapControl
in a UWP app and it works.我已经在 UWP 应用程序中测试了原始MapControl
并且它可以工作。
My code in WPF:我在 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);
}
}
This is the WPF application.这是 WPF 应用程序。 It shows OpenStreetMap
layer and also default Bing
map layer on top:它在顶部显示OpenStreetMap
图层和默认的Bing
地图图层:
This is the UWP app and shows only OpenStreetMap
perfectly:这是 UWP 应用程序,仅完美显示OpenStreetMap
:
Is there any solution to fix it in WPF?有什么解决方案可以在 WPF 中修复它吗?
Update更新
I find out that this line doesn't apply correctly and it caused the error:我发现这条线应用不正确,并导致了错误:
mapControl.Style = Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.MapStyle.None;
Finally I found the solution.最后我找到了解决方案。 Add these lines to the initialization code:将这些行添加到初始化代码中:
Windows.UI.Xaml.Controls.Maps.MapControl originalMapControl =
mapControl.GetUwpInternalObject() as Windows.UI.Xaml.Controls.Maps.MapControl;
if (originalMapControl != null)
{
originalMapControl.Style = MapStyle.None;
}
It fixes the defect.它修复了缺陷。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.