I was wondering if someone could help me break the down the Identity Task. I have been looking at the interactive example of Identity task as well as the the example located in the concepts area. Neither of them really explain the process of the task itself. I have been trying, with very little luck, to use the identity task to be able to click on a facility on a map and return the facility id (FAC_ID) and display it in a textbox. The only thing that I have been able to get it to do is to return the facility's Short Name, which is a field associated with the map service. I am having major issues with trying to define and assign the facility ID field to the text property of a text box. Can anyone one type up a quick example of how to do this. I have to imagine that it is extremely easy to do but I am just getting started and still trying to wrap my head around everything.
private void MyMap_MouseClick(object sender, Map.MouseEventArgs args)
{
// Show an icon at the Identify location.
GraphicsLayer graphicsLayer = MyMap.Layers["IdentifyIconGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
{
Geometry = args.MapPoint,
Symbol = LayoutRoot.Resources["IdentifyLocationSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
};
graphicsLayer.Graphics.Add(graphic);
// Identify task initialization.
IdentifyTask identifyTask = new IdentifyTask("URL to my REST directory map server");
identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
identifyTask.Failed += IdentifyTask_Failed;
// Initialize Identify parameters. Specify search of all layers.
IdentifyParameters identifyParameters = new IdentifyParameters();
identifyParameters.LayerOption = LayerOption.all;
identifyParameters.SpatialReference = MyMap.SpatialReference;
// Pass the current Map properties to Identify parameters.
identifyParameters.MapExtent = MyMap.Extent;
identifyParameters.Width = (int)MyMap.ActualWidth;
identifyParameters.Height = (int)MyMap.ActualHeight;
// Identify features at the click point.
identifyParameters.Geometry = args.MapPoint;
identifyTask.ExecuteAsync(identifyParameters);
}
private List<IdentifyResult> _lastIdentifyResult;
// Populate Querytextbox with the value of FAC_ID when Identify is complete.
private void IdentifyTask_ExecuteCompleted(object sender, IdentifyEventArgs args)
{
QueryTextBox.Text = "";
if (args.IdentifyResults.Count > 0)
{
// Store the list of Identify results.
_lastIdentifyResult = args.IdentifyResults;
foreach (IdentifyResult result in args.IdentifyResults)
{
//This sort of works only instead of returning the primary key, FAC_ID, it returns the SHORT_Name of the facility instead
string FACID = string.Format("{0}", _lastIdentifyResult[0].Value);
QueryTextBox.Text = FACID;
//I have also tried the line below, but get a Error:"An object reference is required for the
//non-static field, method, or property 'ESRI.ArcGIS.Client.Tasks.IdentifyResult.Feature.get'"
//I pulled this from a project done in VB.net hoping that it might work, but it doesn't in C#
//It seems like a statement similar to this is all that I would need though
//QueryTextBox.Text = IdentifyResult.Feature.Attributes("FAC_ID");
}
}
}
Thanks in advance for help. I know there has to be a pretty simple fix to this.