Displaying information from different Feature Layers

569
3
10-19-2012 01:42 AM
IreneGM
New Contributor
Hi all,

I have in my ArcGIS Server 10.1 two layers published: one corresponds to a World map by country and the other to a layer containing some cities, represented by points.

What I would like to do is creating a ESRI Javascript API interface to view those (Feature) layers, so when the user clicks on a point, it appears a popup (or info in a side bar, does not mind) with the BOTH features associated to this city, namely: name of the city AND name of the country the city belongs to. But, if the user clicks on an area where there is not any city, only the name of the country should be displayed.

I know that it is a quite basic example, but I am not sure on how to tackle this problem: I see examples on retrieving information from a SINGLE layer, but not about how to distinguish between information required from different layers.

Please, can anyone provide some information/ideas/links to tutorials about that?

Thanks for your help!
0 Kudos
3 Replies
derekswingley1
Frequent Contributor
Are both layers in the same map service? If so, use an Identify Task.
0 Kudos
SteveCole
Frequent Contributor
This sample basically does what you want using an identify Task. If you were looking to present a more elegant popup back to your user, you'd have to manually build the content in the infoWindow using the query task and a deferred list as (somewhat) shown in this sample. Once the deferred list's results are returned, you would manually step through the results and build up your popup's content however you want it to appear.
0 Kudos
IreneGM
New Contributor
Thank you both for your responses. Yes, it seems that the "Display identify results in popup" sample suits more what I would like my interface to do.

However, I am facing a problem: I copied the example and changed the REST endpoints to my services. Then, on executeIdentifyTask function I changed the sample parameters to show my city names and country names. When I click on a city name, the popup appears saying the city name, but when clicking to a region where there are not cities it says "no information available". I checked the name of the layer just in case was wrong, but it is correct.

Did I skipped anything? The example is the same as the one you linked, but changing parameter names and REST links. Is something going wrong with the countries layer? I am not sure, because when I firstly wrote on this forum, I was able to show the country names OR the city names, so I assume data are ok.
0 Kudos