Skip to main content
A newer version of this page is available. .

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

Zooms a map to fit items contained in the specified set of LayerBase class descendant objects.

Namespace: DevExpress.Xpf.Map

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

NuGet Package: DevExpress.Wpf.Map

Declaration

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

Parameters

Name Type Description
layers IEnumerable<LayerBase>

A IEnumerable object, containing LayerBase class descendant objects.

Optional Parameters

Name Type Default Description
paddingFactor Double 0.15

A Double value, which tunes the border size around visible map items.

Remarks

This method works as follows.

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

    WpfMapControl_ZoomToFit_BoundingBox

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

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

    WpfMapControl_ZoomToFit_HorizontalFitting

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

    WpfMapControl_ZoomToFit_VerticalFitting

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

In using this code:

map.ZoomToFit(new LayerBase[] {vectorLayer}, 0.3);

you will produce a map that looks like this:

WpfMapControl_ZoomToFit_NumericExample

Example

To zoom a map at application launch, call the ZoomToFitLayerItems method in the LayerBase.DataLoaded event handler. If you pass multiple vector layers to the ZoomToFitLayerItems method parameters, handle the DataLoaded event of the vector layer that is added to the MapControl.Layers collection last.

<dxm:MapControl>
  <dxm:VectorLayer x:Name="layer1">
      <dxm:MapItemStorage>
          <dxm:MapRectangle Height="21" Width="30">
              <dxm:MapRectangle.Location>
                  <dxm:GeoPoint Longitude="41.3" Latitude="-54.5"/>
              </dxm:MapRectangle.Location>
          </dxm:MapRectangle>
      </dxm:MapItemStorage>
  </dxm:VectorLayer>
  <dxm:VectorLayer x:Name="layer2" 
                  DataLoaded="VectorLayer_DataLoaded">
      <dxm:MapItemStorage>
          <dxm:MapEllipse Width="20" Height="15">
              <dxm:MapEllipse.Location>
                  <dxm:GeoPoint Longitude="43" Latitude="-57"/>
              </dxm:MapEllipse.Location>
          </dxm:MapEllipse>
      </dxm:MapItemStorage>
  </dxm:VectorLayer>
</dxm:MapControl>

The DataLoaded event’s handler:

private void VectorLayer_DataLoaded(object sender, DataLoadedEventArgs e) {
    mapControl.ZoomToFitLayerItems(new LayerBase[] { layer1, layer2 }, 0.3);            
}
See Also