Remove Only Feature FID and layerName from Popup Window

1309
7
10-02-2016 11:42 AM
LloydBronn
Occasional Contributor II

I have a bunch of features that I want to display attributes for. Right now I have it set to iTemplate = new InfoTemplate(layerName, "${*}"); which shows everything. I want to display everything except the FID and layerName. I really don't want to have to define each attribute for every layer in the map. Each layer has slightly different attributes. Is there a way to exclude those two common attributes from the popup and show everything else?

0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus

Lloyd,

   The only thing I can think of that will allow you to not define all the fields manually and still remove the FID and layer name is to attach an event to the maps infowindow "set-features" event and then get the graphics attributes array and remove those fields from the array.

0 Kudos
LloydBronn
Occasional Contributor II

OK. I'll mess around with it. Thanks!

0 Kudos
LoriGonzalez
New Contributor III

You could write a function to exclude the attributes you don't need. Something like this:

iTemplate = new InfoTemplate("County",getTemplate)

function getTemplate(graphic) {
var content = "";
for (var att in graphic.attributes) {
if (att != "ObjectID" && att != "STATE_FIPS")
content += att + "=" + graphic.attributes[att] + "</br>";
}
return content;
}

0 Kudos
SteveCole
Frequent Contributor

How about specifying your list of fields in the outFields parameter of the featureLayer constructor?...

0 Kudos
LloydBronn
Occasional Contributor II

I could do that, but the only common fields to all the layers are FID and layerName. I would still have to specify the fields for each layer. It's looking like I'm going to have to do that anyway. 

0 Kudos
SteveCole
Frequent Contributor

Gotcha. I pretty much resign myself to the fact that I'll need to write custom formatting functions for all my popups in every app I put together. It sucks but I like having that fine grain control..

0 Kudos
LloydBronn
Occasional Contributor II

Sure. I've had to format popups in ArcGIS online and in the Flexviewer, and it's pretty tedious. 

0 Kudos