Visual Basic (Declaration) | |
---|---|
Public Overloads Sub ZoomToResolution( _ ByVal resolution As Double, _ ByVal center As MapPoint _ ) |
C# | |
---|---|
public void ZoomToResolution( double resolution, MapPoint center ) |
Resolution is defined as the number of map units per pixel.
The following screen shot demonstrates the result of clicking on the Map Control (directly over Spain) with the mouse while simultaneously holding down the Alt key to zoom in and re-center the layers. The screen shot matches the code example in this document.
Note: Using Methods are only available in code-behind. You cannot use a Method via XAML.
Parameters
- resolution
- The pixel resolution to zoom to.
- center
- The center to zoom around.
C# | ![]() |
---|---|
// This example demonstrates how to zoom in and center the map when the user clicks the mouse with the Alt key // being depressed at the same time. The map zooms in by a factor of 10 from its current map resolution. public MainPage() { InitializeComponent(); this.Loaded += new RoutedEventHandler(MainPage_Loaded); Map1.MouseClick +=new EventHandler<ESRI.ArcGIS.Client.Map.MouseEventArgs>(Map1_MouseClick); } void MainPage_Loaded(object sender, RoutedEventArgs e) { // Clear out any existing layers. Map1.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"; Map1.Layers.Add(myArcGISTiledMapServiceLayer); } 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; // Call the CenterAndZoom function which performs the work. // e.MapPoint is where the user clicked on the map. // currentResolution * 0.1 means to zoom in by a factor of 10 (the inverse of 10 is 0.1). CenterAndZoom(Map1, e.MapPoint, currentResolution * 0.1); } } private void CenterAndZoom(ESRI.ArcGIS.Client.Map myMap, ESRI.ArcGIS.Client.Geometry.MapPoint myMapPoint, double myResolution) { // Set a default value to determine whether to 'zoom and center' or just pan. double ratio = 1.0; // Ensure that we only have a map with a non-zero Resolution in order to calculate a new ratio for re-centering. if (myMap.Resolution != 0.0) { // Create the ratio used to re-center the map ratio = myResolution / myMap.Resolution; } if (ratio == 1.0) { // Just perform a pan without zooming in. myMap.PanTo(myMapPoint); } else { // Get the current extent of the map. ESRI.ArcGIS.Client.Geometry.Envelope myEnvelope = myMap.Extent; // Get the current center of the maps extent. ESRI.ArcGIS.Client.Geometry.MapPoint centerMapPoint = myEnvelope.GetCenter(); // Calculate the X,Y coordinates for the new map extent center. double X = (myMapPoint.X - ratio * centerMapPoint.X) / (1 - ratio); double Y = (myMapPoint.Y - ratio * centerMapPoint.Y) / (1 - ratio); ESRI.ArcGIS.Client.Geometry.MapPoint newMapPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(X, Y); // Zoom in and re-center the map. myMap.ZoomToResolution(myResolution, newMapPoint); } } |
VB.NET | ![]() |
---|---|
' This example demonstrates how to zoom in and center the map when the user clicks the mouse with the Alt key ' being depressed at the same time. The map zooms in by a factor of 10 from its current map resolution. Private Sub MainPage_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded ' Clear out any existing layers. Map1.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" Map1.Layers.Add(myArcGISTiledMapServiceLayer) End Sub 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 ' Call the CenterAndZoom function which performs the work. ' e.MapPoint is where the user clicked on the map. ' currentResolution * 0.1 means to zoom in by a factor of 10 (the inverse of 10 is 0.1). CenterAndZoom(Map1, e.MapPoint, currentResolution * 0.1) End If End Sub Private Sub CenterAndZoom(ByVal myMap As ESRI.ArcGIS.Client.Map, ByVal myMapPoint As ESRI.ArcGIS.Client.Geometry.MapPoint, ByVal myResolution As Double) ' Set a default value to determine whether to 'zoom and center' or just pan. Dim ratio As Double = 1.0 ' Ensure that we only have a map with a non-zero Resolution in order to calculate a new ratio for re-centering. If myMap.Resolution <> 0.0 Then ' Create the ratio used to re-center the map ratio = myResolution / myMap.Resolution End If If ratio = 1.0 Then ' Just perform a pan without zooming in. myMap.PanTo(myMapPoint) Else ' Get the current extent of the map. Dim myEnvelope As ESRI.ArcGIS.Client.Geometry.Envelope = myMap.Extent ' Get the current center of the maps extent. Dim centerMapPoint As ESRI.ArcGIS.Client.Geometry.MapPoint = myEnvelope.GetCenter() ' Calculate the X,Y coordinates for the new map extent center. Dim X As Double = (myMapPoint.X - ratio * centerMapPoint.X) / (1 - ratio) Dim Y As Double = (myMapPoint.Y - ratio * centerMapPoint.Y) / (1 - ratio) Dim newMapPoint As ESRI.ArcGIS.Client.Geometry.MapPoint = New ESRI.ArcGIS.Client.Geometry.MapPoint(X, Y) ' Zoom in and re-center the map. myMap.ZoomToResolution(myResolution, newMapPoint) End If End Sub |
Target Platforms:Windows Phone 7