@@ -73,7 +73,6 @@ export const EchartsLayer = L.Layer.extend({
7373 this . _ec = echarts . init ( this . _echartsContainer ) ;
7474 this . _ec . leafletMap = map ;
7575 const me = this ;
76-
7776 map . on ( "zoomstart" , function ( ) {
7877 me . _disableEchartsContainer ( ) ;
7978 } ) ;
@@ -114,15 +113,12 @@ export const EchartsLayer = L.Layer.extend({
114113 const coordSys = LeafletMapModel . coordinateSystem ;
115114
116115 const ecLayers = api . getZr ( ) . painter . getLayers ( ) ;
117-
116+ _setCanvasPosition ( me . _map , viewportRoot ) ;
118117 const moveHandler = function ( ) {
119118 if ( rendering ) {
120119 return ;
121120 }
122- const offset = me . _map . containerPointToLayerPoint ( [ 0 , 0 ] ) ;
123- const mapOffset = [ offset . x || 0 , offset . y || 0 ] ;
124- viewportRoot . style . left = mapOffset [ 0 ] + 'px' ;
125- viewportRoot . style . top = mapOffset [ 1 ] + 'px' ;
121+ const mapOffset = _setCanvasPosition ( me . _map , viewportRoot ) ;
126122
127123 if ( ! me . options . loadWhileAnimating ) {
128124 for ( let item in ecLayers ) {
@@ -209,7 +205,6 @@ export const EchartsLayer = L.Layer.extend({
209205 _div . style . width = size . x + 'px' ;
210206 _div . style . zIndex = 10 ;
211207 this . _echartsContainer = _div ;
212-
213208 this . getPane ( ) . appendChild ( this . _echartsContainer ) ;
214209 const me = this ;
215210
@@ -235,7 +230,7 @@ export const EchartsLayer = L.Layer.extend({
235230export function LeafletMapCoordSys ( leafletMap ) {
236231 this . _LeafletMap = leafletMap ;
237232 this . dimensions = [ 'lng' , 'lat' ] ;
238- this . _mapOffset = [ 0 , 0 ] ;
233+ this . _mapOffset = _getMapOffset ( leafletMap ) ;
239234}
240235
241236LeafletMapCoordSys . prototype . dimensions = [ 'lng' , 'lat' ] ;
@@ -330,7 +325,7 @@ LeafletMapCoordSys.create = function (ecModel) {
330325 coordSys = new LeafletMapCoordSys ( leafletMap ) ;
331326 }
332327 leafletMapModel . coordinateSystem = coordSys ;
333- leafletMapModel . coordinateSystem . setMapOffset ( leafletMapModel . __mapOffset || [ 0 , 0 ] ) ;
328+ leafletMapModel . coordinateSystem . setMapOffset ( leafletMapModel . __mapOffset || _getMapOffset ( leafletMap ) ) ;
334329 } ) ;
335330 ecModel . eachSeries ( function ( seriesModel ) {
336331 if ( ! seriesModel . get ( 'coordinateSystem' ) || seriesModel . get ( 'coordinateSystem' ) === 'leaflet' ) {
@@ -342,6 +337,19 @@ LeafletMapCoordSys.create = function (ecModel) {
342337 }
343338 } )
344339} ;
340+
341+ function _getMapOffset ( map ) {
342+ const offset = map . containerPointToLayerPoint ( [ 0 , 0 ] ) ;
343+ const mapOffset = [ offset . x || 0 , offset . y || 0 ] ;
344+ return mapOffset ;
345+ }
346+
347+ function _setCanvasPosition ( map , viewportRoot ) {
348+ const mapOffset = _getMapOffset ( map ) ;
349+ viewportRoot . style . left = mapOffset [ 0 ] + 'px' ;
350+ viewportRoot . style . top = mapOffset [ 1 ] + 'px' ;
351+ return mapOffset ;
352+ }
345353export const echartsLayer = function ( echartsOptions , options ) {
346354 return new EchartsLayer ( echartsOptions , options ) ;
347355} ;
0 commit comments