Newer
Older
KaiFengPC / src / utils / gis / NewFiberMapUtils.js
@jimengfei jimengfei on 12 Jul 11 KB updata
import request from '../request';

import rainStation_icon from '@/assets/cesiumMap/legendIcon/rainStation_icon.png';
import spongeFacility_icon from '@/assets/cesiumMap/legendIcon/spongeFacility_icon.png';
import sewageBenZhan_icon from '@/assets/cesiumMap/legendIcon/sewageBenZhan_icon.png';
import rainBengZhan_icon from '@/assets/cesiumMap/legendIcon/rainBengZhan_icon.png';
import combineBengZhan_icon from '@/assets/cesiumMap/legendIcon/combineBengZhan_icon.png';

import riverFlow from '@/assets/geojson/kaifeng/riverFlow.json';
import cesiumMapLegend from '@/views/sponeScreen/gisMF/cesiumMapLegend.js';
import newfiberVectorLayer from '@/views/sponeScreen/gisMF/newfiberVectorLayer';
import { facilityPumpList } from '@/api/scada/pumpStationInformation';

let mapParams = {
  geojson: {
    point: {
      type: NewFiberMap.Enum.VectorType.ICON,
      options: {
        url: '/static/images/icon.png',
        width: 20,
        height: 20,
        verticalOrigin: Cesium.HorizontalOrigin.RIGHT,
        pixelOffset: [0, -10],
      },
      labelOptions: {
        font: '17px PingFang SC',
        style: Cesium.LabelStyle.FILL_AND_OUTLINE,
        outlineColor: 'rgba(20,83,154,1)',
        outline: true,
        outlineWidth: 3,
        color: '#ffffff',
        pixelOffset: [0, 25],
        distanceDisplayCondition: [0, 5100],
      },
    },
    warning: {
      type: NewFiberMap.Enum.VectorType.SPECIAL_CIRCLE,
      options: {
        radius: 70,
        material: new NewFiberMap.Material.CircleDiffuseMaterialProperty({
          color: Cesium.Color.fromCssColorString('rgba(255,0,0, .5)'),
          speed: 50,
        }),
      },
    },
    polyline: {
      type: NewFiberMap.Enum.VectorType.POLYLINE,
      options: {
        show: true,
        width: 6,
        material: new Cesium.Spriteline1MaterialProperty(3000, '/static/images/spriteline.png'),
        clampToGround: true,
      },
    },
    polygon: {
      type: NewFiberMap.Enum.VectorType.POLYGON,
      options: {
        width: 1,
        material: 'rgba(46,196,203,0.5)',
        outlineColor: 'rgba(0,244,255,1)',
      },
    },
  },
};
export default class NewFiberMapUtils {
  static defaultParams = {
    keys: {
      //巡查默认专题图
      defaultPatrolDemo: 'defaultPatrolDemo',
      //排水防涝默认专题图
      defaultPreventWaterloggingDemo: 'defaultPreventWaterloggingDemo',
      weather_cloud: 'weather_cloud',
    },
    /* mapParams:{
          geojson:{
              point:{
                  type: NewFiberMap.Enum.VectorType.ICON,
                  options: {
                      url: "/static/images/icon.png",
                      width: 20,
                      height: 20,
                      verticalOrigin: Cesium.HorizontalOrigin.RIGHT,
                      pixelOffset: [0, -10],
                  },
                  labelOptions: {
                      font: "17px PingFang SC",
                      style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                      outlineColor: "rgba(20,83,154,1)",
                      outline: true,
                      outlineWidth: 3,
                      color: "#ffffff",
                      pixelOffset: [0, 25],
                      distanceDisplayCondition: [0, 5100],
                  },
              },
              warning:{
                  type: NewFiberMap.Enum.VectorType.SPECIAL_CIRCLE,
                  options: {
                      radius: 70,
                      material: new NewFiberMap.Material.CircleDiffuseMaterialProperty({
                          color: Cesium.Color.fromCssColorString("rgba(255,0,0, .5)"),
                          speed: 50,
                      }),
                  },
              },
              polyline: {
                  type: NewFiberMap.Enum.VectorType.POLYLINE,
                  options: {
                      show: true,
                      width: 6,
                      material:new Cesium.Spriteline1MaterialProperty(3000,'/static/images/spriteline.png'),
                      clampToGround: true
                  }
              },
              polygon:{
                    type: NewFiberMap.Enum.VectorType.POLYGON,
                    options: {
                      width: 1,
                      material: "rgba(46,196,203,0.5)",
                      outlineColor: "rgba(0,244,255,1)",
                    },
              }
          }
        }*/
  };

