Identify: Do not return unless Layer defined in popup config

977
6
Jump to solution
05-23-2014 07:56 AM
MattRogers
New Contributor
I'm having an issue with click identify returning results when not defined in the config popup file. I can get the popup to return if undefined, and it returns all fields. However I need it to return nothing unless its defined in the conf file.

Here's the portion of code that i'm working with, as is it works correctly for defined ...but we need to change the undefined to return nothing at all and currently its returning all fields.

        identifyCallback: function(identifiedlayers, responseArray) {             var fSet = [];             array.forEach(responseArray, function(response, i) {                 var layerId = identifiedlayers.ref.id;                 array.forEach(response, function(result) {                     // see if we have a Popup config defined for this layer                     if (config.hasOwnProperty(layerId)) {                         if (config[layerId].hasOwnProperty(result.layerId)) {                             result.feature.setInfoTemplate(new PopupTemplate(config[layerId][result.layerId]));                         }                     }                     // if no Popup defined output all attributes                     if (result.feature.infoTemplate === undefined) {                         result.feature.setInfoTemplate(new PopupTemplate({                             title: result.layerName,                             description: esriLang.substitute(result.feature.attributes)                         }));                     }                     fSet.push(result.feature);                 }, this);             }, this);             this.map.infoWindow.setFeatures(fSet);         }


Thanks for the help...this ones got me pretty perplexed.
0 Kudos
1 Solution

Accepted Solutions
LoriGonzalez
New Contributor III
On the inside, use a  'for' loop instead of 'array.forEach' and only push the feature to your feature array if the popup is defined.  Something like this:

  array.forEach(responseArray, function (response, i) {         var layerId = identifiedlayers.ref.id;         for (i=0; i<response.length;i++){             var result = response;             // see if we have a Popup config defined for this layer             if (config.hasOwnProperty(layerId)) {                 if (config[layerId].hasOwnProperty(result.layerId)) {                     result.feature.setInfoTemplate(new PopupTemplate(config[layerId][result.layerId]));                     fSet.push(result.feature);                 }             }             // if no Popup defined output all attributes             //if (result.feature.infoTemplate === undefined) {             //    result.feature.setInfoTemplate(new PopupTemplate({             //        title: result.layerName,             //        description: esriLang.substitute(result.feature.attributes)             //    }));             //}                                                                  };     }, this);

View solution in original post

0 Kudos
6 Replies
sailiTang
New Contributor III
Hi rogers259,

Could you try to change code like this: You can try to set description to "" or not set description but title.

// if no Popup defined output all attributes
if (result.feature.infoTemplate === undefined) {
result.feature.setInfoTemplate(new PopupTemplate({
title: result.layerName,
description: "" }));
}

Saili
0 Kudos
MattRogers
New Contributor
Thats sorta the right idea in that it eliminates the info being returned for the non-defined layers in the config file.

But I need to eliminate the stack of identified items entirely if they are not in the config.

[ATTACH=CONFIG]34055[/ATTACH]

Thanks,

Matt
0 Kudos
sailiTang
New Contributor III
Do you mean the information window is empty or no information window popup if they are not in the config?

Saili
0 Kudos
MattRogers
New Contributor
Saili,

If the layer is not defined in the Config file, no information window popup should appear.

Sorry should have been more clear about that.

Matt
0 Kudos
LoriGonzalez
New Contributor III
On the inside, use a  'for' loop instead of 'array.forEach' and only push the feature to your feature array if the popup is defined.  Something like this:

  array.forEach(responseArray, function (response, i) {         var layerId = identifiedlayers.ref.id;         for (i=0; i<response.length;i++){             var result = response;             // see if we have a Popup config defined for this layer             if (config.hasOwnProperty(layerId)) {                 if (config[layerId].hasOwnProperty(result.layerId)) {                     result.feature.setInfoTemplate(new PopupTemplate(config[layerId][result.layerId]));                     fSet.push(result.feature);                 }             }             // if no Popup defined output all attributes             //if (result.feature.infoTemplate === undefined) {             //    result.feature.setInfoTemplate(new PopupTemplate({             //        title: result.layerName,             //        description: esriLang.substitute(result.feature.attributes)             //    }));             //}                                                                  };     }, this);
0 Kudos
MattRogers
New Contributor
Winner winner chicken dinner!  :cool:

Thanks Guys for the help that got it working the way i needed it to

Matt
0 Kudos