guonan
2025-04-18 1dbf51ab46b6a96daa4b75afa58eb9d1c9570a54
src/utils/tools.js
@@ -23,6 +23,9 @@
  elevationTool: null,
  rainEffect: null,
  snowEffect: null, // 新增雪效果实例
  regionTerrain: null,
  polygonPosition: [],
  PolygonArr: [],
  init(earthCtrl) {
    this.earthCtrl = earthCtrl;
@@ -36,13 +39,13 @@
    return new Cesium.Color(r, g, b, 1.0);
  },
  // 清除天气特效
  delRain(){
  delRain() {
    if (this.rainEffect) {
      this.rainEffect.destroy()
      this.rainEffect = null
    }
  },
  delSnow(){
  delSnow() {
    if (this.snowEffect) {
      this.snowEffect.destroy();
      this.snowEffect = null;
@@ -87,58 +90,81 @@
      this.snowEffect.show(show);
    }
  },
  // 坡度分析
  pdfx(option) {
    this.elevationTool = new SmartEarth.ElevationTool(earthCtrl)
    if (option.terrainRender == '1') {
      this.elevationTool.type = 'slope'
    } else {
      this.elevationTool.type = 'none'
    }
    this.elevationTool.tf = option.contourLines
    this.elevationTool.setSpacing(option.spacing)
    this.elevationTool.setWidth(option.lineWidth)
    this.elevationTool.setContourColor(option.color);
    this.elevationTool.render();
    console.log(this.elevationTool, 'eleelelelelelelel')
  },
  // 坡向箭头
  pxjt(colors, angles) {
    this.slopeArrow = earthCtrl.factory.createSlopeArrow({});
    this.slopeArrow.setColorsAndAngles(colors, angles);
  // 区域划分工具
  hfqy() {
    this.regionTerrain = earthCtrl.factory.createRegionTerrain({});
    this.polygonPosition = [];
    // 创建绘制工具
    const drawTool = earthCtrl.shapeTool.createDrawShapeTool((e) => {
    const draw = earthCtrl.shapeTool.createDrawShapeTool((e) => {
      const polygonI = [];
      const polygonPosition = [];
      for (const i of e.result) {
        const ellipsoid = earthCtrl.coreMap.scene.globe.ellipsoid;
        const cartographic = ellipsoid.cartesianToCartographic(i);
        const lon = Cesium.Math.toDegrees(cartographic.longitude);
        const lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度
        const lon = SmartEarth.Cesium.Math.toDegrees(
          cartographic.longitude
        ); // 经度
        const lat = SmartEarth.Cesium.Math.toDegrees(cartographic.latitude); // 纬度
        polygonI.push(lon, lat, 0);
        polygonPosition.push(lon, lat);
        this.polygonPosition.push(lon, lat);
      }
      const PolygonArr = [];
      PolygonArr.push({
      this.PolygonArr.push({
        id: earthCtrl.factory.createUUID(),
        polygon: polygonI,
      });
      // 清除绘制工具
      drawTool.removeFromMap();
      // 设置坡度箭头的位置和类型
      this.slopeArrow.setPositions(polygonPosition);
      this.slopeArrow.setSlopeType(1);
      this.slopeArrow.setRegionEnabled(true);
      console.log(this.slopeArrow, 'slope')
      draw.removeFromMap();
      this.regionTerrain.setPositions(this.polygonPosition);
      this.regionTerrain.setRegionEnabled(true);
    });
  },
  // 关闭坡向箭头
  gbpxjt() {
  // 坡度分析
  pdfx() {
    if (this.regionTerrain) {
      console.log('坡度分析');
      this.clearPreviousAnalysis(); // 先清除之前的分析
      this.regionTerrain.setType("slope");
      this.regionTerrain.update();
    }
  },
  // 坡向箭头
  pxjt(colors, angles) {
    if (this.regionTerrain) {
      this.clearPreviousAnalysis(); // 先清除之前的分析
      this.regionTerrain.setType("aspect");
      this.regionTerrain.update();
    }
    this.slopeArrow = earthCtrl.factory.createSlopeArrow({});
    this.slopeArrow.setColorsAndAngles(colors, angles);
    this.slopeArrow.setSlopeType(1);
  },
  // 等高线分析
  dgxfx(option) {
    this.clearPreviousAnalysis(); // 先清除之前的分析
    this.hfqy();
    this.elevationTool = new SmartEarth.ElevationTool(earthCtrl);
    this.elevationTool.tf = option.contourLines;
    this.elevationTool.setSpacing(option.spacing);
    this.elevationTool.setWidth(option.lineWidth);
    this.elevationTool.setContourColor(option.color);
    this.elevationTool.render();
  },
  // 清除之前的分析(坡度、坡向、等高线)
  clearPreviousAnalysis() {
    if (this.regionTerrain) {
      this.regionTerrain.setType("");
      this.regionTerrain.update();
    }
    if (this.slopeArrow) {
      this.slopeArrow.setSlopeType(0);
      // this.slopeArrow = null;
    }
    if (this.elevationTool) {
      this.elevationTool = null;
    }
  },
  // 标绘