Learn how to create and display a map with a basemap layer.

A map contains layers of geographic data. A map contains a basemap layer and, optionally, one or more data layers. You can display a specific area of a map by using a map view and setting the location and zoom level.
In this tutorial, you create and display a map of the Santa Monica Mountains in California using the topographic basemap layer.
The map and code will be used as the starting point for other 2D tutorials.
This tutorial builds a cross-platform app using the .NET Multi-platform App UI (.NET MAUI) framework. .NET MAUI allows you to build native cross-platform apps from a shared code base. If you'd prefer to build this app as a Windows desktop app, see the Windows Presentation Foundation (WPF) version of this tutorial.
Prerequisites
Before starting this tutorial:
-
You need an ArcGIS Location Platform or ArcGIS Online account.
-
Ensure your development environment meets the system requirements.
Optionally, you may want to install the ArcGIS Maps SDK for .NET to get access to project templates in Visual Studio (Windows only) and offline copies of the NuGet packages.
Set up authentication
To access the secure ArcGIS location services used in this tutorial, you must implement API key authentication or user authentication using an ArcGIS Location Platform or an ArcGIS Online account.
You can implement API key authentication or user authentication in this tutorial. Compare the differences below:
API key authentication
- Users are not required to sign in.
- Requires creating an API key credential with the correct privileges.
- API keys are long-lived access tokens.
- Service usage is billed to the API key owner/developer.
- Simplest authentication method to implement.
- Recommended approach for new ArcGIS developers.
Learn more in API key authentication.
User authentication
- Users are required to sign in with an ArcGIS account.
- User accounts must have privilege to access the ArcGIS services used in application.
- Requires creating OAuth credentials.
- Application uses a redirect URL and client ID.
- Service usage is billed to the organization of the user signed into the application.
Learn more in User authentication.
Create a new API key access token with privileges to access the secure resources used in this tutorial.
-
Complete the Create an API key tutorial and create an API key with the following privilege(s):
- Privileges
- Location services > Basemaps
- Privileges
-
Copy and paste the API key access token into a safe location. It will be used in a later step.
Develop or download
You have two options for completing this tutorial:
Option 1: Develop the code
Create a new Visual Studio Project
ArcGIS Maps SDK for .NET supports apps for Windows Presentation Framework (WPF), Universal Windows Platform (UWP), Windows UI Library (WinUI), and Multi-platform App UI (.NET MAUI). The instructions for this tutorial are specific to creating a .NET MAUI project using Visual Studio for Windows.
-
Start Visual Studio and create a new project.
- In the Visual Studio start screen, click Create a new project.
- Choose the .NET MAUI App template for C#. If you don't see the template listed, you can find it by typing
MAUI
into the Search for templates text box. - Click Next.
- Provide required values in the Configure your new project panel:
- Project name:
Display
A Map - Location:
choose a folder
- Project name:
- Click Next.
- Choose the .NET 8 as framework you intend to target.
- Click Create to create the project.
If you are developing with Visual Studio for Windows, ArcGIS Maps SDK for .NET provides a set of project templates for each supported .NET platform. These templates provide all of the code needed for a basic Model-View-ViewModel (MVVM) app. Install the ArcGIS Maps SDK for .NET Visual Studio Extension to add the templates to Visual Studio (Windows only). See Install and set up for details.
Add a reference to the API
-
Add a reference to the API by installing a NuGet package.
-
In Solution Explorer, right-click Dependencies and choose Manage NuGet Packages.
-
In the NuGet Package Manager window, ensure the selected Package source is
nuget.org
(upper-right). -
Select the Browse tab and search for ArcGIS Maps SDK.
-
In the search results, select the appropriate package for your platform. For this tutorial project, choose the Esri.ArcGISRuntime.Maui NuGet package.
-
Confirm the Latest stable version of the package is selected in the Version dropdown.
-
Click Apply.
-
The Preview Changes dialog confirms any package(s) dependencies or conflicts. Review the changes and click OK to continue installing the packages.
-
Review the license information on the License Acceptance dialog and click I Accept to add the package(s) to your project.
-
In the Visual Studio Output window, ensure the packages were successfully installed.
-
Close the NuGet Package Manager window.
-
Correct minimum OS versions
The .NET MAUI App template may have operating system (OS) requirements below what ArcGIS Maps SDK for .NET requires for a .NET MAUI app. You must modify the minimum OS versions in your .csproj to satisfy the ArcGIS Maps SDK for .NET requirements.
-
In Visual Studio > Solution Explorer, double-click DisplayAMap to open the .csproj.
-
Modify the
<Supported
properties in theOS Platform Version > <Property
as shown below. This reflects the minimum OS requirements for ArcGIS Maps SDK for .NET MAUI for the current release.Group > DisplayAMap.csprojUse dark colors for code blocks <!-- Versions --> <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> <ApplicationVersion>1</ApplicationVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">26.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.19041.0</SupportedOSPlatformVersion> <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.19041.0</TargetPlatformMinVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion> </PropertyGroup>
The .NET MAUI App template includes Tizen as a platform. ArcGIS Maps SDK for .NET does not support Tizen, so feel free to remove Tizen code and resources from the solution. This step is optional, your project will work fine if you keep it as-is.
-
Save and close the .csproj file.
Set developer credentials
To allow your app users to access ArcGIS Location Services, use the developer credentials that you created in the Set up authentication step to authenticate requests for resources.
-
In the Solution Explorer, open MauiProgram.cs by double-clicking.
-
Add the following required
using
directives at the top of the file.MauiProgram.csUse dark colors for code blocks namespace DisplayAMap; using Esri.ArcGISRuntime; using Esri.ArcGISRuntime.Maui; using Microsoft.Extensions.Logging; public static class MauiProgram { public static MauiApp CreateMauiApp() {
-
Use the existing
builder
variable in theCreate
function to callMaui App() Use
. Use a lambda function to callArcGIS Runtime() Use
on aApi Key() config
parameter to set theApi
property onKey ArcGISRuntimeEnvironment
.MauiProgram.csUse dark colors for code blocks var builder = MauiApp.CreateBuilder(); builder .UseMauiApp<App>() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); }); builder.UseArcGISRuntime(config => { config.UseApiKey("YOUR_ACCESS_TOKEN"); }); #if DEBUG builder.Logging.AddDebug(); #endif
-
Update the
"
placeholder with the API key access token you created earlier.YOUR _ACCESS _TOKE N" -
Save and close the MauiProgram.cs file.
Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.
Remove default controls
The .NET MAUI App template provided by Visual Studio has default controls and logic. These must be removed to make room for the map view in your UI.
-
Open the MainPage.xaml file.
-
Remove the
Scroll
container (and all the controls it contains) from the current UI.View MainPage.xamlUse dark colors for code blocks <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="DisplayAMap.MainPage"> <ScrollView> <VerticalStackLayout Spacing="25" Padding="30,0" VerticalOptions="Center"> <Image Source="dotnet_bot.png" SemanticProperties.Description="Cute dot net bot waving hi to you!" HeightRequest="200" HorizontalOptions="Center" /> <Label Text="Hello, World!" SemanticProperties.HeadingLevel="Level1" FontSize="32" HorizontalOptions="Center" /> <Label Text="Welcome to .NET Multi-platform App UI" SemanticProperties.HeadingLevel="Level2" SemanticProperties.Description="Welcome to dot net Multi platform App U I" FontSize="18" HorizontalOptions="Center" /> <Button x:Name="CounterBtn" Text="Click me" SemanticProperties.Hint="Counts the number of times you click" Clicked="OnCounterClicked" HorizontalOptions="Center" /> </VerticalStackLayout> </ScrollView> </ContentPage>
-
Open the MainPage.xaml.cs file.
-
Remove the
On
function and theCounter Clicked() count
variable.MainPage.xaml.csUse dark colors for code blocks namespace DisplayAMap; public partial class MainPage : ContentPage { int count = 0; public MainPage() { InitializeComponent(); } private void OnCounterClicked(object sender, EventArgs e) { count++; if (count == 1) CounterBtn.Text = $"Clicked {count} time"; else CounterBtn.Text = $"Clicked {count} times"; SemanticScreenReader.Announce(CounterBtn.Text); } }
-
Save and close MainPage.xaml and MainPage.xaml.cs.
Create a view model to store app logic
This app is the foundation for many following tutorials so it's good to build it with a solid design. The Model-View-ViewModel (MVVM) design pattern provides an architecture that separates user interface elements (and related code) from the underlying app logic.
In the MVVM pattern, the model
represents the data consumed in an app, the view
is the user interface, and the view model
contains the logic that binds the models and views together. The extra framework required for such a pattern might seem like a lot of work for a small project, but as the complexity of your project grows, a solid design can make your code much more maintainable and flexible.
In an ArcGIS app designed with MVVM, the map view usually provides the main view component. Many of the classes fill the role of models (representing data as maps, layers, graphics, features, and others). Much of the code you write will be for the view model component, since this is where you will add logic to work with ArcGIS objects and provide data for display in the view.
-
Add a new class that will define a view model for the project.
- Click Project > Add Class ....
- Name the new class
Map
.View Model.cs - Click Add to create the new class and add it to the project.
- The new class will open in Visual Studio.
-
Add required
using
statements to the view model.MapViewModel.csUse dark colors for code blocks using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Esri.ArcGISRuntime.Mapping; using Esri.ArcGISRuntime.Geometry; using System.ComponentModel; using System.Runtime.CompilerServices; using Map = Esri.ArcGISRuntime.Mapping.Map;
-
Implement the
I
interface in theNotify Property Changed Map
class.View Model This interface defines a
Property
event that is used to notify clients (views) that a property of the view model has changed.Changed MapViewModel.csUse dark colors for code blocks namespace DisplayAMap { internal class MapViewModel : INotifyPropertyChanged {
-
Inside the
Map
class, add code to implement theView Model Property
event.Changed When a property of the view model changes, a call to
On
will raise this event.Property Changed MapViewModel.csUse dark colors for code blocks internal class MapViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string propertyName = "") { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } }
-
Define a new property on the view model called
Map
that exposes aMap
object. When the property is set, callOn
.Property Changed MapViewModel.csUse dark colors for code blocks internal class MapViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string propertyName = "") { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } private Map _map; public Map Map { get => _map; set { _map = value; OnPropertyChanged(); } } }
-
Add a function to the
Map
class calledView Model Setup
. This function will create a new map and use it to set theMap Map
property.MapViewModel.csUse dark colors for code blocks private void SetupMap() { // Create a new map with a 'topographic vector' basemap. Map = new Map(BasemapStyle.ArcGISTopographic); }
-
Add code to set the map's
Initial
property to aViewpoint Viewpoint
.MapViewModel.csUse dark colors for code blocks // Create a new map with a 'topographic vector' basemap. Map = new Map(BasemapStyle.ArcGISTopographic); var mapCenterPoint = new MapPoint(-118.805, 34.027, SpatialReferences.Wgs84); Map.InitialViewpoint = new Viewpoint(mapCenterPoint, 100000);
-
Add a constructor to the class that calls
Setup
when a newMap() Map
is instantiated.View Model When you write code like
Map
to create a new instance, the class constructor is called. This is a good place to add code to set default values for properties and perform other setup tasks.View Model new Map V M = new Map View Model(); MapViewModel.csUse dark colors for code blocks namespace DisplayAMap { internal class MapViewModel : INotifyPropertyChanged { public MapViewModel() { SetupMap(); }
-
Save and close the MapViewModel.cs file.
Your Map
is complete!
An advantage of using the MVVM design pattern is the ability to reuse code in a view model. Because this API has a nearly-standard API surface across platforms, a view model
written for one app typically works on all supported .NET platforms.
Next, you will set up a view
in your project to consume the view model.
Add a map view
A MapView
control is used to display a map. You will add a map view to your project UI and wire it up to consume the map that is defined in the Map
.
-
Add required XML namespace and resource declarations to
Main
.Page.xaml - Open MainPage.xaml and switch to the XAML view
- Inside the existing namespace declarations, add an
esri
XML namespace for the ArcGIS controls and alocal
XML namespace - Add XAML that defines a
Map
instance as a static resourceView Model
MainPage.xamlUse dark colors for code blocks <ContentPage x:Class="DisplayAMap.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013" xmlns:local="clr-namespace:DisplayAMap"> <ContentPage.Resources> <local:MapViewModel x:Key="MapViewModel" /> </ContentPage.Resources>
-
Add a
MapView
control to MainPage.xaml and bind it to theMap
.View Model - Add XAML that defines a
Map
control namedView Main
Map View - Use data binding to set the
Map
property of the control using theMap
resourceView Model
MainPage.xamlUse dark colors for code blocks <?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="DisplayAMap.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013" xmlns:local="clr-namespace:DisplayAMap"> <ContentPage.Resources> <local:MapViewModel x:Key="MapViewModel" /> </ContentPage.Resources> <esri:MapView x:Name="MainMapView" Map="{Binding Map, Source={StaticResource MapViewModel}}" /> </ContentPage>
- Add XAML that defines a
-
Save and close the MainPage.xaml file.
Run the app
Click Debug > Start Debugging (or press <F5> on the keyboard) to run the app. If your app uses user authentication, enter your ArcGIS Online credentials when prompted.
Deploy the app to a Windows, Mac, iOS, or Android device. You will see a map with the topographic basemap layer centered on the Santa Monica Mountains in California. Pan and zoom with mouse or touchscreen controls to explore the map.
Alternatively, you can download the tutorial solution, as follows.
Option 2: Download the solution
-
Click the Download solution link in the right-hand panel of the page.
-
Unzip the file to a location on your machine.
-
Open the
.sln
file in Visual Studio.
Since the downloaded solution does not contain authentication credentials, you must add the developer credentials that you created in the set up authentication section.
Set developer credentials in the solution
To allow your app users to access ArcGIS location services, use the developer credentials that you created in the Set up authentication step to authenticate requests for resources.
-
In the Solution Explorer, open MauiProgram.cs by double-clicking.
-
Update the call to
Use
on theApi Key() config
parameter to set your API key access token.MauiProgram.csUse dark colors for code blocks var builder = MauiApp.CreateBuilder(); builder .UseMauiApp<App>() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); }); builder.UseArcGISRuntime(config => { config.UseApiKey("YOUR_ACCESS_TOKEN"); }); #if DEBUG builder.Logging.AddDebug(); #endif
-
Remove the line of code that sets the user authentication handler.
MauiProgram.csUse dark colors for code blocks var builder = MauiApp.CreateBuilder(); builder .UseMauiApp<App>() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); }); builder.UseArcGISRuntime(config => { config.UseApiKey("YOUR_ACCESS_TOKEN"); }); // Set up the AuthenticationManager to use OAuth for secure ArcGIS Online requests. UserAuth.ArcGISLoginPrompt.SetChallengeHandler(); #if DEBUG builder.Logging.AddDebug(); #endif
-
Save and close the MauiProgram.cs file.
Best Practice: The access token is stored directly in the code as a convenience for this tutorial. Do not store credentials directly in source code in a production environment.
Run the app
Click Debug > Start Debugging (or press <F5> on the keyboard) to run the app. If your app uses user authentication, enter your ArcGIS Online credentials when prompted.
Deploy the app to a Windows, Mac, iOS, or Android device. You will see a map with the topographic basemap layer centered on the Santa Monica Mountains in California. Pan and zoom with mouse or touchscreen controls to explore the map.
What's next?
Learn how to use additional API features, ArcGIS location services, and ArcGIS tools in these tutorials: