Browse Source

Merge pull request #124 from pelias/issue84

try/catch extent()
pull/131/head
Peter Johnson a.k.a. insertcoffee 10 years ago
parent
commit
758b8fad60
  1. 14
      helper/geojsonify.js
  2. 2
      package.json
  3. 24
      test/unit/helper/geojsonify.js

14
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;
}

2
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",

24
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 = [

Loading…
Cancel
Save