Skip to content

Commit

Permalink
[maps] fix More than 2 maps embeddables with geo-shape layers results…
Browse files Browse the repository at this point in the history
… in empty layers for 3+ (elastic#107442)

* [maps] fix More than 2 maps embeddables with geo-shape layers results in empty layers for 3+

* comment

* add unit test

* eslint
  • Loading branch information
nreese authored and vadimkibana committed Aug 8, 2021
1 parent 44564e1 commit 7adfd16
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,26 @@ describe('hitsToGeoJson', () => {
type: 'Point',
});
});

it('Should not modify results of flattenHit', () => {
const geoFieldName = 'location';
const cachedProperities = {
[geoFieldName]: '20,100',
};
const cachedFlattenHit = () => {
return cachedProperities;
};
const hits = [
{
_source: {
[geoFieldName]: '20,100',
},
},
];
const geojson = hitsToGeoJson(hits, cachedFlattenHit, geoFieldName, 'geo_point', []);
expect(cachedProperities.hasOwnProperty('location')).toBe(true);
expect(geojson.features[0].properties).toEqual({});
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export function hitsToGeoJson(
const tmpGeometriesAccumulator: Geometry[] = [];

for (let i = 0; i < hits.length; i++) {
const properties = flattenHit(hits[i]);
// flattenHit returns value from cache. Create new object to avoid modifying flattenHit cache.
// not doing deep copy because copying coordinates can be very expensive for complex geometries.
const properties = { ...flattenHit(hits[i]) };

tmpGeometriesAccumulator.length = 0; // truncate accumulator

Expand Down

0 comments on commit 7adfd16

Please sign in to comment.