Skip to main content
All docs
V25.1
  • MapControl.ZoomToFit(IEnumerable<MapItem>, Boolean, Double) Method

    Zooms the map based on a specified padding factor to allow the map viewport to display all items passed in parameters. Allows you to set whether the map should use a non-negative integer zoom level.

    Namespace: DevExpress.Xpf.Map

    Assembly: DevExpress.Xpf.Map.v25.1.dll

    NuGet Package: DevExpress.Wpf.Map

    Declaration

    public void ZoomToFit(
        IEnumerable<MapItem> items,
        bool roundZoomLevel,
        double paddingFactor = 0.15
    )

    Parameters

    Name Type Description
    items IEnumerable<MapItem>

    Items that should be displayed in the map viewport.

    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 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 code zooms the map to display specified items:

    <dxm:MapControl x:Name="mapControl">
        <dxm:ImageLayer>
            <dxm:BingMapDataProvider BingKey="Insert your Bing Key here." 
                                     Kind="RoadGray"/>
        </dxm:ImageLayer>
        <dxm: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>
    
    private void OnWindowLoaded(object sender, RoutedEventArgs e) {
        mapControl.ZoomToFit(items: mapItemStorage.DisplayItems, roundZoomLevel: true, paddingFactor: 0.15);
    }
    
    See Also