关于yarn:Cesium加载广告牌三

27次阅读

共计 1361 个字符,预计需要花费 4 分钟才能阅读完成。

Cesium 加载广告牌(三)

加载实现广告牌之后,如何对广告牌进行操作?这里实现鼠标左键点击获取广告牌信息的性能。

在加载广告牌的过程中,曾经对广告牌进行了许多属性的设置,然而并没有对广告牌的惟一值进行标准。设置惟一值并不是在 billboard 的属性内设置,而是在外层的 Entity 内进行申明。同时 Entity 中也有 name 属性。这里须要留神的是 id 是惟一值,不能与其余 id 值雷同,name 能够。

let bill = new Cesium.Entity({
    id:"200222",
    position: new Cesium.Cartesian3.fromDegrees(120.62521517, 31.42803100),
    billboard: {
        image: "./img/laboratory.png",
        horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
        verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
        scale: 1,
        scaleByDistance: new Cesium.NearFarScalar(30000, 1, 45000, 0.4),
        heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
        disableDepthTestDistance: Number.POSITIVE_INFINITY,
    }
})

这里有一点须要强调,代买只是申明了一个 Entity 实例,并没有进行增加,因而须要将 Entity 增加仅 viewer 实体中才能够应用。

viewer.entities.add(bill)

如果写成 viewer.entities.add({})模式,就不须要额定增加。

增加实现后须要写入点击事件。


let handlerPoint = new Cesium.ScreenSpaceEventHandler(window.viewer.scene.canvas);
  handlerPoint.setInputAction(function(event) {},Cesium.ScreenSpaceEventType.LEFT_CLICK)

在点击事件外面采纳 viewer.scene.pick() 办法,通过坐标地位,拾取实体(Entity),图元(Primitive),3DTiles对象,返回的是 scene 中指定地位最上层的对象。例如点击获取 Entity 的 pick 对象,通过 pick.id 能够拾取以后的 entity 对象。拾取后,能够用于扭转对象的属性参数,如色彩,图片等。


let handlerPoint = new Cesium.ScreenSpaceEventHandler(window.viewer.scene.canvas);
    handlerPoint.setInputAction(function(event) {const pick = window.viewer.scene.pick(event.position);
    console.log(pick)
},Cesium.ScreenSpaceEventType.LEFT_CLICK)

这里的 pick 中就存储了广告牌的信息,而后依据获取的广告牌的 id 不同,能够进行接下来的其余操作。

正文完
 0