江苏省地图大屏展示

Html部分绘制echarts图

<div id="chart3" style="width: 100%;height: 100%;"></div>

Js部分引入地图数据data.js

<script th:src="@{/js/geoJson/data.js}"></script>
<script type="text/javascript">

var chartDom = document.getElementById('chart3');
var myChart3 = echarts.init(chartDom);
var nameMap = '地图数据';
var geoCoordMap = {};
var mapData = [];
$.get('/js/geoJson/data.geoJson', function (gdMap) {
    echarts.registerMap(nameMap, gdMap);
    /*获取地图数据*/
    myChart3.showLoading();
    var mapFeatures = echarts.getMap(nameMap).geoJson.features;
    myChart3.hideLoading();
    var mapName = ''
    var mapInfo = []
    mapFeatures.forEach(function (v, index) {
        // 节点名称
        let name = v.properties.name;
        let value = Math.random() * 100;

        // 根据节点名称设置固定的颜色
        let color;
        switch (name) {
            case '徐州市':
                color = '#4c48c7';
                break;
            case '连云港市':
                color = '#5030a2';
                break;
            case '宿迁市':
                color = '#6552d5';
                break;
            case '淮安市':
                color = '#3892dc';
                break;
            case '盐城市':
                color = '#00b5c7';
                break;
            case '扬州市':
                color = '#4c78da';
                break;
            case '泰州市':
                color = '#4c48c7';
                break;
            case '南通市':
                color = '#4d77da';
                break;
            case '南京市':
                color = '#514aca';
                break;
            case '镇江市':
                color = '#514aca';
                break;
            case '常州市':
                color = '#00a7e1';
                break;
            case '无锡市':
                color = '#5030a2';
                break;
            case '苏州市':
                color = '#514aca';
                break;
            default:
                color = '#4c48c7'; // 默认颜色
        }

        mapData.push({
            name: name,
            value: value,
            itemStyle: {
                normal: {
                    areaColor: color // 固定颜色
                },
                emphasis: {
                    areaColor: '#6666ff' // 鼠标悬停时的颜色
                }
            }
        });

        mapInfo.push({
            name: name,
            code: v.properties.adcode
        });
        geoCoordMap[name] = v.properties.center; // 节点经纬度
    });

    // mapFeatures.forEach(function (v, index) { //使用下方visualMap随机颜色值时替换该方法
    //     // 节点名称
    //     mapData.push({
    //         name: v.properties.name,
    //         value: Math.random() * 100
    //     });
    //     mapInfo.push({
    //         name: v.properties.name,
    //         code: v.properties.adcode
    //     })
    //     mapName = mapName + (mapName ? ',' : '') + v.properties.name
    //     var name = v.properties.name;
    //     // 节点经纬度
    //     geoCoordMap[name] = v.properties.center;
    // });
    console.log(JSON.stringify(mapInfo))
    console.log(mapName)
    var serverdata = [
        { // 地图块的相关信息
            type: 'map',
            map: nameMap,
            zoom: 1.2,
            roam: false,
            selectedMode: "single",
            showLegendSymbol: false,
            visibility: "off",
            label: {
                show: true,
                normal: {
                    show: true,
                    textStyle: {
                        fontSize: 12,
                        fontWeight: 400,
                        color: '#fff'
                    }
                }
            },
            itemStyle: {
                emphasis: {
                    areaColor: '#6666ff' // 鼠标悬停时的颜色
                }
            },
            data: mapData
        }
    ]
    var optionMap = {
        // visualMap: { //使用随机颜色值
        //     type: "piecewise",
        //     pieces: [
        //         {max: 20, label: type[0], color: "#4c48c7"},
        //         {min: 20, max: 40, label: type[1], color: "#5030a2"},
        //         {min: 40, max: 60, label: type[2], color: "#6552d5"},
        //         {min: 60, max: 80, label: type[3], color: "#00babe"},
        //         {min: 80, label: type[4], color: "#3892dc"}
        //     ],
        //     show: false
        // },
        graphic: [
            {
                type: 'rect', // 添加一个矩形作为背景
                z: -1, // 确保矩形在文本后面
                left: '5%',
                top: '50%',
                shape: {
                    x: 0,
                    y: -20, // 调整垂直偏移量
                    width: 150, // 调整宽度
                    height: 200, // 调整高度
                    r: 5 // 圆角
                },
                style: {
                    fill: 'rgba(0,57,121,0.44)', // 背景颜色
                    stroke: '#2C58A6', // 边框颜色
                    lineWidth: 1 // 边框宽度
                }
            },
            {
                type: 'text',
                left: '8%',
                top: '55%',
                style: {
                    text: '省中心',
                    textAlign: 'left',
                    fill: '#fff',
                    fontSize: 16,
                    fontWeight: 'bold' // 设置省中心文本加粗
                }
            },
            {
                type: 'text',
                left: '8%',
                top: '60%',
                style: {
                    text: '个人证书:12 个\n\n单位证书:14 个\n\n设备证书:20 个\n\n软件证书:20 个\n\n管理员证书:20 个',
                    textAlign: 'left',
                    fill: '#fff',
                    fontSize: 12
                }
            }
        ],
        geo: {
            map: nameMap,
            show: false,
            roam: true,
            label: {
                normal: {
                    show: true
                },
                emphasis: {
                    show: false
                }
            }
        },
        series: serverdata
    };
    myChart3.clear()
    myChart3.resize()
    myChart3.setOption(optionMap, true);
});
</script>

/static / js / geoJson 下存放的地图相关数据文件 geoJson

1. data.geoJson

2. data.js

3.data2.geoJson

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值