Use the geojson-bbox module to calculate the bbox of any GeoJSON.
Download this geojson-bbox/dist /geojson-bbox.min.js file and save it in your project.
Usage:
.html file
</body>
<script type="text/javascript" src="path/to/geojson-bbox.min.js"></script>
<body>
.js file:
// reading and parsing the GeoJSON file
const geojson = JSON.parse(geojsonfile);
// getting the bbox extent as an array [left, bottom, right, top] from the GeoJSON file
var gj_extent = bbox(geojson);
There is npm module for geojson-bbox
Node.js usage:
// const bbox = require('geojson-bbox'); // with CommonJS
import * as bbox from 'geojsjon-bbox';
const feature = {
type: 'Feature',
geometry: {
type: 'LineString',
coordinates: [
[10, 40], [40, 30], [20, 20], [30, 10]
]
}
};
const extent = bbox(feature);
// extent is array
// [10, 10, 40, 40]