echarts实现各个省份地图之广东省(海南岛显示过小问题解决)

各省份json:
http://datav.aliyun.com/portal/school/atlas/area_selector#&lat=22.65267050733856&lng=114.18983459472656&zoom=10

html部分

js部分


initMap();
    var hainan="广东"
// 地图
    function initMap(){
    //地图上显示的数据
    var dataJson=[
        {name: '广州市',value: 100 },{name: '韶关市',value: 450 },  
        {name: '深圳市',value: 345 },{name: '珠海市',value: 535 },  
        {name: '汕头市',value: 320 },{name: '佛山市',value: 234 },  
        {name: '江门市',value: 189 },{name: '湛江市',value: 99 },  
        {name: '茂名市',value: 79 },{name: '肇庆市',value: 190 },  
        {name: '惠州市',value: 390 },{name: '梅州市',value: 360 },
        {name: '汕尾市',value: 269 },{name: '河源市',value: 269 },
        {name: '阳江市',value: 269 },{name: '清远市',value: 269 },
        {name: '东莞市',value: 269 },{name: '中山市',value: 269 },
        {name: '潮州市',value: 269 },{name: '揭阳市',value: 269 },
        {name: '云浮市',value: 269 }
    ];
    //获取市的地图信息
    window.onload = function GetGeoMap() {
        var geoJson = null;
//从上面json链接获取url就可以换省份;
        var url = "https://geo.datav.aliyun.com/areas_v3/bound/460000_full.json";
        MapChart.showLoading();
        $.get(url, null, function (ret) {
            geoJson = ret;
            loadMap(geoJson);
        });
    }
//初始化地图容器
MapChart = echarts.init(document.getElementById('main'));
//设置地图。
var loadMap = function (geoJson) {
    echarts.registerMap('guangdong', geoJson);
    MapChart.hideLoading();
    var data = dataJson;
    //气泡点的位置
    var geoCoordMap = {
            '广州市':[120.171465,30.215236],
            '韶关市':[120.172763,30.326271],
            '深圳市':[120.027376,30.132934],
            '珠海市':[120.204053,30.374697],
            '汕头市':[120.362633,30.276603],
            '佛山市':[120.198623,30.166615],
            '江门市':[120.150693,29.962932],
            '湛江市':[119.801737,30.421187],
            '茂名市':[119.949869,29.849871],
            '肇庆市':[119.315101,30.231153],
            '惠州市':[119.585045,29.797437],
            '梅州市':[118.624346,29.404177],
            '汕尾市':[119.279089,29.472284],
            '河源市':[119.279089,29.472284],
            '阳江市':[119.279089,29.472284],
            '汕尾市':[119.279089,29.472284],
            '河源市':[119.279089,29.472284],
            '阳江市':[119.279089,29.472284],
            '清远市':[119.279089,29.472284],
            '东莞市':[119.279089,29.472284],
            '中山市':[119.279089,29.472284],
            '潮州市':[119.279089,29.472284],
            '揭阳市':[119.279089,29.472284],
            '云浮市':[119.279089,29.472284]
    }
    var convertData = function (data) {
        var res = [];
        for (var i = 0; i < data.length; i++) {
            var geoCoord = geoCoordMap[data[i].name];
            if (geoCoord) {
                res.push({
                    name: data[i].name,
                    value: geoCoord.concat(data[i].value)
                });
            }
        }
        return res;
    };
    var low=12;
    var high=600;
    var option = {
        tooltip: {
            trigger: 'item',
            //鼠标放上去显示的数据和文字
            formatter: function (params) {
                if (typeof (params.value)[2] == "undefined") {
                    return params.name + ' : ' + params.value;
                } else {
                    return params.name + ' : ' + params.value[2];
                }
            }
        },
        //在地图旁显示的数据
        visualMap: {
          show: true,
          calculable: false,//数值是否展示
          map: 'china',
          type: 'continuous',
          orient: 'horizontal', //控制条横向
          min: low,
          max: high,
          left: 'left',
          top: 'top',    
          text: [high, low],   
          inRange: {
            color: ['#C4E4FC','#54A4DE']
          },
          textStyle:{
             color:'#999999'
          },
          label: {
            show: false
          },
          emphasis:{
            label:{
              show: false,
            }
          },
          roam: false,
        },
        series: [
            {
                type: 'map',
                map: 'guangdong',
                geoIndex: 0,
                aspectScale: 0.75, //长宽比
                showLegendSymbol: true, // 存在legend时显示
                label: {
                    normal: {
                        show:true,
                        textStyle: {
                            color: '#fff',
                            fontSize: 9,
                        }
                    },
                    emphasis: {
                        show: true,
                        textStyle: {
                            color: '#fff'
                        }
                    }
                },
                roam: false,
                itemStyle: {
                    normal: {
                        areaColor: '#C4E4FC',
                        borderColor: '#fff',
                        borderWidth: 1,
                    },
                    emphasis: {
                        areaColor: '#55A4DE'
                    }
                },
                animation: false,
                data: data
            },

        ]
    };
//判断是否海南省
    if(hainan=='海南'){
        option.series[0].center = [109.844902, 19.0392];
        option.series[0].layoutCenter = ['35%', '50%'];
        option.series[0].layoutSize = "500%";
    } else { //非显示海南时,将设置的参数恢复默认值
      option.series[0].center = undefined;
      option.series[0].layoutCenter = undefined;
      option.series[0].layoutSize = undefined;
}

    MapChart.setOption(option);
}
}



你可能感兴趣的:(echarts实现各个省份地图之广东省(海南岛显示过小问题解决))