Using the Extent interaction to modify an extent.
This example shows how to use an Extent interaction to modify a given extent, by moving its corners or edges.
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import {never} from 'ol/events/condition.js';
import ExtentInteraction from 'ol/interaction/Extent.js';
import TileLayer from 'ol/layer/Tile.js';
import {transformExtent} from 'ol/proj.js';
import OSM from 'ol/source/OSM.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({
extent: transformExtent([-10, -10, 10, 10], 'EPSG:4326', 'EPSG:3857'),
createCondition: never, // do not create a new extent on pointer down
drag: true, // drag existing extent
boxStyle: {
'fill-color': 'rgba(255, 255, 255, 0.4)',
'stroke-color': '#3399CC',
'stroke-width': 1.25,
},
});
map.addInteraction(extent);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Modify an extent</title>
<link rel="stylesheet" href="node_modules/ol/ol.css">
<style>
.map {
width: 100%;
height: 400px;
}
</style>
</head>
<body>
<div id="map" class="map"></div>
<script type="module" src="main.js"></script>
</body>
</html>
{
"name": "extent-interaction-modify",
"dependencies": {
"ol": "10.9.0"
},
"devDependencies": {
"vite": "^3.2.3"
},
"scripts": {
"start": "vite",
"build": "vite build"
}
}