Select to view content in your preferred language

Add a button to a popup using the default contents

1500
12
Jump to solution
10-26-2023 04:50 AM
Char10773g
New Contributor III

Hiya, 

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?

 

Thanks

0 Kudos
12 Replies
Sage_Wall
Esri Contributor

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.

https://codepen.io/sagewall/pen/rNPObKK

 

 

 

            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(() => {
				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(
				() => view.popup,
				"trigger-action",
				(event) => {
					if (event.action.id === "zoom-out") {
						zoomOut();
					}
				});

 

 

 

 

Char10773g
New Contributor III

Very neat, thank you

0 Kudos
MatiasTonelli1
New Contributor II

Hi everyone! This solution works perfectly, but how can I save info of that feature selected when the action triggers?

0 Kudos