Back to Devexpress

MapControl.ZoomToFitLayerItems(IEnumerable<LayerBase>, Double) Method

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

latest4.3 KB
Original Source

MapControl.ZoomToFitLayerItems(IEnumerable<LayerBase>, Double) Method

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

Declaration

csharp
public void ZoomToFitLayerItems(
    IEnumerable<LayerBase> layers,
    double paddingFactor = 0.15
)
vb
Public Sub ZoomToFitLayerItems(
    layers As IEnumerable(Of LayerBase),
    paddingFactor As Double = 0.15
)

Parameters

NameTypeDescription
layersIEnumerable<LayerBase>

A IEnumerable object, containing LayerBase class descendant objects.

|

Optional Parameters

NameTypeDefaultDescription
paddingFactorDouble0.15

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

|

Remarks

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:

csharp
map.ZoomToFit(new LayerBase[] {vectorLayer}, 0.3);
vb
map.ZoomToFit(New LayerBase() {vectorLayer}, 0.3)

you will produce a map that looks like this:

Example

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.

xaml
<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:

csharp
private void VectorLayer_DataLoaded(object sender, DataLoadedEventArgs e) {
    mapControl.ZoomToFitLayerItems(new LayerBase[] { layer1, layer2 }, 0.3);            
}
vb
Private Sub VectorLayer_DataLoaded(ByVal sender As Object, ByVal e As DataLoadedEventArgs)
    mapControl.ZoomToFitLayerItems(New LayerBase() {layer1, layer2}, 0.3)
End Sub

See Also

MapControl Class

MapControl Members

DevExpress.Xpf.Map Namespace