Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Apr 20, 2020
1 parent 0148fb6 commit a94e9e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
13 changes: 4 additions & 9 deletions x-pack/plugins/maps/public/elasticsearch_geo_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,7 @@ function ensureGeometryType(type, expectedTypes) {
* @param {string} geoFieldType Geometry field type ["geo_point", "geo_shape"]
* @returns {number}
*/
export function hitsToGeoJson(
hits,
flattenHit,
geoFieldName,
geoFieldType,
epochMillisFields = []
) {
export function hitsToGeoJson(hits, flattenHit, geoFieldName, geoFieldType, epochMillisFields) {
const features = [];
const tmpGeometriesAccumulator = [];

Expand All @@ -89,11 +83,12 @@ export function hitsToGeoJson(
// There is a bug in Elasticsearch API where epoch_millis are returned as a string instead of a number
// https://github.com/elastic/elasticsearch/issues/50622
// Convert these field values to integers.
epochMillisFields.forEach(fieldName => {
for (let i = 0; i < epochMillisFields.length; i++) {
const fieldName = epochMillisFields[i];
if (typeof properties[fieldName] === 'string') {
properties[fieldName] = parseInt(properties[fieldName]);
}
});
}

// don't include geometry field value in properties
delete properties[geoFieldName];
Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/maps/public/elasticsearch_geo_utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('hitsToGeoJson', () => {
},
},
];
const geojson = hitsToGeoJson(hits, flattenHitMock, geoFieldName, 'geo_point');
const geojson = hitsToGeoJson(hits, flattenHitMock, geoFieldName, 'geo_point', []);
expect(geojson.type).toBe('FeatureCollection');
expect(geojson.features.length).toBe(2);
expect(geojson.features[0]).toEqual({
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('hitsToGeoJson', () => {
_source: {},
},
];
const geojson = hitsToGeoJson(hits, flattenHitMock, geoFieldName, 'geo_point');
const geojson = hitsToGeoJson(hits, flattenHitMock, geoFieldName, 'geo_point', []);
expect(geojson.type).toBe('FeatureCollection');
expect(geojson.features.length).toBe(1);
});
Expand All @@ -111,7 +111,7 @@ describe('hitsToGeoJson', () => {
},
},
];
const geojson = hitsToGeoJson(hits, flattenHitMock, geoFieldName, 'geo_point');
const geojson = hitsToGeoJson(hits, flattenHitMock, geoFieldName, 'geo_point', []);
expect(geojson.features.length).toBe(1);
const feature = geojson.features[0];
expect(feature.properties.myField).toBe(8);
Expand All @@ -128,7 +128,7 @@ describe('hitsToGeoJson', () => {
},
},
];
const geojson = hitsToGeoJson(hits, flattenHitMock, geoFieldName, 'geo_point');
const geojson = hitsToGeoJson(hits, flattenHitMock, geoFieldName, 'geo_point', []);
expect(geojson.type).toBe('FeatureCollection');
expect(geojson.features.length).toBe(2);
expect(geojson.features[0]).toEqual({
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('hitsToGeoJson', () => {
},
},
];
const geojson = hitsToGeoJson(hits, indexPatternFlattenHit, 'my.location', 'geo_point');
const geojson = hitsToGeoJson(hits, indexPatternFlattenHit, 'my.location', 'geo_point', []);
expect(geojson.features[0].geometry).toEqual({
coordinates: [100, 20],
type: 'Point',
Expand All @@ -216,7 +216,7 @@ describe('hitsToGeoJson', () => {
},
},
];
const geojson = hitsToGeoJson(hits, indexPatternFlattenHit, 'my.location', 'geo_point');
const geojson = hitsToGeoJson(hits, indexPatternFlattenHit, 'my.location', 'geo_point', []);
expect(geojson.features[0].geometry).toEqual({
coordinates: [100, 20],
type: 'Point',
Expand Down

0 comments on commit a94e9e9

Please sign in to comment.