@@ -73,7 +73,7 @@ proto.needsNewSource = function(opts) {
73
73
// stay safe and make new source on type changes
74
74
return (
75
75
this . sourceType !== opts . sourcetype ||
76
- this . source !== opts . source ||
76
+ JSON . stringify ( this . source ) !== JSON . stringify ( opts . source ) ||
77
77
this . layerType !== opts . type
78
78
) ;
79
79
} ;
@@ -85,11 +85,23 @@ proto.needsNewLayer = function(opts) {
85
85
) ;
86
86
} ;
87
87
88
+ proto . lookupBelow = function ( ) {
89
+ return this . subplot . belowLookup [ 'layout-' + this . index ] ;
90
+ } ;
91
+
88
92
proto . updateImage = function ( opts ) {
89
93
var map = this . subplot . map ;
90
94
map . getSource ( this . idSource ) . updateImage ( {
91
95
url : opts . source , coordinates : opts . coordinates
92
96
} ) ;
97
+
98
+ // Since the `updateImage` control flow doesn't call updateLayer,
99
+ // We need to take care of moving the image layer to match the location
100
+ // where updateLayer would have placed it.
101
+ var _below = this . findFollowingMapboxLayerId ( this . lookupBelow ( ) ) ;
102
+ if ( _below !== null ) {
103
+ this . subplot . map . moveLayer ( this . idLayer , _below ) ;
104
+ }
93
105
} ;
94
106
95
107
proto . updateSource = function ( opts ) {
@@ -107,29 +119,29 @@ proto.updateSource = function(opts) {
107
119
map . addSource ( this . idSource , sourceOpts ) ;
108
120
} ;
109
121
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
-
122
+ proto . findFollowingMapboxLayerId = function ( below ) {
117
123
if ( below === 'traces' ) {
118
- var mapLayers = subplot . getMapLayers ( ) ;
124
+ var mapLayers = this . subplot . getMapLayers ( ) ;
119
125
120
126
// find id of first plotly trace layer
121
127
for ( var i = 0 ; i < mapLayers . length ; i ++ ) {
122
128
var layerId = mapLayers [ i ] . id ;
123
129
if ( typeof layerId === 'string' &&
124
130
layerId . indexOf ( constants . traceLayerPrefix ) === 0
125
131
) {
126
- _below = layerId ;
132
+ below = layerId ;
127
133
break ;
128
134
}
129
135
}
130
- } else {
131
- _below = below ;
132
136
}
137
+ return below ;
138
+ } ;
139
+
140
+ proto . updateLayer = function ( opts ) {
141
+ var subplot = this . subplot ;
142
+ var convertedOpts = convertOpts ( opts ) ;
143
+ var below = this . lookupBelow ( ) ;
144
+ var _below = this . findFollowingMapboxLayerId ( below ) ;
133
145
134
146
this . removeLayer ( ) ;
135
147
0 commit comments