Skip to content

hosseinnarimanirad/MaptorSamples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🗺️ Maptor Spatial Library - Sample WPF Application

.NET License

A demonstration of building map-enabled applications with minimal code using the Maptor spatial library.

Maptor Sample Application Screenshot

✨ Features

  • 🗺️ 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

🚀 Getting Started

Prerequisites

Installation

  1. Clone the repository:
git clone https://github.com/hosseinnarimanirad/Maptor.git
  1. Open the solution file
  2. Restore NuGet packages
  3. Build and run the application

🛠️ Building Your Own Map Application

Project Setup

  1. Create a new WPF project Visual Studio targeting .NET 8 (or higher).

  2. Install the required Maptor NuGet package

dotnet add package IRI.Maptor.Jab.Controls --version 2.7.1-alpha.20
  1. 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>

Prepare the map in XAML

  1. 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>
  1. 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 }"/> 

Configure the Map in C#

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 Core Functionalities

📍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}"/>

📜 License

This project is licensed under the MIT License.

About

Sample projects using maptor spatial library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages