代码
const map = new BMap.Map('map');
map.centerAndZoom(new BMap.Point(116.404, 39.915), 6);
map.enableScrollWheelZoom(true);
map.setTilt(45);
const start = [116.404, 39.915];
const destinations = [
[126.642, 45.756],
[121.472, 31.231],
[113.264, 23.129],
[104.066, 30.572],
[91.132, 29.66],
[87.617, 43.792],
[108.948, 34.263],
[102.712, 25.04],
];
const arcData = {
type: 'FeatureCollection',
features: destinations.map(function (destination) {
return {
type: 'Feature',
geometry: {
type: 'LineString',
coordinates: [start, destination],
},
};
}),
};
const flyLineLayer = new BMap.FlyLineLayer({
mode: 'arc',
arcHeight: 0.2,
curvature: 0.15,
strokeColor: 'rgba(255, 71, 26, 0.9)',
strokeWeight: 4,
});
map.addLayer(flyLineLayer);
flyLineLayer.setData(arcData);
const arcHeightInput = document.getElementById('arc-height');
const curvatureInput = document.getElementById('curvature');
function updateArcOptions() {
const arcHeight = Number(arcHeightInput.value);
const curvature = Number(curvatureInput.value);
flyLineLayer.setOptions({
arcHeight: arcHeight,
curvature: curvature,
});
document.getElementById('arc-height-value').textContent = arcHeight.toFixed(2);
document.getElementById('curvature-value').textContent = curvature.toFixed(2);
}
arcHeightInput.addEventListener('input', updateArcOptions);
curvatureInput.addEventListener('input', updateArcOptions);
通过调整 arcHeight 和 curvature 控制弧线飞线的高度与水平方向弯曲程度。
预览