Select to view content in your preferred language

ZoomToResolution

759
3
09-20-2011 05:10 AM
NigelAlford
Occasional Contributor
I'm trying to set the slider to zoom the map.  I'm trying to set the ZoomToResolution Method. Can anyone provide some insight. In the API reference the method is declared first, I'm stuck at this declaration and the specifc execution.  I'm thinking I should use the Slider private void "Value Changed"; in this method assign each pixel value to its corresponding slider value (0-22) Using a Switch. We have extra cached layers .

Any help would be much appreciated this is insanely frustrating

ARCGIS API:http://help.arcgis.com/en/webapi/silverlight/apiref/api_start.htm
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
In the API reference the method is declared first, I'm stuck at this declaration and the specifc execution.


What do you mean exactly?


I'm thinking I should use the Slider private void "Value Changed";


Couldn't you use the toolkit navigation control and customize it to your need? Or do you have very specific need?
0 Kudos
HugoCardenas
Emerging Contributor
I have gotten the "ZoomToResolution" method to work not with a slider, but as the user clicks a point or the user clicks a row in a "FeatureDataGrid".  This is how I do it:

I use Bing Maps as a background; and it is Bing Maps resolution that guides all the values below.

1. I had to find out the map minimun resolution; mine is 0.0988998672921598.  The Bing map for my region does not show any thing below this number.  So there is not point allowing the user to zoom beyond this resolution.  Your minimun map resolution may be higher or smaller, depending on the quality of your data.

2. Next, I determined what my optimun zoom resolution would be.  Mine is 2.09612619755423.  When the user clicks a point on the map or a row on the "FeatureDataGrid", I check if the current map resolution is less than my optimun resolution:

// XAML
<esri:FeatureDataGrid  x:Name="MyDataGrid"SelectionChanged="MyDataGrid_SelectionChanged" />

// Event handler for FeatureDataGrid SelectionChanged
private void MyDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs args)
{

// Retrieve current selected point from map or from FeatureDataGrid
IEnumerable<Graphic> myGraphics = MyDataGrid.SelectedGraphics;
Graphic graphic = myGraphics.Last<Graphic>();

// Create a point
MapPoint pt = new MapPoint(graphic.Geometry.Extent.XMin, graphic.Geometry.Extent.YMin);

// Set zoom resolution parameters
double zoomResolution = 2.09612619755423; // this is read-only property in my application
int mapResolution = Convert.ToInt32(MyMap.Resolution);
int zoomResolution = Convert.ToInt32(zoomResolution);

// Zoom to my optimun map resolution, if current map's resolution is higher
if (mapResolution > zoomResolution) MyMap.ZoomToResolution(ZoomResolution, pt);

// Is point inside envelope / map extent? It is, do not pan.
// The global field "currentEnvelope" is set at the map extent changed event:
// _currentEnvelope = e.NewExtent;

if (pt.Extent.Intersects(_currentEnvelope)) return;


/* The point falls outside the map viewable window.
* Pan to it preserving the current map zoom extent.
*/

Envelope env = new Envelope(pt.X - ZoomXRadius, pt.Y - ZoomYRadius, pt.X + ZoomXRadius, pt.Y + ZoomYRadius);

  // Do pan to the point
  MyMap.PanTo(env);
}

The properties ZoomXRadius and ZoomXRadius are read-only.  These are set at the constructor.  These hold the actual meter distance from the center of the optimun zoom resolution (envelope) of step 2.  In my case, ZoomXRadius =1750 meters and ZoomXRadius = 950 meters.

In my case, I need to use "MyMap.PanTo" as well, for I want the map to display the selected point at the optimun zoom resolution.

Hope it helps.

Hugo.
0 Kudos
NigelAlford
Occasional Contributor
Dominique- I'm using those controls for the button functionality and they work great. But yes this is specific, I'm building an in-house silverlight SDK. The "Value Changed" is the on click event associated with slider.  The "Value" in this case ranges from 0-22 depending on the slider position on its line.

Hugo- I'll try to adapt your method, because the map is constantly being panned the specified Map point has be to flexible. Thanks I'll let reply back with the verdict on your method.
0 Kudos