Search code examples
uwpmapsbing

UWP Map Control - Resize MapIcon Images


How do you increase the size of MapIcons and Billboard Images? I've tried the stylesheets scaling as well as C# code, but it does not seem to change.

var mapIcon = new MapIcon()
{
    Location = new Geopoint(
        new BasicGeoposition
        {
            Latitude = entry.Latitude,
            Longitude = entry.Longitude,
        }),
    NormalizedAnchorPoint = new Windows.Foundation.Point(0.5, 1.0),
    Title = entry.Name,
    Image = RandomAccessStreamReference.CreateFromUri(new Uri($"ms-appx:///Assets/KMZ/Pins/icon.png"))                
};

Solution

  • Unfortunately, MapIcon does not provide an API to resize itself, you must resize the image that is used yourself.

    Resizing the image can be done using using BitmapDecoder, which reads the source image and BitmapEncoder which allows you to write a modified stream of the bitmap (even in memory). Resizing can be done using BitmapTransform.ScaledWidth and BitmapTransform.ScaledHeight APIs.

    Jay Zuo shared a full solution in this StackOverflow answer. Although the question mentions Xamarin.Forms, this technique is purely UWP-based so it fully applies to your issue as well.