Back to Devexpress

MapControl.ZoomToFit(IEnumerable<MapItem>, Double) Method

wpf-devexpress-dot-xpf-dot-map-dot-mapcontrol-dot-zoomtofit-x28-system-dot-collections-dot-generic-dot-ienumerable-devexpress-dot-xpf-dot-map-dot-mapitem-system-dot-double-x29.md

latest4.3 KB
Original Source

MapControl.ZoomToFit(IEnumerable<MapItem>, Double) Method

Zooms a map to fit the area containing items sent as a parameter.

Namespace : DevExpress.Xpf.Map

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

NuGet Package : DevExpress.Wpf.Map

Declaration

csharp
public void ZoomToFit(
    IEnumerable<MapItem> items,
    double paddingFactor = 0.15
)
vb
Public Sub ZoomToFit(
    items As IEnumerable(Of MapItem),
    paddingFactor As Double = 0.15
)

Parameters

NameTypeDescription
itemsIEnumerable<MapItem>

A set of MapItem descendant objects that should be visible on a map after zooming.

|

Optional Parameters

NameTypeDefaultDescription
paddingFactorDouble0.15

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

|

Remarks

This method works as follows.

  • Calculates a bounding box around map items.

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

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

In the instance of the following code

xaml
<dxm:MapControl x:Name="map">
    <dxm:VectorLayer DataLoaded="VectorLayer_DataLoaded">
        <dxm:MapItemStorage x:Name="storage">
            <!--...-->
        </dxm:MapItemStorage>
    </dxm:VectorLayer>
</dxm:MapControl>
csharp
private void VectorLayer_DataLoaded(object sender, DataLoadedEventArgs e) {
    map.ZoomToFit(storage.Items, 0.3);
}
vb
Private Sub VectorLayer_DataLoaded(ByVal sender As Object, ByVal e As DataLoadedEventArgs)
    map.ZoomToFit(storage.Items, 0.3)
End Sub

the result should look like the following.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ZoomToFit(IEnumerable<MapItem>, Double) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-map-search-with-azure-map-search-service/CS/DXMapExample/MainWindow.xaml.cs#L41

csharp
private void OnLayerItemsGenerating(object sender, LayerItemsGeneratingEventArgs args) {
    mapControl.ZoomToFit(args.Items, 0.4);
}

wpf-map-search-with-azure-map-search-service/VB/DXMapExample/MainWindow.xaml.vb#L44

vb
Private Sub OnLayerItemsGenerating(ByVal sender As Object, ByVal args As LayerItemsGeneratingEventArgs)
    Me.mapControl.ZoomToFit(args.Items, 0.4)
End Sub

See Also

MapControl Class

MapControl Members

DevExpress.Xpf.Map Namespace