echarts地图的使用

var mapFeatures = echarts.getMap('china').geoJson.features;
let res = []
    mapFeatures.forEach(function (v) {
        // 地区名称
        let name = v.properties.name;
        let value = v.properties.cp;
        value.push(0)
        res.push({name,value})
        // 地区经纬度
        // geoCoordMap[name] = v.properties.cp;
    });
    let max = function (data) {
            return Number(data[0].value)
    }
    let min = function (data) {

        return Number(data[data.length-1].value)
    }
    var convertData = function (data) {
        res.forEach(item=>{
            data.forEach(ite=>{
                if(item.name == ite.name){
                    item.value[2] = ite.value
                }
            })
        })
        return res;
    };












var option = {
        tooltip: {
            trigger: 'item',
            triggerOn:"click",
            confine:true,
            position:"left",
            enterable: true,
            alwaysShowContent: false,
            formatter: function (params) {
                if(type==1){
                    if (params.value==0) {
                        return params.name + ' : ' + 0 + '家';
                    } else {
                        var res = params.name + ':<span style="font-size:22px;color:rgba(122,233,229,1);">' + params.data.value[2] + '</span>家' + '<br/>';
                        res += '<ul class="format-list">'
                        for (var i = 0; i < json.dcqylist.length; i++)
                            if (json.dcqylist[i].name == params.name)
                                res += '<li>' + json.dcqylist[i].DCQY + '</li>'
                        res += '</ul>'
                        return res
                    }
                }else if(type == 2){

                        return params.name + ' : ' + params.data.value[2] + 'GWh';

                }

            },
            textStyle: {
                fontFamily: 'PingFangSC-Regular',
                fontSize: 15,
                lineHeight: 18
            },
            backgroundColor: 'rgba(0,22,30,0.4)',
            borderColor: 'rgba(27, 113, 110, 0.5)',
            borderWidth: '1px',
            padding: [20, 20, 20, 20],
            extraCssText: 'border-radius:2px;'
           
        },
        legend: {
        },
        visualMap: {
            show: true,
            min: min(data),
            max: max(data),
            left: '20%',
            top: 'bottom',
            // text: ['高', '低'], // 文本,默认为数值文本
            seriesIndex: [0],
            inRange: {
                color: ["#48AFC3","#389FB3","#268DA0","#157C8E","#0C7385","#02697B"] // 蓝绿

            },
            textStyle: {
                show:false,
                fontFamily: 'PingFangSC-Regular',
                fontSize: 8,
                lineHeight: 18,
                color:'#fff'
            }
        },
        geo: {
            // regions: [{
            //     name: '广东',
            //     itemStyle: {
            //         areaColor: 'red',
            //         color: 'red'
            //     }
            // }],
            map: 'china',

            zoom:1.2,
            roam: true,
            left:"29%",
            label: {
                normal: {
                    show: false,
                    textStyle: {
                        color: "#e2e2e2",
                        fontSize: 8
                    },

                },
                emphasis: {
                    show: false,
                    textStyle: {
                        color: "#fff"
                    },

                }
            },
            itemStyle: {
                normal: {
                    areaColor: 'rgba(15, 118, 132, 0.9)',
                    color: 'rgba(128, 128, 128, 0)'
                },
                emphasis: {
                    areaColor: 'rgba(239,197,73,0.9)',
                }
            }
        },

        series: [
            {
                type: 'map',
                geoIndex: 0,

                data: convertData(data),
                showLegendSymbol:false,
            },


            {
                type: 'scatter',
                coordinateSystem: 'geo',
                symbol: 'circle', //气泡
                symbolSize: 5,
                label: {
                    normal: {
                        show: true,
                        position:"right",
                        formatter:"{b}",
                        textStyle: {
                            color: "#e2e2e2",
                            fontSize: 8
                        },

                    }
                },
                itemStyle: {
                    normal: {
                        color: '#e2e2e2', //标志颜色
                    }
                },

                data: convertData(data),

            },
        ]
    };
function getGzMap(_data) { if (_chinaMap == undefined) { var dom = document.getElementById("container"); _chinaMap = echarts.init(dom); _chinaMap.on('click', function(params) { console.log(params); var _type = params.seriesType; if (_type == "map") { //window.parent.aaa('aa') //调用父页面方法 } else if (_type == "effectScatter") { window.parent.showMap(); } }) } var option = { backgroundColor: 'rgba(0,0,0,0)', visualMap: { type: 'piecewise', show: false, min: 0, max: 300, splitNumber: 3, itemWidth: 10, itemHeight: 10, itemGap: 5, seriesIndex: [1], pieces: [ { min: 0, max: 100, label: '优' }, { min: 101, max: 200, label: '良' }, { min: 201, max: 300, label: '高风险' } ], //color: ['#FA4D08', '#4BD94F', '#FBD32B'], //红、绿、黄 color: ['#F8DAE6', '#FEF9B5', '#B0D8B3'], //红、黄、绿 textStyle: { color: '#9EA8B1', fontSize: 10 } }, tooltip: { formatter: '{b}' }, geo: { map: 'guangdong', roam: true, aspectScale: 1, zoom: 1.5, layoutCenter: ['55%', '40%'], layoutSize: 500, label: { normal: { show: true }, emphasis: { show: true } }, itemStyle: { normal: { areaColor: '#323c48', borderColor: '#111', borderColor: '#3BB4DF', shadowColor: '#25A3FC', shadowBlur: 10 }, emphasis: { areaColor: '#ddb926' } } }, series: [{ type: 'effectScatter', coordinateSystem: 'geo', data: unitData, symbolSize: 10, symbol: 'image://../../../../Content/images/One/fire.png', //symbolRotate: 35, rippleEffect: { period: 4, scale: 5, brushType: 'fill', }, label: { normal: { formatter: '{b}', position: 'right', show: false }, emphasis: { show: false } }, itemStyle: { normal: { color: '#fff' } } }, { name: '', type: 'map', geoIndex: 0, mapType: 'guangdong', // 自定义扩展图表类型 label: { normal: { show: true, } }, itemStyle: { normal: { label: { show: true, fontSize: 10, color: '#111' }, shadowColor: '#ddb926', shadowBlur: 5, }, emphasis: { label: { show: true }, shadowColor: 'rgba(0, 0, 0, 0.5)', shadowBlur: 10 } }, data: _data }, { type: 'effectScatter', coordinateSystem: 'geo', data: windData, symbolSize: 10, symbol: 'image://../../../../Content/images/One/wind.png', //symbolRotate: 35, rippleEffect: { period: 4, scale: 5, brushType: 'fill', }, label: { normal: { formatter: '{b}', position: 'right', show: false }, emphasis: { show: false } }, itemStyle: { normal: { color: '#fff' } } }, ] }; $.getJSON('../../MapCN/guangdong.json', function(chinaJson) { echarts.registerMap('guangdong', chinaJson); _chinaMap.setOption(option, true); }); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值