Skip to content

Commit

Permalink
Merge pull request #994 from dbauszus-glx/cancel-drawing
Browse files Browse the repository at this point in the history
Cancel drawing interaction with escape key.
  • Loading branch information
RobAndrewHurst authored Nov 13, 2023
2 parents ca5330a + 33a5f87 commit db4b233
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/mapview/interactions/draw.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -150,6 +158,8 @@ export default function(params){

function finish(feature) {

document.removeEventListener('keyup', escape)

// Remove snap interaction.
mapview.interaction.snap?.remove?.()

Expand Down

0 comments on commit db4b233

Please sign in to comment.