Accessing fields from FeatureLayer

3458
3
Jump to solution
06-05-2015 07:52 AM
NicolasPeckman
New Contributor

I have been altering this code to learn some basics about FeatureLayers. I want to add a functionality where upon hovering over a certain county, the pop-up displays additional information, however I'm not sure how to access the results of the query. The code the tutorial uses to display the results of the query looks like this:

var t = "<b>${NAME}</b><hr><b>"

but when I use

if (${NAME} == "example"){
     //add information
}

the viewer won't load. How can I get the information from the out-fields for each county and utilize it in the code?

0 Kudos
1 Solution

Accepted Solutions
thejuskambi
Occasional Contributor III

${NAME} is used for substitution. You could directly use evt.graphic.attributes["NAME"].

View solution in original post

3 Replies
RickeyFight
MVP Regular Contributor

Nicolas,

I think you are asking for a way to add more fields to the popup.

If so, you need to change two sections of code.

You need to look at the service and add more outfields for the ones you want to add.

outFields: ["NAME", "POP2000", "POP2007", "POP00_SQMI", "POP07_SQMI"]

and

you then need to add the corresponding fields to this section.

southCarolinaCounties.on("mouse-over", function(evt){
          var t = "<b>${NAME}</b><hr><b>2000 Population: </b>${POP2000:NumberFormat}<br>"
            + "<b>2000 Population per Sq. Mi.: </b>${POP00_SQMI:NumberFormat}<br>"
            + "<b>2007 Population: </b>${POP2007:NumberFormat}<br>"
            + "<b>2007 Population per Sq. Mi.: </b>${POP07_SQMI:NumberFormat}";

Can you post the code you have changed so we can see what it looks like?

0 Kudos
NicolasPeckman
New Contributor

Sorry if I wasn't specific enough, I'm actually looking for a way to use data from the outfields in conditional statements like this:

southCarolinaCounties.on("mouse-over", function(evt){
        var capitol;
        if (${NAME} == "Richland"){
             capitol = "Contains capitol";
        }
        var t = "<b>${NAME}</b><hr><b>2000 Population: </b>${POP2000:NumberFormat}<br>"
        + "<b>2000 Population per Sq. Mi.: </b>${POP00_SQMI:NumberFormat}<br>"
        + "<b>2007 Population: </b>${POP2007:NumberFormat}<br>"
        + "<b>2007 Population per Sq. Mi.: </b>${POP07_SQMI:NumberFormat}<br>"
        + capitol;

        var content = esriLang.substitute(evt.graphic.attributes,t);
        var highlightGraphic = new Graphic(evt.graphic.geometry,highlightSymbol);
        map.graphics.add(highlightGraphic);
         
        dialog.setContent(content);
        domStyle.set(dialog.domNode, "opacity", 0.85);
        dijitPopup.open({
        popup: dialog,
        x: evt.pageX,
        y: evt.pageY
        });
});

However using the syntax ${NAME} crashes the map. What can I use to determine the name of the county that ${NAME} displays in the popup?

0 Kudos
thejuskambi
Occasional Contributor III

${NAME} is used for substitution. You could directly use evt.graphic.attributes["NAME"].