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); });