Attachments within a popuptemplate

1986
11
01-17-2017 01:14 PM
EvonFranklin
New Contributor III

Attachments set from Arcgis Desktop Service seem to not be displaying in API 4.2, I am using the code below

popupTemplate: {
                                    title: "{CONST}",
                                    content: [{
                                                type: "attachments" 
                                              },
                                              {     
                                                  type: "text",
                                                  text: "Sample data"
                                              }]
                                 }

Can anyone confirm if this is working to date or not as yet? Thanks for any tips and advice.

0 Kudos
11 Replies
KellyHutchins
Esri Frequent Contributor

I just ran a quick test using a hosted feature service and attachments and was able to view them in a 4.2 popup. Here's my test code: 

<!DOCTYPE html>
<html dir="ltr">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"
  />
  <meta name="description" content="[Multiple popup elements - 4.2]">
  <!-- 
  ArcGIS API for JavaScript, https://js.arcgis.com
  For more information about the popup-multipleelements sample, read the original sample description at developers.arcgis.com.
  https://developers.arcgis.com/javascript/latest/popup-multipleelements/index.html  
  -->
  <title>Multiple popup elements - 4.2</title>

  <link rel="stylesheet" href="https://js.arcgis.com/4.2/esri/css/main.css">
  <link rel="stylesheet" href="https://js.arcgis.com/4.2/dijit/themes/claro/claro.css">
  <script src="https://js.arcgis.com/4.2/"></script>

  <style>
    html,
    body,
    #mapDiv {
      height: 100%;
      width: 100%;
      margin: 0;
      padding: 0;
    }
  </style>

  <script>
    require([
      "esri/Map",
      "esri/views/MapView",
      "esri/layers/FeatureLayer",
      "dojo/domReady!"
    ], function(Map, MapView, FeatureLayer) {

      // setup the map
      var map = new Map({
        basemap: "hybrid"
      });
      var view = new MapView({
        container: "mapDiv",
        map: map,
        center: [-118.399400711028, 34.08713590709093],
        zoom: 8,
        // Since there are many elements, it is best to dock the popup so
        // the elements display better rather than have to scroll through them all.
        popup: {
          dockEnabled: true,
          dockOptions: {
            buttonEnabled: false,
            breakpoint: false
          }
        }
      });

      var featureLayer = new FeatureLayer({
        url: "http://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/grafitti/FeatureServer/0",
        popupTemplate: {
          title: "Graffitik",

          // Set content elements in the order to display.
          // The first element displayed here is the fieldInfos.
          content: [{
            // It is also possible to set the fieldInfos outside of the content
            // directly in the popupTemplate. If no fieldInfos is specifically set
            // in the content, it defaults to whatever may be set within the popupTemplate.
            type: "fields",
            fieldInfos: [{
              fieldName: "description",
              visible: false,
              label: "Details"
            }]
          }, {

            type: "attachments"
          }]
        },
        outFields: ["*"]
      });
      map.add(featureLayer);
    });
  </script>

</head>

<body>
  <div id="mapDiv"></div>
</body>

</html>
EvonFranklin
New Contributor III

I will look at this now and give it a shot. Also on the Arcgis Desktop program when compiling your service is there any special setting you selected in order to add the attachment? I just added the attachment via attribute table.

0 Kudos
KellyHutchins
Esri Frequent Contributor

I tested with an ArcGIS Online hosted service.  You'll want to check your service to make sure Has Attachments is set to true. 

http://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/grafitti/FeatureServer/0 

0 Kudos
EvonFranklin
New Contributor III

On my service layer there is this attritbute.

"Has Attachments: true" set

0 Kudos
KellyHutchins
Esri Frequent Contributor

Then you should be good to go. 

0 Kudos
EvonFranklin
New Contributor III

Anyway to get it to auto display instead of providing a clickable link?

0 Kudos
KellyHutchins
Esri Frequent Contributor

Not without writing code to get the attachments and add then add them to the media section of the popup. 

0 Kudos
EvonFranklin
New Contributor III

If I could pull the URL for the attachment I could then figure out the rest myself.

0 Kudos
HeathAnderson
Occasional Contributor II

Were you able to figured this out?

I am trying to do the same thing.  I know the url path to query for the attachment of a specific feature and get a json response, but i don't know how to hold the attachment ObjectID in a variable so that I can populate the mediaInfos section.

0 Kudos