Skip to main content
All docs
V25.2
  • MapControl.ZoomToFitLayerItems(IEnumerable<LayerBase>, Double, Boolean) Method

    Zooms the map to fit items contained in the layers passed in the method parameters.

    Namespace: DevExpress.XtraMap

    Assembly: DevExpress.XtraMap.v25.2.dll

    NuGet Package: DevExpress.Win.Map

    Declaration

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

    Parameters

    Name Type Description
    layers IEnumerable<LayerBase>

    Layers that contain items.

    paddingFactor Double

    Specifies the size of the border around displayed map items.

    roundZoomLevel Boolean

    Specifies whether to round the zoom level value.

    Remarks

    When vector items are loaded at runtime, the ZoomToFitLayerItems method should be called from LayerBase.DataLoaded event handler.

    The ZoomToFitLayerItems method works as follows:

    • Calculates a bounding box around items.

      ZoomToFit_DescribedRegion

    • Zooms the map to fit the box. Note that the padding factor is applied to the larger dimension of the box.

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

      ZoomToFit_ZoomedMap

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

      ZoomToFit_VerticalSizeZooming

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

    The following code snippet zooms a map to display items contained in the specified map layers:

    using DevExpress.XtraMap;
    
    private void OnVectorLayerDataLoaded(object sender, DataLoadedEventArgs e) {
        mapControl1.ZoomToFitLayerItems(layers: new LayerBase[] { vectorLayer }, paddingFactor: 0.3, roundZoomLevel: true);
    }
    
    See Also