diff --git a/helper/geojsonify.js b/helper/geojsonify.js index 299bb4bb..ec1e20f6 100644 --- a/helper/geojsonify.js +++ b/helper/geojsonify.js @@ -61,8 +61,18 @@ function search( docs, params ){ // convert to geojson var geojson = GeoJSON.parse( geodata, { Point: ['lat', 'lng'] }); - // add bbox - geojson.bbox = extent( geojson ) || undefined; + // bounding box calculations + // @note: extent() sometimes throws Errors for unusual data + // eg: https://github.com/pelias/pelias/issues/84 + try { + var bbox = extent( geojson ); + if( !!bbox ){ + geojson.bbox = bbox; + } + } catch( e ){ + console.error( 'bbox error', e.message, e.stack ); + console.error( 'geojson', JSON.stringify( geojson, null, 2 ) ); + } return geojson; } diff --git a/package.json b/package.json index ae77f1ae..526e3e5c 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "dependencies": { "async": "^0.9.0", "express": "^4.8.8", - "geojson": "^0.2.0", + "geojson": "^0.2.1", "geojson-extent": "^0.3.1", "geopipes-elasticsearch-backend": "0.0.12", "is-object": "^1.0.1", diff --git a/test/unit/helper/geojsonify.js b/test/unit/helper/geojsonify.js index 9f1aca4c..831c24cc 100644 --- a/test/unit/helper/geojsonify.js +++ b/test/unit/helper/geojsonify.js @@ -11,6 +11,30 @@ module.exports.tests.interface = function(test, common) { }); }; +// ref: https://github.com/pelias/pelias/issues/84 +module.exports.tests.earth = function(test, common) { + + var earth = [{ + '_type': 'geoname', + '_id': '6295630', + 'name': { + 'default': 'Earth' + }, + 'center_point': { + 'lon': 0, + 'lat': 0 + } + }]; + + test('earth', function(t) { + t.doesNotThrow(function(){ + geojsonify.search( earth, { details: true } ); + }); + t.end(); + }); + +}; + module.exports.tests.search = function(test, common) { var input = [