<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Display Attachement in Popup Template in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224596#M79099</link>
    <description>&lt;P&gt;Done, then I will also try to figure it out, once you publish.&lt;/P&gt;</description>
    <pubDate>Mon, 24 Oct 2022 07:19:07 GMT</pubDate>
    <dc:creator>JayakumarPD</dc:creator>
    <dc:date>2022-10-24T07:19:07Z</dc:date>
    <item>
      <title>Display Attachement in Popup Template</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224578#M79093</link>
      <description>&lt;P&gt;Hi All Greetings&lt;/P&gt;&lt;P&gt;Trying to display the attachment image in&amp;nbsp;Popup Template&lt;FONT face="inherit"&gt;, but not able to display the full image . It shows only like a broken link image. But when clicked , it opens in new window and displaying like charm.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can I display the full image it inside the popup , please&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;urlNaturalresourcesF = "https://xxxxxxxxxxx/arcgis/rest/services/WebQuery/ Naturalresources/MapServer/0";
 naturalServicepathF = new FeatureLayer(urlNaturalresourcesF, { id: "naturalRes", mode: FeatureLayer.MODE_ONDEMAND, outFields: ["*"], listMode: "hide" });

 //Attachment content
let attachmentsElement = new AttachmentsContent({ 
  displayType: "auto" 
  //displayType: "preview"
});

let template = new PopupTemplate({
  title: "Natural Resources",
  outFields: ["*"],
  content: [attachmentsElement]
});


naturalServicepathF.popupTemplate = template;

//check crome if service is running without safe browse for https
map.add(naturalServicepathF);&lt;/LI-CODE&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="attachment.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/54212i2DD106C6DB98762F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="attachment.png" alt="attachment.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 05:48:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224578#M79093</guid>
      <dc:creator>cadgism</dc:creator>
      <dc:date>2022-10-24T05:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Display Attachement in Popup Template</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224582#M79094</link>
      <description>&lt;P&gt;See will this helps you.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-ImageMediaInfo.html" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-popup-content-ImageMediaInfo.html&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Create the ImageMediaInfoValue
let imageMediaInfoValue = new ImageMediaInfoValue({
  sourceURL: "&amp;lt;insert URL&amp;gt;"
});

// Create the ImageMediaInfo
let imageElement = new ImageMediaInfo({
  title: "&amp;lt;b&amp;gt;Mexican Fan Palm&amp;lt;/b&amp;gt;",
  caption: "tree species",
  value: imageMediaInfoValue
});

