From 109758b25ed00ed9f97713d0864f8ef684e5c537 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 23 Nov 2014 08:52:24 +0100 Subject: [PATCH] add geojson bbox --- helper/geojsonify.js | 8 +++++++- package.json | 5 +++-- test/unit/helper/geojsonify.js | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/helper/geojsonify.js b/helper/geojsonify.js index 630f12be..eadd61d1 100644 --- a/helper/geojsonify.js +++ b/helper/geojsonify.js @@ -1,5 +1,6 @@ var GeoJSON = require('geojson'), + extent = require('geojson-extent'), outputGenerator = require('./outputGenerator'); function search( docs ){ @@ -54,7 +55,12 @@ function search( docs ){ }); // convert to geojson - return GeoJSON.parse( geodata, { Point: ['lat', 'lng'] } ); + var geojson = GeoJSON.parse( geodata, { + Point: ['lat', 'lng'] + }); + + geojson.bbox = extent( geojson ) || undefined; + return geojson; } diff --git a/package.json b/package.json index aacccf89..6ef30cc1 100644 --- a/package.json +++ b/package.json @@ -32,12 +32,13 @@ "elasticsearch": ">=1.2.1" }, "dependencies": { + "async": "^0.9.0", "express": "^4.8.8", "geojson": "^0.2.0", + "geojson-extent": "^0.3.1", "geopipes-elasticsearch-backend": "0.0.8", "pelias-esclient": "0.0.25", - "toobusy": "^0.2.4", - "async": "^0.9.0" + "toobusy": "^0.2.4" }, "devDependencies": { "ciao": "^0.3.4", diff --git a/test/unit/helper/geojsonify.js b/test/unit/helper/geojsonify.js index 27bb8b31..f08490c7 100644 --- a/test/unit/helper/geojsonify.js +++ b/test/unit/helper/geojsonify.js @@ -83,6 +83,7 @@ module.exports.tests.search = function(test, common) { var expected = { "type": "FeatureCollection", + "bbox": [ -0.1069716, 51.517806, -0.101795, 51.5337144 ], "features": [ { "type": "Feature",