Skip to main content

Difference Mode

Difference Mode allows you to subtract one polygon from another. The original feature will be replaced with the resulting difference feature.

You can handle Difference Mode for all layers on a map like this:

map.gm.enableGlobalDifferenceMode();
map.gm.disableGlobalDifferenceMode();
map.gm.toggleGlobalDifferenceMode();
map.gm.globalDifferenceModeEnabled();

// Or like this:
map.gm.enableMode('edit', 'difference');
map.gm.disableMode('edit', 'difference');
map.gm.toggleMode('edit', 'difference');
map.gm.isModeEnabled('edit', 'difference');

The following methods are available on map.gm:

MethodReturnsDescription
enableGlobalDifferenceMode()-Enables global Difference Mode.
disableGlobalDifferenceMode()-Disables global Difference Mode.
toggleGlobalDifferenceMode()-Toggles global Difference Mode.
globalDifferenceModeEnabled()BooleanReturns true if global Difference Mode is enabled. false when disabled.

The following events are available on a map instance:

EventParamsDescriptionOutput
gm:differenceeventFired during the difference operation.map, originalFeatures, feature
gm:createeventFired during the difference operation.map, feature, shape

The following events are available on a map instance:

EventParamsDescriptionOutput
gm:globaldifferencemodetoggledeventFired when Difference Mode is toggled.enabled, map

You can also listen to specific Difference Mode events on the map instance like this:

map.on('gm:globaldifferencemodetoggled', (event) => {
console.log(event);
});

Behavior

Difference mode operates by:

  1. Selecting a target polygon (the one to subtract from)
  2. Drawing or selecting another polygon that will be subtracted from the target
  3. The original feature is replaced with the resulting difference feature

Supported Shapes

Difference mode supports the following feature types:

  • Polygons
  • Rectangles
  • Circles

Live Difference Example