Select to view content in your preferred language

Attributes from results of identify task do not show in popup

3012
5
Jump to solution
10-07-2013 03:01 PM
BethDavis
Emerging Contributor
I am using an identify task on layers in a dynamic map service, and displaying the results in a popup.  I have nearly identical code working perfectly for another service, but with this case, the only the template I defined shows in the popup.  The identify does not seem to be pulling the attribute values to populate the fields in the popup.  Any suggestions?

ETA: here is a fiddle.

function mapReady(map){    on(map,"Click",executeIdentifyTask);    //create identify tasks and setup parameters     identifyTask = new esri.tasks.IdentifyTask("http://nmbbmapping.org/arcgis/rest/services/casa/MapServer/");            identifyParams = new esri.tasks.IdentifyParameters();    identifyParams.tolerance = 10;    identifyParams.returnGeometry = true;    identifyParams.layerIds = [1,16];    identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;    identifyParams.width  = map.width;    identifyParams.height = map.height;   }          function executeIdentifyTask(evt) {    identifyParams.geometry = evt.mapPoint;    identifyParams.mapExtent = map.extent;            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;     if(result.layerName === 'Public Schools K12'){       //console.log(feature.attributes.PARCELID);       var template = new PopupTemplate ({        title: "Public Schools K12",        //description: ,        fieldInfos: [{ // define field infos to specify alias         fieldName: "INST_NAME",         visible: true,         label: "Institution Name: "        }, {         fieldName: "ADDRESS",         visible: true,         label: "Address: "        }, {         fieldName: "CITY",         visible: true,         label: "City: "        }]       });      feature.setInfoTemplate(template);     }      else if (result.layerName === 'Non Government Community Support'){       //console.log(feature.attributes.PARCELID);       var template = new PopupTemplate ({        title: "Non Government Community Support",        //description: ,        fieldInfos: [{ // define field infos to specify alias         fieldName: "INST_NAME",         visible: true,         label: "Institution Name: "        }, {         fieldName: "ADDRESS",         visible: true,         label: "Address: "        }, {         fieldName: "CITY",         visible: true,         label: "City: "        }]       });      feature.setInfoTemplate(template);     }   return feature;   });   });          map.infoWindow.setFeatures([ deferred ]);         map.infoWindow.show(evt.mapPoint);       }
0 Kudos
1 Solution

Accepted Solutions
JasonZou
Frequent Contributor
IdentifyTask.execute returns the attributes for each feature with the field alias names instead of the field name. So change all the fieldName property in each fieldInfos with the field alias name. It should work then. Note that the fieldName value is case-sensitive. To test it, take "Public Schools K12" layer as example.

Change:
if (result.layerName === 'Public Schools K12') {                         //console.log(feature.attributes.PARCELID);                         var template = new PopupTemplate({                             title: "Public Schools K12",                             //description: ,                             fieldInfos: [{ // define field infos to specify alias                                 fieldName: "INST_NAME",                                 visible: true,                                 label: "Name: "                             }, {                                 fieldName: "ADDRESS",                                 visible: true,                                 label: "ADDRESS: "                             }, {                                 fieldName: "CITY",                                 visible: true,                                 label: "CITY: "                             }]                         });

To:
if (result.layerName === 'Public Schools K12') {                         //console.log(feature.attributes.PARCELID);                         var template = new PopupTemplate({                             title: "Public Schools K12",                             //description: ,                             fieldInfos: [{ // define field infos to specify alias                                 fieldName: "Name of the Institution",                                 visible: true,                                 label: "Name: "                             }, {                                 fieldName: "Address",                                 visible: true,                                 label: "ADDRESS: "                             }, {                                 fieldName: "City",                                 visible: true,                                 label: "CITY: "                             }]                         });

View solution in original post

0 Kudos
5 Replies
TracySchloss
Honored Contributor
To begin with, I don't think there's supposed to be a backslash after 'MapServer' in my IdentifyTask definition.
0 Kudos
BethDavis
Emerging Contributor
Thanks. I fixed that, but it doesn't appear to have changed anything.
0 Kudos
TracySchloss
Honored Contributor
I'm not seeing that you set a spatialReference.  Have you tried adding that?
0 Kudos
JasonZou
Frequent Contributor
IdentifyTask.execute returns the attributes for each feature with the field alias names instead of the field name. So change all the fieldName property in each fieldInfos with the field alias name. It should work then. Note that the fieldName value is case-sensitive. To test it, take "Public Schools K12" layer as example.

Change:
if (result.layerName === 'Public Schools K12') {                         //console.log(feature.attributes.PARCELID);                         var template = new PopupTemplate({                             title: "Public Schools K12",                             //description: ,                             fieldInfos: [{ // define field infos to specify alias                                 fieldName: "INST_NAME",                                 visible: true,                                 label: "Name: "                             }, {                                 fieldName: "ADDRESS",                                 visible: true,                                 label: "ADDRESS: "                             }, {                                 fieldName: "CITY",                                 visible: true,                                 label: "CITY: "                             }]                         });

To:
if (result.layerName === 'Public Schools K12') {                         //console.log(feature.attributes.PARCELID);                         var template = new PopupTemplate({                             title: "Public Schools K12",                             //description: ,                             fieldInfos: [{ // define field infos to specify alias                                 fieldName: "Name of the Institution",                                 visible: true,                                 label: "Name: "                             }, {                                 fieldName: "Address",                                 visible: true,                                 label: "ADDRESS: "                             }, {                                 fieldName: "City",                                 visible: true,                                 label: "CITY: "                             }]                         });
0 Kudos
BethDavis
Emerging Contributor
That fixed it!  Thank you, Jason.
0 Kudos