@@ -257,49 +257,26 @@ export var ImageMapLayer = Layer.extend({
257257 if ( ! this . _map ) {
258258 return ;
259259 }
260-
261- var image = new ImageOverlay ( url , bounds , {
262- opacity : 0 ,
263- alt : this . options . alt ,
264- zIndex : this . options . zIndex ,
265- className : this . options . className ,
266- errorOverlayUrl : this . options . error ,
267- crossOrigin : this . options . crossOrigin ,
268- pane : this . options . pane || this . getPane ( ) ,
269- interactive : this . options . interactive
270- } ) . addTo ( this . _map ) ;
271-
272- var onLoad = function ( e ) {
273- image . off ( 'error' , onError , this ) ;
260+ if ( this . _currentImage ) {
261+ this . _currentImage . setUrl ( url ) ;
262+ } else {
263+ this . _currentImage = new ImageOverlay ( url , bounds , {
264+ opacity : this . options . opacity ,
265+ alt : this . options . alt ,
266+ zIndex : this . options . zIndex ,
267+ className : this . options . className ,
268+ errorOverlayUrl : this . options . error ,
269+ crossOrigin : this . options . crossOrigin ,
270+ pane : this . options . pane || this . getPane ( ) ,
271+ interactive : this . options . interactive
272+ } ) . addTo ( this . _map ) ;
273+ }
274+ var onLoad = function ( ) {
274275 var map = this . _map ;
275276 if ( ! map ) {
276277 return ;
277278 }
278-
279- var newImage = e . target ;
280- var oldImage = this . _currentImage ;
281-
282- if ( newImage . _bounds && newImage . _bounds . equals ( bounds ) && newImage . _bounds . equals ( map . getBounds ( ) ) ) {
283- this . _currentImage = newImage ;
284-
285- if ( this . options . position === 'front' ) {
286- this . bringToFront ( ) ;
287- }
288- if ( this . options . position === 'back' ) {
289- this . bringToBack ( ) ;
290- }
291-
292- if ( this . _currentImage . _map ) {
293- this . _currentImage . setOpacity ( this . options . opacity ) ;
294- }
295-
296- oldImage && map . removeLayer ( oldImage ) ;
297-
298- oldImage && oldImage . _map && oldImage . _map . removeLayer ( oldImage ) ;
299- } else {
300- map . removeLayer ( newImage ) ;
301- }
302-
279+ this . _currentImage . setBounds ( bounds ) ;
303280 /**
304281 * @event ImageMapLayer#load
305282 * @description 请求图层加载完成后触发。
@@ -308,19 +285,17 @@ export var ImageMapLayer = Layer.extend({
308285 this . fire ( 'load' , { bounds : bounds } ) ;
309286 } ;
310287 var onError = function ( ) {
311- this . _map . removeLayer ( image ) ;
288+ this . _map && this . _map . removeLayer ( this . _currentImage ) ;
312289 /**
313290 * @event ImageMapLayer#error
314291 * @description 请求图层加载失败后触发。
315292 */
316293 this . fire ( 'error' ) ;
317- image . off ( 'load' , onLoad , this ) ;
318294 }
319-
320- image . once ( 'load' , onLoad , this ) ;
321-
322- image . once ( 'error' , onError , this ) ;
323-
295+ this . _currentImage . off ( 'load' ) ;
296+ this . _currentImage . once ( 'load' , onLoad , this ) ;
297+ this . _currentImage . off ( 'error' ) ;
298+ this . _currentImage . once ( 'error' , onError , this ) ;
324299 /**
325300 * @event ImageMapLayer#loading
326301 * @description 请求图层加载中触发。
0 commit comments