123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import * as echarts from 'echarts';
- import styles from './mapComponent.less';
- import React, { useEffect, useRef } from 'react';
- import { queryMapJson, queryProvinceData } from '@/services/dataBoardService';
- import { message } from 'antd';
- interface propsData {
- userData: number;
- deviceData: number;
- }
- /**
- * 地图组件
- * @constructor
- */
- const MapComponent: React.FC<propsData> = (props) => {
- const chartRef: any = useRef();
- const { userData, deviceData } = props;
- const renderMapData = (areaList: any) => {
- // 初始化统计图对象
- const myChart = echarts.init(chartRef.current);
- let options: any;
- queryMapJson().then((res) => {
- if (res && res.code === 0) {
- // 获取地图数据
- const uploadedDataURL = res.data.map_json;
- echarts.registerMap('myMap', uploadedDataURL);
- options = {
- tooltip: {
- show: false,
- },
- geo: {
- map: 'myMap',
- zoom: 1.1,
- show: true,
- roam: false,
- label: {
- emphasis: {
- show: false,
- },
- },
- itemStyle: {
- normal: {
- areaColor: '#091632',
- borderColor: '#1773c3',
- shadowColor: '#1773c3',
- shadowBlur: 20,
- },
- },
- },
- visualMap: {
- show: false,
- max: 1,
- inRange: {
- color: ['#ceb10b'],
- },
- seriesIndex: 0,
- },
- series: [
- {
- type: 'map',
- map: 'myMap',
- zoom: 1.1,
- geoIndex: 1,
- aspectScale: 0.75, //长宽比
- showLegendSymbol: true, // 存在legend时显示
- label: {
- normal: {
- show: true,
- textStyle: {
- color: '#d3d3d3',
- },
- },
- emphasis: {
- show: true,
- textStyle: {
- color: '#ff0000',
- },
- },
- },
- roam: false,
- itemStyle: {
- normal: {
- areaColor: '#031525',
- borderColor: '#3B5077',
- borderWidth: 1,
- },
- emphasis: {
- areaColor: '#0f2c70',
- },
- },
- data: areaList,
- },
- ],
- };
- myChart.setOption(options);
- } else {
- message.error(res?.message);
- }
- });
- // 组件卸载
- return () => {
- myChart.clear();
- };
- };
- // 获取数据
- const getAreaDataList = () => {
- queryProvinceData().then((res) => {
- if (res && res.code === 0) {
- const areaList = res.data.map((item: any) => {
- const nameWithoutCity = item.name.replace(/[省|市]$/, '');
- return {
- ...item,
- name: nameWithoutCity,
- };
- });
- renderMapData(areaList);
- }
- });
- };
- useEffect(() => {
- getAreaDataList();
- }, []);
- return (
- <div className={styles.container}>
- <div ref={chartRef} className={styles.mapContent} />
- <div className={styles.content_num}>
- <div className={styles.content}>
- <div style={{ display: 'flex' }}>
- <div className={styles.content_title}>用户数</div>
- <div className={styles.content_value}>{userData * 2}</div>
- </div>
- <div style={{ display: 'flex' }}>
- <div className={styles.content_title}>设备数</div>
- <div className={styles.content_value}>{deviceData * 6}</div>
- </div>
- </div>
- </div>
- </div>
- );
- };
- export default MapComponent;
|