Created
August 10, 2015 14:35
-
-
Save morlay/e98afc5028b688fc296d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qs from 'qs' | |
import scriptjs from 'scriptjs' | |
const $schoolMap = document.getElementById('school-map'); | |
const baiduMapUri = 'http://api.map.baidu.com/getscript'; | |
const baiduMapConf = { | |
v: '2.0', | |
ak: 'YOUR_ACCESS_KEY' | |
}; | |
function loadBaiduMapJs() { | |
return new Promise((resolve)=> { | |
scriptjs(`${baiduMapUri}?${qs.stringify(baiduMapConf)}`, ()=> { | |
resolve(window.BMap) | |
}); | |
}) | |
} | |
if ($schoolMap) { | |
loadBaiduMapJs() | |
.then((BMap)=> { | |
var myGeo = new BMap.Geocoder(); | |
myGeo.getPoint('北京市海淀区', function (point) { | |
if (point) { | |
var map = new BMap.Map('school-map'); | |
map.enableScrollWheelZoom(true); | |
map.centerAndZoom(point, 16); | |
map.addOverlay(new BMap.Marker(point)); | |
} else { | |
console.error('您选择地址没有解析到结果!'); | |
} | |
}, '北京市'); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment