I can add PNG images without issue to change the default MapIcon Image, but as soon as I try to use an SVG the application crashes with 'application.exe has exited with code -529697949 (0xe06d7363) 'Microsoft C++ Exception'.
I am aware of the SvgImageSource class and I can use this fine in other areas of the application to render an SVG image, however when trying to add an SVG to the MapIcon.Image; which is of type IRandomAccessStreamReference, it does not work. I'm just wondering if this is a limitation of the API and if I should just be using bitmaps rather than an SVG when it comes to displaying custom images on the MapIcon?
I've added a quick failing sample below.
MainPage.xaml:
<Page xmlns:my="using:Windows.UI.Xaml.Controls.Maps"
x:Class="TestMapWithSVGForMapIcon.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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>
<my:MapControl Loaded="{x:Bind _viewModel.AddMapIcon}"/>
</Grid>
</Page>
MainPage.xaml.cs:
public sealed partial class MainPage : Page
{
private MainViewModel _viewModel;
public MainPage()
{
InitializeComponent();
_viewModel = new MainViewModel();
DataContext = _viewModel;
}
}
MainViewModel.cs:
public class MainViewModel
{
protected MapControl Map { get; set; }
public void AddMapIcon(object sender, RoutedEventArgs e)
{
if (sender is MapControl map)
{
Map = map;
}
var mapIcon = new MapIcon
{
Location = new Geopoint(new BasicGeoposition()
{
Latitude = 53.795452,
Longitude = -4.304733
}),
//works Ok with .png files
Image = RandomAccessStreamReference.CreateFromUri(new Uri($"ms-appx:///Assets/Hazard_H1.svg")),
};
Map.MapElements.Add(mapIcon);
}
}
No, SVG is not a supported stream type for MapIcon.Image You can use a stream that contains an encoded raster image in PNG or JPG format, or a raw array of bytes in RGB format.