public MainPage() { InitializeComponent(); FeatureLayer l = new FeatureLayer() { Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/MapServer/0" }; l.OutFields.Add("*"); l.Initialized += l_Initialized; l.Initialize(); } void l_UpdateCompleted(object sender, EventArgs e) { FeatureLayer l = sender as FeatureLayer; l.UpdateCompleted -= l_UpdateCompleted; var id = l.LayerInfo.ObjectIdField; int objId; foreach (var g in l.Graphics) objId = Convert.ToInt32(g.Attributes[id]); } void l_Initialized(object sender, System.EventArgs e) { FeatureLayer l = sender as FeatureLayer; l.Initialized -= l_Initialized; l.UpdateCompleted += l_UpdateCompleted; l.Update(); }
string alias; foreach(var f in l.LayerInfo.Fields) alias = f.Alias;
Jenn,
I got yours to work using the code below. It is retrieves the Realted records per individual feature. I was confused because I thought the RelationshipParameter.ObjectIDs was looking for a list of IDs. I was trying to set RelationshipParameter.ObjectIDs = FeatureSet.ObjectIDs but I think there is a conversion issue.
Many Thanks,
Derald
string objectIdFieldAlias = featureLayer.LayerInfo.Fields.Single(field => string.Equals(field.Name, featureLayer.LayerInfo.ObjectIdField)).Alias; foreach (var relationship in featureLayer.LayerInfo.Relationships) { var objectIds = e.IdentifyResults.Select(item => Convert.ToInt32(item.Feature.Attributes[objectIdFieldAlias])).ToList();
void ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e) { if (!e.Result.RelatedRecordsGroup.Any()) return; var existingResults = e.UserState as IEnumerable<IdentifyResult>; if (existingResults == null) return; // RelationshipResult pr = e.Result; foreach (var graphic in e.Result.RelatedRecordsGroup.Values.SelectMany(graphics => graphics)) { // TODO : get the existing result var existingResult = ?????? foreach(var attribute in graphic1.Attributes) { string key = attribute.Key; existingResult.Feature.Attributes.Add(string.Format("{0} (related)", e.Result.Fields.Single(field => string.Equals(field.Name, key)).Alias), attribute.Value); } } }
// more code here qt.ExecuteRelationshipQueryAsync(rp, incidentsLayer.Graphics); } private void qt_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e) { GraphicCollection graphics = e.UserState as GraphicCollection; // more code here }
private void ParcelSearch_TaskResultsDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { foreach (Graphic g in e.AddedItems) { g.Select(); if (g.Attributes["OBJECTID"] != null) { var id = g.Attributes["OBJECTID"]; PARCELIDPASS.Text = string.Format("The ParcelID passed is {0}", id); ParcelSearch_RelatedRecords(null, null, Convert.ToInt32(g.Attributes["OBJECTID"])); } break; } foreach (Graphic g in e.RemovedItems) g.UnSelect(); } private void ParcelSearch_RelatedRecords(object sender, RoutedEventArgs e, Int32 objectid) { // QueryTask initialization QueryTask ParcelSearch_Related = new QueryTask("{SERVER}/MapServer/79"); //82 ParcelSearch_Related.ExecuteRelationshipQueryCompleted += ParcelSearch_Related_ExecuteRelationshipQueryCompleted; ParcelSearch_Related.Failed += ParcelSearch_Related_Failed; //Relationship query RelationshipParameter relationshipParameters = new RelationshipParameter() { ObjectIds = new int[] { objectid }, OutFields = new string[] { "*" }, RelationshipId = 1, OutSpatialReference = MyMap.SpatialReference }; ParcelSearch_Related.ExecuteRelationshipQueryAsync(relationshipParameters); } private void ParcelSearch_Related_Failed(object sender, TaskFailedEventArgs args) { MessageBox.Show("ParcelSearch_Related Failed: " + args.Error); } void ParcelSearch_Related_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e) { RelationshipResult pr = e.Result; if (pr.RelatedRecordsGroup.Count == 0) { ParcelSearch_TaskResultsDataGrid2.ItemsSource = null; } else { foreach (var pair in pr.RelatedRecordsGroup) { ParcelSearch_TaskResultsDataGrid2.ItemsSource = pair.Value; } } }