Cesium 加载倾斜摄影模型记录(osgb切片,shp拔高切片、模型加载、鼠标移入选中、点选查询功能)

一、shp模型拔高切片

shp如果数据量过大,做分类处理,加载会异常慢,所以需要先对其进行分割之后再进行切片(用qgis即可)

切片规则设置

1、记得勾选构造底面 

2、如果你的shp数据中有高度字段的话,可以选择高度字段,如果没有的话,设置固定高度的高度比你的模型稍微高一点,可以保证包着整个模型,也可以对shp数据稍微做一些缓冲区设置,使其可以前后左右包围整个模型

3、如果你的shp数据原始中文编码是GBK的话,最好提前通过QGIS或者ArcGis转成UTF-8

 

选择输出目录,点击确认即可 

二、osgb切片

设置,选择xml,里面存储着位置信息和投影信息等 

 

三、Cesium 代码加载实现

加载3dtiles模型

     let defaultTilesetConfig = {
        skipLevelOfDetail: true,
        preferLeaves: true,
        maximumMemoryUsage: 256, // 内存分配变小有利于倾斜摄影数据回收,提升性能体验
        // debugShowContentBoundingVolume: true,
        baseScreenSpaceError: 256,
        maximumScreenSpaceError: 16, // 数值加大,能让最终成像变模糊
        skipScreenSpaceErrorFactor: 16,
        skipLevels: 2,//lod级别加载
        immediatelyLoadDesiredLevelOfDetail: true,
        loadSiblings: true, // 如果为true则不会在已加载完概况房屋后,自动从中心开始超清化房屋
        cullWithChildrenBounds: true,
        cullRequestsWhileMoving: true,
        cullRequestsWhileMovingMultiplier: 1, // 值越小能够更快的剔除
        preloadWhenHidden: true,
        progressiveResolutionHeightFraction: 1, // 数值偏于0能够让初始加载变得模糊
        dynamicScreenSpaceErrorDensity: 1, // 数值加大,能让周边加载变快
        dynamicScreenSpaceErrorFactor: 1, // 不知道起了什么作用没,反正放着吧先
        dynamicScreenSpaceError: true // 根据测试,有了这个后,会在真正的全屏加载完之后才清晰化房屋
      }
      //1osgb
      let osgb1 = new Cesium.Cesium3DTileset({
        url: `/upload/3dtiles/cfgzz_3dtiles/tileset.json`,
        ...defaultTilesetConfig
      });

      // 超出可视区的瓦片进行销毁,提高性能
      osgb1.tileLoad.addEventListener(function (tile) {
        tile.tileset.trimLoadedTiles();
      });
      // 贴地处理
      this.handle3dtilesHeight(osgb1, 10.0)
      viewer.scene.primitives.add(osgb1);
      //定位到当前模型位置
      viewer.zoomTo(osgb1)

