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
import * as mars3d from "mars3d"
 
export let map // mars3d.Map三维地图对象
 
// 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并)
export const mapOptions = {
  scene: {
    center: { lat: 26.163233, lng: 77.849567, alt: 17754541, heading: 0, pitch: -90 },
    sceneMode: 2
  },
  terrain: false
}
 
/**
 * 初始化地图业务,生命周期钩子函数(必须)
 * 框架在地图初始化完成后自动调用该函数
 * @param {mars3d.Map} mapInstance 地图对象
 * @returns {void} 无
 */
export function onMounted(mapInstance) {
  map = mapInstance // 记录map
 
  map.basemap = 2017 // 蓝色底图
 
  // 加载数据
  mars3d.Util.fetchJson({ url: "//data.mars3d.cn/file/apidemo/oneBeltOneRoad.json" })
    .then(function (res) {
      showRoad(res.data.land, {
        name: "丝绸之路经济带",
        color: Cesium.Color.CORAL
      })
 
      showRoad(res.data.sea, {
        name: "21世纪海上丝绸之路",
        color: Cesium.Color.DEEPSKYBLUE
      })
    })
    .catch(function () {
      globalMsg("实时查询信息失败,请稍候再试")
    })
}
 
/**
 * 释放当前地图业务的生命周期函数
 * @returns {void} 无
 */
export function onUnmounted() {
  map = null
}
 
function showRoad(arr, options) {
  // 创建矢量数据图层
  const graphicLayer = new mars3d.layer.GraphicLayer()
  map.addLayer(graphicLayer)
 
  let arrPosition = []
  for (let i = 0; i < arr.length; i++) {
    const item = arr[i]
 
    const position = Cesium.Cartesian3.fromDegrees(item.x, item.y)
    item.position = position
 
    arrPosition.push(position)
 
    // 创建点
    if (item.icon) {
      const billboardPrimitive = new mars3d.graphic.BillboardPrimitive({
        name: item.name,
        position: position,
        style: {
          image: "img/country/" + item.icon,
          scale: 0.7,
          horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
          verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
          label: {
            text: item.name,
            font_size: 17,
            font_family: "楷体",
            color: Cesium.Color.WHITE,
            outline: true,
            outlineColor: Cesium.Color.BLACK,
            outlineWidth: 2,
            horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
            verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
            pixelOffset: new Cesium.Cartesian2(0, -30)
          }
        }
      })
      graphicLayer.addGraphic(billboardPrimitive)
 
      const html = `<div class="mars-load-location">
        ${item.continent} - ${item.country} - <i style="color: #00ffff;">${item.name}</i>
      </div>`
      billboardPrimitive.bindPopup(html)
    }
  }
 
  arrPosition = arrPosition.reverse()
  const positions = mars3d.PolyUtil.getBezierCurve(arrPosition)
  positions.push(arrPosition[arrPosition.length - 1])
 
  const primitive = new mars3d.graphic.PolylinePrimitive({
    positions: positions,
    style: {
      width: 4,
      material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.LineFlow, {
        image: "img/textures/line-pulse.png",
        color: options.color,
        repeat: new Cesium.Cartesian2(10.0, 1.0),
        speed: 2
      })
    }
  })
  graphicLayer.addGraphic(primitive)
 
  primitive.bindTooltip(options.name)
}