Skip to main content

Add Hole Mode

add_hole punches an interior ring (a hole) into a polygon or multipolygon. It is a selection-gated mode: select the target polygon first (see Select Mode), then the Add Hole control becomes enabled. With the mode active, draw a closed ring inside the selected polygon by clicking each vertex. A ring drawn outside the polygon is rejected (the geometry is left untouched and a gm:operation_rejected event fires with reason not_contained).

map.gm.enableMode('edit', 'add_hole');
map.gm.disableMode('edit', 'add_hole');
map.gm.toggleMode('edit', 'add_hole');
map.gm.isModeEnabled('edit', 'add_hole');

Programmatic API

For host-driven flows you can add a hole by id with the geoman.edit façade — it runs the same operation and fires the same events, without any toolbar interaction:

// ring: an array of [lng, lat] positions forming a closed ring inside the feature
const result = await map.gm.edit.addHole('subedit-polygon', [
[-4, 51], [-2, 51], [-2, 52], [-4, 52], [-4, 51],
]);

if (result.ok) {
console.log('Updated feature:', result.feature);
} else {
console.warn('Rejected:', result.reason); // e.g. 'not_contained'
}

The following methods are available on map.gm:

MethodReturnsDescription
enableMode('edit', 'add_hole')PromiseEnables Add Hole Mode.
disableMode('edit', 'add_hole')PromiseDisables Add Hole Mode.
toggleMode('edit', 'add_hole')PromiseToggles Add Hole Mode.
isModeEnabled('edit', 'add_hole')BooleanReturns true if Add Hole Mode is enabled. false when disabled.

The following events are available on a map instance:

EventParamsDescriptionOutput
gm:add_holeeventFired when a hole is added to a feature.map, feature, shape
gm:operation_rejectedeventFired when the operation is rejected.map, mode, reason
map.on('gm:add_hole', (event) => {
console.log('Hole added to:', event.feature?.id);
});

Live Add Hole Example

Click the polygon to select it, activate Add Hole, then click vertices to draw a ring inside it and close the ring on the first point.

Building something complex? Our team can help with architecture and integration. Get in touch →