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
| import * as mars3d from "mars3d"
|
| export let map // mars3d.Map三维地图对象
|
| /**
| * 初始化地图业务,生命周期钩子函数(必须)
| * 框架在地图初始化完成后自动调用该函数
| * @param {mars3d.Map} mapInstance 地图对象
| * @returns {void} 无
| */
| export function onMounted(mapInstance) {
| map = mapInstance // 记录首次创建的map
|
| // 创建mapv图层
| createMapvLayer()
| }
|
| /**
| * 释放当前地图业务的生命周期函数
| * @returns {void} 无
| */
| export function onUnmounted() {
| map = null
| }
|
| function createMapvLayer() {
| // 构造数据
| const positions = []
| const geojson = []
| let randomCount = 300
| while (randomCount--) {
| // 取区域内的随机点
| const point = [random(113 * 1000, 119 * 1000) / 1000, random(28 * 1000, 35 * 1000) / 1000]
|
| positions.push(Cesium.Cartesian3.fromDegrees(point[0], point[1]))
|
| geojson.push({
| geometry: {
| type: "Point",
| coordinates: point
| },
| count: 30 * Math.random()
| })
| }
| map.camera.flyTo({
| destination: Cesium.Rectangle.fromCartesianArray(positions)
| })
|
| // mapv图层参数
| const options = {
| fillStyle: "rgba(55, 50, 250, 0.8)",
| shadowColor: "rgba(255, 250, 50, 1)",
| shadowBlur: 20,
| size: 40,
| globalAlpha: 0.5,
| label: {
| show: true,
| fillStyle: "white"
| // shadowColor: 'yellow',
| // font: '20px Arial',
| // shadowBlur: 10,
| },
| gradient: {
| 0.25: "rgb(0,0,255)",
| 0.55: "rgb(0,255,0)",
| 0.85: "yellow",
| 1.0: "rgb(255,0,0)"
| },
| draw: "grid",
| data: geojson // 数据
| }
|
| // 创建MapV图层
| const mapVLayer = new mars3d.layer.MapVLayer(options)
| map.addLayer(mapVLayer)
| }
|
| function random(min, max) {
| return Math.floor(Math.random() * (max - min + 1) + min)
| }
|
|