// Create the MediaContent
let mediaElement = new MediaContent({
  mediaInfos: [ imageElement ]
});&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 24 Oct 2022 06:15:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224582#M79094</guid>
      <dc:creator>JayakumarPD</dc:creator>
      <dc:date>2022-10-24T06:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: Display Attachement in Popup Template</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224584#M79095</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Jayakumar PD&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;This is an attachment,&amp;nbsp; how do I specify the source URL here&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&lt;A href="https://community.esri.com/t5/arcgis-api-for-javascript-questions/display-attachement-in-popup-template/m-p/1224582#" target="_blank" rel="noopener"&gt;PREVIEW&lt;/A&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;let imageMediaInfoValue = new ImageMediaInfoValue({
  sourceURL: "&amp;lt;insert URL&amp;gt;"
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 24 Oct 2022 06:22:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224584#M79095</guid>
      <dc:creator>cadgism</dc:creator>
      <dc:date>2022-10-24T06:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Display Attachement in Popup Template</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224589#M79096</link>
      <description>&lt;P&gt;Is it possible to share the code.&amp;nbsp; I don't have any service layer with image.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 06:28:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224589#M79096</guid>
      <dc:creator>JayakumarPD</dc:creator>
      <dc:date>2022-10-24T06:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Display Attachement in Popup Template</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224590#M79097</link>
      <description>&lt;P&gt;Sure,&amp;nbsp; Will publish a service and share&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 06:38:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224590#M79097</guid>
      <dc:creator>cadgism</dc:creator>
      <dc:date>2022-10-24T06:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: Display Attachement in Popup Template</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224596#M79099</link>
      <description>&lt;P&gt;Done, then I will also try to figure it out, once you publish.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 07:19:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224596#M79099</guid>
      <dc:creator>JayakumarPD</dc:creator>
      <dc:date>2022-10-24T07:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Display Attachement in Popup Template</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224619#M79101</link>
      <description>&lt;P&gt;Solved. This is how it works. Your reply was helpful to solve this issue.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;function showAtts(event){
  view.hitTest(event).then(function getGraphics(response) {
    if (response.results.length) {
      graphic = response.results[0].graphic;
      console.log(graphic);
    
      lyrUrl = graphic.layer.url + "/0/";
      objID = graphic.getAttribute('RemarkPoint.OBJECTID');
      attID = graphic.getAttribute('RemarkPoint__ATTACH.ATTACHMENTID');
      imgUrlPath = lyrUrl+objID+"/attachments/"+attID;

      let imageMediaInfoValue = new ImageMediaInfoValue({
          sourceURL: imgUrlPath
      });

      let imageElement = new ImageMediaInfo({
        title: "Natural Resources",
        caption: "Photo",
        value: imageMediaInfoValue
      });

      let mediaElement = new MediaContent({
        mediaInfos: [ imageElement ]
      });

      let template = new PopupTemplate({
        title: "Natural Resources",
        outFields: ["*"],
        showAttachments: true,
        content: [mediaElement],
      });

      naturalServicepathF.popupTemplate = template;
  
    } 
  });
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 24 Oct 2022 10:27:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1224619#M79101</guid>
      <dc:creator>cadgism</dc:creator>
      <dc:date>2022-10-24T10:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: Display Attachement in Popup Template</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1390843#M83849</link>
      <description>&lt;P&gt;I am still getting a broken picture. Can you show the rest of the code? I may be missing where&amp;nbsp;getGraphics is being used.&lt;/P&gt;&lt;P&gt;My code is below&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2024 22:46:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1390843#M83849</guid>
      <dc:creator>RobertKirkwood</dc:creator>
      <dc:date>2024-03-05T22:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: Display Attachement in Popup Template</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1391075#M83858</link>
      <description>&lt;LI-CODE lang="markup"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8" /&amp;gt;
  &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" /&amp;gt;
  &amp;lt;link rel="shortcut icon" href="//uwoperations.uwyo.edu/uwopsmaps/Documents/Icons/favicon.ico" /&amp;gt;
  &amp;lt;title&amp;gt;Query Attachments Buildings&amp;lt;/title&amp;gt;

  &amp;lt;style&amp;gt;
    html,
    body {
      height: 100%;
      width: 100%;
      margin: 0;
      padding: 0;
    }

    #attachmentsDiv {
      height: 100%;
      width: 30%;
      float: left;
      padding: 20px;
      overflow: auto;
      min-width: 240px;
    }

    #viewDiv {
      height: 100%;
      max-width: 70%;
    }

    .queryImg {
      width: 175px;
      padding-right: 5px;
    }
  &amp;lt;/style&amp;gt;

  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.29/esri/themes/dark/main.css" /&amp;gt;
  &amp;lt;link rel="stylesheet" href="css/allStyles.css"&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.29/"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;!--  &amp;lt;script src="js/map.js"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;script src="js/baseQueries.js"&amp;gt;&amp;lt;/script&amp;gt;--&amp;gt;
  
  &amp;lt;script&amp;gt;
      require ([
    "esri/Map",
    "esri/views/MapView",
    "esri/layers/FeatureLayer",
    "esri/widgets/Legend",
    "esri/PopupTemplate",
    "esri/popup/content/AttachmentsContent",
    "esri/popup/content/support/ImageMediaInfoValue",
    "esri/popup/content/ImageMediaInfo",
    "esri/popup/content/MediaContent"
], function (
        Map, MapView, FeatureLayer, Legend, PopupTemplate, AttachmentsContent, ImageMediaInfoValue, ImageMediaInfo, MediaContent
        )
{

    function showAtts (event)
    {
        view.hitTest (event).then (function getGraphics (response)
        {
            if (response.results.length) {
                graphic = response.results[0].graphic;
                console.log (graphic);

                lyrUrl = graphic.layer.url + "/0/";
                objID = graphic.getAttribute ('RemarkPoint.OBJECTID');
                attID = graphic.getAttribute ('RemarkPoint__ATTACH.ATTACHMENTID');
                imgUrlPath = lyrUrl + objID + "/attachments/" + attID;

                let imageMediaInfoValue = new ImageMediaInfoValue ({
                    sourceURL: imgUrlPath
                });

                let imageElement = new ImageMediaInfo ({
                    title:  "{LONGNAME}",
                    caption: "Photo",
                    value: imageMediaInfoValue
                });

                let mediaElement = new MediaContent ({
                    mediaInfos: [imageElement]
                });

                let template = new PopupTemplate ({
                    title:  "{LONGNAME}",
                    outFields: ["*"],
                    showAttachments: true,
                    content: [mediaElement]
                });
                layer.popupTemplate = template;

            }
        });
    }
    // get layer from online portal
    const layer = new FeatureLayer ({
        url:
                "https://uwoperations.uwyo.edu/hostgis/rest/services/CampusMap/CampusMap_Buildings/FeatureServer/0",
        //popupTemplate: template,
        outFields: ["*"]
    });
    // setup the map
    const map = new Map ({
        basemap: "topo-vector",
        layers: [layer]
    });
    const view = new MapView ({
        container: "viewDiv",
        map: map,
        center: [-105.567, 41.313193],
        zoom: 16

    });

    view.ui.add (new Legend ({view: view}), "bottom-left");

    let highlight;

    view.on ("click", function (event)
    {
        clearMap ();
        queryFeatures (event);
        showAtts (event);
    });

    function queryFeatures (screenPoint)
    {
        const point = view.toMap (screenPoint);

        // Query the for the object ids within 800m from where the user clicked
        layer.queryObjectIds ({
            geometry: point,
            spatialRelationship: "intersects",
            distance: 10,
            units: "meters",
            returnGeometry: false,
            outFields: ["*"]
        })
                .then (function (objectIds)
                {
                    if (!objectIds.length) {
                        showMessage ();
                        return;
                    }
                    // Highlight the query-area on the map
                    view.whenLayerView (layer).then (function (layerView)
                    {
                        if (highlight) {
                            highlight.remove ();
                        }
                        highlight = layerView.highlight (objectIds);
                    });
                    // Query the for the attachments from the object ids found
                    return layer.queryAttachments ({
                        attachmentTypes: ["image/jpeg"],
                        objectIds: objectIds
                    });
                })
                .then (function (attachmentsByFeatureId)
                {
                    if (!attachmentsByFeatureId) {
                        return;
                    }
                    if (Object.keys (attachmentsByFeatureId).length === 0) {
                        const infoP = document.createElement ("p");
                        infoP.innerHTML = "&amp;lt;b&amp;gt;There are no building image/jpeg attachments located in your query area.&amp;lt;/b&amp;gt;";
                        document.getElementById ("queryResults").appendChild (infoP);
                    }
                    // Display the attachments
                    Object.keys (attachmentsByFeatureId)
                            .forEach (function (objectId)
                            {
                                const attachments = attachmentsByFeatureId[objectId];
                                attachments.forEach (function (attachment)
                                {
                                    const image = document.createElement ("img");
                                    image.src=attachment.url;
                                    image.className = "queryImg";
                                    document.getElementById ("queryResults").appendChild (image);
                                });
                            });
                })
                .catch (function (error)
                {
                    showMessage ();
                })
    }

    function showMessage ()
    {
        clearMap ();
        const infoP = document.createElement ("p");
        infoP.innerHTML = "&amp;lt;b&amp;gt;There are no building image/jpeg attachments located in your query area. Please click within the feature layer to get results.&amp;lt;/b&amp;gt;";
        document.getElementById ("queryResults").appendChild (infoP);
    }

    // Clear attachments from div
    function clearMap ()
    {
        if (highlight) {
            highlight.remove ();
        }
        const att = document.getElementById ("queryResults");
        while (att.firstChild) {
            att.removeChild (att.firstChild);
        }
    }
});
  &amp;lt;/script&amp;gt;
  
  


&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  &amp;lt;div id="attachmentsDiv" class="esri-widget"&amp;gt;
    &amp;lt;h2 align="center"&amp;gt; &amp;lt;input id="LogoA" title="UW Website" type="image" alt="LogoA" src="Icons/UWWebA.png"
        onClick="javascript&amp;amp;colon; return popitup ('http://www.uwyo.edu/')" /&amp;gt;&amp;lt;/h2&amp;gt;
    &amp;lt;h2&amp;gt;Building Photos&amp;lt;/h2&amp;gt;
    &amp;lt;p&amp;gt;Click somewhere in the map to query for images of trees located on a block within 800m of your desired location.
    &amp;lt;/p&amp;gt;
    &amp;lt;div id="queryResults"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 05 Mar 2024 13:59:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/display-attachement-in-popup-template/m-p/1391075#M83858</guid>
      <dc:creator>RobertKirkwood</dc:creator>
      <dc:date>2024-03-05T13:59:29Z</dc:date>
    </item>
  </channel>
</rss>

