Jennifer and Morton,Thanks for the reply. O.K. I'm sorry for my ignorance but I'm still having the same issue. How do assign "p" to the queried/selected graphics?I now understand I should use this code:
Envelope env = new Envelope(p.X - 500, p.Y - 500, p.X + 500, p.Y + 500);
Map.ZoomTo(env);
But what do I set the variable "p" to and how? I've tried to define "p" as:
ESRI.ArcGIS.Client.Geometry.MapPoint p = AGraphicslayer;
or
ESRI.ArcGIS.Client.Geometry.MapPoint p = feature;
But I can't convert MapPoint to Graphic or feature so if this is my attribute selection code and the one graphic that is being selected based on the users query is what I want to zoom to then how do set the graphic to the MapPoint "p"
private void ExcuteMS4Query_Click(object sender, RoutedEventArgs e)
{
//Define query task and when query is sucessful fire off AQueryTask_ExecuteCompleted
QueryTask queryTask = new QueryTask("http://arcgisserver10/ArcGIS/rest/services/MS4/MapServer/0");
queryTask.ExecuteCompleted += MS4QueryTask_ExecuteCompleted;
queryTask.Failed += MS4QueryTask_Failed;
GraphicsLayer selectionGraphicslayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;
selectionGraphicslayer.ClearGraphics();
Query query = new ESRI.ArcGIS.Client.Tasks.Query();
query.Where = string.Format("OBJECTID = '{0}'", FindMS4.Text);
query.OutFields.Add("*");
query.Text = FindMS4.Text;
//If query is sucessful fire off AQueryTask_ExecuteCompleted
queryTask.ExecuteAsync(query);
}
private void MS4QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
{
FeatureSet featureSet = args.FeatureSet;
GraphicsLayer AGraphicslayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;
if (featureSet != null && featureSet.Features.Count > 0)
foreach (Graphic feature in featureSet.Features)
{
// Hightlight selected feature
feature.Symbol = LayoutRoot.Resources["ResultsMarkerSymbol"] as SimpleMarkerSymbol;
AGraphicslayer.Graphics.Insert(0, feature);
// Zoom to selected feature (define expand percentage)
//This zoom to selected feature doesn't work for points so I will comment
//it out at a later date after I figure out new zoom point protocal
ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = feature.Geometry.Extent;
double expandPercentage = 30;
double widthExpand = selectedFeatureExtent.Width * (expandPercentage / 100);
double heightExpand = selectedFeatureExtent.Height * (expandPercentage / 100);
ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(
selectedFeatureExtent.XMin - (widthExpand / 2),
selectedFeatureExtent.YMin - (heightExpand / 2),
selectedFeatureExtent.XMax + (widthExpand / 2),
selectedFeatureExtent.YMax + (heightExpand / 2));
Map.ZoomTo(displayExtent);
// Map.ZoomToResolution(Map.Resolution / 2, );
// ResultsDisplay.Visibility = Visibility.Visible;
ResultsDisplay.IsExpanded = true;
}
_drawSurface.IsEnabled = false;
}
private void MS4QueryTask_Failed(object sender, TaskFailedEventArgs args)
{
MessageBox.Show("Query failed: " + args.Error);
}
Thanks a bunch.