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 removing temp-layer if layer is removed while rotation #998

Merged
merged 9 commits into from Oct 10, 2021
16 changes: 16 additions & 0 deletions cypress/integration/rotation.spec.js
Expand Up @@ -191,4 +191,20 @@ describe('Rotation', () => {
expect(Math.ceil(layer.pm.getAngle())).to.eq(64);
});
});

it('removes hidden rotatePoly if layer is removed', () => {
cy.toolbarButton('rectangle')
.click()
.closest('.button-container')
.should('have.class', 'active');
cy.get(mapSelector).click(200, 200).click(600, 350);

cy.window().then(({ map }) => {
const layer = map.pm.getGeomanDrawLayers()[0];
layer.pm.enableRotate();
const rotatePoly = layer.pm._rotatePoly;
layer.remove();
expect(!!rotatePoly._map).to.eq(false);
});
});
});
4 changes: 4 additions & 0 deletions src/js/Mixins/Rotating.js
Expand Up @@ -168,6 +168,8 @@ const RotateMixin = {

this._rotateEnabled = true;

this._layer.on('remove', this.disableRotate, this);

this._fireRotationEnable(this._layer);
// we need to use this._layer._map because this._map can be undefined if layer was never enabled for editing before
this._fireRotationEnable(this._layer._map);
Expand All @@ -181,6 +183,8 @@ const RotateMixin = {
this._rotatePoly = undefined;
this._rotateOrgLatLng = undefined;

this._layer.off('remove', this.disableRotate, this);

this._rotateEnabled = false;

this._fireRotationDisable(this._layer);
Expand Down