@@ -584,6 +584,53 @@ describe('@noCI, mapbox plots', function() {
584584 . then ( done ) ;
585585 } , LONG_TIMEOUT_INTERVAL ) ;
586586
587+ it ( '@gl should not update center while dragging' , function ( done ) {
588+ var map = gd . _fullLayout . mapbox . _subplot . map ;
589+ spyOn ( map , 'setCenter' ) . and . callThrough ( ) ;
590+
591+ var p1 = [ pointPos [ 0 ] + 50 , pointPos [ 1 ] - 20 ] ;
592+
593+ _mouseEvent ( 'mousemove' , pointPos , noop ) . then ( function ( ) {
594+ return Plotly . relayout ( gd , { 'mapbox.center' : { lon : 13.5 , lat : - 19.5 } } ) ;
595+ } ) . then ( function ( ) {
596+ // First relayout on mapbox.center results in setCenter call
597+ expect ( map . setCenter ) . toHaveBeenCalledWith ( [ 13.5 , - 19.5 ] ) ;
598+ expect ( map . setCenter ) . toHaveBeenCalledTimes ( 1 ) ;
599+ } ) . then ( function ( ) {
600+ return _mouseEvent ( 'mousedown' , pointPos , noop ) ;
601+ } ) . then ( function ( ) {
602+ return _mouseEvent ( 'mousemove' , p1 , noop ) ;
603+ } ) . then ( function ( ) {
604+ return Plotly . relayout ( gd , { 'mapbox.center' : { lat : 0 , lon : 0 } } ) ;
605+ } ) . then ( function ( ) {
606+ return _mouseEvent ( 'mouseup' , p1 , noop ) ;
607+ } ) . then ( function ( ) {
608+ // Second relayout on mapbox.center does not result in a setCenter
609+ // call since map drag is underway
610+ expect ( map . setCenter ) . toHaveBeenCalledTimes ( 1 ) ;
611+ } ) . then ( done ) ;
612+ } , LONG_TIMEOUT_INTERVAL ) ;
613+
614+ it ( '@gl should not update zoom while scroll wheeling' , function ( done ) {
615+ var map = gd . _fullLayout . mapbox . _subplot . map ;
616+ spyOn ( map , 'setZoom' ) . and . callThrough ( ) ;
617+
618+ _mouseEvent ( 'mousemove' , pointPos , noop ) . then ( function ( ) {
619+ return Plotly . relayout ( gd , { 'mapbox.zoom' : 5 } ) ;
620+ } ) . then ( function ( ) {
621+ // First relayout on mapbox.zoom results in setZoom call
622+ expect ( map . setZoom ) . toHaveBeenCalledWith ( 5 ) ;
623+ expect ( map . setZoom ) . toHaveBeenCalledTimes ( 1 ) ;
624+ } ) . then ( function ( ) {
625+ mouseEvent ( 'scroll' , pointPos [ 0 ] , pointPos [ 1 ] , { deltaY : - 400 } ) ;
626+ return Plotly . relayout ( gd , { 'mapbox.zoom' : 2 } ) . then ( function ( ) {
627+ // Second relayout on mapbox.zoom does not result in setZoom
628+ // call since a scroll wheel zoom is underway
629+ expect ( map . setZoom ) . toHaveBeenCalledTimes ( 1 ) ;
630+ } ) ;
631+ } ) . then ( done ) ;
632+ } , LONG_TIMEOUT_INTERVAL ) ;
633+
587634 it ( '@gl should be able to restyle' , function ( done ) {
588635 var restyleCnt = 0 ;
589636 var relayoutCnt = 0 ;
@@ -888,6 +935,57 @@ describe('@noCI, mapbox plots', function() {
888935 . then ( done ) ;
889936 } , LONG_TIMEOUT_INTERVAL ) ;
890937
938+ it ( '@gl should be able to update layer image' , function ( done ) {
939+ var coords = [
940+ [ - 80.425 , 46.437 ] ,
941+ [ - 71.516 , 46.437 ] ,
942+ [ - 71.516 , 37.936 ] ,
943+ [ - 80.425 , 37.936 ]
944+ ] ;
945+ function makeFigure ( source ) {
946+ return {
947+ data : [ { type : 'scattermapbox' } ] ,
948+ layout : {
949+ mapbox : {
950+ layers : [ {
951+ 'sourcetype' : 'image' ,
952+ 'coordinates' : coords ,
953+ 'source' : source
954+ } ]
955+ }
956+ }
957+ } ;
958+ }
959+
960+ var map = null ;
961+ var layerSource = null ;
962+
963+ // Single pixel PNGs generated with http://png-pixel.com/
964+ var prefix = 'data:image/png;base64,' ;
965+ var redImage = prefix + 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42m' +
966+ 'P8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==' ;
967+ var greenImage = prefix + 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42m' +
968+ 'Nk+M/wHwAEBgIApD5fRAAAAABJRU5ErkJggg==' ;
969+
970+ Plotly . react ( gd , makeFigure ( redImage ) ) . then ( function ( ) {
971+ var mapbox = gd . _fullLayout . mapbox . _subplot ;
972+ map = mapbox . map ;
973+ layerSource = map . getSource ( mapbox . layerList [ 0 ] . idSource ) ;
974+
975+ spyOn ( layerSource , 'updateImage' ) . and . callThrough ( ) ;
976+ spyOn ( map , 'removeSource' ) . and . callThrough ( ) ;
977+ return Plotly . react ( gd , makeFigure ( greenImage ) ) ;
978+ } )
979+ . then ( function ( ) {
980+ expect ( layerSource . updateImage ) . toHaveBeenCalledWith (
981+ { url : greenImage , coordinates : coords }
982+ ) ;
983+ expect ( map . removeSource ) . not . toHaveBeenCalled ( ) ;
984+ } )
985+ . catch ( failTest )
986+ . then ( done ) ;
987+ } , LONG_TIMEOUT_INTERVAL ) ;
988+
891989 it ( '@gl should be able to react to layer changes' , function ( done ) {
892990 function makeFigure ( color ) {
893991 return {
0 commit comments