ArcGIS API for Silverlight - Library Reference
ZoomToResolution(Double,MapPoint) Method
See Also  Example Send comments on this topic
ESRI.ArcGIS.Client Namespace > Map Class > ZoomToResolution Method : ZoomToResolution(Double,MapPoint) Method

resolution
The pixel resolution of the Map.
center
The center to Map.
Zooms the Map Control to a specific pixel resolution.

Syntax

Visual Basic (Declaration) 
Public Overloads Sub ZoomToResolution( _
   ByVal resolution As Double, _
   ByVal center As MapPoint _
) 
C# 
public void ZoomToResolution( 
   double resolution,
   MapPoint center
)

Remarks

This version of the Map.ZoomToResolution Method takes two parameters: a Double and a MapPoint. When the Map.ZoomToResolution Method is called the Map zooms into the specified resolution (Double) expanded around the MapPoint so as to maintain the exact mouse cursor location relative to the pre and post Map images rendered.

Resolution is defined as the number of map units per pixel.

The standard Map navigation options of left mouse double-click and mouse-wheel zoom in internally make use of the Map.ZoomToResolution Method. The defining feature of these two navigation options is that the mouse cursor remains in the same location on the Map when the zoom in occurs. This means the user does not need to move the mouse cursor to accomplish a fluid motion of multiple zooms for each new Map.Extent change to keep the same location where the mouse cursor is located. As part of the internal algorithm of the Map.ZoomToResolution Method, the Map.Extent is automatically expanded to the inverse of the Map.ZoomFactor Property while maintaining the exact position of the MapPoint between the pre and post images directly where the mouse cursor action was initiated. Depending on the position of the MapPoint in relation to the bounding box of the Map Control will determine how the internal expansion algorithm works. As the user initiated MapPoint location is increased from the dead-center of the Map Control, the exaggeration of the expansion increases.

See the following image for a visual depiction of the expansion exaggeration effect in the automatic calculation of the Map.Extent as part of the Map.ZoomToResolution Method. In the left column, the red star is the MapPoint where the user either left mouse double-clicks or where the cursor was for the mouse-wheel zoom in (both actions call the Map.ZoomToResolution Method internally). The black rectangle, in the left column images, represents a 'zoom-in-factor' of 0.5 (the inverse of the default Map.ZoomFactor which equals 2). The red leading lines inside of the back rectangles represent the internal algorithm of the Map.ZoomToResolution Method which expands the Map.Extent around the MapPoint. Note how the exaggeration of the expansion increases as the MapPoint location moves from the dead-center of the Map Control. In the right column, the MapPoint location stays in the same location; it is the Map.ZoomToResolution internal algorithm which expands the Map.Extent around the MapPoint. Note how the black rectangle in the graphic in the left column exactly matches the Map.Extent shown in right column.

Demonstration of various expansion exaggeration effect that are part of the Map.ZoomToResolution Method.

One common use case that developers request is the ability to click on the Map Control and be able to zoom in by the defined inverse of the Map.ZoomFactor while automatically re-centering the returned image from ArcGIS Server in the Map Control. There are two functions that can accomplish this: the Map.ZoomToResolution and the Map.ZoomTo Methods. The example code in this document demonstrates both ways.

Note: Using Methods are only available in code-behind. You cannot use a Method directly via XAML.

Parameters

resolution
The pixel resolution of the Map.
center
The center to Map.

Example

How to use:

Click on the ZoomToResolution RadioButton and hold down the Alt key and click on the Map. It will zoom in and automatically re-center the image in the Map Control. Then click on the ZoomTo RadioButton and likewise hold down the Alt key and click on the Map. It will also zoom in and automatically re-center the image in the Map Control. Both functions provide equivalent end results.

The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.

The following images correspond to the code example in this page:

In this image the user clicks with the Alt + left mouse directly over Madrid, Spain. Note how using either the ZoomToResolution or ZoomTo RadioButtons produce the same zoom and re-center the image effect in the Map Control.

Demonstrating the example code of performing a zoom and re-center the image in the Map Control.

In this image a visual depiction is shown of how the functions differ in using the ZoomToResolution and ZoomTo RadioButtons. The red dots in the left column Map Controls represent where the user Alt + left mouse clicks over Mardid, Spain. The black rectangles in the left column Map Controls represents a 'zoom-in-factor' of 0.5 (the inverse of the default Map.ZoomFactor which equals 2) which will become the Map.Extent of the right column Map Control (note how the black rectangle in the graphic in the left column exactly matches the Map.Extent shown in right column). The red lines connecting the red dot and the black rectangle show how the algorithms differ in achieving the desired zoom and re-centering functionality. For the ZoomToResolution, the yellow dot is the center of the Map.Extent before the next image is created (it corresponds to the myCenterMapPoint variable in the code). Also for the ZoomToResolution, the blue dot is the derived (or calculated) offset MapPoint that is needed in order to generate an image that is centered in the Map Control at the user click point (the blue dot corresponds to the myNewMapPoint variable in the code).