用shp切片的3dtiles做分类处理

      classificationVector = new Cesium.Cesium3DTileset({
        url: config3dtilesJson.vector,
        classificationType: Cesium.ClassificationType.CESIUM_3D_TILE
      });
      classificationVector.style = new Cesium.Cesium3DTileStyle({
        color: "rgba(255, 255, 255, 0.01)",
        // color: "rgba(0, 255, 0, 0.8)",
      });
      viewer.scene.primitives.add(classificationVector);

 添加鼠标移入选中模型效果


      const highlighted = {
        feature: undefined,
        originalColor: new Cesium.Color(),
      };
      viewer.screenSpaceEventHandler.setInputAction(function onMouseMove(
        movement
      ) {
        // If a feature was previously highlighted, undo the highlight
        if (Cesium.defined(highlighted.feature)) {
          highlighted.feature.color = highlighted.originalColor;
          highlighted.feature = undefined;
        }
        // Pick a new feature
        const pickedFeature = viewer.scene.pick(movement.endPosition);
        if (!(pickedFeature instanceof Cesium.Cesium3DTileFeature)) return;
        if (!Cesium.defined(pickedFeature)) return;
        // Highlight the feature if it's not already selected.
        if (pickedFeature !== selected.feature) {
          highlighted.feature = pickedFeature;
          Cesium.Color.clone(
            pickedFeature.color,
            highlighted.originalColor
          );
          pickedFeature.color = new Cesium.Color(1, 1, 0, 0.2);
        }
      },
        Cesium.ScreenSpaceEventType.MOUSE_MOVE);

 添加鼠标点击展示弹窗效果

      let _this = this


      // Information about the currently selected feature
      const selected = {
        feature: undefined,
        originalColor: new Cesium.Color(),
      };

      // Get default left click handler for when a feature is not picked on left click
      const clickHandler = viewer.screenSpaceEventHandler.getInputAction(
        Cesium.ScreenSpaceEventType.LEFT_CLICK
      );

      // Color a feature on selection and show metadata in the InfoBox.
      viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(
        movement
      ) {
        // 隐藏模态框 
        _this.showMLXCModal = false
        // If a feature was previously selected, undo the highlight
        if (Cesium.defined(selected.feature)) {
          selected.feature.color = selected.originalColor;
          selected.feature = undefined;
        }
        // Pick a new feature
        const pickedFeature = viewer.scene.pick(movement.position);
        if (!(pickedFeature instanceof Cesium.Cesium3DTileFeature)) {
          return;
        }
        if (!Cesium.defined(pickedFeature)) {
          clickHandler(movement);
          return;
        }
        // Select the feature if it's not already selected
        if (selected.feature === pickedFeature) {
          return;
        }
        selected.feature = pickedFeature;

        if (!(pickedFeature instanceof Cesium.Cesium3DTileFeature))  return;


        var position = viewer.scene.pickPosition(movement.position);
        let cartographic = Cesium.Cartographic.fromCartesian(position);
        // 有值则展示模态框,模态框的位置信息
        _this.showMLXCModal = true
        _this.positionXY.lng = Cesium.Math.toDegrees(
          cartographic.longitude
        );
        _this.positionXY.lat = Cesium.Math.toDegrees(cartographic.latitude);
        // height=viewer.camera.positionCartographic.height.toFixed(0);
        _this.positionXY.height = cartographic.height;

        // 获取属性信息
        _this.propertiesObj = pickedFeature.getPropertyNames()
        

        // Save the selected feature's original color
        if (pickedFeature === highlighted.feature) {
          Cesium.Color.clone(
            highlighted.originalColor,
            selected.originalColor
          );
          highlighted.feature = undefined;
        } else {
          Cesium.Color.clone(pickedFeature.color, selected.originalColor);
        }
        // Highlight newly selected feature
        pickedFeature.color = new Cesium.Color(0, 1, 0, 0.2);
        // Set feature infobox description

      },
        Cesium.ScreenSpaceEventType.LEFT_CLICK);

四、实现过程中遇到的问题记录

1、分类未正常显示,原因:shp数据量过大,导致分类要做很多算法,加载不出来

2、中文乱码问题,因为shp原始数据是gbk格式,即便切片时候选择了gbk编码但是依然未生效

3、鼠标移入,选中区域跑出来,如下图:原因是shp切片的时候没有构造底面

五、注意事项

电脑需要有显卡,配置越高越好

六、优化考虑

模型区域比较大的话,如果一些shp数据变化,就要对所有的shp数据重新切片,比较麻烦,所以有两种方式可以避免这种情况发生

1、请求接口的方式获取数据,通过primite做分类处理,这样不论数据怎么变化都不需要重新处理

2、shp上只存储唯一键值,其他信息通过唯一键值去获取数据

  • 10
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
倾斜摄影模型的过程,我们可以使用Cesium来实现。Cesium是一种基于WebGL的三维地理可视化引擎,可以轻松和显示各种地理数据。 在倾斜摄影模型之前,我们需要准备好模型的相关数据。这些数据通常包括影像数据、地面控制点、摄影测量数据等。接下来,我们可以使用一些工具(比如Pix4D、Agisoft Metashape等)来对这些数据进行处理,生成倾斜摄影模型的各个组成部分。 一旦我们拥有了倾斜摄影模型的数据,我们可以利用Cesium和显示它们。首先,我们需要创建一个Cesium的场景,并将其显示在Web页面上。接着,我们可以使用Cesium的3D Tiles功能倾斜摄影模型的数据。 在过程Cesium会将倾斜摄影模型的数据转换为其内部的3D Tiles格式,并进行分层,以优化性能和内存使用。一旦完成,Cesium会自动进行摄影模型的渲染,并显示在场景。 除了倾斜摄影模型的数据,Cesium还提供了一些功能来控制和操作模型。我们可以使用Cesium的相机控制功能来调整视角和缩放级别,以便更好地查看倾斜摄影模型。此外,我们还可以添交互式的元素(比如点、线、面等)和标记,以便进行更详细的分析和演示。 总之,通过使用Cesium,我们可以轻松和显示倾斜摄影模型,实现更丰富和交互式的地理可视化效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值