diff --git a/lib/mapview/interactions/draw.mjs b/lib/mapview/interactions/draw.mjs index 034a91b08..6558c7937 100644 --- a/lib/mapview/interactions/draw.mjs +++ b/lib/mapview/interactions/draw.mjs @@ -38,7 +38,8 @@ export default function(params){ const moveEvent = new ol.MapBrowserEvent('pointermove', mapview.Map, e.originalEvent) mapview.interaction.interaction.handleEvent(moveEvent) - mapview.interaction.interaction.handleEvent(moveEvent) + + mapview.interaction.conditions?.forEach(fn => typeof fn === 'function' && fn(e)) return false; } @@ -88,6 +89,13 @@ export default function(params){ // Add mapview.interaction.Layer to mapview. mapview.Map.addLayer(mapview.interaction.Layer) + + document.addEventListener('keyup', escape) + + function escape(e){ + + e.key === 'Escape' && mapview.interaction.finish() + } // Create OL draw interaction. mapview.interaction.interaction = new ol.interaction.Draw(mapview.interaction) @@ -150,6 +158,8 @@ export default function(params){ function finish(feature) { + document.removeEventListener('keyup', escape) + // Remove snap interaction. mapview.interaction.snap?.remove?.()