@@ -73,7 +73,7 @@ proto.needsNewSource = function(opts) {
7373 // stay safe and make new source on type changes
7474 return (
7575 this . sourceType !== opts . sourcetype ||
76- this . source !== opts . source ||
76+ JSON . stringify ( this . source ) !== JSON . stringify ( opts . source ) ||
7777 this . layerType !== opts . type
7878 ) ;
7979} ;
@@ -85,11 +85,23 @@ proto.needsNewLayer = function(opts) {
8585 ) ;
8686} ;
8787
88+ proto . lookupBelow = function ( ) {
89+ return this . subplot . belowLookup [ 'layout-' + this . index ] ;
90+ } ;
91+
8892proto . updateImage = function ( opts ) {
8993 var map = this . subplot . map ;
9094 map . getSource ( this . idSource ) . updateImage ( {
9195 url : opts . source , coordinates : opts . coordinates
9296 } ) ;
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+ }
93105} ;
94106
95107proto . updateSource = function ( opts ) {
@@ -107,29 +119,29 @@ proto.updateSource = function(opts) {
107119 map . addSource ( this . idSource , sourceOpts ) ;
108120} ;
109121
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 ) {
117123 if ( below === 'traces' ) {
118- var mapLayers = subplot . getMapLayers ( ) ;
124+ var mapLayers = this . subplot . getMapLayers ( ) ;
119125
120126 // find id of first plotly trace layer
121127 for ( var i = 0 ; i < mapLayers . length ; i ++ ) {
122128 var layerId = mapLayers [ i ] . id ;
123129 if ( typeof layerId === 'string' &&
124130 layerId . indexOf ( constants . traceLayerPrefix ) === 0
125131 ) {
126- _below = layerId ;
132+ below = layerId ;
127133 break ;
128134 }
129135 }
130- } else {
131- _below = below ;
132136 }
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 ) ;
133145
134146 this . removeLayer ( ) ;
135147
0 commit comments