首頁 / 浏覽問題 / 三維GIS / 問題詳情
polygon貼地(dì / de)面後,鼠标拾取的(de)不(bù)準
49EXP 2025年04月26日

       polygon: {
            hierarchy: m_poss,
            material: pcolor.withAlpha(0.2),
        },   繪制貼地(dì / de)面區域

鼠标在(zài)區域外點擊模型,也(yě)能識别到(dào)貼地(dì / de)面對象,

而(ér)且識别的(de)面對象有的(de)不(bù)是(shì)附近的(de)面。

cesium sdk  v11.1,   v11.2   ,v11.3,  都有這(zhè)個(gè)拾取問題,  

 scene.globe.depthTestAgainstTerrain = true;   設置true 也(yě)不(bù)行

1個(gè)回答

您好!

我本地(dì / de)使用 Cesium.SuperMapVersion 爲(wéi / wèi) 43549 的(de)包并未重現您所描述的(de)拾取不(bù)準的(de)情況。方便的(de)話您可以(yǐ)将您加載entity的(de)完整代碼發出(chū),我這(zhè)再嘗試複現。

此外,對于(yú)您這(zhè)種需要(yào / yāo)拾取到(dào)一(yī / yì /yí)類entity的(de)情況,建議可以(yǐ)使用id進行區别,實現可以(yǐ)參考如下代碼:

  const pickHandler = new Cesium.ScreenSpaceEventHandler(window.viewer.scene.canvas)
  pickHandler.setInputAction((event) => {
    const feature = window.viewer.scene.pick(event.position)
    if (Cesium.defined(feature)) {
      if (Object.prototype.hasOwnProperty.call(feature, 'id') && feature.id instanceof Cesium.Entity) {
        if (feature.id._id.startsWith('identify-area')) {
          const entity = viewer.entities.getById(feature.id._id)
          tableData.value = Object.keys(entity.info).map((key) => {
            return { name: key, info: entity.info[key] }
          })
          showInfo.value = true
        }
      }
    }
  }, Cesium.ScreenSpaceEventType.LEFT_CLICK)

希望可以(yǐ)幫助到(dào)您!

1,537EXP 2025年04月27日
是(shì)不(bù)是(shì)跟圖層模型有關, 我不(bù)加載模型。     點擊是(shì)沒問題的(de)

代碼是(shì)設置entity貼在(zài)S3M圖層上(shàng)的(de)嗎,可以(yǐ)設置entity的(de)polygon的(de)

classificationType: Cesium.ClassificationType.S3M_TILE

貼在(zài)S3M 模型表面

var tempEntity = {
        position: new Cesium.Cartesian3.fromDegrees(pos.x, pos.y, pos.z),
        label: {
            text: objModel.asset_name,
            scale: 0.3,
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 500),
            font: '30px monospace',
            disableDepthTestDistance: Number.POSITIVE_INFINITY,//是(shì)否遮擋模型
        },
        polyline: {
            positions: m_poss,
            width: 1.2, clampToGround: true,
            material: pcolor,
        },
        polygon: {
            hierarchy: m_poss,
            material: pcolor.withAlpha(0.2),
            classificationType: Cesium.ClassificationType.S3M_TILE
        },
        id: guid,
        ms_type: enType,
        ms_id: objModel.asset_id,
        ms_color: pcolor,
    };
    let objEntity = YWViewer.entities.add(tempEntity);

設置後,點 s3m模型空白處,  還是(shì)會拾取到(dào) entity 标簽
...