Newer
Older
KaiFengPC / src / views / sponeScreen / gisMF / newfiberVectorLayer.js
@jimengfei jimengfei on 9 Aug 9 KB updata
import { querySiteFiveMinuteRain } from '@/api/sponeScreen/syntherticData.js';
export default class newfiberVectorLayer {
  //添加图标标注点
  static addGeojsonPoint(newfiberMap, geojson, icon_url, newfiberId) {
    geojson.features.forEach(
      feature =>
        (feature.properties = Object.assign(feature.properties, {
          style_: {
            type: NewFiberMap.Enum.VectorType.ICON,
            options: {
              show: true,
              url: icon_url,
              width: 30,
              height: 30,
              pixelOffset: [0, 0],
            },
            name:
              feature.properties.name ||
              feature.properties.pumpName ||
              feature.properties.projectAbbreviation ||
              feature.properties.sewageName ||
              feature.properties.stName,
            id: newfiberId,
            labelOptions: {
              font: '16px PingFang SC',
              color: 'rgba(255, 255, 255, 1)',
              pixelOffset: [0, 0],
              backgroundColor: 'rgba(0,0,0,1)',
              showBackground: false,
              outlineColor: 'rgba(14, 139, 90, 1)',
              outlineWidth: 2,
              style: Cesium.LabelStyle.FILL_AND_OUTLINE,
              distanceDisplayCondition: [Number.MIN_VALUE, 70000],
            },
          },
        }))
    );
    if (newfiberMap.getLayers(newfiberId).length > 0) {
      return;
    } else {
      newfiberMap.geojsonToMap(geojson);
    }
  }
  //添加geojson面
  static addGeojsonPolygon(newfiberMap, geojson, newfiberId) {
    geojson.features.forEach(
      feature =>
        (feature.properties = Object.assign(feature.properties, {
          style_: {
            type: NewFiberMap.Enum.VectorType.POLYGON,
            options: {
              show: true,
              material: !!feature.properties.fillcolor ? feature.properties.fillcolor : 'rgba(154,104,171,0.8)',
              outline: false,
              // outlineColorBottom: !!feature.properties.outcolor ? feature.properties.outcolor : 'rgba(189,127,171,0.75)',
              // outlineWidthBottom: 2,
            },

            name: feature.properties.name != ' ' ? feature.properties.name : null,
            id: newfiberId,
            labelOptions: {
              font: '20px PingFang SC',
              color: 'rgba(255, 255, 255, 1)',
              pixelOffset: [0, 0],
              backgroundColor: 'rgba(0,0,0,1)',
              showBackground: false,
              outlineColor: 'rgba(14, 139, 90, 1)',
              outlineWidth: 5,
              style: Cesium.LabelStyle.FILL_AND_OUTLINE,
              distanceDisplayCondition: [Number.MIN_VALUE, 7000000],
            },
          },
        }))
    );
    if (newfiberMap.getLayers(newfiberId).length > 0) {
      return;
    } else {
      newfiberMap.geojsonToMap(geojson);
    }
  }

