I have ArcGIS for javascript 4.24 and the following code where i want to display a popup if the user clicks outside of a polygon.
view.on("click", function (evt) {
view.hitTest(evt).then((response) => {
// check if an existing marker is selected
if (response.results.length && response.results[0].graphic.popupTemplate != null) {
// do nothing as the popup is set to automatically open on click event
} else {
let newPoint = view.toMap({
x: evt.x,
y: evt.y
});
let newMarker = new Graphic(newPoint, markerSymbol);
positionLayer.removeAll();
if (!geometryEngine.contains(boundaryPolygon, newPoint)) {
view.openPopup({
title: "some title",
content: "This location is outside the boundary",
location: newPoint
});
} else {
// Custom data handling
}
}
});
});
However the openPopup function is only available in ArcGIS v 4.27
How do I open a popup in ArcGIS v 4.24? I tried the following and it doesn't work either:
view.popup.open({
title: "some title",
content: "This location is outside the boundary",
location: newPoint
});
I think you just need to disable popup auto open by changing the popup property
autoOpenEnabledtofalse.Important: The action needed to disable popup auto open change from the popup (like mention above) to the view (property
popupEnabled) in version 4.27 (to be fair it is bit different the logic also).