Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when removing image while loading #1397

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 32 additions & 29 deletions src/DistortableImageOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,7 @@ 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 there is a featureGroup, only its editable option matters */
const eventParents = this._eventParents;
if (eventParents) {
this.eP = eventParents[Object.keys(eventParents)[0]];
if (this.eP.editable) { this.editing.enable(); }
} else {
if (this.editable) { this.editing.enable(); }
this.eP = null;
}
});
L.DomEvent.on(this.getElement(), 'load', this._initAfterLoading, this);

L.DomEvent.on(this.getElement(), 'click', this.select, this);
L.DomEvent.on(map, {
Expand All @@ -91,6 +63,7 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
},

onRemove(map) {
L.DomEvent.off(this.getElement(), 'load', this._initAfterLoading, this);
L.DomEvent.off(this.getElement(), 'click', this.select, this);
L.DomEvent.off(map, {
singleclickon: this._singleClickListeners,
Expand All @@ -108,6 +81,36 @@ L.DistortableImageOverlay = L.ImageOverlay.extend({
L.DomEvent.off(this.getElement(), 'mousemove', this.deactivateTooltip, this);
},

_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 there is a featureGroup, only its editable option matters */
const eventParents = this._eventParents;
if (eventParents) {
this.eP = eventParents[Object.keys(eventParents)[0]];
if (this.eP.editable) { this.editing.enable(); }
} else {
if (this.editable) { this.editing.enable(); }
this.eP = null;
}
},

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