使用echarts的map-polygon地图

前言


一 申请百度地图AK

进入百度地图开放平台>开发文档>Web服务API>获取密钥AK。如图

在这里插入图片描述

二、使用步骤

1.将百度地图sdk插入到html模板中

代码如下(示例):

<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=你的AK密钥"></script>

2.在插入图表的组件中插入如下代码

代码如下(示例):

import 'echarts/extension/bmap/bmap'

3.引入echarts

安装echarts

npm install echarts --save

引入全局

main.js

import echarts from 'echarts';
Vue.prototype.$echarts = echarts;

4.将官网实例的地图代码CV到组件中。

(提示):出现如下报错 echart is undefined

解决办法
let that = this;//在外部保存this


    return {
        type: 'polygon',
        shape: {
            points: that.$echarts.graphic.clipPointsByRect(points, {//将this.$echarts改成that.$echarts
                x: params.coordSys.x,
                y: params.coordSys.y,
                width: params.coordSys.width,
                height: params.coordSys.height
            })
        },
        style: api.style({
            fill: color,
            stroke: that.$echarts.color.lift(color)//将this.$echarts改成that.$echarts
        })
    };
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值