Newer
Older
cockpit_hxrq_front / src / views / maps / needTopic.vue
StephanieGitHub on 22 Apr 2021 9 KB MOD:对接实际数据
<!--
 * @Description: 需求专题
 * @Author: 王晓颖
 * @Date: 2021-04-14
 -->
<template>
  <layout-map>
    <!--统计结果显示-->
    <div v-show="boardData.name" class="label-container">
      <div class="label-div">
        <div class="label">
          {{ boardData.name }}总需求
        </div>
        <div class="value">
          {{ boardData.value }}<span class="unit">m³</span>
        </div>
      </div>
      <div>
        <el-row>
          <el-col :span="12">
            <div class="label-div-small">
              <div class="label">
                LNG
              </div>
              <div class="value">
                {{ boardData.lng }}<span class="unit">m³</span>
              </div>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="label-div-small">
              <div class="label">
                PNG
              </div>
              <div class="value">
                {{ boardData.png }}<span class="unit">m³</span>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>

    <!--地图-->
    <Map :url="configUrl" @onload="onMapload" />
    <div class="map-btn-group">
      <!--<select-button :select="needShow" name="需求" icon="icon-need" @click="showNeed(needShow)"/>-->
      <select-button :select="vipShow" name="重点用户" icon="icon-user" @click="showVip(vipShow)"/>
    </div>
  </layout-map>
</template>

