Back to Devexpress

MapControl.ZoomToFit(IEnumerable<MapItem>, Boolean, 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-boolean-system-dot-double-x29.md

latest3.8 KB
Original Source

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

Zooms the map based on a specified padding factor to allow the map viewport to display all items passed in parameters. Allows you to set whether the map should use a non-negative integer zoom level.

Namespace : DevExpress.Xpf.Map

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

NuGet Package : DevExpress.Wpf.Map

Declaration

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

Parameters

NameTypeDescription
itemsIEnumerable<MapItem>

Items that should be displayed in the map viewport.

| | roundZoomLevel | Boolean |

Specifies whether to round the zoom level value.

|

Optional Parameters

NameTypeDefaultDescription
paddingFactorDouble0.15

Specifies the size of the border around displayed map items.

|

Remarks

The padding factor is applied to the larger dimension of the bounding box that contains visible items.

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

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

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

The following code zooms the map to display specified items:

xaml
<dxm:MapControl x:Name="mapControl">
    <dxm:ImageLayer>
        <dxm:BingMapDataProvider BingKey="Insert your Bing Key here." 
                                 Kind="RoadGray"/>
    </dxm:ImageLayer>
    <dxm:VectorLayer>
        <dxm:MapItemStorage x:Name="mapItemStorage">
            <dxm:MapDot Location="51.30, 0.07" Size="20" Fill="Wheat"/>
            <dxm:MapDot Location="52.31, 13.23" Size="20" Fill="Gold"/>
            <dxm:MapDot Location="48.51, 2.21" Size="20" Fill="CadetBlue"/>
            <dxm:MapDot Location="41.54, 12.3" Size="20" Fill="Red"/>
            <dxm:MapDot Location="40.23, -3.43" Size="20" Fill="Green"/>
        </dxm:MapItemStorage>
    </dxm:VectorLayer>
</dxm:MapControl>
csharp
private void OnWindowLoaded(object sender, RoutedEventArgs e) {
    mapControl.ZoomToFit(items: mapItemStorage.DisplayItems, roundZoomLevel: true, paddingFactor: 0.15);
}
vb
Private Sub OnWindowLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
    mapControl.ZoomToFit(items:=mapItemStorage.DisplayItems, roundZoomLevel:=True, paddingFactor:=0.15)
End Sub

See Also

MapControl Class

MapControl Members

DevExpress.Xpf.Map Namespace