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; } } }
// 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 }
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); } } }
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
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;
If queryArgs.FeatureSet Is Nothing Then Return End If Dim FeatLayr As ESRI.ArcGIS.Client.FeatureLayer = Map1.Layers("Institutions") Dim resultFeatureSet As FeatureSet = queryArgs.FeatureSet Dim graphicsLayer As ESRI.ArcGIS.Client.GraphicsLayer = TryCast(Map1.Layers("Institutions"), ESRI.ArcGIS.Client.GraphicsLayer) For Each graphicFeature As ESRI.ArcGIS.Client.Graphic In resultFeatureSet.Features graphicsLayer.Graphics.Add(graphicFeature) RelatedQuery(Convert.ToInt32(graphicFeature.Attributes(FeatLayr.LayerInfo.ObjectIdField))) Next graphicFeature Private Sub RelatedQuery(ByVal ObjectId As Int32) Dim qtRelatedTables As New QueryTask("http://204.68.195.113/ArcGIS/rest/services/DOTResearch/DOTResearchGDB/MapServer/4") AddHandler qtRelatedTables.Failed, AddressOf qtRelatedTables_Failed AddHandler qtRelatedTables.ExecuteRelationshipQueryCompleted, AddressOf qtRelatedTables_ExecuteRelationshipQueryCompleted Dim rp As New RelationshipParameter rp.ObjectIds = {ObjectId} 'rp.ObjectIds = resultsFS.ObjectIDs rp.RelationshipId = 0 rp.ReturnGeometry = False rp.OutFields = {"*"} qtRelatedTables.ExecuteRelationshipQueryAsync(rp) End Sub
Private Sub Query_ExecuteCompleted(ByVal sender As Object, ByVal queryArgs As QueryEventArgs) If queryArgs.FeatureSet Is Nothing Then Return End If Dim resultFeatureSet As FeatureSet = queryArgs.FeatureSet Dim graphicsLayer As ESRI.ArcGIS.Client.GraphicsLayer = TryCast(Map1.Layers("Institutions"), ESRI.ArcGIS.Client.GraphicsLayer) If resultFeatureSet IsNot Nothing AndAlso resultFeatureSet.Features.Count > 0 Then For Each graphicFeature As ESRI.ArcGIS.Client.Graphic In resultFeatureSet.Features graphicsLayer.Graphics.Add(graphicFeature) Next graphicFeature Dim expandPercentage As Double = 30 Dim widthExpand As Double = graphicsLayer.FullExtent.Width * (expandPercentage / 100) Dim heightExpand As Double = graphicsLayer.FullExtent.Height * (expandPercentage / 100) Dim displayExtent As New _ ESRI.ArcGIS.Client.Geometry.Envelope(graphicsLayer.FullExtent.XMin - (widthExpand / 2), _ graphicsLayer.FullExtent.YMin - (heightExpand / 2), _ graphicsLayer.FullExtent.XMax + (widthExpand / 2), _ graphicsLayer.FullExtent.YMax + (heightExpand / 2)) Map1.ZoomTo(displayExtent) End If RelatedQuery(resultFeatureSet) End Sub Private Sub RelatedQuery(ByVal resultsFS As FeatureSet) Dim qtRelatedTables As New QueryTask("http://204.68.195.113/ArcGIS/rest/services/DOTResearch/DOTResearchGDB/MapServer/4") AddHandler qtRelatedTables.Failed, AddressOf qtRelatedTables_Failed AddHandler qtRelatedTables.ExecuteRelationshipQueryCompleted, AddressOf qtRelatedTables_ExecuteRelationshipQueryCompleted Dim listObjIds As New List(Of Integer) Dim intIndex As Integer = 0 For Each Feat In resultsFS.Features listObjIds.Add(resultsFS.Features(intIndex).Attributes("OBJECTID")) intIndex = intIndex + 1 Next Dim rp As New RelationshipParameter rp.ObjectIds = listObjIds rp.RelationshipId = 0 rp.ReturnGeometry = False rp.OutFields = {"*"} qtRelatedTables.ExecuteRelationshipQueryAsync(rp) End Sub Private Sub qtRelatedTables_ExecuteRelationshipQueryCompleted(ByVal sender As Object, ByVal e As RelationshipEventArgs) If e.Result Is Nothing Then Return Else MessageBox.Show("Bingo") End If End Sub Private Sub qtRelatedTables_Failed(ByVal sender As Object, ByVal args As TaskFailedEventArgs) MessageBox.Show("Query failed: " & args.Error.Message) End Sub Private Sub Query_Failed(ByVal sender As Object, ByVal args As TaskFailedEventArgs) MessageBox.Show("Query failed: " & args.Error.Message) End Sub
Dim objectid As Integer = Convert.ToInt32(featureSet.ObjectIdFieldName)
Dim objectId As Integer = Convert.ToInt32(graphic.Attributes(incidentsLayer.LayerInfo.ObjectIdField))
Private Sub QueryTaskab_ExecuteCompleted(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs) Dim featureSet As FeatureSet = args.FeatureSet If featureSet Is Nothing OrElse featureSet.Features.Count < 1 Then MessageBox.Show("No features retured from query") Return End If Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MySelectionGraphicsLayer"), GraphicsLayer) If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then For Each feature As Graphic In featureSet.Features feature.Symbol = TryCast(LayoutRoot.Resources("ResultsFillSymbol"), Symbol) graphicsLayer.Graphics.Insert(0, feature) Next feature ResultsDisplay.Visibility = Visibility.Visible End If MyDrawSurface.IsEnabled = False Dim objectid As Integer = Convert.ToInt32(featureSet.ObjectIdFieldName) Dim queryTaskab As New QueryTask("http://...../ArcGIS/rest/services/10106734/_AsBuiltRelate10/MapServer/0") AddHandler queryTaskab.Failed, AddressOf QueryTaskab_Failed AddHandler queryTaskab.ExecuteRelationshipQueryCompleted, AddressOf QueryTaskab_ExecuteRelationshipQueryCompleted Dim rquery As RelationshipParameter = New ESRI.ArcGIS.Client.Tasks.RelationshipParameter() rquery.ObjectIds = New Integer() {objectid} Dim outList As New List(Of String) outList.Add("OBJECTID") outList.Add("REDBOOKNUM") rquery.RelationshipId = 0 rquery.OutFields = outList queryTaskab.ExecuteRelationshipQueryAsync(rquery) End Sub
private void QueryRelatedTable() { int objectId = Convert.ToInt32(graphic.Attributes[incidentsLayer.LayerInfo.ObjectIdField]); int relationshipId = -1; foreach (var relationship in incidentsLayer.LayerInfo.Relationships) { relationshipId = relationship.RelatedTableId; break; } QueryTask qt = new QueryTask(incidentsLayer.Url); qt.DisableClientCaching = true; RelationshipParameter rp = new RelationshipParameter(); rp.ObjectIds = new int[]{objectId}; rp.OutFields = new string[]{"agree_with_incident"}; rp.RelationshipId = relationshipId; qt.ExecuteRelationshipQueryCompleted += qt_ExecuteRelationshipQueryCompleted; qt.ExecuteRelationshipQueryAsync(rp); } private void qt_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e) { RelationshipResult pr = e.Result; voteCount = 0; foreach (var item in pr.RelatedRecordsGroup) { voteCount = item.Value.Count(); break; } }
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.