使用Echarts制作地图

 {

    var dqmap = "deqing.json";
    var mapname = dqmap;

    var mapDate = [
      {
        name: '凤村镇',
        value: [112.089, 23.235, 299],
      },
      {
        name: '高良镇',
        value: [111.953, 23.281, 600],
      },
      {
        name: '永丰镇',
        value: [112.125, 23.331, 29999],
      },
      {
        name: '莫村镇',
        value: [112.125, 23.409, 29999],
      },
      {
        name: '武垄镇',
        value: [112.201, 23.31, 29999],
      },
      {
        name: '播植镇',
        value: [112.171, 23.242, 29999],
      },
      {
        name: '悦城镇',
        value: [112.14, 23.175, 29999],
      },
      {
        name: '九市镇',
        value: [111.987, 23.176, 29999],
      },
      {
        name: '新圩镇',
        value: [111.781, 23.179, 29999],
      },
      {
        name: '回龙镇',
        value: [111.67, 23.195, 29999],
      },
      {
        name: '官圩镇',
        value: [111.8, 23.270048, 400],
      },
      {
        name: '马圩镇',
        value: [111.849, 23.235, 70],
      },
      {
        name: '德城街道',
        value: [111.778, 23.138, 20],
      },
    ];
    var  option;
    myChart.showLoading();
    let index = -1;
    var timer = setInterval(function () {
      // 隐藏提示框
      myChart.dispatchAction({
        type: 'hideTip',
        seriesIndex: 0,
        dataIndex: index,
      });
      // 显示提示框
      myChart.dispatchAction({
        type: 'showTip',
        seriesIndex: 0,
        dataIndex: index + 1,
      });
      // 取消高亮指定的数据图形
      myChart.dispatchAction({
        type: 'downplay',
        seriesIndex: 0,
        dataIndex: index,
      });
      // 高亮指定的数据图形
      myChart.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: index + 1,
      });
      index++;
      if (index > 13) {
        index = -1;
      }
    }, 2000);

    myChart.on('mousemove', function (e) {
      clearInterval(timer);
      myChart.dispatchAction({
        type: 'downplay',
        seriesIndex: 0,
      });
      myChart.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: e.dataIndex,
      });
      myChart.dispatchAction({
        type: 'showTip',
        seriesIndex: 0,
        dataIndex: e.dataIndex,
      });
    }); //---------------------------------------------鼠标移入静止播放
    myChart.on('mouseout', function (e) {
      clearInterval(timer);
      myChart.dispatchAction({
        type: 'downplay',
        seriesIndex: 0,
        dataIndex: e.dataIndex,
      }); //鼠标移出后先把上次的高亮取消
      timer = setInterval(function () {
        // 隐藏提示框
        myChart.dispatchAction({
          type: 'hideTip',
          seriesIndex: 0,
          dataIndex: index,
        });
        // 显示提示框
        myChart.dispatchAction({
          type: 'showTip',
          seriesIndex: 0,
          dataIndex: index + 1,
        });
        // 取消高亮指定的数据图形
        myChart.dispatchAction({
          type: 'downplay',
          seriesIndex: 0,
          dataIndex: index,
        });
        // 高亮指定的数据图形
        myChart.dispatchAction({
          type: 'highlight',
          seriesIndex: 0,
          dataIndex: index + 1,
        });
        index++;
        if (index > 13) {
          index = -1;
        }
      }, 2000);
    });
    myChart.on('click', function (e) {
      console.log(e);
      var chooseName = mapJson.filter((item) => {
        return item.name == e.name;
      });
      console.log(chooseName);
      mapname = chooseName[0].json;

      console.log(mapname, '选择地图');
      mapDate = [];
      mapInit();
    });

    setTimeout(function () {
      mapInit();
    }, 1000);
    var mapInit = () => {
      console.log('返回', mapname);
      $.getJSON(mapname, function (geoJson) {
        echarts.registerMap('deqing', geoJson);
        myChart.hideLoading();
        option = {
          title: {
            top: 20,
            text: '德庆县',
            subtext: '',
            x: 'center',
            textStyle: {
              color: '#ccc',
            },
          },

         /* tooltip: {
            trigger: 'item',
            formatter: function(params) {
              console.log(params)
              return params.name + '?????: ' + params.value[2];
            }
          },*/
          visualMap: {
            min: 0,
            max: 1000,
            right: 100,
            seriesIndex: 1,
            type: 'piecewise',
            bottom: 100,
            textStyle: {
              color: '#FFFF',
            },
            //图例配置
              splitList: [
                {
                  gt: 500,
                  color: '#F5222D',
                  label: '>500',
                }, 
                {
                  gte: 300,
                  lte: 500,
                  color: '#FA541C ',
                  label: '300-500',
                },
                {
                  gte: 100,
                  lte: 300,
                  color: '#FA8C16',
                  label: '100-300人',
                }, 、
                {
                  lte: 100,
                  color: '#fbe1d6',
                  label: '<100',
                },
              ],

          },
          geo: {
            map: 'deqing',
            aspectScale: 0.75, //长宽比
            zoom: 1,
            roam: false,
            itemStyle: {
              normal: {
                areaColor: '#013C62',
                shadowColor: '#182f68',
                shadowOffsetX: 0,
                shadowOffsetY: 25,
              },
              emphasis: {
                areaColor: '#2AB8FF',
                borderWidth: 0,
                color: 'green',
                label: {
                  show: false,
                },
              },
            },
          },
          series: [
            {
              layoutCenter: ['20%', '25%'],
              type: 'map',
              roam: true,
              label: {
                normal: {
                  show: true,
                  textStyle: {
                    color: '#fff',
                  },
                },
                emphasis: {
                  textStyle: {
                    color: '#fff',
                  },
                },

              },


              itemStyle: {
                normal: {
                  borderColor: '#2ab8ff',
                  borderWidth: 1.5,
                  areaColor: '#12235c',
                },
                emphasis: {
                  areaColor: '#2AB8FF',
                  borderWidth: 0,
                  color: 'green',
                },
              },
              zoom: 1,
              roam: false,
              map: 'deqing', //使用
            },
            {
              type: 'effectScatter',
              coordinateSystem: 'geo',
              showEffectOn: 'render',
              rippleEffect: {
                period: 15,
                scale: 4,
                brushType: 'stroke',
              },
              hoverAnimation: true,
              itemStyle: {
                normal: {
                  color: '#ffff',
                  shadowBlur: 10,
                  shadowColor: '#333',
                },
              },
              data: mapDate,
            },
          ],
        };
        myChart.setOption(option);
      });
    };


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值