fuchengshen
2022-07-09 3a25c05b5ab837714f30469cdcb1e2a77d8d7f6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import * as mars3d from "mars3d"
 
export let map // mars3d.Map三维地图对象
export let graphicLayer // 矢量图层对象
 
const arrData = [
  { name: "油罐一", position: [117.09521, 31.814404, 47.3] },
  { name: "油罐二", position: [117.095206, 31.814878, 47.3] },
  { name: "油罐三", position: [117.094653, 31.814428, 47.3] },
  { name: "发电机", position: [117.093428, 31.816959, 31.8] },
  { name: "指挥室", position: [117.093953, 31.814397, 36] },
  { name: "加热罐", position: [117.09385, 31.815837, 36.9] },
  { name: "冷却室", position: [117.094662, 31.816403, 32.9] }
]
 
// 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并)
export const mapOptions = {
  scene: {
    center: { lat: 31.81226, lng: 117.096703, alt: 231, heading: 329, pitch: -28 }
  }
}
 
/**
 * @param {mars3d.Map} mapInstance 地图对象
 * @returns {void} 无
 */
export function onMounted(mapInstance) {
  map = mapInstance // 记录map
 
  // 加载油田联合站模型
  const tiles3dLayer = new mars3d.layer.TilesetLayer({
    pid: 2020,
    type: "3dtiles",
    name: "油田联合站",
    url: "//data.mars3d.cn/3dtiles/max-ytlhz/tileset.json",
    position: { lng: 117.094224, lat: 31.815859, alt: 26.4 },
    rotation: { z: 116.2 },
    maximumScreenSpaceError: 1,
    center: { lat: 32.407076, lng: 117.459703, alt: 3361, heading: 358, pitch: -51 }
  })
  map.addLayer(tiles3dLayer)
 
  // 创建DIV数据图层
  graphicLayer = new mars3d.layer.GraphicLayer()
  map.addLayer(graphicLayer)
 
  bindLayerPopup() // 在图层上绑定popup,对所有加到这个图层的矢量数据都生效
 
  // 初始加载
  divGraphicYellow()
}
 
/**
 * 释放当前地图业务的生命周期函数
 * @returns {void} 无
 */
export function onUnmounted() {
  map = null
 
  graphicLayer.remove()
  graphicLayer = null
}
 
// 效果一
export function divGraphicYellow() {
  graphicLayer.clear()
 
  for (let i = 0; i < arrData.length; i++) {
    const item = arrData[i]
 
    const divGraphic = new mars3d.graphic.DivGraphic({
      position: item.position,
      style: {
        html: `<div class="marsBlackPanel  animation-spaceInDown">
                <div class="marsBlackPanel-text" style="">
                  ${item.name} <span class="temperature"></span> ℃
                </div>
              </div>`,
        horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
        verticalOrigin: Cesium.VerticalOrigin.CENTER
      },
      attr: {
        index: i + 1,
        duNum: 0
      }
    })
    graphicLayer.addGraphic(divGraphic)
 
    // 刷新局部DOM,不影响popup面板的其他控件操作
    divGraphic.on(mars3d.EventType.postRender, function (event) {
      const container = event.container // popup对应的DOM
      const graphic = event.target
 
      const oldVal = graphic.attr.duNum
 
      const newVal = Number(mars3d.Util.formatDate(new Date(), "ss")) + graphic.attr.index
      if (oldVal !== newVal) {
        graphic.attr.duNum = newVal
        const temperatureDom = container.querySelector(".temperature")
        if (temperatureDom) {
          temperatureDom.innerHTML = newVal
        }
      }
    })
  }
}
 
// 效果二
export function divGraphicBule() {
  graphicLayer.clear()
 
  for (let i = 0; i < arrData.length; i++) {
    const item = arrData[i]
 
    const divGraphic = new mars3d.graphic.DivGraphic({
      position: item.position,
      style: {
        html: `<div class="marsBlueGradientPnl">
            <div>${item.name}</div>
        </div>`,
        offsetY: -60,
        horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
        verticalOrigin: Cesium.VerticalOrigin.BTOOM
      }
    })
    graphicLayer.addGraphic(divGraphic)
  }
}
 
// 效果三
export function divGraphicWhite() {
  graphicLayer.clear()
 
  for (let i = 0; i < arrData.length; i++) {
    const item = arrData[i]
 
    const divGraphic = new mars3d.graphic.DivUpLabel({
      position: item.position,
      style: {
        text: item.name,
        color: "#fff",
        font_size: 16,
        font_family: "微软雅黑",
        lineHeight: 50,
        circleSize: 8,
        distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 100000) // 按视距距离显示
      }
    })
    graphicLayer.addGraphic(divGraphic)
  }
}
 
// 效果四
export function divGraphicHotSpot() {
  graphicLayer.clear()
 
  for (let i = 0; i < arrData.length; i++) {
    const item = arrData[i]
 
    const divGraphic = new mars3d.graphic.DivGraphic({
      position: item.position,
      style: {
        html: `<div class="mars-spot">
        <div class="mars-spot-board">
        <h5>${item.name}</h5>
        </div>
        <div class="mars-spot-line"></div>
      </div>`,
        offsetY: -60,
        horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
        verticalOrigin: Cesium.VerticalOrigin.BTOOM
      }
    })
    graphicLayer.addGraphic(divGraphic)
  }
}
 
// 在图层绑定Popup弹窗
export function bindLayerPopup() {
  graphicLayer.bindPopup(function (event) {
    const attr = event.graphic.attr || {}
    attr["类型"] = event.graphic.type
    attr["来源"] = "我是layer上绑定的Popup"
    attr["备注"] = "我支持鼠标交互"
 
    return mars3d.Util.getTemplateHtml({ title: "矢量图层", template: "all", attr: attr })
  })
}