Back to Devexpress

MapControl.ZoomToFitLayerItems(Double) Method

wpf-devexpress-dot-xpf-dot-map-dot-mapcontrol-dot-zoomtofitlayeritems-x28-system-dot-double-x29.md

latest4.2 KB
Original Source

MapControl.ZoomToFitLayerItems(Double) Method

Zooms a map to fit items contained in all layers of the map.

Namespace : DevExpress.Xpf.Map

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

NuGet Package : DevExpress.Wpf.Map

Declaration

csharp
public void ZoomToFitLayerItems(
    double paddingFactor = 0.15
)
vb
Public Sub ZoomToFitLayerItems(
    paddingFactor As Double = 0.15
)

Optional Parameters

NameTypeDefaultDescription
paddingFactorDouble0.15

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

|

Remarks

The ZoomToFitLayerItems method works as follows:

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

  • Zooms the map to fit the box.

The following image shows a map with the padding factor parameter set at 0.3:

csharp
map.ZoomToFitLayerItems(0.3);
vb
map.ZoomToFitLayerItems(0.3)

Example

To zoom in a map at application launch, call the ZoomToFitLayerItems method in the LayerBase.DataLoaded event handler:

xaml
<dxm:VectorLayer x:Name="layer1" DataLoaded="VectorLayer_DataLoaded">
    <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>

The DataLoaded event’s handler:

csharp
private void VectorLayer_DataLoaded(object sender, DataLoadedEventArgs e) {
    mapControl.ZoomToFitLayerItems(0.3);            
}
vb
Private Sub VectorLayer_DataLoaded(ByVal sender As Object, ByVal e As DataLoadedEventArgs)
    mapControl.ZoomToFitLayerItems(0.3)
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ZoomToFitLayerItems(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.

map-wpf-manually-load-a-cartesian-map-shapefile/CS/BuildInCoordinateConverters/MainWindow.xaml.cs#L12

csharp
private void Button_Click(object sender, RoutedEventArgs e) {
    map.ZoomToFitLayerItems(0.4);
}

map-wpf-manually-load-a-cartesian-map-shapefile/VB/BuildInCoordinateConverters/MainWindow.xaml.vb#L15

vb
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Me.map.ZoomToFitLayerItems(0.4)
End Sub

See Also

MapControl Class

MapControl Members

DevExpress.Xpf.Map Namespace