Skip to main content

How to: Customize the Cylindrical Equal-Area Projection

  • 2 minutes to read

To customize equal-area projection, do the following.

<Page xmlns:Map="using:DevExpress.UI.Xaml.Map" 
    x:Class="MapControl_CustomProjections.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MapControl_CustomProjections"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" Loaded="Page_Loaded">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Map:MapControl x:Name="mapControl">
            <Map:VectorFileLayer>
                <Map:ShapefileReader>
                    <Map:MapPackageFileSource FileName="Assets\Countries.shp"/>
                </Map:ShapefileReader>
            </Map:VectorFileLayer>
        </Map:MapControl>
        <ListView Name="listView"
                  HorizontalAlignment="Right" VerticalAlignment="Top" 
                  Header="Projection Ratio:"
                  ItemsSource="{Binding ProjectionRatios}" 
                  FontSize="26.667" Margin="20" BorderThickness="2" BorderBrush="White"
                  MinWidth="250"
                  SelectionChanged="ListView_SelectionChanged">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}" TextAlignment="Left" Margin="8" />
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

    </Grid>
</Page>
using DevExpress.UI.Xaml.Map;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;

namespace MapControl_CustomProjections {
    public sealed partial class MainPage : Page {
        ProjectionRatio[] projectionRatios = { 
            new ProjectionRatio("Lambert", 3.14),
            new ProjectionRatio("Behrmann", 2.36),
            new ProjectionRatio("Trystan Edwards", 2),
            new ProjectionRatio("Gall-Peters", 1.57),
            new ProjectionRatio("Balthasart", 1.3),
            new ProjectionRatio("Default", 1)
        };

        int sizeValue = 512;

        public  ProjectionRatio[] ProjectionRatios{ get { return projectionRatios; } }

        public MainPage() {
            this.InitializeComponent();
            this.DataContext = this;
        }

        private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e) {
            ListView listView = sender as ListView;
            if (listView == null) return;

            ((VectorFileLayer)mapControl.Layers[0]).InitialMapSize = new Size(
                ((ProjectionRatio)listView.SelectedItem).Value * sizeValue, sizeValue
            );
        }

        private void Page_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) {
            listView.SelectedIndex = ProjectionRatios.Length - 1;
        }
    }

    public class ProjectionRatio {
        public ProjectionRatio(string name, double value) {
            Name = name;
            Value = value;
        }

        public string Name { get; set; }
        public double Value { get; set; }
    }
}