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,18 +77,21 @@ function Map({
useEffect(() => {
if (boundsFromJson) {
const [minX, minY, maxX, maxY] = turfBbox(boundsFromJson)
const vp = new WebMercatorViewport({width: 1000, height: 800}).fitBounds(
[
[minX, minY],
[maxX, maxY],
],
{
padding: 20,
offset: [0, -100],
}
)
setViewport(_.pick(vp, ['zoom', 'latitude', 'longitude']))
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(
[
[minX, minY],
[maxX, maxY],
],
{
padding: 20,
offset: [0, -100],
}
)
setViewport(_.pick(vp, ['zoom', 'latitude', 'longitude']))
}
}
}, [boundsFromJson])