AnsweredAssumed Answered

JavaScript: How to return attribute values from selected features

Question asked by Natalie on Dec 7, 2014
Latest reply on Dec 8, 2014 by Natalie

I have a web page with a map where I want to be able to click on the map and get certain attribute values of the feature that I clicked on.


EG I click on a property and can access the property name, zone, owner etc. These are all attributes in the data.


The purpose for this is to pass the attribute values to another part of the web page.


So far I have tried a lot of variations on query/infotemplate/attributeinspector tasks. It is easy enough to get the values in a popup but I am having trouble accessing the values themselves in a way that I can use them elsewhere.


          var buttonCreateReport = doc.getElementById('btnCreateReport');
          buttonCreateReport.addEventListener('click', function createReport(){
            reportToolbar = new Draw(map);
            var reportQuery = new Query();

            on(reportToolbar, "DrawEnd", function (geometry) {
              reportQuery.geometry = geometry;

              var reportTemplate = new InfoTemplate();

              myGraphic = new Graphic();
              myGraphic.geometry = geometry;
              myGraphic.infoTemplate = reportTemplate;
              myGraphic.attributes = '["Name": {Property_Name}]';


Can anyone give me any help? I am happy to scrap this code and start again if I'm completely on the wrong track... but I have a distinct feeling that I'm just missing a small piece of the puzzle somewhere.