A demonstration of building map-enabled applications with minimal code using the Maptor spatial library.
- 🗺️ Interactive Map Display with multiple layer support
- 📏 Measurement Tools for distance and area
- ✏️ Drawing Tools (points, lines, polygons)
- 🔍 GoTo Location navigation
- 🔄 Coordinate System Transformations
- 🖱️ Mouse Coordinate Tracking
- .NET 8 SDK
- Visual Studio 2019 or newer
- Clone the repository:
git clone https://github.com/hosseinnarimanirad/Maptor.git
- Open the solution file
- Restore NuGet packages
- Build and run the application
-
Create a new WPF project Visual Studio targeting .NET 8 (or higher).
-
Install the required Maptor NuGet package
dotnet add package IRI.Maptor.Jab.Controls --version 2.7.1-alpha.20
- Reference the Maptor’s resource files in App.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<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" />
<ResourceDictionary Source="pack://application:,,,/IRI.Maptor.Jab.Common;component/Assets/Styles/ButtonStyles.xaml"/>
<ResourceDictionary Source="pack://application:,,,/IRI.Maptor.Jab.Common;component/Assets/Shapes/IranBoundaries.xaml"/>
<ResourceDictionary Source="pack://application:,,,/IRI.Maptor.Jab.Common;component/Assets/Shapes/Appbar.xaml"/>
<ResourceDictionary Source="pack://application:,,,/IRI.Maptor.Jab.Common;component/Assets/Shapes/AppbarExtension.xaml"/>
<ResourceDictionary Source="pack://application:,,,/IRI.Maptor.Jab.Common;component/Assets/Shapes/IriShapes.xaml"/>
<ResourceDictionary Source="pack://application:,,,/IRI.Maptor.Jab.Common;component/Assets/Shapes/MaterialDesign.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>
- Define the Maptor namespace in your MainWindow.xaml (or the desired window)
<Window ...
xmlns:maptor="clr-namespace:IRI.Maptor.Jab.Controls.View;assembly=IRI.Maptor.Jab.Controls">
</Window>
- Add the MapViewer control along with any other necessary UI elements
<maptor:MapViewer Grid.Row="1" x:Name="map" BorderBrush="Black" BorderThickness="1"/>
<maptor:MapInfoView Grid.Row="1" DataContext="{Binding }"/>
In the code-behind, configure the map and set up:
- Google Maps as the base layer
- An initial map extent for your view
This is done in the
Window.Loaded
event
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
// initial setup
System.Text.Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
// Initialize map presenter (viewmodel)
var presenter = new MapApplicationPresenter();
await this.map.Register(presenter);
presenter.Initialize(this);
// Configure initial view
presenter.SelectedMapProvider = TileMapProviderFactory.GoogleRoadMap;
presenter.ZoomToExtent(BoundingBoxes.WebMercator_Africa, false, isNewExtent: true);
}
📍Add shapefiles to map
Add a button and set its command to AddShapefileCommand
<Button Content="{Binding AddShapefileText}" Command="{Binding AddShapefileCommand}"/>
📍Measure distance and area
Add buttons and set their commands to MeasureLengthCommand
and MeasureAreaCommand
.
<StackPanel Orientation="Horizontal" >
<Button Content="{Binding MeasureLengthText}" Command="{Binding MeasureLengthCommand}"/>
<Button Content="{Binding MeasureAreaText}" Command="{Binding MeasureAreaCommand}"/>
</StackPanel>
📍Add drawings to map
To draw point/line/polygon add buttons and set their commands.
<StackPanel Orientation="Horizontal" >
<Button Content="{Binding DrawPointText}" Command="{Binding DrawPointCommand}"/>
<Button Content="{Binding DrawPolylineText}" Command="{Binding DrawPolylineCommand}"/>
<Button Content="{Binding DrawPolygonText}" Command="{Binding DrawPolygonCommand}"/>
</StackPanel>
📍Use Go To dialog
To user Go To dialog all you need is to add a button and set its command.
<Button Content="{Binding GoToText}" Command="{Binding GoToCommand}"/>
📍Show current mouse position
You can show the current mouse position in geographic (wgs84), utm, mercator, and several other spatial reference systems. To do that just add the CoordinatePanelView
component and bind its Position
property to the map
:
<maptor:CoordinatePanelView DataContext="{Binding CoordinatePanel}" Position="{Binding CurrentPoint, ElementName=map}"/>
This project is licensed under the MIT License.