Back to Devexpress

How to: Provide Cylindrical Equal-Area Projections

wpf-14081-controls-and-libraries-map-control-examples-vector-data-customize-data-appearance-how-to-provide-cylindrical-equal-area-projections.md

latest7.0 KB
Original Source

How to: Provide Cylindrical Equal-Area Projections

  • Jun 07, 2019
  • 3 minutes to read

This example illustrates how to get equal-area map projections (Lambert, Behrmann, Tristan Edwards, Peters, Gall orthographic and Balthasart) for the shapes loaded from the Shapefiles ( Countries.shp , Countries.dbf ).

To accomplish this task, create an EqualAreaProjection object and assign it to the ((GeoMapCoordinateSystem)MapControl.CoordinateSystem).Projection property. Then, specify the Width/height aspect ratio for each equal area projection using the MapControl.InitialMapSize property.

To learn more about the equal-area projections, see Cylindrical_equal-area_projection.

csharp
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace AvoidMapDistortion {
    public partial class MainWindow : Window {
        public struct WidthHeightRatio {
            public string Name { get; set; }
            public double Value { get; set; }
        }

        int defaultSideSize = 512;
        List<WidthHeightRatio> ratios = new List<WidthHeightRatio>() {
            new WidthHeightRatio() { Name = "(Default)", Value = 1 },
            new WidthHeightRatio() { Name = "Lambert", Value = 3.14 },
            new WidthHeightRatio() { Name = "Behrmann", Value = 2.36 },
            new WidthHeightRatio() { Name = "Trystan Edwards", Value = 2.0 },
            new WidthHeightRatio() { Name = "Gall-Peters", Value = 1.57 },
            new WidthHeightRatio() { Name = "Balthasart", Value = 1.3 }
        };
        public List<WidthHeightRatio> Ratios { get { return ratios; } }

        public MainWindow() {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e) {
            this.DataContext = Ratios;
        }

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
            mapControl.InitialMapSize = new Size() {
                Width = defaultSideSize,
                Height = (int)(defaultSideSize / ((WidthHeightRatio)lbRatio.SelectedValue).Value)
            };
        }
    }
}
vb
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Controls

Namespace AvoidMapDistortion
    Partial Public Class MainWindow
        Inherits Window

        Public Structure WidthHeightRatio
            Public Property Name() As String
            Public Property Value() As Double
        End Structure

        Private defaultSideSize As Integer = 512

        Private ratios_Renamed As New List(Of WidthHeightRatio)() From { _
            New WidthHeightRatio() With {.Name = "(Default)", .Value = 1}, _
            New WidthHeightRatio() With {.Name = "Lambert", .Value = 3.14}, _
            New WidthHeightRatio() With {.Name = "Behrmann", .Value = 2.36}, _
            New WidthHeightRatio() With {.Name = "Trystan Edwards", .Value = 2.0}, _
            New WidthHeightRatio() With {.Name = "Gall-Peters", .Value = 1.57}, _
            New WidthHeightRatio() With {.Name = "Balthasart", .Value = 1.3} _
        }
        Public ReadOnly Property Ratios() As List(Of WidthHeightRatio)
            Get
                Return ratios_Renamed
            End Get
        End Property

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Me.DataContext = Ratios
        End Sub

        Private Sub ListBox_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
            mapControl.InitialMapSize = New Size() With {.Width = defaultSideSize, .Height = CInt((defaultSideSize / CType(lbRatio.SelectedValue, WidthHeightRatio).Value))}
        End Sub
    End Class
End Namespace
xaml
<Window x:Class="AvoidMapDistortion.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map"
        Title="MainWindow" Height="557" Width="707" Loaded="Window_Loaded">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="3*"/>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <dxm:MapControl Name="mapControl" Margin="4,4,2,4"
                        Grid.Row="0" Grid.Column="0">
            <dxm:VectorLayer>
                <dxm:ShapefileDataAdapter 
                    FileUri="Shapefiles/Countries.shp"/>
            </dxm:VectorLayer>
        </dxm:MapControl>
        <StackPanel Orientation="Vertical" Margin="2,4,4,4"
                    Grid.Row="0" Grid.Column="1">
            <Label Content="Width/Height Ratio:"/>
            <ListBox Name="lbRatio" ItemsSource="{Binding}" 
                     DisplayMemberPath="Name" SelectedIndex="0" 
                     SelectionChanged="ListBox_SelectionChanged"/>
        </StackPanel>
    </Grid>
</Window>

See Also

How to: Show Titles for Map Shapes

How to: Show Tooltips for Map Shapes

How to: Create a Map Item Attribute and Show its Value in the Map Tooltip

How to: Customize the Appearance of a Vector Element

How to: Show a Title for a Vector Element

How to: Customize the Appearance of a Vector Element's Title

How to: Customize the Appearance of a Map Pushpin

How to: Customize Animation of a Map Pushpin