Back to Devexpress

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

wpf-devexpress-dot-xpf-dot-map-dot-mapcontrol-dot-zoomtofitlayeritems-x28-system-dot-collections-dot-generic-dot-ienumerable-devexpress-dot-xpf-dot-map-dot-layerbase-system-dot-boolean-system-dot-double-x29.md

latest4.8 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Wpf.Map

Declaration

csharp
public void ZoomToFitLayerItems(
    IEnumerable<LayerBase> layers,
    bool roundZoomLevel,
    double paddingFactor = 0.15
)
vb
Public Sub ZoomToFitLayerItems(
    layers As IEnumerable(Of LayerBase),
    roundZoomLevel As Boolean,
    paddingFactor As Double = 0.15
)

Parameters

NameTypeDescription
layersIEnumerable<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

NameTypeDefaultDescription
paddingFactorDouble0.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.

  • Zooms the map to fit the box.

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

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

xaml
<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>
csharp
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);
        }

    }
}
vb
Imports DevExpress.Xpf.Map

Namespace MapApp
    Public Partial Class MainWindow
        Inherits Window

        Private Sub OnWindowLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            mapControl.ZoomToFitLayerItems(layers:=New LayerBase() {vectorLayer}, roundZoomLevel:=True, paddingFactor:=0.15)
        End Sub
    End Class
End Namespace

See Also

MapControl Class

MapControl Members

DevExpress.Xpf.Map Namespace