Formatting an InfoWindow

549
2
Jump to solution
04-23-2013 11:14 AM
KenBuja
MVP Esteemed Contributor
In my application, I have a map service containing many different layers, each containing many different fields. In the mxd file that created the service, we have hidden all the fields in each layer that don't need to be shown. When the user clicks on the map, I run the IdentifyTask and I'd like to show the user which layer is being represented in the InfoWindow when there are results from different layers.

Currently, using the code

var deferred = identifyTask.execute(identifyParams);  deferred.addCallback(function (response) {     // response is an array of identify result objects         // Let's return an array of features.     return dojo.map(response, function (result) {         var feature = result.feature;         feature.attributes.layerName = result.layerName;         //var infoTemplate = new esri.InfoTemplate('${result.layerName}', "${*}");         var infoTemplate = new esri.InfoTemplate("test", "${*}");         infoTemplate.setTitle("testing");         feature.setInfoTemplate(infoTemplate);     }     return feature; });


gives me an InfoWindow with the layer name appended to the end of the list of fields. How can I format the infoWindow so that the layerName is at the top of the field list? Setting the title doesn't seem to have any effect.

[ATTACH=CONFIG]23729[/ATTACH]
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
With a little more digging, I solved it with this code

var sp = feature.attributes; contentString += "<b>" + result.layerName + "</b>";  for (x in sp) {     contentString += "<br/>";     contentString += x + ": " + feature.attributes; }

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor
I'm making some progress on this by getting the attributes from the graphic. However, I'm running into a problem with the object that's returned from the line "features.attributes". The line

var sp = feature.attributes;

returns this object

Object { OBJECTID="5", County Name= "Palm Beach County",  more...}

However, when I try to loop through sp with the code

var sp = feature.attributes;
contentString += result.layerName;
for (x in sp) {
    contentString += "<br/>";
    contentString += x;
}


the value for x is just the attribute name, not the attribute and its value. That code results in a contentString with a value of

"Study Counties - SEFCRI Region Boundary<br/>OBJECTID<br/>County Name<br/>County Seat"

How can I parse out the attributes object correctly?
0 Kudos
KenBuja
MVP Esteemed Contributor
With a little more digging, I solved it with this code

var sp = feature.attributes; contentString += "<b>" + result.layerName + "</b>";  for (x in sp) {     contentString += "<br/>";     contentString += x + ": " + feature.attributes; }
0 Kudos