@@ -73,7 +73,6 @@ export const EchartsLayer = L.Layer.extend({
73
73
this . _ec = echarts . init ( this . _echartsContainer ) ;
74
74
this . _ec . leafletMap = map ;
75
75
const me = this ;
76
-
77
76
map . on ( "zoomstart" , function ( ) {
78
77
me . _disableEchartsContainer ( ) ;
79
78
} ) ;
@@ -114,15 +113,12 @@ export const EchartsLayer = L.Layer.extend({
114
113
const coordSys = LeafletMapModel . coordinateSystem ;
115
114
116
115
const ecLayers = api . getZr ( ) . painter . getLayers ( ) ;
117
-
116
+ _setCanvasPosition ( me . _map , viewportRoot ) ;
118
117
const moveHandler = function ( ) {
119
118
if ( rendering ) {
120
119
return ;
121
120
}
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 ) ;
126
122
127
123
if ( ! me . options . loadWhileAnimating ) {
128
124
for ( let item in ecLayers ) {
@@ -209,7 +205,6 @@ export const EchartsLayer = L.Layer.extend({
209
205
_div . style . width = size . x + 'px' ;
210
206
_div . style . zIndex = 10 ;
211
207
this . _echartsContainer = _div ;
212
-
213
208
this . getPane ( ) . appendChild ( this . _echartsContainer ) ;
214
209
const me = this ;
215
210
@@ -235,7 +230,7 @@ export const EchartsLayer = L.Layer.extend({
235
230
export function LeafletMapCoordSys ( leafletMap ) {
236
231
this . _LeafletMap = leafletMap ;
237
232
this . dimensions = [ 'lng' , 'lat' ] ;
238
- this . _mapOffset = [ 0 , 0 ] ;
233
+ this . _mapOffset = _getMapOffset ( leafletMap ) ;
239
234
}
240
235
241
236
LeafletMapCoordSys . prototype . dimensions = [ 'lng' , 'lat' ] ;
@@ -330,7 +325,7 @@ LeafletMapCoordSys.create = function (ecModel) {
330
325
coordSys = new LeafletMapCoordSys ( leafletMap ) ;
331
326
}
332
327
leafletMapModel . coordinateSystem = coordSys ;
333
- leafletMapModel . coordinateSystem . setMapOffset ( leafletMapModel . __mapOffset || [ 0 , 0 ] ) ;
328
+ leafletMapModel . coordinateSystem . setMapOffset ( leafletMapModel . __mapOffset || _getMapOffset ( leafletMap ) ) ;
334
329
} ) ;
335
330
ecModel . eachSeries ( function ( seriesModel ) {
336
331
if ( ! seriesModel . get ( 'coordinateSystem' ) || seriesModel . get ( 'coordinateSystem' ) === 'leaflet' ) {
@@ -342,6 +337,19 @@ LeafletMapCoordSys.create = function (ecModel) {
342
337
}
343
338
} )
344
339
} ;
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
+ }
345
353
export const echartsLayer = function ( echartsOptions , options ) {
346
354
return new EchartsLayer ( echartsOptions , options ) ;
347
355
} ;
0 commit comments