Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function fitViewport(viewport, points, padding = 10) {
try {
const bounds = getBounds(points);
return {
...viewport,
...fitBounds({
height: viewport.height,
width: viewport.width,
padding,
bounds,
}),
};
} catch (e) {
/* eslint no-console: 0 */
console.error('Could not auto zoom', e);
return viewport;
}
}
export function fitViewport(viewport, points, padding = 10) {
try {
const bounds = getBounds(points);
return {
...viewport,
...fitBounds({
height: viewport.height,
width: viewport.width,
padding,
bounds,
}),
};
} catch (e) {
/* eslint no-console: 0 */
console.error('Could not auto zoom', e);
return viewport;
}
}
test('fitBounds', (t) => {
for (const [input, expected] of FITBOUNDS_TEST_CASES) {
const result = fitBounds(input);
t.ok(Number.isFinite(result.longitude), 'get valid longitude');
t.ok(Number.isFinite(result.latitude), 'get valid latitude');
t.ok(Number.isFinite(result.zoom), 'get valid zoom');
t.deepEqual(
toLowPrecision(result),
toLowPrecision(expected),
'valid viewport returned'
);
}
t.end();
});
export const fitBoundsToTrack = trackBounds => (dispatch, getState) => {
const vp = fitBounds({
bounds: [[trackBounds.minLng, trackBounds.minLat], [trackBounds.maxLng, trackBounds.maxLat]],
width: getState().mapViewport.viewport.width,
height: getState().mapViewport.viewport.height,
padding: 50
});
dispatch(updateZoom(null, vp.latitude, vp.longitude, vp.zoom));
};