<?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 Adding a div to the popup template in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-a-div-to-the-popup-template/m-p/1107813#M74970</link>
    <description>&lt;P&gt;I am trying to add a div as the content for the &lt;STRONG&gt;popup template&amp;nbsp;&lt;/STRONG&gt;which contains only a photo. I have been using this kind of method in the past but now I can't get it to work for some reason.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var photoContentHtml = "";
photoContentHtml = "&amp;lt;img onerror='this.onerror=null;this.src=\'/layerimages/noimage.jpg\'' src='http://app.org/layerimages/{photo}' width='200px' height='150px'&amp;gt;";&lt;/LI-CODE&gt;&lt;P&gt;and this has always yielded results. I am able to create the div and assign it to a variable as a string and then use the variable as a content for the popup template. For some reason it doesn't work in this scenario so now I am doing it this way, slightly modified.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var disLayer;
var photoContent = "";
var photoContentHtml = "";
var photoId;
var photo;


    // Get the screen point from the view's click event
    view.on("click", function (event) {

        view.hitTest(event).then(function (response) {

            if (response.results.length) {
                let graphic = response.results.filter(function (result) {
                // check if the graphic belongs to the layer of interest
                return result.graphic.layer === disLayer;
                })[0].graphic;

                                                
                photoId = graphic.attributes.objectid;
                                                
                $.get(getBaseUrl() + "enterprises/GetEnterprisePhoto?id=" + photoId, function (data, status) {
              
                if (data == null) {
                                                        
                    photoContent = "&amp;lt;img src='http://app.org/layerimages/noimage.jpg' width='200px' height='150px'&amp;gt;";
                    photoContentHtml = photoContent;

                    }
                    else {
                    photo = data;
                    photoContent = "&amp;lt;img src='http://app.org/layerimages/" + photo + "' width='200px' height='150px'&amp;gt;";
                    photoContentHtml = photoContent;

                    }

                });
            }
        });
    });



        //Check is the layer is queryable
        if (restService.label.includes("*")) {
            disLayer = new FeatureLayer({
            title: restService.label,
            url: restService.restServiceLink,
            outFields: ["*"], // Return all fields so it can be queried client-side
            popupTemplate: {  // Enable a popup
                title: "&amp;lt;b&amp;gt;" + restService.label + ": {" + restService.searchAndPopupFieldName + "} &amp;lt;/b&amp;gt;",
                content: photoContentHtml
                }
            });
		}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;but this doesn't even show the div inside the popup template. Any pointers on how to proceed for this desperate person? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Oct 2021 07:26:13 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-10-15T07:26:13Z</dc:date>
    <item>
      <title>Adding a div to the popup template</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-a-div-to-the-popup-template/m-p/1107813#M74970</link>
      <description>&lt;P&gt;I am trying to add a div as the content for the &lt;STRONG&gt;popup template&amp;nbsp;&lt;/STRONG&gt;which contains only a photo. I have been using this kind of method in the past but now I can't get it to work for some reason.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var photoContentHtml = "";
