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
import * as mars3d from "mars3d"
 
export let map // mars3d.Map三维地图对象
 
// 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并)
export const mapOptions = {
  scene: {
    center: { lat: 31.170953, lng: 121.485939, alt: 7473, heading: 10, pitch: -40 }
  }
}
 
/**
 * 初始化地图业务,生命周期钩子函数(必须)
 * 框架在地图初始化完成后自动调用该函数
 * @param {mars3d.Map} mapInstance 地图对象
 * @returns {void} 无
 */
export function onMounted(mapInstance) {
  map = mapInstance // 记录map
 
  map.basemap = 2017 // 蓝色底图
 
  const tiles3dLayer = new mars3d.layer.TilesetLayer({
    name: "上海市建筑物",
    url: "//data.mars3d.cn/3dtiles/jzw-shanghai/tileset.json",
    maximumScreenSpaceError: 8,
    maximumMemoryUsage: 1024,
    marsJzwStyle: true,
    style: {
      color: {
        conditions: [["true", "rgb(3, 104, 255)"]]
      }
    },
    popup: "all"
  })
  map.addLayer(tiles3dLayer)
 
  // 创建Graphic图层
  const graphicLayer = new mars3d.layer.GraphicLayer()
  map.addLayer(graphicLayer)
 
  // 加一些演示数据
  addDemoGraphic1(graphicLayer)
  addDemoGraphic2(graphicLayer)
  addDemoGraphic3(graphicLayer)
  addDemoGraphic4(graphicLayer)
  addDemoGraphic5(graphicLayer)
}
 
/**
 * 释放当前地图业务的生命周期函数
 * @returns {void} 无
 */
export function onUnmounted() {
  map = null
}
 
function addDemoGraphic1(graphicLayer) {
  // 立体围墙扩散效果,面状
  const diffuseWallGlow = new mars3d.graphic.DiffuseWall({
    positions: [
      [121.475616, 31.255374, 5.87],
      [121.482578, 31.248681, 10.85],
      [121.479447, 31.240235, 14.25],
      [121.470002, 31.240496, 12.92],
      [121.46538, 31.249206, 9.53],
      [121.475616, 31.255374, 5.87]
    ],
    style: {
      color: "#ffff00",
      diffHeight: 2000, // 高度
      speed: 10 // 速度
    },
    attr: { remark: "示例1" }
  })
  graphicLayer.addGraphic(diffuseWallGlow)
}
 
function addDemoGraphic2(graphicLayer) {
  // 立体围墙扩散效果,圆状
  const circleDiffuseWallGlow = new mars3d.graphic.DiffuseWall({
    position: new mars3d.LngLatPoint(121.481165, 31.278668, 44.3), // 圆中心点
    style: {
      diffHeight: 2000, // 高度
      radius: 600, // 半径
      color: "#ff0000",
      speed: 10 // 速度
    },
    attr: { remark: "示例2" }
  })
  graphicLayer.addGraphic(circleDiffuseWallGlow)
}
 
function addDemoGraphic3(graphicLayer) {
  const primitive = new mars3d.graphic.CirclePrimitive({
    position: [121.522454, 31.267553, 61.9],
    style: {
      radius: 2000,
      material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.ScanLine, {
        color: new Cesium.Color(1.0, 1.0, 0.0, 1.0),
        speed: 10
      }),
      clampToGround: true // 是否贴地
    },
    attr: { remark: "示例3" }
  })
  graphicLayer.addGraphic(primitive)
}
 
function addDemoGraphic4(graphicLayer) {
  let _rotation = Math.random()
 
  const graphic = new mars3d.graphic.CircleEntity({
    position: Cesium.Cartesian3.fromDegrees(121.504242, 31.23805, 27.88),
    style: {
      radius: 1500.0,
      // 扫描材质
      material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.CircleScan, {
        image: "img/textures/circle-scan.png",
        color: "#00ff00"
      }),
      stRotation: new Cesium.CallbackProperty(function (e) {
        _rotation -= 0.1
        return _rotation
      }, false),
      classificationType: Cesium.ClassificationType.BOTH,
      clampToGround: true // 是否贴地
    },
    attr: { remark: "示例4" }
  })
  graphicLayer.addGraphic(graphic)
}
 
function addDemoGraphic5(graphicLayer) {
  let _rotation = Math.random()
  const graphic = new mars3d.graphic.CircleEntity({
    position: new mars3d.LngLatPoint(121.526215, 31.245237, 123.5),
    style: {
      radius: 700.0,
      material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.CircleScan, {
        // 扫描材质
        image: "img/textures/circle-two.png",
        color: "#5fc4ee"
      }),
      stRotation: new Cesium.CallbackProperty(function (e) {
        _rotation += 0.1
        return _rotation
      }, false),
      classificationType: Cesium.ClassificationType.BOTH,
      clampToGround: true // 是否贴地
    },
    attr: { remark: "示例5" }
  })
  graphicLayer.addGraphic(graphic)
}