Select to view content in your preferred language

If statement for multiple feature layers infotemplate

1853
9
Jump to solution
08-28-2013 10:42 AM
BarryGuidry
Regular Contributor
I have added two FeatureLayers to query attributes from in an infotemplate (popup). What I would like to figure out is how to write an if statement that states if one attribute is undefined ("SHELTER") to use another attribute field ("BUILDING"), and add to the following function. Is this possible?
function getTextContent(graphic) { //continuation of popup feature             var bldg = "<br /><br />Shelter: " +graphic.attributes.SHELTER + "<br /><br />Shelter Room: " +graphic.attributes.LOCATION; //fields, within the featureLayer, to return information for             return  bldg;         } 
Or, another idea, is how to simply have it always query the top-most layer attributes? I think that would solve my problem as well.
0 Kudos
1 Solution

Accepted Solutions
BenFousek
Deactivated User
FeatureLayer variable name


As in the layer itself or any of the layer's properties, functions, etc?

//the layer itself var layer = graphic.getLayer();  //the layer's id var layerId = graphic.getLayer().id;


function getTextContent(graphic) {   if (graphic.getLayer().id === 'feature_layer_one') {     //do stuff    } else if (graphic.getLayer().id === 'feature_layer_two') {     //do stuff    } }


You would need to set the feature layer's id on creation.
var fl = new esri.layers.FeatureLayer(url, {   mode: 1,   id: 'feature_layer_one' });

View solution in original post

0 Kudos
9 Replies
BenFousek
Deactivated User
function getTextContent(graphic) {
  if (graphic.attributes.SHELTER === undefined) {
    //do stuff 
  } else {
    //do stuff 
  }
}
0 Kudos
BarryGuidry
Regular Contributor
Thank you, Ben. That works except, as I expected, may display the "undefined" information first in a series of features to navigate in the popup. I would rather it display the attributes of the top-most layer of the feature selected instead. Any ideas?
0 Kudos
BenFousek
Deactivated User
I'm not exactly 100% on the workflow that get's you to getTextContent(graphic) or how undefined would be returned if you return something else when SHELTER is undefined.
0 Kudos
BarryGuidry
Regular Contributor
Almost where I need to be with this:
function getTextContent(graphic) { //continuation of popup feature
   if (graphic.attributes.SHELTER === undefined) {
            var bldg = "<br /><br />BUILDING: " +graphic.attributes.BUILDING; //fields, within the featureLayer, to return information for
   return bldg;
            } else {
   var bldg2 = "<br /><br />BUILDING: " +graphic.attributes.SHELTER + "<br /><br />Shelter Room: " +graphic.attributes.LOCATION;
   
   return  bldg2;
        } 
       }
But, would also rather force the popup to auto navigate to the second record of the selected feature if SHELTER is undefined, in addition to displaying the attributes of the variable "bldg2" above. Is there a code snippet to navigate to the next record in an infotemplate popup?
0 Kudos
BenFousek
Deactivated User
FeatureLayer variable name


As in the layer itself or any of the layer's properties, functions, etc?

//the layer itself var layer = graphic.getLayer();  //the layer's id var layerId = graphic.getLayer().id;


function getTextContent(graphic) {   if (graphic.getLayer().id === 'feature_layer_one') {     //do stuff    } else if (graphic.getLayer().id === 'feature_layer_two') {     //do stuff    } }


You would need to set the feature layer's id on creation.
var fl = new esri.layers.FeatureLayer(url, {   mode: 1,   id: 'feature_layer_one' });
0 Kudos
BarryGuidry
Regular Contributor
As in the layer itself or any of the layer's properties, functions, etc?

//the layer itself
var layer = graphic.getLayer();

//the layer's id
var layerId = graphic.getLayer().id;


function getTextContent(graphic) {
  if (graphic.getLayer().id === 'feature_layer_one') {
    //do stuff 
  } else if (graphic.getLayer().id === 'feature_layer_two') {
    //do stuff 
  }
}
You would need to set the feature layer's id on creation.
var fl = new esri.layers.FeatureLayer(url, {
  mode: 1,
  id: 'feature_layer_one'
});
Thats even better, Ben, but I still need to somehow have it navigate to attributes of 'feature_layer_one' first if it exists where clicked, and if non-existent, then navigate to 'feature_layer_two', as well, somewhere in the if statement that I have now (below).
function getTextContent(graphic) { //continuation of popup feature
   if (graphic.getLayer().id === 'fl') {
   var bldg = "<br /><br />BUILDING: " +graphic.attributes.SHELTER + "<br /><br />Shelter Room: " +graphic.attributes.LOCATION; //fields, within the featureLayer, to return information for
   return  bldg; 
   } else if (graphic.getLayer().id === 'fl2') {
   var bldg = "<br /><br />BUILDING: " +graphic.attributes.BUILDING; //fields, within the featureLayer, to return information for
   return bldg; 
   }
  }


Thanks again.
0 Kudos
BenFousek
Deactivated User
Is there a reason you don't just set the infoTemplate of the feature layer?
0 Kudos
BarryGuidry
Regular Contributor
Is there a reason you don't just set the infoTemplate of the feature layer?

Yes Sir. I am pulling attribute data from two FeatureLayers, with one of the fields being the same name (for good reason; BUILDING).
0 Kudos
VinayBansal
Frequent Contributor
Is there a code snippet to navigate to the next record in an infotemplate popup?



You can use select function of infoWindow to navigate to the index of feature
https://developers.arcgis.com/en/javascript/jsapi/popup-amd.html#select
0 Kudos