Custom info window for several map layers

676
1
08-21-2013 07:44 AM
JoseSanchez
Occasional Contributor III
Hi all,

This sample only works for one layer,

https://developers.arcgis.com/en/javascript/jssamples/widget_extendInfowindow.html


but in a regular map service there are several layers. Is there any generic Custom info window that will show like in ArcMap or Web ADF the attributes for several layers?



Regards
0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor
You can programmatically build a template with all the visible fields for multiple layers. This is how I did it for one application, but I also had modified the MXD file for the service to show only certain fields with aliases. This also leaves off the OBJECTID and SHAPE fields from the content.

    function executeIdentifyTask(evt) {
        map.graphics.clear();
        identifyParams.geometry = evt.mapPoint;
        identifyParams.mapExtent = map.extent;

        var deferred = identifyTask.execute(identifyParams);
        deferred.addCallback(function (response) {
            return dojo.map(response, function (result) {
                var feature = result.feature;
                var contentString = "";
                var sp = feature.attributes;

                contentString += "<b>" + result.layerName + "</b><hr width = '90%'>";

                for (var x in sp) {
                    if (x !== "OBJECTID" && x !== "Shape") {
                        contentString += "<i>" + x + "</i>: " + feature.attributes + "<br/>";
                    }
                }
                var infoTemplate = new esri.InfoTemplate();
                infoTemplate.setTitle("Results");
                infoTemplate.setContent(contentString);
                feature.setInfoTemplate(infoTemplate);

                return feature;
            });
        });
        map.infoWindow.setFeatures([deferred]);
        map.infoWindow.show(evt.mapPoint);
    }


0 Kudos