百度API一次最多只支持10个点坐标转换 解决方法可以每十个点为一组,然后依次转换
<div id="map" style="width:100%;height:90%;"></div>
<div class="buttons">
<p @click="startGps">开始动画</p>
<p @click="endGps">结束动画</p>
</div>
</div>
const vm = this
let map = new BMapGL.Map('map')
map.centerAndZoom(new BMapGL.Point(115.463486, 38.908104), 17)
map.enableScrollWheelZoom(true)
let points = []
let translatePoint = []
for (var i = 0; i < this.list.length; i++) {
points.push(new BMapGL.Point(this.list[i].lng, this.list[i].lat))
}
let total = 0
let groupCount = 0
if (points.length % 10 > 0) {
groupCount = (points.length / 10) + 1
} else {
groupCount = (points.length / 10)
}
for (let i = 0; i < groupCount; i++) {
var pos = new Array()
for (let j = 0; j < 10; j++) {
if (total < points.length) {
let point = new BMapGL.Point(points[(i * 10) + j].lng, points[(i * 10) + j].lat)
pos.push(point)
}
total++
}
let convertor = new BMapGL.Convertor()
convertor.translate(pos, 1, 5, function(data) {
if (data.status === 0) {
for (let x = 0; x < data.points.length; x++) {
translatePoint.push({
lng: data.points[x].lng,
lat: data.points[x].lat
})
}
}
})
}
setTimeout(() => {
let pl = new BMapGL.Polyline(translatePoint)
vm.trackAni = new BMapGLLib.TrackAnimation(map, pl, {
overallView: true,
tilt: 30,
duration: 20000,
delay: 300
})
}, 1000)
/ 开始动画
startGps() {
this.trackAni.start()
},
endGps() {
this.trackAni.cancel()
},
|