代码
const map = new BMap.Map('map');
map.centerAndZoom(new BMap.Point(116.404, 39.915), 6);
map.enableScrollWheelZoom(true);
map.setTilt(45);
map.setMapStyle({
styleJson: darkStyle,
merge: true,
});
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',
properties: {
name: 'to ' + destination.join(','),
},
geometry: {
type: 'LineString',
coordinates: [start, destination],
},
};
}),
};
const flyLineLayer = new BMap.FlyLineLayer({
mode: 'arc',
duration: 6,
interval: 1,
trailLength: 0.8,
baseOpacity: 0.1,
animation: true,
randomPhase: false,
blend: 'lighter',
strokeColor: 'rgba(120, 160, 255, 0.9)',
strokeWeight: 4,
});
map.addLayer(flyLineLayer);
flyLineLayer.setData(arcData);
const controls = {
duration: document.getElementById('duration'),
interval: document.getElementById('interval'),
trailLength: document.getElementById('trail'),
baseOpacity: document.getElementById('base'),
animation: document.getElementById('animation'),
blend: document.getElementById('blend'),
};
function updateAnimationOptions() {
const duration = Number(controls.duration.value);
const interval = Number(controls.interval.value);
const trailLength = Number(controls.trailLength.value);
const baseOpacity = Number(controls.baseOpacity.value);
flyLineLayer.setOptions({
duration: duration,
interval: interval,
trailLength: trailLength,
baseOpacity: baseOpacity,
animation: controls.animation.value === 'true',
blend: controls.blend.value,
});
document.getElementById('duration-value').textContent = duration + ' s';
document.getElementById('interval-value').textContent = interval.toFixed(2);
document.getElementById('trail-value').textContent = trailLength.toFixed(2);
document.getElementById('base-value').textContent = baseOpacity.toFixed(2);
}
controls.duration.addEventListener('input', updateAnimationOptions);
controls.interval.addEventListener('input', updateAnimationOptions);
controls.trailLength.addEventListener('input', updateAnimationOptions);
controls.baseOpacity.addEventListener('input', updateAnimationOptions);
controls.animation.addEventListener('change', updateAnimationOptions);
controls.blend.addEventListener('change', updateAnimationOptions);
通过调整动画时长、粒子间距、拖尾长度、底线透明度、动画开关和混合模式,观察弧线飞线的动效变化。
预览