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?
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
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.
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.
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
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? :
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)!
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
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 });
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.