Hi,
I am adding a popup by clicking the map. It is not showing up with the first click, but shows up with subsequent clicks. Any idea why this is happening? Here is the code.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta
name="viewport"
content="initial-scale=1, maximum-scale=1,user-scalable=no"
/>
<title>
Custom popup content | Sample | ArcGIS API for JavaScript 4.24
</title>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.24/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.24/"></script>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<script>
require([
"esri/Map",
"esri/views/MapView"
], (
Map,
MapView
) => {
const map = new Map({
basemap: "topo-vector"
});
const view = new MapView({
map: map,
container: "viewDiv",
zoom: 4,
center: [-98, 38.5]
});
view.when(() => {
view.on("click", function(event){
view.popup.autoOpenEnabled = false;
view.popup.title = "ArcGIS";
view.popup.content="Hello";
view.popup.visible = false;
view.popup.open({shouldFocus:false});
view.popup.location=event.mapPoint;
});
});
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
Hi @MappingGal -
Looks like you need to pull view.popup.autoOpenEnabled = false; outside of your click event handler. I also moved the location of the popup to be set inside the open method.
Check out your code with these udpates here: https://codepen.io/laurenb14/pen/dymPmaB?editors=1000
Hope this helps!
Thankyou so much I was facing the same issue, but your solution worked for me. Such a silly mistake from my side.