diff --git a/README.md b/README.md index ab2b03a2..dd44866d 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ See the available options in the table below. | snapDistance | `20` | the distance to another vertex when a snap should happen | | snapMiddle | `false` | allow snapping to the middle of a layers segments (between two vertexes) | | tooltips | `true` | show helpful tooltips for your user | -| allowSelfIntersection | `true` | allow self intersections | +| allowSelfIntersection | `false` | allow self intersections | | templineStyle | `{ color: 'red' },` | [leaflet path options](https://leafletjs.com/reference-1.4.0.html#path) for the lines between drawn vertices/markers. | | hintlineStyle | `{ color: 'red', dashArray: [5, 5] }` | [leaflet path options](https://leafletjs.com/reference-1.4.0.html#path) for the helper line between last drawn vertex and the cursor. | | cursorMarker | `true` | show a marker at the cursor | @@ -224,7 +224,7 @@ Let's you edit vertices of layers. Use it like this: ```js // enable edit mode layer.pm.enable({ - allowSelfIntersection: false, + allowSelfIntersection: true, }); ``` @@ -234,7 +234,7 @@ See the available options in the table below. | :-------------------- | :------ | :-------------------------------------------------------------------------------------------------------- | | snappable | `true` | Enable snapping to other layers vertices for precision drawing. Can be disabled by holding the `ALT` key. | | snapDistance | `20` | The distance to another vertex when a snap should happen. | -| allowSelfIntersection | `true` | Allow/Disallow self-intersections on polygons and polylines. | +| allowSelfIntersection | `false` | Allow/Disallow self-intersections on polygons and polylines. | | preventMarkerRemoval | `false` | Disable the removal of markers/vertexes via right click. | The following methods are available for layers under `layer.pm`: diff --git a/cypress/integration/polygon.spec.js b/cypress/integration/polygon.spec.js index 70bbecca..6b42ada9 100644 --- a/cypress/integration/polygon.spec.js +++ b/cypress/integration/polygon.spec.js @@ -74,15 +74,11 @@ describe('Draw & Edit Poly', () => { it('prevents self intersections', () => { cy.window().then(({ map }) => { - map.pm.enableDraw('Polygon', { - allowSelfIntersection: false, - }); + map.pm.enableDraw('Polygon'); Cypress.$(map).on('pm:create', ({ originalEvent: event }) => { const poly = event.layer; - poly.pm.enable({ - allowSelfIntersection: false, - }); + poly.pm.enable(); }); }); @@ -219,8 +215,14 @@ describe('Draw & Edit Poly', () => { cy.hasLayers(1); // activate polygon drawing + cy.window().then(({ map }) => { + map.pm.enableDraw('Polygon', { + allowSelfIntersection: true, + }); + }); + + // check button activity cy.toolbarButton('polygon') - .click() .closest('.button-container') .should('have.class', 'active'); @@ -241,7 +243,11 @@ describe('Draw & Edit Poly', () => { cy.hasLayers(3); // enable global edit mode - cy.toolbarButton('edit').click(); + cy.window().then(({ map }) => { + map.pm.enableGlobalEditMode({ + allowSelfIntersection: true, + }); + }); cy.hasVertexMarkers(5); cy.hasMiddleMarkers(5); diff --git a/src/js/Draw/L.PM.Draw.js b/src/js/Draw/L.PM.Draw.js index 233a7c8a..4f6f3971 100644 --- a/src/js/Draw/L.PM.Draw.js +++ b/src/js/Draw/L.PM.Draw.js @@ -9,7 +9,7 @@ const Draw = L.Class.extend({ cursorMarker: true, finishOnDoubleClick: false, finishOn: null, - allowSelfIntersection: true, + allowSelfIntersection: false, templineStyle: {}, hintlineStyle: { color: '#3388ff', diff --git a/src/js/Edit/L.PM.Edit.js b/src/js/Edit/L.PM.Edit.js index 368ad4c2..a1c0f3a0 100644 --- a/src/js/Edit/L.PM.Edit.js +++ b/src/js/Edit/L.PM.Edit.js @@ -6,7 +6,7 @@ const Edit = L.Class.extend({ options: { snappable: true, snapDistance: 20, - allowSelfIntersection: true, + allowSelfIntersection: false, draggable: true, }, isPolygon() { diff --git a/src/js/Toolbar/L.PM.Toolbar.js b/src/js/Toolbar/L.PM.Toolbar.js index 6adcdfca..562798e5 100644 --- a/src/js/Toolbar/L.PM.Toolbar.js +++ b/src/js/Toolbar/L.PM.Toolbar.js @@ -276,7 +276,6 @@ const Toolbar = L.Class.extend({ this.map.pm.Draw.Cut.toggle({ snappable: true, cursorMarker: true, - allowSelfIntersection: false, }); }, doToggle: true,