在Arcgis 3.X中,點(diǎn)擊事件一般可放置于layer,graphic或地圖上括荡,當(dāng)獲取圖片的點(diǎn)擊事件時(shí),就給該組圖片添加點(diǎn)擊事件即可溉旋。
但是在Arcgis 4.X中畸冲,點(diǎn)擊事件只放置于地圖上,即view,mapView,sceneView上观腊,此時(shí)直接獲取點(diǎn)擊事件返回的屬性并不能知曉該點(diǎn)擊處是否是圖片召夹,好在4.X中提供了一個(gè)hitTest()函數(shù),該函數(shù)可判斷點(diǎn)擊處是否有圖片存在恕沫,從而返回圖片信息监憎。
圖片上傳不上來(lái)了,自己可根據(jù)下方示例進(jìn)行嘗試即可婶溯。
官網(wǎng)給出的示例:
// Get the screen point from the view's click event
view.on("click", function(event) {
var screenPoint = {
x: event.x,
y: event.y
};
// Search for graphics at the clicked location
view.hitTest(screenPoint).then(function(response) {
var result = response.results[0];
if (result) {
var lon = result.mapPoint.longitude;
var lat = result.mapPoint.latitude;
console.log("Hit surface at (" + lon + ", " + lat + "), graphic:", result.graphic || "none");
}
});
});