【Echarts】 绘制世界地图和中国省份

部分代码

# 参数设置
lineOptions: {
  backgroundColor: 'transparent',
  title: {
    text: this.title,
    left: 'center',
    top: "5",
    textStyle: {
        color: '#333',
        fontSize: '20'
    }
  },
  geo: {
    map: 'worldAndChina', // china/world
    center: [xxx,xxxx], // 视角中心点,经纬度
    zoom: 5, // 当前视角缩放比例, china:1;world:3,
    roam: true,
    silent: true,
    top: "top",
    label: {
      normal: {
        show: true,
      }
    },
    itemStyle: {
      normal: {
        areaColor: '#ACBDEF99',
        borderColor: '#fff'
      },
      emphasis: {
        areaColor: '#ACBDEF',
      }
    },
  },
  grid: {
    containLabel: true,
    left: "10",
    right: "10%",
    bottom: "10"
  },
  toolbox: {
    feature: {
      restore: {
        icon:
          "path://M744.825185 959.604364c99.432617-180.095751 116.152417-454.878025-274.385231-445.671339l0 221.86404L134.765845 400.102491 470.439954 64.394612l0 217.134319C938.120562 269.358751 990.225267 694.347025 744.825185 959.604364L744.825185 959.604364 744.825185 959.604364zM744.825185 959.604364"
      },
      saveAsImage: {},
    }
  },
  tooltip: {
    triggerOn: 'mousemove',
    confine: true, // 是否限制在图表区域
    extraCssText: "box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);",
    backgroundColor: "#dde4ed",
    padding: 10,
    textStyle: {
      color: "#000"
    },
    position:"right",
  },
  series: []
},
## 渲染绘制
let echartsBox = document.getElementById("echartsMap");
let myChart = window.echarts.init(echartsBox);
 myChart.showLoading({
   text: "数据加载中 请稍后...",
   textStyle: {
     fontSize: 20
   }
 });

metricData= [{
  name: el,
  value: el.prop_lon_lat, // 此处为经纬度
}]
// 填充数据
let echartsOptions = this.lineOptions
echartsOptions.series.push({
    type: 'effectScatter',
    name: 'test',
    coordinateSystem: 'geo',
    symbol: "circle", // 标记的图形
    symbolSize: 7,
    showEffectOn: 'render',
    data: metricData,
    itemStyle: {
      color: "#00a65a",
    },
}),


myChart.clear(); 
this.$nextTick(() => {
  myChart.setOption(echartsOptions, true);
  this.pointClick(myChart);
  // 监听地图缩放事件,
  // 由于缩小地图的时候,地图文字存在堆在一起的情况,故判断zoom,控制label的展示和消失
  // 该部分参考:https://juejin.im/post/5dca2e5b5188255719075f64
  myChart.on('georoam', (params) => {
    //获取最新的option配制
    const { center, zoom } = myChart.getOption().geo[0];
    echartsOptions.geo.zoom = zoom;
    echartsOptions.geo.center = center;
    if(zoom<3 && this.mapIsLarge){
      echartsOptions.geo.label.normal.show = false;
      myChart.setOption(echartsOptions, true);
      this.mapIsLarge = false;
    }else if(zoom>=3 && !this.mapIsLarge){
      echartsOptions.geo.label.normal.show = true;
      myChart.setOption(echartsOptions, true);
      this.mapIsLarge = true;
    }
  });
});

截图

在这里插入图片描述
在这里插入图片描述

地图经纬度资源下载

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值