Popup components provide an easy way to add interactivity to your
Configure the Map and Popup components
Create a Map component and set the basemap, center, and zoom attributes.
The map component currently uses the Popup widget by default.
To utilize the Popup component instead, add an <arcgis-popup> as a child of the Map component in the “popup” slot.
Since the Popup component is not tied to any layers in this example, set the popup-disabled attribute on the Map component to disable the default popup behavior.
<arcgis-map basemap="streets-navigation-vector" zoom="12" center="-71.6899, 43.7598" popup-disabled> <arcgis-popup slot="popup"></arcgis-popup></arcgis-map>Listen to the map’s click event and display the popup at the clicked location
To display the popup component with location information, add an event listener to the map component’s arcgisViewClick event and get the longitude and latitude of the clicked location.
Then set the location and the heading properties and then set the open property to true to display the popup.
viewElement.addEventListener("arcgisViewClick", (event) => { const { mapPoint } = event.detail; const lat = Math.round(mapPoint.latitude * 1000) / 1000; const lon = Math.round(mapPoint.longitude * 1000) / 1000; popupComponent.location = mapPoint; popupComponent.heading = `Reverse geocode: [${lon}, ${lat}]`; popupComponent.open = true; const params = { location: mapPoint, }; // Execute a reverse geocode using the clicked location locator .locationToAddress(locatorUrl, params) .then((response) => { // If an address is successfully found, show it in the popup's content popupComponent.content = response.address; }) .catch(() => { // If the promise fails and no result is found, show a generic message popupComponent.content = "No address was found for this location"; });});