javascript - How to get ObjectID from ArcGIS FeatureLayer on click function? -


i'm trying work arcgis javascript api. i'm using this featurelayer example , try make popup, display different data based on objectid click on. see on example.

the problem can't access objectid outside variable template. inside variable template set title title: "id of object {objectid}". works good. have data stored in mysql database want objectid stored variable when click , possibly send through ajax route. in controller find matched object, data database , send popup template , display it.

that's idea how possibly work, need objectid first, don't know how access. if have idea how solved or know better way how put additional data database popuptemplate, let me know please. thanks.

edit:

require([         "esri/map",         "esri/views/mapview",         "esri/layers/featurelayer",         "dojo/on",         "dojo/domready!"     ], function(map, mapview, featurelayer, on) {         var featurelayer = new featurelayer({             url: "https://services.arcgis.com/v6zhfr6zdgnzuvg0/arcgis/rest/services/nycdemographics1/featureserver/0",             outfields: ["*"]         });          var map = new map({             basemap: "streets",             layers: [featurelayer]         });          var view = new mapview({             container: "viewdiv",             map: map,             zoom: 11,             center: [-73.950, 40.702] //cz [16, 49]         });          var template = {             title: "marriage in ny, zip code: {zip}",             content: "<p>as of 2015, <b>{marriedrate}%</b> of population in zip code married.</p>" +             "<ul><li>{married_cy} people married</li>" +             "<li>{nevmarr_cy} have never married</li>" +             "<li>{divorcd_cy} divorced</li><ul>"         };          featurelayer.popuptemplate = template;          on(featurelayer, 'click', function(e){             console.log(e);         });      }); 

with "dojo/on" can handle click event on feature layer, attributes of shape clicked on :

on(featurelayer, 'click', function (e) {   console.log(e.graphic.attributes.objectid); }); 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -