Browse Source

Change properties.bounding_box to bbox at top level

pull/482/head
Diana Shkolnikov 9 years ago
parent
commit
7ebb653c22
  1. 34
      helper/geojsonify.js
  2. 7
      test/unit/helper/geojsonify.js

34
helper/geojsonify.js

@ -35,8 +35,7 @@ var DETAILS_PROPS = [
'locality_id', 'locality_id',
'locality_a', 'locality_a',
'neighbourhood', 'neighbourhood',
'neighbourhood_id', 'neighbourhood_id'
'bounding_box'
]; ];
@ -65,6 +64,10 @@ function geojsonifyPlaces( docs ){
var geojson = GeoJSON.parse( geodata, { Point: ['lat', 'lng'] }); var geojson = GeoJSON.parse( geodata, { Point: ['lat', 'lng'] });
var geojsonExtentPoints = GeoJSON.parse( extentPoints, { Point: ['lat', 'lng'] }); var geojsonExtentPoints = GeoJSON.parse( extentPoints, { Point: ['lat', 'lng'] });
// to insert the bbox property at the top level of each feature, it must be done separately after
// initial geojson construction is finished
addBBoxPerFeature(geojson);
// bounding box calculations // bounding box calculations
computeBBox(geojson, geojsonExtentPoints); computeBBox(geojson, geojsonExtentPoints);
@ -117,6 +120,30 @@ function addLabel(src, dst) {
dst.label = labelGenerator(dst); dst.label = labelGenerator(dst);
} }
/**
* Add bounding box
*
* @param {object} geojson
*/
function addBBoxPerFeature(geojson) {
geojson.features.forEach(function (feature) {
if (!feature.properties.hasOwnProperty('bounding_box')) {
return;
}
if (feature.properties.bounding_box) {
feature.bbox = [
feature.properties.bounding_box.min_lon,
feature.properties.bounding_box.min_lat,
feature.properties.bounding_box.max_lon,
feature.properties.bounding_box.max_lat
];
}
delete feature.properties.bounding_box;
});
}
/** /**
* Collect all points from the geodata. * Collect all points from the geodata.
@ -222,6 +249,9 @@ function addMetaData(src, dst) {
dst.gid = makeGid(src); dst.gid = makeGid(src);
dst.layer = lookupLayer(src); dst.layer = lookupLayer(src);
dst.source = lookupSource(src); dst.source = lookupSource(src);
if (src.hasOwnProperty('bounding_box')) {
dst.bounding_box = src.bounding_box;
}
} }
/** /**

7
test/unit/helper/geojsonify.js

@ -333,14 +333,9 @@ module.exports.tests.search = function(test, common) {
'localadmin_id': '404521211', 'localadmin_id': '404521211',
'locality': 'New York', 'locality': 'New York',
'locality_id': '85977539', 'locality_id': '85977539',
'bounding_box': {
'min_lat': 40.6514712164,
'max_lat': 40.6737320588,
'min_lon': -73.8967895508,
'max_lon': -73.8665771484
},
'label': 'East New York, Brooklyn, NY, USA' 'label': 'East New York, Brooklyn, NY, USA'
}, },
'bbox': [-73.8967895508,40.6514712164,-73.8665771484,40.6737320588],
'geometry': { 'geometry': {
'type': 'Point', 'type': 'Point',
'coordinates': [ 'coordinates': [

Loading…
Cancel
Save