  //添加发光线
  static addLightenLine(geojson, newfiberId) {
    let width = 10;
    geojson.features.forEach(
      feature =>
        (feature.properties = Object.assign(feature.properties, {
          style_: {
            name: !!feature.properties.dikeName ? feature.properties.dikeName : '',
            type: NewFiberMap.Enum.VectorType.POLYLINE,
            options: {
              material: new Cesium.PolylineGlowMaterialProperty({
                glowPower: 0.3, //一个数字属性,指定发光强度,占总线宽的百分比。
                color: new Cesium.Color.fromCssColorString('rgba(163, 100, 214,1)'),
              }),
              width: 25,
              // width: new Cesium.CallbackProperty(() => {
              //   width += 0.3;
              //   if (width > 20) {
              //     width = 5;
              //   }
              //   return width;
              // }, false),
              show: true,
            },
            id: newfiberId,
            // labelOptions: {
            //   font: '15px PingFang SC',
            //   color: 'rgba(225, 242, 255,1)',
            //   pixelOffset: [0, -30],
            //   backgroundColor: 'rgba(0,0,0,0.7)',
            //   showBackground: false,
            //   distanceDisplayCondition: [Number.MIN_VALUE, 7000000],
            // },
          },
        }))
    );
    if (newfiberMap.getLayers(newfiberId).length > 0) {
      return;
    } else {
      newfiberMap.geojsonToMap(geojson);
    }
  }
  //添加geojson立体墙
  static addGeojsonWall(newfiberMap, geojson, newfiberId, maximumHeights) {
    geojson.features.forEach(feature => {
      feature.properties = Object.assign(feature.properties, {
        style_: {
          type: NewFiberMap.Enum.VectorType.WALL,
          id: newfiberId,
          options: {
            maximumHeights: maximumHeights || 100,
            minimunHeights: 0,
            material: new NewFiberMap.Material.WallTrailMaterialProperty({
              image: NewFiberMapConfig.SDK_INIT_SRC_PREFIX + '/static/images/material/wall/colors_blue_v1.png',
              color: feature.properties.fillcolor
                ? new Cesium.Color.fromCssColorString(feature.properties.fillcolor)
                : new Cesium.Color.fromCssColorString('rgba(55,193,139,.7)'),
              speed: 1000,
            }),
          },
        },
      });
    });
    newfiberMap.geojsonToMap(geojson);
  }
  //添加geojson立体墙2
  static addGeojsonWall2(geojson, newfiberId) {
    geojson.features.forEach(feature => {
      feature.properties = Object.assign(feature.properties, {
        style_: {
          type: NewFiberMap.Enum.VectorType.WALL,
          id: newfiberId,
          options: {
            maximumHeights: 100,
            minimunHeights: 0,
            material: new NewFiberMap.Material.WallDiffuseMaterialProperty({
              image: NewFiberMapConfig.SDK_INIT_SRC_PREFIX + '/static/images/material/wall/colors_blue_v1.png',
              duration: 1000,
            }),
          },
        },
      });
    });
    newfiberMap.geojsonToMap(geojson);
  }
  //添加发光圈
  static addLightenClrcle(geojson, newfiberId) {
    geojson.features.forEach(feature => {
      feature.properties = Object.assign(feature.properties, {
        style_: {
          type: NewFiberMap.Enum.VectorType.SPECIAL_CIRCLE,
          id: newfiberId,
          options: {
            radius: 500,
            clampToGround: false,
            material: new NewFiberMap.Material.CircleDiffuseMaterialProperty({
              color: Cesium.Color.fromCssColorString('rgba(92, 223, 99,.5)'),
              speed: 30,
            }),
          },
        },
      });
    });
    newfiberMap.geojsonToMap(geojson);
  }
  //添加流动线
  static addDynamicLine(geojson, newfiberId) {
    geojson.features.forEach(feature => {
      feature.properties = Object.assign(feature.properties, {
        style_: {
          type: NewFiberMap.Enum.VectorType.POLYLINE,
          id: newfiberId,
          options: {
            width: 3,
            clampToGround: false,
            material: new NewFiberMap.Material.PolylineTrailMaterialProperty({
              speed: 30,
              color:
                feature.properties.type == 'ys'
                  ? Cesium.Color.fromCssColorString('rgba(27, 97, 255, 1)')
                  : feature.properties.type == 'ws'
                  ? Cesium.Color.fromCssColorString('rgba(223, 68, 68, 1)')
                  : Cesium.Color.fromCssColorString('rgba(234, 163, 51, 1)'),
            }),
          },
        },
      });
    });
    newfiberMap.geojsonToMap(geojson);
  }
  //添加动态河流
  static addDynamicWater(newfiberMap, geojson, newfiberId) {
    NewFiberMap.Layer.Primitive.loadWaterPrimitive({ geojson: geojson, height: 10, id: newfiberId, show: true }, newfiberMap.getMap());
  }
  //动态河流显示与隐藏
  static setDynamicWaterVisible(visible) {
    let dynamicWaterList = newfiberMap.getMap().scene.primitives._primitives.filter(i => i.key == 'dynamicWater');
    dynamicWaterList.map(feature => {
      feature.show = visible;
    });
  }
  //添加三维模型
  static add3DModelLayers(newfiberMap, url, newfiberId) {
    let modelList = newfiberMap.getMap().scene.primitives._primitives.filter(i => i.newfiberId == newfiberId);
    if (!modelList.length) {
      let models = new SuperMap3D.S3MTilesLayer({
        context: newfiberMap.getMap().scene.context,
        url: url,
      });
      models.newfiberId = newfiberId;
      newfiberMap.getMap().scene.primitives.add(models);
    } else {
      newfiberVectorLayer.set3DModelVisible(newfiberId, true);
    }
  }
  //隐藏三维模型
  static set3DModelVisible(newfiberId, visible) {
    let models = newfiberMap.getMap().scene.primitives._primitives.filter(i => i.newfiberId == newfiberId);
    models.map(feature => {
      feature.show = visible;
    });
  }
  //实时天气效果
  static async setCurrentWeather() {
    let res = await querySiteFiveMinuteRain();
    if (res && res.code == 200) {
      let currentRainValue = res.data.monitorValue;
      if (currentRainValue >= 0.017 && currentRainValue < 0.035) {
        newfiberMap.weatherRain({
          tiltAngle: -0.2,
          rainSize: 1,
          rainSpeed: 150.0,
        }); //小
      } else if (currentRainValue >= 0.035 && currentRainValue < 0.086) {
        newfiberMap.weatherRain({
          tiltAngle: -0.2,
          rainSize: 0.5,
          rainSpeed: 150.0,
        }); //中
      } else if (currentRainValue >= 0.086 && currentRainValue < 0.17) {
        newfiberMap.weatherRain({
          tiltAngle: -0.2,
          rainSize: 0.2,
          rainSpeed: 150.0,
        }); // 大
      } else if (currentRainValue >= 0.17) {
        newfiberMap.weatherRain({
          tiltAngle: -0.2,
          rainSize: 0.1,
          rainSpeed: 150.0,
        }); // 暴雨
      } else {
        newfiberMap.weatherRemove();
      }
    }
  }
}