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
Solved! Go to Solution.
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();
}
});
Very neat, thank you
Hi everyone! This solution works perfectly, but how can I save info of that feature selected when the action triggers?