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

Don't finish Single-Coord Line/Polys #349

Merged
merged 3 commits into from
Oct 25, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions cypress/integration/line.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ describe('Draw & Edit Line', () => {

const mapSelector = '#map';

it('doesnt finish single point lines', () => {
cy.toolbarButton('polyline').click();

cy.get(mapSelector)
.click(90, 250)
.click(90, 250);

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

cy.hasVertexMarkers(0);
});

it('draws and edits a line', () => {
cy.window().then(({ map }) => {
cy.hasLayers(map, 1);
Expand Down
12 changes: 12 additions & 0 deletions cypress/integration/polygon.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
describe('Draw & Edit Poly', () => {
const mapSelector = '#map';

it('doesnt finish single point polys', () => {
cy.toolbarButton('polygon').click();

cy.get(mapSelector)
.click(90, 250)
.click(90, 250);

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

cy.hasVertexMarkers(0);
});

it('adds new vertex to end of array', () => {
// when adding a vertex between the first and last current vertex,
// the new coord should be added to the end, not the beginning of the coord array
Expand Down
9 changes: 8 additions & 1 deletion src/js/Draw/L.PM.Draw.Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,15 @@ Draw.Line = Draw.extend({
return;
}

// get coordinates, create the leaflet shape and add it to the map
// get coordinates
const coords = this._layer.getLatLngs();

// if there is only one coords, don't finish the shape!
if (coords.length <= 1) {
return;
}

// create the leaflet shape and add it to the map
const polylineLayer = L.polyline(
coords,
this.options.pathOptions,
Expand Down
11 changes: 9 additions & 2 deletions src/js/Draw/L.PM.Draw.Poly.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ Draw.Poly = Draw.Line.extend({
return;
}

// get coordinates, create the leaflet shape and add it to the map
// get coordinates
const coords = this._layer.getLatLngs();

// if there is only one coords, don't finish the shape!
if (coords.length <= 1) {
return;
}

// create the leaflet shape and add it to the map
if (event && event.type === 'dblclick') {
// Leaflet creates an extra node with double click
coords.splice(coords.length - 1, 1);
}
const polygonLayer = L.polygon(coords, this.options.pathOptions).addTo(this._map);
const polygonLayer = L.polygon(coords, this.options.pathOptions).addTo(this._map,);

// disable drawing
this.disable();
Expand Down