From 7ebb653c22fbcad6d7b73e1cc024445621041cf5 Mon Sep 17 00:00:00 2001 From: Diana Shkolnikov Date: Mon, 4 Apr 2016 22:20:49 -0400 Subject: [PATCH] Change properties.bounding_box to bbox at top level --- helper/geojsonify.js | 34 ++++++++++++++++++++++++++++++++-- test/unit/helper/geojsonify.js | 7 +------ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/helper/geojsonify.js b/helper/geojsonify.js index 1f9a60a8..a6e082eb 100644 --- a/helper/geojsonify.js +++ b/helper/geojsonify.js @@ -35,8 +35,7 @@ var DETAILS_PROPS = [ 'locality_id', 'locality_a', 'neighbourhood', - 'neighbourhood_id', - 'bounding_box' + 'neighbourhood_id' ]; @@ -65,6 +64,10 @@ function geojsonifyPlaces( docs ){ var geojson = GeoJSON.parse( geodata, { 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 computeBBox(geojson, geojsonExtentPoints); @@ -117,6 +120,30 @@ function addLabel(src, 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. @@ -222,6 +249,9 @@ function addMetaData(src, dst) { dst.gid = makeGid(src); dst.layer = lookupLayer(src); dst.source = lookupSource(src); + if (src.hasOwnProperty('bounding_box')) { + dst.bounding_box = src.bounding_box; + } } /** diff --git a/test/unit/helper/geojsonify.js b/test/unit/helper/geojsonify.js index 7b371b27..132f1e97 100644 --- a/test/unit/helper/geojsonify.js +++ b/test/unit/helper/geojsonify.js @@ -333,14 +333,9 @@ module.exports.tests.search = function(test, common) { 'localadmin_id': '404521211', 'locality': 'New York', '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' }, + 'bbox': [-73.8967895508,40.6514712164,-73.8665771484,40.6737320588], 'geometry': { 'type': 'Point', 'coordinates': [