diff --git a/helper/geojsonify.js b/helper/geojsonify.js index 515446ce..0b9d46ac 100644 --- a/helper/geojsonify.js +++ b/helper/geojsonify.js @@ -28,6 +28,16 @@ function geojsonifyPlaces( params, docs ){ const geojson = GeoJSON.parse( geodata, { Point: ['lat', 'lng'] }); const geojsonExtentPoints = GeoJSON.parse( extentPoints, { Point: ['lat', 'lng'] }); + // iterate all features removing empire* properties if there is a country_gid property + // per: https://github.com/pelias/placeholder/issues/54#issuecomment-333921012 + geojson.features.forEach(feature => { + if (_.has(feature, 'properties.country_gid')) { + delete feature.properties.empire_gid; + delete feature.properties.empire; + delete feature.properties.empire_a; + } + }); + // 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); diff --git a/test/unit/helper/geojsonify.js b/test/unit/helper/geojsonify.js index 72ff6392..cc0abe74 100644 --- a/test/unit/helper/geojsonify.js +++ b/test/unit/helper/geojsonify.js @@ -636,6 +636,104 @@ module.exports.tests.non_optimal_conditions = (test, common) => { }); + test('empire properties should be removed when there is a country_gid property', t => { + const input = [ + { + _id: 'id 1', + source: 'source 1', + source_id: 'source_id 1', + layer: 'layer 1', + name: { + default: 'name 1', + }, + center_point: { + lat: 12.121212, + lon: 21.212121 + } + }, + { + _id: 'id 2', + source: 'source 2', + source_id: 'source_id 2', + layer: 'layer 2', + name: { + default: 'name 2', + }, + center_point: { + lat: 13.131313, + lon: 31.313131 + } + } + ]; + + const geojsonify = proxyquire('../../../helper/geojsonify', { + './geojsonify_place_details': (params, source, dst) => { + if (source._id === 'id 1') { + return { + country_gid: 'country gid', + empire_gid: 'empire gid', + empire: 'empire', + empire_a: 'empire abbr' + }; + } else if (source._id === 'id 2') { + return { + empire_gid: 'empire gid', + empire: 'empire', + empire_a: 'empire abbr' + }; + } + + } + }); + + const actual = geojsonify({}, input); + + const expected = { + type: 'FeatureCollection', + features: [ + { + type: 'Feature', + geometry: { + type: 'Point', + coordinates: [ 21.212121, 12.121212 ] + }, + properties: { + id: 'id 1', + gid: 'source 1:layer 1:id 1', + layer: 'layer 1', + source: 'source 1', + source_id: 'source_id 1', + name: 'name 1', + country_gid: 'country gid', + } + }, + { + type: 'Feature', + geometry: { + type: 'Point', + coordinates: [ 31.313131, 13.131313 ] + }, + properties: { + id: 'id 2', + gid: 'source 2:layer 2:id 2', + layer: 'layer 2', + source: 'source 2', + source_id: 'source_id 2', + name: 'name 2', + empire_gid: 'empire gid', + empire: 'empire', + empire_a: 'empire abbr' + } + } + ], + bbox: [21.212121, 12.121212, 31.313131, 13.131313] + }; + + t.deepEquals(actual, expected); + t.end(); + + }); + }; module.exports.all = (tape, common) => {