  static async defaultPatrolDemo(newfiberMap) {
    const { keys } = NewFiberMapUtils.defaultParams;
    const defaulGeoJSONParams = _.cloneDeep(mapParams.geojson);
    const icons = { ylz: rainStation_icon, hmss: spongeFacility_icon, car: '/images/car.png' };
    NewFiberMapUtils.removeByIds([keys.defaultPatrolDemo]);

    let results = await Promise.all(['/static/json/malfunction.json', '/static/json/track.json'].map(i => request(i)));
    let warningData = _.cloneDeep(results[0]);
    results[0].features.forEach(
      i =>
        (i.properties.style_ = _.cloneDeep({
          id: keys.defaultPatrolDemo,
          name: i.properties.name,
          ...defaulGeoJSONParams.point,
          options: Object.assign(defaulGeoJSONParams.point.options, { url: icons[i.properties.type] }),
        }))
    );
    warningData.features.forEach(i => (i.properties.style_ = { id: keys.defaultPatrolDemo, ...defaulGeoJSONParams.warning }));
    let markers = warningData.features.concat(results[0].features);
    newfiberMap.geojsonToMap(turf.featureCollection(markers));

    newfiberMap.patrolDemoTracks = results[1].features.map(feature => {
      let datas = turf.getCoords(feature.geometry).map(coords => ({ l: coords[0], a: coords[1], height: 10, time: 10 }));
      return new NewFiberMap.Layer.RunningPath({
        paths: datas,
        name,
        newfiberMap,
        options: {
          style: { move: icons.car },
          perSec: 5,
          speed: 10,
          pathColor: [38, 178, 107, 1],
          passPathColor: [89, 91, 93, 1],
          isStart: false,
          isEnd: false,
          fields: { lng: 'l', lat: 'a', height: 'height', time: 'time' },
        },
      });
    });

    let timeout = setTimeout(() => {
      newfiberMap.setView({
        lng: 114.332,
        lat: 34.662,
        heading: 2.281299097855777,
        zoom: 6358.12942752382,
        pitch: -25.2508969308367,
        roll: 0.005453465256790101,
      });
      clearTimeout(timeout);
    }, 4000);
  }

  static async defaultPreventWaterlogging(newfiberMap) {
    const { keys } = NewFiberMapUtils.defaultParams;
    NewFiberMapUtils.removeByIds([keys.defaultPreventWaterloggingDemo]);
    const defaulGeoJSONParams = _.cloneDeep(mapParams.geojson);
    // const icons = {
    //   confluence: sewageBenZhan_icon,
    //   rain_water: rainBengZhan_icon,
    //   sewage_water: combineBengZhan_icon,
    // };
    // let result = await facilityPumpList();
    // let pumpData = result.data.filter(i => i.lon && i.lat && i.geometrys);
    // let points = pumpData.map(i =>
    //   turf.point([i.lon, i.lat].map(Number), {
    //     style_: {
    //       id: keys.defaultPreventWaterloggingDemo,
    //       name: i.pumpName,
    //       ...defaulGeoJSONParams.point,
    //       options: { ...defaulGeoJSONParams.point.options, url: icons[i.pumpType] },
    //     },
    //   })
    // );
    // console.log('points', points);
    // let polygons = pumpData.map(i =>
    //   turf.feature(Terraformer.WKT.parse(i.geometrys), { style_: { id: keys.defaultPatrolDemo, ...defaulGeoJSONParams.polygon } })
    // );
    NewFiberMapUtils.weatherToMap(newfiberMap);
    /*   let modelLegends = cesiumMapLegend.map(i => i.children).flat(Infinity).filter(i => i.layername.includes('Line') && i.type == '3dModel');
        let modelIds = modelLegends.map(i => i.layername);
        let models = newfiberMap.getMap().scene.primitives._primitives.filter(i => modelIds.includes(i.newfiberId));
        if (models.length > 0) {
            models.forEach(i => i.show = true);
        } else {
            modelLegends.forEach(i => i.data.forEach(url => newfiberVectorLayer.add3DModelLayers(newfiberMap, url, i.layername)));
        }*/
    riverFlow.features.forEach(i => (i.properties.style_ = { id: keys.defaultPreventWaterloggingDemo, ...defaulGeoJSONParams.polyline }));
    newfiberMap.geojsonToMap(riverFlow);
    //newfiberMap.geojsonToMap(turf.featureCollection([...points, ...polygons]));
  }

