From 13f12e3f6217046e61e3c71dd5d548212d16d66f Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Fri, 15 Jan 2021 19:05:45 -0700 Subject: [PATCH] [Maps] fix zooming while drawing shape filter logs errors in console (#88413) * [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> --- .../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); });