直接上代码
this.view.on("pointer-move", function (evt) {
var screenPoint = {
x: evt.x,
y: evt.y
};
_this.view.hitTest(screenPoint)
.then(function (response) {
var mapPoint = _this.view.toMap(screenPoint);
if (response.results.length > 0) {
window.clearTimeout(_this.timeOut);
_this.timeOut = "";
var name = response.results[0].graphic.attributes.stnm;
_this.view.popup.open({
location: mapPoint,
title: "站名",
content: `<span style="color:red;">${name}</span>`
});
} else {
_this.timeOut || (_this.timeOut = setTimeout(() => {
_this.view.popup.close();
}, 500))
}
});
})
注:注册该事件,并声明全局变量timeOut