1- import L from " leaflet" ;
1+ import L from ' leaflet' ;
22import echarts from 'echarts' ;
33
44import '../core/Base' ;
@@ -77,7 +77,6 @@ import MapCoordSys from './echart/MapCoordSys';
7777 };
7878 */
7979export var EchartsLayer = L . Layer . extend ( {
80-
8180 map : null , //传入的leaflet地图
8281 chart : null ,
8382 options : null ,
@@ -86,9 +85,10 @@ export var EchartsLayer = L.Layer.extend({
8685 initialize : function ( map , options ) {
8786 this . map = map ;
8887 this . options = options ;
89- this . layerId = options . layerId || " echartlayerdefaultid" ;
90- this . layerClass = options . classId || " echartlayerdefaultclass" ;
88+ this . layerId = options . layerId || ' echartlayerdefaultid' ;
89+ this . layerClass = options . classId || ' echartlayerdefaultclass' ;
9190
91+ this . visible = true ;
9292 this . initDevicePixelRatio ( ) ;
9393 this . initOptions ( this . options ) ;
9494 this . initEcharts ( ) ;
@@ -102,12 +102,12 @@ export var EchartsLayer = L.Layer.extend({
102102
103103 initOptions : function ( options ) {
104104 if ( options ) {
105- if ( options . leaflet ) {
105+ if ( options . leaflet ) {
106106 return ;
107107 }
108108 this . options . leaflet = {
109109 roam : true
110- }
110+ } ;
111111 }
112112 } ,
113113
@@ -124,7 +124,8 @@ export var EchartsLayer = L.Layer.extend({
124124 }
125125 } ) ;
126126
127- echarts . registerAction ( {
127+ echarts . registerAction (
128+ {
128129 type : 'LeafletRoma' ,
129130 event : 'LeafletRoma' ,
130131 update : 'updateLayout'
@@ -143,14 +144,17 @@ export var EchartsLayer = L.Layer.extend({
143144 } ,
144145
145146 _visible : function ( ) {
146- this . canvas . style . visibility = "visible" ;
147+ this . visible = true ;
148+ this . canvas . style . visibility = 'visible' ;
147149 } ,
148150
149151 _unvisible : function ( ) {
150- this . canvas . style . visibility = "hidden" ;
152+ this . visible = false ;
153+ this . canvas . style . visibility = 'hidden' ;
151154 } ,
152155
153156 onAdd : function ( map ) {
157+ const vm = this ;
154158 this . map = map ;
155159 this . canvas = this . _createCanvas ( ) ;
156160 map . getPanes ( ) . overlayPane . appendChild ( this . canvas ) ;
@@ -164,9 +168,9 @@ export var EchartsLayer = L.Layer.extend({
164168 let size = e . newSize ;
165169 self . canvas . style . width = size . x + 'px' ;
166170 self . canvas . style . height = size . y + 'px' ;
167- self . chart . resize ( )
168- } )
169- map . on ( " zoomstart" , function ( ) {
171+ self . chart . resize ( ) ;
172+ } ) ;
173+ map . on ( ' zoomstart' , function ( ) {
170174 self . _unvisible ( ) ;
171175 } ) ;
172176
@@ -182,24 +186,24 @@ export var EchartsLayer = L.Layer.extend({
182186 var coordSys = mapModel . coordinateSystem ;
183187
184188 var moveHandler = function ( ) {
185- if ( rendering ) {
189+ if ( rendering || ! vm . visible ) {
186190 return ;
187191 }
188192 var topleft = leafletMap . getBounds ( ) . getNorthWest ( ) ;
189193 var offset = leafletMap . latLngToLayerPoint ( topleft ) ;
190- var mapOffset = [ parseInt ( offset . x , 10 ) || 0 , parseInt ( offset . y , 10 ) || 0 ]
194+ var mapOffset = [ parseInt ( offset . x , 10 ) || 0 , parseInt ( offset . y , 10 ) || 0 ] ;
191195 viewportRoot . style . left = mapOffset [ 0 ] + 'px' ;
192196 viewportRoot . style . top = mapOffset [ 1 ] + 'px' ;
193197 coordSys . setMapOffset ( mapOffset ) ;
194198 mapModel . __mapOffset = mapOffset ;
195199
196200 api . dispatchAction ( {
197201 type : 'LeafletRoma'
198- } )
202+ } ) ;
199203 } ;
200204
201205 var zoomEndHandler = function ( ) {
202- if ( rendering ) {
206+ if ( rendering || ! vm . visible ) {
203207 return ;
204208 }
205209
@@ -210,8 +214,8 @@ export var EchartsLayer = L.Layer.extend({
210214 self . _visible ( ) ;
211215 } ;
212216
213- leafletMap . off ( 'move' , this . _oldMoveHandler )
214- leafletMap . off ( 'zoomend' , this . _oldZoomEndHandler )
217+ leafletMap . off ( 'move' , this . _oldMoveHandler ) ;
218+ leafletMap . off ( 'zoomend' , this . _oldZoomEndHandler ) ;
215219 // FIXME
216220 // Moveend may be triggered by centerAndZoom method when creating coordSys next time
217221 // leafletMap.off('moveend', this._oldMoveHandler)
@@ -221,7 +225,7 @@ export var EchartsLayer = L.Layer.extend({
221225 this . _oldMoveHandler = moveHandler ;
222226 this . _oldZoomEndHandler = zoomEndHandler ;
223227
224- var roam = mapModel . get ( 'roam' )
228+ var roam = mapModel . get ( 'roam' ) ;
225229 if ( roam && roam !== 'scale' ) {
226230 // todo 允许拖拽
227231 } else {
@@ -247,8 +251,8 @@ export var EchartsLayer = L.Layer.extend({
247251 var canvas = document . createElement ( 'div' ) ;
248252 canvas . id = this . layerId ;
249253 //canvas.style.position = 'absolute';
250- canvas . style . top = " 0px" ;
251- canvas . style . left = " 0px" ;
254+ canvas . style . top = ' 0px' ;
255+ canvas . style . left = ' 0px' ;
252256 canvas . height = this . map . getSize ( ) . y + 'px' ;
253257 canvas . width = this . map . getSize ( ) . x + 'px' ;
254258 canvas . style . height = this . map . getSize ( ) . y + 'px' ;
@@ -271,8 +275,8 @@ export var EchartsLayer = L.Layer.extend({
271275 var map = self . map ;
272276
273277 //canvas.style.position = 'absolute';
274- canvas . style . top = " 0px" ;
275- canvas . style . left = " 0px" ;
278+ canvas . style . top = ' 0px' ;
279+ canvas . style . left = ' 0px' ;
276280 canvas . height = this . map . getSize ( ) . y + 'px' ;
277281 canvas . width = this . map . getSize ( ) . x + 'px' ;
278282 canvas . style . height = this . map . getSize ( ) . y + 'px' ;
@@ -307,8 +311,8 @@ export var EchartsLayer = L.Layer.extend({
307311 var map = this . map ;
308312
309313 //canvas.style.position = 'absolute';
310- canvas . style . top = " 0px" ;
311- canvas . style . left = " 0px" ;
314+ canvas . style . top = ' 0px' ;
315+ canvas . style . left = ' 0px' ;
312316 canvas . height = this . map . getSize ( ) . y + 'px' ;
313317 canvas . width = this . map . getSize ( ) . x + 'px' ;
314318 canvas . style . height = this . map . getSize ( ) . y + 'px' ;
@@ -317,13 +321,13 @@ export var EchartsLayer = L.Layer.extend({
317321 this . chart . resize ( ) ;
318322 } ,
319323
320- /**
324+ /**
321325 * @function L.zondy.EchartsLayer.prototype.update
322326 * @param {* } option echarts.option
323327 * @see https://www.echartsjs.com/zh/tutorial.html#异步数据加载和更新
324328 * @description ECharts 由数据驱动,数据的改变驱动图表展现的改变,因此动态数据的实现也变得异常简单。所有数据的更新都通过 setOption实现,你只需要定时获取数据,setOption 填入数据,而不用考虑数据到底产生了那些变化,ECharts 会找到两组数据之间的差异然后通过合适的动画去表现数据的变化。
325329 */
326- update : function ( option ) {
330+ update : function ( option ) {
327331 this . chart . setOption ( option ) ;
328332 }
329333} ) ;
0 commit comments