This sample demonstrates how to create a UWP Map using the Syncfusion SfMap control.
- Visual Studio 2022 or later
- Windows 10 SDK (10.0.16299.0 or later)
- Syncfusion.SfMaps.UWP NuGet package (latest)
- Right-click on the project in Solution Explorer and select Manage NuGet Packages.
- Search for
Syncfusion.SfMaps.UWPand install it.
- Open the Add Reference window from your project.
- Choose Windows > Extensions > Syncfusion Controls for UWP XAML.
After adding the reference, include the following namespace in your MainPage.xaml:
xmlns:syncfusion="using:Syncfusion.UI.Xaml.Maps"In MainPage.xaml, initialize SfMap by adding a ShapeFileLayer and setting the Uri property to point to your shape file:
<Page
x:Class="MapsGettingStarted_Sample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MapsGettingStarted_Sample"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:syncfusion="using:Syncfusion.UI.Xaml.Maps"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" Name="mainGrid">
<syncfusion:SfMap>
<syncfusion:SfMap.Layers>
<syncfusion:ShapeFileLayer Uri="MapsGettingStarted_Sample.Assets.ShapeFiles.world1.shp">
</syncfusion:ShapeFileLayer>
</syncfusion:SfMap.Layers>
</syncfusion:SfMap>
</Grid>
</Page>Alternatively, you can create the map entirely in C# code-behind:
using Syncfusion.UI.Xaml.Maps;
// Initializing the map
SfMap syncMap = new SfMap();
// Creating and configuring the shape file layer
ShapeFileLayer layer = new ShapeFileLayer();
layer.Uri = "MapsGettingStarted_Sample.Assets.ShapeFiles.world1.shp";
// Adding the layer to the map
syncMap.Layers.Add(layer);
// Adding map to the Grid
mainGrid.Children.Add(syncMap);