Draw Control
The Draw Control provides an interface for drawing and editing geometries directly on the map. It supports various drawing modes including points, lines, polygons, and more complex shapes.
Constructor
OR
new GTSWebSDKDrawControl.GTSWebSDKDrawControl(options?: DrawOptions)
Creates a new Draw Control with the specified options.
Parameters:
| Name | Type | Description |
|---|---|---|
| options | DrawOptions | Options for configuring the draw control's behavior and available modes. |
Example:
modes: [
'point',
'linestring',
'polygon',
'rectangle',
'angled-rectangle',
'circle',
'sector',
'sensor',
'freehand',
'select',
'delete-selection',
'delete',
'download'
],
open: true,
computeElevation: false
});
map.addControl(drawMeasureControl, 'top-left');
const drawControl = new GTSWebSDKDrawControl.GTSWebSDKDrawControl({
modes: [
'point',
'linestring',
'polygon',
'rectangle',
'angled-rectangle',
'circle',
'sector',
'sensor',
'freehand',
'select',
'delete-selection',
'delete',
'download'
],
open: true,
computeElevation: false
});
//custom style
drawControl.measureOptions.modeOptions.point.styles= {
"pointColor": "#FF0000",
"pointWidth": 5,
"pointOutlineColor": "#666666",
"pointOutlineWidth": 1
};
map.addControl(drawControl, 'top-left');
Properties
The following properties are set via the DrawOptions object during construction.
An array of drawing modes to enable in the control. Available modes
include: 'point', 'linestring', 'polygon',
'rectangle', 'angled-rectangle', 'circle',
'sector', 'sensor', 'freehand', 'select',
'delete-selection', 'delete', 'download'.
If true, the draw control UI will be open by default
when added to the map. **Default:** false.
If true, elevation data will be computed for drawn
geometries. **Default:** false.
If true, vertices will snap to existing features when
drawing. **Default:** false.
Events
The Draw Control emits events related to drawing activities and geometry changes.
Fired when a new geometry is created.
drawInstance.on('create', (features) => {
const all = drawInstance.getSnapshot();
console.log('Drawing finished id: ', features);
});
Fired when an existing geometry is updated.
drawInstance.on('update', (features) => {
const all = drawInstance.getSnapshot();
console.log('Drawing finished id: ', features);
});
Fired when a geometry is deleted.
drawInstance.on('delete', (features) => {
const all = drawInstance.getSnapshot();
console.log('Drawing finished id: ', features);
});
Fired when the selection of geometries changes.
drawInstance.on('select', (features) => {
const all = drawInstance.getSnapshot();
console.log('Drawing finished id: ', features);
});
Methods
Returns all the features currently drawn on the map in GeoJSON format.
Clears all features from the map for the current drawing instance.
Adds one or more GeoJSON features to the control and displays them on the map.