Skip to content

Commit 0d1db3f

Browse files
committed
Refactor to extract lookupBelow and findFollowingMapboxLayerId functions
1 parent 98dfdb8 commit 0d1db3f

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/plots/mapbox/layers.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ proto.needsNewLayer = function(opts) {
8585
);
8686
};
8787

88+
proto.lookupBelow = function() {
89+
return this.subplot.belowLookup['layout-' + this.index];
90+
};
91+
8892
proto.updateImage = function(opts) {
8993
var map = this.subplot.map;
9094
map.getSource(this.idSource).updateImage({
@@ -107,29 +111,29 @@ proto.updateSource = function(opts) {
107111
map.addSource(this.idSource, sourceOpts);
108112
};
109113

110-
proto.updateLayer = function(opts) {
111-
var subplot = this.subplot;
112-
var convertedOpts = convertOpts(opts);
113-
114-
var below = this.subplot.belowLookup['layout-' + this.index];
115-
var _below;
116-
114+
proto.findFollowingMapboxLayerId = function(below) {
117115
if(below === 'traces') {
118-
var mapLayers = subplot.getMapLayers();
116+
var mapLayers = this.subplot.getMapLayers();
119117

120118
// find id of first plotly trace layer
121119
for(var i = 0; i < mapLayers.length; i++) {
122120
var layerId = mapLayers[i].id;
123121
if(typeof layerId === 'string' &&
124122
layerId.indexOf(constants.traceLayerPrefix) === 0
125123
) {
126-
_below = layerId;
124+
below = layerId;
127125
break;
128126
}
129127
}
130-
} else {
131-
_below = below;
132128
}
129+
return below;
130+
};
131+
132+
proto.updateLayer = function(opts) {
133+
var subplot = this.subplot;
134+
var convertedOpts = convertOpts(opts);
135+
var below = this.lookupBelow();
136+
var _below = this.findFollowingMapboxLayerId(below);
133137

134138
this.removeLayer();
135139

0 commit comments

Comments
 (0)