I created a simple Silverlight page that replicated the issue for me. The service where I'm hitting the issue is not available online, but I've used one here that is and that uses WKT. The page has a map, two buttons and a checkbox. Each button zooms the map to a point/resolution. If the checkbox is off, it'll use the native ZoomToResolution; if on, it'll use the workaround method. This example didn't behave exactly as in my full application, in that Map.ZoomToResolution does change the extent, but it zooms to the wrong extent. If I successively click the two buttons, it'll progressively move the map to the northwest (vs. consistent zoom to the same location with the workaround).XAML:[HTML]<UserControl xmlns:esri="http://schemas.esri.com/arcgis/client/2009" x:Class="ZoomToResolutionTest.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <esri:Map x:Name="Map1" ExtentChanged="Map1_ExtentChanged"> <esri:ArcGISDynamicMapServiceLayer ID="base" Url="http://maps.cityofnovi.org/ArcGIS/rest/services/Publish/QuickSearchLayers/MapServer" /> </esri:Map> <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0" Background="WhiteSmoke"> <TextBlock Text="Map resolution: "/> <TextBlock x:Name="MapResText" /> <TextBlock x:Name="MapLocText" Margin="8,0,0,0" /> <Button x:Name="Zoom1" Content="Zoom (13350000, 360000)" Click="Zoom1_Click" Margin="10,0,0,0"/> <Button x:Name="Zoom2" Content="Zoom (13370000, 350000)" Click="Zoom2_Click" Margin="5,0,0,0"/> <CheckBox x:Name="UseAltCkBox" Content="Use workaround" Margin="5,0,0,0" /> </StackPanel> </Grid></UserControl>[/HTML]Code:using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client.Geometry;
using ESRI.ArcGIS.Client;
namespace ZoomToResolutionTest
{
public partial class MainPage : UserControl
{
double _startupRes;
public MainPage()
{
InitializeComponent();
Map1.Layers.LayersInitialized += new ESRI.ArcGIS.Client.LayerCollection.LayersInitializedHandler(Layers_LayersInitialized);
}
void Layers_LayersInitialized(object sender, EventArgs args)
{
_startupRes = Map1.Resolution;
}
private void Zoom1_Click(object sender, RoutedEventArgs e)
{
ZoomMap(13350000, 360000, _startupRes / 8);
}
private void Zoom2_Click(object sender, RoutedEventArgs e)
{
ZoomMap(13370000, 350000, _startupRes / 4);
}
private void ZoomMap(double x, double y, double resolution)
{
MapPoint pt = new MapPoint(x, y);
if (UseAltCkBox.IsChecked == true)
ZoomToResolution(Map1, resolution, pt);
else
Map1.ZoomToResolution(resolution, pt);
}
private void ZoomToResolution(Map map, double resolution, MapPoint center)
{
// Workaround for Map.ZoomToResolution
double halfWidth = resolution * map.ActualWidth / 2;
double halfHeight = resolution * map.ActualHeight / 2;
Envelope newExtent = new Envelope(center.X - halfWidth, center.Y - halfHeight,
center.X + halfWidth, center.Y + halfHeight);
map.ZoomTo(newExtent);
}
private void Map1_ExtentChanged(object sender, ExtentEventArgs e)
{
MapResText.Text = String.Format("{0:N0}", Map1.Resolution);
MapPoint centerPt = Map1.Extent.GetCenter();
MapLocText.Text = String.Format("Center X:{0:N0}, Y:{1:N0}", centerPt.X, centerPt.Y);
}
}
}