在过去的几个小时里,我一直在苦思冥想。
我试图让Mapbox在加载时缩放到所有标记的边界区域。
但是,以下代码导致了错误:
在控制台日志图像之后出现此错误,因此经纬度坐标肯定存在。
未捕获的错误:无效的LngLat对象:(NaN,NaN)
const onLoad = () => {
let points = [];
props.cats.forEach(cat => (
points.push([ cat.lat, cat.lng ])
));
points.length > 0 && ref.current.getMap().fitBounds(points, {
padding: { top: 50, bottom: 50, left: 50, right: 50 },
easing(t) {
return t * (2 - t);
},
});
};