# cesium-动态闪烁点
# 介绍
之前介绍了点动态扩散效果,现在实现一下点的动态闪烁效果
# 实现效果

# 完整代码
这里使用vue实现
<template>
<div class="home">
<el-row type="flex" :gutter="20">
<el-col :span="24">
<div class="grid-content bg-purple">
<el-breadcrumb separator="/">
<el-breadcrumb-item>cesium</el-breadcrumb-item>
<el-breadcrumb-item>效果</el-breadcrumb-item>
<el-breadcrumb-item>动态闪烁点</el-breadcrumb-item>
</el-breadcrumb>
</div>
</el-col>
</el-row>
<el-row type="flex" :gutter="20">
<el-col :span="24">
<div class="grid-content bg-purple">
<cesiumComponent id="cesium" ref="refCesium"/>
</div>
</el-col>
</el-row>
<el-row type="flex" :gutter="20">
<el-col :span="24">
<div class="grid-content bg-purple">
<el-button type="primary" @click="addMarks()">添加标记</el-button>
<el-button type="primary" @click="removeMarks()">移除标记</el-button>
</div>
</el-col>
</el-row>
</div>
</template>
<script>
import cesiumComponent from '../cesium.vue'
export default {
name: "dynamic_flickering_point",
data() {
return {
_viewer: undefined,
_camera: undefined,
};
},
components: {
cesiumComponent
},
mounted() {
this.init();
let tileset = this._viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
id: '天街',
url: '../tianjie/tileset.json',
modelMatrix: Cesium.Matrix4.fromArray(
[0.9972458032561666, 0.04372029028528979, 0.05991113506964879, 0,
-0.03623787897545647, 0.9920229449104262, -0.12073646051879428, 0,
-0.06471185374661931, 0.11823287609043515, 0.9908750491338749, 0,
-663.0794944260269, 1211.490494620055, 2974.1003134818748, 1]),
}));
this.model = tileset;
this._viewer.flyTo(tileset, {
offset: {
heading: Cesium.Math.toRadians(20.0),//方向
pitch: Cesium.Math.toRadians(-25),//倾斜角度
range: 1000
}
});
},
methods: {
init() {
let that = this;
that.$refs.refCesium.initMap();
that._viewer = that.$refs.refCesium._viewer;
that._camera = that._viewer.camera;
that._viewer.scene.globe.depthTestAgainstTerrain = true;
},
/**
* 添加闪烁点标记
*/
addMarks() {
let mark = this._viewer.entities.getById('pointMark0');
if (mark) {
return;
}
let lon = 118.69693328438744;
let lat = 32.16565389248538;
let viewer = this._viewer;
let arr = [
[118.69232168070495, 32.17174377911045, '1']
, [118.70118355191211, 32.17149742965923, '1']
, [118.7135201280693, 32.17060732976496, '2']
, [118.7100182943429, 32.162827576311784, '2']
, [118.70330930974372, 32.16393800944561, '2']
, [118.69847930003235, 32.157558579127496, '1']
, [118.69667363062379, 32.15193789644726, '2']
, [118.71018941128641, 32.15143816299957, '1']
, [118.72503235072867, 32.16550092454843, '2']
, [118.72514124726581, 32.16078350776156, '1']
, [118.68319522051482, 32.17526753953092, '2']
, [118.67295317984683, 32.16930630619532, '1']
, [118.67520477557645, 32.160922933703525, '2']
, [118.68377541019898, 32.15496145901921, '1']
, [118.68704447669086, 32.16446774199275, '2']
, [118.7043719927273, 32.15781582115282, '2']
, [118.69821296130193, 32.16344450797241, '1']
, [118.70534769065021, 32.15041271677243, '1']
, [118.6918349411336, 32.16543250471732, '2']
, [118.68851486117792, 32.15898581278363, '1']
, [118.68819143314698, 32.15327145811716, '2']
, [118.69247031627323, 32.15111753617475, '1']
, [118.68762735329693, 32.17146614334811, '2']
];
for (let i = 0; i < arr.length; i++) {
let x = 1;
let pixelSize = 30;
let outLineOpacity = 0.2;
let outLineFlog = true;
let pixelSizeFlog = true;
let flog = true;
viewer.entities.add({
id: 'pointMark' + i,
name: "圆点point闪烁",
// position:Cesium.Cartesian3.fromDegrees(lon+0.03,lat+0.03,0),
position: Cesium.Cartesian3.fromDegrees(arr[i][0], arr[i][1], 0),
billboard: {
image: require('../../../assets/mark.png'),
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
scale: 0.4,
},
point: {
show: true, // default
color: new Cesium.CallbackProperty(function () {
if (flog) {
x = x - 0.03;
if (x <= 0) {
flog = false;
}
} else {
x = x + 0.03;
if (x >= 1) {
flog = true;
}
}
if (arr[i][2] === '1') {
return Cesium.Color.YELLOW.withAlpha(x);
} else {
return Cesium.Color.RED.withAlpha(x);
}
}, false),
pixelSize: new Cesium.CallbackProperty((time, result) => {
return pixelSizeFlog ? (pixelSize += 2,
pixelSize >= 30 && (pixelSizeFlog = false)) : (pixelSize = 10,
pixelSizeFlog = true),
pixelSize
}, false),
outlineColor: new Cesium.CallbackProperty(() => {
if (arr[i][2] === '1') {
return outLineFlog ? (outLineOpacity -= .035,
outLineOpacity <= 0 && (outLineFlog = false)) : (outLineOpacity = .7,
outLineFlog = true),
Cesium.Color.YELLOW.withAlpha(outLineOpacity)
} else {
return outLineFlog ? (outLineOpacity -= .035,
outLineOpacity <= 0 && (outLineFlog = false)) : (outLineOpacity = .7,
outLineFlog = true),
Cesium.Color.RED.withAlpha(outLineOpacity)
}
}, false),
outlineWidth: 30,
scaleByDistance: new Cesium.NearFarScalar(1200, 1, 5200, 0.4),
}
});
}
},
/**
* 移除标记
**/
removeMarks() {
let arr = [
[118.69232168070495, 32.17174377911045, '1']
, [118.70118355191211, 32.17149742965923, '1']
, [118.7135201280693, 32.17060732976496, '2']
, [118.7100182943429, 32.162827576311784, '2']
, [118.70330930974372, 32.16393800944561, '2']
, [118.69847930003235, 32.157558579127496, '1']
, [118.69667363062379, 32.15193789644726, '2']
, [118.71018941128641, 32.15143816299957, '1']
, [118.72503235072867, 32.16550092454843, '2']
, [118.72514124726581, 32.16078350776156, '1']
, [118.68319522051482, 32.17526753953092, '2']
, [118.67295317984683, 32.16930630619532, '1']
, [118.67520477557645, 32.160922933703525, '2']
, [118.68377541019898, 32.15496145901921, '1']
, [118.68704447669086, 32.16446774199275, '2']
, [118.7043719927273, 32.15781582115282, '2']
, [118.69821296130193, 32.16344450797241, '1']
, [118.70534769065021, 32.15041271677243, '1']
, [118.6918349411336, 32.16543250471732, '2']
, [118.68851486117792, 32.15898581278363, '1']
, [118.68819143314698, 32.15327145811716, '2']
, [118.69247031627323, 32.15111753617475, '1']
, [118.68762735329693, 32.17146614334811, '2']
];
for (let i = 0; i < arr.length; i++) {
let mark = this._viewer.entities.getById('pointMark' + i);
this._viewer.entities.remove(mark)
}
},
},
created() {
},
}
</script>
<style scoped>
.home {
height: 100%;
margin: 0;
padding: 0;
overflow-y: auto;
overflow-x: hidden;
}
.el-breadcrumb {
margin: 10px;
font-size: 15px;
}
#cesium {
max-height: 700px;
}
</style>
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# 核心代码
/**
* 添加闪烁点标记
*/
addMarks() {
let mark = this._viewer.entities.getById('pointMark0');
if (mark) {
return;
}
let lon = 118.69693328438744;
let lat = 32.16565389248538;
let viewer = this._viewer;
let arr = [
[118.69232168070495, 32.17174377911045, '1']
, [118.70118355191211, 32.17149742965923, '1']
, [118.7135201280693, 32.17060732976496, '2']
, [118.7100182943429, 32.162827576311784, '2']
, [118.70330930974372, 32.16393800944561, '2']
, [118.69847930003235, 32.157558579127496, '1']
, [118.69667363062379, 32.15193789644726, '2']
, [118.71018941128641, 32.15143816299957, '1']
, [118.72503235072867, 32.16550092454843, '2']
, [118.72514124726581, 32.16078350776156, '1']
, [118.68319522051482, 32.17526753953092, '2']
, [118.67295317984683, 32.16930630619532, '1']
, [118.67520477557645, 32.160922933703525, '2']
, [118.68377541019898, 32.15496145901921, '1']
, [118.68704447669086, 32.16446774199275, '2']
, [118.7043719927273, 32.15781582115282, '2']
, [118.69821296130193, 32.16344450797241, '1']
, [118.70534769065021, 32.15041271677243, '1']
, [118.6918349411336, 32.16543250471732, '2']
, [118.68851486117792, 32.15898581278363, '1']
, [118.68819143314698, 32.15327145811716, '2']
, [118.69247031627323, 32.15111753617475, '1']
, [118.68762735329693, 32.17146614334811, '2']
];
for (let i = 0; i < arr.length; i++) {
let x = 1;
let pixelSize = 30;
let outLineOpacity = 0.2;
let outLineFlog = true;
let pixelSizeFlog = true;
let flog = true;
viewer.entities.add({
id: 'pointMark' + i,
name: "圆点point闪烁",
// position:Cesium.Cartesian3.fromDegrees(lon+0.03,lat+0.03,0),
position: Cesium.Cartesian3.fromDegrees(arr[i][0], arr[i][1], 0),
billboard: {
image: require('../../../assets/mark.png'),
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
scale: 0.4,
},
point: {
show: true, // default
color: new Cesium.CallbackProperty(function () {
if (flog) {
x = x - 0.03;
if (x <= 0) {
flog = false;
}
} else {
x = x + 0.03;
if (x >= 1) {
flog = true;
}
}
if (arr[i][2] === '1') {
return Cesium.Color.YELLOW.withAlpha(x);
} else {
return Cesium.Color.RED.withAlpha(x);
}
}, false),
pixelSize: new Cesium.CallbackProperty((time, result) => {
return pixelSizeFlog ? (pixelSize += 2,
pixelSize >= 30 && (pixelSizeFlog = false)) : (pixelSize = 10,
pixelSizeFlog = true),
pixelSize
}, false),
outlineColor: new Cesium.CallbackProperty(() => {
if (arr[i][2] === '1') {
return outLineFlog ? (outLineOpacity -= .035,
outLineOpacity <= 0 && (outLineFlog = false)) : (outLineOpacity = .7,
outLineFlog = true),
Cesium.Color.YELLOW.withAlpha(outLineOpacity)
} else {
return outLineFlog ? (outLineOpacity -= .035,
outLineOpacity <= 0 && (outLineFlog = false)) : (outLineOpacity = .7,
outLineFlog = true),
Cesium.Color.RED.withAlpha(outLineOpacity)
}
}, false),
outlineWidth: 30,
scaleByDistance: new Cesium.NearFarScalar(1200, 1, 5200, 0.4),
}
});
}
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
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