Select to view content in your preferred language

Loading popup on click

73
2
9 hours ago
ArthurBazin
New Member

Hello,

My problem : 
I'm trying to display a popup with the location clicked each time the user click on the map.
But the popup is not displayed each time. It pops up only a few time and I can't find why.

My code :
I'm using ArcGIS SDK 4.33 + webcomponents.

Here is part of my code with comments :

// Map
self._arcgisMap = document.createElement("arcgis-map");

self._arcgisMap.viewOnReady().then(function() {
	self._map = self._arcgisMap.map;
	self._view = self._arcgisMap.view;
	console.debug("MapView Ready");
	
	self._view.popup.autoOpenEnabled = true;

	require(["esri/core/reactiveUtils"], function(reactiveUtils) {

		reactiveUtils.on(
			() => self._view,
			"click",
			(event) => {
				self._view.hitTest(event).then((response) => {
					const results = response.results;

					// If the click is on a feature : do not display popup
					const featureResults = results
						.map(r => r.graphic?.layer)
						.filter(layer => layer && layer.declaredClass === "esri.layers.FeatureLayer");

					const stageTouched = featureResults.some(layer => {
						return self._allLayers.some(layerInfo => layerInfo._sourceType === "stage" && layerInfo.url === layer.url);
					});

					if (!stageTouched) {

						const mapPoint= event.mapPoint;
						const lat = Math.round(mapPoint.latitude * 1000) / 1000;
						const lon = Math.round(mapPoint.longitude * 1000) / 1000;

						// This log is displayed each time I click on an empty location
						// So this code is working
						console.log("Click:", `Location: ${lat}°N, ${lon}°E`)

						// The popup is displayed only when it want...
						// I can't find why it is not displayed each time
						self._arcgisMap.view.popup.open({
							title: `Location: ${lat}°N, ${lon}°E`,
							location: mapPoint,
							visible: true
						})

					}
				})
			}
		);

	});

});

Behaviour and tests :
My map is working, I can navigate and I have no error into the console.

I've tryed the openPopup method but I have the same result.

 

Feel free to ask for more details if needed.

Thank you for your help.

 

0 Kudos
2 Replies
ArthurBazin
New Member

Ok, I needed to desable popups...

self._arcgisMap.popupDisabled = true;

Not easy to catch 😉 

ReneRubalcava
Esri Frequent Contributor

Yeah, any time you want to take over the Popup on click, you need to set this. Note, this only disables popup on click, it won't disable the Search popup.