vue3+SuperMap iClient3D for Cesium实现地形开挖功能

本人小白一枚,文章如有问题还请各位大神评论区指出。整体实现是参考SuperMap iClient3D for Cesium的地形开挖功能源码~


前言

SuperMap iClient3D for Cesium中的Globe类提供了removeAllExcavationRegion方法,可移除开挖面(这里还可以通过选用removeAllExtractRegion方法实现地形抽出显示效果)。具体实现方法见下方代码。

一、主要功能

效果图:

 该功能主要实现通过指定开挖深度,绘制开挖区域从而实现地形开挖效果,如果配合地下管线数据效果更佳。

二、具体实现

1.HTML主要结构

代码如下:

<div class="content">
      <p>开挖深度(米):</p>
      <el-input size="small" v-model="depValue" placeholder="1~5000" />
      <el-button type="primary" @click="draw">绘 制</el-button>
      <el-button type="primary" @click="clear">清 除</el-button>
</div>

2.javascript

代码如下:

<script setup>
import { ref, onBeforeUnmount } from "vue";
import { useStore } from "vuex";
const store = useStore();
// let viewer = window.viewer;
let scene = viewer.scene;
let depValue = ref(50);
//绘制多边形
var handlerPolygon = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Polygon, 0);
//绘制
function draw() {
  //简单控制了一下深度取值范围
  if (depValue.value < 1 || depValue.value > 5000) {
    depValue.value = 50;
  }
  handlerPolygon.drawEvt.addEventListener(function (result) {
    if (!result.object.positions) {
      handlerPolygon.polygon.show = false;
      handlerPolygon.polyline.show = false;
      handlerPolygon.deactivate();
      handlerPolygon.activate();
      return;
    }
    //处理开挖区域坐标
    var array = [].concat(result.object.positions);
    var positions = [];
    for (var i = 0, len = array.length; i < len; i++) {
      var cartographic = Cesium.Cartographic.fromCartesian(array[i]);
      var longitude = Cesium.Math.toDegrees(cartographic.longitude);
      var latitude = Cesium.Math.toDegrees(cartographic.latitude);
      var h = cartographic.height;
      if (
        positions.indexOf(longitude) == -1 &&
        positions.indexOf(latitude) == -1
      ) {
        positions.push(longitude);
        positions.push(latitude);
        positions.push(h);
      }
    }
    //移除所有开挖面
    viewer.scene.globe.removeAllExcavationRegion();
    //添加地形开挖区域
    viewer.scene.globe.addExcavationRegion({
      name: "ggg",
      position: positions,
      height: depValue.value,
      transparent: false,
    });
    handlerPolygon.polygon.show = false;
    handlerPolygon.polyline.show = false;
    handlerPolygon.deactivate();
    handlerPolygon.activate();
  });
  handlerPolygon.activate();
}
//清除
function clear() {
  if (!handlerPolygon.polygon || !handlerPolygon.polyline) {
    return;
  }
  viewer.scene.globe.removeAllExcavationRegion();
  handlerPolygon.polygon.show = false;
  handlerPolygon.polyline.show = false;
  handlerPolygon.deactivate();
}

if (!scene.pickPositionSupported) {
  alert("不支持深度纹理,无法绘制多边形,地形开挖功能无法使用!");
}
onBeforeUnmount(() => {
  clear();
});
</script>

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值