Skip to content

Commit

Permalink
Prevent opening popup on ignored layers while drawing (#1471) (patch)
Browse files Browse the repository at this point in the history
  • Loading branch information
Falke-Design authored Mar 26, 2024
1 parent f551fa7 commit b491854
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
29 changes: 29 additions & 0 deletions cypress/integration/rectangle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,35 @@ describe('Draw Rectangle', () => {
});
});

it('disable popup on pmIgnore-layer while drawing', () => {
let rect = null;
cy.window().then(({ map, L }) => {
map.on('pm:create', (e) => {
e.layer.bindPopup('Popup test');
if (e.layer instanceof L.Rectangle) {
e.layer.options.pmIgnore = true;
rect = e.layer;
}
});
});

cy.toolbarButton('rectangle').click();
cy.get(mapSelector).click(100, 50).click(700, 400);

cy.toolbarButton('marker').click();
cy.get(mapSelector).click(300, 250);

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

cy.window().then(({ map }) => {
const len = map.pm.getGeomanDrawLayers().length;
expect(len).to.equal(1);

const text = rect.getPopup().getContent();
expect(text).to.equal('Popup test');
});
});

it('prevent not correct created snaplist', () => {
cy.window().then(({ map }) => {
map.on('pm:create', (e) => {
Expand Down
17 changes: 16 additions & 1 deletion src/js/Draw/L.PM.Draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,22 @@ const Draw = L.Class.extend({
this._fireGlobalDrawModeToggled();
}

const layers = L.PM.Utils.findLayers(this._map);
const layers = [];
this._map.eachLayer((layer) => {
if (
layer instanceof L.Polyline ||
layer instanceof L.Marker ||
layer instanceof L.Circle ||
layer instanceof L.CircleMarker ||
layer instanceof L.ImageOverlay
) {
// filter out everything that's leaflet-geoman specific temporary stuff
if (!layer._pmTempLayer) {
layers.push(layer);
}
}
});

if (this._enabled) {
layers.forEach((layer) => {
L.PM.Utils.disablePopup(layer);
Expand Down

0 comments on commit b491854

Please sign in to comment.