photoContentHtml = "&amp;lt;img onerror='this.onerror=null;this.src=\'/layerimages/noimage.jpg\'' src='http://app.org/layerimages/{photo}' width='200px' height='150px'&amp;gt;";&lt;/LI-CODE&gt;&lt;P&gt;and this has always yielded results. I am able to create the div and assign it to a variable as a string and then use the variable as a content for the popup template. For some reason it doesn't work in this scenario so now I am doing it this way, slightly modified.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var disLayer;
var photoContent = "";
var photoContentHtml = "";
var photoId;
var photo;


    // Get the screen point from the view's click event
    view.on("click", function (event) {

        view.hitTest(event).then(function (response) {

            if (response.results.length) {
                let graphic = response.results.filter(function (result) {
                // check if the graphic belongs to the layer of interest
                return result.graphic.layer === disLayer;
                })[0].graphic;

                                                
                photoId = graphic.attributes.objectid;
                                                
                $.get(getBaseUrl() + "enterprises/GetEnterprisePhoto?id=" + photoId, function (data, status) {
              
                if (data == null) {
                                                        
                    photoContent = "&amp;lt;img src='http://app.org/layerimages/noimage.jpg' width='200px' height='150px'&amp;gt;";
                    photoContentHtml = photoContent;

                    }
                    else {
                    photo = data;
                    photoContent = "&amp;lt;img src='http://app.org/layerimages/" + photo + "' width='200px' height='150px'&amp;gt;";
                    photoContentHtml = photoContent;

                    }

                });
            }
        });
    });



        //Check is the layer is queryable
        if (restService.label.includes("*")) {
            disLayer = new FeatureLayer({
            title: restService.label,
            url: restService.restServiceLink,
            outFields: ["*"], // Return all fields so it can be queried client-side
            popupTemplate: {  // Enable a popup
                title: "&amp;lt;b&amp;gt;" + restService.label + ": {" + restService.searchAndPopupFieldName + "} &amp;lt;/b&amp;gt;",
                content: photoContentHtml
                }
            });
		}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;but this doesn't even show the div inside the popup template. Any pointers on how to proceed for this desperate person? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 07:26:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-a-div-to-the-popup-template/m-p/1107813#M74970</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-10-15T07:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a div to the popup template</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-a-div-to-the-popup-template/m-p/1107845#M74973</link>
      <description>&lt;P&gt;I decided to change a few things so here is take two &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;I am using a function&amp;nbsp;to create a simple node and display it in the popup template content as instructed &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html#content" target="_self"&gt;here&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;disLayer = new FeatureLayer({
    title: restService.label,
    url: restService.restServiceLink,
    outFields: ["*"], // Return all fields so it can be queried client-side
    popupTemplate: {  // Enable a popup
        title: "&amp;lt;b&amp;gt;" + restService.label + ": {" + restService.searchAndPopupFieldName + "} &amp;lt;/b&amp;gt;",
        content: setContentInfo
        }

    });
	
	function setContentInfo() {
        let node = domConstruct.create("div", { innerHTML: "test test test" });
        return node;
    }&lt;/LI-CODE&gt;&lt;P&gt;but this also doesn't insert a the "test" string as a content in the popup template.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2021 10:25:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-a-div-to-the-popup-template/m-p/1107845#M74973</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-10-15T10:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a div to the popup template</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-a-div-to-the-popup-template/m-p/1108256#M74982</link>
      <description>&lt;P&gt;Works fine if you pass an element like so:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// rest of your code above
//Check is the layer is queryable
if (restService.label.includes("*")) {
  disLayer = new FeatureLayer({
  title: restService.label,
  url: restService.restServiceLink,
  outFields: ["*"], // Return all fields so it can be queried client-side
  popupTemplate: {  // Enable a popup
    title: "&amp;lt;b&amp;gt;" + restService.label + ": {" + restService.searchAndPopupFieldName + "} &amp;lt;/b&amp;gt;",
    content: setContentInfo
    }
  });
}

function setContentInfo() {
  let div = document.createElement("div");
  div.innerHTML = "test test test";
  return div;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Oct 2021 19:19:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-a-div-to-the-popup-template/m-p/1108256#M74982</guid>
      <dc:creator>RyanGatchell1</dc:creator>
      <dc:date>2021-10-17T19:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a div to the popup template</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-a-div-to-the-popup-template/m-p/1317296#M81938</link>
      <description>&lt;P&gt;I tried to create the element in a function then return it, but it returns &lt;SPAN&gt;[object HTMLDivElement]&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function returnElement(href) {
          var node = document.createElement("div", { innerHTML: "Vai all'evento"});
          node.setAttribute("class", "Arcgis-Map-Popup-GoTo-Button");
          node.setAttribute("onclick", "window.location.href = " + href);
          return node;
        };
        // Setta il template per i popup dei punti evento
        var popup_event_template = {
          title: "{Name}",
          content: "{Description}&amp;lt;br&amp;gt;" + returnElement("{href}")
        }&lt;/LI-CODE&gt;&lt;P&gt;These are the parameters i set&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var attributes = {
          Name: "Graphic",
          Description: "I am a point",
          Href: "nevent.one"
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 10 Aug 2023 10:38:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/adding-a-div-to-the-popup-template/m-p/1317296#M81938</guid>
      <dc:creator>LorenzoMara</dc:creator>
      <dc:date>2023-08-10T10:38:00Z</dc:date>
    </item>
  </channel>
</rss>

