From b0ba8bded514e791ba8bd7eda4a513a762c5e5ae Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 19 Apr 2018 13:08:03 -0400 Subject: [PATCH] fix #6501, fix moving layer to it's current location --- src/style/style.js | 4 ++++ test/unit/style/style.test.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/style/style.js b/src/style/style.js index e34f9d6995a..a8dbde5ab9c 100644 --- a/src/style/style.js +++ b/src/style/style.js @@ -605,6 +605,10 @@ class Style extends Evented { return; } + if (id === before) { + return; + } + const index = this._order.indexOf(id); this._order.splice(index, 1); diff --git a/test/unit/style/style.test.js b/test/unit/style/style.test.js index d101aeaafbf..1f3c2e65fcc 100644 --- a/test/unit/style/style.test.js +++ b/test/unit/style/style.test.js @@ -1273,6 +1273,23 @@ test('Style#moveLayer', (t) => { }); }); + t.test('moves to existing location', (t) => { + const style = new Style(new StubMap()); + style.loadJSON(createStyleJSON({ + layers: [ + {id: 'a', type: 'background'}, + {id: 'b', type: 'background'}, + {id: 'c', type: 'background'} + ] + })); + + style.on('style.load', () => { + style.moveLayer('b', 'b'); + t.deepEqual(style._order, ['a', 'b', 'c']); + t.end(); + }); + }); + t.end(); });