JavaScript ArcGIS Maps – Identify All Layers Without Pre-Designing InfoWindow

arcgis-javascript-apijavascript

This applies to the ArcGIS Server JavaScript API 2.4.

The Identify Task sample shows how IdentifyTask can be used to find features in multiple layers, as specified in the IdentifyParameters:

identifyParams.layerIds = [0,2];

In this sample, the infoWindow already contains elements for the expected layers, which are used to display multiple features in separate tabs of the infoWindow:

<!-- info window tabs -->
<div id="tabs" dojoType="dijit.layout.TabContainer" style="width:385px;height:150px;">
  <div id="bldgTab" dojoType="dijit.layout.ContentPane" title="Buildings"></div>
  <div id="parcelTab" dojoType="dijit.layout.ContentPane" title="Tax Parcels"></div>
</div>

//In the JavaScript:
dijit.byId("bldgTab").setContent(layerTabContent(bldgResults,"bldgResults"));
dijit.byId("parcelTab").setContent(layerTabContent(parcelResults,"parcelResults"));

Is there a way to handle this dynamically, and create the required tabs at run-time?

For example, I wish to run IdentifyTask on all visible layers, and return the results in a separate tab of the infoWindow. How can I create the tabs dynamically?

Best Answer

Yes, this is possible. To create your tabs dynamically, look at creating dojo dijits programmatically vs. declaratively. When your visible layers change, modify your tab container to remove or add the appropriate tabs.

Edit: here's a proof of concept on JS Fiddle: http://jsfiddle.net/swingley/wKue4/ It doesn't really handle attributes but lets you select which layers to identify and builds the info window content dynamically.

Related Question