earthSDK之点添加点击事件

earthSDK之点添加点击事件

点击事件代码:

//点击事件
            pin.onclick = () => {
                console.log('点击确认')
            }

注意:

点击事件功能需在创建底图时全局打开点击事件权限,否则点击事件不生效。

打开权限代码:(添加在     let earth = new XE.Earth('earthContainer'     之后);

earth.interaction.picking.enabled = true
earth.interaction.picking.hoverEnable = false

添加点代码:

   // 绘制点位
        createODPoints(earth, item, imgUrl) {
            // 度转弧度
            function DtoR(val) {
                let r = (val * Math.PI) / 180
                return r
            }
            const objConfig = {
                name: 'Pin1',
                xbsjType: 'Pin',
                position: [DtoR(120.48), DtoR(39.52), 500],
                near: 20000,
                imageUrl: '/images/earth/img/station.png',
                disableDepthTestDistance: 0
            }
            const pin = new XE.Obj.Pin(earth)
            pin.xbsjFromJSON(objConfig)
            //点击事件
            pin.onclick = () => {
                console.log('点击确认')
            }
            return pin
        }

钻研不易,转载请注明出处......

原文地址:https://www.cnblogs.com/s313139232/p/13386868.html