Newer
Older
KaiFengPC / src / utils / gis / NewFiberMapUtils.js
@wudi wudi on 26 Jun 9 KB 1
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';
export default class NewFiberMapUtils {

    static defaultParams = {
        keys:{
            //巡查默认专题图
            defaultPatrolDemo:'defaultPatrolDemo',
            //排水防涝默认专题图
            defaultPreventWaterloggingDemo:'defaultPreventWaterloggingDemo'
        },
        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 {mapParams,keys} = NewFiberMapUtils.defaultParams;
        const defaulGeoJSONParams = _.cloneDeep(mapParams.geojson);
        const icons = {ylz:rainStation_icon, hmss:spongeFacility_icon, car:'/images/people.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'}}});
        });
    }

    static async defaultPreventWaterlogging(newfiberMap){
        const {mapParams, keys} = NewFiberMapUtils.defaultParams;
        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:Object.assign(defaulGeoJSONParams.point.options,{url:icons[i.pumpType]})}}))
        let polygons = pumpData.map(i => turf.feature(Terraformer.WKT.parse(i.geometrys),{style_:{id:keys.defaultPatrolDemo,...defaulGeoJSONParams.polygon}}));
        NewFiberMapUtils.removeByIds([keys.defaultPreventWaterloggingDemo]);
        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)});
        riverFlow.features = riverFlow.features.concat([...points,...polygons]);
        newfiberMap.geojsonToMap(riverFlow);
    }

    static async weatherToMap(newfiberMap){
        const {mapParams, keys} = NewFiberMapUtils.defaultParams;
        const urls = [
            "/images/weather/QPFRef_202406251910.png",
            "/images/weather/QPFRef_202406251920.png",
            "/images/weather/QPFRef_202406251930.png",
            "/images/weather/QPFRef_202406251940.png",
            "/images/weather/QPFRef_202406251950.png",
            "/images/weather/QPFRef_202406252000.png",
            "/images/weather/QPFRef_202406252010.png",
            "/images/weather/QPFRef_202406252020.png",
            "/images/weather/QPFRef_202406252030.png",
            "/images/weather/QPFRef_202406252040.png",
            "/images/weather/QPFRef_202406252050.png",
            "/images/weather/QPFRef_202406252100.png",
            "/images/weather/QPFRef_202406252110.png",
            "/images/weather/QPFRef_202406252120.png",
            "/images/weather/QPFRef_202406252130.png",
            "/images/weather/QPFRef_202406252140.png",
            "/images/weather/QPFRef_202406252150.png",
            "/images/weather/QPFRef_202406252200.png",
            "/images/weather/QPFRef_202406252210.png",
            "/images/weather/QPFRef_202406252220.png",
            "/images/weather/QPFRef_202406252230.png",
            "/images/weather/QPFRef_202406252240.png",
            "/images/weather/QPFRef_202406252250.png",
            "/images/weather/QPFRef_202406252300.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.defaultPreventWaterloggingDemo,
            ...(_.cloneDeep((defaulGeoJSONParams.polygon))),
            options: Object.assign(defaulGeoJSONParams.polygon.options, {
                material: new Cesium.ImageMaterialProperty({
                    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;
        if (ids.includes(keys.defaultPreventWaterloggingDemo)) newfiberMap.weatherInterVal && clearInterval(newfiberMap.weatherInterVal), newfiberMap.weatherInterVal = undefined;
    }
}