<script>
import 'mars3d-echarts'
import Map from '@/components/Map/MarsMap.vue'
import SelectButton from '@/components/SelectTool/components/selectButton'
import { getAreaSupply, getUserSupply } from '@/api/needSupply'
import LayoutMap from '@/layout/layoutMap'
import { getToday } from '@/utils/dateutils'
import { getIndex } from '@/utils/mathUtils'
export default {
  name: 'Vip',
  components: {
    LayoutMap,
    SelectButton,
    Map
  },
  filters: {
    boardNameFilter(val) {
      if (val === '全部' || val === '') {
        return '全省重点用户'
      } else {
        return val + '区域重点用户'
      }
    }
  },
  data() {
    return {
      map: null, // 地图
      configUrl: 'static/config/config.json',
      alpha: 100, // 透明度
      underground: null, // ?
      index: null, // 放大倍数
      pointColorArr: ['#f33349', '#f79a2c', '#95e40c', '#95e40c', '#1ffee6'],
      vipShow: true, // 显示位置
      needShow: true, // 显示需求
      boardData: {
        type: '', // area or vip
        name: '',
        value: '',
        lng: '',
        png: ''
      }, // 统计版展示数据
      cities: [],
      vipList: [], // 重点用户供需列表
      vipLayer: null, // 重点用户分布图层
      needLayer: null, // 需求光锥图层
      graphicLayer: null, // 管理站标签图层
      timer: null, // 轮训定时器
      clock: 30 // 间隔时间
    }
  },
  methods: {
    // 地图构造完成回调
    onMapload(map) {
      // 以下为演示代码
      this.map = map
      // 背景透明
      this.map._viewer.scene.backgroundColor = new this.Cesium.Color(0.0, 0.0, 0.0, 0.0)
      this.map._viewer.scene.globe.baseColor.alpha = 0
      // 添加重点用户隐患点
      this.addVipPosition()
      // this.addNeed()
      this.refreshData()
    },
    // 添加供需数据
    addNeed() {
      const { mars3d, Cesium } = this
      if (this.needLayer) {
        this.map.removeLayer(this.needLayer)
      }
      var graphicLayer = new mars3d.layer.DivLayer()
      this.needLayer = graphicLayer
      graphicLayer.on(mars3d.EventType.click, event => {
        const item = event.graphic.attr
        this.boardData.type = 'area'
        this.boardData.name = item.name
        this.boardData.value = item.need.toFixed(2)
        this.boardData.lng = item.lngNeed.toFixed(2)
        this.boardData.png = item.pngNeed.toFixed(2)
      })
      this.map.addLayer(graphicLayer)
      const date = getToday()
      getAreaSupply(date).then(res => {
        if (res.status === 200) {
          const data = res.data.map(item => {
            return {
              name: item['WD09_05'],
              pngNeed: item['DL03'] / 10000.0,
              lngNeed: item['DL02'] / 10000.0,
              need: (item['DL03'] + item['DL02']) / 10000.0
            }
          })
          this.cities = data
          if (this.index == null) {
            this.index = getIndex(this.cities.map(item => item.supply))
            console.log('index', this.index)
          }
          for (const item of this.cities) {
            const x = this.citiesPositions[item.name].x
            const y = this.citiesPositions[item.name].y
            var coneGlow2 = new mars3d.graphic.LightCone({
              position: Cesium.Cartesian3.fromDegrees(x, y, 0),
              attr: item,
              style: {
                color: '#00ffff',
                radius: 5000,
                height: item.need * this.index,
                popup: item.name,
                distanceDisplayCondition: new Cesium.DistanceDisplayConditionGeometryInstanceAttribute(80000, 3010000)
              }
            })
            graphicLayer.addGraphic(coneGlow2)
          }
        }
      })
    },
    // 重点用户位置
    addVipPosition() {
      const date = getToday()
      getUserSupply(date).then(res => {
        const data = res.data.map(item => {
          return {
            name: item['WD02_03'],
            x: parseFloat(item['WD02_04']),
            y: parseFloat(item['WD02_05']),
            pngNeed: item['DL03'],
            lngNeed: item['DL02'],
            need: item['DL03'] + item['DL02']
          }
        })
        this.vipList = data
        this.addFeatures(this.vipList)
      })
    },
    // 添加用户点位
    addFeatures(arr) {
      const { mars3d, Cesium } = this
      // 创建DIV数据图层
      if (this.vipLayer) {
        this.map.removeLayer(this.vipLayer)
      }
      var graphicLayer = new mars3d.layer.DivLayer()
      this.vipLayer = graphicLayer
      this.map.addLayer(graphicLayer)
      // 在layer上绑定监听事件
      graphicLayer.on(mars3d.EventType.click, event => {
        const item = event.graphic.attr
        this.boardData.type = 'vip'
        this.boardData.name = item.name
        this.boardData.value = item.need
        this.boardData.lng = item.lngNeed
        this.boardData.png = item.pngNeed
      })
      // 遍历显示图标
      for (const item of arr) {
        var jd = item.x
        var wd = item.y
        var clr = this.pointColorArr[2]
        var graphic = new mars3d.graphic.DivGraphic({
          position: Cesium.Cartesian3.fromDegrees(jd, wd, 0),
          style: {
            html: '<div class="mars3d-animation-point" style="color:' + clr + ';"><p></p></div>',
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 2000000) // 按视距距离显示
          },
          attr: item
        })
        graphicLayer.addGraphic(graphic)
      }
    },
    // 显示需求
    showNeed(show) {
      if (show) { // 移除
        this.needShow = false
        this.map.removeLayer(this.needLayer, true)
        this.needLayer = null
        if (this.boardData.type === 'area') {
          this.clearBoardData()
        }
      } else {
        this.needShow = true
        this.addNeed()
      }
    },
    // 显示重点用户分布和需求
    showVip(show) {
      if (show) { // 移除
        this.vipShow = false
        this.map.removeLayer(this.vipLayer, true)
        this.vipLayer = null
        if (this.boardData.type === 'vip') {
          this.clearBoardData()
        }
      } else {
        this.vipShow = true
        this.addVipPosition()
      }
    },
    clearBoardData() {
      this.boardData = {
        type: '', // area or vip
        name: '',
        value: '',
        lng: '',
        png: ''
      }
    },
    // 打开轮询,定时刷新数据
    refreshData() {
      this.timer = setInterval(() => {
        console.log('refreshData')
        if (this.needLayer) { // 如果供需图层不为空,刷新工薪数据
          this.addNeed()
        }
        if (this.vipLayer) {
          this.addVipPosition()
        }
      }, this.clock * 1000)
    }

  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .label-container {
    position: absolute;
    top: 140px;
    left: 31rem;
    z-index: 100;
    .label-div {
      color: white;
      padding: 1.5rem 2.5rem 1rem 2.5rem;
      background-image: url("../../assets/button_images/board-box1.png");
      background-size: 100% 100%;
      margin-bottom: 20px;
      .label {
        margin-bottom: 0.8rem;
        font-size: 1rem;
      }
      .value {
        font-family: DS-DigitalBold;
        font-size: 2rem;
      }
      .unit{
        font-family: "Microsoft YaHei";
        font-size:1rem;
      }
    }
    .label-div-small {
      color: white;
      padding: 1rem 2rem 1rem 2rem;
      background-image: url("../../assets/button_images/board-box1.png");
      background-size: 100% 100%;
      margin-bottom: 20px;
      .label {
        margin-bottom: 0.2rem;
        font-size: 1rem;
      }
      .value {
        font-family: DS-DigitalBold;
        font-size: 2rem;
      }
      .unit{
        font-family: "Microsoft YaHei";
        font-size:1rem;
      }
    }
  }
  .map-btn-group{
    position: absolute;
    bottom:3rem;
    left:50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
  }
</style>

<style rel="stylesheet/scss" lang="scss">
  /*整个容器*/
  .mapcontainer {
    position: relative;
    height: 100%;
    width: 100%;
    background-color: transparent;
    /*background-color: #051151;*/
  }

</style>