worldwind-ui API / worldwind-kit / DrawTool
Class: DrawTool ​
Defined in: kit/src/draw.ts:138
Draws and edits points, lines and polygons on the globe.
Call start('polygon') and clicks add vertices; a double-click, finish() or Enter completes the shape. Finished features can be clicked to select them, their vertices dragged, and removed with Delete. Everything lives in the tool's own layer and round-trips through GeoJSON.
Example ​
const draw = new DrawTool(globe);
draw.subscribe((state) => console.log(state.features.length, 'features'));
draw.start('polygon');
// ... user clicks three times and presses Enter ...
console.log(draw.toGeoJson());Constructors ​
Constructor ​
new DrawTool(
globe,options?):DrawTool
Defined in: kit/src/draw.ts:158
Parameters ​
globe ​
options? ​
DrawToolOptions = {}
Returns ​
DrawTool
Properties ​
layer ​
readonlylayer:WWRenderableLayer
Defined in: kit/src/draw.ts:139
Accessors ​
state ​
Get Signature ​
get state():
DrawState
Defined in: kit/src/draw.ts:188
Current state; the same object until something changes.
Returns ​
Methods ​
add() ​
add(
input):DrawFeature
Defined in: kit/src/draw.ts:238
Adds a finished feature programmatically.
Parameters ​
input ​
Returns ​
cancel() ​
cancel():
void
Defined in: kit/src/draw.ts:223
Throws the current draft away.
Returns ​
void
clear() ​
clear():
void
Defined in: kit/src/draw.ts:301
Returns ​
void
destroy() ​
destroy():
void
Defined in: kit/src/draw.ts:362
Stops the tool and removes its layer from the globe.
Returns ​
void
featureAt() ​
featureAt(
object):DrawFeature|null
Defined in: kit/src/draw.ts:316
The feature a picked renderable belongs to, if it is one of the tool's.
Parameters ​
object ​
unknown
Returns ​
DrawFeature | null
find() ​
find(
id):DrawFeature|undefined
Defined in: kit/src/draw.ts:311
Parameters ​
id ​
string
Returns ​
DrawFeature | undefined
finish() ​
finish():
DrawFeature|null
Defined in: kit/src/draw.ts:210
Completes the line or polygon being drawn, when it has enough vertices.
Returns ​
DrawFeature | null
load() ​
load(
collection,options?):DrawFeature[]
Defined in: kit/src/draw.ts:337
Adds Point, LineString and Polygon features from GeoJSON (other geometries are skipped).
Parameters ​
collection ​
options? ​
replace? ​
boolean
Returns ​
remove() ​
remove(
id):boolean
Defined in: kit/src/draw.ts:274
Parameters ​
id ​
string
Returns ​
boolean
removeSelected() ​
removeSelected():
void
Defined in: kit/src/draw.ts:286
Removes the selected vertex when the feature can spare it, else the selected feature.
Returns ​
void
select() ​
select(
id,vertex?):void
Defined in: kit/src/draw.ts:265
Parameters ​
id ​
string | null
vertex? ​
number | null
Returns ​
void
start() ​
start(
mode):void
Defined in: kit/src/draw.ts:193
Starts drawing features of a kind; clicks on the globe now add points.
Parameters ​
mode ​
Returns ​
void
stop() ​
stop():
void
Defined in: kit/src/draw.ts:202
Stops drawing (finished features stay); an unfinished draft is discarded.
Returns ​
void
subscribe() ​
subscribe(
listener):Unsubscribe
Defined in: kit/src/draw.ts:357
Parameters ​
listener ​
(state) => void
Returns ​
toGeoJson() ​
toGeoJson():
DrawFeatureCollection
Defined in: kit/src/draw.ts:321
Returns ​
undo() ​
undo():
void
Defined in: kit/src/draw.ts:230
Removes the last draft vertex.
Returns ​
void
update() ​
update(
id,changes):void
Defined in: kit/src/draw.ts:245
Replaces a feature's positions or properties.
Parameters ​
id ​
string
changes ​
positions? ​
readonly LatLonAlt[]
properties? ​
Record<string, unknown>
Returns ​
void