wpf-devexpress-dot-xpf-dot-map-dot-mapcontrol-dot-zoomtofitlayeritems-x28-system-dot-collections-dot-generic-dot-ienumerable-devexpress-dot-xpf-dot-map-dot-layerbase-system-dot-double-x29.md
Zooms a map to fit items contained in the specified set of LayerBase class descendant objects.
Namespace : DevExpress.Xpf.Map
Assembly : DevExpress.Xpf.Map.v25.2.dll
NuGet Package : DevExpress.Wpf.Map
public void ZoomToFitLayerItems(
IEnumerable<LayerBase> layers,
double paddingFactor = 0.15
)
Public Sub ZoomToFitLayerItems(
layers As IEnumerable(Of LayerBase),
paddingFactor As Double = 0.15
)
| Name | Type | Description |
|---|---|---|
| layers | IEnumerable<LayerBase> |
A IEnumerable object, containing LayerBase class descendant objects.
|
| Name | Type | Default | Description |
|---|---|---|---|
| paddingFactor | Double | 0.15 |
A Double value, which tunes the border size around visible map items.
|
This method works as follows.
Calculates a bounding box around map items contained in specified layers.
Zooms the map to fit the box. Note that the padding factor is applied to the larger dimension of box.
Note that the padding factor is divided by two for each side of the region.
In using this code:
map.ZoomToFit(new LayerBase[] {vectorLayer}, 0.3);
map.ZoomToFit(New LayerBase() {vectorLayer}, 0.3)
you will produce a map that looks like this:
To zoom a map at application launch, call the ZoomToFitLayerItems method in the LayerBase.DataLoaded event handler. If you pass multiple vector layers to the ZoomToFitLayerItems method parameters, handle the DataLoaded event of the vector layer that is added to the MapControl.Layers collection last.
<dxm:MapControl>
<dxm:VectorLayer x:Name="layer1">
<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>
<dxm:VectorLayer x:Name="layer2"
DataLoaded="VectorLayer_DataLoaded">
<dxm:MapItemStorage>
<dxm:MapEllipse Width="20" Height="15">
<dxm:MapEllipse.Location>
<dxm:GeoPoint Longitude="43" Latitude="-57"/>
</dxm:MapEllipse.Location>
</dxm:MapEllipse>
</dxm:MapItemStorage>
</dxm:VectorLayer>
</dxm:MapControl>
The DataLoaded event’s handler:
private void VectorLayer_DataLoaded(object sender, DataLoadedEventArgs e) {
mapControl.ZoomToFitLayerItems(new LayerBase[] { layer1, layer2 }, 0.3);
}
Private Sub VectorLayer_DataLoaded(ByVal sender As Object, ByVal e As DataLoadedEventArgs)
mapControl.ZoomToFitLayerItems(New LayerBase() {layer1, layer2}, 0.3)
End Sub
See Also