From 7c9eb9490cc3a72a49b561485074d98ec0caedde Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Sat, 16 Jan 2021 07:26:43 -0700 Subject: [PATCH] [Maps] fix zooming while drawing shape filter logs errors in console (#88413) (#88553) * [Maps] fix zooming while drawing shape filter logs errors in console * add unit test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../connected_components/mb_map/mb.utils.test.js | 12 ++++++++++++ .../maps/public/connected_components/mb_map/utils.js | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/x-pack/plugins/maps/public/connected_components/mb_map/mb.utils.test.js b/x-pack/plugins/maps/public/connected_components/mb_map/mb.utils.test.js index a28cc75f6d89d..2d6cba84e17e5 100644 --- a/x-pack/plugins/maps/public/connected_components/mb_map/mb.utils.test.js +++ b/x-pack/plugins/maps/public/connected_components/mb_map/mb.utils.test.js @@ -185,4 +185,16 @@ describe('removeOrphanedSourcesAndLayers', () => { removeOrphanedSourcesAndLayers(mockMbMap, [], spatialFilterLayer); expect(mockMbMap.getStyle()).toEqual(styleWithSpatialFilters); }); + + test('should not remove mapbox gl draw layers and sources', async () => { + const fooLayer = makeMultiSourceMockLayer('foo'); + const layerList = [fooLayer]; + + const currentStyle = getMockStyle(layerList); + currentStyle.layers.push({ id: 'gl-draw-points' }); + const mockMbMap = new MockMbMap(currentStyle); + + removeOrphanedSourcesAndLayers(mockMbMap, layerList, spatialFilterLayer); + expect(mockMbMap.getStyle()).toEqual(currentStyle); + }); }); diff --git a/x-pack/plugins/maps/public/connected_components/mb_map/utils.js b/x-pack/plugins/maps/public/connected_components/mb_map/utils.js index e5801afd5b601..f12f34061756f 100644 --- a/x-pack/plugins/maps/public/connected_components/mb_map/utils.js +++ b/x-pack/plugins/maps/public/connected_components/mb_map/utils.js @@ -16,6 +16,11 @@ export function removeOrphanedSourcesAndLayers(mbMap, layerList, spatialFilterLa return; } + // ignore gl-draw layers + if (mbLayer.id.startsWith('gl-draw')) { + return; + } + const layer = layerList.find((layer) => { return layer.ownsMbLayerId(mbLayer.id); });