Skip to main content
All docs
V24.2

MapControl.ZoomToFitLayerItems(IEnumerable<LayerBase>, Boolean, Double) Method

Zooms a map to fit vector items contained in the specified map layers. Allows you to specify whether to use an integer zoom level, and set the padding factor.

Namespace: DevExpress.Xpf.Map

Assembly: DevExpress.Xpf.Map.v24.2.dll

NuGet Package: DevExpress.Wpf.Map

Declaration

public void ZoomToFitLayerItems(
    IEnumerable<LayerBase> layers,
    bool roundZoomLevel,
    double paddingFactor = 0.15
)

Parameters

Name Type Description
layers IEnumerable<LayerBase>

A collection of layers that contain items to be displayed on the map.

roundZoomLevel Boolean

Specifies whether to round the zoom level value.

Optional Parameters

Name Type Default Description
paddingFactor Double 0.15

Specifies the size of the border around displayed map items.

Remarks

The ZoomToFitLayerItems method works as follows:

  • Calculates a bounding box around map items contained in map layers.

    WpfMapControl_ZoomToFit_BoundingBox

  • Zooms the map to fit the box.

    The padding factor is applied to the larger dimension of the bounding box that contains visible items.

    The following image shows an instance of a horizontal dimension that is larger than the vertical (“PF” means “Padding Factor” on images):

    WpfMapControl_ZoomToFit_VerticalFitting

    When the vertical dimension is larger than the horizontal, the zoom appears as follows:

    WpfMapControl_ZoomToFit_HorizontalFitting

    Note that the padding factor is divided by two for each side of the region.

The following image shows a map with the padding factor parameter set to 0.3:

WpfMapControl_ZoomToFit_NumericExample

The following example shows how to zoom a map to display items contained in the specified map layers:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:MapApp"
        xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts" 
        xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map" 
        x:Class="MapApp.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800" Loaded="OnWindowLoaded">
    <Grid>

        <dxm:MapControl x:Name="mapControl">
            <dxm:VectorLayer x:Name="vectorLayer">
                <dxm:MapItemStorage x:Name="mapItemStorage">
                    <dxm:MapDot Location="51.30, 0.07" Size="20" Fill="Wheat"/>
                    <dxm:MapDot Location="52.31, 13.23" Size="20" Fill="Gold"/>
                    <dxm:MapDot Location="48.51, 2.21" Size="20" Fill="CadetBlue"/>
                    <dxm:MapDot Location="41.54, 12.3" Size="20" Fill="Red"/>
                    <dxm:MapDot Location="40.23, -3.43" Size="20" Fill="Green"/>
                </dxm:MapItemStorage>
            </dxm:VectorLayer>
        </dxm:MapControl>
    </Grid>
</Window>
using DevExpress.Xpf.Map;
using System.Windows;

namespace MapApp {
    public partial class MainWindow : Window {

        private void OnWindowLoaded(object sender, RoutedEventArgs e) {
            mapControl.ZoomToFitLayerItems(layers: new LayerBase[] { vectorLayer }, roundZoomLevel: true, paddingFactor: 0.15);
        }

    }
}
See Also