Skip to main content

Add Part Mode

add_part appends a new part to a polygon or multipolygon. Adding a part to a plain Polygon promotes it to a MultiPolygon. It is a selection-gated mode: select the target feature first (see Select Mode), then activate Add Part and draw the new part by clicking each vertex.

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

Programmatic API

// partRings: an array of rings ([[ [lng, lat], ... ]]) describing the new part
const result = await map.gm.edit.addPart(
'subedit-polygon',
[[[0, 50], [2, 50], [2, 52], [0, 52], [0, 50]]],
{ allowOverlap: false }, // optional; reject parts that overlap the existing geometry
);

if (result.ok) {
console.log('Feature is now a multipolygon:', result.feature);
} else {
console.warn('Rejected:', result.reason); // e.g. 'overlap'
}

The following methods are available on map.gm:

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

The following events are available on a map instance:

EventParamsDescriptionOutput
gm:add_parteventFired when a part is appended to a feature.map, feature, shape
gm:operation_rejectedeventFired when the operation is rejected.map, mode, reason
map.on('gm:add_part', (event) => {
console.log('Part added to:', event.feature?.id);
});

Live Add Part Example

Click the polygon to select it, activate Add Part, then draw a separate polygon next to it — the feature is promoted to a multipolygon.

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