gis地图鼠标悬浮文字显示

直接上代码

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: `"color:red;">${name}`
                    });
                } else {
                    _this.timeOut || (_this.timeOut = setTimeout(() => {
                        _this.view.popup.close();
                    }, 500))
                }
            });
    })

注:注册该事件,并声明全局变量timeOut

你可能感兴趣的:(GIS)