xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.87k forks source link

[Bug] The tile layer image for OpenStreetMap was not displayed in Xamarin.Forms UWP when the tile layer URI is added to the Image control #15783

Open VishalOmprasad opened 1 year ago

VishalOmprasad commented 1 year ago

Description

I was trying to display the image of tile layer for OpenStreetMap using the Image control in the UWP platform, but the tile layer was displayed or displayed blank.

Steps to Reproduce

  1. Create a new Xamarin.Forms application.
  2. In the MainPage.xaml, add a simple image control.
  3. In the MainPage.xaml.cs, initialize a new BitMapImage control and set the OSM tile layer's URI to its UriSource property. Then set the BitMapImage to the Image.Source.
  4. Run the application.

Expected Behavior

The image of the OSM tile should be displayed.

Actual Behavior

The image of the OSM tile was not displayed.

Example Code Snippet

In MainPage.xaml

<Page
    x:Class="BitmapImageDemo.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BitmapImageDemo"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <Image x:Name="image"
               Stretch="Uniform" />
    </Grid>
</Page>

In MainPage.xaml.cs

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
        BitmapImage bitmapImage = new BitmapImage();
        bitmapImage.UriSource = new Uri("https://tile.openstreetmap.org/1/1/0.png", UriKind.RelativeOrAbsolute);
        image.Width = bitmapImage.DecodePixelWidth = 256;
        image.Height = bitmapImage.DecodePixelHeight = 256;
        image.Source = bitmapImage;
    }
}

Your can also find/download the example sample from the following github link.

Basic Information