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:
How would I get just the value of the field OBJECTID for example?
Solved! Go to Solution.
You can use the onclick event of your feature layer to get any attribute you want:
yourlayer.on("click", function (evt){ theAttributeYouWant = evt.graphic.attributes.OBJECTID; });
Tim
When you create the layer you can specify it in the outfield property
layer = new FeatureLayer("//sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2", {
"id": "Washington",
"infoTemplate": popupTemplate,
"mode": FeatureLayer.MODE_SNAPSHOT,
"outFields": [OBJECTID],
"opacity": 0.8
});
This is close but I don't want a template, I know how to do that. What I want is to get the individual values so I can take the values and write them to the form below. If I had a line of code as an example, I could write the code for the other values. Any ideas? :
You can use the onclick event of your feature layer to get any attribute you want:
yourlayer.on("click", function (evt){ theAttributeYouWant = evt.graphic.attributes.OBJECTID; });
Tim
I think I am doing it wrong. I wrote this:
app.citizenRequestLayer.on("click", function (evt) {
myObject = evt.graphic.attributes.OBJECTID;
});
and I get: Uncaught ReferenceError: myObject is not defined
What happens if you leave app. off. just have it as citizenRequestLayer.on?
That won't work. app is an object for the purpose of unobtrusive JavaScript, so it's needed.
You need to make sure that myObject is globally defined.
It is.
Where are you defining the variable "myObject" and where do you get the error? Is it in the click callback or somewhere else?