Skip to content
Open
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
35 changes: 32 additions & 3 deletions src/Leaflet.Editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,13 @@
// 🍂method continue()
// Continue the vertex LatLngs from this vertex. Only active for first and last vertices of a Polyline.
continue: function () {
if (!this.editor.continueBackward) return // Only for PolylineEditor
const index = this.getIndex()
if (index === 0) this.editor.continueBackward(this.latlngs)
else if (index === this.getLastIndex()) this.editor.continueForward(this.latlngs)
if (index === 0 && this.editor.continueBackward)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add brackets now that the if is not a one line anymore ?

this.editor.continueBackward(this.latlngs)
else if (index === this.getLastIndex() && this.editor.continueForward)
this.editor.continueForward(this.latlngs)
else if (this.editor.continueHere)
this.editor.continueHere(this.latlngs, index)
},
})

Expand Down Expand Up @@ -1640,6 +1643,32 @@
CLOSED: true,
MIN_VERTEX: 3,

// 🍂method continueHere(latlngs: Array, index: int)
// Set up drawing tools to continue the line forward,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in the comment we should talk about "path" or "stroke" or even "polygon", given it does not apply for actually lines ?

// after rotating the line end to the clicked vertex.
continueHere: function (latlngs, index) {
if (this.drawing()) return
latlngs = latlngs || this.getDefaultLatLngs()
this.rotateHere(latlngs, index)
this.refresh()
this.setDrawnLatLngs(latlngs)
if (latlngs.length > 0) {
this.tools.attachForwardLineGuide()
this.tools.anchorForwardLineGuide(latlngs[latlngs.length - 1])
}
this.startDrawingForward()
},

// Make index the end of latlngs.
rotateHere: function (latlngs, index) {
const old = [...latlngs]
const len = latlngs.length
for (let i = 0; i < len; i++) {
// goal: latlngs[len-1] = old[index]
latlngs[i] = old[(i + index + 1) % len]
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this method is touching the latlngs, I think we whould call onEdited here.

},

newPointForward: function (latlng) {
L.Editable.PathEditor.prototype.newPointForward.call(this, latlng)
if (!this.tools.backwardLineGuide._latlngs.length)
Expand Down