AnsweredAssumed Answered

How can I add an attachment as an image in InfoTemplate?

Question asked by schlot on Oct 20, 2015
Latest reply on Oct 20, 2015 by schlot

I have a featureLayer that has attachments.  I'd like the attachments to be added as an image in the infoTemplate.  I have a function to generate its content .   If I put in a breakpoint on the line return formatString, it gets to it before it evaluates queryAttachmentInfos.

 

It is finding the right URL for the attachment.  The rest of the tag is populated, it just doesn't have the image I expect. 

 

var infoTemplate = new InfoTemplate();
infoTemplate.setContent(setWindowContent);

 function setWindowContent(graphic){
   var formatString = "";
   var imageString = "";
   var imageStyle = " height='30' width='30' alt='site image'";
  var  objectId = graphic.attributes[featureLayer.objectIdField];
   formatString = "<b>"+graphic.attributes.Facility +"</b><br/>" +graphic.attributes.Address+"<br/>" 
    + graphic.attributes.City+", " + graphic.attributes.State ;
       
       featureLayer.queryAttachmentInfos(objectId, function(infos){
             var imgSrc;
            if (!!infos[0].url) {
              imgSrc = infos[0].url;
            }               
           if (imgSrc){
             imageString = "</br><img src='"+imgSrc +"' " + imageStyle+">";
             console.log(imageString);  // I am getting value here
               formatString += imageString;
           }
          });   
    return formatString;
 }

Outcomes