Prevent JS error on track page when bounding box is invalid

This commit is contained in:
Paul Bienkowski 2022-03-02 19:02:24 +01:00
parent 70fa1a41c4
commit 7e33fb6424

View file

@ -77,7 +77,9 @@ function Map({
useEffect(() => { useEffect(() => {
if (boundsFromJson) { if (boundsFromJson) {
const [minX, minY, maxX, maxY] = turfBbox(boundsFromJson) const bbox = turfBbox(boundsFromJson);
if (bbox.every(v => Math.abs(v) !== Infinity)) {
const [minX, minY, maxX, maxY] = bbox;
const vp = new WebMercatorViewport({width: 1000, height: 800}).fitBounds( const vp = new WebMercatorViewport({width: 1000, height: 800}).fitBounds(
[ [
[minX, minY], [minX, minY],
@ -90,6 +92,7 @@ function Map({
) )
setViewport(_.pick(vp, ['zoom', 'latitude', 'longitude'])) setViewport(_.pick(vp, ['zoom', 'latitude', 'longitude']))
} }
}
}, [boundsFromJson]) }, [boundsFromJson])
return ( return (