[GIS] Merging Popups with Relationship Queries using ArcGIS API for JavaScript

arcgis-javascript-api

I am trying to merge two ArcGIS JS API examples: Feature Layer with Popup and Query Related Records. The idea I have in mind is clicking on a country feature, retrieve all related records from a service (already prepared for relationship queries) and present those text records inside a Popup (esri.dijit.Popup).

I was interested in doing this exercise, because I like the way this Popup presents multiple results for a feature, by paging them as you can see in the first link when clicking on a tree. And it was a good match for my application with Relationship Queries. So far, I have most of the functionality already prepared and I can see the related records retrieved from the services in my firebug console. Good news.

My problem comes when I have to put those records in the Dojo Popup: The example shows that adding features to the Popup is as "simple" as using the setFeatures(features) method. This method receives either an array of Deferreds or an array of Features. In my case, I have both of them available.

I get the results like this and add it to the popup on map.infoWindow parameter:

mydeferred = featureLayer.queryRelatedFeatures(relatedTopsQuery, function(relatedRecords) {
var fset = relatedRecords[res.attributes['OBJECTID']];
var items = dojo.map(fset.features, function(feature) {
    feature.attributes.DateStart = Date(feature.attributes.DateStart).toLocaleString();
    feature.attributes.DateEnd = Date(feature.attributes.DateEnd).toLocaleString();
    feature.setGeometry(evt.mapPoint);              
    return feature.attributes;
}); 

map.infoWindow.setFeatures(fset.features);
map.infoWindow.show(evt.mapPoint);

But, no matter if I pass to setFeatures a Deferred or a Feature array, that my output is the following one:

enter image description here

Does anyone detect the problem or the bug? I think that the problem might be related with the DOM structure of the features, because if you see the image attached, the function knows the size of the array of features, but does not display any of the related records. It is important to highlight that:

  • I had to manually add the geometry field to the features, maybe any other required parameter is missing and that is why the popup is showing nothing. Does it make sense?
  • At this moment, the info template function getTextContent() returns a string "Hello world", but it is not appearing in the popup.

Just to illustrate what I mean I have adapted ESRI's Query Related Records example to use Popup in this jsfiddle: http://jsfiddle.net/uBNAm/ I hope if you see this, you can understand fully what I mean. Just click red spots until a popup like the one above appears.

Maybe is it a bug? How should I proceed to report it?

Best Answer

Some time ago, I faced a similar situation. In my case, I even tried to pass to setFeatures the output of the queryRelatedFeatures, something like:

map.infoWindow.setFeatures(myFeatureLayer.queryRelatedFeatures(query, function(relatedRecords){...});

But it did not work either. I also tried the same with deferred and fset.features, without luck. Finally I had to show results in a panel, but I think that it is better to show them in a Popup.

In my opinion, DOM object returned by FeatureLayer::queryRelatedFeatures is different than the one returned, as in the examples, by FeatureLayer::selectFeatures although they both are Deferred. And this might have "unpredictable" consequences. I am attaching an image below:

enter image description here

First row is what a queryRelatedFeatures() returns. Second is what selectFeatures() returns. As you may see, they are completely different in the inside.

To conclude: results returned in the first case, are contained in a Feature Set, while results returned on the second case are contained in an Array of Features. I am not an expert in this ESRI ArcGIS JS-API, but I guess this might be a bug or a lack of functionality that could be fixed in a future release... Any ESRI developer around here to bring light? :-)