Hi Robert, thanks for your reply! I tried it but it doesn't work. I just show you a simple version with your suggestion. How to catch the click event from the map layer? Could you take a look at the sample code here? I cannot get that event if I use view.on().
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>ArcGIS API for JavaScript Tutorials: Create a JavaScript starter app</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
<link rel="stylesheet" href="https://js.arcgis.com/4.16/esri/themes/light/main.css">
<script src="https://js.arcgis.com/4.16/"></script>
<script>
require(["esri/Map", "esri/views/MapView", "esri/widgets/Search"], function (Map, MapView, Search) {
var map = new Map({
basemap: "topo-vector"
});
var view = new MapView({
container: "viewDiv",
center: [-168, 30],
zoom: 3,
map: map
});
var search = new Search({
view: view
});
view.ui.add(search, "top-right");
// search.on('search-complete', function(result){
// map.emit('click', {mapPoint: results[0].results[0].feature.geometry});
// });
search.on('search-complete', function(result)
{
map.emit('click', {mapPoint: result.results[0].results[0].feature.geometry});
view.on("click", function(event)
{
console.log(event.mapPoint);
});
});
});
</script>