Demonstrating the example code of performing a zoom and re-center the image in the Map Control.

XAMLCopy Code
<Grid x:Name="LayoutRoot" >
  
  <!-- 
  Add a Map control with an ArcGISTiledMapServiceLayer with a pre-defined Extent. The MouseClick
  Event has been wired-up for use with code-behind functionality. 
  -->
  <esri:Map Background="White" HorizontalAlignment="Left" Name="Map1" VerticalAlignment="Top" 
            Height="300" Width="300" Margin="55,114,0,0" MouseClick="Map1_MouseClick" 
            Extent="-6904231,-7526802,7317314,6432596">
    <esri:ArcGISTiledMapServiceLayer ID="MyLayer"
              Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
  </esri:Map>
  
  <!-- 
  Add two RadioButtons to demonstrate that the same functionality of zoom-in with automatic Map
  re-centering using both the ZoomToResolution and ZoomTo Methods.
  -->
  <RadioButton Content="ZoomToResolution" Height="16" HorizontalAlignment="Left" Margin="55,94,0,0" 
               Name="RadioButton_ZoomToResolution" VerticalAlignment="Top" />
  <RadioButton Content="ZoomTo" Height="16" HorizontalAlignment="Left" Margin="289,94,0,0" 
               Name="RadioButton_ZoomTo" VerticalAlignment="Top" />
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="79" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" 
             Width="585" TextWrapping="Wrap" Margin="2,9,0,0" 
             Text="Click on the ZoomToResolution RadioButton and hold down the Alt key and click on 
             the Map. It will zoom in and automatically re-center the image in the Map Control. Then 
             click on the ZoomTo RadioButton and likewise hold down the Alt key and click on the Map. 
             It will also zoom in and automatically re-center the image in the Map Control. Both
             functions provide equivalent end results." />
             
</Grid>
C#Copy Code
private void Map1_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
{
  // Get the ModifierKeys that are currently depressed (options include: None, Alt, 
  // Control, Shift, Windows, and Apple)
  ModifierKeys theKey = Keyboard.Modifiers;
  
  // Check to ensure that only the Alt key is being depressed.
  if (theKey == ModifierKeys.Alt)
  {
    // Get the current Map Resolution. 
    double currentResolution = Map1.Resolution;
    
    // Get the ZoomFactor of the Map. The default is 2.
    double myZoomFactor = Map1.ZoomFactor;
    
    // Calculate the ZoomIn Ratio. It is the inverse of the ZoomFactor (ex: 1 / 2 = 0.5).
    double myZoomInRatio = 1 / myZoomFactor;
    
    // Calculate the ZoomIn Resolution. The current Map.Resolution * ZoomIn Ratio.
    double myZoomInResolution = currentResolution * myZoomInRatio;
    
    if (RadioButton_ZoomToResolution.IsChecked == true)
    {
      // Use the ZoomToResolution Method to perform the zoom and center.
      CenterAndZoom_via_ZoomToResolution(Map1, e.MapPoint, myZoomInResolution);
    }
    else if (RadioButton_ZoomTo.IsChecked == true)
    {
      // Use the ZoomTo Methdod to perform the zoom and center.
      CenterAndZoom_via_ZoomTo(Map1, e.MapPoint, myZoomInResolution);
    }
  }
}
            
private void CenterAndZoom_via_ZoomTo(ESRI.ArcGIS.Client.Map myMap, ESRI.ArcGIS.Client.Geometry.MapPoint myMapPoint, double myResolution)
{
  // Calculate the bounding extents of the zoom centered on the users point click on the Map.
  double xMin = myMapPoint.X - (myMap.ActualWidth * myResolution * 0.5);
  double yMin = myMapPoint.Y - (myMap.ActualHeight * myResolution * 0.5);
  double xMax = myMapPoint.X + (myMap.ActualWidth * myResolution * 0.5);
  double yMax = myMapPoint.Y + (myMap.ActualHeight * myResolution * 0.5);
  
  // Construct an Envelope from the bounding extents.
  ESRI.ArcGIS.Client.Geometry.Envelope myEnvelope = new ESRI.ArcGIS.Client.Geometry.Envelope(xMin, yMin, xMax, yMax);
  
  // Adjust the Map.Extent using the ZoomTo Method. It will be centered where the user clicked.
  myMap.ZoomTo(myEnvelope);
}
            
