<Button Style="{StaticResource MenuItem}"
Content="Zoom To" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<esri:ZoomToAction
TargetName="MyMap">
<esri:ZoomToAction.Geometry>
<esri:Envelope XMin="-110" YMin="40" XMax="-100" YMax="50" />
</esri:ZoomToAction.Geometry>
</esri:ZoomToAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
MapPoint myPoint = new MapPoint(x, y, spatialRef); MyMap.ZoomTo(myPoint);
Envelope env = new Envelope(p.X - 500, p.Y - 500, p.X + 500, p.Y + 500); MyMap.ZoomTo(env);
The above code only zoom "around" that point (meaning that's the point that will stay at the same place on the screen, similar to a double-click zoom where the point you clicked stays at the same position).
I'm guessing you want to the point centered on the screen?
As you found out, you cannot zoom to a point, since a point has an infinitely small extent. The map simply doesn't know how far in you want to zoom. If the point represents an address, you probably want to zoom further in than if the point represents a city.
You can zoom to a point by constructing an extent around the point. ie.Envelope env = new Envelope(p.X - 500, p.Y - 500, p.X + 500, p.Y + 500); MyMap.ZoomTo(env);
In this example if the map units are meters, it would zoom to a 1kmx1km box centered on the point 'p'. Based on your map units and the scale you want to zoom to, you probably want to use a different number.
Alternatively you can just pan to the point: Ie: MyMap.PanTo(p);
I used the points from a FINDTASk - but couldn't make it work. here are the codes, Any suggestions would be appreciated!
FindResult findResult = (FindResult)FindDetailsDataGrid.SelectedItem;
Graphic graphic = findResult.Feature;
ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(graphic.Geometry.Extent.XMin, graphic.Geometry.Extent.YMin, graphic.Geometry.Extent.XMax, graphic.Geometry.Extent.YMax);
MyMap.ZoomTo(selectedFeatureExtent);
private void centerAndZoom(ESRI.ArcGIS.Client.Map map, ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint, double resolution)
{
double ratio = 1.0;
if (map.Resolution != 0.0)
ratio = resolution / map.Resolution;
if (ratio == 1.0)
map.PanTo(mapPoint);
else
{
ESRI.ArcGIS.Client.Geometry.MapPoint mapCenter = map.Extent.GetCenter();
double X = (mapPoint.X - ratio * mapCenter.X) / (1 - ratio);
double Y = (mapPoint.Y - ratio * mapCenter.Y) / (1 - ratio);
map.ZoomToResolution(resolution, new ESRI.ArcGIS.Client.Geometry.MapPoint(X, Y));
}
}
centerAndZoom(MyMap, pt, MyMap.MinimumResolution * 4);
You might also be interested by a centerAndZoom function:
private void centerAndZoom(ESRI.ArcGIS.Client.Map map, ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint, double resolution) { double ratio = 1.0; if (map.Resolution != 0.0) ratio = resolution / map.Resolution; if (ratio == 1.0) map.PanTo(mapPoint); else { ESRI.ArcGIS.Client.Geometry.MapPoint mapCenter = map.Extent.GetCenter(); double X = (mapPoint.X - ratio * mapCenter.X) / (1 - ratio); double Y = (mapPoint.Y - ratio * mapCenter.Y) / (1 - ratio); map.ZoomToResolution(resolution, new ESRI.ArcGIS.Client.Geometry.MapPoint(X, Y)); } }
You can use it to center on a point and zoom to a given resolution.
For examplecenterAndZoom(MyMap, pt, MyMap.MinimumResolution * 4);