Shape Events
Shape events let you respond when a shape is added, updated, cleared or deleted. For drawing or editing an individual feature within a shape, see Feature Drawing Events.
The examples use the control obtained in Registering for Map Events. The parameters are passed to your function in the order shown.
shapeId identifies the whole shape, not one of its features. Use this ID to recognise the same shape after a rename. Events report changes on the map; they do not confirm that the record has been saved to Dataverse.
Where provided, geojson is a FeatureCollection JSON string containing the shape's features, properties and available feature IDs. Use JSON.parse(geojson) to read it. An empty shape contains {"type":"FeatureCollection","features":[]}.
ShapeDrawingAdded
The ShapeDrawingAdded event is triggered when a user adds a new shape. The shape may not contain any drawn features yet.
Parameters:
shapeName(string): The name of the new shape.geojson(string): The shape's FeatureCollection as a JSON string.shapeId(string): The ID of the new shape.
Loading existing or predefined shapes does not trigger this event. Adding another feature to a shape triggers an update instead.
Usage:
control.on('ShapeDrawingAdded', (shapeName, geojson, shapeId) => {
const collection = JSON.parse(geojson);
console.log('Added shape', shapeId, shapeName, collection.features);
});
ShapeDrawingStarted
The ShapeDrawingStarted event is triggered when a user opens a shape's Draw or Edit controls. It also occurs when changes to a shape are applied, just before ShapeDrawingModified.
Parameters:
shapeName(string): The name of the shape.shapeType(string):''when opening Draw/Edit. For an update, the geometry type for a single feature, or'GeometryCollection'for multiple features or an empty shape.shapeId(string): The ID of the shape.
This event does not provide coordinates and does not necessarily mean the user has clicked the map or started a new drawing.
Usage:
control.on('ShapeDrawingStarted', (shapeName, shapeType, shapeId) => {
console.log('Shape interaction/update', shapeId, shapeName, shapeType);
});
ShapeDrawingModified
The ShapeDrawingModified event is triggered when changes to a shape are applied. This includes changes to its name, feature properties, title or style, as well as completed drawings, geometry edits, Transform, upload/paste, feature deletion and clearing.
Parameters:
shapeName(string): The current name of the shape.geojson(string): The updated FeatureCollection as a JSON string.shapeId(string): The ID of the shape.
An update triggers ShapeDrawingStarted → ShapeDrawingModified → ShapeDrawingCompleted, using the same shape ID. It does not trigger Modified for every pointer movement.
Property/style changes made close together are usually grouped into one update after a 400 ms pause. Selecting another shape can send that update sooner. Renaming a shape or confirming a drawing, geometry edit or Transform does not wait for this pause.
Usage:
control.on('ShapeDrawingModified', (shapeName, geojson, shapeId) => {
const collection = JSON.parse(geojson);
console.log('Updated shape', shapeId, shapeName, collection.features);
});
ShapeDrawingCompleted
The ShapeDrawingCompleted event is triggered after a shape is updated on the map. This includes finishing a drawing, but also property changes, clearing and feature deletion.
Parameters:
shapeName(string): The current name of the shape.geojson(string): The updated FeatureCollection as a JSON string.shapeId(string): The ID of the shape.
It follows ShapeDrawingModified. For a completed drawing or geometry edit, FeatureDrawingCompleted follows afterwards. Confirming Transform triggers the shape events, but not FeatureDrawingCompleted.
Cancelling geometry editing or Transform does not trigger these shape update events for the discarded changes. This event also does not confirm a record save.
For checks such as intersection validation, listen to either Modified or Completed so that you do not check the same update twice.
Usage:
control.on('ShapeDrawingCompleted', (shapeName, geojson, shapeId) => {
const collection = JSON.parse(geojson);
console.log('Updated shape', shapeId, shapeName, collection.features);
});
ShapeDrawingCleared
The ShapeDrawingCleared event is triggered when a user clears a shape's contents using Clear. Its features and original uploaded-file association are removed, but the shape and its ID remain.
Parameters:
shapeName(string): The name of the cleared shape.shapeId(string): The ID of the shape, which is still available on the map.
Started/Modified/Completed report the empty FeatureCollection before Cleared occurs. Removing an unfinished drawing point or leaving a drawing tool does not trigger this event.
Usage:
control.on('ShapeDrawingCleared', (shapeName, shapeId) => {
console.log('Shape retained, contents cleared', shapeId, shapeName);
});
ShapeDrawingDeleted
The ShapeDrawingDeleted event is triggered when a user deletes a shape. Unlike Clear, this removes the whole shape rather than just its features.
Parameters:
shapeName(string): The name of the deleted shape.shapeId(string): The ID of the deleted shape.
Deleting a whole shape does not trigger a separate FeatureDrawingDeleted event for each feature. Your listener runs before the shape is removed from the map's shape list and its layer is removed, so use the supplied ID rather than relying on the map having finished redrawing.
Usage:
control.on('ShapeDrawingDeleted', (shapeName, shapeId) => {
console.log('Deleted shape', shapeId, shapeName);
});
ShapeDrawingFileSelected
The ShapeDrawingFileSelected event is triggered after a selected or dropped shape file is successfully imported. It provides the shape's name, ID and the original file.
Parameters:
shapeName(string): The name of the shape.file(File): The original browser File object, including its name, size and file type.shapeId(string): The ID of the shape receiving the file.
The shape update events occur first. Opening the file picker, selecting a file that fails validation, or a failed import does not trigger this event.
Usage:
control.on('ShapeDrawingFileSelected', (shapeName, file, shapeId) => {
console.log('Imported file', shapeId, shapeName, file.name, file.size, file.type);
});
ShapeDrawingPasted
The ShapeDrawingPasted event is triggered after GeoJSON from the clipboard is successfully pasted into a shape.
Parameters:
shapeName(string): The name of the destination shape.geojson(string): The resulting FeatureCollection as a JSON string, not the original clipboard text.shapeId(string): The ID of the destination shape.
The shape update events occur first. A failed or rejected paste does not trigger this event.
Usage:
control.on('ShapeDrawingPasted', (shapeName, geojson, shapeId) => {
console.log('Pasted into shape', shapeId, shapeName, JSON.parse(geojson).features);
});
ShapeDrawingCancelled
This event is no longer triggered. Existing scripts can still register a listener, but registration displays a deprecation warning and the listener will not be called.
Legacy parameters:
shapeName(string): The name of the shape.shapeId(string): The ID of the shape.
To respond when a user cancels drawing or geometry editing, use FeatureDrawingCancelled. Transform Cancel has no separate public event. Neither action undoes name, property or style changes already applied.
Removing listeners
Keep the same function reference to remove only your own listener:
const onShapeModified = (shapeName, geojson, shapeId) => {
console.log(shapeId, shapeName, JSON.parse(geojson));
};
control.on('ShapeDrawingModified', onShapeModified);
// Run during your custom code's cleanup.
control.off('ShapeDrawingModified', onShapeModified);
control.off('ShapeDrawingModified') removes all listeners for that event on this control.