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
Section titled “Properties”Get current sketch tool.
Syntax
Section titled “Syntax”reearth.sketch.tool: SketchType;Return Value
Section titled “Return Value”Type SketchType = | "marker" | "polyline" | "circle" | "rectangle" | "polygon" | "extrudedCircle" | "extrudedRectangle" | "extrudedPolygon"
options
Section titled “options”Get current sketch options.
Syntax
Section titled “Syntax”reearth.sketch.options: SketchOptions;Return Value
Section titled “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
Section titled “Methods”setTool
Section titled “setTool”Configure the sketch tool to a specific type, or set it to undefined to exit sketch mode.
Syntax
Section titled “Syntax”reearth.sketch.setTool: (type: SketchType | undefined) => void;Parameters
Section titled “Parameters”Type SketchType | undefined
Return Value
Section titled “Return Value”None (void). The method performs its operation without returning a value.
overrideOptions
Section titled “overrideOptions”This method is used to override the current sketch options.
Syntax
Section titled “Syntax”reearth.sketch.overrideOptions: (options: SketchOptions) => void;Parameters
Section titled “Parameters”options
Section titled “options”Type SketchOptions
Return Value
Section titled “Return Value”None (void). The method performs its operation without returning a value.
Events
Section titled “Events”create
Section titled “create”This event is triggered when a sketch drawing is successfully completed.
Syntax
Section titled “Syntax”reearth.sketch.on("create", (prop: SketchEventProps) => void);Parameters
Section titled “Parameters”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
Section titled “Example”reearth.sketch.setTool("polygon");
reearth.sketch.on("create", (props) => { console.log(`New sketch feature created:`, props);});toolChange
Section titled “toolChange”This event will be triggered when sketch tool changes.
Syntax
Section titled “Syntax”reearth.sketch.on("toolChange", (type: SketchType | undefined) => void);Parameters
Section titled “Parameters”Type SketchType | undefined
Example
Section titled “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);