Skip to content

Commit

Permalink
do not advance beneathMbLayerId if bottomMbLayer could not be found f…
Browse files Browse the repository at this point in the history
…or a layer (#76007)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
nreese and elasticmachine committed Aug 27, 2020
1 parent 54bbd6a commit b293961
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,25 @@ describe('sortLayer', () => {
]);
});

// Hidden map layers on map load may not add mbLayers to mbStyle.
test('Should sort with missing mblayers to expected order', () => {
// Notice there are no bravo mbLayers in initial style.
const initialMbStyle = {
version: 0,
layers: [
{ id: `${CHARLIE_LAYER_ID}_fill`, type: 'fill' } as MbLayer,
{ id: `${ALPHA_LAYER_ID}_circle`, type: 'circle' } as MbLayer,
],
};
const mbMap = new MockMbMap(initialMbStyle);
syncLayerOrder((mbMap as unknown) as MbMap, spatialFilterLayer, mapLayers);
const sortedMbStyle = mbMap.getStyle();
const sortedMbLayerIds = sortedMbStyle.layers!.map((mbLayer) => {
return mbLayer.id;
});
expect(sortedMbLayerIds).toEqual(['charlie_fill', 'alpha_circle']);
});

test('Should not call move layers when layers are in expected order', () => {
const initialMbStyle = {
version: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ export function syncLayerOrder(mbMap: MbMap, spatialFiltersLayer: ILayer, layerL
if (!isLayerInOrder(mbMap, mapLayer, LAYER_CLASS.LABEL, beneathMbLayerId)) {
moveMapLayer(mbMap, mbLayers, mapLayer, LAYER_CLASS.LABEL, beneathMbLayerId);
}
beneathMbLayerId = getBottomMbLayerId(mbLayers, mapLayer, LAYER_CLASS.LABEL);
const bottomMbLayerId = getBottomMbLayerId(mbLayers, mapLayer, LAYER_CLASS.LABEL);
if (bottomMbLayerId) beneathMbLayerId = bottomMbLayerId;
});

// Sort map layers
Expand All @@ -137,6 +138,7 @@ export function syncLayerOrder(mbMap: MbMap, spatialFiltersLayer: ILayer, layerL
if (!isLayerInOrder(mbMap, mapLayer, layerClass, beneathMbLayerId)) {
moveMapLayer(mbMap, mbLayers, mapLayer, layerClass, beneathMbLayerId);
}
beneathMbLayerId = getBottomMbLayerId(mbLayers, mapLayer, layerClass);
const bottomMbLayerId = getBottomMbLayerId(mbLayers, mapLayer, layerClass);
if (bottomMbLayerId) beneathMbLayerId = bottomMbLayerId;
});
}

0 comments on commit b293961

Please sign in to comment.