Back to Devexpress

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

windowsforms-devexpress-dot-xtramap-dot-mapcontrol-dot-zoomtofit-x28-system-dot-collections-dot-generic-dot-ienumerable-devexpress-dot-xtramap-dot-mapitem-system-dot-double-x29.md

latest4.6 KB
Original Source

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

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

Namespace : DevExpress.XtraMap

Assembly : DevExpress.XtraMap.v25.2.dll

NuGet Package : DevExpress.Win.Map

Declaration

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

Parameters

NameTypeDescription
itemsIEnumerable<MapItem>

A IEnumerable object that contains MapItem descendant objects that should be visible on a map after it is zoomed.

| | paddingFactor | Double |

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

|

Remarks

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

The ZoomToFit method works as follows:

  • Calculates a bounding box around items.

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

Example

The following image shows a map with paddingFactor equal to 0.3:

csharp
map.ZoomToFit(mapItemStorage.Items, 0.3);
vb
map.ZoomToFit(mapItemStorage.Items, 0.3)

The following code snippets (auto-collected from DevExpress Examples) contain references 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.

winforms-map-get-geo-point-info-from-bing-geocode-service/CS/RequestLocationInformation/Form1.cs#L95

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

map-for-winforms-azure-geocoding/CS/AzureGeocoding/Form1.cs#L90

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

winforms-map-get-geo-point-info-from-bing-geocode-service/VB/RequestLocationInformation/Form1.vb#L102

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

map-for-winforms-azure-geocoding/VB/AzureGeocoding/Form1.vb#L99

vb
Private Sub OnLayerItemsGenerating(ByVal sender As Object, ByVal e As LayerItemsGeneratingEventArgs)
    mapControl1.ZoomToFit(e.Items, 0.4)
End Sub

See Also

MapControl Class

MapControl Members

DevExpress.XtraMap Namespace