Skip to content

Instantly share code, notes, and snippets.

@JamesChevalier
JamesChevalier / index.js
Created March 15, 2016 01:23
Get the bounding box of a GeoJSON object, regardless of how many polygons it contains. The core of this is from http://mikefowler.me/2014/06/10/drawing-geojson-in-a-canvas/
function getBoundingBox(data) {
var bounds = {}, coordinates, point, latitude, longitude;
// Loop through each "feature"
for (var i = 0; i < data.features.length; i++) {
coordinates = data.features[i].geometry.coordinates;
if(coordinates.length === 1){
// It's only a single Polygon
// For each individual coordinate in this feature's coordinates...