Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d43cfca

Browse files
committed
mapbox: skip over non-object layer containers
- and keep track of input index with '_index'
1 parent 9125f21 commit d43cfca

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/plots/mapbox/layout_defaults.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ function handleLayerDefaults(containerIn, containerOut) {
5050
}
5151

5252
for(var i = 0; i < layersIn.length; i++) {
53-
layerIn = layersIn[i] || {};
53+
layerIn = layersIn[i];
5454
layerOut = {};
5555

56+
if(!Lib.isPlainObject(layerIn)) continue;
57+
5658
var sourceType = coerce('sourcetype');
5759
coerce('source');
5860

@@ -86,6 +88,7 @@ function handleLayerDefaults(containerIn, containerOut) {
8688
coerce('symbol.textposition');
8789
}
8890

91+
layerOut._index = i;
8992
layersOut.push(layerOut);
9093
}
9194
}

test/jasmine/tests/mapbox_test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ describe('mapbox defaults', function() {
8080
expect(layoutOut.mapbox.layers[1].sourcetype).toEqual('geojson');
8181
});
8282

83+
it('should skip over non-object layer containers', function() {
84+
layoutIn = {
85+
mapbox: {
86+
layers: [{}, null, 'remove', {}]
87+
}
88+
};
89+
90+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
91+
expect(layoutOut.mapbox.layers[0].sourcetype).toEqual('geojson');
92+
expect(layoutOut.mapbox.layers[0]._index).toEqual(0);
93+
expect(layoutOut.mapbox.layers[1].sourcetype).toEqual('geojson');
94+
expect(layoutOut.mapbox.layers[1]._index).toEqual(3);
95+
});
96+
8397
it('should coerce \'sourcelayer\' only for *vector* \'sourcetype\'', function() {
8498
layoutIn = {
8599
mapbox: {

0 commit comments

Comments
 (0)