private void CenterAndZoom_via_ZoomToResolution(ESRI.ArcGIS.Client.Map myMap, ESRI.ArcGIS.Client.Geometry.MapPoint myMapPoint, double myResolution)
{
  // Create the ratio used to re-center the map
  double myRatio = myResolution / myMap.Resolution;
  
  // Get the current extent of the Map before any zooming occurs.
  ESRI.ArcGIS.Client.Geometry.Envelope myEnvelope = myMap.Extent;
  
  // Get the current center of the Map extent before any zooming occurs.
  ESRI.ArcGIS.Client.Geometry.MapPoint myCenterMapPoint = myEnvelope.GetCenter();
  
  // Calculate the X,Y coordinates for the new Map extent center.
  double myX = (myMapPoint.X - (myRatio * myCenterMapPoint.X)) / (1 - myRatio);
  double myY = (myMapPoint.Y - (myRatio * myCenterMapPoint.Y)) / (1 - myRatio);
  ESRI.ArcGIS.Client.Geometry.MapPoint myNewMapPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(myX, myY);
  
  // The Map will re-center the map using the artifically calculated myNewMapPoint and expand
  // the extent using the calculated myResolution value.
  myMap.ZoomToResolution(myResolution, myNewMapPoint);
}
VB.NETCopy Code
Private Sub Map1_MouseClick(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Client.Map.MouseEventArgs) Handles Map1.MouseClick
  
  ' Get the ModifierKeys that are currently depressed (options include: None, Alt, 
  ' Control, Shift, Windows, and Apple)
  Dim theKey As ModifierKeys = Keyboard.Modifiers
  
  ' Check to ensure that only the Alt key is being depressed.
  If theKey = ModifierKeys.Alt Then
    
    ' Get the current Map Resolution. 
    Dim currentResolution As Double = Map1.Resolution
    
    ' Get the ZoomFactor of the Map. The default is 2.
    Dim myZoomFactor As Double = Map1.ZoomFactor
    
    ' Calculate the ZoomIn Ratio. It is the inverse of the ZoomFactor (ex: 1 / 2 = 0.5).
    Dim myZoomInRatio As Double = 1 / myZoomFactor
    
    ' Calculate the ZoomIn Resolution. The current Map.Resolution * ZoomIn Ratio.
    Dim myZoomInResolution As Double = currentResolution * myZoomInRatio
    
    If RadioButton_ZoomToResolution.IsChecked = True Then
      
      ' Use the ZoomToResolution Method to perform the zoom and center.
      CenterAndZoom_via_ZoomToResolution(Map1, e.MapPoint, myZoomInResolution)
    ElseIf RadioButton_ZoomTo.IsChecked = True Then
      
      ' Use the ZoomTo Methdod to perform the zoom and center.
      CenterAndZoom_via_ZoomTo(Map1, e.MapPoint, myZoomInResolution)
      
    End If
    
  End If
  
End Sub
            
Private Sub CenterAndZoom_via_ZoomTo(ByVal myMap As ESRI.ArcGIS.Client.Map, ByVal myMapPoint As ESRI.ArcGIS.Client.Geometry.MapPoint, ByVal myResolution As Double)
  
  ' Calculate the bounding extents of the zoom centered on the users point click on the Map.
  Dim xMin As Double = myMapPoint.X - (myMap.ActualWidth * myResolution * 0.5)
  Dim yMin As Double = myMapPoint.Y - (myMap.ActualHeight * myResolution * 0.5)
  Dim xMax As Double = myMapPoint.X + (myMap.ActualWidth * myResolution * 0.5)
  Dim yMax As Double = myMapPoint.Y + (myMap.ActualHeight * myResolution * 0.5)
  
  ' Construct an Envelope from the bounding extents.
  Dim myEnvelope As New ESRI.ArcGIS.Client.Geometry.Envelope(xMin, yMin, xMax, yMax)
  
  ' Adjust the Map.Extent using the ZoomTo Method. It will be centered where the user clicked.
  myMap.ZoomTo(myEnvelope)
  
End Sub
            
Private Sub CenterAndZoom_via_ZoomToResolution(ByVal myMap As ESRI.ArcGIS.Client.Map, ByVal myMapPoint As ESRI.ArcGIS.Client.Geometry.MapPoint, ByVal myResolution As Double)
  
  ' Create the ratio used to re-center the map
  Dim myRatio As Double = myResolution / myMap.Resolution
  
  ' Get the current extent of the Map before any zooming occurs.
  Dim myEnvelope As ESRI.ArcGIS.Client.Geometry.Envelope = myMap.Extent
  
  ' Get the current center of the Map extent before any zooming occurs.
  Dim myCenterMapPoint As ESRI.ArcGIS.Client.Geometry.MapPoint = myEnvelope.GetCenter()
  
  ' Calculate the X,Y coordinates for the new Map extent center.
  Dim myX As Double = (myMapPoint.X - (myRatio * myCenterMapPoint.X)) / (1 - myRatio)
  Dim myY As Double = (myMapPoint.Y - (myRatio * myCenterMapPoint.Y)) / (1 - myRatio)
  Dim myNewMapPoint As ESRI.ArcGIS.Client.Geometry.MapPoint = New ESRI.ArcGIS.Client.Geometry.MapPoint(myX, myY)
  
  ' The Map will re-center the map using the artifically calculated myNewMapPoint and expand
  ' the extent using the calculated myResolution value.
  myMap.ZoomToResolution(myResolution, myNewMapPoint)
  
End Sub

Requirements

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

See Also

© ESRI, Inc. All Rights Reserved.