Skip to content

Fix Bug: preventMarkerRremoval #597

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

Merged
merged 6 commits into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
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
36 changes: 36 additions & 0 deletions cypress/integration/globalmodes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,40 @@ describe('Modes', () => {

cy.testLayerAdditionPerformance();
});


it('Test removal when preventMarkerRremoval is passed to global options', () => {
cy.toolbarButton('rectangle')
.click()
.closest('.button-container')
.should('have.class', 'active');

cy.get(mapSelector)
.click(200, 200)
.click(400, 350);

cy.window().then(({ map }) => {
map.pm.toggleGlobalEditMode({
preventMarkerRemoval: true
});
});

cy.toolbarButton('delete')
.click()
.closest('.button-container')
.should('have.class', 'active');

cy.get(mapSelector)
.click(200, 300);

cy.toolbarButton('delete').click();

cy.window().then(({ L, map }) => {
const layers = map._layers;

expect(
Object.entries(layers).filter(l => l[1] instanceof L.Rectangle).length
).to.equal(0);
});
});
});
5 changes: 2 additions & 3 deletions src/js/Mixins/Modes/Mode.Removal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const GlobalRemovalMode = {
enableGlobalRemovalMode() {
const isRelevant = layer =>
layer.pm &&
!(layer.pm.options && layer.pm.options.preventMarkerRemoval) &&
!(layer instanceof L.LayerGroup);

this._globalRemovalMode = true;
Expand Down Expand Up @@ -70,7 +69,7 @@ const GlobalRemovalMode = {
}
},
reinitGlobalRemovalMode({ layer }) {
// do nothing if layer is not handled by leaflet so it doesn't fire unnecessarily
// do nothing if layer is not handled by leaflet so it doesn't fire unnecessarily
const isRelevant = !!layer.pm && !layer._pmTempLayer;
if (!isRelevant) {
return;
Expand All @@ -84,4 +83,4 @@ const GlobalRemovalMode = {
},
}

export default GlobalRemovalMode
export default GlobalRemovalMode