From b64c6c5ec8dc946736cb81a139981e78aca191cf Mon Sep 17 00:00:00 2001 From: Brian Savage Date: Thu, 22 Aug 2024 08:18:50 -0400 Subject: [PATCH] draw:drawvertex can add or remove points; handle point removal --- src/components/AppMap.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/AppMap.ts b/src/components/AppMap.ts index 01e9843..90ba2c0 100644 --- a/src/components/AppMap.ts +++ b/src/components/AppMap.ts @@ -887,8 +887,17 @@ export default class AppMap extends mixins(MixinUtil) { 'draw:drawstart': () => { this.drawVertexLayers = []; }, - 'draw:drawvertex': () => { - this.drawVertexLayers.push(this.map.activeLayer); + 'draw:drawvertex': (item: any) => { + // Determine if points have been added or removed + const n0 = this.drawVertexLayers.length + const n1 = item.layers.getLayers().length; + if (n0 + 1 == n1) // Point Added + this.drawVertexLayers.push(this.map.activeLayer); + else if (n0 - 1 == n1) // Point Removed (Assume 'delete last point' clicked) + this.drawVertexLayers.pop() + else { + console.log(`Unknown state encountered currentPoints(edit) ${n1} layers ${n0}`) + } }, 'draw:edited': (e: any) => { e.layers.eachLayer((layer: L.Marker | L.Polyline) => {