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
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
public void ZoomToFit(
IEnumerable<MapItem> items,
double paddingFactor = 0.15
)
Public Sub ZoomToFit(
items As IEnumerable(Of MapItem),
paddingFactor As Double = 0.15
)
| Name | Type | Description |
|---|---|---|
| items | IEnumerable<MapItem> |
A set of MapItem descendant objects that should be visible on a map after zooming.
|
| Name | Type | Default | Description |
|---|---|---|---|
| paddingFactor | Double | 0.15 |
A Double object, which tunes the border size around visible map items.
|
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
<dxm:MapControl x:Name="map">
<dxm:VectorLayer DataLoaded="VectorLayer_DataLoaded">
<dxm:MapItemStorage x:Name="storage">
<!--...-->
</dxm:MapItemStorage>
</dxm:VectorLayer>
</dxm:MapControl>
private void VectorLayer_DataLoaded(object sender, DataLoadedEventArgs e) {
map.ZoomToFit(storage.Items, 0.3);
}
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
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
Private Sub OnLayerItemsGenerating(ByVal sender As Object, ByVal args As LayerItemsGeneratingEventArgs)
Me.mapControl.ZoomToFit(args.Items, 0.4)
End Sub
See Also