Freehand Drawing

draw14 edit13 freehand3 vector79

Example using the ol/interaction/Draw interaction in freehand mode.

This example demonstrates the ol/interaction/Draw in freehand mode. During freehand drawing, points are added while dragging. Set freehand: true to enable freehand mode. Note that freehand mode can be conditionally enabled by using the freehandCondition option. For example to toggle freehand mode with the Shift key, use freehandCondition: shiftKeyOnly.

import Draw from 'ol/interaction/Draw.js';
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import {OSM, Vector as VectorSource} from 'ol/source.js';
import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer.js';

const raster = new TileLayer({
  source: new OSM(),

const source = new VectorSource({wrapX: false});

const vector = new VectorLayer({
  source: source,

const map = new Map({
  layers: [raster, vector],
  target: 'map',
  view: new View({
    center: [-11000000, 4600000],
    zoom: 4,

const typeSelect = document.getElementById('type');

let draw; // global so we can remove it later
function addInteraction() {
  const value = typeSelect.value;
  if (value !== 'None') {
    draw = new Draw({
      source: source,
      type: typeSelect.value,
      freehand: true,

 * Handle change event.
typeSelect.onchange = function () {

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Freehand Drawing</title>
    <link rel="stylesheet" href="node_modules/ol/ol.css">
      .map {
        width: 100%;
        height: 400px;
    <div id="map" class="map"></div>
      <label for="type">Geometry type &nbsp;</label>
      <select id="type">
        <option value="LineString">LineString</option>
        <option value="Polygon">Polygon</option>
        <option value="Circle">Circle</option>
        <option value="None">None</option>

    <script type="module" src="main.js"></script>
  "name": "draw-freehand",
  "dependencies": {
    "ol": "9.2.4"
  "devDependencies": {
    "vite": "^3.2.3"
  "scripts": {
    "start": "vite",
    "build": "vite build"