簡體   English   中英

MapControl 在 WPF 中使用 XAML 島:默認地圖層顯示在自定義圖塊層上

[英]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地圖圖層:

WPF 中的地圖控件

這是 UWP 應用程序,僅完美顯示OpenStreetMap

UWP 中的 MapControl

有什么解決方案可以在 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM