首页 / 浏览问题 / 三维GIS / 问题详情
polygon贴地面后,鼠标拾取的不准
49EXP 2025年04月26日

       polygon: {
            hierarchy: m_poss,
            material: pcolor.withAlpha(0.2),
        },   绘制贴地面区域

鼠标在区域外点击模型,也能识别到贴地面对象,

而且识别的面对象有的不是附近的面。

cesium sdk  v11.1,   v11.2   ,v11.3,  都有这个拾取问题,  

 scene.globe.depthTestAgainstTerrain = true;   设置true 也不行

1个回答

您好!

我本地使用 Cesium.SuperMapVersion 为 43549 的包并未重现您所描述的拾取不准的情况。方便的话您可以将您加载entity的完整代码发出,我这再尝试复现。

此外,对于您这种需要拾取到一类entity的情况,建议可以使用id进行区别,实现可以参考如下代码:

  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)

希望可以帮助到您!

1,557EXP 2025年04月27日
是不是跟图层模型有关, 我不加载模型。     点击是没问题的

代码是设置entity贴在S3M图层上的吗,可以设置entity的polygon的

classificationType: Cesium.ClassificationType.S3M_TILE

贴在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,//是否遮挡模型
        },
        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模型空白处,  还是会拾取到 entity 标签
...