建立 script标签进行加载javascript
export function MP(ak){ return new Promise(function (resolve, reject){ window.onload = function () { resolve(BMap) } var script = document.createElement("script"); script.type = "text/javascript"; script.src = "http://api.map.baidu.com/api?v=2.0&ak="+ak+"&callback=init"; script.onerror = reject; document.head.appendChild(script); }); }
使用:css
import {MP} from './map.js'; MP("your ak").then(BMap => { // do something })
须要
1 百度地图
2 echart
3 bmap.min.js 添加扩展,用于让百度地图支持echart https://github.com/apache/inc...java
可能会碰见两个问题:
1 地图图片错位 忘记加载leaflet.css
2 webpack 中使用leaflet 的一个主要问题是默认图标的加载问题,详见
https://segmentfault.com/q/10...webpack
另外也能够考虑使用动态建立<script>标签的方法,相似百度地图加载git
由于leaflet自己支持的是WGS84的坐标系 ,而百度地图在中国使用的是百度坐标系,因此若是要在百度地图中使用leaflet的话,一是须要绘图数据变动为百度地图的BD09坐标系,二是须要对leaflet添加扩展,使其在进行经纬度坐标转化时使用百度地图的映射系统github
解决方案: http://tiven.wang/articles/us...web
以上问题的代码示例 https://gitlab.com/dahou/mapsapache