Repository navigation
Your first map enabled desktop application
Learn how to build a desktop mapping application from scratch using WPF (Windows Presentation Foundation) and the Maptor spatial library. This tutorial is designed for beginners with no prior WPF experience.

By the end of this tutorial, you'll have a fully functional desktop application that can:
- Display interactive maps
- Add shapefile data to the map
- Measure distances and areas
- Navigate around the map
Before starting, make sure you have:
- .NET 8 SDK installed
- Visual Studio 2022 (Community edition is free) or Visual Studio Code
- Basic knowledge of C# (variables, methods, classes)
Note: If you're completely new to C#, we recommend going through a basic C# tutorial first.
WPF (Windows Presentation Foundation) is Microsoft's framework for building desktop applications on Windows. It uses XAML (eXtensible Application Markup Language) to design user interfaces and C# for the application logic.
- Open Visual Studio and select "Create a new project"
- Search for "WPF" and select "WPF Application" (make sure it targets .NET 8)
- Name your project (e.g., "MyFirstMapApp")
- Choose a location and click "Create"

After creating the project, you'll see these files:
- MainWindow.xaml - The visual design of your main window
- MainWindow.xaml.cs - The C# code behind the window
- App.xaml - Application-level settings and resources
- App.xaml.cs - Application startup code
- Right-click on your project in Solution Explorer
- Select "Manage NuGet Packages"
- Go to the "Browse" tab
- Search for "IRI.Maptor.Jab.Controls"
- Click "Install"
Alternatively, you can use the Package Manager Console:
dotnet add package IRI.Maptor.Jab.Controls Application resources in WPF are reusable styles, templates, and other UI elements that can be shared across your entire application. We need to configure these to make the Maptor controls look and work properly.
- Open App.xaml in your project
- Replace the existing content with the following:
<Application x:Class="MyFirstMapApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro Styles for Modern UI -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.Slider.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.RadioButton.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.TabControl.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Amber.xaml" />
<!-- Maptor Custom Styles -->
<ResourceDictionary Source="pack://application:,,,/IRI.Maptor.Jab.Common;component/Assets/Styles/ButtonStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/IRI.Maptor.Jab.Common;component/Assets/Shapes/Others.xaml"/>
<ResourceDictionary Source="pack://application:,,,/IRI.Maptor.Jab.Common;component/Assets/IRI.Converters.xaml"/>
<ResourceDictionary Source="pack://application:,,,/IRI.Maptor.Jab.Common;component/Assets/IRI.Fonts.xaml"/>
<ResourceDictionary Source="pack://application:,,,/IRI.Maptor.Jab.Common;component/Assets/IRI.Colors.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>XAML (eXtensible Application Markup Language) is used to design the user interface. It's similar to HTML but for desktop applications.
- Open MainWindow.xaml
- Replace the existing content with the following:
<Window x:Class="MyFirstMapApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maptor="clr-namespace:IRI.Maptor.Jab.Controls.View;assembly=IRI.Maptor.Jab.Controls"
Title="My First Map Application"
Height="600"
Width="800"
Loaded="Window_Loaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Toolbar with buttons using predefined commands -->
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="10" Background="LightGray">
<Button Content="Add Shapefile" Command="{Binding AddShapefileCommand}" Margin="5" Padding="10,5"/>
<Button Content="Measure Length" Command="{Binding MeasureLengthCommand}" Margin="5" Padding="10,5"/>
<Button Content="Measure Area" Command="{Binding MeasureAreaCommand}" Margin="5" Padding="10,5"/>
</StackPanel>
<!-- Map Control -->
<maptor:MapViewer x:Name="map" Grid.Row="1" BorderBrush="Black" BorderThickness="1"/>
<!-- Map Info Panel -->
<maptor:MapInfoView DataContext="{Binding}" Grid.Row="1" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10"/>
</Grid>
</Window>- Open MainWindow.xaml.cs
- Replace the existing content with the following:
using System;
using System.Windows;
using IRI.Maptor.Jab.Controls.Presenter;
using IRI.Maptor.Jab.Common;
namespace MyFirstMapApp
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
// Initialize encoding support for international characters
System.Text.Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
// Create and initialize the map presenter (viewmodel)
var presenter = new MapApplicationPresenter();
await this.map.Register(presenter);
presenter.Initialize(this);
// Configure the map
presenter.SelectedMapProvider = TileMapProviderFactory.GoogleRoadMap;
presenter.ZoomToExtent(BoundingBoxes.WebMercator_Africa, false, isNewExtent: true);
}
catch (Exception ex)
{
MessageBox.Show($"Error initializing map: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}-
Window_Loaded- This method runs when the window is first displayed -
MapApplicationPresenter- This is the "brain" of the map that handles all map operations -
this.map.Register(presenter)- This connects the map control to the presenter -
presenter.Initialize(this)- This sets up the presenter with the current window -
TileMapProviderFactory.GoogleRoadMap- This sets Google Maps as the base layer -
BoundingBoxes.WebMercator_Africa- This sets the initial view to show Africa - No button click handlers needed! - The buttons use predefined commands that work automatically
- Press F5 or click the "Start" button in Visual Studio
- Your application should start and show a map of Africa
- Try the buttons to test the functionality
You've successfully created your first map-enabled desktop application!
- How to create a WPF application
- How to use XAML to design user interfaces
- How to integrate third-party controls (Maptor)
- How to handle user interactions with C#
- How to display interactive maps in a desktop application
- Try adding more features to your application
- Experiment with different map providers
- Add more buttons and functionality
- Learn more about WPF layouts and styling
For a more advanced example with additional features, check out the complete sample project.
π Home
π IRI.Maptor.Sta.ShapefileFormat
Coming Soon
Coming Soon
Maptor Spatial Library Ecosystem