Skip to content

Commit

Permalink
Fix error when removing image while loading publiclab#1396
Browse files Browse the repository at this point in the history
  • Loading branch information
Falke-Design committed Jun 22, 2024
1 parent bc49085 commit 03635a4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion dist/leaflet.distortableimage.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/leaflet.distortableimage.js.map

Large diffs are not rendered by default.

47 changes: 25 additions & 22 deletions src/DistortableImageOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,42 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
}

// Have to wait for the image to load because need to access its w/h
L.DomEvent.on(this.getElement(), 'load', () => {
this.getPane().appendChild(this.getElement());
this._initImageDimensions();

if (this.options.rotation) {
const units = this.options.rotation.deg >= 0 ? 'deg' : 'rad';
this.setAngle(this.options.rotation[units], units);
} else {
this.rotation = {deg: 0, rad: 0};
this._reset();
}

/* Initialize default corners if not already set */
if (!this._corners) {
if (map.options.zoomAnimation && L.Browser.any3d) {
map.on('zoomanim', this._animateZoom, this);
}
}

if (this.editable) { this.editing.enable(); }
this.eP = null;
});
L.DomEvent.on(this.getElement(), 'load', this._initAfterLoading, this);

this.fire('add');
},

onRemove(map) {
L.DomEvent.on(this.getElement(), 'load', this._initAfterLoading, this);
if (this.editing) { this.editing.disable(); }
this.fire('remove');

L.ImageOverlay.prototype.onRemove.call(this, map);
},

_initAfterLoading() {
this.getPane().appendChild(this.getElement());
this._initImageDimensions();

if (this.options.rotation) {
const units = this.options.rotation.deg >= 0 ? 'deg' : 'rad';
this.setAngle(this.options.rotation[units], units);
} else {
this.rotation = {deg: 0, rad: 0};
this._reset();
}

/* Initialize default corners if not already set */
if (!this._corners) {
if (map.options.zoomAnimation && L.Browser.any3d) {
map.on('zoomanim', this._animateZoom, this);
}
}

if (this.editable) { this.editing.enable(); }
this.eP = null;
},

_initImageDimensions() {
const map = this._map;
const originalImageWidth = L.DomUtil.getStyle(this.getElement(), 'width');
Expand Down

0 comments on commit 03635a4

Please sign in to comment.