Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.14] [maps] fix More than 2 maps embeddables with geo-shape layers results in empty layers for 3+ (#107442) #107586

Merged
merged 1 commit into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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