AnsweredAssumed Answered

Only top graphic's attributes are getting returned for popup

Question asked by marshallrobinson on Oct 14, 2020

I have a function that pulls the attributes from a feature layer and uses them in a popupTemplate. It works fine when returning the attributes for the top graphic in a layer, but does not return any of the attributes for any overlapped graphics in the same layer. It returns the OBJECTID, but nothing else unfortunately. Thanks in advance for any help.

function getContent(graphic) {
        var gr = graphic.graphic.attributes;
          var sku = (gr.map_number) ? gr.map_number : '';
          map = "'"+sku+"'";
          console.log(graphic);
          var options = {
                      query: {
                         mapid: map
                      },
                      responseType: "json"
                    };
          //console.log(options.query.mapid);
          var content = esriRequest("../intgeomap/mysqlMapData.php", options).then(function (response2) {
               var g = response2.data[0];
               var thmb = g.pub_thumb;
               if (! thmb) {               //check if thumb_graphic field is empty
                    var image_url = 'not-available.png';
               } else {
                    var image_url = 'https://ugspub.nr.utah.gov/publications/mapthumbs/'+thmb;
               }
               var pubtitle = (g.pub_name) ? g.pub_name : ' ';
               if (g.pub_author && g.pub_sec_author) {
                    authors = '<div style="margin-bottom:.5em;"><b>Authors:</b> '+g.pub_author+', '+g.pub_sec_author+'<br></div>';
               } else if (g.pub_author) {
                    authors = '<div style="margin-bottom:.5em;"><b>Author:</b> '+g.pub_author+'<br></div>';
               } else {
                    authors = '';
               }     
               if (g.pub_publisher && g.series_id && g.pub_year) {
                    subTitle = '<div style="margin-bottom:.5em;"><b>Publisher:</b> '+g.pub_publisher+' | <b>Series ID:</b> '+g.series_id+' | <b>Date:</b> '+g.pub_year+'<br></div>';
               } else if (g.pub_publisher && g.series_id) {
                    subTitle = '<div style="margin-bottom:.5em;"><b>Publisher:</b> '+g.pub_publisher+' | <b>Series ID:</b> '+g.series_id+'<br></div>';
               } else if (g.pub_publisher && g.pub_year) {
                    subTitle = '<div style="margin-bottom:.5em;"><b>Publisher:</b> '+g.pub_publisher+' | <b>Date:</b> '+g.pub_year+'<br></div>';
               } else if (g.series_id && g.pub_year) {
                    subTitle = '<div style="margin-bottom:.5em;"><b>Series ID:</b> '+g.series_id+' | <b>Date:</b> '+g.pub_year+'<br></div>';
               } else if (g.series_id) {
                    subTitle = '<div style="margin-bottom:.5em;"><b>Series ID:</b> '+g.series_id+'<br></div>';
               } else if (g.pub_year) {
                    subTitle = '<div style="margin-bottom:.5em;"><b>Date:</b> '+g.pub_year+'<br></div>';
               } else if (g.pub_publisher) {
                    subTitle = '<div style="margin-bottom:.5em;"><b>Publisher:</b> '+g.pub_publisher+'<br></div>';
               } else {
                    subTitle = '';
               }     
               //var publisher = (g.pub_publisher) ? '<tr><td colspan="2">'+g.pub_publisher+ '<br><br></td></tr>' : ' ';
               var purchase = (g.bsurl) ? '<div style="margin-bottom:.5em;"><a href="https://www.utahmapstore.com/products/'+g.series_id+' " target="_blank">Purchase Map <img src="https://geology.utah.gov/apps/geoindex/buy3.png" alt="click to purchase" width="16" height="16" border="0" align="absbottom"></a></div>' : ' ';
               var pdf = (g.pub_url) ? '<div style="margin-bottom:.5em;"><a href="'+g.pub_url+'" target="_blank">Open PDF <img src="https://geology.utah.gov/images/pdf16x16.gif" alt="pdf" width="16" border="0" align="absbottom"></a></div>' : ' ';
               var gis = (g.gis_data) ? '<div style="margin-bottom:.5em;"><a href="https://ugspub.nr.utah.gov/publications/'+g.gis_data+'" target="_blank">Download GIS Data <img src="https://geology.utah.gov/images/zip16x16.gif" alt="GIS zip file" width="16" height="16" border="0" align="absbottom"></a></div>' : ' ';
               var usgs = !(g.pub_url) ? '<div style="margin-bottom:.5em;"><a href="https://ngmdb.usgs.gov/ngm-bin/ngm_compsearch.pl" target="_blank">Search USGS for pdf <img src="https://geology.utah.gov/images/pdf16x16.gif" alt="pdf" width="16" border="0" align="absbottom"></a></div>' : ' ';
               var popupText = '<div style="height:100%; line-height:1.3em;">'+'<div><img style="text-align:center;display:block;margin-left:auto;margin-right:auto;" src="'+image_url+'" border="0" width="225" ></a></div><hr>'+'<div style="margin-bottom:.5em;">'+'<b>'+pubtitle+'</b>'+'<br></div>'+authors+subTitle+'<hr>'+purchase+pdf+gis+usgs+'</div>';
               return popupText;
          });
          return content;
    }

Outcomes