Newer
Older
KaiFengPC / src / utils / gis / NewFiberMapUtils.js
@wudi wudi 7 days ago 13 KB 1
import request from "../request";
import in_icon from "@/assets/images/gisMap/in.png";

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:in_icon};
        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_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",
            "/images/weather/QPFRef_202406211350.png",
            "/images/weather/QPFRef_202406211400.png",
            "/images/weather/QPFRef_202406211410.png",
            "/images/weather/QPFRef_202406211420.png",
            "/images/weather/QPFRef_202406211430.png",
            "/images/weather/QPFRef_202406211440.png",
            "/images/weather/QPFRef_202406211450.png",
            "/images/weather/QPFRef_202406211500.png",
            "/images/weather/QPFRef_202406211510.png",
            "/images/weather/QPFRef_202406211520.png",
            "/images/weather/QPFRef_202406211530.png",
            "/images/weather/QPFRef_202406211540.png",
            "/images/weather/QPFRef_202406211550.png",
            "/images/weather/QPFRef_202406211600.png",
            "/images/weather/QPFRef_202406211610.png",
            "/images/weather/QPFRef_202406211620.png",
            "/images/weather/QPFRef_202406211630.png",
            "/images/weather/QPFRef_202406211640.png",
            "/images/weather/QPFRef_202406211650.png",
            "/images/weather/QPFRef_202406211700.png",
            "/images/weather/QPFRef_202406211710.png",
            "/images/weather/QPFRef_202406211720.png",
            "/images/weather/QPFRef_202406211730.png",
            "/images/weather/QPFRef_202406211740.png",
            "/images/weather/QPFRef_202406211750.png",
            "/images/weather/QPFRef_202406211800.png",
            "/images/weather/QPFRef_202406211810.png",
            "/images/weather/QPFRef_202406211820.png",
            "/images/weather/QPFRef_202406211830.png",
            "/images/weather/QPFRef_202406211840.png",
            "/images/weather/QPFRef_202406211850.png",
            "/images/weather/QPFRef_202406211900.png",
            "/images/weather/QPFRef_202406211910.png",
            "/images/weather/QPFRef_202406211920.png",
            "/images/weather/QPFRef_202406211930.png",
            "/images/weather/QPFRef_202406211940.png",
            "/images/weather/QPFRef_202406211950.png",
            "/images/weather/QPFRef_202406212000.png",
            "/images/weather/QPFRef_202406212010.png",
            "/images/weather/QPFRef_202406212020.png",
            "/images/weather/QPFRef_202406212030.png",
            "/images/weather/QPFRef_202406212040.png",
            "/images/weather/QPFRef_202406212050.png",
            "/images/weather/QPFRef_202406212100.png",
            "/images/weather/QPFRef_202406212110.png",
            "/images/weather/QPFRef_202406212120.png",
            "/images/weather/QPFRef_202406212130.png",
            "/images/weather/QPFRef_202406212140.png",
            "/images/weather/QPFRef_202406212150.png",
            "/images/weather/QPFRef_202406212200.png",
            "/images/weather/QPFRef_202406212210.png",
            "/images/weather/QPFRef_202406212220.png",
            "/images/weather/QPFRef_202406212230.png",
            "/images/weather/QPFRef_202406212240.png",
            "/images/weather/QPFRef_202406212250.png",
            "/images/weather/QPFRef_202406212300.png",
            "/images/weather/QPFRef_202406212310.png",
            "/images/weather/QPFRef_202406212320.png",
            "/images/weather/QPFRef_202406212330.png",
            "/images/weather/QPFRef_202406212340.png",
            "/images/weather/QPFRef_202406212350.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;
    }
}