  static async weatherToMap(newfiberMap) {
    const { keys } = NewFiberMapUtils.defaultParams;
    const urls = [
      '/images/weather/QPFRef_202406210650.png',
      '/images/weather/QPFRef_202406210700.png',
      '/images/weather/QPFRef_202406210710.png',
      '/images/weather/QPFRef_202406210720.png',
      '/images/weather/QPFRef_202406210730.png',
      '/images/weather/QPFRef_202406210740.png',
      '/images/weather/QPFRef_202406210750.png',
      '/images/weather/QPFRef_202406210800.png',
      '/images/weather/QPFRef_202406210810.png',
      '/images/weather/QPFRef_202406210820.png',
      '/images/weather/QPFRef_202406210830.png',
      '/images/weather/QPFRef_202406210840.png',
      '/images/weather/QPFRef_202406210850.png',
      '/images/weather/QPFRef_202406210900.png',
      '/images/weather/QPFRef_202406210910.png',
      '/images/weather/QPFRef_202406210920.png',
      '/images/weather/QPFRef_202406210930.png',
      '/images/weather/QPFRef_202406210940.png',
      '/images/weather/QPFRef_202406210950.png',
      '/images/weather/QPFRef_202406211000.png',
      '/images/weather/QPFRef_202406211010.png',
      '/images/weather/QPFRef_202406211020.png',
      '/images/weather/QPFRef_202406211030.png',
      '/images/weather/QPFRef_202406211040.png',
      '/images/weather/QPFRef_202406211050.png',
      '/images/weather/QPFRef_202406211100.png',
      '/images/weather/QPFRef_202406211110.png',
      '/images/weather/QPFRef_202406211120.png',
      '/images/weather/QPFRef_202406211130.png',
      '/images/weather/QPFRef_202406211140.png',
      '/images/weather/QPFRef_202406211150.png',
      '/images/weather/QPFRef_202406211200.png',
      '/images/weather/QPFRef_202406211210.png',
      '/images/weather/QPFRef_202406211220.png',
      '/images/weather/QPFRef_202406211230.png',
      '/images/weather/QPFRef_202406211240.png',
      '/images/weather/QPFRef_202406211250.png',
      '/images/weather/QPFRef_202406211300.png',
      '/images/weather/QPFRef_202406211310.png',
      '/images/weather/QPFRef_202406211320.png',
      '/images/weather/QPFRef_202406211330.png',
      '/images/weather/QPFRef_202406211340.png',
    ];
    const defaulGeoJSONParams = _.cloneDeep(mapParams.geojson);
    const bbox = [73.49899858945263, 10.228437, 135.08738720258265, 53.56131497236056];
    let polygon = turf.bboxPolygon(bbox);
    let i = 0;
    polygon.properties.style_ = {
      id: keys.weather_cloud,
      ..._.cloneDeep(defaulGeoJSONParams.polygon),
      options: Object.assign(defaulGeoJSONParams.polygon.options, {
        show: false,
        material: new Cesium.ImageMaterialProperty({
          transparent: true,
          alpha: 0.5,
          image: new Cesium.CallbackProperty(function () {
            return urls[i];
          }),
        }),
      }),
    };
    newfiberMap.geojsonToMap(turf.featureCollection([polygon]));
    newfiberMap.weatherInterVal = setInterval(() => {
      i++;
      if (i == urls.length) {
        i = 0;
      }
    }, 1000);
  }

  static removeByIds(ids) {
    const { keys } = NewFiberMapUtils.defaultParams;
    newfiberMap.removeByIds(ids);
    if (ids.includes(keys.defaultPatrolDemo))
      if (newfiberMap.patrolDemoTracks) newfiberMap.patrolDemoTracks.forEach(i => i.destroy()), (newfiberMap.patrolDemoTracks = undefined);
  }
}