<?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: Add a button to a popup using the default contents in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1342195#M82569</link>
    <description>&lt;P&gt;You can load the layer, then add your custom content to the PopupTemplate content.&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/odoe/pen/oNmjejJ?editors=1000" target="_blank" rel="noopener"&gt;https://codepen.io/odoe/pen/oNmjejJ?editors=1000&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        featureLayer.load().then(() =&amp;gt; {
          const customContent = new CustomContent({
            creator: () =&amp;gt; {
              return "&amp;lt;div&amp;gt;I am custom&amp;lt;/div&amp;gt;";
            }
          });
          
          featureLayer.popupTemplate.content.push(customContent);
          
          map.add(featureLayer);
        });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 26 Oct 2023 17:42:06 GMT</pubDate>
    <dc:creator>ReneRubalcava</dc:creator>
    <dc:date>2023-10-26T17:42:06Z</dc:date>
    <item>
      <title>Add a button to a popup using the default contents</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1341868#M82558</link>
      <description>&lt;P&gt;Hiya,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the latest version of the arcgis js api and cannot understand from the documentation how to set up a popupTemplate and populate it with the contents that has been configured in AGOL. The context is that I want to add a button to the popups on some layers, but not alter the popup in any other way (i.e. still display the default contents without configuring it in my application). Is this possible?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 11:50:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1341868#M82558</guid>
      <dc:creator>Char10773g</dc:creator>
      <dc:date>2023-10-26T11:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: Add a button to a popup using the default contents</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1341906#M82559</link>
      <description>&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html#actions" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html#actions&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Building a button a popup requires adding an action to the PopupTemplate. See the documentation above. I'm not sure if doing so will break the default PopupTemplate or not.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 12:57:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1341906#M82559</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2023-10-26T12:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: Add a button to a popup using the default contents</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1341913#M82560</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/677423"&gt;@JeffreyThompson2&lt;/a&gt;&amp;nbsp;! I have managed to add the button, but I am unsure of what I need to add in the contents so that the default fields/ configuration shows without me having to define them in code. Any ideas?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 13:03:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1341913#M82560</guid>
      <dc:creator>Char10773g</dc:creator>
      <dc:date>2023-10-26T13:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: Add a button to a popup using the default contents</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1341933#M82562</link>
      <description>&lt;P&gt;Assuming you are just using a basic table for your popup, you could build a loop that grabs all the fields in your feature layer and passes a name and label in to feildInfos, as part of field type content.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html#content" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-PopupTemplate.html#content&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 13:26:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1341933#M82562</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2023-10-26T13:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: Add a button to a popup using the default contents</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1341943#M82565</link>
      <description>&lt;P&gt;I'm not sure I want to display all the fields in the feature layer, but only those configured by those who publish the service from pro/ set on the layer in AGOL? Just wondering if there is any way to add a button to a popup but keep everything the same as it comes into the app so that those who manage the data can determine for each layer what fields gets shown and how, without having to interact with the application code.&lt;BR /&gt;I've set mapView.popup.defaultPopupTemplateEnabled to true as suggested in the content section of the PopupTemplate documentation, but the layer that I have applied my popupTemplate to with the button still opens a blank popup when I click on it.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 13:38:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1341943#M82565</guid>
      <dc:creator>Char10773g</dc:creator>
      <dc:date>2023-10-26T13:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: Add a button to a popup using the default contents</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1341994#M82566</link>
      <description>&lt;P&gt;I think the unfortunate truth is that doing anything to the PopupTemplate breaks the default popup template and makes you responsible for defining all the content.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 14:38:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1341994#M82566</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2023-10-26T14:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: Add a button to a popup using the default contents</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1342125#M82568</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/677423"&gt;@JeffreyThompson2&lt;/a&gt;&amp;nbsp;I was hoping the SDK would be more configurable than that but I fear you are right. Thanks for helping!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 16:42:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1342125#M82568</guid>
      <dc:creator>Char10773g</dc:creator>
      <dc:date>2023-10-26T16:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: Add a button to a popup using the default contents</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1342195#M82569</link>
      <description>&lt;P&gt;You can load the layer, then add your custom content to the PopupTemplate content.&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/odoe/pen/oNmjejJ?editors=1000" target="_blank" rel="noopener"&gt;https://codepen.io/odoe/pen/oNmjejJ?editors=1000&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        featureLayer.load().then(() =&amp;gt; {
          const customContent = new CustomContent({
            creator: () =&amp;gt; {
              return "&amp;lt;div&amp;gt;I am custom&amp;lt;/div&amp;gt;";
            }
          });
          
          featureLayer.popupTemplate.content.push(customContent);
          
          map.add(featureLayer);
        });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 17:42:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1342195#M82569</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2023-10-26T17:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Add a button to a popup using the default contents</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1342202#M82570</link>
      <description>&lt;P&gt;It is possible to do this if you don't mind using a bit of a hack to override the layer's &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#createPopupTemplate" target="_self"&gt;createPopupTemplate&lt;/A&gt; method.&amp;nbsp; If you replace the contents of the script tag starting on line 29 of the &lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=layers-featurelayer" target="_self"&gt;Intro to FeatureLayer Sample Sandbox&lt;/A&gt;&amp;nbsp;with the code below, and click the Refresh button at the top right, you'll see it works as described:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/core/reactiveUtils"
      ], (Map, MapView, FeatureLayer, reactiveUtils) =&amp;gt; {
        const map = new Map({
          basemap: "hybrid"
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          popup: {
            defaultPopupTemplateEnabled: true
          },
          extent: {
            // autocasts as new Extent()
            xmin: -9177811,
            ymin: 4247000,
            xmax: -9176791,
            ymax: 4247784,
            spatialReference: 102100
          }
        });

        /********************
         * Add feature layer
         ********************/

        // Carbon storage of trees in Warren Wilson College.
        const featureLayer = new FeatureLayer({
          url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
        });

        featureLayer._esriCreatePopupTemplate = featureLayer.createPopupTemplate;
        featureLayer.createPopupTemplate = function (options) {
          var popupTemplate = this._esriCreatePopupTemplate(options);
          popupTemplate.actions = [
            {
              title: "My Action",
              id: "my-action",
              className: "esri-icon-locate-circled"
            }
          ];

          return popupTemplate;
        };

        reactiveUtils.when(
          () =&amp;gt; view.popup?.actions,
          () =&amp;gt; {
            view.popup.on("trigger-action", function (evt) {
              alert(evt.action.title + " :: " + evt.action.id);
            });
          }
        );

        map.add(featureLayer);
      });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The main part of this is seen on lines 36-48 above,&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 17:49:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1342202#M82570</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2023-10-26T17:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: Add a button to a popup using the default contents</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1342545#M82585</link>
      <description>&lt;P&gt;Thanks very much! Great insight! Works perfectly &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 08:49:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1342545#M82585</guid>
      <dc:creator>Char10773g</dc:creator>
      <dc:date>2023-10-27T08:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: Add a button to a popup using the default contents</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1342585#M82586</link>
      <description>&lt;P&gt;I personally avoid using `_esriCreatePopupTemplate` and instead do something along the lines of what Rene suggested but slightly modified to add an action instead of custom content. Undocumented properties and methods may change at any time without any notification.&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/sagewall/pen/rNPObKK" target="_blank" rel="noopener"&gt;https://codepen.io/sagewall/pen/rNPObKK&lt;/A&gt;&lt;/P&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;&lt;LI-CODE lang="javascript"&gt;            const map = new Map({
				basemap: "hybrid"
			});
			const view = new MapView({
				center: [-105, 43],
				container: "viewDiv",
				map,
				zoom: 5
			});

			const featureLayer = new FeatureLayer({
				portalItem: {
					id: "afc1428f16f94579950431add9625b43"
				}
			});
			featureLayer.load().then(() =&amp;gt; {
				let zoomOutAction = {
					title: "Zoom out",
					id: "zoom-out",
					className: "esri-icon-zoom-out-magnifying-glass"
				};
				featureLayer.popupTemplate.actions = [zoomOutAction];
				map.add(featureLayer);
			});
			
			function zoomOut() {
				view.goTo({
					center: view.center,
					zoom: view.zoom - 2
				});
			}
			
			reactiveUtils.on(
				() =&amp;gt; view.popup,
				"trigger-action",
				(event) =&amp;gt; {
					if (event.action.id === "zoom-out") {
						zoomOut();
					}
				});&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 11:42:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1342585#M82586</guid>
      <dc:creator>Sage_Wall</dc:creator>
      <dc:date>2023-10-27T11:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: Add a button to a popup using the default contents</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1344031#M82637</link>
      <description>&lt;P&gt;Very neat, thank you&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 18:01:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1344031#M82637</guid>
      <dc:creator>Char10773g</dc:creator>
      <dc:date>2023-10-31T18:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Add a button to a popup using the default contents</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1349188#M82760</link>
      <description>&lt;P&gt;Hi everyone! This solution works perfectly, but how can I save info of that feature selected when the action triggers?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2023 15:16:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/add-a-button-to-a-popup-using-the-default-contents/m-p/1349188#M82760</guid>
      <dc:creator>MatiasTonelli1</dc:creator>
      <dc:date>2023-11-14T15:16:09Z</dc:date>
    </item>
  </channel>
</rss>

