Skip to content

useOlDrawEventListener

useOlDrawEventListener(draw, type, listener): void

Defined in: src/use-ol-draw-event-listener.ts:33

Hook to attach an event listener to an OpenLayers Draw interaction. Automatically handles cleanup when the component unmounts or dependencies change.

The OpenLayers Draw interaction instance (null-safe)

Draw | null

DrawEventType

The type of draw event to listen for (e.g., ‘drawstart’, ‘drawend’, ‘drawabort’)

DrawListener

The callback function to execute when the event fires

void

const draw = useOlDraw()
useOlDrawEventListener(draw, 'drawend', (evt) => {
console.log('Feature drawn', evt.feature)
})