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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
| <script>
| import * as echarts from 'echarts';
| import base from './mixins/base.js';
| import { defineComponent } from 'vue';
| import mapCommon from '@/utils/mapCommon.js';
| const { throttle } = mapCommon;
| // 正常的图标
| import HomeNormalImage from '@/assets/images/home-normal.png';
| // 充电的图标
| import HomeChargeImage from '@/assets/images/home-charge.png';
| // 告警图标
| import HomeWarnImage from '@/assets/images/home-warn.png';
| // 放电图标
| import HomeDischargeImage from '@/assets/images/home-discharge.png';
| // 停电放电图标
| import HomeTingDianImage from '@/assets/images/home-tingdian.png';
| // 透明背景图标
| import HomeTransImage from '@/assets/images/home-trans.png';
|
| export default defineComponent({
| name: 'MapChart',
| mixins: [base],
| props: {
| roam: {
| type: [String, Boolean],
| validator: (v) => [true, false, 'scale', 'move'].includes(v),
| default: true
| }
| },
| data() {
| return {
| name: 'zhongguo'
| };
| },
| methods: {
| setMapName() {
| this.init();
| },
| init() {
| const option = this.getOption([]);
| this.setOption(option);
| },
| async getOption(list) {
| const mapName = this.name;
| let data = [
| {
| name: '节',
| label: '测试机房1',
| value: 8,
| color: '#7668F9',
| points: [118.8062, 31.9208]
| },
| {
| name: '',
| label: '测试机房2',
| value: 100,
| color: '#0081FF',
| points: [127.9688, 45.368]
| },
| {
| name: '',
| label: '测试机房3',
| value: 100,
| color: '#0081FF',
| points: [110.3467, 41.4899]
| },
| {
| name: '节',
| label: '测试机房4',
| value: 50,
| color: '#FF6B6C',
| points: [125.8154, 44.2584]
| },
| {
| name: '',
| value: 8,
| label: '测试机房6',
| color: '#7668F9',
| points: [116.4551, 40.2539]
| },
| {
| name: '节',
| label: '测试机房7',
| value: 8,
| color: '#66F842',
| points: [123.1238, 42.1216]
| },
| {
| name: '节',
| label: '测试机房8',
| value: 100,
| color: '#0081FF',
| points: [114.4995, 38.1006]
| }
| ];
| data = list;
| // eslint-disable-next-line @typescript-eslint/no-var-requires
| const geoJson = await import(`../../../public/mapJson/${mapName}.json`);
| echarts.registerMap(mapName, geoJson);
|
| const areaList = geoJson.features || [];
| const data0 = [];
| areaList.forEach((v) => {
| data0.push({
| name: v.properties.name,
| value: Math.floor(Math.random() * 2) * 100
| });
| });
|
| const convertData = function (data) {
| const res = [];
| for (let i = 0; i < data.length; i++) {
| const item = data[i];
| res.push({
| name: item.name,
| color: item.color,
| fontColor: item.fontColor,
| value: item.points.concat(data[i].value),
| label: item.label ? item.label : '',
| data: item
| });
| }
| return res;
| };
| return {
| tooltip: {
| show: true,
| formatter(params) {
| // console.log(params);
| return params.data.label;
| }
| },
| visualMap:
| {
| show: false,
| type: 'continuous',
| text: ['', ''],
| showLabel: true,
| left: '50',
| min: 0,
| max: 100,
| inRange: {
| color: ['#025483', '#116493']
| },
| // seriesIndex: [1],
| seriesIndex: 1
| },
| geo: {
| show: true,
| map: mapName,
| label: {
| normal: {
| show: false
| },
| emphasis: {
| show: false
| }
| },
| roam: this.roam,
| itemStyle: {
| normal: {
| borderColor: 'rgba(147, 235, 248, 1)',
| borderWidth: 1,
| areaColor: {
| type: 'radial',
| x: 0.5,
| y: 0.5,
| r: 0.8,
| colorStops: [
| {
| offset: 0,
| color: 'rgba(147, 235, 248, 0)' // 0% 处的颜色
| },
| {
| offset: 1,
| color: 'rgba(147, 235, 248, .2)' // 100% 处的颜色
| }
| ],
| globalCoord: false // 缺省为 false
| },
| shadowColor: 'rgba(128, 217, 248, 1)',
| shadowOffsetX: -2,
| shadowOffsetY: 2,
| shadowBlur: 10
| },
| emphasis: {
| areaColor: '#1ecee5',
| borderWidth: 0,
| label: {
| show: false
| }
| }
| }
| },
| series: [
| // 图片底色
| {
| name: '',
| type: 'scatter',
| coordinateSystem: 'geo',
| symbol: 'circle',
| symbolSize: [24, 24],
| label: {
| formatter: '{b}',
| position: 'inside',
| show: true,
| color: '#FFFFFF',
| fontWeight: 'bold'
| },
| itemStyle: {
| color(params) {
| return params.data.color;
| }
| },
| data: convertData(data),
| z: 3
| },
| {
| // 图片
| name: '图片',
| type: 'scatter',
| coordinateSystem: 'geo',
| symbol: function (value, params) {
| let img;
| const color = params.data.color;
| // let color = "#ff6b6c";
| switch (color) {
| case '#0081ff': // 浮充
| img = HomeChargeImage;
| break;
| case '#ff6b6c': // 放电
| img = HomeDischargeImage;
| break;
| case '#66f842': // 充电
| img = HomeNormalImage;
| break;
| case '#7668f9': // 停电
| img = HomeTingDianImage;
| break;
| default:
| // img = HomeChargeImage;
| img = HomeTransImage;
| break;
| }
| return params.data.name ? 'circle' : 'image://' + img;
| },
| symbolSize: [24, 24],
| label: {
| formatter: '{b}',
| position: 'inside',
| show: true,
| color: '#FFFFFF',
| fontWeight: 'bold'
| },
| itemStyle: {
| color(params) {
| return params.data.color;
| }
| },
| data: convertData(data),
| showEffectOn: 'render',
| rippleEffect: {
| brushType: 'stroke'
| },
| hoverAnimation: true,
| // zlevel: 3
| z: 4
| },
| {
| name: '波纹',
| type: 'effectScatter',
| coordinateSystem: 'geo',
| rippleEffect: {
| scale: 3
| },
| symbolSize: [18, 18],
| data: convertData(data),
| itemStyle: {
| color(params) {
| return params.data.color;
| }
| },
| tooltip: {
| show: true
| },
| // zlevel: 2
| z: 2
| },
| {
| type: 'map',
| map: mapName,
| geoIndex: 0,
| aspectScale: 0.75, // 长宽比
| showLegendSymbol: false, // 存在legend时显示
| label: {
| normal: {
| show: true
| },
| emphasis: {
| show: false,
| textStyle: {
| color: '#FF0000'
| }
| }
| },
| itemStyle: {
| areaColor: '#FF0000'
| },
| roam: true,
| animation: false,
| data: data0,
| tooltip: {
| show: false
| }
| }
| ]
| };
| }
| },
| mounted() {
| const chart = this.$options.chart;
| this.setMapName();
| chart.off('click'); // 防止chart点击触发多次
| chart.on('click', (params) => {
| this.handleClick(params);
| });
| chart.off('georoam');
| chart.on(
| 'georoam',
| throttle(() => {
| const option = chart.getOption();
| chart.setOption(option);
| }, 100)
| );
| }
| });
| </script>
|
| <template>
| <div
| class="e-chart-root"
| :class="{ 'full-screen': fullScreenFlag }"
| @click="handleClick"
| @dblclick="fullScreen">
| <div class="e-chart-container">
| <div class="e-chart" ref="chart"></div>
| <slot name="tools"></slot>
| </div>
| <div class="export-chart-wrapper">
| <div class="export-chart" ref="exportChart"></div>
| </div>
| </div>
| </template>
|
| <style scoped lang="scss">
|
| </style>
|
|