<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>Popup for WMS - 4.15</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.15/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.15/"></script>
<script>
var view;
require([
"esri/Map",
"esri/layers/WMSLayer",
"esri/views/MapView",
], function (Map, WMSLayer, MapView) {
var map = new Map({
basemap: "gray",
});
view = new MapView({
container: "viewDiv",
map: map,
center: [7, 51.5],
zoom: 9,
});
var layer = new WMSLayer({
url: "https://www.wms.nrw.de/wms/krankenhaus",
featureInfoFormat: "text/html",
featureInfoUrl: "https://www.wms.nrw.de/wms/krankenhaus?",
sublayers: [
{
name: "krankenhaus",
popupEnabled: true,
},
],
});
map.add(layer);
view.when(function () {
view.popup.autoOpenEnabled = false;
view.on("click", function (event) {
var info = layer.getFeatureInfo();
console.log(info)
view.popup.open({
location: event.mapPoint
});
});
});
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
Add the lines which add the click event handler (form line 59) to your code. The popup should open at the click event's location