Select to view content in your preferred language

How do I get individual values back from FeatureLayers on a click event?

5312
15
Jump to solution
04-28-2015 10:31 AM
ChrisSergent
Deactivated User

I want to be able to get individual values to populate this application: http://maps.decaturil.gov Currently when I click on a point on the map, its displays this:

StreetSignsInfoDisplay.png

How would I get just the value of the field OBJECTID for example?

0 Kudos
15 Replies
ChrisSergent
Deactivated User

I just have the click event. Here is the full code: https://github.com/csergent45/streetSigns/blob/master/app/main.js

and here is an excerpt:

app.citizenRequestLayer = new FeatureLayer(config.citizenRequestLayerUrl, {

            mode: FeatureLayer.MODE_ONEDEMAND,

            //infoTemplate: new InfoTemplate(config.infoTemplate),

            outFields: ["*"]

        });

        app.map.addLayer(app.citizenRequestLayer);

      

        app.citizenRequestLayer.on("click", function (evt) {

          myObject = evt.graphic.attributes.OBJECTID;

        });

0 Kudos
KenBuja
MVP Esteemed Contributor

You defined "myobject" (line 89) but attempt to use "myObject"

TimWitt2
MVP Alum

Or you can create a infotemplate for each layer if you want to make your popups look different.

Custom info window | ArcGIS API for JavaScript

ChrisSmith7
Honored Contributor

Here's an example of using a custom template:

var serviceUrl = "https://myserviceurl.com/arcgis/rest/services/etc ...";

var outFields = ["OBJECTID", "FIELD1", "FIELD2", "FIELD3"];

var content = "<tr>" + $("#ff_formVal").val() + ": <td>{FIELD3}</td></tr>"

var infoTemplate = new esri.InfoTemplate("{FIELD3}", content);

var fl = new FeatureLayer(serviceUrl, {

     id: "featLayer",

     mode: FeatureLayer.MODE_ONDEMAND,

     outFields: outFields,

     infoTemplate: infoTemplate,

     wkid: 102100

});

I made some code mods after pasting, so hopefully I didn't foobar something (updates not tested)!

0 Kudos
NicholasHaney
Regular Contributor

Chris, I took a look at your code on GitHub. You declare the variable myobject on line 89 but then try to use the variable myObject on line 137. Variables are case sensitive in Javascript. Change the variable on line 137 to myobject and it should work.

ChrisSergent
Deactivated User

Yea Nicholas Haney​ and Ken Buja​, I feel like an idiot. I know that JavaScript is case sensitive. Should've checked my case when I received those errors. Thanks for getting me back on track. And this is my easy question.