最近公司在做一个街道地图的项目,之前都是直接用echart中自带的地图,但是这次要求街道地图,echart要弄接到全国的街道地图就不太好搞了,(这个具体没研究),就直接接了百度地图。 使用百度地图首先要去官网申请ak,百度2.0已经支持https访问了。 init方法里面要这么写: init(){ //防止页面警告dom已经存在
if(this.myChart && this.dispose) {
this.myChart.dispose();
this.myChart = null;
}
!this.myChart && (this.myChart = echarts.init(document.getElementById('main')));
this.options && this.myChart.setOption(this.options, true);
//echart配置的注入加百度地图的配置
var bmap = this.myChart.getModel().getComponent('bmap').getBMap();
//设置百度地图的显示范围,超出弹回,要使用这个功能,还得引入
<!--<script type="text/javascript" src="https://api.map.baidu.com/library/AreaRestriction/1.2/src/AreaRestriction_min.js"></script>-->
var b = new BMap.Bounds(new BMap.Point(116.027143, 39.772348),new BMap.Point(116.832025, 40.126349));
try {
BMapLib.AreaRestriction.setBounds(bmap, b);
} catch (e) {
;
}
}