1212var 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
3531var 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
5547proto . 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+
105105proto . dispose = function dispose ( ) {
106106 var map = this . map ;
107107
@@ -166,8 +166,12 @@ function convertSourceOpts(opts) {
166166}
167167
168168module . 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