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
:
Method | Returns | Description |
---|---|---|
enableGlobalDifferenceMode() | - | Enables global Difference Mode. |
disableGlobalDifferenceMode() | - | Disables global Difference Mode. |
toggleGlobalDifferenceMode() | - | Toggles global Difference Mode. |
globalDifferenceModeEnabled() | Boolean | Returns true if global Difference Mode is enabled. false when disabled. |
The following events are available on a map instance:
Event | Params | Description | Output |
---|---|---|---|
gm:difference | event | Fired during the difference operation. | map , originalFeatures , feature |
gm:create | event | Fired during the difference operation. | map , feature , shape |
The following events are available on a map instance:
Event | Params | Description | Output |
---|---|---|---|
gm:globaldifferencemodetoggled | event | Fired 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:
- Selecting a target polygon (the one to subtract from)
- Drawing or selecting another polygon that will be subtracted from the target
- The original feature is replaced with the resulting difference feature
Supported Shapes
Difference mode supports the following feature types:
- Polygons
- Rectangles
- Circles