Prevent JS error on track page when bounding box is invalid
This commit is contained in:
parent
70fa1a41c4
commit
7e33fb6424
|
@ -77,18 +77,21 @@ function Map({
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (boundsFromJson) {
|
if (boundsFromJson) {
|
||||||
const [minX, minY, maxX, maxY] = turfBbox(boundsFromJson)
|
const bbox = turfBbox(boundsFromJson);
|
||||||
const vp = new WebMercatorViewport({width: 1000, height: 800}).fitBounds(
|
if (bbox.every(v => Math.abs(v) !== Infinity)) {
|
||||||
[
|
const [minX, minY, maxX, maxY] = bbox;
|
||||||
[minX, minY],
|
const vp = new WebMercatorViewport({width: 1000, height: 800}).fitBounds(
|
||||||
[maxX, maxY],
|
[
|
||||||
],
|
[minX, minY],
|
||||||
{
|
[maxX, maxY],
|
||||||
padding: 20,
|
],
|
||||||
offset: [0, -100],
|
{
|
||||||
}
|
padding: 20,
|
||||||
)
|
offset: [0, -100],
|
||||||
setViewport(_.pick(vp, ['zoom', 'latitude', 'longitude']))
|
}
|
||||||
|
)
|
||||||
|
setViewport(_.pick(vp, ['zoom', 'latitude', 'longitude']))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [boundsFromJson])
|
}, [boundsFromJson])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue