Skip to content

Commit

Permalink
Fix rotation (#1306)
Browse files Browse the repository at this point in the history
  • Loading branch information
Falke-Design authored Feb 19, 2023
1 parent 88d2d0a commit 68f6dd1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
37 changes: 37 additions & 0 deletions cypress/integration/rotation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,41 @@ describe('Rotation', () => {
expect(map.pm.getGeomanLayers().length).to.eq(1);
});
});

it("fixes enabling rotation multiple times", () => {
cy.window().then(({ map, L }) => {
const coords = [
[1, 2],
[3, 4],
];
const rect = L.rectangle(coords).addTo(map);
rect.pm.enableRotate();
rect.pm.enableRotate();

cy.hasVertexMarkers(4);
expect(map.pm.getGeomanLayers().length).to.eq(1);
});
});


it("prevents enabling rotation on temp layer", () => {
cy.window().then(({ map, L }) => {
const coords = [
[1, 2],
[3, 4],
];
L.rectangle(coords).addTo(map);
const coords2 = [
[2, 3],
[3, 4],
];
L.rectangle(coords2).addTo(map);

map.pm.enableGlobalRotateMode();
map.pm.enableGlobalRotateMode();

cy.hasVertexMarkers(8);
expect(map.pm.getGeomanLayers().length).to.eq(2);
});
});
});
9 changes: 7 additions & 2 deletions src/js/Mixins/Rotating.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ const RotateMixin = {
return;
}

if(this.rotateEnabled()){
this.disableRotate();
}

// We create an hidden polygon. We set pmIgnore to false, so that the `pm` property will be always create, also if OptIn == true
const options = {
fill: false,
Expand All @@ -155,7 +159,9 @@ const RotateMixin = {
};

// we create a temp polygon for rotation
this._rotatePoly = L.polygon(this._layer.getLatLngs(), options).addTo(
this._rotatePoly = L.polygon(this._layer.getLatLngs(), options);
this._rotatePoly._pmTempLayer = true;
this._rotatePoly.addTo(
this._layer._map
);
this._rotatePoly.pm._setAngle(this.getAngle());
Expand All @@ -167,7 +173,6 @@ const RotateMixin = {
});
// we connect the temp polygon (that will be enabled for rotation) with the current layer, so that we can rotate the current layer too
this._rotatePoly.pm._rotationLayer = this._layer;
this._rotatePoly._pmTempLayer = true;
this._rotatePoly.pm.enable();

// store the original latlngs
Expand Down

0 comments on commit 68f6dd1

Please sign in to comment.