ArcGIS API for WPF - Library Reference
Extent Property
See Also  Example Send comments on this topic
ESRI.ArcGIS.Client Namespace > Map Class : Extent Property

Get or set the extent that layers are viewed at in the Map Control.

Syntax

Visual Basic (Declaration) 
Public Property Extent As Envelope
C# 
public Envelope Extent {get; set;}

Example

XAMLCopy Code
<Grid x:Name="LayoutRoot" Background="White">
  
  <!--
  Add an ArcGISTiledMapsServiceLayer to the Map.
  Set the initial Extent of the Map (Continental US).
  -->
  <esri:Map Name="Map1" Height="300" Width="300" HorizontalAlignment="Left" VerticalAlignment="Top"
        Extent="-130,5,-70,65">
    <esri:ArcGISTiledMapServiceLayer Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
  </esri:Map>
  
  <!--
  Display the Map's Extent Properties in TextBlocks.
  -->
  <TextBlock Name="TextBlock_XMin" Height="23" HorizontalAlignment="Left" Margin="306,42,0,0"  
             Text="{Binding ElementName=Map1, Path=Extent.XMin}" VerticalAlignment="Top" />
  <TextBlock Name="TextBlock_YMin" Height="23" HorizontalAlignment="Left" Margin="306,63,0,0"  
             Text="{Binding ElementName=Map1, Path=Extent.YMin}" VerticalAlignment="Top" />
  <TextBlock Name="TextBlock_XMax" Height="23" HorizontalAlignment="Left" Margin="306,83,0,0"  
             Text="{Binding ElementName=Map1, Path=Extent.XMax}" VerticalAlignment="Top" />
  <TextBlock Name="TextBlock_YMax" Height="23" HorizontalAlignment="Left" Margin="306,101,0,0"  
             Text="{Binding ElementName=Map1, Path=Extent.YMax}" VerticalAlignment="Top" />
 </Grid>
C#Copy Code
// A Map Control (named myMap) was previously added in to the project either in XAML or code-behind.
            
public void SetExtent(ESRI.ArcGIS.Client.Map myMap)
{
  
  // Clear out any existing layers.
  myMap.Layers.Clear();
  
  // Add an ArcGISTiledMapsServiceLayer to the Map.
  ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer myArcGISTiledMapServiceLayer = new ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer();
  myArcGISTiledMapServiceLayer.Url = "http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer";
  myMap.Layers.Add(myArcGISTiledMapServiceLayer);
  
  // Set the initial Extent of the Map (Continental US).
  ESRI.ArcGIS.Client.Geometry.Envelope myEnvelope = new ESRI.ArcGIS.Client.Geometry.Envelope();
  myEnvelope.XMin = -130;
  myEnvelope.YMin = 5;
  myEnvelope.XMax = -70;
  myEnvelope.YMax = 65;
  myMap.Extent = myEnvelope;
  
}
  
public void GetExtent(ESRI.ArcGIS.Client.Map mymap)
{
  
  // Extent (Read/Write)
  // Returns Nothing/null if no layers added to Map.
  ESRI.ArcGIS.Client.Geometry.Envelope myEnvelope = new ESRI.ArcGIS.Client.Geometry.Envelope();
  myEnvelope = mymap.Extent;
  
  // Return the Map.Extent in a MessageBox
  string myString = null;
  if (myEnvelope != null)
  {
      myString = "The Map.Extent is:" + System.Environment.NewLine + "XMin: " + mymap.Extent.XMin.ToString() + System.Environment.NewLine + "YMin: " + mymap.Extent.YMin.ToString() + System.Environment.NewLine + "XMax: " + mymap.Extent.XMax.ToString() + System.Environment.NewLine + "YMax:" + mymap.Extent.YMax.ToString();
  }
  else
  {
      myString = "No Map.Extent set.";
  }
  System.Windows.MessageBox.Show(myString);
}
VB.NETCopy Code
' A Map Control (named myMap) was previously added in to the project either in XAML or code-behind.
            
Public Sub SetExtent(ByVal myMap As ESRI.ArcGIS.Client.Map)
  
  ' Clear out any existing layers.
  myMap.Layers.Clear()
  
  ' Add an ArcGISTiledMapsServiceLayer to the Map.
  Dim myArcGISTiledMapServiceLayer As New ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer
  myArcGISTiledMapServiceLayer.Url = "http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"
  myMap.Layers.Add(myArcGISTiledMapServiceLayer)
  
  ' Set the initial Extent of the Map (Continental US).
  Dim myEnvelope As New ESRI.ArcGIS.Client.Geometry.Envelope
  myEnvelope.XMin = -130
  myEnvelope.YMin = 5
  myEnvelope.XMax = -70
  myEnvelope.YMax = 65
  myMap.Extent = myEnvelope
  
End Sub
  
Public Sub GetExtent(ByVal mymap As ESRI.ArcGIS.Client.Map)
  
  ' Extent (Read/Write)
  ' Returns Nothing/null if no layers added to Map.
  Dim myEnvelope As New ESRI.ArcGIS.Client.Geometry.Envelope
  myEnvelope = mymap.Extent
  
  ' Return the Map.Extent in a MessageBox
  Dim myString As String = Nothing
  If myEnvelope IsNot Nothing Then
      myString = "The Map.Extent is:" + vbCrLf + _
      "XMin: " + mymap.Extent.XMin.ToString + vbCrLf + _
      "YMin: " + mymap.Extent.YMin.ToString + vbCrLf + _
      "XMax: " + mymap.Extent.XMax.ToString + vbCrLf + _
      "YMax:" + mymap.Extent.YMax.ToString
  Else
      myString = "No Map.Extent set."
  End If
  System.Windows.MessageBox.Show(mystring)
End Sub

Remarks

If no layer has been added to the Map then the Extent will be Nothing/null.

The order of the parameters in the string for the Map.Extent of XAML is: "XMin, YMin, XMax, YMax". In the following XAML code fragment the Envelope properties for setting the Extent are XMin=-130, YMin=5, XMax=-70, YMax=65:

<esri:Map Name="Map1" Extent="-130,5,-70,65" />

When setting the Extent Property prior to the adding layers to the Map, you can specify an Envelope as the Extent. However, after the Map has loaded, the Map.SpatialReference must match the Envelope.SpatialReference. To see a code example of how to set the SpatialReference of a Map by setting the Map.Extent Property see the Map.SpatialReference documentation.

To automatically preserve the Extent of the Map as the size of the Map Control changes (for instance: resizing the browser window and having the Map Control adjust it size accordingly) consider using the Client.Behaviors.MaintainExtentBehavior Class.

To see a practical example of using the getter for the Extent Property to zoom in and center the layers in a Map based upon a user click of the mouse, see the ZoomToResolution(Double, MapPoint) Method.

An example using the Extent of a Layer to adjust the Map.Extent can be found by in the Map.ZoomTo Method documentation.

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© ESRI, Inc. All Rights Reserved.