| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d021d6d commit 712eebb
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -257,49 +257,26 @@ export var ImageMapLayer = Layer.extend({ | |||
| 257 | 257 | if (!this._map) { | |
| 258 | 258 | return; | |
| 259 | 259 | } | |
| 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() { | ||
| 274 | 275 | var map = this._map; | |
| 275 | 276 | if (!map) { | |
| 276 | 277 | return; | |
| 277 | 278 | } | |
| 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); | ||
| 303 | 280 | /** | |
| 304 | 281 | * @event ImageMapLayer#load | |
| 305 | 282 | * @description 请求图层加载完成后触发。 | |
@@ -308,19 +285,17 @@ export var ImageMapLayer = Layer.extend({ | |||
| 308 | 285 | this.fire('load', { bounds: bounds }); | |
| 309 | 286 | }; | |
| 310 | 287 | var onError = function() { | |
| 311 | - this._map.removeLayer(image); | ||
| 288 | + this._map && this._map.removeLayer(this._currentImage); | ||
| 312 | 289 | /** | |
| 313 | 290 | * @event ImageMapLayer#error | |
| 314 | 291 | * @description 请求图层加载失败后触发。 | |
| 315 | 292 | */ | |
| 316 | 293 | this.fire('error'); | |
| 317 | - image.off('load', onLoad, this); | ||
| 318 | 294 | } | |
| 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); | ||
| 324 | 299 | /** | |
| 325 | 300 | * @event ImageMapLayer#loading | |
| 326 | 301 | * @description 请求图层加载中触发。 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments