reearth.sketch
The Re:Earth Visualizer includes a powerful sketch feature that enables users to dynamically draw custom markers, polylines, polygons, and more directly on the map. This functionality is accessible through the plugin API via reearth.sketch.
Properties
tool
Get current sketch tool.
Syntax
reearth.sketch.tool: SketchType;Return Value
Type SketchType = | "marker" | "polyline" | "circle" | "rectangle" | "polygon" | "extrudedCircle" | "extrudedRectangle" | "extrudedPolygon"
options
Get current sketch options.
Syntax
reearth.sketch.options: SketchOptions;Return Value
Type
type SketchOptions = { color?: string; appearance?: SketchAppearance; dataOnly?: boolean; disableShadow?: boolean; rightClickToAbort?: boolean; autoResetInteractionMode?: boolean;};- color: Specifies the primary color for the sketch geometry.
- appearance: Defines the styles applied to the sketch geometry once the drawing is completed.
- dataOnly: When set to true, the sketch will not append a new layer to the map after drawing. Default:
false(Note: this option will be set totruein Re:Earth Visualizer Editor). - disableShadow: Determines whether shadows are displayed for the drawn geometry. Default:
false. - rightClickToAbort: Enables the ability to abort the current drawing by right-clicking the mouse. Default:
true. (Note: this option will be set tofalsein Re:Earth Visualizer Editor). - autoResetInteractionMode: Automatically resets the viewer’s interaction mode to the default after completing a drawing. Default:
true.
Methods
setTool
Configure the sketch tool to a specific type, or set it to undefined to exit sketch mode.
Syntax
reearth.sketch.setTool: (type: SketchType | undefined) => void;Parameters
type
Type SketchType | undefined
Return Value
None (void). The method performs its operation without returning a value.
overrideOptions
This method is used to override the current sketch options.
Syntax
reearth.sketch.overrideOptions: (options: SketchOptions) => void;Parameters
options
Type SketchOptions
Return Value
None (void). The method performs its operation without returning a value.
Events
create
This event is triggered when a sketch drawing is successfully completed.
Syntax
reearth.sketch.on("create", (prop: SketchEventProps) => void);Parameters
prop
Type
type SketchEventProps = { layerId?: string; featureId?: string; feature?: SketchFeature;};- layerId: The ID of the sketch layer. This property will not be available if the
dataOnlyoption is enabled. - featureId: The ID of the sketch feature. This property will also be unavailable if the
dataOnlyoption is enabled. - feature: A
GeoJSONobject, withidtypepositionsextrudedHeightinproperties.
Example
reearth.sketch.setTool("polygon");
reearth.sketch.on("create", (props) => { console.log(`New sketch feature created:`, props);});toolChange
This event will be triggered when sketch tool changes.
Syntax
reearth.sketch.on("toolChange", (type: SketchType | undefined) => void);Parameters
type
Type SketchType | undefined
Example
reearth.sketch.on("toolChange", (tool) => { console.log(`Sketch tool changed:`, tool);});
// run below in async to check the event:reearth.sketch.setTool("polygon");reearth.sketch.setTool(undefined);