Freehand Drawing

draw12 edit13 freehand3 vector66

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 'ol/ol.css';
import Draw from 'ol/interaction/Draw';
import Map from 'ol/Map';
import View from 'ol/View';
import {OSM, Vector as VectorSource} from 'ol/source';
import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer';

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>
    <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
    <script src="https://unpkg.com/elm-pep"></script>
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v3/polyfill.min.js?features=fetch,requestAnimationFrame,Element.prototype.classList,URL,TextDecoder,Number.isInteger"></script>
      .map {
        width: 100%;
    <div id="map" class="map"></div>
    <form class="form-inline">
      <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 src="main.js"></script>
  "name": "draw-freehand",
  "dependencies": {
    "ol": "6.9.0"
  "devDependencies": {
    "parcel": "^2.0.0-beta.1"
  "scripts": {
    "start": "parcel index.html",
    "build": "parcel build --public-url . index.html"