Skip to content

Commit 911e872

Browse files
committed
clean up update steps upon layer creation
1 parent 7af55ea commit 911e872

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/plots/mapbox/layers.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
var Lib = require('../../lib');
1313

1414

15-
function MapboxLayer(mapbox, index, opts) {
15+
function MapboxLayer(mapbox, index) {
1616
this.mapbox = mapbox;
1717
this.map = mapbox.map;
1818

@@ -26,10 +26,6 @@ function MapboxLayer(mapbox, index, opts) {
2626
this.source = null;
2727
this.layerType = null;
2828
this.below = null;
29-
30-
// IMPORTANT: must create source before layer to not cause errors
31-
this.updateSource(opts);
32-
this.updateLayer(opts);
3329
}
3430

3531
var proto = MapboxLayer.prototype;
@@ -45,11 +41,7 @@ proto.update = function update(opts) {
4541
this.updateLayer(opts);
4642
}
4743

48-
var paintOpts = convertPaintOpts(opts);
49-
50-
if(isVisible(opts)) {
51-
this.mapbox.setOptions(this.idLayer, 'setPaintProperty', paintOpts);
52-
}
44+
this.updateStyle(opts);
5345
};
5446

5547
proto.needsNewSource = function(opts) {
@@ -102,6 +94,14 @@ proto.updateLayer = function(opts) {
10294
this.mapbox.setOptions(this.idLayer, 'setLayoutProperty', layoutOpts);
10395
};
10496

97+
proto.updateStyle = function(opts) {
98+
var paintOpts = convertPaintOpts(opts);
99+
100+
if(isVisible(opts)) {
101+
this.mapbox.setOptions(this.idLayer, 'setPaintProperty', paintOpts);
102+
}
103+
};
104+
105105
proto.dispose = function dispose() {
106106
var map = this.map;
107107

@@ -166,8 +166,12 @@ function convertSourceOpts(opts) {
166166
}
167167

168168
module.exports = function createMapboxLayer(mapbox, index, opts) {
169-
var mapboxLayer = new MapboxLayer(mapbox, index, opts);
170-
mapboxLayer.update(opts);
169+
var mapboxLayer = new MapboxLayer(mapbox, index);
170+
171+
// IMPORTANT: must create source before layer to not cause errors
172+
mapboxLayer.updateSource(opts);
173+
mapboxLayer.updateLayer(opts);
174+
mapboxLayer.updateStyle(opts);
171175

172176
return mapboxLayer;
173177
};

0 commit comments

Comments
 (0)