Extent Interaction

Extent4 interaction5 box2

Using an Extent interaction to draw an extent.

This example shows how to use an Extent interaction to draw a modifiable extent.

Use Shift+Drag to draw an extent. Shift+Drag on the corners or edges of the extent to resize it. Shift+Click off the extent to remove it.

import ExtentInteraction from 'ol/interaction/Extent.js';
import Map from 'ol/Map.js';
import OSM from 'ol/source/OSM.js';
import TileLayer from 'ol/layer/Tile.js';
import View from 'ol/View.js';
import {shiftKeyOnly} from 'ol/events/condition.js';

const map = new Map({
  layers: [
    new TileLayer({
      source: new OSM(),
  target: 'map',
  view: new View({
    center: [0, 0],
    zoom: 2,

const extent = new ExtentInteraction({condition: shiftKeyOnly});
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Extent Interaction</title>
    <link rel="stylesheet" href="node_modules/ol/ol.css">
      .map {
        width: 100%;
        height: 400px;
    <div id="map" class="map"></div>

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